2026-01-30 10:46:54 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\admin\service;
|
|
|
|
|
|
|
|
|
|
use app\common\validate\InvRequisitionValidate;
|
|
|
|
|
use app\common\traits\crud\CrudServiceTrait;
|
|
|
|
|
use app\common\model\InvRequisition;
|
2026-02-02 13:17:11 +08:00
|
|
|
use support\Request;
|
2026-01-30 10:46:54 +08:00
|
|
|
|
|
|
|
|
class InvRequisitionService
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
use CrudServiceTrait;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 指定当前要操作的模型
|
|
|
|
|
*/
|
|
|
|
|
protected string $modelClass = InvRequisition::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证器
|
|
|
|
|
*/
|
|
|
|
|
protected $validator = InvRequisitionValidate::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取验证器
|
|
|
|
|
*/
|
|
|
|
|
public function getValidator()
|
|
|
|
|
{
|
|
|
|
|
return new $this->validator;
|
|
|
|
|
}
|
2026-02-02 13:17:11 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造 CrudUtil 查询配置
|
|
|
|
|
*/
|
|
|
|
|
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
|
|
|
|
{
|
|
|
|
|
$p = $request->all();
|
|
|
|
|
|
|
|
|
|
$config = [];
|
|
|
|
|
$config['model'] = $this->modelClass;
|
|
|
|
|
switch ($scene) {
|
|
|
|
|
case 'default':
|
|
|
|
|
//$config['where']['status'] = 1;
|
|
|
|
|
$config['order']['id'] = 'desc';
|
|
|
|
|
break;
|
|
|
|
|
case 'index':
|
|
|
|
|
if(isset($p['status']) && $p['status']){
|
|
|
|
|
$config['where']['status'] = $p['status'];
|
|
|
|
|
}
|
2026-02-09 10:40:50 +08:00
|
|
|
if (isset($p['applicant_id']) && $p['applicant_id'] == 'self') { //自己的领用申请
|
|
|
|
|
$config['where']['applicant_id'] = $request->user->uid;
|
|
|
|
|
} elseif (isset($p['applicant_id']) && $p['applicant_id']) { //指定人员的申请
|
2026-02-02 13:17:11 +08:00
|
|
|
$config['where']['applicant_id'] = $p['applicant_id'];
|
2026-02-09 10:40:50 +08:00
|
|
|
} else { //审批人对应的记录
|
|
|
|
|
$config['where']['approval.approver_id'] = $request->user->uid;
|
|
|
|
|
$config['where']['approval.action'] = 0;
|
|
|
|
|
}
|
|
|
|
|
if(isset($p['phase']) && $p['phase'] == 'approve'){//借用审批中
|
|
|
|
|
$config['where']['status'] = ['in',[10,11,13]];
|
|
|
|
|
}elseif(isset($p['phase']) && $p['phase'] == 'repaid'){//已全部归还
|
|
|
|
|
$config['where']['status'] = 17;
|
|
|
|
|
}elseif(isset($p['phase']) && $p['phase'] == 'unreturned'){ //未归还
|
|
|
|
|
$config['where']['status'] = ['in',[12,14,15,16,18]];
|
2026-02-02 13:17:11 +08:00
|
|
|
}
|
|
|
|
|
$config['order']['id'] = 'desc';
|
|
|
|
|
break;
|
|
|
|
|
case 'show':
|
|
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
//$config['where']['status'] = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'store':
|
|
|
|
|
break;
|
|
|
|
|
case 'update':
|
|
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
break;
|
|
|
|
|
case 'destroy':
|
|
|
|
|
$config['where']['id'] = $p['id'];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 审批
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return mixed|string[]|null
|
|
|
|
|
*/
|
|
|
|
|
public function serviceApprove(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$param = $request->all();
|
2026-02-11 10:48:06 +08:00
|
|
|
$attachment = $param['attachment']??[];
|
2026-02-02 13:17:11 +08:00
|
|
|
//$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
|
|
|
|
$appro = new \app\common\service\InvRequisitionApproveService();
|
|
|
|
|
//requisition_id:申请id
|
2026-02-25 13:13:36 +08:00
|
|
|
//approve_id:审核步骤id
|
2026-02-02 13:17:11 +08:00
|
|
|
//action:审批动作:1通过 2驳回
|
|
|
|
|
//comment:审批意见
|
2026-02-11 10:48:06 +08:00
|
|
|
return $appro->approve($param['requisition_id'], $param['approve_id'], $request->user->uid, $param['action'], $param['comment'], $attachment);
|
2026-02-02 13:17:11 +08:00
|
|
|
}
|
2026-02-24 11:28:12 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 管理员代领
|
|
|
|
|
* 调用 common 服务层方法
|
|
|
|
|
*/
|
|
|
|
|
public function proxyClaim(Request $request, array $data): array
|
|
|
|
|
{
|
|
|
|
|
return (new \app\common\service\InvRequisitionService())->proxyClaim($request, $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 扫码/代领记录查询
|
|
|
|
|
* 调用 common 服务层方法
|
|
|
|
|
*/
|
|
|
|
|
public function qrClaimsList(Request $request): array
|
|
|
|
|
{
|
|
|
|
|
return (new \app\common\service\InvRequisitionService())->qrClaimsList($request);
|
|
|
|
|
}
|
2026-01-30 10:46:54 +08:00
|
|
|
}
|