mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 06:30:49 +00:00
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Listeners;
|
||
|
|
|
||
|
|
use App\Events\BatchStockUpdateEvent;
|
||
|
|
use App\Models\GoodsSku;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
|
||
|
|
class BatchStockWarning implements ShouldQueue
|
||
|
|
{
|
||
|
|
use InteractsWithQueue;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create the event listener.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
//
|
||
|
|
}
|
||
|
|
|
||
|
|
public function handle(BatchStockUpdateEvent $event)
|
||
|
|
{
|
||
|
|
if (!$event->stockWarning) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
$warningIds = $normalIds = $downIds = [];
|
||
|
|
foreach ($event->goodsSkus as $goodsSku) {
|
||
|
|
if (0 >= $goodsSku['stock']) {
|
||
|
|
$downIds[] = $goodsSku['id'];
|
||
|
|
} elseif (5 < $goodsSku['stock']) {
|
||
|
|
$normalIds[] = $goodsSku['id'];
|
||
|
|
} else {
|
||
|
|
$warningIds[] = $goodsSku['id'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ($warningIds) {
|
||
|
|
GoodsSku::query()->whereIn('id', $warningIds)->update(['status' => 2]);
|
||
|
|
}
|
||
|
|
if ($normalIds) {
|
||
|
|
GoodsSku::query()->whereIn('id', $normalIds)->update(['status' => 1]);
|
||
|
|
}
|
||
|
|
if ($downIds) {
|
||
|
|
GoodsSku::query()->whereIn('id', $downIds)->update(['status' => 0]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|