From 1251f78c6b66ae1ef940f80f27d2e4cfe04d2b24 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 25 Feb 2026 10:40:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=AB=E7=A0=81=E9=A2=86=E5=8F=96=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/InvItemController.php | 3 +++ app/common/model/InvItem.php | 2 +- app/common/model/InvRequisitionItem.php | 8 ++++++++ app/common/service/InvRequisitionService.php | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/admin/controller/InvItemController.php b/app/admin/controller/InvItemController.php index 33337ec..6589666 100644 --- a/app/admin/controller/InvItemController.php +++ b/app/admin/controller/InvItemController.php @@ -66,6 +66,7 @@ class InvItemController extends BaseController { try { $id = $request->post('id'); + $num = $request->post('num'); if (!$id) { return $this->error('物品ID不能为空'); } @@ -86,6 +87,7 @@ class InvItemController extends BaseController // 更新物品记录 $item->qr_code = $result['path']; + $item->qr_code_num = !empty($num)?$num:0; $item->qr_code_url = $result['url']; $item->save(); @@ -125,6 +127,7 @@ class InvItemController extends BaseController // 清空物品记录中的二维码字段 $item->qr_code = ''; + $item->qr_code_num = 0; $item->qr_code_url = ''; $item->save(); diff --git a/app/common/model/InvItem.php b/app/common/model/InvItem.php index c6dfa32..4581847 100644 --- a/app/common/model/InvItem.php +++ b/app/common/model/InvItem.php @@ -41,7 +41,7 @@ class InvItem extends Model * 允许自动填充模型字段 */ protected $fillable = ['id', 'company_id', 'item_code', 'item_name', - 'category_id', 'spec_model', 'unit', 'is_consumable', 'allow_qr_claim', 'qr_code', 'qr_code_url', + 'category_id', 'spec_model', 'unit', 'is_consumable', 'allow_qr_claim', 'qr_code', 'qr_code_num', 'qr_code_url', 'stock_qty', 'manage_user_id', 'location', 'remark', 'sort', 'status', 'created_at', 'updated_at']; diff --git a/app/common/model/InvRequisitionItem.php b/app/common/model/InvRequisitionItem.php index 261bb0b..7270127 100644 --- a/app/common/model/InvRequisitionItem.php +++ b/app/common/model/InvRequisitionItem.php @@ -46,4 +46,12 @@ class InvRequisitionItem extends Model * 不允许自动填充模型字段 */ protected $guarded = []; + + /** + * 关联领用申请主表 + */ + public function requisition() + { + return $this->belongsTo('app\common\model\InvRequisition', 'requisition_id', 'id'); + } } \ No newline at end of file diff --git a/app/common/service/InvRequisitionService.php b/app/common/service/InvRequisitionService.php index bcfbf0e..e22907f 100644 --- a/app/common/service/InvRequisitionService.php +++ b/app/common/service/InvRequisitionService.php @@ -352,6 +352,20 @@ class InvRequisitionService $applicantId = (int)$user['user']['id']; $applicantName = (string)$user['user']['name']; + // 检查扫码领取数量限制 + if ($item->qr_code_num > 0) { + // 查询该用户已扫码领取该物品的数量 + $claimedQty = InvRequisitionItem::whereHas('requisition', function ($q) use ($applicantId) { + $q->where('applicant_id', $applicantId) + ->where('claim_type', InvRequisition::CLAIM_TYPE_QR); + })->where('item_id', $itemId) + ->sum('approved_qty'); + + if (($claimedQty + $qty) > $item->qr_code_num) { + throw new BusinessException("扫码领取数量超限,每人最多可领取 {$item->qr_code_num} {$item->unit},已领取 {$claimedQty} {$item->unit}"); + } + } + // 检查库存 if ($item->stock_qty < $qty) { throw new BusinessException('库存不足,当前库存: ' . $item->stock_qty);