Skip to content

Commit

Permalink
解决商品购买但是商品页面的库存显示不正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lifenlong committed Jul 20, 2021
1 parent f35ae5b commit 44fb060
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import cn.lili.common.exception.ServiceException;
import cn.lili.common.vo.PageVO;
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.dto.GoodsSearchParams;
import cn.lili.modules.goods.entity.vos.GoodsVO;
Expand Down Expand Up @@ -61,12 +60,6 @@ public class GoodsBuyerController {
*/
@Autowired
private EsGoodsSearchService goodsSearchService;
/**
* 分销员
*/
@Autowired
private DistributionService distributionService;


@ApiOperation(value = "通过id获取商品信息")
@ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, paramType = "path", dataType = "Long")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ private void setPromotionStock(List<String> keys, List<String> values, OrderItem
/**
* 同步库存和促销库存
*
* 需修改:DB:商品库存、Sku商品库存、活动商品库存
* 1.获取需要修改的Sku列表、活动商品列表
* 2.写入sku商品库存,批量修改
* 3.写入促销商品的卖出数量、剩余数量,批量修改
* 4.调用方法修改商品库存
* @param order 订单
*/
private void synchroDB(OrderDetailVO order) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,15 @@ public GoodsSku getGoodsSkuByIdFromCache(String id) {
}
cache.put(GoodsSkuService.getCacheKeys(id), goodsSku);
}

//获取商品库存
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;
}

Expand Down Expand Up @@ -437,7 +435,7 @@ public void updateGoodsStuck(List<GoodsSku> goodsSkus) {
quantity += goodsSku.getQuantity();
}
}
//保存商品库存结果 这里在for循环中调用数据库保存不太好,需要优化
//保存商品库存结果
goodsService.updateStock(goodsId, quantity);
}

Expand Down

0 comments on commit 44fb060

Please sign in to comment.