From 32b3d894b7cfaefb321d78a87f9756d9dc9b7558 Mon Sep 17 00:00:00 2001 From: cloudroam <cloudroam> Date: 星期三, 04 九月 2024 11:18:55 +0800 Subject: [PATCH] add:会员保存成长值空值处理 --- src/main/java/com/mzl/flower/service/payment/OrderService.java | 96 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 66 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/mzl/flower/service/payment/OrderService.java b/src/main/java/com/mzl/flower/service/payment/OrderService.java index ca0a23a..9660450 100644 --- a/src/main/java/com/mzl/flower/service/payment/OrderService.java +++ b/src/main/java/com/mzl/flower/service/payment/OrderService.java @@ -43,6 +43,7 @@ import com.mzl.flower.service.flower.FlowerService; import com.mzl.flower.service.menber.MemberGrowthRecordService; import com.mzl.flower.service.point.CustomerPointService; +import com.mzl.flower.service.point.PointGoodsService; import com.mzl.flower.service.system.CodeService; import com.mzl.flower.service.system.WeChatService; import com.mzl.flower.service.transport.TransportService; @@ -147,47 +148,74 @@ @Autowired private CustomerPointService customerPointService; + @Autowired + private PointGoodsService pointGoodsService; + + @Autowired + private RedisLockService lockService; + public void changeFlower2Cart(CartSaveDTO dto) { String userId = SecurityUtils.getUserId(); - Cart c = cartMapper.selectOne(new QueryWrapper<Cart>() - .eq("create_by", userId).eq("flower_id", dto.getId())); - if (c == null) { - if (dto.getNum() <= 0) { - throw new ValidationException("数量不能小于等于0,请刷新页面重试"); - } - c = new Cart(); - c.setFlowerId(dto.getId()); - c.setNum(dto.getNum()); - c.create(userId); + String key = userId + "_" + dto.getId(); + boolean lock = lockService.getObjectLock(RedisLockService.LOCK_KEY_CART_, key); + if(!lock){ + return; + } - cartMapper.insert(c); - } else { - c.setNum(c.getNum() + dto.getNum()); - c.update(userId); - if (c.getNum() <= 0) { - cartMapper.deleteById(c.getId()); + try { + Cart c = cartMapper.selectOne(new QueryWrapper<Cart>() + .eq("create_by", userId).eq("flower_id", dto.getId())); + if (c == null) { + if (dto.getNum() <= 0) { + throw new ValidationException("数量不能小于等于0,请刷新页面重试"); + } + c = new Cart(); + c.setFlowerId(dto.getId()); + c.setNum(dto.getNum()); + c.create(userId); + + cartMapper.insert(c); } else { - cartMapper.updateById(c); + c.setNum(c.getNum() + dto.getNum()); + c.update(userId); + if (c.getNum() <= 0) { + cartMapper.deleteById(c.getId()); + } else { + cartMapper.updateById(c); + } } + } finally { + lockService.releaseObjectLock(RedisLockService.LOCK_KEY_CART_, key); } } public void saveFlower2Cart(CartSaveDTO dto) { String userId = SecurityUtils.getUserId(); - Cart c = cartMapper.selectOne(new QueryWrapper<Cart>() - .eq("create_by", userId).eq("flower_id", dto.getId())); - if (c == null) { - c = new Cart(); - c.setFlowerId(dto.getId()); - c.setNum(dto.getNum()); - c.create(userId); - cartMapper.insert(c); - } else { - c.setNum(dto.getNum()); - c.update(userId); + String key = userId + "_" + dto.getId(); + boolean lock = lockService.getObjectLock(RedisLockService.LOCK_KEY_CART_, key); + if(!lock){ + return; + } - cartMapper.updateById(c); + try { + Cart c = cartMapper.selectOne(new QueryWrapper<Cart>() + .eq("create_by", userId).eq("flower_id", dto.getId())); + if (c == null) { + c = new Cart(); + c.setFlowerId(dto.getId()); + c.setNum(dto.getNum()); + c.create(userId); + + cartMapper.insert(c); + } else { + c.setNum(dto.getNum()); + c.update(userId); + + cartMapper.updateById(c); + } + } finally { + lockService.releaseObjectLock(RedisLockService.LOCK_KEY_CART_, key); } } @@ -503,7 +531,12 @@ } private void usePointGoods(String orderId, List<Long> goodsRecordIdList){ - //TODO 使用积分商品兑换券 + //使用积分商品兑换券 + if(goodsRecordIdList != null && goodsRecordIdList.size() > 0){ + for(Long grId : goodsRecordIdList){ + pointGoodsService.useExchangeGoods(grId, orderId); + } + } } /** @@ -949,6 +982,9 @@ if(checkList != null && checkList.size() > 0){ for(OrderItemCheck c : checkList){ + if(Constants.CHECK_TYPE.replace.name().equals(c.getType())){ + continue; + } totalAmount = totalAmount.subtract(getAmount(c.getDeductAmount())); } } -- Gitblit v1.9.3