魔法发送礼物和中奖后消费逻辑处理
This commit is contained in:
parent
078e53e937
commit
39f8c63620
@ -258,6 +258,12 @@ public class GiveAwayGiftBatchEvent implements Serializable {
|
|||||||
return Objects.nonNull(giftConfig) && Objects.equals(giftConfig.getGiftTab(), "ACTIVITY");
|
return Objects.nonNull(giftConfig) && Objects.equals(giftConfig.getGiftTab(), "ACTIVITY");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是魔法礼物.
|
||||||
|
*/
|
||||||
|
public boolean checkMagicGift() {
|
||||||
|
return Objects.nonNull(giftConfig) && Objects.equals(giftConfig.getGiftTab(), "MAGIC");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -58,7 +58,8 @@ public class LuckyGiftGiveCmdExe {
|
|||||||
|
|
||||||
// 判断版本号从而保证使用幸运礼物必须升级版本
|
// 判断版本号从而保证使用幸运礼物必须升级版本
|
||||||
ResponseAssert.isTrue(CommonErrorCode.NOT_ACCEPT_REQUEST,
|
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,
|
ResponseAssert.isTrue(ResponseErrorCode.REQUEST_PARAMETER_ERROR,
|
||||||
@ -72,9 +73,11 @@ public class LuckyGiftGiveCmdExe {
|
|||||||
// 付钱
|
// 付钱
|
||||||
WalletReceiptResDTO receipt = consumeCandy(cmd, giftConfig);
|
WalletReceiptResDTO receipt = consumeCandy(cmd, giftConfig);
|
||||||
|
|
||||||
// 礼物处理mq
|
// 礼物处理mq 魔法礼物不处理,放到中奖后处理
|
||||||
giftMqMessage.sendGift(receipt.getAssetRecordId().toString(),
|
if (!GiftTabEnum.MAGIC.name().equals(giftConfig.getGiftTab())) {
|
||||||
giftAppConvertor.toGiveAwayGiftBatchEvent(cmd, giftConfig, receipt.getAssetRecordId()));
|
giftMqMessage.sendGift(receipt.getAssetRecordId().toString(),
|
||||||
|
giftAppConvertor.toGiveAwayGiftBatchEvent(cmd, giftConfig, receipt.getAssetRecordId()));
|
||||||
|
}
|
||||||
|
|
||||||
// 抽奖mq
|
// 抽奖mq
|
||||||
gameLuckyGiftCommon.sendMq(cmd, giftConfig.getStandardId());
|
gameLuckyGiftCommon.sendMq(cmd, giftConfig.getStandardId());
|
||||||
|
|||||||
@ -6,8 +6,10 @@ import cn.hutool.http.HttpUtil;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
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.common.business.core.enums.SysOriginPlatformEnum;
|
||||||
import com.red.circle.component.mq.MessageEvent;
|
import com.red.circle.component.mq.MessageEvent;
|
||||||
import com.red.circle.component.mq.service.FixedTopic;
|
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.framework.core.dto.ReqSysOrigin;
|
||||||
import com.red.circle.mq.business.model.event.gift.GameLuckyGiftBusinessEvent;
|
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.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.service.MessageSenderService;
|
||||||
import com.red.circle.mq.rocket.business.streams.GameLuckyGiftBusinessSink;
|
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.convertor.user.UserProfileAppConvertor;
|
||||||
import com.red.circle.other.app.dto.clientobject.game.GameLuckyGiftMsgCO;
|
import com.red.circle.other.app.dto.clientobject.game.GameLuckyGiftMsgCO;
|
||||||
import com.red.circle.other.app.dto.cmd.activity.RankingDataUpdateCmd;
|
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.config.EnumConfigKey;
|
||||||
import com.red.circle.other.inner.enums.game.luckgift.GameLuckyGiftModeEnum;
|
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.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.enums.material.PropsCommodityType;
|
||||||
import com.red.circle.other.inner.model.dto.material.GiftConfigDTO;
|
import com.red.circle.other.inner.model.dto.material.GiftConfigDTO;
|
||||||
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
|
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
|
||||||
@ -75,6 +82,7 @@ import lombok.Data;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,6 +110,8 @@ public class GameLuckyGiftCommon {
|
|||||||
private final LuckyGiftProbabilityDetailsService luckyGiftProbabilityDetailsService;
|
private final LuckyGiftProbabilityDetailsService luckyGiftProbabilityDetailsService;
|
||||||
private final LuckyGiftApiConfig luckyGiftApiConfig;
|
private final LuckyGiftApiConfig luckyGiftApiConfig;
|
||||||
private final RankingActivityService rankingActivityService;
|
private final RankingActivityService rankingActivityService;
|
||||||
|
private final GiftMqMessage giftMqMessage;
|
||||||
|
private final GiftAppConvertor giftAppConvertor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送幸运礼物抽奖mq.
|
* 发送幸运礼物抽奖mq.
|
||||||
@ -204,7 +214,6 @@ public class GameLuckyGiftCommon {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public void run(GameLuckyGiftParamCmd cmd) {
|
public void run(GameLuckyGiftParamCmd cmd) {
|
||||||
// runLuckyGiftGame(cmd);
|
|
||||||
runLuckyGiftGameNew(cmd);
|
runLuckyGiftGameNew(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +234,60 @@ public class GameLuckyGiftCommon {
|
|||||||
Integer totalAwardAmount = apiResult.getOrderResults().stream().mapToInt(OrderResult::getRewardNum).sum();
|
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<GiveAwayGiftRoomAccepts> getAccepts(GameLuckyGiftParamCmd cmd) {
|
||||||
|
List<GiveAwayGiftRoomAccepts> 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();
|
long payAmount = param.getQuantity() * param.getGift().getGiftCandy().longValue();
|
||||||
int multiple = (int) (awardAmount / payAmount);
|
int multiple = (int) (awardAmount / payAmount);
|
||||||
@ -333,19 +395,6 @@ public class GameLuckyGiftCommon {
|
|||||||
.setRegionCode(param.getRoomRegionCode())
|
.setRegionCode(param.getRoomRegionCode())
|
||||||
.setDateNumber(ZonedDateTimeAsiaRiyadhUtils.nowDateToInt())
|
.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) {
|
private void getDataUpdateCmd(Long userId, Long actualAmount) {
|
||||||
|
|||||||
@ -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);
|
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);
|
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 {
|
} else {
|
||||||
// 普通礼物
|
// 普通礼物
|
||||||
acceptAssistRatio = calculateAcceptAssistRatio(event, acceptRegion);
|
acceptAssistRatio = calculateAcceptAssistRatio(event, acceptRegion);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user