|
|
|
@@ -485,11 +485,48 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int updateCouponStockAndEndTime(WxCoupon wxCoupon) { |
|
|
|
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
public ResultData updateCouponStockAndEndTime(WxCoupon wxCoupon) { |
|
|
|
// 1. get old coupon info |
|
|
|
// 2. check 库存是否合适 |
|
|
|
// 3. check 新的有效期是否合适 |
|
|
|
// 4. 更新库存及有效期 |
|
|
|
return 0; |
|
|
|
WxCoupon oldCoupon = wxCouponMapper.selectByPrimaryKey(wxCoupon.getId()); |
|
|
|
if(wxCoupon.getInventory() < wxCoupon.getRemainInventory()) { |
|
|
|
// 总库存数要大于等于可用库存数 |
|
|
|
return new ResultData(ErrorCode.COUPON_STOCK_ERR); |
|
|
|
} |
|
|
|
if(wxCoupon.getInventory() <= oldCoupon.getInventory() - oldCoupon.getRemainInventory()) { |
|
|
|
// 库存可增, 可减, 但是要保证,总库存数要大于已售卖数 |
|
|
|
return new ResultData(ErrorCode.COUPON_STOCK_ERR); |
|
|
|
} |
|
|
|
if(wxCoupon.getInventory()-wxCoupon.getRemainInventory() != oldCoupon.getInventory() - oldCoupon.getRemainInventory()) { |
|
|
|
// 已售卖数不变 |
|
|
|
return new ResultData(ErrorCode.COUPON_STOCK_ERR); |
|
|
|
} |
|
|
|
if(wxCoupon.getValidType() != oldCoupon.getValidType()) { |
|
|
|
// 券有效期类型不能改变 |
|
|
|
return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR); |
|
|
|
} |
|
|
|
if(oldCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { |
|
|
|
if(wxCoupon.getValidEndDate().before(oldCoupon.getValidEndDate())) { |
|
|
|
// 券有效期只可增加 |
|
|
|
return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if(wxCoupon.getValidDays()<oldCoupon.getValidDays()) { |
|
|
|
// 券有效期只可增加 |
|
|
|
return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
wxCoupon.setOrgInventory(oldCoupon.getOrgInventory()); |
|
|
|
wxCoupon.setRemainInventory(oldCoupon.getRemainInventory()); |
|
|
|
|
|
|
|
int ret = wxCouponMapper.updateStockAndValidDate(wxCoupon); |
|
|
|
if(ret != 1) { |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "数据库更新数量错误"); |
|
|
|
} |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
} |