diff --git a/app/common/service/InvItemService.php b/app/common/service/InvItemService.php index 6ce0453..3dad1cd 100644 --- a/app/common/service/InvItemService.php +++ b/app/common/service/InvItemService.php @@ -3,9 +3,11 @@ namespace app\common\service; use app\common\logic\InvItemLogic; +use app\common\model\User; use app\common\validate\InvItemValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\InvItem; +use support\Redis; use support\Request; use support\exception\BusinessException; @@ -114,8 +116,30 @@ class InvItemService $data['is_consumable'] = 0; $data['stock_qty'] = $data['stock_qty']??1; $data['location'] = ''; + + Redis::set('inv_store_u_stock', $request->user->uid, 'EX', 30); + return $data; } + public function afterServiceStore($res) + { + $uid = redis::get('inv_store_u_stock'); + $name = $uid ? User::where('id', $uid)->value('name') : ''; + Redis::del('inv_store_u_stock'); + // 记录库存变化日志 + $this->recordStockLog([ + 'item_id' => $res['id'], + 'item_name_snap' => $res['item_name'], + 'change_qty' => $res['stock_qty'], + 'before_qty' => 0, + 'after_qty' => $res['stock_qty'], + 'biz_type' => 1, + 'biz_no' => '', + 'operator_id' => $uid, + 'operator_name' => $name, + 'remark' => '初始数量', + ], $res['stock_qty']); + } /**