diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index caf974d..5a7c06c 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -217,6 +217,17 @@ 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); + } } // 子订单数据 @@ -338,18 +349,6 @@ class OrderOnlineService implements OrderOnlineServiceInterface Db::commit(); - // 压redis库存 - foreach ($carts as $k => &$cart) { - // 拼接activity_type和goods_id - $inventoryKey = 'goods_inventory_sold_'.$cart->activity_type.'_'.$cart->goods_id; - // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 - if (!$redis->exists($inventoryKey)) { - $redis->set($inventoryKey, $cart->num); - } else { - $redis->incrBy($inventoryKey, $cart->num); - } - } - // 清除购物车 $this->shopCartUpdateService->doClear($userId, $marketId);