审核附件

This commit is contained in:
2026-02-10 13:57:52 +08:00
parent 6469e05176
commit 452182f0b2
8 changed files with 147 additions and 7 deletions
@@ -99,12 +99,19 @@ class InvRequisitionItemReturnController extends BaseController
if (isset($data['return_at']))
$data['return_at'] = date('Y-m-d H:i:s', $data['return_at']);
if (isset($data['id'])){
//归还附件
$data['return_attachment'] = InvRequisitionItemReturnAttachment::where('return_id', $data['id'])->get();
$ossservice = new OssService();
foreach ($data['return_attachment'] as $item){
$item['file_path_pull'] = $ossservice->generatePrivateUrl($item['file_path']);
}
//归还审核附件
$data['return_approve_attachment'] = InvRequisitionItemReturnAttachment::where('return_id', $data['id'])->get();
foreach ($data['return_approve_attachment'] as $item){
$item['file_path_pull'] = $ossservice->generatePrivateUrl($item['file_path']);
}
}
/*if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class InvRequisitionApproveAttachment extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'inv_requisition_approve_attachment';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'requisition_id', 'approve_id', 'file_name', 'file_path', 'file_size', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class InvRequisitionReturnApproveAttachment extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'inv_requisition_return_approve_attachment';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = [];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
@@ -93,13 +93,13 @@ class InvRequisitionApproveService
}
/** 执行审批 */
public function approve(int $requisitionId, int $approverId, int $uid, string $action, string $comment = '')
public function approve(int $requisitionId, int $approverId, int $uid, string $action, string $comment = '', array $attachment = [])
{
if (!in_array($action, ['1','2'], true)) { //审批动作:1通过 2驳回
throw new BusinessException("无效的审批操作");
}
return Db::transaction(function () use ($requisitionId, $approverId, $uid, $action, $comment) {
return Db::transaction(function () use ($requisitionId, $approverId, $uid, $action, $comment, $attachment) {
// $instance = Db::table('approval_instances')->where('id', $instanceId)->lockForUpdate()->first();
$requisition = Db::table('inv_requisition')->where('id', $requisitionId)->lockForUpdate()->first();
if (!$requisition) throw new BusinessException("审批实例未找到");
@@ -151,6 +151,16 @@ class InvRequisitionApproveService
'action_at' => $now,
'updated_at' => $now,
]);
foreach ($attachment as $attac) {
Db::table('inv_requisition_approve_attachment')->insertGetId([
'requisition_id' => $requisitionId,
'approve_id' => $approverId,
'file_name' => $attac['original_name'],
'file_path' => $attac['file_path'],
'created_at' => $now,
]);
}
// 2) 已通过步骤与总步数相等则结束审核流程
$pass = Db::table('inv_requisition_approve')
@@ -386,8 +386,10 @@ class InvRequisitionItemReturnService
public function serviceReturnConfirm(Request $request, array $data, string $scene = 'returnConfirm')
{
try {
$attachment = $request->post('attachment');
unset($data['attachment']);
// 归还确认是业务顶层方法,这里统一使用事务
return Db::transaction(function () use ($request, $data, $scene) {
return Db::transaction(function () use ($request, $data, $scene, $attachment) {
// 1. 当前操作人信息
$userInfo = (new UserService())->getUserInfo($request->user->uid, '');
@@ -430,7 +432,16 @@ class InvRequisitionItemReturnService
// 4. 更新归还记录(状态 + 审核人 + 备注等)
$updateResult = $this->logicUpdateBy($config, $data);
$resultItem = $this->logicShow($config);
InvRequisitionReturn::where('id',$resultItem['status'])->update(['status' => $data['status']]);
InvRequisitionReturn::where('id',$resultItem['return_id'])->update(['status' => $data['status']]);
foreach ($attachment as $attac) {
Db::table('inv_requisition_return_approve_attachment')->insertGetId([
'requisition_id' => $resultItem['requisition_id'],
'return_id' => $resultItem['return_id'],
'file_name' => $attac['original_name'],
'file_path' => $attac['file_path'],
'created_at' => time(),
]);
}
if ($updateResult === 0) {
throw new BusinessException('更新归还申请失败,可能记录不存在或已被处理');
}