diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java index c9bceb231..82b322a85 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java @@ -21,18 +21,20 @@ public interface WxCouponSendMapper extends CommonMapper { * 商户注券 库存减少 * * @param id 券ID + * @param merchantRemain 当前库存 * @param merchantSend 当前已发数 * @param number 减少数量 */ - Integer reduceMerchantSend(Long id, Integer merchantSend, Integer number); + Integer reduceMerchantSend(Long id, Integer merchantRemain,Integer merchantSend,Integer number); /** * 商户注券 库存退回 * * @param id 券ID + * @param merchantRemain 当前库存 * @param merchantSend 当前已发数 * @param number 回退数量 */ - Integer backMerchantSend(Long id, Integer merchantSend, Integer number); + Integer backMerchantSend(Long id, Integer merchantRemain, Integer merchantSend,Integer number); } diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java index 730ef4185..456964729 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java @@ -78,18 +78,20 @@ public interface WxCouponSendService { * * @param id 券ID * @param merchantRemain 当前库存 + * @param merchantSend 当前已发 * @param number 减少数量 */ - void reduceMerchantSend(Long id, Integer merchantRemain, Integer number); + void reduceMerchantSend(Long id, Integer merchantRemain, Integer merchantSend ,Integer number); /** * 商户注券 库存退回 * * @param id 券ID * @param merchantRemain 当前库存 + * @param merchantSend 当前已发 * @param number 回退数量 */ - void backMerchantRemainInventory(Long id, Integer merchantRemain, Integer number); + void backMerchantRemainInventory(Long id, Integer merchantRemain, Integer merchantSend ,Integer number); void handSel(WxCouponSend wxCouponSend, WxCUser user) ; diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java index cc8626e42..63390dfe8 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java @@ -126,8 +126,9 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { //商户注券 参数校验 int merchantLnventory = 0; String merchantIdStr = null; + JSONObject jo; try { - JSONObject jo = JSONObject.parseObject(record.getConditions()); + jo = JSONObject.parseObject(record.getConditions()); merchantLnventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY); merchantIdStr = jo.getString("id"); jo.put(WxCouponSend.KEY_MERCHANT_SEND,0) ; @@ -568,16 +569,16 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { } @Override - public void reduceMerchantSend(Long id, Integer merchantRemain, Integer number) { - int num = wxCouponSendMapper.reduceMerchantSend(id, merchantRemain, number); + public void reduceMerchantSend(Long id, Integer merchantRemain, Integer merchantSend ,Integer number) { + int num = wxCouponSendMapper.reduceMerchantSend(id, merchantRemain, merchantSend,number); if (num == 0) { throw new MallinkException(ErrorCode.ORDER_IS_FAIL); } } @Override - public void backMerchantRemainInventory(Long id, Integer merchantRemain, Integer number) { - int num = wxCouponSendMapper.backMerchantSend(id, merchantRemain, number); + public void backMerchantRemainInventory(Long id, Integer merchantRemain, Integer merchantSend, Integer number) { + int num = wxCouponSendMapper.backMerchantSend(id, merchantRemain, merchantSend,number); if (num == 0) { throw new MallinkException(ErrorCode.ORDER_IS_FAIL); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index 98ac6553a..97e1b9f02 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -655,8 +655,8 @@ import java.util.stream.Collectors; @Override @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) - public void backRemainInventory(Long id, Integer merchantSend, Integer number) { - int num = wxCouponMapper.backRemainInventory(id, merchantSend, number); + public void backRemainInventory(Long id, Integer remainInventory, Integer number) { + int num = wxCouponMapper.backRemainInventory(id, remainInventory, number); if (num == 0) { throw new MallinkException(ErrorCode.REMAIN_BACK_FAIL); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java index de236d1ca..28cf2a7bf 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -320,7 +320,7 @@ public class WxOrderServiceImpl implements WxOrderService { } JSONObject jo = JSONObject.parseObject(wxCouponSendVo.getConditions()) ; - int merchantLnventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY) ; + int merchantSend = jo.getIntValue(WxCouponSend.KEY_MERCHANT_SEND) ; int merchantRemain = jo.getIntValue(WxCouponSend.KEY_MERCHANT_REMAIN); // 检查 优惠券 库存 @@ -366,9 +366,9 @@ public class WxOrderServiceImpl implements WxOrderService { try { // 减库存 - wxCouponSendService.reduceMerchantSend(wxCouponSendVo.getId(), merchantRemain, 1); + wxCouponSendService.reduceMerchantSend(wxCouponSendVo.getId(), merchantRemain,merchantSend,1); } catch (RuntimeException e) { - logger.error("此券减库存失败, couponId: " + couponIdStr); + logger.error("此券减库存失败, couponId: {}, error: {}", couponIdStr, e.getMessage()); throw new MallinkException(ErrorCode.ORDER_IS_FAIL); } finally { //解锁 diff --git a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml index 903265871..c1b3f51aa 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml @@ -164,9 +164,17 @@ ((c.status = 1) or (c.valid_type = 1 and c.valid_end_date < now())) - update wx_coupon_send SET conditions = JSON_SET(conditions,'$.merchantRemain',#{merchantRemain} - #{number}) where id = #{id} and conditions->'$.merchantRemain' = #{merchantRemain} + update wx_coupon_send + SET conditions = JSON_SET(conditions, '$.merchantRemain', #{merchantRemain} - #{number} , '$.merchantSend', + #{merchantSend} + #{number}) + where id = #{id} + and conditions -> '$.merchantRemain' = #{merchantRemain} - update wx_coupon_send SET conditions = JSON_SET(conditions,'$.merchantRemain',#{merchantRemain} + #{number}) where id = #{id} and conditions->'$.merchantRemain' = #{merchantRemain} + update wx_coupon_send + SET conditions = JSON_SET(conditions, '$.merchantRemain', #{merchantRemain} + #{number} , '$.merchantSend', + #{merchantSend} - #{number}) + where id = #{id} + and conditions -> '$.merchantRemain' = #{merchantRemain}