瀏覽代碼

小小训练营

zouxuan 3 年之前
父節點
當前提交
4afa7ceb81

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/LiveGoodsServiceImpl.java

@@ -91,7 +91,7 @@ public class LiveGoodsServiceImpl extends BaseServiceImpl<Integer, LiveGoods>  i
 	@Transactional(rollbackFor = Exception.class)
 	public void reduceGoodsStock(Integer liveGoodsId, String liveId) {
 		int i = liveGoodsDao.reduceStock(liveGoodsId);
-		if (i == 0) throw new BizException("商品库存不足");
+		if (i == 0) throw new BizException("商品已售罄");
 //		RBucket<Integer> bucket = redissonClient.getBucket(RedisKeyConstant.LIVE_GOODS_STOCK_CACHE_KEY + liveId + liveGoodsId);
 //		boolean exists = bucket.isExists();
 //		if (exists) {

+ 5 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MemberRankSettingServiceImpl.java

@@ -265,6 +265,9 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
         } else if (memberPayParamDto.getLiveGoodsId() == 2){
             RBucket<List<Integer>> bucket = redissonClient.getBucket(RedisKeyConstant.LIVE_GOODS_ZERO_CACHE_KEY + memberPayParamDto.getLiveId());
             List<Integer> list = bucket.get();
+            if(CollectionUtils.isEmpty(list)){
+                list = new ArrayList<>();
+            }
             //当前用户是否购买过免费直播课
             if(list.contains(sysUser.getId())){
                 throw new BizException("您已购买过本轮免费直播课");
@@ -274,12 +277,12 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
             if(count >= 2){
                 throw new BizException("免费直播课已达到购买次数上限");
             }
+            //保存购买记录
+            tempBuyFreeLiveTheoryCourseDao.insert(new TempBuyFreeLiveTheoryCourse(sysUser.getId()));
             //扣减库存
             liveGoodsService.reduceGoodsStock(memberPayParamDto.getLiveGoodsId(),memberPayParamDto.getLiveId());
             list.add(sysUser.getId());
             bucket.set(list);
-            //保存购买记录
-            tempBuyFreeLiveTheoryCourseDao.insert(new TempBuyFreeLiveTheoryCourse(sysUser.getId()));
             return BaseController.succeed();
         }else {
             throw new BizException("当前商品不可购买");