抽奖新增金币抽奖
This commit is contained in:
parent
1b5fc22d7f
commit
8c77513e38
@ -757,6 +757,11 @@ public enum GoldOrigin {
|
||||
* 签到补签
|
||||
*/
|
||||
SIGN_IN_SUPPLEMENT("Sign-in supplement"),
|
||||
|
||||
/**
|
||||
* cp抽奖
|
||||
*/
|
||||
CP_LOTTERY("CP lottery"),
|
||||
;
|
||||
|
||||
private final String desc;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.red.circle.other.app.command.activity;
|
||||
|
||||
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
|
||||
import com.red.circle.component.redis.service.RedisService;
|
||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.LotteryDrawResultCO;
|
||||
@ -39,6 +40,10 @@ import java.util.Locale;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.red.circle.tool.core.tuple.PennyAmount;
|
||||
import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient;
|
||||
import com.red.circle.wallet.inner.model.cmd.GoldReceiptCmd;
|
||||
import com.red.circle.wallet.inner.model.enums.GoldOrigin;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@ -68,6 +73,7 @@ public class LotteryDrawExe {
|
||||
private final LatestMobileDeviceService latestMobileDeviceService;
|
||||
private final LotteryDeviceRecordService lotteryDeviceRecordService;
|
||||
private final UserActivityRechargeService userActivityRechargeService;
|
||||
private final WalletGoldClient walletGoldClient;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public LotteryDrawResultCO execute(LotteryDrawCmd cmd) {
|
||||
@ -87,8 +93,14 @@ public class LotteryDrawExe {
|
||||
// 4. 查询用户充值金额(用于过滤美元奖励)
|
||||
BigDecimal userRechargeAmount = getUserRechargeAmount(userId, activityId);
|
||||
|
||||
// 5. 校验并扣除抽奖券(如果需要)
|
||||
deductTicket(userId, activity.getId(), activity.getTicketCost());
|
||||
if (Boolean.TRUE.equals(cmd.getNeedCoins()) &&
|
||||
Boolean.TRUE.equals(activity.getNeedCoins())) {
|
||||
deductUserGold(userId, activity);
|
||||
} else {
|
||||
// 5. 校验并扣除抽奖券
|
||||
deductTicket(userId, activity);
|
||||
}
|
||||
|
||||
|
||||
// 6. 获取或创建用户进度(用于动态概率)
|
||||
LotteryUserProgress progress = getOrCreateUserProgress(userId, activityId);
|
||||
@ -126,6 +138,18 @@ public class LotteryDrawExe {
|
||||
return convertToResultCO(record, prize);
|
||||
}
|
||||
|
||||
private void deductUserGold(Long userId, LotteryActivity activity) {
|
||||
GoldReceiptCmd build = GoldReceiptCmd.builder()
|
||||
.appIncome()
|
||||
.userId(userId)
|
||||
.amount(PennyAmount.ofDollar(activity.getCoinCost().longValue()))
|
||||
.eventId(activity.getId())
|
||||
.sysOrigin(SysOriginPlatformEnum.LIKEI)
|
||||
.origin(GoldOrigin.CP_LOTTERY)
|
||||
.build();
|
||||
ResponseAssert.requiredSuccess(walletGoldClient.changeBalance(build));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验设备唯一性(防止小号薅羊毛)
|
||||
*/
|
||||
@ -470,7 +494,10 @@ public class LotteryDrawExe {
|
||||
/**
|
||||
* 扣除抽奖券.
|
||||
*/
|
||||
private void deductTicket(Long userId, Long activityId, Integer ticketCost) {
|
||||
private void deductTicket(Long userId, LotteryActivity activity) {
|
||||
Long activityId = activity.getId();
|
||||
Integer ticketCost = activity.getTicketCost();
|
||||
|
||||
List<LotteryTicket> tickets = lotteryTicketService.query()
|
||||
.eq(LotteryTicket::getUserId, userId)
|
||||
.eq(LotteryTicket::getActivityId, activityId)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.red.circle.other.app.command.activity;
|
||||
|
||||
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
|
||||
import com.red.circle.component.redis.service.RedisService;
|
||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.LotteryDrawResultCO;
|
||||
@ -37,6 +38,11 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.red.circle.tool.core.tuple.PennyAmount;
|
||||
import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient;
|
||||
import com.red.circle.wallet.inner.model.cmd.GoldReceiptCmd;
|
||||
import com.red.circle.wallet.inner.model.enums.GoldOrigin;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@ -66,6 +72,7 @@ public class LotteryMultiDrawExe {
|
||||
private final LatestMobileDeviceService latestMobileDeviceService;
|
||||
private final LotteryDeviceRecordService lotteryDeviceRecordService;
|
||||
private final UserActivityRechargeService userActivityRechargeService;
|
||||
private final WalletGoldClient walletGoldClient;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public LotteryMultiDrawResultCO execute(LotteryMultiDrawCmd cmd) {
|
||||
@ -94,8 +101,15 @@ public class LotteryMultiDrawExe {
|
||||
Integer ticketCost = activity.getMultiDrawTicketCost() != null
|
||||
? activity.getMultiDrawTicketCost()
|
||||
: drawCount * activity.getTicketCost();
|
||||
|
||||
deductTicket(userId, activityId, ticketCost);
|
||||
|
||||
if (Boolean.TRUE.equals(cmd.getNeedCoins()) &&
|
||||
Boolean.TRUE.equals(activity.getNeedCoins())) {
|
||||
// 扣除用户金币
|
||||
Integer amount = activity.getCoinCost() * (drawCount - 1);
|
||||
deductUserGold(userId, activityId, amount);
|
||||
} else {
|
||||
deductTicket(userId, activityId, ticketCost);
|
||||
}
|
||||
|
||||
// 7. 获取或创建用户进度(用于动态概率)
|
||||
LotteryUserProgress progress = getOrCreateUserProgress(userId, activityId);
|
||||
@ -504,6 +518,18 @@ public class LotteryMultiDrawExe {
|
||||
}
|
||||
}
|
||||
|
||||
private void deductUserGold(Long userId, Long activityId, Integer amount) {
|
||||
GoldReceiptCmd build = GoldReceiptCmd.builder()
|
||||
.appIncome()
|
||||
.userId(userId)
|
||||
.amount(PennyAmount.ofDollar(amount.longValue()))
|
||||
.eventId(activityId)
|
||||
.sysOrigin(SysOriginPlatformEnum.LIKEI)
|
||||
.origin(GoldOrigin.CP_LOTTERY)
|
||||
.build();
|
||||
ResponseAssert.requiredSuccess(walletGoldClient.changeBalance(build));
|
||||
}
|
||||
|
||||
private boolean deductPrizeStock(Long prizeId) {
|
||||
return lotteryPrizeService.update()
|
||||
.eq(LotteryPrize::getId, prizeId)
|
||||
|
||||
@ -23,4 +23,8 @@ public class LotteryDrawCmd extends AppExtCommand {
|
||||
@NotNull(message = "activityId required.")
|
||||
private Long activityId;
|
||||
|
||||
/**
|
||||
* 是否需要金币
|
||||
*/
|
||||
private Boolean needCoins;
|
||||
}
|
||||
|
||||
@ -35,4 +35,9 @@ public class LotteryMultiDrawCmd extends AppExtCommand {
|
||||
@Max(value = 10, message = "drawCount must <= 10")
|
||||
private Integer drawCount;
|
||||
|
||||
/**
|
||||
* 是否需要金币
|
||||
*/
|
||||
private Boolean needCoins;
|
||||
|
||||
}
|
||||
|
||||
@ -104,6 +104,19 @@ public class LotteryActivity implements Serializable {
|
||||
@TableField("ticket_cost")
|
||||
private Integer ticketCost;
|
||||
|
||||
/**
|
||||
* 是否需要金币:0-否,1-是.
|
||||
*/
|
||||
@TableField("need_coins")
|
||||
private Boolean needCoins;
|
||||
|
||||
/**
|
||||
* 每次消耗金币的数量.
|
||||
*/
|
||||
@TableField("coin_cost")
|
||||
private Integer coinCost;
|
||||
|
||||
|
||||
/**
|
||||
* 排序.
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user