mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
feat: #10000 库存更新修改
This commit is contained in:
parent
80e63ec32d
commit
72ffbbc40d
@ -45,7 +45,12 @@ class BusinessOrdersUpdate
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->goodsSku) {
|
if ($this->goodsSku) {
|
||||||
|
$stock = $this->goodsSku->stock + $this->num;
|
||||||
|
if ($stock >= 0) {
|
||||||
$this->goodsSku->stock += $this->num;
|
$this->goodsSku->stock += $this->num;
|
||||||
|
} else {
|
||||||
|
$this->goodsSku->status = 0;
|
||||||
|
}
|
||||||
$this->goodsSku->save();
|
$this->goodsSku->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,6 @@ class GoodsRequest extends FormRequest
|
|||||||
return [
|
return [
|
||||||
'id' => ['sometimes', 'required', 'integer', 'exists:goods,id'],
|
'id' => ['sometimes', 'required', 'integer', 'exists:goods,id'],
|
||||||
'title' => ['required', 'string', 'max:191'],
|
'title' => ['required', 'string', 'max:191'],
|
||||||
'img_url' => ['string', 'max:191'],
|
|
||||||
'type_id' => ['required', 'integer', 'exists:goods_types,id'],
|
'type_id' => ['required', 'integer', 'exists:goods_types,id'],
|
||||||
'brand_id' => ['integer', 'exists:goods_brands,id'],
|
'brand_id' => ['integer', 'exists:goods_brands,id'],
|
||||||
'goods_code' => ['required', 'alpha_dash', 'max:32', Rule::unique('goods')->ignore(request('goods_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)
|
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;
|
$event->goodsSku->status = 2;
|
||||||
|
} else {
|
||||||
|
$event->goodsSku->status = 1;
|
||||||
|
}
|
||||||
$event->goodsSku->save();
|
$event->goodsSku->save();
|
||||||
}
|
}
|
||||||
if (isset($event->goodsSkus)) {
|
if (isset($event->goodsSkus)) {
|
||||||
$ids = [];
|
$warningIds = $normalIds = [];
|
||||||
foreach ($event->goodsSkus as $goodsSku) {
|
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