parent
b36abdd513
commit
2f73eb9032
|
|
@ -15,7 +15,9 @@ import com.sqx.modules.app.service.UserService;
|
|||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinning;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningAmount;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
|
||||
import com.sqx.modules.discSpinning.service.DiscSpinningAmountService;
|
||||
import com.sqx.modules.discSpinning.service.DiscSpinningRecordService;
|
||||
import com.sqx.modules.discSpinning.service.DiscSpinningService;
|
||||
import com.sqx.modules.orders.entity.Orders;
|
||||
|
|
@ -47,9 +49,10 @@ import java.util.concurrent.CompletableFuture;
|
|||
public class DiscSpinningController {
|
||||
|
||||
private final DiscSpinningService discSpinningService;
|
||||
private final DiscSpinningRecordService recordService;
|
||||
private final DiscSpinningAmountService amountService;
|
||||
private final CommonInfoService commonRepository;
|
||||
private final OrdersService ordersService;
|
||||
private final DiscSpinningRecordService recordService;
|
||||
private final UserMoneyService userMoneyService;
|
||||
private final UserMoneyDetailsService userMoneyDetailsService;
|
||||
private final UserService userService;
|
||||
|
|
@ -62,10 +65,11 @@ public class DiscSpinningController {
|
|||
UserMoneyDetailsService userMoneyDetailsService, CashOutService cashOutService,
|
||||
OrdersService ordersService, DiscSpinningRecordService recordService,
|
||||
UserMoneyService userMoneyService, UserService userService,
|
||||
TaskCenterService taskCenterService
|
||||
TaskCenterService taskCenterService, DiscSpinningAmountService amountService
|
||||
) {
|
||||
this.commonRepository = commonRepository;
|
||||
this.discSpinningService = discSpinningService;
|
||||
this.amountService = amountService;
|
||||
this.ordersService = ordersService;
|
||||
this.recordService = recordService;
|
||||
this.userMoneyService = userMoneyService;
|
||||
|
|
@ -273,34 +277,22 @@ public class DiscSpinningController {
|
|||
randomDouble = random.nextDouble();
|
||||
} while (randomDouble == 0);
|
||||
BigDecimal randomNum = new BigDecimal(randomDouble).multiply(new BigDecimal(10000)).divide(new BigDecimal(100));
|
||||
List<DiscSpinningAmount> amounts = amountService.list(new QueryWrapper<DiscSpinningAmount>().eq("status",1).orderByAsc("max_amount"));
|
||||
for (DiscSpinning prize : prizes) {
|
||||
if (randomNum.compareTo(prize.getNumber()) < 0) {
|
||||
if (prize.getType() == 2) {
|
||||
int maxAmount = Integer.parseInt(commonRepository.findOne(900).getValue());
|
||||
double resultAmount = 0;
|
||||
//从0 到 80-amount 直接 取 多个区间 数值越小 概率越大
|
||||
if (prize.getType() == 2) {
|
||||
double baseRandom = random.nextDouble();
|
||||
if (baseRandom < 0.8) {
|
||||
// 0.8到0.82范围内概率最大(这里示例以当前订单金额为基础,模拟类似0.8的情况)
|
||||
resultAmount = random.nextDouble() * 0.02;
|
||||
} else if (baseRandom < 0.9) {
|
||||
// 0.82 - 0.85范围概率小一些
|
||||
resultAmount = 0.02 + (random.nextDouble() * 0.03);
|
||||
} else if (baseRandom < 0.95) {
|
||||
// 0.85 - 0.9概率更小
|
||||
resultAmount = 0.05 + (random.nextDouble() * 0.05);
|
||||
} else if (baseRandom < 0.97) {
|
||||
// 0.9 - 1概率更小
|
||||
resultAmount = 0.1 + (random.nextDouble() * 0.1);
|
||||
} else if (baseRandom < 0.99) {
|
||||
//1 - 1.3 概率更小
|
||||
resultAmount = 0.2 + (random.nextDouble() * 0.3);
|
||||
double baseAmount = 0;
|
||||
for (DiscSpinningAmount amount : amounts) {
|
||||
if (baseRandom < amount.getRandom()) {
|
||||
resultAmount = baseAmount + random.nextDouble() * (amount.getMaxAmont() - baseAmount);
|
||||
}
|
||||
baseAmount = amount.getMaxAmont();
|
||||
}
|
||||
// else {
|
||||
// // 1.3 - 控制最大金额为80
|
||||
// resultAmount = 1 + (random.nextDouble() * (maxAmount - 1));
|
||||
// }
|
||||
|
||||
if (resultAmount == 0) {
|
||||
resultAmount = 0.01;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package com.sqx.modules.discSpinning.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningAmount;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DiscSpinningAmountDao extends BaseMapper<DiscSpinningAmount> {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.sqx.modules.discSpinning.entity;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 现金红包 抽奖配置(DiscSpinningAmount)表实体类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-12-11 14:59:01
|
||||
*/
|
||||
@Data
|
||||
@TableName("disc_spinning_amount")
|
||||
@ApiModel(value = "现金红包 抽奖配置 实体类")
|
||||
public class DiscSpinningAmount extends Model<DiscSpinningAmount> {
|
||||
@ApiModelProperty("主键id")
|
||||
private Long id;
|
||||
@ApiModelProperty("描述")
|
||||
private String name;
|
||||
@ApiModelProperty("0-1 小于 多少为该奖励")
|
||||
private Double random;
|
||||
@ApiModelProperty("最大金额")
|
||||
private Double maxAmont;
|
||||
private Integer status;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.sqx.modules.discSpinning.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningAmount;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface DiscSpinningAmountService extends IService<DiscSpinningAmount> {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.sqx.modules.discSpinning.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.modules.discSpinning.dao.DiscSpinningAmountDao;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningAmount;
|
||||
import com.sqx.modules.discSpinning.service.DiscSpinningAmountService;
|
||||
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 DiscSpinningAmountServiceImpl extends ServiceImpl<DiscSpinningAmountDao, DiscSpinningAmount> implements DiscSpinningAmountService {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -6,6 +6,6 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
|
||||
@Mapper
|
||||
public interface TaskCenterRecordDao extends BaseMapper<TaskCenterRecord> {
|
||||
|
||||
Integer countTaskNum(Long userId, Long taskId, String time);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,9 @@
|
|||
package com.sqx.modules.taskCenter.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class TaskCenterRecordServiceImpl extends ServiceImpl<TaskCenterRecordDao
|
|||
|
||||
@Override
|
||||
public Integer countTaskNum(Long userId, Long taskId, String time) {
|
||||
return baseMapper.selectCount(new QueryWrapper<TaskCenterRecord>().eq("user_id", userId).eq("task_id", taskId).gt("create_time", time));
|
||||
return baseMapper.countTaskNum(userId, taskId, time);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,48 +56,64 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
|||
signWrapper.orderByAsc("create_time");
|
||||
List<UserSignRecord> signRecordList = signRecordService.list(signWrapper);
|
||||
for (TaskCenter s : taskPage.getRecords()) {
|
||||
//签到任务
|
||||
if (s.getType() == 2) {
|
||||
if (s.getNumber().equals(1)) {
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
if (dayOrderNum < 3) {
|
||||
s.setDiscNumber(dayOrderNum);
|
||||
s.setNumber(3);
|
||||
switch (s.getType()) {
|
||||
//签到任务
|
||||
case 2:
|
||||
if (s.getNumber().equals(1)) {
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
if (dayOrderNum < 3) {
|
||||
s.setDiscNumber(dayOrderNum);
|
||||
s.setNumber(3);
|
||||
// s.setDisabled(false);
|
||||
todaySign = false;
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setNumber(null);
|
||||
s.setDisabled(false);
|
||||
} else {
|
||||
s.setDiscNumber(0);
|
||||
s.setNumber(null);
|
||||
s.setJumpType(0);
|
||||
}
|
||||
} else {
|
||||
if (todaySign) {
|
||||
if ((signRecordList.size() < (s.getNumber().intValue() - 1))) {
|
||||
s.setDiscNumber(s.getNumber() - signRecordList.size());
|
||||
s.setNumber(null);
|
||||
s.setDisabled(false);
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.beginOfMonth(new Date()).toString()) > 0) {
|
||||
todaySign = false;
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
s.setDisabled(false);
|
||||
} else {
|
||||
s.setDiscNumber(0);
|
||||
s.setNumber(null);
|
||||
s.setJumpType(0);
|
||||
}
|
||||
} else {
|
||||
if ((signRecordList.size() < s.getNumber().intValue())) {
|
||||
s.setDiscNumber(s.getNumber() - signRecordList.size());
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.beginOfMonth(new Date()).toString()) > 0) {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
if (todaySign) {
|
||||
if ((signRecordList.size() < (s.getNumber().intValue() - 1))) {
|
||||
s.setDiscNumber(s.getNumber() - signRecordList.size());
|
||||
s.setNumber(null);
|
||||
s.setDisabled(false);
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.beginOfMonth(new Date()).toString()) > 0) {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
}
|
||||
} else {
|
||||
if ((signRecordList.size() < s.getNumber().intValue())) {
|
||||
s.setDiscNumber(s.getNumber() - signRecordList.size());
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.beginOfMonth(new Date()).toString()) > 0) {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
//一次性任务
|
||||
case 3:
|
||||
if (s.getId().equals(1)) {
|
||||
Integer sumOrderNum = ordersService.countOrderNum(userId, null);
|
||||
if (sumOrderNum != null && sumOrderNum < s.getNumber()) {
|
||||
s.setDiscNumber(sumOrderNum);
|
||||
s.setNumber(s.getNumber());
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), null) > 0) {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Result.success().put("data", taskPage);
|
||||
|
|
@ -152,6 +168,13 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (taskCenter.getType().equals(3) && taskCenter.getId() == 1) {
|
||||
Integer sumOrderNum = ordersService.countOrderNum(userId, null);
|
||||
if (sumOrderNum != null && sumOrderNum < taskCenter.getNumber()) {
|
||||
return Result.error("领取失败,未达成领取条件");
|
||||
} else if (recordService.countTaskNum(userId, taskCenter.getId(), null) > 0) {
|
||||
return Result.error("不可重复领取");
|
||||
}
|
||||
}
|
||||
List<TaskCenterRecord> records = new ArrayList<>();
|
||||
Long targetId = null;
|
||||
|
|
|
|||
|
|
@ -314,6 +314,7 @@
|
|||
WHERE
|
||||
orders.user_id = #{userId}
|
||||
AND orders.`status` = 1
|
||||
AND orders.`pay_way` = 9
|
||||
<if test="time !=null and time != ''">
|
||||
and create_time > #{time}
|
||||
</if>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<?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.TaskCenterRecordDao">
|
||||
|
||||
|
||||
<select id="countTaskNum" resultType="Integer">
|
||||
SELECT
|
||||
count(*)
|
||||
FROM
|
||||
task_center_record record
|
||||
WHERE
|
||||
record.user_id = #{userId}
|
||||
AND record.task_id = #{taskId}
|
||||
<if test="time !=null and time != ''">
|
||||
and create_time > #{time}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue