From 8c77513e383dc5a6c1dcd9dc18d20961c4917808 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 15 Jan 2026 17:55:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=A5=96=E6=96=B0=E5=A2=9E=E9=87=91?= =?UTF-8?q?=E5=B8=81=E6=8A=BD=E5=A5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wallet/inner/model/enums/GoldOrigin.java | 5 +++ .../app/command/activity/LotteryDrawExe.java | 33 +++++++++++++++++-- .../command/activity/LotteryMultiDrawExe.java | 30 +++++++++++++++-- .../app/dto/cmd/activity/LotteryDrawCmd.java | 4 +++ .../dto/cmd/activity/LotteryMultiDrawCmd.java | 5 +++ .../rds/entity/activity/LotteryActivity.java | 13 ++++++++ 6 files changed, 85 insertions(+), 5 deletions(-) diff --git a/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/GoldOrigin.java b/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/GoldOrigin.java index f3208aec..542e9c2a 100644 --- a/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/GoldOrigin.java +++ b/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/GoldOrigin.java @@ -757,6 +757,11 @@ public enum GoldOrigin { * 签到补签 */ SIGN_IN_SUPPLEMENT("Sign-in supplement"), + + /** + * cp抽奖 + */ + CP_LOTTERY("CP lottery"), ; private final String desc; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryDrawExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryDrawExe.java index 6d24d6a3..7da20ed0 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryDrawExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryDrawExe.java @@ -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 tickets = lotteryTicketService.query() .eq(LotteryTicket::getUserId, userId) .eq(LotteryTicket::getActivityId, activityId) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryMultiDrawExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryMultiDrawExe.java index 6b3ff5ec..aca560ae 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryMultiDrawExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryMultiDrawExe.java @@ -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) diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryDrawCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryDrawCmd.java index c7a350b6..810e8e3d 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryDrawCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryDrawCmd.java @@ -23,4 +23,8 @@ public class LotteryDrawCmd extends AppExtCommand { @NotNull(message = "activityId required.") private Long activityId; + /** + * 是否需要金币 + */ + private Boolean needCoins; } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryMultiDrawCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryMultiDrawCmd.java index 1c7ddb2f..219518df 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryMultiDrawCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryMultiDrawCmd.java @@ -35,4 +35,9 @@ public class LotteryMultiDrawCmd extends AppExtCommand { @Max(value = 10, message = "drawCount must <= 10") private Integer drawCount; + /** + * 是否需要金币 + */ + private Boolean needCoins; + } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/activity/LotteryActivity.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/activity/LotteryActivity.java index e3bde15a..775390ce 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/activity/LotteryActivity.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/activity/LotteryActivity.java @@ -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; + + /** * 排序. */