| @@ -71,8 +71,7 @@ public class WxCouponController extends BaseController { | |||||
| return new ResultData(ResultData.ERROR, "缺少id"); | return new ResultData(ResultData.ERROR, "缺少id"); | ||||
| } | } | ||||
| wxCoupon.setTenantId(getTenantId()); | wxCoupon.setTenantId(getTenantId()); | ||||
| wxCouponService.updateCouponStockAndEndTime(wxCoupon); | |||||
| return new ResultData(); | |||||
| return wxCouponService.updateCouponStockAndEndTime(wxCoupon); | |||||
| } | } | ||||
| @ApiOperation("根据id删除接口") | @ApiOperation("根据id删除接口") | ||||
| @@ -106,6 +106,8 @@ public enum ErrorCode{ | |||||
| COUPON_MERCHANT_NOT_FOUND(2032, "卡券关联商户未发现"), | COUPON_MERCHANT_NOT_FOUND(2032, "卡券关联商户未发现"), | ||||
| COUPON_CHANNEL_IS_NOT_STARTED(2033, "此券活动未开始"), | COUPON_CHANNEL_IS_NOT_STARTED(2033, "此券活动未开始"), | ||||
| COUPON_CHANNEL_IS_END(2033, "此券活动已结束"), | COUPON_CHANNEL_IS_END(2033, "此券活动已结束"), | ||||
| COUPON_STOCK_ERR(2034, "券库存设置错误"), | |||||
| COUPON_VALID_DATE_ERR(2035, "券有效期设置错误"), | |||||
| PUSH_LIMIT_UP_TO_1DAYLIMIT(2040, "此用户一天内发券到达疲劳度限制"), | PUSH_LIMIT_UP_TO_1DAYLIMIT(2040, "此用户一天内发券到达疲劳度限制"), | ||||
| PUSH_LIMIT_UP_TO_COUPONLIMIT(2041, "此用户发此券到达疲劳度限制"), | PUSH_LIMIT_UP_TO_COUPONLIMIT(2041, "此用户发此券到达疲劳度限制"), | ||||
| @@ -184,12 +184,21 @@ public class WxCoupon extends BaseEntity { | |||||
| @Transient | @Transient | ||||
| private String merchantParams; | private String merchantParams; | ||||
| /**投放频道参数,用来过滤**/ | |||||
| @Transient | @Transient | ||||
| @io.swagger.annotations.ApiModelProperty(value="投放频道参数,用来过滤",name="targetAd") | |||||
| private Integer targetAd; | private Integer targetAd; | ||||
| @Transient | @Transient | ||||
| @io.swagger.annotations.ApiModelProperty(value="投放频道参数,用来过滤",name="couponId") | |||||
| private Long couponId; | private Long couponId; | ||||
| @Transient | |||||
| @io.swagger.annotations.ApiModelProperty(value="修改库存有效期参数, 用来做乐观锁",name="orgRemainInventory") | |||||
| private Integer orgRemainInventory; | |||||
| @Transient | |||||
| @io.swagger.annotations.ApiModelProperty(value="修改库存有效期参数, 用来做乐观锁",name="orgInventory") | |||||
| private Integer orgInventory; | |||||
| //营销分析 | //营销分析 | ||||
| private WxCouponStatisVo wxCouponStatisVo; | private WxCouponStatisVo wxCouponStatisVo; | ||||
| @@ -504,7 +513,23 @@ public class WxCoupon extends BaseEntity { | |||||
| this.creditRefund = creditRefund; | this.creditRefund = creditRefund; | ||||
| } | } | ||||
| public static enum Field | |||||
| public Integer getOrgRemainInventory() { | |||||
| return orgRemainInventory; | |||||
| } | |||||
| public void setOrgRemainInventory(Integer orgRemainInventory) { | |||||
| this.orgRemainInventory = orgRemainInventory; | |||||
| } | |||||
| public Integer getOrgInventory() { | |||||
| return orgInventory; | |||||
| } | |||||
| public void setOrgInventory(Integer orgInventory) { | |||||
| this.orgInventory = orgInventory; | |||||
| } | |||||
| public static enum Field | |||||
| { | { | ||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | ||||
| ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") | ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") | ||||
| @@ -72,4 +72,7 @@ public interface WxCouponMapper extends CommonMapper<WxCoupon, Long> { | |||||
| Long priceCouponCancelCount(WxCoupon wxCoupon); | Long priceCouponCancelCount(WxCoupon wxCoupon); | ||||
| List<WxCouponStatisVo> findSaleCardCountHistory(WxCoupon wxCoupon); | List<WxCouponStatisVo> findSaleCardCountHistory(WxCoupon wxCoupon); | ||||
| // 库存,有效期修改 | |||||
| int updateStockAndValidDate(WxCoupon wxCoupon); | |||||
| } | } | ||||
| @@ -197,6 +197,6 @@ public interface WxCouponService { | |||||
| /** | /** | ||||
| * 增加库存及修改有效时间 | * 增加库存及修改有效时间 | ||||
| */ | */ | ||||
| int updateCouponStockAndEndTime(WxCoupon wxCoupon); | |||||
| ResultData updateCouponStockAndEndTime(WxCoupon wxCoupon); | |||||
| } | } | ||||
| @@ -485,11 +485,48 @@ public class WxCouponServiceImpl implements WxCouponService { | |||||
| } | } | ||||
| @Override | @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 | // 1. get old coupon info | ||||
| // 2. check 库存是否合适 | // 2. check 库存是否合适 | ||||
| // 3. check 新的有效期是否合适 | // 3. check 新的有效期是否合适 | ||||
| // 4. 更新库存及有效期 | // 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(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -248,6 +248,14 @@ | |||||
| <include refid="dynamicWhereConditions"/> | <include refid="dynamicWhereConditions"/> | ||||
| </select> | </select> | ||||
| <update id="updateStockAndValidDate" parameterType="com.iformall.domain.po.WxCoupon"> | |||||
| update wx_coupon | |||||
| SET | |||||
| `remain_inventory` = #{remainInventory}, `inventory` = #{inventory}, | |||||
| `valid_type` = #{validType}, `valid_end_date` = #{validEndDate}, `valid_days` = #{validDays} | |||||
| WHERE id = #{id} and `remain_inventory` = #{orgRemainInventory} and `inventory` = #{orgInventory} | |||||
| </update> | |||||
| <sql id="dynamicWhereConditionsForCoupon"> | <sql id="dynamicWhereConditionsForCoupon"> | ||||
| where 1 = 1 | where 1 = 1 | ||||