feat: #10000 feat: #10000 商品状态标准化

This commit is contained in:
赵世界 2022-11-03 16:09:13 +08:00
parent 58412bc549
commit 790ab6bdca
2 changed files with 14 additions and 42 deletions

View File

@ -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)
{
//
}
}

View File

@ -23,21 +23,24 @@ class StockWarning implements ShouldQueue
public function handle($event) public function handle($event)
{ {
if (isset($event->goodsSku->stock)) { if (isset($event->goodsSku->stock)) {
if (5 >= $event->goodsSku->stock) {
// 修改状态为预警,发送通知给管理员
$event->goodsSku->status = 2; $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->status = 1;
} }
$event->goodsSku->save(); $event->goodsSku->save();
} }
if (isset($event->goodsSkus)) { if (isset($event->goodsSkus)) {
$warningIds = $normalIds = []; $warningIds = $normalIds = $downIds = [];
foreach ($event->goodsSkus as $goodsSku) { foreach ($event->goodsSkus as $goodsSku) {
if (5 >= $goodsSku['stock']) { if (0 >= $goodsSku['stock']) {
$warningIds[] = $goodsSku['id']; $downIds[] = $goodsSku['id'];
} else { } elseif (5 < $goodsSku['stock']) {
$normalIds[] = $goodsSku['id']; $normalIds[] = $goodsSku['id'];
} else {
$warningIds[] = $goodsSku['id'];
} }
} }
if ($warningIds) { if ($warningIds) {
@ -46,6 +49,9 @@ class StockWarning implements ShouldQueue
if ($normalIds) { if ($normalIds) {
GoodsSku::query()->whereIn('id', $normalIds)->update(['status' => 1]); GoodsSku::query()->whereIn('id', $normalIds)->update(['status' => 1]);
} }
if ($downIds) {
GoodsSku::query()->whereIn('id', $downIds)->update(['status' => 0]);
}
} }
} }
} }