!130 库存同步优化

Merge pull request !130 from develop
This commit is contained in:
赵世界 2022-11-04 08:46:31 +00:00 committed by Gitee
commit 3e2f756a6b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 18 additions and 5 deletions

View File

@ -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();

View File

@ -73,6 +73,6 @@ class InventoryImport implements ToCollection, SkipsEmptyRows
$goodsSku->stock = 0;
$goodsSku->save();
}
event(new StockUpdateEvent($onSkuIds));
event(new StockUpdateEvent($onSkuIds, 1));
}
}

View File

@ -43,7 +43,13 @@ class StockUpdateListener
->where('is_sync', 1)
->where('external_sku_id', $event->goodsSku->goods['goods_code'] . '_' . $event->goodsSku->sku_code)
->get();
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();
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);
}
}
}
}
}