Merge branch 'test' into dev
# Conflicts: # src/main/java/com/sqx/modules/taskCenter/service/TaskCenterService.java # src/main/java/com/sqx/modules/taskCenter/service/impl/TaskCenterServiceImpl.java
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.sqx.modules.app.entity;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
@@ -15,7 +16,6 @@ import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("user_money_details")
|
||||
@ApiModel("钱包详情")
|
||||
public class UserMoneyDetails implements Serializable {
|
||||
@@ -82,5 +82,31 @@ public class UserMoneyDetails implements Serializable {
|
||||
@ApiModelProperty("创建时间")
|
||||
private String createTime;
|
||||
|
||||
public UserMoneyDetails() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId 用户Id tb_user的id
|
||||
* @param sysUserId 系统用户Id tb_sys_user的id
|
||||
* @param byUserId 对应用户Id
|
||||
* @param title 标题
|
||||
* @param classify 1注册 2首次购买 3购买 4提现 5现金大转盘 6 分享 7 分享达标
|
||||
* @param type 类别(1充值2支出)
|
||||
* @param state 状态 1待支付 2已到账 3取消
|
||||
* @param money 金额
|
||||
* @param content 内容描述
|
||||
*/
|
||||
public UserMoneyDetails(Long userId, Long sysUserId, Long byUserId, String title, Integer classify, Integer type, Integer state, BigDecimal money, String content) {
|
||||
this.userId = userId;
|
||||
this.sysUserId = sysUserId;
|
||||
this.byUserId = byUserId;
|
||||
this.title = title;
|
||||
this.classify = classify;
|
||||
this.type = type;
|
||||
this.state = state;
|
||||
this.money = money;
|
||||
this.content = content;
|
||||
this.createTime = DateUtil.now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.sqx.modules.discSpinning.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.util.concurrent.RateLimiter;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
@@ -23,6 +25,7 @@ import com.sqx.modules.pay.entity.CashOut;
|
||||
import com.sqx.modules.pay.service.CashOutService;
|
||||
import com.sqx.modules.pay.wuyou.BaseResp;
|
||||
import com.sqx.modules.pay.wuyou.WuyouPay;
|
||||
import com.sqx.modules.taskCenter.service.TaskCenterService;
|
||||
import com.sqx.modules.utils.AliPayOrderUtil;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -38,6 +41,7 @@ import java.math.RoundingMode;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -53,11 +57,19 @@ public class DiscSpinningController {
|
||||
private final UserMoneyDetailsService userMoneyDetailsService;
|
||||
private final UserService userService;
|
||||
private final CashOutService cashOutService;
|
||||
private final TaskCenterService taskCenterService;
|
||||
|
||||
// 以id为键,对应的RateLimiter实例为值,用于不同id的防抖控制
|
||||
private static final ConcurrentHashMap<Long, RateLimiter> rateLimiterMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@Autowired
|
||||
public DiscSpinningController(CommonInfoService commonRepository, DiscSpinningService discSpinningService,
|
||||
UserMoneyDetailsService userMoneyDetailsService, CashOutService cashOutService,
|
||||
OrdersService ordersService, DiscSpinningRecordService recordService, UserMoneyService userMoneyService, UserService userService) {
|
||||
OrdersService ordersService, DiscSpinningRecordService recordService,
|
||||
UserMoneyService userMoneyService, UserService userService,
|
||||
TaskCenterService taskCenterService
|
||||
) {
|
||||
this.commonRepository = commonRepository;
|
||||
this.discSpinningService = discSpinningService;
|
||||
this.ordersService = ordersService;
|
||||
@@ -66,6 +78,7 @@ public class DiscSpinningController {
|
||||
this.userMoneyDetailsService = userMoneyDetailsService;
|
||||
this.userService = userService;
|
||||
this.cashOutService = cashOutService;
|
||||
this.taskCenterService = taskCenterService;
|
||||
|
||||
}
|
||||
|
||||
@@ -144,7 +157,7 @@ public class DiscSpinningController {
|
||||
map.put("sum", drawCount);
|
||||
if (maps != null && maps.containsKey("source") && "task".equals(maps.get("source"))) {
|
||||
//任务可抽奖次数
|
||||
|
||||
map.put("count", taskCenterService.countTaskDisc(userId));
|
||||
} else {
|
||||
int i = recordService.countDraw(userId);
|
||||
if (drawCount - i > 0) {
|
||||
@@ -186,87 +199,74 @@ public class DiscSpinningController {
|
||||
@PostMapping("/app/discSpinning/receive")
|
||||
@ApiOperation("大转盘奖项领取")
|
||||
public Result receive(@RequestBody DiscSpinningRecord receive) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
receiveAsync(receive);
|
||||
});
|
||||
return Result.success();
|
||||
// 每秒允许0.6次操作
|
||||
RateLimiter rateLimiter = rateLimiterMap.computeIfAbsent(receive.getId(), k -> RateLimiter.create(0.6));
|
||||
if (rateLimiter.tryAcquire()) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
DiscSpinningRecord record = recordService.getById(receive.getId());
|
||||
CompletableFuture.runAsync(() -> {
|
||||
receiveAsync(record);
|
||||
});
|
||||
});
|
||||
return Result.success();
|
||||
}
|
||||
return Result.error("操作过于频繁,请稍后再试");
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void receiveAsync(DiscSpinningRecord receive) {
|
||||
UserEntity userInfo = userService.queryByUserId(receive.getUserId());
|
||||
if (receive.getNumber().compareTo(new BigDecimal("0.1")) > 0 && StringUtils.isNotBlank(userInfo.getZhiFuBao()) && StringUtils.isNotBlank(userInfo.getZhiFuBaoName())) {
|
||||
receive.setTarget("1");
|
||||
//提现
|
||||
String result = withdraw(receive, receive.getUserId(), receive.getNumber().doubleValue());
|
||||
recordService.updateById(receive);
|
||||
|
||||
if (StringUtils.isBlank(result)) {
|
||||
// return Result.success();
|
||||
return;
|
||||
}
|
||||
|
||||
if ("提现成功,将在三个工作日内到账,请耐心等待!".equals(result)) {
|
||||
// return Result.success(result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails();
|
||||
userMoneyDetails.setClassify(5);
|
||||
userMoneyDetails.setMoney(receive.getNumber());
|
||||
userMoneyDetails.setUserId(receive.getUserId());
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetails.setContent("现金红包奖励" + receive.getNumber() + "元");
|
||||
userMoneyDetails.setTitle("[现金大转盘]");
|
||||
userMoneyDetails.setState(2);
|
||||
userMoneyDetails.setType(1);
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
||||
receive.getUserId(),null,null,"[现金大转盘]",5,1,2,
|
||||
receive.getNumber(),"现金红包奖励" + receive.getNumber() + "元");
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
receive.setTarget("2");
|
||||
receive.setTargetId(userMoneyDetails.getId());
|
||||
recordService.updateById(receive);
|
||||
//存入余额 钱
|
||||
userMoneyService.updateAmount(1, receive.getUserId(), receive.getNumber().doubleValue());
|
||||
receive.setTarget("2");
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
receive.setTargetId(userMoneyDetails.getId());
|
||||
|
||||
recordService.updateById(receive);
|
||||
if (receive.getNumber().compareTo(new BigDecimal("0.1")) > 0 && StringUtils.isNotBlank(userInfo.getZhiFuBao()) && StringUtils.isNotBlank(userInfo.getZhiFuBaoName())) {
|
||||
//提现
|
||||
withdraw(userInfo, receive.getNumber().doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public String withdraw(DiscSpinningRecord record, Long userId, Double money) {
|
||||
UserEntity userInfo = userService.queryByUserId(userId);
|
||||
//最高提现金额
|
||||
CommonInfo one2 = commonRepository.findOne(910);
|
||||
public void withdraw(UserEntity userInfo, Double money) {
|
||||
CashOut cashOut = new CashOut();
|
||||
cashOut.setIsOut(false);
|
||||
cashOut.setMoney(money.toString());
|
||||
cashOut.setUserId(userInfo.getUserId());
|
||||
cashOut.setZhifubao(userInfo.getZhiFuBao());
|
||||
cashOut.setZhifubaoName(userInfo.getZhiFuBaoName());
|
||||
|
||||
cashOut.setState(0);
|
||||
cashOut.setRate(0.00);
|
||||
cashOut.setUserType(1);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String date = sdf.format(new Date());
|
||||
cashOut.setCreateAt(date);
|
||||
if (one2 != null && money >= Double.parseDouble(one2.getValue())) {
|
||||
cashOutService.saveBody(cashOut);
|
||||
return "提现成功,将在三个工作日内到账,请耐心等待!";
|
||||
}
|
||||
cashOut.setCreateAt(DateUtil.now());
|
||||
|
||||
String outOrderNo = AliPayOrderUtil.createOrderId();
|
||||
cashOut.setOrderNumber(outOrderNo);
|
||||
BaseResp baseResp = WuyouPay.extractOrder(outOrderNo, cashOut.getMoney(), cashOut.getZhifubao(), cashOut.getZhifubaoName());
|
||||
if (baseResp.getStatus() != null && baseResp.getStatus().equals(2)) {
|
||||
cashOut.setState(1);
|
||||
} else if (StringUtils.isNotBlank(baseResp.getErrorMsg())) {
|
||||
return baseResp.getErrorMsg();
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
||||
userInfo.getUserId(),null,null,"[现金大转盘]",4,2,1,
|
||||
new BigDecimal(money),"现金红包自动提现" + money + "元");
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
//减去余额 钱
|
||||
userMoneyService.updateAmount(2, userInfo.getUserId(), money);
|
||||
|
||||
//最高提现金额
|
||||
CommonInfo one2 = commonRepository.findOne(910);
|
||||
if (one2 == null || money <= Double.parseDouble(one2.getValue())) {
|
||||
String outOrderNo = AliPayOrderUtil.createOrderId();
|
||||
cashOut.setOrderNumber(outOrderNo);
|
||||
BaseResp baseResp = WuyouPay.extractOrder(outOrderNo, cashOut.getMoney(), cashOut.getZhifubao(), cashOut.getZhifubaoName());
|
||||
if (baseResp.getStatus() != null && baseResp.getStatus().equals(2)) {
|
||||
cashOut.setState(1);
|
||||
} else if (StringUtils.isNotBlank(baseResp.getErrorMsg())) {
|
||||
cashOut.setState(2);
|
||||
cashOut.setRefund(baseResp.getErrorMsg());
|
||||
}
|
||||
}
|
||||
cashOutService.saveBody(cashOut);
|
||||
record.setTargetId(cashOut.getId());
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
@@ -45,16 +45,10 @@ public class CashOutTask implements ITask {
|
||||
} else {
|
||||
cashOut.setRefund(StringUtils.isNotBlank(baseResp.getMsg()) ? baseResp.getMsg() : baseResp.getErrorMsg());
|
||||
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails();
|
||||
userMoneyDetails.setClassify(5);
|
||||
userMoneyDetails.setMoney(new BigDecimal(cashOut.getMoney()));
|
||||
userMoneyDetails.setUserId(cashOut.getUserId());
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetails.setContent("提现失败存入余额" + cashOut.getMoney() + "元");
|
||||
userMoneyDetails.setTitle("[现金大转盘]");
|
||||
userMoneyDetails.setState(2);
|
||||
userMoneyDetails.setType(1);
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
||||
cashOut.getUserId(),null,null,"提现失败",4,1,1,
|
||||
new BigDecimal(cashOut.getMoney()),"提现失败存入余额" + cashOut.getMoney() + "元");
|
||||
|
||||
//存入余额 钱
|
||||
userMoneyService.updateAmount(1, cashOut.getUserId(), Double.parseDouble(cashOut.getMoney()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
|
||||
@@ -240,11 +240,15 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||
//设置短剧id
|
||||
orders.setCourseId(courseId);
|
||||
orders.setCourseDetailsId(courseDetailsId);
|
||||
|
||||
// 金豆和金额的比例
|
||||
String value = commonInfoService.findOne(914).getValue();
|
||||
BigDecimal v = new BigDecimal(value);
|
||||
if (courseDetailsId != null) {
|
||||
CourseDetails courseDetails = courseDetailsService.getById(courseDetailsId);
|
||||
orders.setPayMoney(courseDetails.getPrice());
|
||||
orders.setPayMoney(courseDetails.getPrice().multiply(v));
|
||||
} else {
|
||||
orders.setPayMoney(course.getPrice());
|
||||
orders.setPayMoney(course.getPrice().multiply(v));
|
||||
}
|
||||
BigDecimal payDiamond = orders.getPayMoney().multiply(new BigDecimal(commonInfoService.findOne(892).getValue()));
|
||||
orders.setPayDiamond(payDiamond);
|
||||
|
||||
@@ -125,22 +125,17 @@ public class WuyouController {
|
||||
if ("2".equals(notifyDto.getStatus())) {
|
||||
cashOut.setState(1);
|
||||
} else {
|
||||
cashOut.setState(2);
|
||||
cashOut.setRefund(notifyDto.getMsg());
|
||||
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails();
|
||||
userMoneyDetails.setClassify(5);
|
||||
userMoneyDetails.setMoney(new BigDecimal(cashOut.getMoney()));
|
||||
userMoneyDetails.setUserId(cashOut.getUserId());
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetails.setContent("提现失败存入余额" + cashOut.getMoney() + "元");
|
||||
userMoneyDetails.setTitle("提现失败");
|
||||
userMoneyDetails.setState(2);
|
||||
userMoneyDetails.setType(1);
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
||||
cashOut.getUserId(),null,null,"提现失败",4,1,1,
|
||||
new BigDecimal(cashOut.getMoney()),"提现失败存入余额" + cashOut.getMoney() + "元");
|
||||
//存入余额 钱
|
||||
userMoneyService.updateAmount(1, cashOut.getUserId(), Double.parseDouble(cashOut.getMoney()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}
|
||||
cashOutDao.updateById(cashOut);
|
||||
}
|
||||
return "success";
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class CashOut implements Serializable {
|
||||
private String orderNumber;
|
||||
|
||||
/**
|
||||
* 状态 0待转账 1成功 -1退款
|
||||
* 状态 0待转账 1成功 -1退款 2失败
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.sqx.modules.pay.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
@@ -441,11 +442,10 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
||||
cashOut.setState(0);
|
||||
cashOut.setRate(0.00);
|
||||
cashOut.setUserType(1);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String date = sdf.format(new Date());
|
||||
cashOut.setCreateAt(date);
|
||||
cashOut.setCreateAt(DateUtil.now());
|
||||
|
||||
String outOrderNo = AliPayOrderUtil.createOrderId();
|
||||
cashOut.setOrderNumber(outOrderNo);
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails();
|
||||
userMoneyDetails.setUserId(userId);
|
||||
userMoneyDetails.setTitle("[提现]");
|
||||
@@ -454,7 +454,7 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
||||
userMoneyDetails.setState(1);
|
||||
userMoneyDetails.setClassify(4);
|
||||
userMoneyDetails.setMoney(new BigDecimal(money));
|
||||
userMoneyDetails.setCreateTime(date);
|
||||
userMoneyDetails.setCreateTime(DateUtil.now());
|
||||
UserMoney userMoney;
|
||||
if (isSys) {
|
||||
userMoney = userMoneyService.selectSysUserMoneyByUserId(userId);
|
||||
|
||||
@@ -4,8 +4,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenter;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface TaskCenterDao extends BaseMapper<TaskCenter> {
|
||||
|
||||
//大转盘任务
|
||||
List<TaskCenter> queryTaskDiscCenter(Long userId);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.sqx.modules.taskCenter.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterRecord;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface TaskCenterRecordDao extends BaseMapper<TaskCenterRecord> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.sqx.modules.taskCenter.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 任务领取记录(TaskCenterRecord)表实体类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-12-07 17:40:56
|
||||
*/
|
||||
@Data
|
||||
@TableName("task_center_record")
|
||||
@ApiModel(value = "任务领取记录 实体类")
|
||||
public class TaskCenterRecord extends Model<TaskCenterRecord> {
|
||||
@ApiModelProperty("id")
|
||||
private Long id;
|
||||
@ApiModelProperty("用户id")
|
||||
private Long userId;
|
||||
@ApiModelProperty("任务Id")
|
||||
private Long taskId;
|
||||
@ApiModelProperty("奖励名称")
|
||||
private String name;
|
||||
@ApiModelProperty("奖励类型 1 金豆 2 现金 3 4 5")
|
||||
private Integer type;
|
||||
@ApiModelProperty("${column.comment}")
|
||||
private Long targetId;
|
||||
@ApiModelProperty("数量")
|
||||
private Integer number;
|
||||
@ApiModelProperty("${column.comment}")
|
||||
private Date createTime;
|
||||
@ApiModelProperty("${column.comment}")
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.sqx.modules.taskCenter.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterRecord;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface TaskCenterRecordService extends IService<TaskCenterRecord> {
|
||||
|
||||
/**
|
||||
* 统计 用户领取过的任务
|
||||
* @param userId
|
||||
* @param taskId
|
||||
* @param time 时间条件 不传为全部订单 格式 yyyy-MM-dd HH:mm:ss
|
||||
* @return
|
||||
*/
|
||||
Integer countTaskNum(Long userId,Long taskId,String time);
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ package com.sqx.modules.taskCenter.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenter;
|
||||
import org.springframework.web.bind.annotation.RequestAttribute;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface TaskCenterService extends IService<TaskCenter> {
|
||||
|
||||
Result queryTaskCenter(Integer page, Integer limit, Long userId);
|
||||
Result taskReceive(Long userId,Long id);
|
||||
Result queryTaskCenter(Integer page, Integer limit, Long userId);
|
||||
|
||||
Result taskReceive(Long userId, Long id);
|
||||
|
||||
int countTaskDisc(Long userId);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.sqx.modules.taskCenter.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.modules.taskCenter.dao.TaskCenterRecordDao;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterRecord;
|
||||
import com.sqx.modules.taskCenter.service.TaskCenterRecordService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class TaskCenterRecordServiceImpl extends ServiceImpl<TaskCenterRecordDao, TaskCenterRecord> implements TaskCenterRecordService {
|
||||
|
||||
|
||||
@Override
|
||||
public Integer countTaskNum(Long userId, Long taskId, String time) {
|
||||
return baseMapper.selectCount(new QueryWrapper<TaskCenterRecord>().eq("user_id", userId).eq("task_id", taskId).lt("create_time", time));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.sqx.modules.taskCenter.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -8,25 +9,24 @@ import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.app.service.UserMoneyService;
|
||||
import com.sqx.modules.course.entity.CourseUser;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.taskCenter.dao.TaskCenterDao;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenter;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterRecord;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterReward;
|
||||
import com.sqx.modules.taskCenter.service.TaskCenterRecordService;
|
||||
import com.sqx.modules.taskCenter.service.TaskCenterRewardService;
|
||||
import com.sqx.modules.taskCenter.service.TaskCenterService;
|
||||
import com.sqx.modules.userSign.entity.UserSignRecord;
|
||||
import com.sqx.modules.userSign.service.UserSignRecordService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter> implements TaskCenterService {
|
||||
@@ -38,13 +38,16 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
||||
@Autowired
|
||||
private TaskCenterRewardService taskCenterRewardService;
|
||||
@Autowired
|
||||
private TaskCenterRecordService recordService;
|
||||
@Autowired
|
||||
private UserMoneyService userMoneyService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
|
||||
@Override
|
||||
public Result queryTaskCenter(Integer page, Integer limit, Long userId) {
|
||||
//任务
|
||||
IPage<TaskCenter> taskPage = baseMapper.selectPage(new Page<>(page, limit), new QueryWrapper<TaskCenter>().orderByDesc("sort"));
|
||||
IPage<TaskCenter> taskPage = baseMapper.selectPage(new Page<>(page, limit), new QueryWrapper<TaskCenter>().eq("show", 1).orderByDesc("sort"));
|
||||
boolean todaySign = true;
|
||||
//月 签到记录
|
||||
QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>();
|
||||
@@ -57,17 +60,17 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
||||
if (s.getType() == 2) {
|
||||
if (s.getNumber().equals(1)) {
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
if (dayOrderNum < 3) {
|
||||
if (dayOrderNum < 3 || recordService.countTaskNum(userId, s.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
s.setDisabled(false);
|
||||
todaySign = false;
|
||||
}
|
||||
} else {
|
||||
if (todaySign) {
|
||||
if (signRecordList.size() < (s.getNumber().intValue() - 1)) {
|
||||
if ((signRecordList.size() < (s.getNumber().intValue() - 1)) || recordService.countTaskNum(userId, s.getId(), DateUtil.beginOfMonth(new Date()).toString()) > 0) {
|
||||
s.setDisabled(false);
|
||||
}
|
||||
} else {
|
||||
if (signRecordList.size() < s.getNumber().intValue()) {
|
||||
if ((signRecordList.size() < s.getNumber().intValue()) || recordService.countTaskNum(userId, s.getId(), DateUtil.beginOfMonth(new Date()).toString()) > 0) {
|
||||
s.setDisabled(false);
|
||||
}
|
||||
}
|
||||
@@ -90,54 +93,101 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
||||
List<UserSignRecord> signRecordList = signRecordService.list(signWrapper);
|
||||
|
||||
if (taskCenter.getType().equals(2)) {
|
||||
if (taskCenter.getType() == 2) {
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
if (taskCenter.getNumber().equals(1)) {
|
||||
if (dayOrderNum < 3) {
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
if (taskCenter.getNumber().equals(1)) {
|
||||
UserSignRecord yesterday = signRecordService.getOne(new QueryWrapper<UserSignRecord>().eq("user_id", userId).eq("sign_day",
|
||||
DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd")));
|
||||
UserSignRecord signRecord = new UserSignRecord();
|
||||
if (yesterday != null && yesterday.getDay() != null) {
|
||||
signRecord.setDay(yesterday.getDay() + 1);
|
||||
} else {
|
||||
signRecord.setDay(1);
|
||||
}
|
||||
signRecord.setUserId(userId);
|
||||
signRecord.setSignDay(DateUtil.today());
|
||||
signRecord.setCreateTime(new Date());
|
||||
if (dayOrderNum < 3) {
|
||||
return Result.error("领取失败,未达成领取条件");
|
||||
}
|
||||
if (recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
return Result.error("不可重复领取");
|
||||
}
|
||||
signRecordService.save(signRecord);
|
||||
} else {
|
||||
if (dayOrderNum > 2) {
|
||||
if (signRecordList.size() < (taskCenter.getNumber().intValue() - 1)) {
|
||||
return Result.error("领取失败,未达成领取条件");
|
||||
}
|
||||
} else {
|
||||
if (dayOrderNum > 2) {
|
||||
if (signRecordList.size() < (taskCenter.getNumber().intValue() - 1)) {
|
||||
return Result.error("领取失败,未达成领取条件");
|
||||
}
|
||||
} else {
|
||||
if (signRecordList.size() < taskCenter.getNumber().intValue()) {
|
||||
return Result.error("领取失败,未达成领取条件");
|
||||
}
|
||||
if (recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
return Result.error("不可重复领取");
|
||||
}
|
||||
} else {
|
||||
if (signRecordList.size() < taskCenter.getNumber().intValue()) {
|
||||
return Result.error("领取失败,未达成领取条件");
|
||||
}
|
||||
if (recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
return Result.error("不可重复领取");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
List<TaskCenterRecord> records = new ArrayList<>();
|
||||
Long targetId = null;
|
||||
QueryWrapper<TaskCenterReward> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("task_id",id);
|
||||
queryWrapper.eq("task_id", id);
|
||||
List<TaskCenterReward> list = taskCenterRewardService.list(queryWrapper);
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails();
|
||||
userMoneyDetails.setClassify(8);
|
||||
userMoneyDetails.setUserId(userId);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetails.setTitle("任务中心");
|
||||
userMoneyDetails.setState(2);
|
||||
userMoneyDetails.setType(1);
|
||||
for (TaskCenterReward reward : list) {
|
||||
userMoneyDetails.setMoney(new BigDecimal(reward.getNumber()));
|
||||
switch (reward.getType()){
|
||||
switch (reward.getType()) {
|
||||
case 1:
|
||||
userMoneyDetails.setContent(taskCenter.getTitle()+"任务完成,金豆奖励" + reward.getNumber());
|
||||
UserMoneyDetails userMoneyDetails1 = new UserMoneyDetails();
|
||||
userMoneyDetails1.setClassify(8);
|
||||
userMoneyDetails1.setUserId(userId);
|
||||
userMoneyDetails1.setCreateTime(DateUtil.now());
|
||||
userMoneyDetails1.setTitle("任务中心");
|
||||
userMoneyDetails1.setState(2);
|
||||
userMoneyDetails1.setType(1);
|
||||
userMoneyDetails1.setMoney(new BigDecimal(reward.getNumber()));
|
||||
userMoneyDetails1.setContent(taskCenter.getTitle() + "任务完成,金豆奖励" + reward.getNumber());
|
||||
userMoneyService.updateMoney(1, userId, reward.getNumber());
|
||||
userMoneyDetailsService.save(userMoneyDetails1);
|
||||
targetId = userMoneyDetails1.getId();
|
||||
break;
|
||||
case 2:
|
||||
userMoneyDetails.setContent(taskCenter.getTitle()+"任务完成,现金奖励" + reward.getNumber());
|
||||
UserMoneyDetails userMoneyDetails2 = new UserMoneyDetails();
|
||||
userMoneyDetails2.setClassify(8);
|
||||
userMoneyDetails2.setUserId(userId);
|
||||
userMoneyDetails2.setCreateTime(DateUtil.now());
|
||||
userMoneyDetails2.setTitle("任务中心");
|
||||
userMoneyDetails2.setState(2);
|
||||
userMoneyDetails2.setType(1);
|
||||
userMoneyDetails2.setMoney(new BigDecimal(reward.getNumber()));
|
||||
userMoneyDetails2.setContent(taskCenter.getTitle() + "任务完成,现金奖励" + reward.getNumber());
|
||||
userMoneyService.updateAmount(1, userId, reward.getNumber());
|
||||
userMoneyDetailsService.save(userMoneyDetails2);
|
||||
targetId = userMoneyDetails2.getId();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
TaskCenterRecord record = new TaskCenterRecord();
|
||||
record.setUserId(userId);
|
||||
record.setTaskId(id);
|
||||
record.setType(reward.getType());
|
||||
record.setNumber(reward.getNumber());
|
||||
record.setName(taskCenter.getTitle() + ":" + record.getName());
|
||||
record.setTargetId(targetId);
|
||||
records.add(record);
|
||||
}
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
recordService.saveBatch(records);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countTaskDisc(Long userId) {
|
||||
//TaskCenter的number为大转盘次数
|
||||
List<TaskCenter> taskCenters = baseMapper.queryTaskDiscCenter(userId);
|
||||
//大转盘任务 校验 次数
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ spring:
|
||||
max-request-size: 10240MB
|
||||
enabled: true
|
||||
redis:
|
||||
open: false # 是否开启redis缓存 true开启 false关闭
|
||||
open: true # 是否开启redis缓存 true开启 false关闭
|
||||
database: 0
|
||||
host: localhost
|
||||
port: 6379
|
||||
|
||||
@@ -287,6 +287,7 @@
|
||||
WHERE
|
||||
orders.user_id = #{userId}
|
||||
AND orders.`status` = 1
|
||||
AND orders.`pay_way` = 9
|
||||
AND orders.create_time > DATE_FORMAT( CURDATE(), '%Y-%m-%d 00:00:00' )
|
||||
AND record.order_id IS NULL
|
||||
ORDER BY
|
||||
|
||||
16
src/main/resources/mapper/tashCenter/TaskCenterDto.xml
Normal file
16
src/main/resources/mapper/tashCenter/TaskCenterDto.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sqx.modules.taskCenter.dao.TaskCenterDao">
|
||||
|
||||
|
||||
<!-- 根据key,查询value -->
|
||||
<select id="queryTaskDiscCenter" resultType="com.sqx.modules.taskCenter.entity.TaskCenter">
|
||||
SELECT task.*,
|
||||
reward.number as number
|
||||
FROM task_center_reward reward
|
||||
INNER JOIN task_center task ON reward.task_id = task.id and task.show = 1
|
||||
where reward.type = 9
|
||||
and user_id = #{userId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user