Commit cfbe3b54 authored by zhangfeng's avatar zhangfeng

礼品过期校验

parent cde39899
......@@ -19,6 +19,7 @@ import cn.iocoder.yudao.module.reward.dal.mysql.redeem.RewardRedeemMapper;
import cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper;
import cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum;
import cn.iocoder.yudao.module.reward.enums.RewardStatusEnum;
import cn.iocoder.yudao.module.reward.service.reward.RewardService;
import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
......@@ -52,6 +53,8 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
@Resource
private RewardMapper rewardMapper;
@Resource
private RewardService rewardService;
@Resource
private RewardRedeemMapper rewardRedeemMapper;
@Resource
private MemberUserApi memberUserApi;
......@@ -67,7 +70,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean redeemReward(RedeemRewardReqVO redeemRewardReqVO) {
if (redeemRewardReqVO.getEntrance() != PlatformTypeEnum.BACKEND.getValue() && redeemRewardReqVO instanceof AppRedeemRewardReqVO){
if (redeemRewardReqVO.getEntrance() != PlatformTypeEnum.BACKEND.getValue() && redeemRewardReqVO instanceof AppRedeemRewardReqVO) {
AppRedeemRewardReqVO appRedeemRewardReqVO = (AppRedeemRewardReqVO) redeemRewardReqVO;
SmsCodeUseReqDTO smsCodeUseReqDTO = new SmsCodeUseReqDTO();
UserRespDTO memberUserApiUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId());
......@@ -86,7 +89,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
throw exception(REWARD_NOT_EXISTS);
}
// 礼品未开启
if (rewardDO.getStatus() != 1) {
if (rewardDO.getStatus() != RewardStatusEnum.ENABLED.getValue() || rewardService.validateExpire(rewardDO)) {
throw exception(REWARD_NOT_ENABLE);
}
// 礼品数量不够
......@@ -164,7 +167,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
// 查询礼品
RewardDO rewardDO = rewardMapper.selectById(rewardId);
// 礼品未开启
if (rewardDO.getStatus() != RewardStatusEnum.ENABLED.getValue()) {
if (rewardDO.getStatus() != RewardStatusEnum.ENABLED.getValue() || rewardService.validateExpire(rewardDO)) {
throw exception(REWARD_NOT_ENABLE);
}
int totalCount = 0;
......
......@@ -78,6 +78,7 @@ public interface RewardService extends IService<RewardDO> {
void updateStatus(RewardStatusReqVO statusVO);
Boolean validateExpire(RewardDO rewardDO);
/**
* 客户端获得礼品列表
* @param reqVO
......
......@@ -320,15 +320,17 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
/**
* 校验礼品是否过期并修改礼品状态
*/
private void validateExpire(RewardDO rewardDO) {
//TODO:异步更新礼品状态
public Boolean validateExpire(RewardDO rewardDO) {
if (rewardDO.getEndTime() != null) {
if (rewardDO.getStatus() == RewardStatusEnum.DISABLED.getValue() && rewardDO.getEndTime().toInstant().isBefore(Instant.now())) {
if (rewardDO.getStatus() == RewardStatusEnum.ENABLED.getValue() && rewardDO.getEndTime().toInstant().isBefore(Instant.now())) {
rewardDO.setStatus(RewardStatusEnum.EXPIRED.getValue());
RewardDO expireReward = new RewardDO();
expireReward.setId(rewardDO.getId());
expireReward.setStatus(RewardStatusEnum.EXPIRED.getValue());
rewardMapper.updateById(expireReward);
return true;
}
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment