From e16c61080c475135f4665368ab0001eb7c91e9ec Mon Sep 17 00:00:00 2001 From: Burce Date: Fri, 30 Aug 2019 15:40:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E6=88=B7=E6=B3=A8=E5=88=B8->=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=BA=93=E5=AD=98=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/iformall/domain/po/WxCouponSend.java | 6 ++++ .../iformall/mapper/WxCouponSendMapper.java | 8 ++--- .../iformall/service/WxCouponSendService.java | 8 ++--- .../service/impl/WxCouponSendServiceImpl.java | 30 ++++++++++++------- .../impl/WxCreditHistoryServiceImpl.java | 4 +-- .../service/impl/WxOrderServiceImpl.java | 5 ++-- .../mapper/WxCouponActionLogMapper.xml | 4 ++- .../resources/mapper/WxCouponSendMapper.xml | 8 ++--- 8 files changed, 46 insertions(+), 27 deletions(-) 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 a05388604..a24f17bdb 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java @@ -32,6 +32,12 @@ public class WxCouponSend extends BaseEntity { @Transient public static final String KEY_MERCHANT_LNVENTORY = "merchantLnventory" ; + /** + * limit 商户注券数 + */ + @Transient + public static final String KEY_MERCHANT_SEND = "merchantSend" ; + @Id protected Long id; diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java index 04767920c..33dd66b5a 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java @@ -20,18 +20,18 @@ public interface WxCouponSendMapper extends CommonMapper { * 商户注券 库存减少 * * @param id 券ID - * @param remainInventory 当前库存 + * @param merchantSend 当前已发数 * @param number 减少数量 */ - Integer reduceMerchantRemainInventory(Long id, Integer remainInventory, Integer number); + Integer reduceMerchantSend(Long id, Integer merchantSend, Integer number); /** * 商户注券 库存退回 * * @param id 券ID - * @param remainInventory 当前库存 + * @param merchantSend 当前已发数 * @param number 回退数量 */ - Integer backMerchantRemainInventory(Long id, Integer remainInventory, Integer number); + Integer backMerchantSend(Long id, 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 fec6f59ac..ea86e7ca4 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 remainInventory 当前库存 + * @param merchantSend 当前已发数 * @param number 减少数量 */ - void reduceMerchantRemainInventory(Long id, Integer remainInventory, Integer number); + void reduceMerchantSend(Long id, Integer merchantSend, Integer number); /** * 商户注券 库存退回 * * @param id 券ID - * @param remainInventory 当前库存 + * @param merchantSend 当前已发数 * @param number 回退数量 */ - void backMerchantRemainInventory(Long id, Integer remainInventory, Integer number); + void backMerchantRemainInventory(Long id, 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 9040be663..34a0bfcf1 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java @@ -99,7 +99,8 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { //商户卡库存校验 if (Objects.equals(record.getSendType(), EnumCouponSendSendType.MERCHANT.getCode())) { JSONObject jo = JSONObject.parseObject(record.getConditions()); - if (Objects.isNull(jo) || !jo.containsKey(WxCouponSend.KEY_MERCHANT_LNVENTORY)) { + int merchantLnventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY); + if (0 >= merchantLnventory) { throw new MallinkException(ErrorCode.COUPON_SEND_LIMIT_VERIFY); } //查询总库存 @@ -123,7 +124,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { //if (Objects.isNull(couponMerchant)) { // throw new MallinkException(ErrorCode.COUPON_MERCHANT_NOT_FOUND); //} - int merchantLnventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY); + //商家购券数不能大于总库存 if (merchantLnventory > wxCouponOfDb.getRemainInventory()) { throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); @@ -156,13 +157,19 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); } //查询商家 - JSONObject jo = JSONObject.parseObject(record.getConditions()); - if (Objects.isNull(jo) || !jo.containsKey(WxCouponSend.KEY_MERCHANT_LNVENTORY)) { + int merchantLnventory = 0, merchantSend = 0; + try { + JSONObject jo = JSONObject.parseObject(record.getConditions()); + merchantLnventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY); + merchantSend = jo.getIntValue(WxCouponSend.KEY_MERCHANT_SEND); + } catch (Exception e) { + logger.error(" updateInvalid 解析异常:{}", e.getMessage()); + } + if (0 >= merchantLnventory || 0 > merchantSend) { throw new MallinkException(ErrorCode.COUPON_SEND_LIMIT_VERIFY); } - int merchantLnventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY); //退回coupon库存 - wxCouponService.backRemainInventory(queryById.getId(), wxCouponOfDb.getRemainInventory(), merchantLnventory); + wxCouponService.backRemainInventory(queryById.getId(), wxCouponOfDb.getRemainInventory(), merchantLnventory - merchantSend); } wxCouponSendMapper.updateByPrimaryKeySelective(record); } @@ -537,16 +544,16 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { } @Override - public void reduceMerchantRemainInventory(Long id, Integer remainInventory, Integer number) { - int num = wxCouponSendMapper.reduceMerchantRemainInventory(id, remainInventory, number); + public void reduceMerchantSend(Long id, Integer merchantSend, Integer number) { + int num = wxCouponSendMapper.reduceMerchantSend(id, merchantSend, number); if (num == 0) { throw new MallinkException(ErrorCode.ORDER_IS_FAIL); } } @Override - public void backMerchantRemainInventory(Long id, Integer remainInventory, Integer number) { - int num = wxCouponSendMapper.backMerchantRemainInventory(id, remainInventory, number); + public void backMerchantRemainInventory(Long id, Integer merchantSend, Integer number) { + int num = wxCouponSendMapper.backMerchantSend(id, merchantSend, number); if (num == 0) { throw new MallinkException(ErrorCode.ORDER_IS_FAIL); } @@ -564,6 +571,9 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { // 发放免费券 WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(user.getId(), cs.getCouponId(), cs); wxCouponActionLogService.addOne(user.getTenantId(), cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId()); + if (couponOrder != null) { + sendMsgForSendCoupon(cs.getTenantId(), cs, couponOrder, user); + } }); } } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java index 45217f18b..f92793b48 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java @@ -218,7 +218,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { int creditChangeNum = creditChangeNumOrigin ; if (record.getCreditType().equals(EnumScoreType.CONSUMPTION.getCode()) || record.getCreditType().equals(EnumScoreType.SPEND_CREDIT.getCode())) { //等级积分配置 - int levelScale = wxLevelConfigMapper.getScale(wxCUser.getTenantId(), wxCUser.getScore()) ; + Integer levelScale = wxLevelConfigMapper.getScale(wxCUser.getTenantId(), wxCUser.getScore()); creditChangeNum = CreditUtil.calUserCredit(creditChangeNumOrigin, wxCUser, levelScale, wxCUserBasicInfo, wxScoreRulesService); } @@ -328,7 +328,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { if (Objects.nonNull(userId)) { WxCUser wxCUser = wxCUserMapper.selectByPrimaryKey(userId); WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectByPrimaryKey(userId); - int birthdayScale = wxLevelConfigMapper.getScale(wxCUser.getTenantId(), wxCUser.getScore()) ; + Integer birthdayScale = wxLevelConfigMapper.getScale(wxCUser.getTenantId(), wxCUser.getScore()); creditNew = CreditUtil.calUserCredit(credit, wxCUser, birthdayScale, wxCUserBasicInfo, wxScoreRulesService); } else { creditNew = credit; 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 a8b776bcd..4e03e04b1 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -321,9 +321,10 @@ public class WxOrderServiceImpl implements WxOrderService { JSONObject jo = JSONObject.parseObject(wxCouponSendVo.getConditions()) ; int merchantLnventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY) ; + int merchantSend = jo.getInteger(WxCouponSend.KEY_MERCHANT_SEND); // 检查 优惠券 库存 - if (merchantLnventory <= 0) { + if (merchantLnventory - merchantSend <= 0) { //解锁 redisLock.unlock(couponIdStr, timeStr); logger.error("此券库存为0, couponId: " + couponIdStr); @@ -365,7 +366,7 @@ public class WxOrderServiceImpl implements WxOrderService { try { // 减库存 - wxCouponSendService.reduceMerchantRemainInventory(wxCouponSendVo.getId(),merchantLnventory,1); + wxCouponSendService.reduceMerchantSend(wxCouponSendVo.getId(), merchantSend, 1); } catch (RuntimeException e) { logger.error("此券减库存失败, couponId: " + couponIdStr); throw new MallinkException(ErrorCode.ORDER_IS_FAIL); diff --git a/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml index a7f2caa38..bf1821efb 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml @@ -207,7 +207,9 @@ WHERE a.coupon_order_id = o.id AND a.tenant_id = #{tenantId} AND o.c_user_id = #{cUserId} - AND a.coupon_id = #{couponId} + + AND a.coupon_id = #{couponId} + AND a.channel_type = #{channelType} and a.create_time >= #{startTime} and a.create_time <= #{endTime} diff --git a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml index bdcf52f57..787d19956 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml @@ -155,10 +155,10 @@ where c.id = cs.coupon_id and cs.status = 0 and ((c.status = 1) or (c.valid_type = 1 and c.valid_end_date < now())) - - update wx_coupon_send SET conditions = JSON_SET(conditions,'$.merchantLnventory',#{remainInventory} - #{number}) where id = #{id} and conditions->'$.merchantLnventory' = #{remainInventory} + + 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,'$.merchantLnventory',#{remainInventory} + #{number}) where id = #{id} and conditions->'$.merchantLnventory' = #{remainInventory} + + update wx_coupon_send SET conditions = JSON_SET(conditions,'$.merchantSend',#{merchantSend} + #{number}) where id = #{id} and conditions->'$.merchantSend' = #{merchantSend}