mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
parent
58412bc549
commit
790ab6bdca
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Models\Shop;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class BindBusinessGoods
|
||||
{
|
||||
protected $shop;
|
||||
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Shop $shop)
|
||||
{
|
||||
$this->shop = $shop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param Registered $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Registered $event)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -23,21 +23,24 @@ class StockWarning implements ShouldQueue
|
||||
public function handle($event)
|
||||
{
|
||||
if (isset($event->goodsSku->stock)) {
|
||||
if (5 >= $event->goodsSku->stock) {
|
||||
// 修改状态为预警,发送通知给管理员
|
||||
$event->goodsSku->status = 2;
|
||||
} else {
|
||||
if (0 >= $event->goodsSku->stock) {
|
||||
$event->goodsSku->status = 0;
|
||||
}
|
||||
if (5 < $event->goodsSku->stock) {
|
||||
$event->goodsSku->status = 1;
|
||||
}
|
||||
$event->goodsSku->save();
|
||||
}
|
||||
if (isset($event->goodsSkus)) {
|
||||
$warningIds = $normalIds = [];
|
||||
$warningIds = $normalIds = $downIds = [];
|
||||
foreach ($event->goodsSkus as $goodsSku) {
|
||||
if (5 >= $goodsSku['stock']) {
|
||||
$warningIds[] = $goodsSku['id'];
|
||||
} else {
|
||||
if (0 >= $goodsSku['stock']) {
|
||||
$downIds[] = $goodsSku['id'];
|
||||
} elseif (5 < $goodsSku['stock']) {
|
||||
$normalIds[] = $goodsSku['id'];
|
||||
} else {
|
||||
$warningIds[] = $goodsSku['id'];
|
||||
}
|
||||
}
|
||||
if ($warningIds) {
|
||||
@ -46,6 +49,9 @@ class StockWarning implements ShouldQueue
|
||||
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