新增功能

This commit is contained in:
2026-02-10 14:56:16 +08:00
parent 743bbc9e34
commit fb0cbea2dc
63 changed files with 5831 additions and 0 deletions

View File

@ -0,0 +1,218 @@
package com.fuint.common.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fuint.repository.model.MtUser;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
/**
* 积分记录实体类
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public class RaffleDto implements Serializable {
private Integer id;
private String title;
private String brief;
private String hot;
private String image;
private String raffleType;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBrief() {
return brief;
}
public void setBrief(String brief) {
this.brief = brief;
}
public String getHot() {
return hot;
}
public void setHot(String hot) {
this.hot = hot;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getRaffleType() {
return raffleType;
}
public void setRaffleType(String raffleType) {
this.raffleType = raffleType;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getClick() {
return click;
}
public void setClick(Integer click) {
this.click = click;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
private String description;
private Integer click;
private Integer sort;
private Date createTime;
private Date updateTime;
private String status;
private String operator;
private Integer nowCnt;
private Integer allCnt;
private Integer rafflePoint;
public Integer getRafflePoint() {
return rafflePoint;
}
public void setRafflePoint(Integer rafflePoint) {
this.rafflePoint = rafflePoint;
}
public Integer getNowCnt() {
return nowCnt;
}
public void setNowCnt(Integer nowCnt) {
this.nowCnt = nowCnt;
}
public Integer getAllCnt() {
return allCnt;
}
public void setAllCnt(Integer allCnt) {
this.allCnt = allCnt;
}
private String extraPrize;
private String extraImage;
private String extraType;
private Integer forwardPoint;
public String getExtraPrize() {
return extraPrize;
}
public void setExtraPrize(String extraPrize) {
this.extraPrize = extraPrize;
}
public String getExtraImage() {
return extraImage;
}
public void setExtraImage(String extraImage) {
this.extraImage = extraImage;
}
public String getExtraType() {
return extraType;
}
public void setExtraType(String extraType) {
this.extraType = extraType;
}
public Integer getForwardPoint() {
return forwardPoint;
}
public void setForwardPoint(Integer forwardPoint) {
this.forwardPoint = forwardPoint;
}
}

View File

@ -0,0 +1,187 @@
package com.fuint.common.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
/**
* 抽奖表
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public class RaffleItemDto {
private Integer id;
private Integer raffleId;
private String title;
private String prize;
private Integer point;
private Integer userId;
private String userNo;
private String name;
private String image;
private Integer win;
private Integer deal;
private String description;
private Date createTime;
private Date updateTime;
private String operator;
private String forwardUserId;
private String prizeType;
public String getForwardUserId() {
return forwardUserId;
}
public void setForwardUserId(String forwardUserId) {
this.forwardUserId = forwardUserId;
}
public String getPrizeType() {
return prizeType;
}
public void setPrizeType(String prizeType) {
this.prizeType = prizeType;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getRaffleId() {
return raffleId;
}
public void setRaffleId(Integer raffleId) {
this.raffleId = raffleId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getPrize() {
return prize;
}
public void setPrize(String prize) {
this.prize = prize;
}
public Integer getPoint() {
return point;
}
public void setPoint(Integer point) {
this.point = point;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getUserNo() {
return userNo;
}
public void setUserNo(String userNo) {
this.userNo = userNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public Integer getWin() {
return win;
}
public void setWin(Integer win) {
this.win = win;
}
public Integer getDeal() {
return deal;
}
public void setDeal(Integer deal) {
this.deal = deal;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
}

View File

@ -0,0 +1,40 @@
package com.fuint.common.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 抽奖类型DTO
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Data
public class RaffleTypeDto implements Serializable {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("商户ID")
private Integer merchantId;
@ApiModelProperty("店铺ID")
private Integer storeId;
@ApiModelProperty("类型编码")
private String code;
@ApiModelProperty("类型名称")
private String name;
@ApiModelProperty("备注")
private String description;
@ApiModelProperty("排序")
private Integer sort;
@ApiModelProperty("状态")
private String status;
}

View File

@ -0,0 +1,64 @@
package com.fuint.common.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 任务中心实体
*
* Created by Codex
*/
@Data
public class TaskDto implements Serializable {
@ApiModelProperty("自增ID")
private Integer id;
@ApiModelProperty("所属商户ID")
private Integer merchantId;
@ApiModelProperty("所属店铺ID")
private Integer storeId;
@ApiModelProperty("任务编码")
private String taskCode;
@ApiModelProperty("任务名称")
private String taskName;
@ApiModelProperty("任务类型")
private String taskType;
@ApiModelProperty("任务描述")
private String taskDesc;
@ApiModelProperty("任务跳转链接")
private String jumpUrl;
@ApiModelProperty("奖励积分")
private Integer rewardPoint;
@ApiModelProperty("每日可领取次数")
private Integer dailyLimit;
@ApiModelProperty("排序")
private Integer sort;
@ApiModelProperty("最后操作人")
private String operator;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty("创建时间")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("状态A正常D删除")
private String status;
}

View File

@ -0,0 +1,36 @@
package com.fuint.common.enums;
/**
* 订单类型
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public enum PrizeTypeEnum {
NORMAL("NORMAL", "普通奖"),
EXTRA("EXTRA", "额外奖");
private String key;
private String value;
PrizeTypeEnum(String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,39 @@
package com.fuint.common.enums;
/**
* 订单类型
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public enum RaffleTypeEnum {
TCG("tcg", "集换式卡牌"),
GK("gk", "手办"),
GAME("game", "主机游戏"),
POPMART("popmart", "泡泡玛特"),
ALL("all", "所有");
private String key;
private String value;
RaffleTypeEnum(String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,20 @@
package com.fuint.common.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 卡券列表请求参数
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Data
public class RaffleParam extends PageParam implements Serializable {
private String dataType;
}

View File

@ -0,0 +1,31 @@
package com.fuint.common.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 抽奖类型分页请求参数
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Data
public class RaffleTypePage extends PageParam implements Serializable {
@ApiModelProperty("所属商户ID")
private Integer merchantId;
@ApiModelProperty("所属店铺ID")
private Integer storeId;
@ApiModelProperty("类型编码")
private String code;
@ApiModelProperty("类型名称")
private String name;
@ApiModelProperty("状态")
private String status;
}

View File

@ -0,0 +1,30 @@
package com.fuint.common.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 任务中心分页请求参数
*
* Created by Codex
*/
@Data
public class TaskPage extends PageParam implements Serializable {
@ApiModelProperty("所属商户ID")
private Integer merchantId;
@ApiModelProperty("所属店铺ID")
private Integer storeId;
@ApiModelProperty("任务名称")
private String taskName;
@ApiModelProperty("任务类型")
private String taskType;
@ApiModelProperty("状态")
private String status;
}

View File

@ -0,0 +1,26 @@
package com.fuint.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuint.common.dto.PointDto;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.model.MtGrow;
import com.fuint.repository.model.MtPoint;
/**
* 积分业务接口
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public interface GrowService extends IService<MtGrow> {
MtGrow querySignInfo(Integer userId);
boolean doSign(Integer id) throws BusinessCheckException;
boolean doAdv(Integer id) throws BusinessCheckException;
void clearAdvNum() throws BusinessCheckException;
}

View File

@ -0,0 +1,108 @@
package com.fuint.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuint.common.dto.PointDto;
import com.fuint.common.dto.RaffleDto;
import com.fuint.common.dto.RaffleItemDto;
import com.fuint.common.dto.UserInfo;
import com.fuint.common.param.RaffleParam;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtPoint;
import com.fuint.repository.model.MtRaffle;
import com.fuint.repository.model.MtRaffleItem;
import com.fuint.repository.model.MtUser;
import java.util.List;
/**
* 抽奖业务接口
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public interface RaffleService extends IService<MtRaffle> {
/**
* 分页查询抽奖列表
*
* @param paginationRequest
* @return
*/
PaginationResponse<RaffleDto> queryListByPagination(PaginationRequest paginationRequest) throws BusinessCheckException;
/**
* 保存抽奖
*
* @param reqRaffleDto
* @return
*/
int addRaffle(MtRaffle reqRaffleDto) throws BusinessCheckException;
/**
* 保存抽奖明细
*
* @param reqRaffleItemDto
* @return
*/
void addRaffleItem(MtRaffleItem reqRaffleItemDto) throws BusinessCheckException;
/**
* 保存抽奖明细
*
* @param raffleItemDto
* @return
*/
List<MtRaffleItem> queryRaffleItemByRaffleId(RaffleItemDto raffleItemDto) throws BusinessCheckException;
List<RaffleItemDto> queryRaffleItemByRaffleId2wechat(Integer raffleId) throws BusinessCheckException;
List<MtRaffleItem> doRaffleByRaffleId(Integer raffleId,Integer num, UserInfo mtUser,Integer forwardUserId) throws BusinessCheckException;
ResponseObject findRaffleList(RaffleParam raffleParam) throws BusinessCheckException;
MtRaffle queryRaffle(Integer raffleId) throws BusinessCheckException;
/**
* 保存抽奖
*
* @param reqRaffleDto
* @return
*/
int updRaffle(MtRaffle reqRaffleDto) throws BusinessCheckException;
/**
* 保存抽奖明细
*
* @param userId
* @return
*/
List<RaffleItemDto> queryRaffleItemByUserId(Integer userId) throws BusinessCheckException;
boolean tranfer2Point(Integer raffleItemId, Integer userId) throws BusinessCheckException;
Integer userPoint(Integer userId) throws BusinessCheckException;
boolean dealRaffleItem(Integer raffleItemId, String name) throws BusinessCheckException;
/**
* 最新抽奖列表
*
* @param limit
* @return
*/
List<RaffleDto> getLatestRaffles(Integer limit) throws BusinessCheckException;
/**
* 最新中奖列表
*
* @param limit
* @return
*/
List<RaffleItemDto> getLatestWinItems(Integer limit) throws BusinessCheckException;
}

View File

@ -0,0 +1,28 @@
package com.fuint.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuint.common.param.RaffleTypePage;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.model.MtRaffleType;
import java.util.List;
/**
* 抽奖类型服务接口
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public interface RaffleTypeService extends IService<MtRaffleType> {
PaginationResponse<MtRaffleType> queryRaffleTypeListByPagination(RaffleTypePage page) throws BusinessCheckException;
MtRaffleType addRaffleType(MtRaffleType raffleType) throws BusinessCheckException;
MtRaffleType getRaffleTypeById(Integer id) throws BusinessCheckException;
MtRaffleType updateRaffleType(MtRaffleType raffleType) throws BusinessCheckException;
List<MtRaffleType> getAvailableRaffleType(Integer merchantId, Integer storeId) throws BusinessCheckException;
}

View File

@ -0,0 +1,59 @@
package com.fuint.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuint.common.dto.TaskDto;
import com.fuint.common.param.TaskPage;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.model.MtTask;
import java.util.List;
import java.util.Map;
/**
* 任务中心业务接口
*
* Created by Codex
*/
public interface TaskService extends IService<MtTask> {
/**
* 分页查询列表
*/
PaginationResponse<MtTask> queryTaskListByPagination(TaskPage taskPage) throws BusinessCheckException;
/**
* 添加任务
*/
MtTask addTask(TaskDto taskDto) throws BusinessCheckException;
/**
* 根据ID获取任务信息
*/
MtTask queryTaskById(Integer id) throws BusinessCheckException;
/**
* 更新任务
*/
MtTask updateTask(TaskDto taskDto) throws BusinessCheckException;
/**
* 根据条件查询任务列表
*/
List<MtTask> queryTaskListByParams(Map<String, Object> params) throws BusinessCheckException;
/**
* 会员端任务列表(含完成/领取进度)
*/
List<Map<String, Object>> queryClientTaskList(Integer merchantId, Integer storeId, Integer userId) throws BusinessCheckException;
/**
* 完成任务
*/
Map<String, Object> completeTask(Integer merchantId, Integer storeId, Integer userId, Integer taskId, String operator) throws BusinessCheckException;
/**
* 领取任务奖励
*/
Map<String, Object> claimTask(Integer merchantId, Integer storeId, Integer userId, Integer taskId, String operator) throws BusinessCheckException;
}

View File

@ -0,0 +1,137 @@
package com.fuint.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.common.dto.PointDto;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.enums.WxMessageEnum;
import com.fuint.common.service.GrowService;
import com.fuint.common.service.MemberService;
import com.fuint.common.service.PointService;
import com.fuint.common.service.WeixinService;
import com.fuint.common.util.DateUtil;
import com.fuint.framework.annoation.OperationServiceLog;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.mapper.MtGrowMapper;
import com.fuint.repository.mapper.MtPointMapper;
import com.fuint.repository.mapper.MtUserMapper;
import com.fuint.repository.model.MtGrow;
import com.fuint.repository.model.MtPoint;
import com.fuint.repository.model.MtRaffleItem;
import com.fuint.repository.model.MtUser;
import com.fuint.utils.StringUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* 积分管理业务实现类
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Service
@AllArgsConstructor
public class GrowServiceImpl extends ServiceImpl<MtGrowMapper, MtGrow> implements GrowService {
private MtGrowMapper mtGrowMapper;
private PointService pointService;
private CouponServiceImpl couponService;
@Override
public MtGrow querySignInfo(Integer userId) {
LambdaQueryWrapper<MtGrow> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtGrow::getUserId, userId);
List<MtGrow> signInfoList = mtGrowMapper.selectList(lambdaQueryWrapper);
if (signInfoList != null && signInfoList.size() > 0) {
return signInfoList.get(0);
}
MtGrow signInfo = new MtGrow();
signInfo.setUserId(userId);
signInfo.setAdvNum(0);
signInfo.setAdvTotal(3);
signInfo.setGrowTotal(0);
signInfo.setCreateTime(new Date());
signInfo.setUpdateTime(new Date());
signInfo.setOperator("SYSTEM");
mtGrowMapper.insertForId(signInfo);
return signInfo;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean doSign(Integer id) throws BusinessCheckException {
//
MtGrow grow = mtGrowMapper.selectById(id);
MtGrow newGrow = new MtGrow();
newGrow.setId(grow.getId());
newGrow.setSignTime(new Date());
newGrow.setUpdateTime(new Date());
mtGrowMapper.updateById(newGrow);
MtPoint reqPointDto = new MtPoint();
reqPointDto.setAmount(1);
reqPointDto.setUserId(grow.getUserId());
reqPointDto.setDescription("签到1积分");
reqPointDto.setOperator("系统");
pointService.addPoint(reqPointDto);
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean doAdv(Integer id) throws BusinessCheckException {
//
MtGrow grow = mtGrowMapper.selectById(id);
MtGrow newGrow = new MtGrow();
newGrow.setId(grow.getId());
newGrow.setAdvNum(grow.getAdvNum()+1);
newGrow.setGrowTotal(grow.getGrowTotal() + 1);
newGrow.setUpdateTime(new Date());
mtGrowMapper.updateById(newGrow);
MtPoint reqPointDto = new MtPoint();
reqPointDto.setAmount(1);
reqPointDto.setUserId(grow.getUserId());
reqPointDto.setDescription("视频广告1积分");
reqPointDto.setOperator("系统");
pointService.addPoint(reqPointDto);
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
int nine = (newGrow.getGrowTotal())%9;
if (nine == 0) {
couponService.sendCoupon(13, grow.getUserId(),1,true,uuid,"SYSTEM");
}
int eleven = (newGrow.getGrowTotal())%11;
if (eleven == 0) {
couponService.sendCoupon(14, grow.getUserId(),1,true,uuid,"SYSTEM");
}
return true;
}
@Override
public void clearAdvNum() {
MtGrow et = new MtGrow();
et.setAdvNum(0);
Wrapper<MtGrow> ew = new LambdaQueryWrapper<>();
mtGrowMapper.update(et,ew);
}
}

View File

@ -0,0 +1,436 @@
package com.fuint.common.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.common.Constants;
import com.fuint.common.dto.*;
import com.fuint.common.enums.PrizeTypeEnum;
import com.fuint.common.enums.RaffleTypeEnum;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.enums.WxMessageEnum;
import com.fuint.common.param.RaffleParam;
import com.fuint.common.service.*;
import com.fuint.common.util.DateUtil;
import com.fuint.framework.annoation.OperationServiceLog;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.ResponseObject;
import com.fuint.module.clientApi.controller.ClientRaffleController;
import com.fuint.repository.mapper.MtPointMapper;
import com.fuint.repository.mapper.MtRaffleItemMapper;
import com.fuint.repository.mapper.MtRaffleMapper;
import com.fuint.repository.mapper.MtUserMapper;
import com.fuint.repository.model.*;
import com.fuint.utils.StringUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
/**
* 积分管理业务实现类
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Service
public class RaffleServiceImpl extends ServiceImpl<MtRaffleMapper, MtRaffle> implements RaffleService {
private static final Logger logger = LoggerFactory.getLogger(RaffleServiceImpl.class);
@Resource
private MtRaffleMapper mtRaffleMapper;
@Resource
private MtRaffleItemMapper mtRaffleItemMapper;
@Resource
private MtUserMapper mtUserMapper;
@Resource
private PointService pointService;
@Autowired
private SettingService settingService;
@Resource
private BalanceService balanceService;
/**
* 分页查询积分列表
*
* @param paginationRequest
* @return
*/
@Override
public PaginationResponse<RaffleDto> queryListByPagination(PaginationRequest paginationRequest) throws BusinessCheckException {
Page<MtPoint> pageHelper = PageHelper.startPage(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
LambdaQueryWrapper<MtRaffle> lambdaQueryWrapper = Wrappers.lambdaQuery();
String status = paginationRequest.getSearchParams().get("status") == null ? "" : paginationRequest.getSearchParams().get("status").toString();
String title = paginationRequest.getSearchParams().get("title") == null ? "" : paginationRequest.getSearchParams().get("title").toString();
if (StringUtils.isNotBlank(status)) {
lambdaQueryWrapper.eq(MtRaffle::getStatus, status);
}
if (StringUtils.isNotBlank(title)) {
lambdaQueryWrapper.like(MtRaffle::getTitle, title);
}
lambdaQueryWrapper.orderByDesc(MtRaffle::getCreateTime);
List<MtRaffle> raffleList = mtRaffleMapper.selectList(lambdaQueryWrapper);
List<RaffleDto> dataList = new ArrayList<>();
for (MtRaffle raffle : raffleList) {
RaffleDto item = new RaffleDto();
item.setId(raffle.getId());
item.setBrief(raffle.getBrief());
item.setTitle(raffle.getTitle());
item.setDescription(raffle.getDescription());
item.setRafflePoint(raffle.getRafflePoint());
item.setImage(raffle.getImage());
item.setRaffleType(raffle.getRaffleType());
item.setClick(raffle.getClick());
item.setHot(raffle.getHot());
item.setSort(raffle.getSort());
item.setNowCnt(raffle.getNowCnt());
item.setAllCnt(raffle.getAllCnt());
item.setDescription(raffle.getDescription());
item.setCreateTime(raffle.getCreateTime());
item.setUpdateTime(raffle.getUpdateTime());
item.setOperator(raffle.getOperator());
item.setStatus(raffle.getStatus());
dataList.add(item);
}
PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
PaginationResponse<RaffleDto> paginationResponse = new PaginationResponse(pageImpl, RaffleDto.class);
paginationResponse.setTotalPages(pageHelper.getPages());
paginationResponse.setTotalElements(pageHelper.getTotal());
paginationResponse.setContent(dataList);
return paginationResponse;
}
@Override
public int addRaffle(MtRaffle reqRaffleDto) throws BusinessCheckException {
return mtRaffleMapper.insertForId(reqRaffleDto);
}
@Override
public void addRaffleItem(MtRaffleItem reqRaffleItemDto) throws BusinessCheckException {
mtRaffleItemMapper.insert(reqRaffleItemDto);
}
@Override
public List<MtRaffleItem> queryRaffleItemByRaffleId(RaffleItemDto raffleItemDto) throws BusinessCheckException {
LambdaQueryWrapper<MtRaffleItem> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleItem::getRaffleId, raffleItemDto.getRaffleId());
if (raffleItemDto.getUserId() != null) {
lambdaQueryWrapper.eq(MtRaffleItem::getUserId, raffleItemDto.getUserId());
}
if (raffleItemDto.getWin() != null) {
lambdaQueryWrapper.eq(MtRaffleItem::getWin, raffleItemDto.getWin());
}
if (raffleItemDto.getDeal() != null) {
lambdaQueryWrapper.eq(MtRaffleItem::getDeal,raffleItemDto.getDeal());
}
if (raffleItemDto.getUserNo() != null) {
lambdaQueryWrapper.eq(MtRaffleItem::getUserNo,raffleItemDto.getUserNo());
}
List<MtRaffleItem> raffleList = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
return raffleList;
}
@Override
@Transactional(rollbackFor = Exception.class)
public List<MtRaffleItem> doRaffleByRaffleId(Integer raffleId, Integer num, UserInfo userinfo, Integer forwardUserId) throws BusinessCheckException {
MtUser user = mtUserMapper.selectById(userinfo.getId());
//获取抽奖信息
MtRaffle mtRaffle = mtRaffleMapper.selectById(raffleId);
mtRaffle.setNowCnt(mtRaffle.getNowCnt()+num);
mtRaffleMapper.updateById(mtRaffle);
LambdaQueryWrapper<MtRaffleItem> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleItem::getRaffleId, raffleId);
lambdaQueryWrapper.eq(MtRaffleItem::getWin, 0); //奖品状态 1已抽中 0未抽中
List<MtRaffleItem> raffleList = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
//扣减积分
MtPoint mtPoint = new MtPoint();
mtPoint.setUserId(user.getId());
mtPoint.setAmount(mtRaffle.getRafflePoint()*-1*num);
mtPoint.setDescription("一番赏:"+mtRaffle.getTitle()+ "/" + num+"");
pointService.addPoint(mtPoint);
//更新中奖信息
String baseImage = settingService.getUploadBasePath();
List<MtRaffleItem> resultList = new ArrayList<>();
for (int i = 0; i < num; i++) {
int removeNum = new Random().nextInt(raffleList.size());
MtRaffleItem mtRaffleItem = raffleList.get(removeNum);
mtRaffleItem.setUserId(user.getId());
mtRaffleItem.setUserNo(user.getUserNo());
mtRaffleItem.setWin(1);//奖品状态 1已抽中 0未抽中
mtRaffleItem.setName(user.getName());
mtRaffleItem.setUpdateTime(new Date());
mtRaffleItem.setForwardUserId(forwardUserId);
mtRaffleItemMapper.updateById(mtRaffleItem);
mtRaffleItem.setImage(baseImage + mtRaffleItem.getImage());
raffleList.remove(removeNum);
resultList.add(mtRaffleItem);
}
//判断额外奖是随机还是最终
List<MtRaffleItem> count = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
if (count.size() == 0 && StringUtil.isNotEmpty(mtRaffle.getExtraPrize())) {
logger.info(mtRaffle.getTitle()+"抽完准备出赏");
MtRaffleItem extraItem = new MtRaffleItem();
extraItem.setTitle(mtRaffle.getTitle());
extraItem.setPrize(mtRaffle.getExtraPrize());
extraItem.setImage(mtRaffle.getExtraImage());
extraItem.setPoint(mtRaffle.getRafflePoint());
extraItem.setRaffleId(mtRaffle.getId());
extraItem.setUserId(user.getId());
extraItem.setUserNo(user.getUserNo());
extraItem.setName(user.getName());
extraItem.setWin(1);//奖品状态 1已抽中 0未抽中
extraItem.setPrizeType(PrizeTypeEnum.EXTRA.getKey());
extraItem.setUpdateTime(new Date());
if ("L".equals(mtRaffle.getExtraType())) {
extraItem.setUserId(user.getId());
extraItem.setUserNo(user.getUserNo());
extraItem.setName(user.getName());
logger.info(mtRaffle.getTitle()+"最后出赏");
} else if ("R".equals(mtRaffle.getExtraType())) {
List<Integer> userIdlist = mtRaffleItemMapper.queryUserIdByRaffleId(mtRaffle.getId());
logger.info(mtRaffle.getTitle()+"随机出赏");
logger.info("随机用户ID" + JSONArray.toJSONString(userIdlist));
Integer userId = userIdlist.get(new Random().nextInt(userIdlist.size()));
MtUser extraUser = mtUserMapper.selectById(userId);
extraItem.setUserId(extraUser.getId());
extraItem.setUserNo(extraUser.getUserNo());
extraItem.setName(extraUser.getName());
}
mtRaffleItemMapper.insert(extraItem);
}
//转发奖励积分
if (forwardUserId > 0 && forwardUserId != user.getId() && mtRaffle.getForwardPoint() > 0) {
MtPoint forwardUser = new MtPoint();
forwardUser.setUserId(forwardUserId);
forwardUser.setAmount(mtRaffle.getForwardPoint()*num);
forwardUser.setDescription("推广一番赏:"+mtRaffle.getTitle()+ "/" + num+"次,转发奖励:"+forwardUser.getAmount()+"积分");
pointService.addPoint(forwardUser);
// MtBalance dto = new MtBalance();
// dto.setUserId(forwardUserId);
// dto.setAmount(BigDecimal.valueOf(mtRaffle.getForwardPoint()*num));
// dto.setDescription("推广一番赏:"+mtRaffle.getTitle()+ "/" + num+"次,转发奖励:"+dto.getAmount());
// dto.setOperator("system");
// balanceService.addBalance(dto);
}
return resultList;
}
@Override
public ResponseObject findRaffleList(RaffleParam raffleParam) throws BusinessCheckException {
Integer pageNumber = raffleParam.getPage() == null ? Constants.PAGE_NUMBER : raffleParam.getPage();
Integer pageSize = raffleParam.getPageSize() == null ? Constants.PAGE_SIZE : raffleParam.getPageSize();
String dataType = raffleParam.getDataType() == null ? null : raffleParam.getDataType();
Page<MtPoint> pageHelper = PageHelper.startPage(pageNumber, pageSize);
LambdaQueryWrapper<MtRaffle> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffle::getStatus, StatusEnum.ENABLED.getKey());
if (dataType != null && !RaffleTypeEnum.ALL.getKey().equals(dataType)) {
lambdaQueryWrapper.eq(MtRaffle::getRaffleType, dataType);
}
lambdaQueryWrapper.orderByDesc(MtRaffle::getCreateTime);
String baseImage = settingService.getUploadBasePath();
List<MtRaffle> raffleList = mtRaffleMapper.selectList(lambdaQueryWrapper);
List<RaffleDto> resultList = new ArrayList<>();
for (MtRaffle raffle:raffleList) {
RaffleDto dto = new RaffleDto();
BeanUtils.copyProperties(raffle, dto);
dto.setImage(baseImage+raffle.getImage());
if (raffle.getExtraImage() != null) {
dto.setExtraImage(baseImage + raffle.getExtraImage());
}
resultList.add(dto);
}
PageRequest pageRequest = PageRequest.of(pageNumber, pageSize);
PageImpl pageImpl = new PageImpl(resultList, pageRequest, pageHelper.getTotal());
PaginationResponse<RaffleDto> paginationResponse = new PaginationResponse(pageImpl, RaffleDto.class);
paginationResponse.setTotalPages(pageHelper.getPages());
paginationResponse.setTotalElements(pageHelper.getTotal());
paginationResponse.setContent(resultList);
return new ResponseObject(200, "查询成功", paginationResponse);
}
@Override
public MtRaffle queryRaffle(Integer raffleId) throws BusinessCheckException {
String baseImage = settingService.getUploadBasePath();
MtRaffle raffle = mtRaffleMapper.selectById(raffleId);
raffle.setImage(baseImage+raffle.getImage());
raffle.setExtraImage(baseImage+raffle.getExtraImage());
return raffle;
}
@Override
public int updRaffle(MtRaffle reqRaffleDto) throws BusinessCheckException {
return mtRaffleMapper.updateById(reqRaffleDto);
}
@Override
public List<RaffleItemDto> queryRaffleItemByUserId(Integer userId) throws BusinessCheckException {
LambdaQueryWrapper<MtRaffleItem> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleItem::getUserId, userId);
lambdaQueryWrapper.eq(MtRaffleItem::getWin,1); //1已抽中
lambdaQueryWrapper.eq(MtRaffleItem::getDeal,0);//0未处理
lambdaQueryWrapper.orderByDesc(MtRaffleItem::getCreateTime);
List<MtRaffleItem> raffleList = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
String baseImage = settingService.getUploadBasePath();
List<RaffleItemDto> resultList = new ArrayList<>();
for (MtRaffleItem raffle:raffleList) {
RaffleItemDto dto = new RaffleItemDto();
BeanUtils.copyProperties(raffle, dto);
dto.setImage(baseImage+raffle.getImage());
resultList.add(dto);
}
return resultList;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean tranfer2Point(Integer raffleItemId, Integer userId) throws BusinessCheckException {
MtUser user = mtUserMapper.selectById(userId);
MtRaffleItem item = mtRaffleItemMapper.selectById(raffleItemId);
//已转化积分或者已领取
if (item.getDeal() == 1) {
return false;
}
MtPoint mtPoint = new MtPoint();
mtPoint.setUserId(user.getId());
mtPoint.setAmount(item.getPoint());
mtPoint.setDescription("转化积分:"+item.getTitle());
pointService.addPoint(mtPoint);
item.setDeal(1); //1:已处理2未处理
item.setUpdateTime(new Date());
item.setOperator("操作人:" + userId);
mtRaffleItemMapper.updateById(item);
return true;
}
@Override
public Integer userPoint(Integer userId) throws BusinessCheckException {
MtUser user = mtUserMapper.selectById(userId);
return user.getPoint();
}
@Override
public boolean dealRaffleItem(Integer raffleItemId, String name) throws BusinessCheckException {
MtRaffleItem item = new MtRaffleItem();
item.setId(raffleItemId);
item.setDeal(1);
item.setOperator("操作人:" + name);
mtRaffleItemMapper.updateById(item);
return true;
}
@Override
public List<RaffleDto> getLatestRaffles(Integer limit) throws BusinessCheckException {
int size = (limit == null || limit <= 0) ? 5 : limit;
LambdaQueryWrapper<MtRaffle> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffle::getStatus, StatusEnum.ENABLED.getKey());
lambdaQueryWrapper.orderByDesc(MtRaffle::getCreateTime);
lambdaQueryWrapper.last("limit " + size);
String baseImage = settingService.getUploadBasePath();
List<MtRaffle> raffleList = mtRaffleMapper.selectList(lambdaQueryWrapper);
List<RaffleDto> resultList = new ArrayList<>();
for (MtRaffle raffle : raffleList) {
RaffleDto dto = new RaffleDto();
BeanUtils.copyProperties(raffle, dto);
dto.setImage(baseImage + raffle.getImage());
if (raffle.getExtraImage() != null) {
dto.setExtraImage(baseImage + raffle.getExtraImage());
}
resultList.add(dto);
}
return resultList;
}
@Override
public List<RaffleItemDto> getLatestWinItems(Integer limit) throws BusinessCheckException {
int size = (limit == null || limit <= 0) ? 20 : limit;
LambdaQueryWrapper<MtRaffleItem> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleItem::getWin, 1);
lambdaQueryWrapper.orderByDesc(MtRaffleItem::getCreateTime);
lambdaQueryWrapper.last("limit " + size);
String baseImage = settingService.getUploadBasePath();
List<MtRaffleItem> raffleList = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
List<RaffleItemDto> resultList = new ArrayList<>();
for (MtRaffleItem raffle : raffleList) {
RaffleItemDto dto = new RaffleItemDto();
BeanUtils.copyProperties(raffle, dto);
dto.setImage(baseImage + raffle.getImage());
resultList.add(dto);
}
return resultList;
}
@Override
public List<RaffleItemDto> queryRaffleItemByRaffleId2wechat(Integer raffleId) throws BusinessCheckException {
LambdaQueryWrapper<MtRaffleItem> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleItem::getRaffleId, raffleId);
lambdaQueryWrapper.eq(MtRaffleItem::getPrizeType, PrizeTypeEnum.NORMAL.getKey());
List<MtRaffleItem> raffleList = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
List<RaffleItemDto> resultList = new ArrayList<>();
String baseImage = settingService.getUploadBasePath();
for (MtRaffleItem mtRaffleItem:raffleList) {
RaffleItemDto dto = new RaffleItemDto();
BeanUtils.copyProperties(mtRaffleItem, dto);
dto.setImage(baseImage+mtRaffleItem.getImage());
resultList.add(dto);
}
return resultList;
}
}

View File

@ -0,0 +1,156 @@
package com.fuint.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.param.RaffleTypePage;
import com.fuint.common.service.RaffleTypeService;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.mapper.MtRaffleTypeMapper;
import com.fuint.repository.model.MtRaffleType;
import com.fuint.utils.StringUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* 抽奖类型服务实现类
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Service
public class RaffleTypeServiceImpl extends ServiceImpl<MtRaffleTypeMapper, MtRaffleType> implements RaffleTypeService {
private static final Logger logger = LoggerFactory.getLogger(RaffleTypeServiceImpl.class);
private MtRaffleTypeMapper mtRaffleTypeMapper;
public RaffleTypeServiceImpl(MtRaffleTypeMapper mtRaffleTypeMapper) {
this.mtRaffleTypeMapper = mtRaffleTypeMapper;
}
@Override
public PaginationResponse<MtRaffleType> queryRaffleTypeListByPagination(RaffleTypePage page) {
Page<MtRaffleType> pageHelper = PageHelper.startPage(page.getPage(), page.getPageSize());
LambdaQueryWrapper<MtRaffleType> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.ne(MtRaffleType::getStatus, StatusEnum.DISABLE.getKey());
if (StringUtil.isNotEmpty(page.getName())) {
lambdaQueryWrapper.like(MtRaffleType::getName, page.getName());
}
if (StringUtil.isNotEmpty(page.getCode())) {
lambdaQueryWrapper.like(MtRaffleType::getCode, page.getCode());
}
if (StringUtil.isNotEmpty(page.getStatus())) {
lambdaQueryWrapper.eq(MtRaffleType::getStatus, page.getStatus());
}
if (page.getMerchantId() != null && page.getMerchantId() > 0) {
lambdaQueryWrapper.eq(MtRaffleType::getMerchantId, page.getMerchantId());
}
if (page.getStoreId() != null) {
lambdaQueryWrapper.and(wq -> wq
.eq(MtRaffleType::getStoreId, 0)
.or()
.eq(MtRaffleType::getStoreId, page.getStoreId()));
}
lambdaQueryWrapper.orderByAsc(MtRaffleType::getSort);
List<MtRaffleType> dataList = mtRaffleTypeMapper.selectList(lambdaQueryWrapper);
PageRequest pageRequest = PageRequest.of(page.getPage(), page.getPageSize());
PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
PaginationResponse<MtRaffleType> paginationResponse = new PaginationResponse(pageImpl, MtRaffleType.class);
paginationResponse.setTotalPages(pageHelper.getPages());
paginationResponse.setTotalElements(pageHelper.getTotal());
paginationResponse.setContent(dataList);
return paginationResponse;
}
@Override
public MtRaffleType addRaffleType(MtRaffleType raffleType) throws BusinessCheckException {
if (raffleType.getMerchantId() == null || raffleType.getMerchantId() <= 0) {
throw new BusinessCheckException("新增抽奖类型失败:所属商户不能为空!");
}
if (StringUtil.isEmpty(raffleType.getName())) {
throw new BusinessCheckException("抽奖类型名称不能为空!");
}
if (StringUtil.isEmpty(raffleType.getCode())) {
throw new BusinessCheckException("抽奖类型编码不能为空!");
}
MtRaffleType entity = new MtRaffleType();
entity.setMerchantId(raffleType.getMerchantId());
entity.setStoreId(raffleType.getStoreId() == null ? 0 : raffleType.getStoreId());
entity.setName(raffleType.getName());
entity.setCode(raffleType.getCode());
entity.setDescription(raffleType.getDescription());
entity.setSort(raffleType.getSort() == null ? 0 : raffleType.getSort());
entity.setOperator(raffleType.getOperator());
entity.setStatus(StringUtil.isNotEmpty(raffleType.getStatus()) ? raffleType.getStatus() : StatusEnum.ENABLED.getKey());
entity.setCreateTime(new Date());
entity.setUpdateTime(new Date());
mtRaffleTypeMapper.insert(entity);
return entity;
}
@Override
public MtRaffleType getRaffleTypeById(Integer id) {
return mtRaffleTypeMapper.selectById(id);
}
@Override
public MtRaffleType updateRaffleType(MtRaffleType raffleType) throws BusinessCheckException {
MtRaffleType entity = getRaffleTypeById(raffleType.getId());
if (entity == null) {
throw new BusinessCheckException("抽奖类型不存在");
}
if (raffleType.getName() != null) {
entity.setName(raffleType.getName());
}
if (raffleType.getCode() != null) {
entity.setCode(raffleType.getCode());
}
if (raffleType.getStoreId() != null) {
entity.setStoreId(raffleType.getStoreId());
}
if (raffleType.getDescription() != null) {
entity.setDescription(raffleType.getDescription());
}
if (raffleType.getOperator() != null) {
entity.setOperator(raffleType.getOperator());
}
if (raffleType.getStatus() != null) {
entity.setStatus(raffleType.getStatus());
}
if (raffleType.getSort() != null) {
entity.setSort(raffleType.getSort());
}
entity.setUpdateTime(new Date());
mtRaffleTypeMapper.updateById(entity);
return entity;
}
@Override
public List<MtRaffleType> getAvailableRaffleType(Integer merchantId, Integer storeId) {
LambdaQueryWrapper<MtRaffleType> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleType::getStatus, StatusEnum.ENABLED.getKey());
if (merchantId != null && merchantId > 0) {
lambdaQueryWrapper.eq(MtRaffleType::getMerchantId, merchantId);
}
if (storeId != null && storeId > 0) {
lambdaQueryWrapper.and(wq -> wq.eq(MtRaffleType::getStoreId, 0).or().eq(MtRaffleType::getStoreId, storeId));
}
lambdaQueryWrapper.orderByAsc(MtRaffleType::getSort);
return mtRaffleTypeMapper.selectList(lambdaQueryWrapper);
}
}

View File

@ -0,0 +1,435 @@
package com.fuint.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.common.dto.TaskDto;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.param.TaskPage;
import com.fuint.common.service.PointService;
import com.fuint.common.service.StoreService;
import com.fuint.common.service.TaskService;
import com.fuint.common.util.DateUtil;
import com.fuint.framework.annoation.OperationServiceLog;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.mapper.MtPointMapper;
import com.fuint.repository.mapper.MtTaskMapper;
import com.fuint.repository.mapper.MtTaskRecordMapper;
import com.fuint.repository.model.MtPoint;
import com.fuint.repository.model.MtStore;
import com.fuint.repository.model.MtTask;
import com.fuint.repository.model.MtTaskRecord;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 任务中心服务实现
*
* Created by Codex
*/
@Service
@AllArgsConstructor(onConstructor_ = {@Lazy})
public class TaskServiceImpl extends ServiceImpl<MtTaskMapper, MtTask> implements TaskService {
private static final Logger logger = LoggerFactory.getLogger(TaskServiceImpl.class);
private MtTaskMapper mtTaskMapper;
private MtTaskRecordMapper mtTaskRecordMapper;
private MtPointMapper mtPointMapper;
private PointService pointService;
private StoreService storeService;
@Override
public PaginationResponse<MtTask> queryTaskListByPagination(TaskPage taskPage) {
Page<MtTask> pageHelper = PageHelper.startPage(taskPage.getPage(), taskPage.getPageSize());
LambdaQueryWrapper<MtTask> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.ne(MtTask::getStatus, StatusEnum.DISABLE.getKey());
if (StringUtils.isNotBlank(taskPage.getTaskName())) {
lambdaQueryWrapper.like(MtTask::getTaskName, taskPage.getTaskName());
}
if (StringUtils.isNotBlank(taskPage.getTaskType())) {
lambdaQueryWrapper.eq(MtTask::getTaskType, taskPage.getTaskType());
}
if (StringUtils.isNotBlank(taskPage.getStatus())) {
lambdaQueryWrapper.eq(MtTask::getStatus, taskPage.getStatus());
}
if (taskPage.getMerchantId() != null) {
lambdaQueryWrapper.eq(MtTask::getMerchantId, taskPage.getMerchantId());
}
if (taskPage.getStoreId() != null) {
lambdaQueryWrapper.eq(MtTask::getStoreId, taskPage.getStoreId());
}
lambdaQueryWrapper.orderByAsc(MtTask::getSort).orderByDesc(MtTask::getId);
List<MtTask> dataList = mtTaskMapper.selectList(lambdaQueryWrapper);
PageRequest pageRequest = PageRequest.of(taskPage.getPage(), taskPage.getPageSize());
PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
PaginationResponse<MtTask> paginationResponse = new PaginationResponse(pageImpl, MtTask.class);
paginationResponse.setTotalPages(pageHelper.getPages());
paginationResponse.setTotalElements(pageHelper.getTotal());
paginationResponse.setContent(dataList);
return paginationResponse;
}
@Override
@OperationServiceLog(description = "新增任务")
public MtTask addTask(TaskDto taskDto) throws BusinessCheckException {
MtTask mtTask = new MtTask();
BeanUtils.copyProperties(taskDto, mtTask);
Integer storeId = taskDto.getStoreId() == null ? 0 : taskDto.getStoreId();
if (taskDto.getMerchantId() == null || taskDto.getMerchantId() <= 0) {
MtStore mtStore = storeService.queryStoreById(storeId);
if (mtStore != null) {
mtTask.setMerchantId(mtStore.getMerchantId());
}
}
if (mtTask.getMerchantId() == null || mtTask.getMerchantId() <= 0) {
throw new BusinessCheckException("新增任务失败:所属商户不能为空!");
}
if (StringUtils.isBlank(mtTask.getTaskCode())) {
throw new BusinessCheckException("任务编码不能为空");
}
if (StringUtils.isBlank(mtTask.getTaskName())) {
throw new BusinessCheckException("任务名称不能为空");
}
LambdaQueryWrapper<MtTask> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MtTask::getMerchantId, mtTask.getMerchantId())
.eq(MtTask::getStoreId, storeId)
.eq(MtTask::getTaskCode, mtTask.getTaskCode())
.ne(MtTask::getStatus, StatusEnum.DISABLE.getKey());
if (mtTaskMapper.selectCount(wrapper) > 0) {
throw new BusinessCheckException("任务编码已存在,请更换后重试");
}
mtTask.setStoreId(storeId);
mtTask.setRewardPoint(mtTask.getRewardPoint() == null ? 0 : mtTask.getRewardPoint());
mtTask.setDailyLimit(mtTask.getDailyLimit() == null ? 1 : mtTask.getDailyLimit());
mtTask.setSort(mtTask.getSort() == null ? 0 : mtTask.getSort());
mtTask.setStatus(StringUtils.isBlank(mtTask.getStatus()) ? StatusEnum.ENABLED.getKey() : mtTask.getStatus());
mtTask.setCreateTime(new Date());
mtTask.setUpdateTime(new Date());
Integer id = mtTaskMapper.insert(mtTask);
if (id > 0) {
return mtTask;
}
logger.error("新增任务失败.");
throw new BusinessCheckException("抱歉,新增任务失败!");
}
@Override
public MtTask queryTaskById(Integer id) {
return mtTaskMapper.selectById(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
@OperationServiceLog(description = "更新任务")
public MtTask updateTask(TaskDto taskDto) throws BusinessCheckException {
MtTask mtTask = queryTaskById(taskDto.getId());
if (mtTask == null) {
throw new BusinessCheckException("该任务不存在");
}
Integer targetStoreId = taskDto.getStoreId() == null ? mtTask.getStoreId() : taskDto.getStoreId();
if (StringUtils.isNotBlank(taskDto.getTaskCode())) {
LambdaQueryWrapper<MtTask> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MtTask::getMerchantId, mtTask.getMerchantId())
.eq(MtTask::getStoreId, targetStoreId)
.eq(MtTask::getTaskCode, taskDto.getTaskCode())
.ne(MtTask::getStatus, StatusEnum.DISABLE.getKey())
.ne(MtTask::getId, mtTask.getId());
if (mtTaskMapper.selectCount(wrapper) > 0) {
throw new BusinessCheckException("任务编码已存在,请更换后重试");
}
mtTask.setTaskCode(taskDto.getTaskCode());
}
if (StringUtils.isNotBlank(taskDto.getTaskName())) {
mtTask.setTaskName(taskDto.getTaskName());
}
if (taskDto.getStoreId() != null) {
mtTask.setStoreId(targetStoreId);
}
if (StringUtils.isNotBlank(taskDto.getTaskType())) {
mtTask.setTaskType(taskDto.getTaskType());
}
if (taskDto.getTaskDesc() != null) {
mtTask.setTaskDesc(taskDto.getTaskDesc());
}
if (taskDto.getJumpUrl() != null) {
mtTask.setJumpUrl(taskDto.getJumpUrl());
}
if (taskDto.getRewardPoint() != null) {
mtTask.setRewardPoint(taskDto.getRewardPoint());
}
if (taskDto.getDailyLimit() != null) {
mtTask.setDailyLimit(taskDto.getDailyLimit());
}
if (taskDto.getSort() != null) {
mtTask.setSort(taskDto.getSort());
}
if (taskDto.getOperator() != null) {
mtTask.setOperator(taskDto.getOperator());
}
if (taskDto.getStatus() != null) {
mtTask.setStatus(taskDto.getStatus());
}
mtTask.setUpdateTime(new Date());
mtTaskMapper.updateById(mtTask);
return mtTask;
}
@Override
public List<MtTask> queryTaskListByParams(Map<String, Object> params) {
String status = params.get("status") == null ? StatusEnum.ENABLED.getKey() : params.get("status").toString();
String storeId = params.get("storeId") == null ? "" : params.get("storeId").toString();
String merchantId = params.get("merchantId") == null ? "" : params.get("merchantId").toString();
LambdaQueryWrapper<MtTask> lambdaQueryWrapper = Wrappers.lambdaQuery();
if (StringUtils.isNotBlank(status)) {
lambdaQueryWrapper.eq(MtTask::getStatus, status);
}
if (StringUtils.isNotBlank(merchantId)) {
lambdaQueryWrapper.eq(MtTask::getMerchantId, merchantId);
}
if (StringUtils.isNotBlank(storeId)) {
lambdaQueryWrapper.and(wq -> wq
.eq(MtTask::getStoreId, 0)
.or()
.eq(MtTask::getStoreId, storeId));
}
lambdaQueryWrapper.orderByAsc(MtTask::getSort).orderByDesc(MtTask::getId);
return mtTaskMapper.selectList(lambdaQueryWrapper);
}
@Override
public List<Map<String, Object>> queryClientTaskList(Integer merchantId, Integer storeId, Integer userId) {
Map<String, Object> params = new HashMap<>();
params.put("merchantId", merchantId);
params.put("storeId", storeId);
params.put("status", StatusEnum.ENABLED.getKey());
List<MtTask> taskList = this.queryTaskListByParams(params);
Map<Integer, MtTaskRecord> recordMap = new HashMap<>();
if (userId != null && userId > 0) {
String taskDate = DateUtil.getNow(DateUtil.PATTERN_ISO_DATE);
LambdaQueryWrapper<MtTaskRecord> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MtTaskRecord::getMerchantId, merchantId)
.eq(MtTaskRecord::getUserId, userId)
.eq(MtTaskRecord::getTaskDate, taskDate)
.eq(MtTaskRecord::getStatus, StatusEnum.ENABLED.getKey());
List<MtTaskRecord> recordList = mtTaskRecordMapper.selectList(wrapper);
for (MtTaskRecord record : recordList) {
recordMap.put(record.getTaskId(), record);
}
}
List<Map<String, Object>> result = new ArrayList<>();
for (MtTask task : taskList) {
MtTaskRecord record = recordMap.get(task.getId());
int completeNum = record == null || record.getCompleteNum() == null ? 0 : record.getCompleteNum();
int claimNum = record == null || record.getClaimNum() == null ? 0 : record.getClaimNum();
int dailyLimit = task.getDailyLimit() == null ? 1 : task.getDailyLimit();
int rewardPoint = task.getRewardPoint() == null ? 0 : task.getRewardPoint();
Map<String, Object> item = new HashMap<>();
item.put("id", task.getId());
item.put("taskCode", task.getTaskCode());
item.put("taskName", task.getTaskName());
item.put("taskType", task.getTaskType());
item.put("taskDesc", task.getTaskDesc());
item.put("jumpUrl", task.getJumpUrl());
item.put("rewardPoint", rewardPoint);
item.put("dailyLimit", dailyLimit);
item.put("sort", task.getSort());
item.put("completeNum", completeNum);
item.put("claimNum", claimNum);
item.put("canComplete", completeNum < dailyLimit);
item.put("canClaim", claimNum < completeNum);
item.put("finished", claimNum >= dailyLimit);
result.add(item);
}
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> completeTask(Integer merchantId, Integer storeId, Integer userId, Integer taskId, String operator) throws BusinessCheckException {
MtTask taskInfo = queryTaskByScope(merchantId, storeId, taskId);
if (taskInfo == null) {
throw new BusinessCheckException("任务不存在或已下线");
}
int dailyLimit = taskInfo.getDailyLimit() == null ? 1 : taskInfo.getDailyLimit();
String taskDate = DateUtil.getNow(DateUtil.PATTERN_ISO_DATE);
Date nowTime = new Date();
MtTaskRecord record = getOrCreateRecord(merchantId, storeId, userId, taskId, taskDate, operator, nowTime);
int effect = mtTaskRecordMapper.incrCompleteNum(record.getId(), dailyLimit, nowTime);
if (effect < 1) {
throw new BusinessCheckException("今日任务已达上限");
}
MtTaskRecord latest = mtTaskRecordMapper.selectById(record.getId());
return buildTaskProgress(taskInfo, latest);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> claimTask(Integer merchantId, Integer storeId, Integer userId, Integer taskId, String operator) throws BusinessCheckException {
MtTask taskInfo = queryTaskByScope(merchantId, storeId, taskId);
if (taskInfo == null) {
throw new BusinessCheckException("任务不存在或已下线");
}
int dailyLimit = taskInfo.getDailyLimit() == null ? 1 : taskInfo.getDailyLimit();
int rewardPoint = taskInfo.getRewardPoint() == null ? 0 : taskInfo.getRewardPoint();
if (rewardPoint <= 0) {
throw new BusinessCheckException("该任务未配置奖励积分");
}
String taskDate = DateUtil.getNow(DateUtil.PATTERN_ISO_DATE);
Date nowTime = new Date();
MtTaskRecord record = getOrCreateRecord(merchantId, storeId, userId, taskId, taskDate, operator, nowTime);
int completeNum = record.getCompleteNum() == null ? 0 : record.getCompleteNum();
int claimNum = record.getClaimNum() == null ? 0 : record.getClaimNum();
if (claimNum >= dailyLimit) {
throw new BusinessCheckException("今日奖励已领取完");
}
if (claimNum >= completeNum) {
throw new BusinessCheckException("请先完成任务后再领取");
}
int nextClaimNum = claimNum + 1;
String orderSn = buildOrderSn(taskId, userId, taskDate, nextClaimNum);
LambdaQueryWrapper<MtPoint> pointWrapper = Wrappers.lambdaQuery();
pointWrapper.eq(MtPoint::getUserId, userId)
.eq(MtPoint::getOrderSn, orderSn)
.eq(MtPoint::getStatus, StatusEnum.ENABLED.getKey());
MtPoint existed = mtPointMapper.selectOne(pointWrapper);
if (existed != null) {
if (claimNum < nextClaimNum) {
mtTaskRecordMapper.incrClaimNumIfMatch(record.getId(), claimNum, nowTime);
record = mtTaskRecordMapper.selectById(record.getId());
}
return buildTaskProgress(taskInfo, record);
}
int effect = mtTaskRecordMapper.incrClaimNumIfMatch(record.getId(), claimNum, nowTime);
if (effect < 1) {
MtTaskRecord latest = mtTaskRecordMapper.selectById(record.getId());
int latestClaimNum = latest.getClaimNum() == null ? 0 : latest.getClaimNum();
if (latestClaimNum >= nextClaimNum) {
return buildTaskProgress(taskInfo, latest);
}
throw new BusinessCheckException("领取过于频繁,请稍后重试");
}
// 幂等发积分:同任务同日期同轮次固定 orderSn只会发一次
pointWrapper = Wrappers.lambdaQuery();
pointWrapper.eq(MtPoint::getUserId, userId)
.eq(MtPoint::getOrderSn, orderSn)
.eq(MtPoint::getStatus, StatusEnum.ENABLED.getKey());
existed = mtPointMapper.selectOne(pointWrapper);
if (existed == null) {
MtPoint reqPointDto = new MtPoint();
reqPointDto.setUserId(userId);
reqPointDto.setOrderSn(orderSn);
reqPointDto.setAmount(rewardPoint);
reqPointDto.setDescription("任务奖励:" + taskInfo.getTaskName() + " +" + rewardPoint + "积分");
reqPointDto.setOperator(operator);
pointService.addPoint(reqPointDto);
}
MtTaskRecord latest = mtTaskRecordMapper.selectById(record.getId());
return buildTaskProgress(taskInfo, latest);
}
private MtTask queryTaskByScope(Integer merchantId, Integer storeId, Integer taskId) {
LambdaQueryWrapper<MtTask> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MtTask::getId, taskId)
.eq(MtTask::getMerchantId, merchantId)
.eq(MtTask::getStatus, StatusEnum.ENABLED.getKey());
if (storeId != null && storeId > 0) {
wrapper.and(wq -> wq.eq(MtTask::getStoreId, 0).or().eq(MtTask::getStoreId, storeId));
}
return mtTaskMapper.selectOne(wrapper);
}
private MtTaskRecord getOrCreateRecord(Integer merchantId, Integer storeId, Integer userId, Integer taskId, String taskDate, String operator, Date nowTime) {
LambdaQueryWrapper<MtTaskRecord> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MtTaskRecord::getMerchantId, merchantId)
.eq(MtTaskRecord::getTaskId, taskId)
.eq(MtTaskRecord::getUserId, userId)
.eq(MtTaskRecord::getTaskDate, taskDate)
.eq(MtTaskRecord::getStatus, StatusEnum.ENABLED.getKey());
MtTaskRecord record = mtTaskRecordMapper.selectOne(wrapper);
if (record != null) {
return record;
}
MtTaskRecord insertItem = new MtTaskRecord();
insertItem.setMerchantId(merchantId);
insertItem.setStoreId(storeId == null ? 0 : storeId);
insertItem.setTaskId(taskId);
insertItem.setUserId(userId);
insertItem.setTaskDate(taskDate);
insertItem.setCompleteNum(0);
insertItem.setClaimNum(0);
insertItem.setCreateTime(nowTime);
insertItem.setUpdateTime(nowTime);
insertItem.setOperator(operator);
insertItem.setStatus(StatusEnum.ENABLED.getKey());
try {
mtTaskRecordMapper.insert(insertItem);
return insertItem;
} catch (Exception e) {
// 并发下可能已创建,回查最新记录
return mtTaskRecordMapper.selectOne(wrapper);
}
}
private String buildOrderSn(Integer taskId, Integer userId, String taskDate, Integer seq) {
return "TASK-" + taskId + "-" + userId + "-" + taskDate.replace("-", "") + "-" + seq;
}
private Map<String, Object> buildTaskProgress(MtTask taskInfo, MtTaskRecord record) {
int completeNum = record == null || record.getCompleteNum() == null ? 0 : record.getCompleteNum();
int claimNum = record == null || record.getClaimNum() == null ? 0 : record.getClaimNum();
int dailyLimit = taskInfo.getDailyLimit() == null ? 1 : taskInfo.getDailyLimit();
Map<String, Object> result = new HashMap<>();
result.put("taskId", taskInfo.getId());
result.put("completeNum", completeNum);
result.put("claimNum", claimNum);
result.put("dailyLimit", dailyLimit);
result.put("canComplete", completeNum < dailyLimit);
result.put("canClaim", claimNum < completeNum);
result.put("finished", claimNum >= dailyLimit);
return result;
}
}

View File

@ -0,0 +1,315 @@
package com.fuint.module.backendApi.controller;
import com.alibaba.fastjson.JSONArray;
import com.fuint.common.Constants;
import com.fuint.common.dto.*;
import com.fuint.common.enums.*;
import com.fuint.common.param.RechargeParam;
import com.fuint.common.service.*;
import com.fuint.common.util.CommonUtil;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.*;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
/**
* 积分管理controller
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Api(tags="管理端-积分相关接口")
@RestController
@RequestMapping(value = "/backendApi/raffle")
public class BackendRaffleController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(BackendRaffleController.class);
/**
* 积分服务接口
* */
@Autowired
private RaffleService raffleService;
/**
* 系统设置服务接口
* */
@Autowired
private SettingService settingService;
/**
* 积分明细列表查询
*
* @param request HttpServletRequest对象
* @return 积分明细列表
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
String status = request.getParameter("status") == null ? StatusEnum.ENABLED.getKey() : request.getParameter("status");
String title = request.getParameter("title") == null ? "" : request.getParameter("title");
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
PaginationRequest paginationRequest = new PaginationRequest();
paginationRequest.setCurrentPage(page);
paginationRequest.setPageSize(pageSize);
Map<String, Object> searchParams = new HashMap<>();
if (StringUtil.isNotEmpty(status)) {
searchParams.put("status", status);
}
if (StringUtil.isNotEmpty(title)) {
searchParams.put("title", title);
}
paginationRequest.setSearchParams(searchParams);
PaginationResponse<RaffleDto> paginationResponse = raffleService.queryListByPagination(paginationRequest);
Map<String, Object> result = new HashMap<>();
result.put("dataList", paginationResponse);
String imagePath = settingService.getUploadBasePath();
result.put("imagePath", imagePath);
return getSuccessResult(result);
}
/**
* 提交保存
*
* @param request HttpServletRequest对象
* @return
*/
@RequestMapping(value = "/save", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject saveRaffleHandler(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
String title = param.get("title") == null ? "" : param.get("title").toString();
String brief = param.get("brief") == null ? "" : param.get("brief").toString();
String status = param.get("status") == null ? "A" : param.get("status").toString();
String image = param.get("image") == null ? "" : param.get("image").toString();
String description = param.get("description") == null ? "A" : param.get("description").toString();
Integer rafflePoint = param.get("rafflePoint") == null ? 0 : Integer.parseInt(param.get("rafflePoint").toString());
List<LinkedHashMap> rafList = param.get("rafData") == null ? new ArrayList<>() : (List) param.get("rafData");
String extraImage = param.get("extraImage") == null ? "" : param.get("extraImage").toString();
String extraType = param.get("extraType") == null ? "L" : param.get("extraType").toString();
String extraPrize = param.get("extraPrize") == null ? "" : param.get("extraPrize").toString();
Integer forwardPoint = 0;
if (StringUtil.isEmpty(param.get("forwardPoint").toString())) {
forwardPoint = Integer.parseInt(param.get("forwardPoint").toString());
}
String raffleType = param.get("raffleType") == null ? "pokemon" : param.get("raffleType").toString();
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
logger.info(JSONArray.toJSONString(param));
MtRaffle dto = new MtRaffle();
dto.setRaffleType(raffleType);
dto.setTitle(title);
dto.setBrief(brief);
dto.setStatus(status);
dto.setImage(image);
dto.setDescription(description);
dto.setRafflePoint(rafflePoint);
dto.setOperator(accountInfo.getAccountName());
dto.setCreateTime(new Date());
dto.setExtraImage(extraImage);
dto.setExtraType(extraType);
dto.setExtraPrize(extraPrize);
dto.setForwardPoint(forwardPoint);
raffleService.addRaffle(dto);
int allCnt = 0;
if (rafList.size() > 0) {
for (LinkedHashMap item: rafList) {
Integer num = Integer.parseInt(item.get("num").toString());
String raffleTitle = item.get("title") == null ? "" : item.get("title").toString();
String prize = item.get("prize") == null ? "" : item.get("prize").toString();
Integer point = item.get("point") == null ? 0 : Integer.parseInt(item.get("point").toString());
String raffleImage = item.get("image") == null ? "" : item.get("image").toString();
allCnt = allCnt + num;
for (int i = 0; i < num; i++) {
MtRaffleItem raffleItem = new MtRaffleItem();
raffleItem.setRaffleId(dto.getId());
raffleItem.setPrize(prize);
raffleItem.setTitle(raffleTitle);
raffleItem.setPoint(point);
raffleItem.setImage(raffleImage);
raffleItem.setOperator(accountInfo.getAccountName());
raffleItem.setPrizeType(PrizeTypeEnum.NORMAL.getKey());
raffleService.addRaffleItem(raffleItem);
}
}
}
dto.setNowCnt(0);
dto.setAllCnt(allCnt);
raffleService.updRaffle(dto);
return getSuccessResult(true);
}
/**
* 抽奖明细
*
* @param request HttpServletRequest对象
* @return
*/
@RequestMapping(value = "/detail", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject detailRaffleHandler(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
String raffleId = request.getParameter("raffleId") == null ? "" : request.getParameter("raffleId");
String userId = request.getParameter("userId") == null ? "" : request.getParameter("userId");
String win = request.getParameter("win") == null ? "" : request.getParameter("win");
String deal = request.getParameter("deal") == null ? "" : request.getParameter("deal");
String userNo = request.getParameter("userNo") == null ? "" : request.getParameter("userNo");
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
RaffleItemDto raffleItemDto = new RaffleItemDto();
if (StringUtil.isNotEmpty(raffleId)) {
raffleItemDto.setRaffleId(Integer.parseInt(raffleId));
}
if (StringUtil.isNotEmpty(userId)) {
raffleItemDto.setUserId(Integer.parseInt(userId));
}
if (StringUtil.isNotEmpty(win)) {
raffleItemDto.setWin(Integer.parseInt(win));
}
if (StringUtil.isNotEmpty(deal)) {
raffleItemDto.setDeal(Integer.parseInt(deal));
}
if (StringUtil.isNotEmpty(userNo)) {
raffleItemDto.setUserNo(userNo);
}
logger.info("raffle detail condition: " + JSONArray.toJSONString(raffleItemDto));
List<MtRaffleItem> raffleList = raffleService.queryRaffleItemByRaffleId(raffleItemDto);
Map<String, Object> result = new HashMap<>();
result.put("rafList", raffleList);
String imagePath = settingService.getUploadBasePath();
result.put("imagePath", imagePath);
return getSuccessResult(result);
}
/**
* 抽奖基础信息
*
* @param request HttpServletRequest对象
* @return
*/
@RequestMapping(value = "/info", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject info(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
MtRaffle raffle = raffleService.queryRaffle(id);
if (raffle == null) {
return getFailureResult(201, "抽奖不存在");
}
Map<String, Object> result = new HashMap<>();
result.put("dataList", raffle);
String imagePath = settingService.getUploadBasePath();
result.put("imagePath", imagePath);
return getSuccessResult(result);
}
@RequestMapping(value = "/deal", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject deal(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
logger.info("deal id: " + id);
raffleService.dealRaffleItem(id, accountInfo.getAccountName());
Map<String, Object> result = new HashMap<>();
result.put("deal", "succ");
return getSuccessResult(result);
}
/**
* 更新会员状态
*
* @return
*/
@RequestMapping(value = "/change", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject updateStatus(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id").toString());
String status = request.getParameter("status") == null ? StatusEnum.ENABLED.getKey() : request.getParameter("status").toString();
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
logger.info("changeStatus id="+id + " status=" + status);
MtRaffle raffle = raffleService.queryRaffle(id);
if (raffle == null) {
return getFailureResult(201, "抽奖不存在");
}
MtRaffle updraffle = new MtRaffle();
updraffle.setId(id);
updraffle.setStatus(status);
updraffle.setOperator(accountInfo.getAccountName());
updraffle.setUpdateTime(new Date());
raffleService.updRaffle(updraffle);
return getSuccessResult(true);
}
}

View File

@ -0,0 +1,145 @@
package com.fuint.module.backendApi.controller;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.RaffleTypeDto;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.param.RaffleTypePage;
import com.fuint.common.service.RaffleTypeService;
import com.fuint.common.service.StoreService;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtRaffleType;
import com.fuint.repository.model.MtStore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 抽奖类型管理类controller
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Api(tags="管理端-抽奖类型相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/backendApi/raffleType")
public class BackendRaffleTypeController extends BaseController {
/**
* 抽奖类型服务接口
*/
private RaffleTypeService raffleTypeService;
/**
* 店铺服务接口
*/
private StoreService storeService;
/**
* 抽奖类型列表查询
*/
@ApiOperation(value = "抽奖类型列表查询")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject list(@ModelAttribute RaffleTypePage page) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
page.setMerchantId(accountInfo.getMerchantId());
}
if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
page.setStoreId(accountInfo.getStoreId());
}
PaginationResponse<MtRaffleType> paginationResponse = raffleTypeService.queryRaffleTypeListByPagination(page);
List<MtStore> storeList = storeService.getMyStoreList(accountInfo.getMerchantId(), accountInfo.getStoreId(), StatusEnum.ENABLED.getKey());
Map<String, Object> result = new HashMap<>();
result.put("dataList", paginationResponse);
result.put("storeList", storeList);
return getSuccessResult(result);
}
/**
* 更新抽奖类型状态
*/
@ApiOperation(value = "更新抽奖类型状态")
@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject updateStatus(@RequestBody Map<String, Object> params) throws BusinessCheckException {
String status = params.get("status") != null ? params.get("status").toString() : StatusEnum.ENABLED.getKey();
Integer typeId = params.get("typeId") == null ? 0 : Integer.parseInt(params.get("typeId").toString());
AccountInfo accountInfo = TokenUtil.getAccountInfo();
MtRaffleType raffleType = raffleTypeService.getRaffleTypeById(typeId);
if (raffleType == null) {
return getFailureResult(201);
}
raffleType.setOperator(accountInfo.getAccountName());
raffleType.setStatus(status);
raffleTypeService.updateRaffleType(raffleType);
return getSuccessResult(true);
}
/**
* 保存抽奖类型
*/
@ApiOperation(value = "保存抽奖类型")
@RequestMapping(value = "/save", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject saveHandler(@RequestBody RaffleTypeDto raffleTypeDto) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
if (accountInfo.getMerchantId() == null || accountInfo.getMerchantId() < 1) {
return getFailureResult(5002);
}
MtRaffleType raffleType = new MtRaffleType();
BeanUtils.copyProperties(raffleTypeDto, raffleType);
raffleType.setOperator(accountInfo.getAccountName());
raffleType.setMerchantId(accountInfo.getMerchantId());
if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
raffleType.setStoreId(accountInfo.getStoreId());
}
if (raffleTypeDto.getId() != null && raffleTypeDto.getId() > 0) {
raffleTypeService.updateRaffleType(raffleType);
} else {
raffleTypeService.addRaffleType(raffleType);
}
return getSuccessResult(true);
}
/**
* 获取抽奖类型详情
*/
@ApiOperation(value = "获取抽奖类型详情")
@RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject info(@PathVariable("id") Integer id) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
MtRaffleType raffleType = raffleTypeService.getRaffleTypeById(id);
if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
if (raffleType != null && !raffleType.getMerchantId().equals(accountInfo.getMerchantId())) {
return getFailureResult(1004);
}
}
Map<String, Object> result = new HashMap<>();
result.put("raffleTypeInfo", raffleType);
return getSuccessResult(result);
}
}

View File

@ -0,0 +1,128 @@
package com.fuint.module.backendApi.controller;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.TaskDto;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.param.TaskPage;
import com.fuint.common.service.StoreService;
import com.fuint.common.service.TaskService;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtStore;
import com.fuint.repository.model.MtTask;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 任务中心管理 controller
*
* Created by Codex
*/
@Api(tags = "管理端-任务中心相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/backendApi/task")
public class BackendTaskController extends BaseController {
private TaskService taskService;
private StoreService storeService;
@ApiOperation(value = "任务列表查询")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@CrossOrigin
@PreAuthorize("@pms.hasPermission('content:task:index')")
public ResponseObject list(@ModelAttribute TaskPage taskPage) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
taskPage.setMerchantId(accountInfo.getMerchantId());
}
if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
taskPage.setStoreId(accountInfo.getStoreId());
}
PaginationResponse<MtTask> paginationResponse = taskService.queryTaskListByPagination(taskPage);
List<MtStore> storeList = storeService.getMyStoreList(accountInfo.getMerchantId(), accountInfo.getStoreId(), StatusEnum.ENABLED.getKey());
Map<String, Object> result = new HashMap<>();
result.put("dataList", paginationResponse);
result.put("storeList", storeList);
return getSuccessResult(result);
}
@ApiOperation(value = "获取任务详情")
@RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
@CrossOrigin
@PreAuthorize("@pms.hasPermission('content:task:index')")
public ResponseObject info(@PathVariable("id") Integer id) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
MtTask taskInfo = taskService.queryTaskById(id);
if (taskInfo == null) {
return getFailureResult(201);
}
if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0
&& !taskInfo.getMerchantId().equals(accountInfo.getMerchantId())) {
return getFailureResult(1004);
}
Map<String, Object> result = new HashMap<>();
result.put("taskInfo", taskInfo);
return getSuccessResult(result);
}
@ApiOperation(value = "保存任务")
@RequestMapping(value = "/save", method = RequestMethod.POST)
@CrossOrigin
@PreAuthorize("@pms.hasPermission('content:task:add') or @pms.hasPermission('content:task:edit')")
public ResponseObject saveHandler(@RequestBody TaskDto taskDto) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
taskDto.setOperator(accountInfo.getAccountName());
if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
taskDto.setMerchantId(accountInfo.getMerchantId());
}
if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
taskDto.setStoreId(accountInfo.getStoreId());
}
if (taskDto.getId() != null && taskDto.getId() > 0) {
taskService.updateTask(taskDto);
} else {
taskService.addTask(taskDto);
}
return getSuccessResult(true);
}
@ApiOperation(value = "更新任务状态")
@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
@CrossOrigin
@PreAuthorize("@pms.hasPermission('content:task:edit')")
public ResponseObject updateStatus(@RequestBody Map<String, Object> params) throws BusinessCheckException {
String status = params.get("status") != null ? params.get("status").toString() : StatusEnum.ENABLED.getKey();
Integer id = params.get("id") == null ? 0 : Integer.parseInt(params.get("id").toString());
AccountInfo accountInfo = TokenUtil.getAccountInfo();
MtTask taskInfo = taskService.queryTaskById(id);
if (taskInfo == null) {
return getFailureResult(201);
}
TaskDto taskDto = new TaskDto();
taskDto.setId(id);
taskDto.setOperator(accountInfo.getAccountName());
taskDto.setStatus(status);
taskService.updateTask(taskDto);
return getSuccessResult(true);
}
}

View File

@ -0,0 +1,162 @@
package com.fuint.module.clientApi.controller;
import com.fuint.common.Constants;
import com.fuint.common.dto.PointDto;
import com.fuint.common.dto.UserInfo;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.service.GrowService;
import com.fuint.common.service.PointService;
import com.fuint.common.util.DateUtil;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtGrow;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 积分相关controller
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Api(tags="会员端-增长相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/clientApi/grow")
public class ClientGrowController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ClientGrowController.class);
/**
* 服务接口
*/
private GrowService growService;
/**
* 查询我的积分明细
*
* @param request Request对象
*/
@ApiOperation(value = "查询我的签到")
@RequestMapping(value = "/sign", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject sign(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
};
MtGrow signInfo = growService.querySignInfo(mtUser.getId());
Map<String, Object> result = new HashMap<>();
result.put("growId",signInfo.getId());
if (signInfo.getSignTime() == null) {
result.put("isSign",false);
} else {
BigDecimal diff = DateUtil.getDiffDays(signInfo.getSignTime(), new Date());
if (diff.intValue() == 0) {
result.put("isSign",true);
} else {
result.put("isSign",false);
}
}
if (signInfo.getAdvNum() == null) {
result.put("advNum", 0);
} else {
result.put("advNum", signInfo.getAdvNum());
}
result.put("advTotal",signInfo.getAdvTotal());
result.put("growTotal",signInfo.getGrowTotal());
result.put("growDisp",true);
return getSuccessResult(result);
}
/**
* 签到
*
*/
@ApiOperation(value = "签到")
@RequestMapping(value = "/doSign", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject doSign(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
Integer growId = request.getParameter("growId") == null ? 0:Integer.parseInt(request.getParameter("growId"));
logger.info("dosign growid: " + growId);
try {
growService.doSign(growId);
return getSuccessResult(true);
} catch (BusinessCheckException e) {
return getFailureResult(3008, "失败");
}
}
/**
* 点击广告
*
*/
@ApiOperation(value = "点击广告")
@RequestMapping(value = "/doAdv", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject doAdv(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
Integer growId = request.getParameter("growId") == null ? 0:Integer.parseInt(request.getParameter("growId"));
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
logger.info("doAdv growid: " + growId);
try {
growService.doAdv(growId);
return getSuccessResult(true);
} catch (BusinessCheckException e) {
return getFailureResult(3008, "失败");
}
}
}

View File

@ -0,0 +1,446 @@
package com.fuint.module.clientApi.controller;
import com.alibaba.fastjson.JSONArray;
import com.fuint.common.dto.OrderDto;
import com.fuint.common.dto.RaffleDto;
import com.fuint.common.dto.RaffleItemDto;
import com.fuint.common.dto.UserInfo;
import com.fuint.common.enums.OrderStatusEnum;
import com.fuint.common.enums.PayStatusEnum;
import com.fuint.common.enums.PayTypeEnum;
import com.fuint.common.enums.YesOrNoEnum;
import com.fuint.common.param.RaffleParam;
import com.fuint.common.param.RechargeParam;
import com.fuint.common.service.MemberService;
import com.fuint.common.service.OrderService;
import com.fuint.common.service.PaymentService;
import com.fuint.common.service.RaffleService;
import com.fuint.common.util.CommonUtil;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtOrder;
import com.fuint.repository.model.MtRaffle;
import com.fuint.repository.model.MtRaffleItem;
import com.fuint.repository.model.MtUser;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 抽奖相关controller
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Api(tags="会员端-抽奖相关接口")
@RestController
@RequestMapping(value = "/clientApi/raffle")
public class ClientRaffleController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ClientRaffleController.class);
/**
* 抽奖服务接口
*/
@Autowired
private RaffleService raffleService;
/**
* 订单服务接口
* */
@Autowired
private OrderService orderService;
/**
* 会员服务接口
*/
@Autowired
private MemberService memberService;
/**
* 支付服务接口
* */
@Autowired
private PaymentService paymentService;
/**
* 查询我的积分明细
*
* @param request Request对象
*/
@ApiOperation(value = "抽奖列表")
@RequestMapping(value = "/list", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject list(HttpServletRequest request, @RequestBody RaffleParam raffleParam) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
logger.info("微信一番赏一览数据:" + JSONArray.toJSONString(raffleParam));
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
ResponseObject rafList = raffleService.findRaffleList(raffleParam);
return getSuccessResult(rafList.getData());
}
/**
* 最新抽奖
*/
@ApiOperation(value = "最新抽奖")
@RequestMapping(value = "/latest", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject latest(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
List<RaffleDto> list = raffleService.getLatestRaffles(5);
return getSuccessResult(list);
}
/**
* 最新中奖
*/
@ApiOperation(value = "最新中奖")
@RequestMapping(value = "/latestWins", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject latestWins(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
List<RaffleItemDto> list = raffleService.getLatestWinItems(20);
return getSuccessResult(list);
}
/**
* 抽奖详情
*
* @param request Request对象
*/
@ApiOperation(value = "抽奖详情")
@RequestMapping(value = "/detail", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject detailRaffle(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
Integer raffleId = request.getParameter("raffleId") == null ? 0:Integer.parseInt(request.getParameter("raffleId"));
try {
Map<String, Object> result = new HashMap<>();
List<RaffleItemDto> detail = raffleService.queryRaffleItemByRaffleId2wechat(raffleId);
result.put("detail", detail);
MtRaffle raffle = raffleService.queryRaffle(raffleId);
MtRaffle updClick = new MtRaffle();
updClick.setId(raffle.getId());
if (raffle.getClick() == null) {
updClick.setClick(1);
} else {
updClick.setClick(raffle.getClick() + 1);
}
updClick.setUpdateTime(raffle.getUpdateTime());
raffleService.updRaffle(updClick);
result.put("raffle", raffle);
Integer point = raffleService.userPoint(mtUser.getId());
result.put("point", point);
result.put("userId", mtUser.getId());
return getSuccessResult(result);
} catch (BusinessCheckException e) {
return getFailureResult(3008, e.getMessage());
}
}
/**
* 抽一发
*
* @param request Request对象
*/
@ApiOperation(value = "抽一发")
@RequestMapping(value = "/doRaffle", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject doRaffle(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
Integer raffleId = request.getParameter("raffleId") == null ? 0:Integer.parseInt(request.getParameter("raffleId"));
Integer num = request.getParameter("num") == null ? 0:Integer.parseInt(request.getParameter("num"));
logger.info("抽一抽:"+raffleId+""+ num+"");
Integer forwardUserId = 0;
try {
forwardUserId = Integer.parseInt(request.getParameter("forwardUserId"));
} catch (NumberFormatException ne) {
logger.info("抽一抽 forwardUserId"+forwardUserId);
}
logger.info("抽一抽转发人:"+forwardUserId);
try {
List<MtRaffleItem> item = raffleService.doRaffleByRaffleId(raffleId, num, mtUser, forwardUserId);
Map<String, Object> result = new HashMap<>();
result.put("stat", "yes");
result.put("item", item);
return getSuccessResult(result);
} catch (BusinessCheckException e) {
return getFailureResult(3008, e.getMessage());
}
}
/**
* 排队
*
* @param request Request对象
*/
@ApiOperation(value = "排队")
@RequestMapping(value = "/doQueue", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject doQueue(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
Integer raffleId = request.getParameter("raffleId") == null ? 0:Integer.parseInt(request.getParameter("raffleId"));
try {
MtRaffle raffle = raffleService.queryRaffle(raffleId);
long diff = 1000;
if (raffle.getUserTime() != null) {
long userTIme = raffle.getUserTime().getTime();
long now = new Date().getTime();
diff = (now - userTIme)/1000;
}
logger.info("diff " + diff);
Map<String, String> result = new HashMap<>();
if (diff <= 60) {
result.put("stat", "no");
result.put("time", String.valueOf(60-diff));
return getSuccessResult(result);
}
MtRaffle newRaffle = new MtRaffle();
newRaffle.setId(raffleId);
newRaffle.setUserId(mtUser.getId());
newRaffle.setUserTime(new Date());
raffleService.updRaffle(newRaffle);
result.put("stat", "yes");
result.put("time", "60");
return getSuccessResult(result);
} catch (BusinessCheckException e) {
return getFailureResult(3008, e.getMessage());
}
}
/**
* 背包
*
* @param request Request对象
*/
@ApiOperation(value = "背包")
@RequestMapping(value = "/findBag", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject findBag(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
try {
List<RaffleItemDto> items = raffleService.queryRaffleItemByUserId(mtUser.getId());
MtUser member = memberService.queryMemberById(mtUser.getId());
Map<String,Object> result = new HashMap<>();
result.put("item", items);
result.put("member", member);
return getSuccessResult(items);
} catch (BusinessCheckException e) {
return getFailureResult(3008, e.getMessage());
}
}
/**
* 转化积分
*
* @param request Request对象
*/
@ApiOperation(value = "转化积分")
@RequestMapping(value = "/sellPoint", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject sellPoint(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
Integer raffleItemId = request.getParameter("raffleItemId") == null ? 0:Integer.parseInt(request.getParameter("raffleItemId"));
try {
boolean result = raffleService.tranfer2Point(raffleItemId,mtUser.getId());
return getSuccessResult(result);
} catch (BusinessCheckException e) {
return getFailureResult(3008, e.getMessage());
}
}
/**
* 充值积分
* */
@RequestMapping(value = "/doCharge", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject doCharge(HttpServletRequest request, @RequestBody RechargeParam rechargeParam) throws BusinessCheckException {
Integer storeId = request.getHeader("storeId") == null ? 0 : Integer.parseInt(request.getHeader("storeId"));
String platform = request.getHeader("platform") == null ? "" : request.getHeader("platform");
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo userInfo = TokenUtil.getUserInfoByToken(token);
if (null == userInfo) {
return getFailureResult(1001);
}
String rechargeAmount = rechargeParam.getRechargeAmount() == null ? "" : rechargeParam.getRechargeAmount();
String customAmount = rechargeParam.getCustomAmount() == null ? "" : rechargeParam.getCustomAmount();
if (StringUtil.isEmpty(rechargeAmount) && StringUtil.isEmpty(customAmount)) {
return getFailureResult(2000, "请确认充值金额");
}
logger.info("rechargeAmount: " + rechargeAmount);
logger.info("customAmount: " + customAmount);
String ruleParam = "";
// 自定义充值没有赠送金额
if (StringUtil.isEmpty(rechargeAmount)) {
ruleParam = customAmount + "_0";
}
BigDecimal amount = new BigDecimal(customAmount);
logger.info("amount: " + amount);
OrderDto orderDto = new OrderDto();
orderDto.setType("pointChange");
orderDto.setUserId(userInfo.getId());
orderDto.setStoreId(storeId);
orderDto.setAmount(amount);
orderDto.setUsePoint(0);
orderDto.setRemark("积分充值");
orderDto.setParam(ruleParam);
orderDto.setStatus(OrderStatusEnum.CREATED.getKey());
orderDto.setPayStatus(PayStatusEnum.WAIT.getKey());
orderDto.setPointAmount(new BigDecimal("0"));
orderDto.setOrderMode("");
orderDto.setCouponId(0);
orderDto.setPlatform(platform);
MtOrder orderInfo = orderService.saveOrder(orderDto);
MtUser mtUser = memberService.queryMemberById(userInfo.getId());
String ip = CommonUtil.getIPFromHttpRequest(request);
BigDecimal pay = amount.multiply(new BigDecimal("100"));
orderInfo.setPayType(PayTypeEnum.JSAPI.getKey());
ResponseObject paymentInfo = paymentService.createPrepayOrder(mtUser, orderInfo, (pay.intValue()), "", 0, ip, platform, YesOrNoEnum.YES.getKey());
if (paymentInfo.getData() == null) {
return getFailureResult(201, "抱歉,发起支付失败");
}
Object payment = paymentInfo.getData();
Map<String, Object> data = new HashMap();
data.put("payment", payment);
data.put("orderInfo", orderInfo);
return getSuccessResult(data);
}
}

View File

@ -0,0 +1,65 @@
package com.fuint.module.clientApi.controller;
import com.fuint.common.service.MerchantService;
import com.fuint.common.service.RaffleTypeService;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtRaffleType;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 抽奖类型controller
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Api(tags="会员端-抽奖类型相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/clientApi/raffleType")
public class ClientRaffleTypeController extends BaseController {
/**
* 抽奖类型服务接口
*/
private RaffleTypeService raffleTypeService;
/**
* 商户服务接口
*/
private MerchantService merchantService;
/**
* 抽奖类型列表
*/
@ApiOperation(value = "抽奖类型列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
Integer storeId = StringUtil.isEmpty(request.getHeader("storeId")) ? 0 : Integer.parseInt(request.getHeader("storeId"));
Integer merchantId = 0;
if (StringUtil.isNotEmpty(merchantNo)) {
merchantId = merchantService.getMerchantId(merchantNo);
}
List<MtRaffleType> typeList = raffleTypeService.getAvailableRaffleType(merchantId, storeId);
Map<String, Object> result = new HashMap<>();
result.put("typeList", typeList);
return getSuccessResult(result);
}
}

View File

@ -0,0 +1,113 @@
package com.fuint.module.clientApi.controller;
import com.fuint.common.dto.UserInfo;
import com.fuint.common.service.MerchantService;
import com.fuint.common.service.TaskService;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 任务中心接口 controller
*
* Created by Codex
*/
@Api(tags = "会员端-任务中心相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/clientApi/task")
public class ClientTaskController extends BaseController {
private TaskService taskService;
private MerchantService merchantService;
@ApiOperation(value = "任务列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
Integer storeId = StringUtil.isEmpty(request.getHeader("storeId")) ? 0 : Integer.parseInt(request.getHeader("storeId"));
UserInfo userInfo = TokenUtil.getUserInfo();
Integer userId = userInfo == null ? 0 : userInfo.getId();
Integer merchantId = merchantService.getMerchantId(merchantNo);
if (merchantId <= 0) {
return getFailureResult(201, "商户信息异常");
}
List<Map<String, Object>> taskList = taskService.queryClientTaskList(merchantId, storeId, userId);
int totalDailyPoints = 0;
for (Map<String, Object> task : taskList) {
int rewardPoint = task.get("rewardPoint") == null ? 0 : Integer.parseInt(task.get("rewardPoint").toString());
int dailyLimit = task.get("dailyLimit") == null ? 1 : Integer.parseInt(task.get("dailyLimit").toString());
totalDailyPoints += rewardPoint * dailyLimit;
}
Map<String, Object> outParams = new HashMap<>();
outParams.put("taskList", taskList);
outParams.put("totalDailyPoints", totalDailyPoints);
return getSuccessResult(outParams);
}
@ApiOperation(value = "完成任务")
@RequestMapping(value = "/complete", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject complete(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
UserInfo userInfo = TokenUtil.getUserInfo();
if (userInfo == null) {
return getFailureResult(1001);
}
String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
Integer storeId = StringUtil.isEmpty(request.getHeader("storeId")) ? 0 : Integer.parseInt(request.getHeader("storeId"));
Integer taskId = param.get("taskId") == null ? 0 : Integer.parseInt(param.get("taskId").toString());
if (taskId <= 0) {
return getFailureResult(201, "任务ID不能为空");
}
Integer merchantId = merchantService.getMerchantId(merchantNo);
if (merchantId <= 0) {
return getFailureResult(201, "商户信息异常");
}
Map<String, Object> result = taskService.completeTask(merchantId, storeId, userInfo.getId(), taskId, "USER");
return getSuccessResult(result);
}
@ApiOperation(value = "领取任务奖励")
@RequestMapping(value = "/claim", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject claim(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
UserInfo userInfo = TokenUtil.getUserInfo();
if (userInfo == null) {
return getFailureResult(1001);
}
String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
Integer storeId = StringUtil.isEmpty(request.getHeader("storeId")) ? 0 : Integer.parseInt(request.getHeader("storeId"));
Integer taskId = param.get("taskId") == null ? 0 : Integer.parseInt(param.get("taskId").toString());
if (taskId <= 0) {
return getFailureResult(201, "任务ID不能为空");
}
Integer merchantId = merchantService.getMerchantId(merchantNo);
if (merchantId <= 0) {
return getFailureResult(201, "商户信息异常");
}
Map<String, Object> result = taskService.claimTask(merchantId, storeId, userInfo.getId(), taskId, "USER");
return getSuccessResult(result);
}
}

View File

@ -0,0 +1,52 @@
package com.fuint.module.schedule;
import com.fuint.common.enums.PayStatusEnum;
import com.fuint.common.service.CommissionLogService;
import com.fuint.common.service.GrowService;
import com.fuint.common.service.OrderService;
import com.fuint.common.util.DateUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.repository.model.MtOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* 定时任务
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@EnableScheduling
@Component("GrowJob")
public class GrowJob {
private Logger logger = LoggerFactory.getLogger(GrowJob.class);
/**
* 系统环境变量
* */
@Autowired
private Environment environment;
@Autowired
private GrowService growService;
@Scheduled(cron = "${grow.job.time}")
@Transactional(rollbackFor = Exception.class)
public void dealGrow() throws BusinessCheckException {
String theSwitch = environment.getProperty("grow.job.switch");
if (theSwitch != null && theSwitch.equals("1")) {
logger.info("GrowJobStart!!!");
growService.clearAdvNum();
logger.info("GrowJobEnd!!!");
}
}
}