From 790ab6bdcae6dbd6e7772ff0fe6f60332744a7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Thu, 3 Nov 2022 16:09:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20#10000=20feat:=20#10000=20=E5=95=86?= =?UTF-8?q?=E5=93=81=E7=8A=B6=E6=80=81=E6=A0=87=E5=87=86=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Listeners/BindBusinessGoods.php | 34 ----------------------------- app/Listeners/StockWarning.php | 22 ++++++++++++------- 2 files changed, 14 insertions(+), 42 deletions(-) delete mode 100644 app/Listeners/BindBusinessGoods.php diff --git a/app/Listeners/BindBusinessGoods.php b/app/Listeners/BindBusinessGoods.php deleted file mode 100644 index b6c3ed8..0000000 --- a/app/Listeners/BindBusinessGoods.php +++ /dev/null @@ -1,34 +0,0 @@ -shop = $shop; - } - - /** - * Handle the event. - * - * @param Registered $event - * @return void - */ - public function handle(Registered $event) - { - // - } -} diff --git a/app/Listeners/StockWarning.php b/app/Listeners/StockWarning.php index b688d40..cb33eed 100644 --- a/app/Listeners/StockWarning.php +++ b/app/Listeners/StockWarning.php @@ -23,21 +23,24 @@ class StockWarning implements ShouldQueue public function handle($event) { if (isset($event->goodsSku->stock)) { - if (5 >= $event->goodsSku->stock) { - // 修改状态为预警,发送通知给管理员 - $event->goodsSku->status = 2; - } else { + $event->goodsSku->status = 2; + if (0 >= $event->goodsSku->stock) { + $event->goodsSku->status = 0; + } + if (5 < $event->goodsSku->stock) { $event->goodsSku->status = 1; } $event->goodsSku->save(); } if (isset($event->goodsSkus)) { - $warningIds = $normalIds = []; + $warningIds = $normalIds = $downIds = []; foreach ($event->goodsSkus as $goodsSku) { - if (5 >= $goodsSku['stock']) { - $warningIds[] = $goodsSku['id']; - } else { + if (0 >= $goodsSku['stock']) { + $downIds[] = $goodsSku['id']; + } elseif (5 < $goodsSku['stock']) { $normalIds[] = $goodsSku['id']; + } else { + $warningIds[] = $goodsSku['id']; } } if ($warningIds) { @@ -46,6 +49,9 @@ class StockWarning implements ShouldQueue if ($normalIds) { GoodsSku::query()->whereIn('id', $normalIds)->update(['status' => 1]); } + if ($downIds) { + GoodsSku::query()->whereIn('id', $downIds)->update(['status' => 0]); + } } } }