diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java index 4ad8d0d41..a911531e6 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java @@ -11,6 +11,7 @@ import com.iformall.domain.po.*; import com.iformall.domain.vo.WxCouponChannelVo; import com.iformall.enums.EnumCouponSourceType; import com.iformall.domain.po.base.BaseEntity; +import com.iformall.exception.MallinkException; import com.iformall.service.WxCouponChannelService; import com.iformall.service.WxCouponService; import com.iformall.utils.RedisLock; @@ -144,10 +145,18 @@ public class WxCouponChannelController extends BaseController { if (coupon.getRemainInventory().intValue() < wxCouponChannel.getChannelStock().intValue()) { return new ResultData(Result.ERROR, "渠道库存不能大于券剩余总库存."); } - wxCouponChannelService.setChannelStock(wxCouponChannel, wxCouponChannel.getChannelStock()); - redisLock.setCouponStock(wxCouponChannel.getCouponId(), coupon.getRemainInventory()); - redisLock.setCouponChannelStock(wxCouponChannel.getId(), wxCouponChannel.getChannelStock()); - return new ResultData(Result.SUCCESS, "设置成功", ""); + try { + wxCouponChannelService.setChannelStock(wxCouponChannel, wxCouponChannel.getChannelStock()); + redisLock.setCouponStock(wxCouponChannel.getCouponId(), coupon.getRemainInventory()); + redisLock.setCouponChannelStock(wxCouponChannel.getId(), wxCouponChannel.getChannelStock()); + return new ResultData(Result.SUCCESS, "设置成功", ""); + }catch(MallinkException e) { + logger.error("setChannelStock error.",e); + return new ResultData(e.getErrorCode(),e.getMessage()); + }catch(Exception e){ + return new ResultData(Result.ERROR,e.getMessage()); + } + } @ApiOperation("解除锁定库存") @@ -155,10 +164,17 @@ public class WxCouponChannelController extends BaseController { @SystemControllerLog(description = "释放渠道锁定库存") public ResultData releaseChannelStock(@RequestBody WxCouponChannel wxCouponChannel) { wxCouponChannel.updateTenantInfo(getTenantInfo()); - wxCouponChannelService.releaseChannelStock(wxCouponChannel); - redisLock.removeCouponStock(wxCouponChannel.getCouponId()); - redisLock.removeCouponChannelStock(wxCouponChannel.getId()); - return new ResultData(Result.SUCCESS, "设置成功", ""); + try { + wxCouponChannelService.releaseChannelStock(wxCouponChannel); + redisLock.removeCouponStock(wxCouponChannel.getCouponId()); + redisLock.removeCouponChannelStock(wxCouponChannel.getId()); + return new ResultData(Result.SUCCESS, "设置成功", ""); + }catch(MallinkException e) { + logger.error("releaseChannelStock error.",e); + return new ResultData(e.getErrorCode(),e.getMessage()); + }catch(Exception e){ + return new ResultData(Result.ERROR,e.getMessage()); + } } @ApiOperation("设置价格") @@ -168,9 +184,17 @@ public class WxCouponChannelController extends BaseController { if (null == wxCouponChannel.getChannelPrice() || wxCouponChannel.getChannelPrice() < 0) { return new ResultData(Result.ERROR, "价格未设置或者价格小于0, 如不需要可点击解除价格设置."); } - wxCouponChannel.updateTenantInfo(getTenantInfo()); - wxCouponChannelService.setChannelPrice(wxCouponChannel); - return new ResultData(Result.SUCCESS, "设置成功", ""); + + try { + wxCouponChannel.updateTenantInfo(getTenantInfo()); + wxCouponChannelService.setChannelPrice(wxCouponChannel); + return new ResultData(Result.SUCCESS, "设置成功", ""); + }catch(MallinkException e) { + logger.error("setChannelPrice error.",e); + return new ResultData(e.getErrorCode(),e.getMessage()); + }catch(Exception e){ + return new ResultData(Result.ERROR,e.getMessage()); + } } @ApiOperation("解除价格设置") @@ -179,8 +203,16 @@ public class WxCouponChannelController extends BaseController { public ResultData releaseSetChannelPrice(@RequestBody WxCouponChannel wxCouponChannel) { wxCouponChannel.setChannelPrice(null); wxCouponChannel.updateTenantInfo(getTenantInfo()); - wxCouponChannelService.setChannelPrice(wxCouponChannel); - return new ResultData(Result.SUCCESS, "设置成功", ""); + try { + wxCouponChannelService.setChannelPrice(wxCouponChannel); + return new ResultData(Result.SUCCESS, "设置成功", ""); + }catch(MallinkException e) { + logger.error("releaseSetChannelPrice error.",e); + return new ResultData(e.getErrorCode(),e.getMessage()); + }catch(Exception e){ + return new ResultData(Result.ERROR,e.getMessage()); + } + } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxActivityServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxActivityServiceImpl.java index 0cf499bc8..072e17b98 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxActivityServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxActivityServiceImpl.java @@ -142,10 +142,10 @@ public class WxActivityServiceImpl implements WxActivityService { wxActivity.setCreateTime(date); wxActivityMapper.insert(wxActivity); } else { - WxActivity wxActivity1 = wxActivityMapper.selectById(wxActivity.getId()); - if(wxActivity1.getStatus().equals(EnumActivityStatus.STATUS_TAKE_OFFF.getCode())){ - return new ResultData(ErrorCode.ACTIVITY_NOT_UPDATE); - } +// WxActivity wxActivity1 = wxActivityMapper.selectById(wxActivity.getId()); +// if(wxActivity1.getStatus().equals(EnumActivityStatus.STATUS_TAKE_OFFF.getCode())){ +// return new ResultData(ErrorCode.ACTIVITY_NOT_UPDATE); +// } wxActivityMapper.updateById(wxActivity); } return new ResultData(Result.SUCCESS, "操作成功"); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java index 079c0df30..9d56a9953 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java @@ -226,6 +226,7 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { } @Override + @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) public ResultData addBatch(String type,String[] ids, String[] channelId, TenantEntity tenantEntity, Date showBeginTime, Date beginTime, Date endTime,Integer channelPrice,Integer channelStock) { //如果当前版本是推广版,则线上只能有一个拼团,一个砍价 WxMall mall = wxMallService.getByTenantId(tenantEntity.getTenantId()); @@ -561,6 +562,13 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { } } + if(channelStock != null && channelStock.intValue() > 0){ + int num = wxCouponMapper.reduceInventory(wxCoupon.getId(),tenantEntity.getTenantId(), channelStock); + if (num == 0) { + throw new MallinkException(ErrorCode.ORDER_SAVE_ERR); + } + } + WxCouponChannel wxCouponChannel = new WxCouponChannel(); if(showBeginTime == null){ wxCouponChannel.setShowBeginTime(new Date());