Commit cfbe3b54 authored by zhangfeng's avatar zhangfeng

礼品过期校验

parent cde39899
...@@ -19,6 +19,7 @@ import cn.iocoder.yudao.module.reward.dal.mysql.redeem.RewardRedeemMapper; ...@@ -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.dal.mysql.reward.RewardMapper;
import cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum; import cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum;
import cn.iocoder.yudao.module.reward.enums.RewardStatusEnum; 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.SmsCodeApi;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
...@@ -52,6 +53,8 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -52,6 +53,8 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
@Resource @Resource
private RewardMapper rewardMapper; private RewardMapper rewardMapper;
@Resource @Resource
private RewardService rewardService;
@Resource
private RewardRedeemMapper rewardRedeemMapper; private RewardRedeemMapper rewardRedeemMapper;
@Resource @Resource
private MemberUserApi memberUserApi; private MemberUserApi memberUserApi;
...@@ -67,7 +70,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -67,7 +70,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean redeemReward(RedeemRewardReqVO redeemRewardReqVO) { 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; AppRedeemRewardReqVO appRedeemRewardReqVO = (AppRedeemRewardReqVO) redeemRewardReqVO;
SmsCodeUseReqDTO smsCodeUseReqDTO = new SmsCodeUseReqDTO(); SmsCodeUseReqDTO smsCodeUseReqDTO = new SmsCodeUseReqDTO();
UserRespDTO memberUserApiUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId()); UserRespDTO memberUserApiUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId());
...@@ -86,7 +89,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -86,7 +89,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
throw exception(REWARD_NOT_EXISTS); throw exception(REWARD_NOT_EXISTS);
} }
// 礼品未开启 // 礼品未开启
if (rewardDO.getStatus() != 1) { if (rewardDO.getStatus() != RewardStatusEnum.ENABLED.getValue() || rewardService.validateExpire(rewardDO)) {
throw exception(REWARD_NOT_ENABLE); throw exception(REWARD_NOT_ENABLE);
} }
// 礼品数量不够 // 礼品数量不够
...@@ -164,7 +167,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -164,7 +167,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
// 查询礼品 // 查询礼品
RewardDO rewardDO = rewardMapper.selectById(rewardId); 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); throw exception(REWARD_NOT_ENABLE);
} }
int totalCount = 0; int totalCount = 0;
......
...@@ -78,6 +78,7 @@ public interface RewardService extends IService<RewardDO> { ...@@ -78,6 +78,7 @@ public interface RewardService extends IService<RewardDO> {
void updateStatus(RewardStatusReqVO statusVO); void updateStatus(RewardStatusReqVO statusVO);
Boolean validateExpire(RewardDO rewardDO);
/** /**
* 客户端获得礼品列表 * 客户端获得礼品列表
* @param reqVO * @param reqVO
......
...@@ -320,15 +320,17 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i ...@@ -320,15 +320,17 @@ public class RewardServiceImpl extends AbstractService<RewardMapper, RewardDO> i
/** /**
* 校验礼品是否过期并修改礼品状态 * 校验礼品是否过期并修改礼品状态
*/ */
private void validateExpire(RewardDO rewardDO) { public Boolean validateExpire(RewardDO rewardDO) {
//TODO:异步更新礼品状态
if (rewardDO.getEndTime() != null) { 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(); RewardDO expireReward = new RewardDO();
expireReward.setId(rewardDO.getId()); expireReward.setId(rewardDO.getId());
expireReward.setStatus(RewardStatusEnum.EXPIRED.getValue()); expireReward.setStatus(RewardStatusEnum.EXPIRED.getValue());
rewardMapper.updateById(expireReward); 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