Просмотр исходного кода

商户注券->更新库存操作

release_toaliyun_real
Burce 6 лет назад
Родитель
Сommit
d6da1b3989
3 измененных файлов: 54 добавлений и 41 удалений
  1. +0
    -3
      mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java
  2. +52
    -36
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java
  3. +2
    -2
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java

+ 0
- 3
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<WxCouponSendVo> page = wxCouponSendService.listAsPage(wxCouponSend, pageNum, pageSize);

for (WxCouponSendVo cs:page.getList())
cs.setSendCount(wxCouponActionLogService.getCountByChannelId(getTenantId(), cs.getSendType(), cs.getId()));
return new ResultData(page);
}



+ 52
- 36
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) {


+ 2
- 2
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) {


Загрузка…
Отмена
Сохранить