From 39f8c6362005660ccc70c7e09c2cf2610881b0fc Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 22 Jan 2026 17:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AD=94=E6=B3=95=E5=8F=91=E9=80=81=E7=A4=BC?= =?UTF-8?q?=E7=89=A9=E5=92=8C=E4=B8=AD=E5=A5=96=E5=90=8E=E6=B6=88=E8=B4=B9?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/gift/GiveAwayGiftBatchEvent.java | 6 ++ .../app/command/gift/LuckyGiftGiveCmdExe.java | 11 ++- .../app/common/gift/GameLuckyGiftCommon.java | 81 +++++++++++++++---- .../app/listener/gift/GiveGiftsListener.java | 5 ++ 4 files changed, 83 insertions(+), 20 deletions(-) diff --git a/rc-common-business/common-business-mq/business-mq-model/src/main/java/com/red/circle/mq/business/model/event/gift/GiveAwayGiftBatchEvent.java b/rc-common-business/common-business-mq/business-mq-model/src/main/java/com/red/circle/mq/business/model/event/gift/GiveAwayGiftBatchEvent.java index d45a9371..c2ea005c 100644 --- a/rc-common-business/common-business-mq/business-mq-model/src/main/java/com/red/circle/mq/business/model/event/gift/GiveAwayGiftBatchEvent.java +++ b/rc-common-business/common-business-mq/business-mq-model/src/main/java/com/red/circle/mq/business/model/event/gift/GiveAwayGiftBatchEvent.java @@ -258,6 +258,12 @@ public class GiveAwayGiftBatchEvent implements Serializable { return Objects.nonNull(giftConfig) && Objects.equals(giftConfig.getGiftTab(), "ACTIVITY"); } + /** + * 是否是魔法礼物. + */ + public boolean checkMagicGift() { + return Objects.nonNull(giftConfig) && Objects.equals(giftConfig.getGiftTab(), "MAGIC"); + } /** diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/LuckyGiftGiveCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/LuckyGiftGiveCmdExe.java index 552d17c0..0ab9de07 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/LuckyGiftGiveCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/LuckyGiftGiveCmdExe.java @@ -58,7 +58,8 @@ public class LuckyGiftGiveCmdExe { // 判断版本号从而保证使用幸运礼物必须升级版本 ResponseAssert.isTrue(CommonErrorCode.NOT_ACCEPT_REQUEST, - Objects.equals(giftConfig.getGiftTab(), GiftTabEnum.LUCKY_GIFT.name())); + Objects.equals(giftConfig.getGiftTab(), GiftTabEnum.LUCKY_GIFT.name()) || + Objects.equals(giftConfig.getGiftTab(), GiftTabEnum.MAGIC.name())); // 过滤赠送人非法值 ResponseAssert.isTrue(ResponseErrorCode.REQUEST_PARAMETER_ERROR, @@ -72,9 +73,11 @@ public class LuckyGiftGiveCmdExe { // 付钱 WalletReceiptResDTO receipt = consumeCandy(cmd, giftConfig); - // 礼物处理mq - giftMqMessage.sendGift(receipt.getAssetRecordId().toString(), - giftAppConvertor.toGiveAwayGiftBatchEvent(cmd, giftConfig, receipt.getAssetRecordId())); + // 礼物处理mq 魔法礼物不处理,放到中奖后处理 + if (!GiftTabEnum.MAGIC.name().equals(giftConfig.getGiftTab())) { + giftMqMessage.sendGift(receipt.getAssetRecordId().toString(), + giftAppConvertor.toGiveAwayGiftBatchEvent(cmd, giftConfig, receipt.getAssetRecordId())); + } // 抽奖mq gameLuckyGiftCommon.sendMq(cmd, giftConfig.getStandardId()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/gift/GameLuckyGiftCommon.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/gift/GameLuckyGiftCommon.java index ca61672c..63f89f0e 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/gift/GameLuckyGiftCommon.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/gift/GameLuckyGiftCommon.java @@ -6,8 +6,10 @@ import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.google.common.collect.Lists; import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; import com.red.circle.component.mq.MessageEvent; import com.red.circle.component.mq.service.FixedTopic; @@ -19,8 +21,12 @@ import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.dto.ReqSysOrigin; import com.red.circle.mq.business.model.event.gift.GameLuckyGiftBusinessEvent; import com.red.circle.mq.business.model.event.gift.GameLuckyGiftUser; +import com.red.circle.mq.business.model.event.gift.GiveAwayGiftBatchEvent; +import com.red.circle.mq.business.model.event.gift.GiveAwayGiftRoomAccepts; +import com.red.circle.mq.rocket.business.producer.GiftMqMessage; import com.red.circle.mq.rocket.business.service.MessageSenderService; import com.red.circle.mq.rocket.business.streams.GameLuckyGiftBusinessSink; +import com.red.circle.other.app.convertor.material.GiftAppConvertor; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.game.GameLuckyGiftMsgCO; import com.red.circle.other.app.dto.cmd.activity.RankingDataUpdateCmd; @@ -50,6 +56,7 @@ import com.red.circle.other.infra.database.rds.service.sys.EnumConfigService; import com.red.circle.other.inner.enums.config.EnumConfigKey; import com.red.circle.other.inner.enums.game.luckgift.GameLuckyGiftModeEnum; import com.red.circle.other.inner.enums.game.luckgift.GameLuckyGiftMultipleEnum; +import com.red.circle.other.inner.enums.material.GiftTabEnum; import com.red.circle.other.inner.enums.material.PropsCommodityType; import com.red.circle.other.inner.model.dto.material.GiftConfigDTO; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; @@ -75,6 +82,7 @@ import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Component; /** @@ -102,6 +110,8 @@ public class GameLuckyGiftCommon { private final LuckyGiftProbabilityDetailsService luckyGiftProbabilityDetailsService; private final LuckyGiftApiConfig luckyGiftApiConfig; private final RankingActivityService rankingActivityService; + private final GiftMqMessage giftMqMessage; + private final GiftAppConvertor giftAppConvertor; /** * 发送幸运礼物抽奖mq. @@ -204,7 +214,6 @@ public class GameLuckyGiftCommon { */ public void run(GameLuckyGiftParamCmd cmd) { -// runLuckyGiftGame(cmd); runLuckyGiftGameNew(cmd); } @@ -225,7 +234,60 @@ public class GameLuckyGiftCommon { Integer totalAwardAmount = apiResult.getOrderResults().stream().mapToInt(OrderResult::getRewardNum).sum(); // 保存幸运礼物流水 - sendMessageNew(param, Long.valueOf(String.valueOf(totalAwardAmount))); + Long rewardAmount = Long.valueOf(String.valueOf(totalAwardAmount)); + saveLuckGiftCount(param, rewardAmount); + + if (totalAwardAmount <= 0) { + return; + } + + // 发送中奖金币 + BigDecimal balance = sendGold(param.getUserId(), param.getSysOrigin(), rewardAmount); + + // 发送中奖通知 + int multiple = getRewardMultiple(param, rewardAmount); + sendMsg(param, multiple, balance, rewardAmount); + + // 魔法礼物中奖后处理 + GiftConfigDTO giftConfigDTO = getGiftConfigDTO(cmd.getGiftId()); + if (GiftTabEnum.MAGIC.name().equals(giftConfigDTO.getGiftTab())) { + String timeId = IdWorker.getIdStr(); + GiveAwayGiftBatchEvent giftBatchEvent = buildGiftBatchEvent(cmd, timeId, param, giftConfigDTO); + + giftMqMessage.sendGift(timeId, giftBatchEvent); + } + + } + + @NotNull + private GiveAwayGiftBatchEvent buildGiftBatchEvent(GameLuckyGiftParamCmd cmd, String timeId, + GameLuckyGiftParam param, GiftConfigDTO giftConfigDTO) { + return new GiveAwayGiftBatchEvent() + .setSysOrigin(SysOriginPlatformEnum.valueOf(param.getSysOrigin())) + .setRequestPlatform("Android") + .setSendUserId(cmd.getUserId()) + .setAccepts(getAccepts(cmd)) + .setQuantity(cmd.getQuantity()) + .setGiftConfig(giftAppConvertor.toGiveGiftConfig(giftConfigDTO)) + .setRoomId(cmd.getRoomId()) + .setTrackId(Long.parseLong(timeId)) + .setBagGift(Boolean.FALSE) + .setCreateTime(TimestampUtils.now()); + + } + + + private List getAccepts(GameLuckyGiftParamCmd cmd) { + List accepts = new ArrayList<>(); + accepts.add(new GiveAwayGiftRoomAccepts() + .setAcceptUserId(cmd.getAcceptUserId())); + return accepts; + } + + + private static int getRewardMultiple(GameLuckyGiftParam param, Long rewardAmount) { + long payAmount = param.getQuantity() * param.getGift().getGiftCandy().longValue(); + return (int) (rewardAmount / payAmount); } /** @@ -310,7 +372,7 @@ public class GameLuckyGiftCommon { /** * 处理用户连续赠送幸运礼物奖励逻辑 */ - private void sendMessageNew(GameLuckyGiftParam param, Long awardAmount) { + private void saveLuckGiftCount(GameLuckyGiftParam param, Long awardAmount) { long payAmount = param.getQuantity() * param.getGift().getGiftCandy().longValue(); int multiple = (int) (awardAmount / payAmount); @@ -333,19 +395,6 @@ public class GameLuckyGiftCommon { .setRegionCode(param.getRoomRegionCode()) .setDateNumber(ZonedDateTimeAsiaRiyadhUtils.nowDateToInt()) ); - - if (awardAmount <= 0) { - return; - } - - // 发送中奖金币 - BigDecimal balance = sendGold(param.getUserId(), param.getSysOrigin(), awardAmount); - -// getDataUpdateCmd(param.getUserId(), awardAmount); - - // 发送中奖通知 - sendMsg(param, multiple, balance, awardAmount); - } private void getDataUpdateCmd(Long userId, Long actualAmount) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/GiveGiftsListener.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/GiveGiftsListener.java index f7037ddf..84c93853 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/GiveGiftsListener.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/GiveGiftsListener.java @@ -530,6 +530,11 @@ public class GiveGiftsListener implements MessageListener { targetAmount = giftValue.getGiftValue().multiply(acceptAssistRatio.multiply(new BigDecimal("10")).min(new BigDecimal("0.7"))).setScale(0, RoundingMode.DOWN); acceptAmount = giftValue.getGiftValue().multiply(acceptAssistRatio).setScale(0, RoundingMode.DOWN); + } else if (event.checkMagicGift()) { + // 魔法礼物 + acceptAssistRatio = new BigDecimal("0.1"); + targetAmount = giftValue.getGiftValue().multiply(acceptAssistRatio).setScale(0, RoundingMode.DOWN); + acceptAmount = giftValue.getGiftValue().multiply(acceptAssistRatio).setScale(0, RoundingMode.DOWN); } else { // 普通礼物 acceptAssistRatio = calculateAcceptAssistRatio(event, acceptRegion);