Browse Source

库存再试

master
weigang 5 years ago
parent
commit
cf5a9e1c93
  1. 8
      app/Service/v3/Implementations/GoodsActivityService.php
  2. 7
      app/Service/v3/Implementations/GoodsService.php
  3. 11
      app/Service/v3/Implementations/OrderOnlineService.php

8
app/Service/v3/Implementations/GoodsActivityService.php

@ -54,6 +54,14 @@ class GoodsActivityService implements GoodsActivityServiceInterface
return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR;
}
// 压redis库存
// redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放
if (!$redis->exists($inventoryKey)) {
$redis->set($inventoryKey, $num);
} else {
$redis->incrBy($inventoryKey, $num);
}
// 是否超过限购数量
if ($goods->restrict_num != 0 && $goods->restrict_num < $num) {
return ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT;

7
app/Service/v3/Implementations/GoodsService.php

@ -44,6 +44,13 @@ class GoodsService implements GoodsServiceInterface
if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){
return ErrorCode::GOODS_INVENTORY_ERROR;
}
// 压redis库存
// redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放
if (!$redis->exists($inventoryKey)) {
$redis->set($inventoryKey, $num);
} else {
$redis->incrBy($inventoryKey, $num);
}
// 是否超过限购数量
if ($goods->restrict_num != 0 && $goods->restrict_num < $num) {

11
app/Service/v3/Implementations/OrderOnlineService.php

@ -217,17 +217,6 @@ class OrderOnlineService implements OrderOnlineServiceInterface
'cover_img' => $goods->cover_img ?: '',
'spec' => json_encode($goods->spec),
];
// 拼接activity_type和goods_id
$inventoryKey = 'goods_inventory_sold_'.$cart->activity_type.'_'.$cart->goods_id;
// 压redis库存
// redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放
if (!$redis->exists($inventoryKey)) {
$redis->set($inventoryKey, $cart->num);
} else {
$redis->incrBy($inventoryKey, $cart->num);
}
}
// 子订单数据

Loading…
Cancel
Save