新增领取道具券功能

This commit is contained in:
tianfeng 2025-11-13 17:18:12 +08:00
parent f5c8dbc333
commit ad98917741
2 changed files with 31 additions and 10 deletions

View File

@ -15,7 +15,9 @@ import com.red.circle.other.domain.gateway.RocketConfigGateway;
import com.red.circle.other.domain.gateway.RocketHistoryGateway;
import com.red.circle.other.domain.gateway.RocketRewardLogGateway;
import com.red.circle.other.domain.gateway.RocketStatusGateway;
import com.red.circle.other.domain.propcoupon.PropCouponSource;
import com.red.circle.other.domain.rocket.*;
import com.red.circle.other.infra.common.props.PropsSendCommon;
import com.red.circle.other.infra.database.cache.key.RocketKeys;
import com.red.circle.other.inner.endpoint.material.props.BadgeBackpackClient;
import com.red.circle.other.inner.endpoint.material.props.PropsBackpackClient;
@ -23,6 +25,7 @@ import com.red.circle.other.inner.enums.material.BadgeBackpackExpireTypeEnum;
import com.red.circle.other.inner.enums.sys.SysBadgeConfigTypeEnum;
import com.red.circle.other.inner.model.cmd.material.GiveBadgeCmd;
import com.red.circle.other.inner.model.cmd.material.GivePropsBackpackCmd;
import com.red.circle.other.inner.model.cmd.material.PrizeDescribe;
import com.red.circle.other.inner.model.dto.material.PropsActivityRewardConfigInfoDTO;
import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient;
import com.red.circle.wallet.inner.model.cmd.GoldReceiptCmd;
@ -32,13 +35,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.*;
/**
* 火箭奖励领取命令执行器
@ -60,7 +61,7 @@ public class RocketRewardClaimCmdExe {
private final PropsBackpackClient propsBackpackClient;
private final BadgeBackpackClient badgeBackpackClient;
private final RocketHistoryGateway rocketHistoryGateway;
private final PropsSendCommon propsSendCommon;
private final Random random = new Random();
/**
@ -217,6 +218,10 @@ public class RocketRewardClaimCmdExe {
Integer quantity = reward.getQuantity() != null ? reward.getQuantity() : 1;
grantBadge(userId, badgeId, quantity, bizNo);
}
case "PROP_COUPON" -> {
Integer quantity = reward.getQuantity() != null ? reward.getQuantity() : 1;
grantPropCoupon(userId, reward.getContent(), quantity);
}
default -> throw new RuntimeException("不支持的奖励类型: " + rewardType);
}
@ -252,6 +257,22 @@ public class RocketRewardClaimCmdExe {
}
}
/**
* 发放道具
*/
private void grantPropCoupon(Long userId, String propId, Integer quantity) {
try {
PrizeDescribe prizeDescribe = new PrizeDescribe();
prizeDescribe.setContent(propId);
prizeDescribe.setQuantity(quantity);
propsSendCommon.sendPropCoupon(userId, PropCouponSource.ACTIVITY, List.of(prizeDescribe));
} catch (Exception e) {
log.error("道具券发放失败: userId={}, propId={}", userId, propId, e);
throw new RuntimeException("道具券发放失败");
}
}
/**
* 发放道具
*/

View File

@ -161,7 +161,7 @@ public class PropsSendCommon {
// 发放道具券
List<PrizeDescribe> coupons = filterPrize(cmd, PropsActivityRewardEnum.PROP_COUPON);
sendPropCoupon(cmd.getAcceptUserId(), coupons);
sendPropCoupon(cmd.getAcceptUserId(), PropCouponSource.ADMIN_GRANT, coupons);
saveSendLog(cmd);
}
@ -176,7 +176,7 @@ public class PropsSendCommon {
});
}
private void sendPropCoupon(Long acceptUserId, List<PrizeDescribe> coupons) {
public void sendPropCoupon(Long acceptUserId, PropCouponSource source, List<PrizeDescribe> coupons) {
coupons.forEach(prizeDescribe -> {
String content = prizeDescribe.getContent();
@ -191,7 +191,7 @@ public class PropsSendCommon {
grantCmd.setCouponType(couponType.getCode());
grantCmd.setValidDays(prizeDescribe.getQuantity());
List<PropCoupon> propCoupons = generateCoupons(grantCmd, couponType, Collections.singleton(acceptUserId));
List<PropCoupon> propCoupons = generateCoupons(grantCmd, source, couponType, Collections.singleton(acceptUserId));
// 5. 批量插入券记录
propCouponGateway.batchSave(propCoupons);
@ -474,7 +474,7 @@ public class PropsSendCommon {
/**
* 批量生成券
*/
private List<PropCoupon> generateCoupons(PropCouponGrantCmd cmd, PropCouponType couponType, Set<Long> userIds) {
private List<PropCoupon> generateCoupons(PropCouponGrantCmd cmd, PropCouponSource source, PropCouponType couponType, Set<Long> userIds) {
List<PropCoupon> propCoupons = new ArrayList<>();
LocalDateTime now = LocalDateTime.now();
LocalDateTime expireTime = now.plusDays(cmd.getValidDays());
@ -491,7 +491,7 @@ public class PropsSendCommon {
propCoupon.setPropName(displayPropName);
propCoupon.setValidDays(cmd.getValidDays());
propCoupon.setStatus(PropCouponStatus.UNUSED);
propCoupon.setSource(PropCouponSource.ADMIN_GRANT);
propCoupon.setSource(source);
propCoupon.setExpireTime(expireTime);
propCoupon.setCreateTime(now);
propCoupon.setUpdateTime(now);