抽奖活动新增activityId整改
This commit is contained in:
parent
37f9fc3612
commit
2aa5da1546
@ -36,6 +36,7 @@ public interface LotteryTicketClientApi {
|
||||
@PostMapping("/addTicket")
|
||||
ResultResponse<Long> addTicket(
|
||||
@RequestParam("userId") Long userId,
|
||||
@RequestParam("activityId") Long activityId,
|
||||
@RequestParam("count") Integer count,
|
||||
@RequestParam(value = "source", required = false) String source,
|
||||
@RequestParam(value = "sourceId", required = false) String sourceId
|
||||
|
||||
@ -151,8 +151,11 @@ public class LotteryActivityRestController extends BaseController {
|
||||
* @eo.request-type formdata
|
||||
*/
|
||||
@GetMapping("/my-tickets")
|
||||
public List<LotteryTicketCO> listMyTickets(AppExtCommand cmd) {
|
||||
return lotteryActivityRestService.listMyTickets(cmd);
|
||||
public List<LotteryTicketCO> listMyTickets(AppExtCommand cmd, Long activityId) {
|
||||
if (activityId == null) {
|
||||
activityId = 2005571533988298753L;
|
||||
}
|
||||
return lotteryActivityRestService.listMyTickets(cmd, activityId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,8 +167,11 @@ public class LotteryActivityRestController extends BaseController {
|
||||
* @eo.request-type formdata
|
||||
*/
|
||||
@GetMapping("/my-ticket-count")
|
||||
public Integer getMyTicketCount(AppExtCommand cmd) {
|
||||
return lotteryActivityRestService.getMyTicketCount(cmd);
|
||||
public Integer getMyTicketCount(AppExtCommand cmd, Long activityId) {
|
||||
if (activityId == null) {
|
||||
activityId = 2005571533988298753L;
|
||||
}
|
||||
return lotteryActivityRestService.getMyTicketCount(cmd, activityId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,8 +183,11 @@ public class LotteryActivityRestController extends BaseController {
|
||||
* @eo.request-type formdata
|
||||
*/
|
||||
@GetMapping("/my-total-draw-count")
|
||||
public MyTotalDrawCountCO getMyTotalDrawCount(AppExtCommand cmd) {
|
||||
return lotteryActivityRestService.getMyTotalDrawCount(cmd);
|
||||
public MyTotalDrawCountCO getMyTotalDrawCount(AppExtCommand cmd, Long activityId) {
|
||||
if (activityId == null) {
|
||||
activityId = 2005571533988298753L;
|
||||
}
|
||||
return lotteryActivityRestService.getMyTotalDrawCount(cmd, activityId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -48,8 +48,9 @@ public class SpinsTaskRestController {
|
||||
*/
|
||||
@PostMapping("/receive/reward")
|
||||
public SpinsTaskRewardCO receiveReward(@Validated @RequestBody SpinsTaskReceiveRewardCmd cmd) {
|
||||
log.info("领取任务奖励, userId={}, taskCode={}", cmd.getReqUserId(), cmd.getTaskCode());
|
||||
SpinsTaskRewardCO reward = spinsTaskService.receiveTaskReward(cmd);
|
||||
return reward;
|
||||
if (cmd.getActivityId() == null) {
|
||||
cmd.setActivityId(2005571533988298753L);
|
||||
}
|
||||
return spinsTaskService.receiveTaskReward(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ public class SpinsTaskReceiveRewardExe {
|
||||
public SpinsTaskRewardCO execute(SpinsTaskReceiveRewardCmd cmd) {
|
||||
Long userId = cmd.getReqUserId();
|
||||
String taskCode = cmd.getTaskCode();
|
||||
Long activityId = cmd.getActivityId();
|
||||
|
||||
// 构建分布式锁key
|
||||
String lockKey = DistributedLockUtil.buildLockKey(LOCK_KEY_PREFIX, userId, taskCode);
|
||||
@ -58,13 +59,13 @@ public class SpinsTaskReceiveRewardExe {
|
||||
// 使用分布式锁工具类执行业务逻辑
|
||||
return distributedLockUtil.executeWithLock(
|
||||
lockKey,
|
||||
() -> executeReceiveReward(userId, taskCode));
|
||||
() -> executeReceiveReward(userId, activityId, taskCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行领取任务奖励的核心逻辑
|
||||
*/
|
||||
private SpinsTaskRewardCO executeReceiveReward(Long userId, String taskCode) {
|
||||
private SpinsTaskRewardCO executeReceiveReward(Long userId, Long activityId, String taskCode) {
|
||||
// 1. 查询任务配置
|
||||
List<SpinsTaskConfig> spinsTaskConfigs = spinsTaskConfigDAO.selectList(
|
||||
new LambdaQueryWrapper<SpinsTaskConfig>()
|
||||
@ -106,6 +107,7 @@ public class SpinsTaskReceiveRewardExe {
|
||||
for (int i = 0; i < taskConfig.getRewardValue(); i++) {
|
||||
Long ticketId = lotteryTicketClient.addTicket(
|
||||
userId,
|
||||
activityId,
|
||||
1,
|
||||
"SPINS_TASK",
|
||||
taskCode
|
||||
|
||||
@ -53,7 +53,7 @@ public class ActivityRewardConfigBadgeQryExe {
|
||||
List<Long> ruleIds = ruleConfigs.stream().map(ActivityPropsRule::getId).collect(Collectors.toList());
|
||||
Map<Long, UserActivityRewardClaim> claimMap = getUserClaimMap(cmd.getReqUserId(), ruleIds);
|
||||
|
||||
MyTotalDrawCountCO drawCount = lotteryActivityRestService.getMyTotalDrawCount(cmd);
|
||||
MyTotalDrawCountCO drawCount = lotteryActivityRestService.getMyTotalDrawCount(cmd, cmd.getActivityId());
|
||||
|
||||
|
||||
BigDecimal finalUserTotalAmount = drawCount != null && drawCount.getUsedCount() != null ? new BigDecimal(drawCount.getUsedCount()) : BigDecimal.ZERO;
|
||||
|
||||
@ -84,7 +84,7 @@ public class ClaimActivityRewardBadgeExe {
|
||||
BigDecimal requiredAmount = parseRequiredAmount(targetRule.getJsonData());
|
||||
ResponseAssert.notNull(DynamicErrorCode.NO_RELATED_INFORMATION_FOUND, requiredAmount);
|
||||
|
||||
MyTotalDrawCountCO drawCount = lotteryActivityRestService.getMyTotalDrawCount(cmd);
|
||||
MyTotalDrawCountCO drawCount = lotteryActivityRestService.getMyTotalDrawCount(cmd, cmd.getActivityId());
|
||||
|
||||
BigDecimal finalUserTotalAmount = drawCount != null && drawCount.getUsedCount() != null ? new BigDecimal(drawCount.getUsedCount()) : BigDecimal.ZERO;
|
||||
|
||||
|
||||
@ -97,6 +97,7 @@ public class ClaimActivityRewardExe {
|
||||
Long ticketId = ResponseAssert.requiredSuccess(
|
||||
lotteryTicketClient.addTicket(
|
||||
cmd.getReqUserId(),
|
||||
cmd.getActivityId(),
|
||||
1,
|
||||
"ACTIVITY_REWARD",
|
||||
cmd.getRuleId().toString()
|
||||
|
||||
@ -73,6 +73,7 @@ public class LotteryActivityDetailQryExe {
|
||||
if (activity.getNeedTicket() == 1) {
|
||||
ticketCount = lotteryTicketService.query()
|
||||
.eq(LotteryTicket::getUserId, userId)
|
||||
.eq(LotteryTicket::getActivityId, activity.getId())
|
||||
.eq(LotteryTicket::getStatus, 1)
|
||||
.gt(LotteryTicket::getRemainingCount, 0)
|
||||
.list()
|
||||
|
||||
@ -88,7 +88,7 @@ public class LotteryDrawExe {
|
||||
BigDecimal userRechargeAmount = getUserRechargeAmount(userId, activityId);
|
||||
|
||||
// 5. 校验并扣除抽奖券(如果需要)
|
||||
deductTicket(userId, activity.getTicketCost());
|
||||
deductTicket(userId, activity.getId(), activity.getTicketCost());
|
||||
|
||||
// 6. 获取或创建用户进度(用于动态概率)
|
||||
LotteryUserProgress progress = getOrCreateUserProgress(userId, activityId);
|
||||
@ -470,9 +470,10 @@ public class LotteryDrawExe {
|
||||
/**
|
||||
* 扣除抽奖券.
|
||||
*/
|
||||
private void deductTicket(Long userId, Integer ticketCost) {
|
||||
private void deductTicket(Long userId, Long activityId, Integer ticketCost) {
|
||||
List<LotteryTicket> tickets = lotteryTicketService.query()
|
||||
.eq(LotteryTicket::getUserId, userId)
|
||||
.eq(LotteryTicket::getActivityId, activityId)
|
||||
.eq(LotteryTicket::getStatus, 1)
|
||||
.gt(LotteryTicket::getRemainingCount, 0)
|
||||
.orderByAsc(LotteryTicket::getExpireTime)
|
||||
|
||||
@ -95,7 +95,7 @@ public class LotteryMultiDrawExe {
|
||||
? activity.getMultiDrawTicketCost()
|
||||
: drawCount * activity.getTicketCost();
|
||||
|
||||
deductTicket(userId, ticketCost);
|
||||
deductTicket(userId, activityId, ticketCost);
|
||||
|
||||
// 7. 获取或创建用户进度(用于动态概率)
|
||||
LotteryUserProgress progress = getOrCreateUserProgress(userId, activityId);
|
||||
@ -469,8 +469,13 @@ public class LotteryMultiDrawExe {
|
||||
return lotteryPrizeService.query().eq(LotteryPrize::getActivityId, activityId).eq(LotteryPrize::getIsGuaranteePrize, 1).gt(LotteryPrize::getRemainingStock, 0).orderByDesc(LotteryPrize::getPrizeValue).last("LIMIT 1").getOne();
|
||||
}
|
||||
|
||||
private void deductTicket(Long userId, Integer ticketCost) {
|
||||
List<LotteryTicket> tickets = lotteryTicketService.query().eq(LotteryTicket::getUserId, userId).eq(LotteryTicket::getStatus, 1).gt(LotteryTicket::getRemainingCount, 0).orderByAsc(LotteryTicket::getExpireTime).list();
|
||||
private void deductTicket(Long userId, Long activityId, Integer ticketCost) {
|
||||
List<LotteryTicket> tickets = lotteryTicketService.query()
|
||||
.eq(LotteryTicket::getUserId, userId)
|
||||
.eq(LotteryTicket::getActivityId, activityId)
|
||||
.eq(LotteryTicket::getStatus, 1)
|
||||
.gt(LotteryTicket::getRemainingCount, 0)
|
||||
.orderByAsc(LotteryTicket::getExpireTime).list();
|
||||
int totalRemaining = tickets.stream().mapToInt(LotteryTicket::getRemainingCount).sum();
|
||||
ResponseAssert.isTrue(LotteryErrorCode.INSUFFICIENT_TICKETS, totalRemaining >= ticketCost);
|
||||
List<LotteryTicketRecord> records = new ArrayList<>();
|
||||
@ -478,7 +483,12 @@ public class LotteryMultiDrawExe {
|
||||
for (LotteryTicket ticket : tickets) {
|
||||
if (remaining <= 0) break;
|
||||
int deduct = Math.min(remaining, ticket.getRemainingCount());
|
||||
boolean updateSuccess = lotteryTicketService.update().eq(LotteryTicket::getId, ticket.getId()).eq(LotteryTicket::getRemainingCount, ticket.getRemainingCount()).setSql("used_count = used_count + " + deduct).setSql("remaining_count = remaining_count - " + deduct).execute();
|
||||
boolean updateSuccess = lotteryTicketService.update()
|
||||
.eq(LotteryTicket::getId, ticket.getId())
|
||||
.eq(LotteryTicket::getRemainingCount, ticket.getRemainingCount())
|
||||
.setSql("used_count = used_count + " + deduct)
|
||||
.setSql("remaining_count = remaining_count - " + deduct)
|
||||
.execute();
|
||||
ResponseAssert.isTrue(LotteryErrorCode.INSUFFICIENT_TICKETS, updateSuccess);
|
||||
LotteryTicketRecord ticketRecord = new LotteryTicketRecord();
|
||||
ticketRecord.setUserId(userId);
|
||||
|
||||
@ -19,11 +19,12 @@ public class LotteryTicketCountQryExe {
|
||||
|
||||
private final LotteryTicketService lotteryTicketService;
|
||||
|
||||
public Integer execute(AppExtCommand cmd) {
|
||||
public Integer execute(AppExtCommand cmd, Long activityId) {
|
||||
Long userId = cmd.requiredReqUserId();
|
||||
|
||||
List<LotteryTicket> tickets = lotteryTicketService.query()
|
||||
.eq(LotteryTicket::getUserId, userId)
|
||||
.eq(LotteryTicket::getActivityId, activityId)
|
||||
.eq(LotteryTicket::getStatus, 1)
|
||||
.gt(LotteryTicket::getRemainingCount, 0)
|
||||
.list();
|
||||
|
||||
@ -22,11 +22,12 @@ public class LotteryTicketQryExe {
|
||||
|
||||
private final LotteryTicketService lotteryTicketService;
|
||||
|
||||
public List<LotteryTicketCO> execute(AppExtCommand cmd) {
|
||||
public List<LotteryTicketCO> execute(AppExtCommand cmd, Long activityId) {
|
||||
Long userId = cmd.requiredReqUserId();
|
||||
|
||||
List<LotteryTicket> tickets = lotteryTicketService.query()
|
||||
.eq(LotteryTicket::getUserId, userId)
|
||||
.eq(LotteryTicket::getActivityId, activityId)
|
||||
.eq(LotteryTicket::getStatus, 1)
|
||||
.gt(LotteryTicket::getRemainingCount, 0)
|
||||
.orderByAsc(LotteryTicket::getExpireTime)
|
||||
|
||||
@ -18,11 +18,12 @@ public class MyTotalDrawCountQryExe {
|
||||
|
||||
private final LotteryTicketService lotteryTicketService;
|
||||
|
||||
public MyTotalDrawCountCO execute(AppExtCommand cmd) {
|
||||
public MyTotalDrawCountCO execute(AppExtCommand cmd, Long activityId) {
|
||||
Long userId = cmd.getReqUserId();
|
||||
|
||||
List<LotteryTicket> tickets = lotteryTicketService.query()
|
||||
.eq(LotteryTicket::getUserId, userId)
|
||||
.eq(LotteryTicket::getActivityId, activityId)
|
||||
.eq(LotteryTicket::getStatus, 1)
|
||||
.list();
|
||||
|
||||
|
||||
@ -84,18 +84,18 @@ public class LotteryActivityRestServiceImpl implements LotteryActivityRestServic
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LotteryTicketCO> listMyTickets(AppExtCommand cmd) {
|
||||
return lotteryTicketQryExe.execute(cmd);
|
||||
public List<LotteryTicketCO> listMyTickets(AppExtCommand cmd, Long activityId) {
|
||||
return lotteryTicketQryExe.execute(cmd, activityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getMyTicketCount(AppExtCommand cmd) {
|
||||
return lotteryTicketCountQryExe.execute(cmd);
|
||||
public Integer getMyTicketCount(AppExtCommand cmd, Long activityId) {
|
||||
return lotteryTicketCountQryExe.execute(cmd, activityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyTotalDrawCountCO getMyTotalDrawCount(AppExtCommand cmd) {
|
||||
return myTotalDrawCountQryExe.execute(cmd);
|
||||
public MyTotalDrawCountCO getMyTotalDrawCount(AppExtCommand cmd, Long activityId) {
|
||||
return myTotalDrawCountQryExe.execute(cmd, activityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -44,9 +44,4 @@ public class LotteryServiceImpl implements LotteryService {
|
||||
return lotteryDrawExe.execute(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LotteryTicketCO> listMyTickets(AppExtCommand cmd) {
|
||||
return lotteryTicketQryExe.execute(cmd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,4 +18,6 @@ public class SpinsTaskReceiveRewardCmd extends AppExtCommand {
|
||||
|
||||
@NotBlank(message = "任务编码不能为空")
|
||||
private String taskCode;
|
||||
|
||||
private Long activityId;
|
||||
}
|
||||
|
||||
@ -60,17 +60,17 @@ public interface LotteryActivityRestService {
|
||||
/**
|
||||
* 查询我的抽奖券.
|
||||
*/
|
||||
List<LotteryTicketCO> listMyTickets(AppExtCommand cmd);
|
||||
List<LotteryTicketCO> listMyTickets(AppExtCommand cmd, Long activityId);
|
||||
|
||||
/**
|
||||
* 获取抽奖券总数.
|
||||
*/
|
||||
Integer getMyTicketCount(AppExtCommand cmd);
|
||||
Integer getMyTicketCount(AppExtCommand cmd, Long activityId);
|
||||
|
||||
/**
|
||||
* 查询我的总抽奖次数.
|
||||
*/
|
||||
MyTotalDrawCountCO getMyTotalDrawCount(AppExtCommand cmd);
|
||||
MyTotalDrawCountCO getMyTotalDrawCount(AppExtCommand cmd, Long activityId);
|
||||
|
||||
/**
|
||||
* 查询排行榜.
|
||||
|
||||
@ -33,9 +33,4 @@ public interface LotteryService {
|
||||
*/
|
||||
LotteryDrawResultCO draw(LotteryDrawCmd cmd);
|
||||
|
||||
/**
|
||||
* 查询用户抽奖券.
|
||||
*/
|
||||
List<LotteryTicketCO> listMyTickets(AppExtCommand cmd);
|
||||
|
||||
}
|
||||
|
||||
@ -37,6 +37,12 @@ public class LotteryTicket implements Serializable {
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 活动ID.
|
||||
*/
|
||||
@TableField("activity_id")
|
||||
private Long activityId;
|
||||
|
||||
/**
|
||||
* 来源:SYSTEM-系统发放,ACTIVITY-活动赠送,PURCHASE-购买.
|
||||
*/
|
||||
|
||||
@ -36,8 +36,8 @@ public class LotteryTicketClientEndpoint implements LotteryTicketClientApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultResponse<Long> addTicket(Long userId, Integer count, String source, String sourceId) {
|
||||
Long result = lotteryTicketClientService.addTicket(userId, count, source, sourceId);
|
||||
public ResultResponse<Long> addTicket(Long userId, Long activityId, Integer count, String source, String sourceId) {
|
||||
Long result = lotteryTicketClientService.addTicket(userId, activityId, count, source, sourceId);
|
||||
return ResultResponse.success(result);
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +34,6 @@ public interface LotteryTicketClientService {
|
||||
* @param sourceId 来源ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
Long addTicket(Long userId, Integer count, String source, String sourceId);
|
||||
Long addTicket(Long userId, Long activityId, Integer count, String source, String sourceId);
|
||||
|
||||
}
|
||||
|
||||
@ -86,9 +86,10 @@ public class LotteryTicketClientServiceImpl implements LotteryTicketClientServic
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long addTicket(Long userId, Integer count, String source, String sourceId) {
|
||||
public Long addTicket(Long userId, Long activityId, Integer count, String source, String sourceId) {
|
||||
LotteryTicket ticket = new LotteryTicket();
|
||||
ticket.setUserId(userId);
|
||||
ticket.setActivityId(activityId);
|
||||
ticket.setTicketSource(source != null ? source : "SYSTEM");
|
||||
ticket.setSourceId(sourceId);
|
||||
ticket.setTotalCount(count);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user