diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index 5bb2122..da5516a 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/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; diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 57fb1c3..1198ce8 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/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) { diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 5a7c06c..a2824dd 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/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); - } } // 子订单数据