| @@ -116,23 +116,6 @@ public class WxCouponSendController extends BaseController { | |||
| return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE); | |||
| } | |||
| //商户卡库存校验 | |||
| if(Objects.equals(wxCouponSend.getSendType(),EnumCouponSendSendType.MERCHANT.getCode())) { | |||
| JSONObject jo = JSONObject.parseObject(wxCouponSend.getConditions()) ; | |||
| if(Objects.isNull(jo)||!jo.containsKey(WxCouponSend.KEY_MERCHANT_LNVENTORY)) { | |||
| return new ResultData(ErrorCode.COUPON_SEND_LIMIT_VERIFY); | |||
| } | |||
| WxCoupon queryById = new WxCoupon() ; | |||
| queryById.setId(wxCouponSend.getId()); | |||
| WxCoupon wxCouponOfDb = wxCouponService.findById(queryById); | |||
| if(Objects.isNull(wxCouponOfDb)) { | |||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| if(jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY) >wxCouponOfDb.getRemainInventory()) { | |||
| return new ResultData(ErrorCode.REMAIN_IS_EMPTY); | |||
| } | |||
| } | |||
| wxCouponSend.setTenantId(wxCoupon.getTenantId()); | |||
| wxCouponSend.setTitle(wxCoupon.getTitle()); | |||
| @@ -311,7 +311,6 @@ public class CouponSendSchedule { | |||
| "]给:" + cu.getNickName() + | |||
| " 电话-" + cu.getPhone() + | |||
| " id-" + cu.getId()); | |||
| break; | |||
| } | |||
| }); | |||
| }); | |||
| @@ -45,6 +45,7 @@ public class WxCouponSend extends BaseEntity { | |||
| protected Integer merchantLnventory; | |||
| /**发卷所属商户名**/ | |||
| @Transient | |||
| private String merchantName; | |||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||
| @@ -58,7 +59,7 @@ public class WxCouponSend extends BaseEntity { | |||
| private Integer sendType; | |||
| @io.swagger.annotations.ApiModelProperty(value="发券条件",name="condition") | |||
| private String conditions; | |||
| @io.swagger.annotations.ApiModelProperty(value="0:有效 1:无效",name="status") | |||
| @io.swagger.annotations.ApiModelProperty(value="全部时不传 0:有效 1:无效",name="status") | |||
| private Integer status; | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| @@ -21,7 +21,11 @@ public interface WxCouponMapper extends CommonMapper<WxCoupon, Long> { | |||
| void reduceInventory(@Param("id")Long id,@Param("number")Integer number); | |||
| void backInventory(@Param("id")Long id,@Param("remainInventory")Integer remainInventory, @Param("number")Integer number); | |||
| void backInventory(@Param("id")Long id,@Param("remainInventory")Integer remainInventory, @Param("number")Integer number); | |||
| Integer reduceRemainInventory(@Param("id") Long id, @Param("remainInventory") Integer remainInventory, @Param("number") Integer number); | |||
| Integer backRemainInventory(@Param("id") Long id, @Param("remainInventory") Integer remainInventory, @Param("number") Integer number); | |||
| void offExpiriedCouponByValidDate(); | |||
| @@ -6,6 +6,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.vo.WxCouponCVo; | |||
| import com.iformall.domain.vo.WxCouponStatisVo; | |||
| import org.apache.ibatis.annotations.Param; | |||
| public interface WxCouponService { | |||
| @@ -202,4 +203,22 @@ public interface WxCouponService { | |||
| WxCoupon findById(WxCoupon wxCoupon); | |||
| /** | |||
| * 库存减少 | |||
| * | |||
| * @param id 券ID | |||
| * @param remainInventory 当前库存 | |||
| * @param number 减少数量 | |||
| */ | |||
| void reduceRemainInventory(Long id, Integer remainInventory, Integer number); | |||
| /** | |||
| * 库存回退 | |||
| * | |||
| * @param id 券ID | |||
| * @param remainInventory 当前库存 | |||
| * @param number 回退数量 | |||
| */ | |||
| void backRemainInventory(Long id, Integer remainInventory, Integer number); | |||
| } | |||
| @@ -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(); | |||
| @@ -14,6 +14,7 @@ import com.iformall.domain.vo.WxCouponCVo; | |||
| import com.iformall.domain.vo.WxCouponStatisVo; | |||
| import com.iformall.domain.vo.WxMerchantVo; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.BizMessageException; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.*; | |||
| @@ -36,7 +37,7 @@ import java.util.stream.Collectors; | |||
| @Service | |||
| public class WxCouponServiceImpl implements WxCouponService { | |||
| public class WxCouponServiceImpl implements WxCouponService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| @@ -642,4 +643,22 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| } | |||
| return null; | |||
| } | |||
| @Override | |||
| @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| public void reduceRemainInventory(Long id, Integer remainInventory, Integer number) { | |||
| int num = wxCouponMapper.reduceRemainInventory(id, remainInventory, number); | |||
| if (num == 0) { | |||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||
| } | |||
| } | |||
| @Override | |||
| @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| public void backRemainInventory(Long id, Integer remainInventory, Integer number) { | |||
| int num = wxCouponMapper.backRemainInventory(id, remainInventory, number); | |||
| if (num == 0) { | |||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||
| } | |||
| } | |||
| } | |||
| @@ -519,6 +519,14 @@ | |||
| update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory>= #{remainInventory} | |||
| </update> | |||
| <update id="reduceRemainInventory"> | |||
| update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory= #{remainInventory} | |||
| </update> | |||
| <update id="backRemainInventory"> | |||
| update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory= #{remainInventory} | |||
| </update> | |||
| <update id="offExpiriedCouponByValidDate"> | |||
| update wx_coupon SET status = 1, update_date = now() | |||
| where status = 0 and valid_type = 1 and valid_end_date < now() | |||
| @@ -104,7 +104,7 @@ | |||
| from wx_coupon_send cs left join wx_coupon c on c.id = cs.coupon_id | |||
| <include refid="dynamicWhereConditions"/>) as tt | |||
| <if test=" null != merchantName "> | |||
| where tt.merchant_name like concat('%', #{merchantName},'%') | |||
| where tt.conditions like concat('%', #{merchantName},'%') | |||
| </if> | |||
| </select> | |||