From 6b6c49dd75d8f4a37fd8a32c2e5f7203624af91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Fri, 4 Nov 2022 16:45:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20#10000=20=E5=BF=AB=E5=9B=A2=E5=9B=A2?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Events/StockUpdateEvent.php | 5 +++-- app/Imports/InventoryImport.php | 2 +- app/Listeners/StockUpdateListener.php | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/Events/StockUpdateEvent.php b/app/Events/StockUpdateEvent.php index 4caca63..5a81484 100644 --- a/app/Events/StockUpdateEvent.php +++ b/app/Events/StockUpdateEvent.php @@ -17,7 +17,7 @@ class StockUpdateEvent public $goodsSku; public $goodsSkus; - + public $isBatch; /** * Create a new event instance. @@ -26,8 +26,9 @@ class StockUpdateEvent * * @return void */ - public function __construct($data) + public function __construct($data, $isBatch = 0) { + $this->isBatch = $isBatch; if (is_array($data)) { // ids集合 $this->goodsSkus = GoodsSku::query()->whereIn('id', $data)->with(['goods:id,goods_code'])->get(); diff --git a/app/Imports/InventoryImport.php b/app/Imports/InventoryImport.php index ae433e2..4e087b4 100644 --- a/app/Imports/InventoryImport.php +++ b/app/Imports/InventoryImport.php @@ -73,6 +73,6 @@ class InventoryImport implements ToCollection, SkipsEmptyRows $goodsSku->stock = 0; $goodsSku->save(); } - event(new StockUpdateEvent($onSkuIds)); + event(new StockUpdateEvent($onSkuIds, 1)); } } diff --git a/app/Listeners/StockUpdateListener.php b/app/Listeners/StockUpdateListener.php index 9bf7b67..aa28787 100644 --- a/app/Listeners/StockUpdateListener.php +++ b/app/Listeners/StockUpdateListener.php @@ -43,7 +43,13 @@ class StockUpdateListener ->where('is_sync', 1) ->where('external_sku_id', $event->goodsSku->goods['goods_code'] . '_' . $event->goodsSku->sku_code) ->get(); - BusinessFactory::init()->make($shop['plat_id'])->setShopWithId($shop['id'])->batchIncrQuantity($businessGoodsSkus->toArray(), $num, false); + if ($event->isBatch) { + BusinessFactory::init()->make($shop['plat_id'])->setShopWithId($shop['id'])->batchIncrQuantity($businessGoodsSkus->toArray(), $num, false); + } else { + foreach ($businessGoodsSkus as $businessGoodsSku) { + BusinessGoodsSkuIncrQuantity::dispatch($shop, $businessGoodsSku->toArray(), $num, false); + } + } } if (isset($event->goodsSkus)) { foreach ($event->goodsSkus as $goodsSku) { @@ -54,7 +60,13 @@ class StockUpdateListener ->where('is_sync', 1) ->where('external_sku_id', $goodsSku->goods['goods_code'] . '_' . $goodsSku->sku_code) ->get(); - BusinessFactory::init()->make($shop['plat_id'])->setShopWithId($shop['id'])->batchIncrQuantity($businessGoodsSkus->toArray(), $num, false); + if ($event->isBatch) { + BusinessFactory::init()->make($shop['plat_id'])->setShopWithId($shop['id'])->batchIncrQuantity($businessGoodsSkus->toArray(), $num, false); + } else { + foreach ($businessGoodsSkus as $businessGoodsSku) { + BusinessGoodsSkuIncrQuantity::dispatch($shop, $businessGoodsSku->toArray(), $num, false); + } + } } } }