|
|
|
@@ -5,13 +5,16 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.domain.po.msg.AppUniformMsg; |
|
|
|
import com.iformall.domain.po.msg.MpAppMsg; |
|
|
|
import com.iformall.domain.po.msg.WxMsgRecord; |
|
|
|
import com.iformall.domain.vo.WxCouponSendVo; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.exception.BizMessageException; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.*; |
|
|
|
import com.iformall.mq.MqBaseProducer; |
|
|
|
@@ -23,6 +26,7 @@ import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Isolation; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
@@ -84,14 +88,36 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { |
|
|
|
return wxCouponSendMapper.selectByPrimaryKey(id); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public void saveOrUpdate(WxCouponSend record) { |
|
|
|
//会员生日券配置 |
|
|
|
if(Objects.equals(record.getSendType(),EnumCouponSendSendType.BIRTHDAY.getCode())) { |
|
|
|
WxCouponSend config = getConfig(record.getSendType(),record.getTenantId()) ; |
|
|
|
if(Objects.nonNull(config)) { |
|
|
|
record.setConditions(config.getConditions()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//商户卡库存校验 |
|
|
|
if(Objects.equals(record.getSendType(),EnumCouponSendSendType.MERCHANT.getCode())) { |
|
|
|
JSONObject jo = JSONObject.parseObject(record.getConditions()) ; |
|
|
|
if(Objects.isNull(jo)||!jo.containsKey(WxCouponSend.KEY_MERCHANT_LNVENTORY)) { |
|
|
|
throw new BizMessageException(ErrorCode.COUPON_SEND_LIMIT_VERIFY.getMessage()) ; |
|
|
|
} |
|
|
|
WxCoupon queryById = new WxCoupon() ; |
|
|
|
queryById.setId(record.getId()); |
|
|
|
WxCoupon wxCouponOfDb = wxCouponService.findById(queryById); |
|
|
|
if(Objects.isNull(wxCouponOfDb)) { |
|
|
|
throw new BizMessageException(ErrorCode.COUPON_IS_EMPTY.getMessage()) ; |
|
|
|
} |
|
|
|
int merchantLnventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY) ; |
|
|
|
if(merchantLnventory > wxCouponOfDb.getRemainInventory()) { |
|
|
|
throw new BizMessageException(ErrorCode.REMAIN_IS_EMPTY.getMessage()) ; |
|
|
|
} |
|
|
|
//更新库存 |
|
|
|
wxCouponService.reduceRemainInventory(wxCouponOfDb.getId(),wxCouponOfDb.getRemainInventory(),merchantLnventory); |
|
|
|
} |
|
|
|
if (record.getId() == null) { |
|
|
|
//record.setId(UUID.randomUUID().toString().replaceAll("-", "")); |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
|