库存更新同步修改
This commit is contained in:
parent
7dc861db0d
commit
c6e7f7edb6
@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Listeners;
|
|
||||||
|
|
||||||
use App\Events\BatchStockUpdateEvent;
|
|
||||||
use App\Models\DailyStockRecord;
|
|
||||||
use App\Models\GoodsSku;
|
|
||||||
use App\Utils\DateTimeUtils;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
$dailyStockRecord = DailyStockRecord::query()
|
|
||||||
->where('day', DateTimeUtils::getToday())
|
|
||||||
->whereIn('sku_id', $event->goodsSkus->pluck('id'))
|
|
||||||
->pluck('arrived_today_num', 'sku_id')
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
$normalIds = $downIds = [];
|
|
||||||
foreach ($event->goodsSkus as $goodsSku) {
|
|
||||||
if (0 >= $goodsSku['stock']) {
|
|
||||||
$downIds[] = $goodsSku['id'];
|
|
||||||
} else {
|
|
||||||
$normalIds[] = $goodsSku['id'];
|
|
||||||
}
|
|
||||||
if (20 < $dailyStockRecord[$goodsSku['id']] + $goodsSku->yesterday_num && 4 > $goodsSku['stock']) {
|
|
||||||
$downIds[] = $goodsSku['id'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($normalIds) {
|
|
||||||
GoodsSku::query()->whereIn('id', $normalIds)->update(['status' => 1]);
|
|
||||||
}
|
|
||||||
if ($downIds) {
|
|
||||||
GoodsSku::query()->whereIn('id', $downIds)->update(['status' => 0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user