commit
25319e2465
@ -45,7 +45,12 @@ class BusinessOrdersUpdate
|
||||
return false;
|
||||
}
|
||||
if ($this->goodsSku) {
|
||||
$stock = $this->goodsSku->stock + $this->num;
|
||||
if ($stock >= 0) {
|
||||
$this->goodsSku->stock += $this->num;
|
||||
} else {
|
||||
$this->goodsSku->status = 0;
|
||||
}
|
||||
$this->goodsSku->save();
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,6 @@ class GoodsRequest extends FormRequest
|
||||
return [
|
||||
'id' => ['sometimes', 'required', 'integer', 'exists:goods,id'],
|
||||
'title' => ['required', 'string', 'max:191'],
|
||||
'img_url' => ['string', 'max:191'],
|
||||
'type_id' => ['required', 'integer', 'exists:goods_types,id'],
|
||||
'brand_id' => ['integer', 'exists:goods_brands,id'],
|
||||
'goods_code' => ['required', 'alpha_dash', 'max:32', Rule::unique('goods')->ignore(request('goods_id'))],
|
||||
|
||||
@ -22,18 +22,29 @@ class StockWarning implements ShouldQueue
|
||||
|
||||
public function handle($event)
|
||||
{
|
||||
if (isset($event->goodsSku->stock) && 5 >= $event->goodsSku->stock) {
|
||||
if (isset($event->goodsSku->stock)) {
|
||||
if (5 >= $event->goodsSku->stock) {
|
||||
// 修改状态为预警,发送通知给管理员
|
||||
$event->goodsSku->status = 2;
|
||||
} else {
|
||||
$event->goodsSku->status = 1;
|
||||
}
|
||||
$event->goodsSku->save();
|
||||
}
|
||||
if (isset($event->goodsSkus)) {
|
||||
$ids = [];
|
||||
$warningIds = $normalIds = [];
|
||||
foreach ($event->goodsSkus as $goodsSku) {
|
||||
$ids[] = $goodsSku['id'];
|
||||
if (5 >= $goodsSku['stock']) {
|
||||
$warningIds[] = $goodsSku['id'];
|
||||
} else {
|
||||
$normalIds[] = $goodsSku['id'];
|
||||
}
|
||||
if ($ids) {
|
||||
GoodsSku::whereIn('id', $ids)->update(['status' => 2]);
|
||||
}
|
||||
if ($warningIds) {
|
||||
GoodsSku::whereIn('id', $warningIds)->update(['status' => 2]);
|
||||
}
|
||||
if ($normalIds) {
|
||||
GoodsSku::whereIn('id', $normalIds)->update(['status' => 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user