|
|
|
@@ -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) { |
|
|
|
|