diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java index ab46e731d..cb1b82335 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java @@ -41,6 +41,13 @@ public class WxCouponSend extends BaseEntity { @Transient public static final String KEY_MERCHANT_SEND = "merchantSend" ; + /** + * limit 商户注券数 + */ + @JsonIgnore + @Transient + public static final String KEY_MERCHANT_REMAIN = "merchantRemain" ; + /** * 排序-商户购券数 */ diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java index ea86e7ca4..730ef4185 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponSendService.java @@ -77,19 +77,19 @@ public interface WxCouponSendService { * 商户注券 库存减少 * * @param id 券ID - * @param merchantSend 当前已发数 + * @param merchantRemain 当前库存 * @param number 减少数量 */ - void reduceMerchantSend(Long id, Integer merchantSend, Integer number); + void reduceMerchantSend(Long id, Integer merchantRemain, Integer number); /** * 商户注券 库存退回 * * @param id 券ID - * @param merchantSend 当前已发数 + * @param merchantRemain 当前库存 * @param number 回退数量 */ - void backMerchantRemainInventory(Long id, Integer merchantSend, Integer number); + void backMerchantRemainInventory(Long id, Integer merchantRemain, 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 f584cd4f7..cc8626e42 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java @@ -131,6 +131,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { merchantLnventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY); merchantIdStr = jo.getString("id"); jo.put(WxCouponSend.KEY_MERCHANT_SEND,0) ; + jo.put(WxCouponSend.KEY_MERCHANT_REMAIN,merchantLnventory) ; record.setConditions(jo.toJSONString()); } catch (Exception e) { logger.error(" updateInvalid 解析异常:{}", e.getMessage()); @@ -181,20 +182,18 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { if (Objects.isNull(wxCouponOfDb)) { throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); } - //查询商家 - int merchantLnventory = 0, merchantSend = 0; + //查询商家库存和 + int merchantRemain = 0; try { JSONObject jo = JSONObject.parseObject(record.getConditions()); - merchantLnventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY); - merchantSend = jo.getIntValue(WxCouponSend.KEY_MERCHANT_SEND); + merchantRemain = jo.getIntValue(WxCouponSend.KEY_MERCHANT_REMAIN); } catch (Exception e) { logger.error(" updateInvalid 解析异常:{}", e.getMessage()); } - if (0 >= merchantLnventory || 0 > merchantSend) { - throw new MallinkException(ErrorCode.COUPON_SEND_LIMIT_VERIFY); - } //退回coupon库存 - wxCouponService.backRemainInventory(queryById.getId(), wxCouponOfDb.getRemainInventory(), merchantLnventory - merchantSend); + if(merchantRemain!=0) { + wxCouponService.backRemainInventory(queryById.getId(), wxCouponOfDb.getRemainInventory(), merchantRemain); + } } wxCouponSendMapper.updateByPrimaryKeySelective(record); } @@ -569,16 +568,16 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { } @Override - public void reduceMerchantSend(Long id, Integer merchantSend, Integer number) { - int num = wxCouponSendMapper.reduceMerchantSend(id, merchantSend, number); + public void reduceMerchantSend(Long id, Integer merchantRemain, Integer number) { + int num = wxCouponSendMapper.reduceMerchantSend(id, merchantRemain, number); if (num == 0) { throw new MallinkException(ErrorCode.ORDER_IS_FAIL); } } @Override - public void backMerchantRemainInventory(Long id, Integer merchantSend, Integer number) { - int num = wxCouponSendMapper.backMerchantSend(id, merchantSend, number); + public void backMerchantRemainInventory(Long id, Integer merchantRemain, Integer number) { + int num = wxCouponSendMapper.backMerchantSend(id, merchantRemain, 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 97e1b9f02..98ac6553a 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 remainInventory, Integer number) { - int num = wxCouponMapper.backRemainInventory(id, remainInventory, number); + public void backRemainInventory(Long id, Integer merchantSend, Integer number) { + int num = wxCouponMapper.backRemainInventory(id, merchantSend, 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 ea1ece0e3..de236d1ca 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -321,10 +321,10 @@ 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); // 检查 优惠券 库存 - if (merchantLnventory - merchantSend <= 0) { + if (merchantRemain <= 0) { //解锁 redisLock.unlock(couponIdStr, timeStr); logger.error("此券库存为0, couponId: " + couponIdStr); @@ -366,7 +366,7 @@ public class WxOrderServiceImpl implements WxOrderService { try { // 减库存 - wxCouponSendService.reduceMerchantSend(wxCouponSendVo.getId(), merchantSend, 1); + wxCouponSendService.reduceMerchantSend(wxCouponSendVo.getId(), merchantRemain, 1); } catch (RuntimeException e) { logger.error("此券减库存失败, couponId: " + couponIdStr); throw new MallinkException(ErrorCode.ORDER_IS_FAIL); diff --git a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml index 36d4e2baa..903265871 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml @@ -164,9 +164,9 @@ ((c.status = 1) or (c.valid_type = 1 and c.valid_end_date < now())) - update wx_coupon_send SET conditions = JSON_SET(conditions,'$.merchantSend',#{merchantSend} + #{number}) where id = #{id} and conditions->'$.merchantSend' = #{merchantSend} + 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,'$.merchantSend',#{merchantSend} - #{number}) where id = #{id} and conditions->'$.merchantSend' = #{merchantSend} + update wx_coupon_send SET conditions = JSON_SET(conditions,'$.merchantRemain',#{merchantRemain} + #{number}) where id = #{id} and conditions->'$.merchantRemain' = #{merchantRemain}