解决商品购买但是商品页面的库存显示不正确的问题
This commit is contained in:
parent
f35ae5b1ee
commit
44fb0601a6
@ -5,7 +5,6 @@ import cn.lili.common.enums.ResultUtil;
|
|||||||
import cn.lili.common.exception.ServiceException;
|
import cn.lili.common.exception.ServiceException;
|
||||||
import cn.lili.common.vo.PageVO;
|
import cn.lili.common.vo.PageVO;
|
||||||
import cn.lili.common.vo.ResultMessage;
|
import cn.lili.common.vo.ResultMessage;
|
||||||
import cn.lili.modules.distribution.service.DistributionService;
|
|
||||||
import cn.lili.modules.goods.entity.dos.Goods;
|
import cn.lili.modules.goods.entity.dos.Goods;
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||||
import cn.lili.modules.goods.entity.vos.GoodsVO;
|
import cn.lili.modules.goods.entity.vos.GoodsVO;
|
||||||
@ -61,12 +60,6 @@ public class GoodsBuyerController {
|
|||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private EsGoodsSearchService goodsSearchService;
|
private EsGoodsSearchService goodsSearchService;
|
||||||
/**
|
|
||||||
* 分销员
|
|
||||||
*/
|
|
||||||
@Autowired
|
|
||||||
private DistributionService distributionService;
|
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "通过id获取商品信息")
|
@ApiOperation(value = "通过id获取商品信息")
|
||||||
@ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, paramType = "path", dataType = "Long")
|
@ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, paramType = "path", dataType = "Long")
|
||||||
|
@ -161,6 +161,11 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
|
|||||||
/**
|
/**
|
||||||
* 同步库存和促销库存
|
* 同步库存和促销库存
|
||||||
*
|
*
|
||||||
|
* 需修改:DB:商品库存、Sku商品库存、活动商品库存
|
||||||
|
* 1.获取需要修改的Sku列表、活动商品列表
|
||||||
|
* 2.写入sku商品库存,批量修改
|
||||||
|
* 3.写入促销商品的卖出数量、剩余数量,批量修改
|
||||||
|
* 4.调用方法修改商品库存
|
||||||
* @param order 订单
|
* @param order 订单
|
||||||
*/
|
*/
|
||||||
private void synchroDB(OrderDetailVO order) {
|
private void synchroDB(OrderDetailVO order) {
|
||||||
|
@ -189,17 +189,15 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
}
|
}
|
||||||
cache.put(GoodsSkuService.getCacheKeys(id), goodsSku);
|
cache.put(GoodsSkuService.getCacheKeys(id), goodsSku);
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取商品库存
|
//获取商品库存
|
||||||
String quantity = stringRedisTemplate.opsForValue().get(GoodsSkuService.getStockCacheKey(id));
|
String quantity = stringRedisTemplate.opsForValue().get(GoodsSkuService.getStockCacheKey(id));
|
||||||
if (quantity != null) {
|
|
||||||
if (goodsSku.getQuantity().equals(Convert.toInt(quantity))) {
|
|
||||||
goodsSku.setQuantity(Convert.toInt(quantity));
|
|
||||||
this.updateById(goodsSku);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(id), goodsSku.getQuantity().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//如果sku缓存的库存与库存缓存不符则按照库存缓存进行
|
||||||
|
if (quantity == null) {
|
||||||
|
goodsSku.setQuantity(Convert.toInt(quantity));
|
||||||
|
cache.put(GoodsSkuService.getCacheKeys(goodsSku.getId()), goodsSku);
|
||||||
|
}
|
||||||
return goodsSku;
|
return goodsSku;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +435,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
quantity += goodsSku.getQuantity();
|
quantity += goodsSku.getQuantity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//保存商品库存结果 这里在for循环中调用数据库保存不太好,需要优化
|
//保存商品库存结果
|
||||||
goodsService.updateStock(goodsId, quantity);
|
goodsService.updateStock(goodsId, quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user