每日任务领取奖励增加VIP额外奖励逻辑
This commit is contained in:
parent
b5747387bd
commit
f1fb151d7e
@ -9,24 +9,34 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand;
|
||||
import com.red.circle.common.business.enums.SendPropsOrigin;
|
||||
import com.red.circle.component.redis.service.RedisService;
|
||||
import com.red.circle.other.app.dto.task.TaskDTO;
|
||||
import com.red.circle.other.domain.enums.VipBenefitType;
|
||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||
import com.red.circle.other.infra.database.rds.dao.task.TaskConfigDAO;
|
||||
import com.red.circle.other.infra.database.rds.dao.task.UserTaskProgressDAO;
|
||||
import com.red.circle.other.infra.database.rds.entity.activity.PropsActivityRewardConfig;
|
||||
import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord;
|
||||
import com.red.circle.other.infra.database.rds.entity.task.TaskConfig;
|
||||
import com.red.circle.other.infra.database.rds.entity.task.UserTaskProgress;
|
||||
import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService;
|
||||
import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService;
|
||||
import com.red.circle.other.infra.database.rds.service.activity.PropsActivityRewardConfigService;
|
||||
import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService;
|
||||
import com.red.circle.other.infra.database.rds.service.user.user.ConsumptionLevelService;
|
||||
import com.red.circle.other.inner.endpoint.activity.PropsActivityClient;
|
||||
import com.red.circle.other.inner.model.cmd.activity.SendActivityRewardCmd;
|
||||
import com.red.circle.other.inner.model.dto.activity.props.ActivityPropsGroup;
|
||||
import com.red.circle.other.inner.model.dto.activity.props.ActivityRewardProps;
|
||||
import com.red.circle.tool.core.date.TimestampUtils;
|
||||
import com.red.circle.tool.core.sequence.IdWorkerUtils;
|
||||
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.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -42,6 +52,11 @@ public class TaskServiceImpl implements TaskService {
|
||||
private final UserTaskProgressDAO userTaskProgressDao;
|
||||
private final PropsActivityClient propsActivityCnfClient;
|
||||
private final RedisService redisService;
|
||||
private final PropsActivityRewardConfigService propsActivityRewardConfigService;
|
||||
private final PropsSourceRecordService propsSourceRecordService;
|
||||
private final ConsumptionLevelService consumptionLevelService;
|
||||
private final WalletGoldClient walletGoldClient;
|
||||
private final UserProfileGateway userProfileGateway;
|
||||
|
||||
/**
|
||||
* 获取任务列表
|
||||
@ -318,14 +333,18 @@ public class TaskServiceImpl implements TaskService {
|
||||
UserTaskProgress userTaskProgress = userTaskProgresses.get(0);
|
||||
|
||||
// 发送道具
|
||||
Long sourceGroupId = taskConfigs.get(0).getRewardId();
|
||||
propsActivityCnfClient.sendActivityReward(new SendActivityRewardCmd()
|
||||
.setTrackId(IdWorkerUtils.getId())
|
||||
.setSysOrigin(SysOriginPlatformEnum.valueOf(cmd.getReqSysOrigin().getOrigin()))
|
||||
.setAcceptUserId(cmd.getReqUserId())
|
||||
.setSourceGroupId(taskConfigs.get(0).getRewardId())
|
||||
.setSourceGroupId(sourceGroupId)
|
||||
.setOrigin(SendPropsOrigin.DAILY_TASK_REWARD)
|
||||
);
|
||||
|
||||
//如果是VIP 发送额外金额和经验值
|
||||
sendVipExtraReward(sourceGroupId, cmd);
|
||||
|
||||
userTaskProgress.setIsRewardCollected(1);
|
||||
userTaskProgress.setCompletedTime(TimestampUtils.now());
|
||||
userTaskProgressDao.updateById(userTaskProgress);
|
||||
@ -337,6 +356,50 @@ public class TaskServiceImpl implements TaskService {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendVipExtraReward(Long sourceGroupId, AppExtCommand cmd) {
|
||||
Long acceptUserId = cmd.getReqUserId();
|
||||
List<PropsActivityRewardConfig> configs = propsActivityRewardConfigService.listByGroupId(sourceGroupId);
|
||||
if (configs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BigDecimal benefit = userProfileGateway.getUserVipBenefit(acceptUserId, VipBenefitType.XP_RATE);
|
||||
|
||||
for (PropsActivityRewardConfig rewardConfig : configs) {
|
||||
if ("GOLD".equalsIgnoreCase(rewardConfig.getType())) {
|
||||
long baseGold = Long.parseLong(rewardConfig.getContent());
|
||||
long extraGold = new BigDecimal(baseGold).multiply(benefit)
|
||||
.setScale(0, RoundingMode.DOWN).longValue() - baseGold;
|
||||
|
||||
if (extraGold <= 0) {
|
||||
continue;
|
||||
}
|
||||
walletGoldClient.changeBalance(GoldReceiptCmd.builder()
|
||||
.appIncome()
|
||||
.userId(acceptUserId)
|
||||
.eventId(acceptUserId + "_vip_extra")
|
||||
.sysOrigin(SysOriginPlatformEnum.valueOf(cmd.getReqSysOrigin().getOrigin()))
|
||||
.origin(GoldOrigin.CP_REWARD)
|
||||
.originDescribe(SendPropsOrigin.DAILY_TASK_REWARD.getDesc())
|
||||
.amount(PennyAmount.ofPenny(extraGold))
|
||||
.build());
|
||||
|
||||
} else if ("CUSTOMIZE".equalsIgnoreCase(rewardConfig.getType())) {
|
||||
long baseExp = rewardConfig.getQuantity();
|
||||
long extraExp = new BigDecimal(baseExp).multiply(benefit)
|
||||
.setScale(0, RoundingMode.DOWN).longValue() - baseExp;
|
||||
|
||||
if (extraExp <= 0) {
|
||||
continue;
|
||||
}
|
||||
PropsSourceRecord props = propsSourceRecordService.getPropsById(Long.parseLong(rewardConfig.getContent()));
|
||||
if (Objects.nonNull(props) && "EXP".equalsIgnoreCase(props.getCode())) {
|
||||
consumptionLevelService.incrConsumptionDiamond(acceptUserId, BigDecimal.valueOf(extraExp));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务列表V2(优化版)
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user