diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/OtherErrorCode.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/OtherErrorCode.java index 78268457..b2d6fb2d 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/OtherErrorCode.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/OtherErrorCode.java @@ -209,6 +209,8 @@ public enum OtherErrorCode implements IResponseErrorCode { * 签到操作频繁 */ SIGN_IN_OPERATION_TOO_FREQUENT(3286, "Sign-in operation too frequent, please try again later"), + + CONSECUTIVE_REWARD(3287, "Consecutive Check-in Reward!"), ; private final int code; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/signin/SignCheckInExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/signin/SignCheckInExe.java index b2a00c47..619bcdfb 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/signin/SignCheckInExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/signin/SignCheckInExe.java @@ -16,6 +16,7 @@ import com.red.circle.other.infra.database.rds.entity.UserSignInRecord; import com.red.circle.other.infra.database.rds.entity.activity.PropsActivityRewardConfig; import com.red.circle.other.infra.database.rds.service.activity.PropsActivityRewardConfigService; import com.red.circle.other.inner.asserts.OtherErrorCode; +import com.red.circle.other.inner.endpoint.activity.LotteryTicketClient; import com.red.circle.other.inner.model.cmd.material.PrizeDescribe; import com.red.circle.other.inner.model.cmd.material.PrizeDescribeRewardCmd; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; @@ -30,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.DayOfWeek; import java.time.LocalDate; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -43,6 +45,9 @@ public class SignCheckInExe { private final WalletGoldClient walletGoldClient; private final PropsSendCommon propsSendCommon; private final PropsActivityRewardConfigService propsActivityRewardConfigService; + private final LotteryTicketClient lotteryTicketClient; + + private final static Long FIXED_ACTIVITY_ID = 2004471533988167125L; @Transactional(rollbackFor = Exception.class) public CheckInResultCO execute(CheckInCmd cmd) { @@ -70,7 +75,7 @@ public class SignCheckInExe { .eq(UserSignInRecord::getWeekStartDate, weekStartDate) .eq(UserSignInRecord::getDayIndex, i) ); - ResponseAssert.isTrue(OtherErrorCode.SIGN_IN_NEED_PREVIOUS, count > 0); + ResponseAssert.isTrue(OtherErrorCode.CONSECUTIVE_REWARD, count > 0); } SignInDailyConfig config = dailyConfigDAO.selectList( @@ -101,6 +106,9 @@ public class SignCheckInExe { sendReward(userId, config); + // 发放抽奖券 + sendLotteryTickets(userId, config, record.getId()); + CheckInResultCO resultCO = new CheckInResultCO(); resultCO.setSuccess(true); resultCO.setMessage("Sign-in successful"); @@ -148,4 +156,30 @@ public class SignCheckInExe { .setQuantity(config.getQuantity()))) ); } + + /** + * 发放抽奖券 + */ + private void sendLotteryTickets(Long userId, SignInDailyConfig config, Long trackId) { + if (config.getLotteryTicketCount() == null || config.getLotteryTicketCount() <= 0) { + return; + } + + try { + for (int i = 0; i < config.getLotteryTicketCount(); i++) { + Long ticketId = lotteryTicketClient.addTicket( + userId, + FIXED_ACTIVITY_ID, + 1, + "SIGN_IN", + "SIGN_IN_DAY_" + config.getDayIndex() + ).getBody(); + } + } catch (Exception e) { + log.error("发放签到抽奖券失败, userId={}, dayIndex={}, count={}", + userId, config.getDayIndex(), config.getLotteryTicketCount(), e); + throw new RuntimeException("Failed to send lottery tickets"); + } + } + } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/signin/SupplementCheckInExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/signin/SupplementCheckInExe.java index 52116510..362eb276 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/signin/SupplementCheckInExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/signin/SupplementCheckInExe.java @@ -15,6 +15,7 @@ import com.red.circle.other.infra.database.rds.entity.UserSignInRecord; import com.red.circle.other.infra.database.rds.entity.activity.PropsActivityRewardConfig; import com.red.circle.other.infra.database.rds.service.activity.PropsActivityRewardConfigService; import com.red.circle.other.inner.asserts.OtherErrorCode; +import com.red.circle.other.inner.endpoint.activity.LotteryTicketClient; import com.red.circle.other.inner.model.cmd.material.PrizeDescribe; import com.red.circle.other.inner.model.cmd.material.PrizeDescribeRewardCmd; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; @@ -42,6 +43,9 @@ public class SupplementCheckInExe { private final WalletGoldClient walletGoldClient; private final PropsSendCommon propsSendCommon; private final PropsActivityRewardConfigService propsActivityRewardConfigService; + private final LotteryTicketClient lotteryTicketClient; + + private final static Long FIXED_ACTIVITY_ID = 2004471533988167125L; private static final int BASE_SUPPLEMENT_COST = 500; @@ -105,6 +109,9 @@ public class SupplementCheckInExe { sendReward(userId, config); + // 发放抽奖券 + sendLotteryTickets(userId, config, record.getId()); + CheckInResultCO resultCO = new CheckInResultCO(); resultCO.setSuccess(true); resultCO.setMessage("Make-up successful"); @@ -153,4 +160,31 @@ public class SupplementCheckInExe { .setQuantity(config.getQuantity()))) ); } + + + /** + * 发放抽奖券 + */ + private void sendLotteryTickets(Long userId, SignInDailyConfig config, Long trackId) { + if (config.getLotteryTicketCount() == null || config.getLotteryTicketCount() <= 0) { + return; + } + + try { + for (int i = 0; i < config.getLotteryTicketCount(); i++) { + Long ticketId = lotteryTicketClient.addTicket( + userId, + FIXED_ACTIVITY_ID, + 1, + "SIGN_IN", + "SIGN_IN_DAY_" + config.getDayIndex() + ).getBody(); + } + } catch (Exception e) { + log.error("发放签到抽奖券失败, userId={}, dayIndex={}, count={}", + userId, config.getDayIndex(), config.getLotteryTicketCount(), e); + throw new RuntimeException("Failed to send lottery tickets"); + } + } + } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/SignInDailyConfig.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/SignInDailyConfig.java index ed897fe5..ba6acc17 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/SignInDailyConfig.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/SignInDailyConfig.java @@ -23,6 +23,11 @@ public class SignInDailyConfig { private Integer paidCost; + /** + * 抽奖券数量 + */ + private Integer lotteryTicketCount; + private Long resourceGroupId; private LocalDateTime createTime;