Commit 3a84402f authored by zhangfeng's avatar zhangfeng

客户端兑换礼品

parent 9bf98be2
...@@ -10,6 +10,8 @@ public class RedeemRewardRespDTO { ...@@ -10,6 +10,8 @@ public class RedeemRewardRespDTO {
@ApiModelProperty(value = "兑换操作结果") @ApiModelProperty(value = "兑换操作结果")
private Boolean exchangeResult; private Boolean exchangeResult;
@ApiModelProperty(value = "兑换操作详情") @ApiModelProperty(value = "兑换操作详情中文")
private String msg; private String msgZh;
@ApiModelProperty(value = "兑换操作详情英文")
private String msgEn;
} }
...@@ -61,28 +61,28 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -61,28 +61,28 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
// 查询礼品 // 查询礼品
RewardDO rewardDO = rewardMapper.selectById(redeemRewardReqVO.getRewardId()); RewardDO rewardDO = rewardMapper.selectById(redeemRewardReqVO.getRewardId());
if (rewardDO == null) { if (rewardDO == null) {
throw exception(REWARD_NOT_EXISTS); return getRedeemResp(false, "礼品不存在", "reward do not exist!");
} }
// 礼品未开启 // 礼品未开启
if (rewardDO.getStatus() != 1) { if (rewardDO.getStatus() != 1) {
throw exception(REWARD_NOT_ENABLE); return getRedeemResp(false, "礼品未开启", "reward do not enable!");
} }
// 礼品数量不够 // 礼品数量不够
if (rewardDO.getQuantityRemain() < redeemRewardReqVO.getRewardCount()) { if (rewardDO.getQuantityRemain() < redeemRewardReqVO.getRewardCount()) {
throw exception(REWARD_COUNT_NOT_ENOUGH); return getRedeemResp(false, "礼品数量不够", "reward do not enough!");
} }
// 兑换方式不匹配 // 兑换方式不匹配
String pickMethod = rewardDO.getPickMethod(); String pickMethod = rewardDO.getPickMethod();
String[] split = pickMethod.split(","); String[] split = pickMethod.split(",");
if (!Arrays.asList(split).contains(String.valueOf(redeemRewardReqVO.getRedeemType()))) { if (!Arrays.asList(split).contains(String.valueOf(redeemRewardReqVO.getRedeemType()))) {
throw exception(REWARD_PICK_METHOD_NOT_ALLOW_CREATE); return getRedeemResp(false, "兑换方式不支持", "redeem type do not support!");
} }
verifyMemberUser(redeemRewardReqVO, rewardDO); verifyMemberUser(redeemRewardReqVO, rewardDO);
String lockKey = "reward:redeem:lock:" + redeemRewardReqVO.getRewardId(); String lockKey = "reward:redeem:lock:" + redeemRewardReqVO.getRewardId();
RLock lock = redissonClient.getLock(lockKey); RLock lock = redissonClient.getLock(lockKey);
try { try {
if (!lock.tryLock(2, 10, TimeUnit.SECONDS)) { if (!lock.tryLock(2, 10, TimeUnit.SECONDS)) {
throw exception(GET_LOCK_FAILED); return getRedeemResp(false, "系统繁忙,请稍后再试", "The service is busy, please try again later");
} }
// 添加兑换记录 // 添加兑换记录
Long redeemId = addRedeemRecord(redeemRewardReqVO, rewardDO); Long redeemId = addRedeemRecord(redeemRewardReqVO, rewardDO);
...@@ -91,11 +91,19 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -91,11 +91,19 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
// 更新礼品 // 更新礼品
redeemReward(rewardDO, redeemRewardReqVO.getRewardCount()); redeemReward(rewardDO, redeemRewardReqVO.getRewardCount());
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw exception(GET_LOCK_FAILED); return getRedeemResp(false, "系统繁忙,请稍后再试", "The service is busy, please try again later");
} finally { } finally {
lock.unlock(); lock.unlock();
} }
return null; return getRedeemResp(true, "兑换成功!", "redeem success!");
}
private RedeemRewardRespDTO getRedeemResp(Boolean exchangeResult, String msgZh, String msgEn) {
RedeemRewardRespDTO redeemRewardRespDTO = new RedeemRewardRespDTO();
redeemRewardRespDTO.setExchangeResult(false);
redeemRewardRespDTO.setMsgZh(msgZh);
redeemRewardRespDTO.setMsgEn(msgEn);
return redeemRewardRespDTO;
} }
private void redeemReward(RewardDO reward, Integer rewardCount) { private void redeemReward(RewardDO reward, Integer rewardCount) {
......
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