From 9be3cb94131cf57a6e7860f2f05406aabfcb3f24 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 25 Sep 2020 11:46:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E9=80=80=E6=AC=BE=E5=90=8E=E8=BF=94=E5=BA=93=E5=AD=98=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E5=81=9A=E5=8E=8B=E5=BA=93=E5=AD=98=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/NotifyController.php | 15 ++++++++++-- .../v3/Implementations/OrderOnlineService.php | 24 +++++++++---------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/Controller/v3/NotifyController.php b/app/Controller/v3/NotifyController.php index fb6cc66..b1cb2de 100644 --- a/app/Controller/v3/NotifyController.php +++ b/app/Controller/v3/NotifyController.php @@ -7,6 +7,8 @@ use App\Constants\v3\OrderState; use App\Constants\v3\OrderType; use App\Constants\v3\Payment; use App\Controller\BaseController; +use App\Model\v3\Goods; +use App\Model\v3\GoodsActivity; use App\Model\v3\Order; use App\Model\v3\OrderGoods; use App\Model\v3\OrderMain; @@ -347,10 +349,19 @@ class NotifyController extends BaseController // 处理特价商品缓存 $orderChildren = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->get()->toArray(); $orderGoods = OrderGoods::query() - ->where(['activity_type' => 2]) + // ->where(['activity_type' => 2]) ->whereIn('order_id', array_values(array_column($orderChildren, 'id')))->get(); foreach ($orderGoods as $key => &$item) { - $this->goodsActivityService->clearCacheRecord($item['goods_id'], $item['number'], $orderMain->userId); + + if ($item['activity_type'] == 2) { # 活动商品 + $this->goodsActivityService->clearCacheRecord($item['goods_id'], $item['number'], $orderMain->userId); + $goods = GoodsActivity::find($item['goods_id']); + } else { + $goods = Goods::find($item['goods_id']); + } + $goods->inventory = $goods->inventory + $item['number']; + $goods->sales = $goods->sales - $item['number']; + $goods->save(); } // 添加用户的流水 diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index d55b658..dd7cdec 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -691,18 +691,18 @@ class OrderOnlineService implements OrderOnlineServiceInterface $orderIds = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->pluck('id'); $orderGoods = OrderGoods::query()->whereIn('order_id', $orderIds)->get()->toArray(); - // 释redis库存 - $redis = ApplicationContext::getContainer()->get(Redis::class); - foreach ($orderGoods as $k => &$goodsItem) { - // 拼接activity_type和goods_id - $inventoryKey = 'goods_inventory_sold_'.$goodsItem['activity_type'].'_'.$goodsItem['goods_id']; - // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 - if (!$redis->exists($inventoryKey)) { - $redis->set($inventoryKey, 0); - } else { - $redis->decrBy($inventoryKey, intval($goodsItem['number'])); - } - } + // // 释redis库存 + // $redis = ApplicationContext::getContainer()->get(Redis::class); + // foreach ($orderGoods as $k => &$goodsItem) { + // // 拼接activity_type和goods_id + // $inventoryKey = 'goods_inventory_sold_'.$goodsItem['activity_type'].'_'.$goodsItem['goods_id']; + // // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 + // if (!$redis->exists($inventoryKey)) { + // $redis->set($inventoryKey, 0); + // } else { + // $redis->decrBy($inventoryKey, intval($goodsItem['number'])); + // } + // } // 微信退款 if ($orderMain->pay_type == Payment::WECHAT) { From fd77452d9ae97ef3a92754a351dc76f3244dbdce Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 25 Sep 2020 15:03:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/NotifyController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controller/v3/NotifyController.php b/app/Controller/v3/NotifyController.php index b1cb2de..ed5d970 100644 --- a/app/Controller/v3/NotifyController.php +++ b/app/Controller/v3/NotifyController.php @@ -350,11 +350,11 @@ class NotifyController extends BaseController $orderChildren = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->get()->toArray(); $orderGoods = OrderGoods::query() // ->where(['activity_type' => 2]) - ->whereIn('order_id', array_values(array_column($orderChildren, 'id')))->get(); + ->whereIn('order_id', array_values(array_column($orderChildren, 'id')))->get()->toArray(); foreach ($orderGoods as $key => &$item) { if ($item['activity_type'] == 2) { # 活动商品 - $this->goodsActivityService->clearCacheRecord($item['goods_id'], $item['number'], $orderMain->userId); + $this->goodsActivityService->clearCacheRecord($item['goods_id'], $item['number'], $orderMain->user_id); $goods = GoodsActivity::find($item['goods_id']); } else { $goods = Goods::find($item['goods_id']); From 298b63a707a669c187e83f9eb23aa9fda450aa24 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 25 Sep 2020 15:13:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=80=80=E6=AC=BE=E7=89=B9=E4=BB=B7?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AE=B0=E5=BD=95=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/GoodsActivityService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index 5fdb515..f2c9595 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -150,8 +150,7 @@ class GoodsActivityService implements GoodsActivityServiceInterface $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - if (!$ssdb->exec('exists', $ssdbKey)) { - } else { + if ($ssdb->exec('exists', $ssdbKey)) { $res = $ssdb->exec('incr', $ssdbKey, -1*$num); } }