From 2d837cb959d084328a4c83c6284701e50d25939e Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 17 Sep 2020 18:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/OrderOnlineService.php | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) 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);