mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 14:40:44 +00:00
52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Events\StockUpdateEvent;
|
|
use App\Jobs\BusinessGoodsSkuIncrQuantity;
|
|
use App\Models\BusinessGoodsSku;
|
|
use App\Models\Shop;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
class StockUpdateListener
|
|
{
|
|
/**
|
|
* Create the event listener.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Handle the event.
|
|
*
|
|
* @param StockUpdateEvent $event
|
|
* @return void
|
|
*/
|
|
public function handle(StockUpdateEvent $event)
|
|
{
|
|
$shops = Shop::query()->where('status', 1)->get(['id', 'plat_id']);
|
|
if (empty($shops)) {
|
|
return;
|
|
}
|
|
foreach ($shops as $shop) {
|
|
if (isset($event->goodsSku)) {
|
|
$num = $event->goodsSku->stock;
|
|
$businessGoodsSku = BusinessGoodsSku::query()->where('shop_id', $shop->id)->where('external_sku_id', $event->goodsSku->goods['goods_code'] . '_' . $event->goodsSku->sku_code)->first();
|
|
BusinessGoodsSkuIncrQuantity::dispatch($shop, $businessGoodsSku, $num, false);
|
|
}
|
|
if (isset($event->goodsSkus)) {
|
|
foreach ($event->goodsSkus as $goodsSku) {
|
|
$num = $goodsSku->stock;
|
|
$businessGoodsSku = BusinessGoodsSku::query()->where('shop_id', $shop->id)->where('external_sku_id', $goodsSku->goods['goods_code'] . '_' . $goodsSku->sku_code)->first();
|
|
BusinessGoodsSkuIncrQuantity::dispatch($shop, $businessGoodsSku, $num, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|