From d6da1b3989217699ee4d9f5953432d2b8e68a31e Mon Sep 17 00:00:00 2001 From: Burce Date: Fri, 30 Aug 2019 17:18:59 +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 --- .../market/WxCouponSendController.java | 3 - .../service/impl/WxCouponSendServiceImpl.java | 88 +++++++++++-------- .../service/impl/WxOrderServiceImpl.java | 4 +- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java index 14bb6c622..962922a6a 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java @@ -68,9 +68,6 @@ public class WxCouponSendController extends BaseController { wxCouponSend.setStatus(valid); wxCouponSend.setSortColumns(BaseEntity.SortField.CreateDate_DESC); PageInfo page = wxCouponSendService.listAsPage(wxCouponSend, pageNum, pageSize); - - for (WxCouponSendVo cs:page.getList()) - cs.setSendCount(wxCouponActionLogService.getCountByChannelId(getTenantId(), cs.getSendType(), cs.getId())); return new ResultData(page); } 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 34a0bfcf1..a10c6ce53 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java @@ -72,11 +72,15 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSendMapper.findListVoByValidType(record)); for (WxCouponSendVo cs : pageInfo.getList()) { JSONObject jo = JSONObject.parseObject(cs.getConditions()); - int inventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY); + int inventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY); + int sendCound = jo.getIntValue(WxCouponSend.KEY_MERCHANT_SEND); cs.setInventory(inventory); + cs.setSendCount(sendCound); } } else { pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSendMapper.findListVo(record)); + for (WxCouponSendVo cs:pageInfo.getList()) + cs.setSendCount(wxCouponActionLogService.getCountByChannelId(record.getTenantId(), cs.getSendType(), cs.getId())); } return pageInfo; } @@ -96,42 +100,8 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { record.setConditions(config.getConditions()); } } - //商户卡库存校验 if (Objects.equals(record.getSendType(), EnumCouponSendSendType.MERCHANT.getCode())) { - JSONObject jo = JSONObject.parseObject(record.getConditions()); - int merchantLnventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY); - if (0 >= merchantLnventory) { - throw new MallinkException(ErrorCode.COUPON_SEND_LIMIT_VERIFY); - } - //查询总库存 - WxCoupon queryById = new WxCoupon(); - queryById.setId(record.getCouponId()); - WxCoupon wxCouponOfDb = wxCouponService.findById(queryById); - if (Objects.isNull(wxCouponOfDb)) { - throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); - } - String merchantIdStr = jo.getString("id"); - if (Objects.isNull(merchantIdStr)) { - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); - } - //产品需求,暂时不约束发券商户和券所属商户 - //WxCouponMerchant couponMerchantQ = new WxCouponMerchant(); - //couponMerchantQ.setTenantId(record.getTenantId()); - //couponMerchantQ.setProductId(record.getCouponId()); - //couponMerchantQ.setMerchantId(Long.parseLong(merchantIdStr)); - //couponMerchantQ.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); - //WxCouponMerchant couponMerchant = wxCouponMerchantMapper.selectOne(couponMerchantQ); - //if (Objects.isNull(couponMerchant)) { - // throw new MallinkException(ErrorCode.COUPON_MERCHANT_NOT_FOUND); - //} - - //商家购券数不能大于总库存 - if (merchantLnventory > wxCouponOfDb.getRemainInventory()) { - throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); - } - - //更新库存 - wxCouponService.reduceRemainInventory(wxCouponOfDb.getId(), wxCouponOfDb.getRemainInventory(), merchantLnventory); + addForMerchant(record); } if (record.getId() == null) { //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); @@ -143,6 +113,52 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { } } + private void addForMerchant(WxCouponSend record) { + //商户注券 参数校验 + int merchantLnventory = 0; + String merchantIdStr = null; + try { + JSONObject jo = JSONObject.parseObject(record.getConditions()); + merchantLnventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY); + merchantIdStr = jo.getString("id"); + jo.put(WxCouponSend.KEY_MERCHANT_SEND,0) ; + record.setConditions(jo.toJSONString()); + } catch (Exception e) { + logger.error(" updateInvalid 解析异常:{}", e.getMessage()); + } + if (Objects.isNull(merchantIdStr)) { + throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); + } + if (0 >= merchantLnventory) { + throw new MallinkException(ErrorCode.COUPON_SEND_LIMIT_VERIFY); + } + //查询总库存 + WxCoupon queryById = new WxCoupon(); + queryById.setId(record.getCouponId()); + WxCoupon wxCouponOfDb = wxCouponService.findById(queryById); + if (Objects.isNull(wxCouponOfDb)) { + throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); + } + //产品需求,暂时不约束发券商户和券所属商户 + //WxCouponMerchant couponMerchantQ = new WxCouponMerchant(); + //couponMerchantQ.setTenantId(record.getTenantId()); + //couponMerchantQ.setProductId(record.getCouponId()); + //couponMerchantQ.setMerchantId(Long.parseLong(merchantIdStr)); + //couponMerchantQ.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); + //WxCouponMerchant couponMerchant = wxCouponMerchantMapper.selectOne(couponMerchantQ); + //if (Objects.isNull(couponMerchant)) { + // throw new MallinkException(ErrorCode.COUPON_MERCHANT_NOT_FOUND); + //} + + //商家购券数不能大于总库存 + if (merchantLnventory > wxCouponOfDb.getRemainInventory()) { + throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); + } + + //更新库存 + wxCouponService.reduceRemainInventory(wxCouponOfDb.getId(), wxCouponOfDb.getRemainInventory(), merchantLnventory); + } + @Override @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) public void updateInvalid(WxCouponSend record) { 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 4e03e04b1..ea1ece0e3 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -320,8 +320,8 @@ 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); + int merchantLnventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY) ; + int merchantSend = jo.getIntValue(WxCouponSend.KEY_MERCHANT_SEND); // 检查 优惠券 库存 if (merchantLnventory - merchantSend <= 0) {