Commit e6432353 authored by wlx@33.cn's avatar wlx@33.cn

优化盲盒购买

parent 70eaf279
...@@ -30,17 +30,17 @@ public class IOrderBindBoxServiceImpl implements IOrderBindBoxService { ...@@ -30,17 +30,17 @@ public class IOrderBindBoxServiceImpl implements IOrderBindBoxService {
* 从数据库获取库存大于0的盲盒sku列表 * 从数据库获取库存大于0的盲盒sku列表
*/ */
List<SkuVo> skuList = goodSkuMapper.listAvailableSku(goodsId); List<SkuVo> skuList = goodSkuMapper.listAvailableSku(goodsId);
if (!CollectionUtils.isEmpty(skuList)) {
int difficulty = skuList.stream().map(SkuVo::getDifficulty).findFirst().get(); int difficulty = skuList.stream().map(SkuVo::getDifficulty).findFirst().get();
while(!CollectionUtils.isEmpty(skuList)){
result = genRandomSku(skuList, difficulty); result = genRandomSku(skuList, difficulty);
}
if (result == null) { if (result == null) {
throw new RuntimeException("库存不足!!!"); throw new RuntimeException("库存不足!!!");
} }
//加时间锁 //加时间锁
int i = goodSkuMapper.delStock(result.getSkuId(), GoodMainConst.BLIND_BOX_ORDER_SKU_NUM, result.getUpdateTime()); int i = goodSkuMapper.delStock(result.getSkuId(), GoodMainConst.BLIND_BOX_ORDER_SKU_NUM, result.getUpdateTime());
if (i == 0) { if (i == 0) {
throw new RuntimeException("活动火爆"); skuList.remove(result);
}
} }
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment