Merge branch 'feature/inv' into develop
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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'];
|
||||
|
||||
@@ -46,4 +46,12 @@ class InvRequisitionItem extends Model
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 关联领用申请主表
|
||||
*/
|
||||
public function requisition()
|
||||
{
|
||||
return $this->belongsTo('app\common\model\InvRequisition', 'requisition_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user