Commit e3dea02c authored by zhangfeng's avatar zhangfeng

feat(redeem): 记录用户兑换前积分

parent e275c3aa
...@@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemDetailForUserDTO; ...@@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemDetailForUserDTO;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO; import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO; import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
...@@ -25,8 +26,9 @@ public interface RedeemRewardApi { ...@@ -25,8 +26,9 @@ public interface RedeemRewardApi {
* @param redeemRewardReqVO * @param redeemRewardReqVO
* @param pointsRequire * @param pointsRequire
* @param rewardId * @param rewardId
* @param holdScore
*/ */
void executeRedeem(RedeemRewardReqVO redeemRewardReqVO, Integer pointsRequire, Long rewardId); void executeRedeem(RedeemRewardReqVO redeemRewardReqVO, Integer pointsRequire, Long rewardId, Integer holdScore);
/** /**
* 批量兑换礼品 * 批量兑换礼品
...@@ -42,8 +44,9 @@ public interface RedeemRewardApi { ...@@ -42,8 +44,9 @@ public interface RedeemRewardApi {
* @param redeemRewardReqVOList * @param redeemRewardReqVOList
* @param pointsRequire * @param pointsRequire
* @param rewardId * @param rewardId
* @param holdScoreMap
*/ */
void batchExecuteRedeem(List<RedeemRewardReqVO> redeemRewardReqVOList, Integer pointsRequire, Long rewardId); void batchExecuteRedeem(List<RedeemRewardReqVO> redeemRewardReqVOList, Integer pointsRequire, Long rewardId, HashMap<Long, Integer> holdScoreMap);
/** /**
* 客户端获取礼品详情 * 客户端获取礼品详情
......
...@@ -102,7 +102,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -102,7 +102,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
throw exception(GET_LOCK_FAILED); throw exception(GET_LOCK_FAILED);
} }
RedeemRewardApi currentProxy = (RedeemRewardApi) AopContext.currentProxy(); RedeemRewardApi currentProxy = (RedeemRewardApi) AopContext.currentProxy();
currentProxy.executeRedeem(redeemRewardReqVO, rewardDO.getPointsRequire(), rewardDO.getId()); currentProxy.executeRedeem(redeemRewardReqVO, rewardDO.getPointsRequire(), rewardDO.getId(), memberUser.getHoldScore());
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw exception(GET_LOCK_FAILED); throw exception(GET_LOCK_FAILED);
} finally { } finally {
...@@ -113,9 +113,9 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -113,9 +113,9 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void executeRedeem(RedeemRewardReqVO redeemRewardReqVO, Integer pointsRequire, Long rewardId) { public void executeRedeem(RedeemRewardReqVO redeemRewardReqVO, Integer pointsRequire, Long rewardId, Integer holdScore) {
// 添加兑换记录 // 添加兑换记录
RewardRedeemDO redeemRecord = addRedeemRecord(redeemRewardReqVO, pointsRequire); RewardRedeemDO redeemRecord = addRedeemRecord(redeemRewardReqVO, pointsRequire, holdScore);
// 更新会员积分 // 更新会员积分
updateMemberScore(redeemRewardReqVO, pointsRequire, redeemRecord.getId(), redeemRecord.getRedemptionNumber()); updateMemberScore(redeemRewardReqVO, pointsRequire, redeemRecord.getId(), redeemRecord.getRedemptionNumber());
// 更新礼品 // 更新礼品
...@@ -187,11 +187,12 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -187,11 +187,12 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
.build()); .build());
} }
private RewardRedeemDO addRedeemRecord(RedeemRewardReqVO redeemRewardReqVO, Integer pointsRequire) { private RewardRedeemDO addRedeemRecord(RedeemRewardReqVO redeemRewardReqVO, Integer pointsRequire, Integer holdScore) {
RewardRedeemDO rewardRedeemDO = BeanUtil.copyProperties(redeemRewardReqVO, RewardRedeemDO.class); RewardRedeemDO rewardRedeemDO = BeanUtil.copyProperties(redeemRewardReqVO, RewardRedeemDO.class);
rewardRedeemDO.setId(snowflakeGenerator.next()); rewardRedeemDO.setId(snowflakeGenerator.next());
rewardRedeemDO.setRedemptionNumber(rewardGenCodeUtils.generateRedemptionNumber()); rewardRedeemDO.setRedemptionNumber(rewardGenCodeUtils.generateRedemptionNumber());
rewardRedeemDO.setStatus(RewardRedeemStatusEnum.REDEEMING.getValue()); rewardRedeemDO.setStatus(RewardRedeemStatusEnum.REDEEMING.getValue());
rewardRedeemDO.setHoldScoreBeforeRedeem(holdScore);
rewardRedeemDO.setScoreCount(redeemRewardReqVO.getRewardCount() * pointsRequire); rewardRedeemDO.setScoreCount(redeemRewardReqVO.getRewardCount() * pointsRequire);
rewardRedeemMapper.insert(rewardRedeemDO); rewardRedeemMapper.insert(rewardRedeemDO);
return rewardRedeemDO; return rewardRedeemDO;
...@@ -214,6 +215,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -214,6 +215,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
throw exception(REWARD_NOT_ENABLE); throw exception(REWARD_NOT_ENABLE);
} }
int totalCount = 0; int totalCount = 0;
HashMap<Long, Integer> holdScoreMap = new HashMap<>();
for (RedeemRewardReqVO redeemRewardReqVO : redeemRewardReqVOList) { for (RedeemRewardReqVO redeemRewardReqVO : redeemRewardReqVOList) {
UserRespDTO memberUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId()); UserRespDTO memberUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId());
if (memberUser == null) { if (memberUser == null) {
...@@ -230,6 +232,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -230,6 +232,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
} }
} }
verifyMemberUser(redeemRewardReqVO, rewardDO, memberUser.getHoldScore()); verifyMemberUser(redeemRewardReqVO, rewardDO, memberUser.getHoldScore());
holdScoreMap.put(redeemRewardReqVO.getMemberId(), memberUser.getHoldScore());
// 记录兑换总数 // 记录兑换总数
totalCount += redeemRewardReqVO.getRewardCount(); totalCount += redeemRewardReqVO.getRewardCount();
// 判断兑换总数是否大于礼物数量 // 判断兑换总数是否大于礼物数量
...@@ -244,7 +247,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -244,7 +247,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
throw exception(GET_LOCK_FAILED); throw exception(GET_LOCK_FAILED);
} }
RedeemRewardApi currentProxy = (RedeemRewardApi) AopContext.currentProxy(); RedeemRewardApi currentProxy = (RedeemRewardApi) AopContext.currentProxy();
currentProxy.batchExecuteRedeem(redeemRewardReqVOList, rewardDO.getPointsRequire(), rewardDO.getId()); currentProxy.batchExecuteRedeem(redeemRewardReqVOList, rewardDO.getPointsRequire(), rewardDO.getId(), holdScoreMap);
} catch (ServiceException e) { } catch (ServiceException e) {
log.error("batch redeem rewards exception:{}", e.getMessage()); log.error("batch redeem rewards exception:{}", e.getMessage());
throw e; throw e;
...@@ -258,9 +261,9 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -258,9 +261,9 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void batchExecuteRedeem(List<RedeemRewardReqVO> redeemRewardReqVOList, Integer pointsRequire, Long rewardId) { public void batchExecuteRedeem(List<RedeemRewardReqVO> redeemRewardReqVOList, Integer pointsRequire, Long rewardId, HashMap<Long, Integer> holdScoreMap) {
for (RedeemRewardReqVO redeemRewardReqVO : redeemRewardReqVOList) { for (RedeemRewardReqVO redeemRewardReqVO : redeemRewardReqVOList) {
executeRedeem(redeemRewardReqVO, pointsRequire, rewardId); executeRedeem(redeemRewardReqVO, pointsRequire, rewardId, holdScoreMap.get(redeemRewardReqVO.getMemberId()));
} }
} }
......
...@@ -37,6 +37,13 @@ public class RewardRedeemDO extends BaseDO { ...@@ -37,6 +37,13 @@ public class RewardRedeemDO extends BaseDO {
* 兑换状态 * 兑换状态
*/ */
private Integer status; private Integer status;
/**
* 兑换前持有的积分
*/
private Integer holdScoreBeforeRedeem;
/**
* 兑换消耗积分数量
*/
private Integer scoreCount; private Integer scoreCount;
/** /**
* 兑换数量 * 兑换数量
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</select> </select>
<select id="detail" resultType="cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageRespVO"> <select id="detail" resultType="cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageRespVO">
select select
mus.hold_score as holdScore, err.hold_score_before_redeem as holdScore,
er.points_require as pointsRequire, er.points_require as pointsRequire,
er.start_time as startTime, er.start_time as startTime,
er.end_time as endTime, er.end_time as endTime,
......
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