!43 库存修改

Merge pull request !43 from develop
This commit is contained in:
赵世界 2022-08-20 07:46:44 +00:00 committed by Gitee
commit 25319e2465
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 24 additions and 9 deletions

View File

@ -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();
}
}

View File

@ -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'))],

View File

@ -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]);
}
}
}