审核详情

This commit is contained in:
2025-03-20 10:08:23 +08:00
parent 05a0577d3e
commit 4046811b6d
9 changed files with 521 additions and 148 deletions

View File

@ -7,6 +7,9 @@ use think\admin\Controller;
use think\admin\helper\QueryHelper;
use think\admin\model\SystemUser;
/**
* 审核流程管理
*/
class Approval extends Controller
{
/**

View File

@ -0,0 +1,180 @@
<?php
namespace plugin\ticket\controller;
use plugin\ticket\model\ApprovalStep;
use plugin\ticket\model\TicketTicket;
use think\admin\Controller;
use plugin\ticket\model\ApprovalInstance as Model;
use think\admin\helper\QueryHelper;
use think\admin\model\SystemUser;
use think\exception\HttpResponseException;
/**
* 去审核
*/
class ApprovalInstance extends Controller
{
/**
* 审批流程列表
* @auth true
* @menu true
*/
public function index()
{
$this->title = '审批流程管理';
$this->user_id = $this->request->session('user')['id'];
Model::mQuery()->layTable(function () {
}, function (QueryHelper $query) {
$query->like('title')->equal('status');
$query->dateBetween('create_time');
$query->with(['steps'])->append(['current', 'status_text']);
});
}
/**
* 审批流程详情
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function detail()
{
$this->title = '审批流程详情';
$this->user_id = $this->request->session('user')['id'];
$this->id = $this->request->get('id');
$instance = Model::query()->where('id', '=', $this->id)->with(['steps', 'process'])->append(['current'])->findOrEmpty();
if ($instance->isEmpty()) {
$this->error('审批流程不存在');
}
$this->vo = $instance;
$this->instance = $instance;
$this->steps = $instance->steps;
$this->step_index = $instance->current_step;
if (sizeof($instance->steps) <= ($instance->current_step + 1)) {
$this->next_step = ApprovalStep::mk(['approver_type' => 0]);
} else {
$this->next_step = $instance->steps[$instance->current_step + 1];
}
$this->users = SystemUser::query()->field('id,username,nickname')->select();
$this->process = $instance->process;
switch ($instance->process->type) {
case 'HSSH':
// 核实工单
$this->ticket = TicketTicket::query()->where('view_pid', '=', $instance->id)->with(['views', 'repairs', 'verifys'])->findOrEmpty();
break;
case 'WXSH':
// 维修审核
$this->ticket = TicketTicket::query()->where('repair_pid', '=', $instance->id)->with(['views', 'repairs', 'verifys'])->findOrEmpty();
break;
case 'YSSH':
// 验收审核
$this->ticket = TicketTicket::query()->where('verify_pid', '=', $instance->id)->with(['views', 'repairs', 'verifys'])->findOrEmpty();
break;
default:
$this->ticket = TicketTicket::mk([]);
}
$this->fetch();
}
/**
* 取消审批
* @auth true
* @return void
*/
public function cancel()
{
$this->id = $this->request->param('id');
$instance = Model::query()->where('id', '=', $this->id)->with(['steps'])->append(['current'])->findOrEmpty();
if ($instance->isEmpty()) {
$this->error('审批流程不存在');
}
if ($instance->status !== 0) {
$this->error('当前无法取消该审批流程');
} else {
Model::mk()->startTrans();
try {
foreach ($instance->steps as $step) {
if ($step->status === 0) {
$step->status = -1;
$step->save();
}
}
$instance->status = -1;
$instance->save();
} catch (\Exception $e) {
Model::mk()->rollback();
$this->error($e->getMessage());
}
$this->success('取消审批成功');
}
}
/**
* 进行审核
* @return void
* @throws \Exception
*
* @auth true
* @menu true
*/
public function do_approve()
{
$data = $this->_vali([
'id.require'=>'请指定当前审核ID!',
'step_index.require'=>'请指定当前步骤!',
'status.require'=>'请指定审核结果!',
'content.default'=>'',
]);
$adminInfo = $this->request->session('user');
$instance = Model::query()->with('steps')->findOrEmpty($data['id']);
if ($instance->isEmpty()) {
$this->error('审核流程不存在!');
}
if ($instance->status == 1) {
$this->error('工单已通过,请勿重复操作!');
} else if ($instance->status == 2) {
$this->error('工单已驳回,请勿重复操作!');
}
if ($instance->current_step != $data['step_index']) {
$this->error('当前步骤不正确!');
}
if ($instance->current->approver_id != $adminInfo['id']) {
$this->error('您不是当前审核人,请勿操作!');
}
Model::mk()->startTrans();
try {
$instance->current->status = $data['status'];
$instance->current->content = $data['content'];
$instance->current->approve_time = date('Y-m-d H:i:s');
$instance->current->save();
if ($data['status'] == 2) {
$instance->status = 2;
} else {
$instance->current_step++;
if ($instance->current_step >= count($instance->steps)) {
$instance->status = 1;
} else {
$step = $instance->steps[$instance->current_step];
if ($step['approver_type'] == 3) {
$approve_data = $this->_vali([
'approver_id.require' => '请指定审核人!',
]);
$step->approver_id = $approve_data['approver_id'];
$step->save();
}
}
}
$instance->save();
Model::mk()->commit();
} catch (HttpResponseException $e) {
Model::mk()->rollback();
throw $e;
} catch (\Exception $e) {
Model::mk()->rollback();
$this->error("审核失败");
}
$this->success('审核成功!');
}
}

View File

@ -496,79 +496,7 @@ class Ticket extends Controller
}
}
/**
* 进行审核
* @return void
* @throws \Exception
*
* @auth true
* @menu true
*/
public function do_approve()
{
$data = $this->_vali([
'id.require'=>'请指定工单ID!',
'instance_id.require'=>'请指定当前审核ID!',
'step_index.require'=>'请指定当前步骤!',
'status.require'=>'请指定审核结果!',
'content.default'=>'',
]);
$ticket = TicketTicket::query()->findOrEmpty($data['id']);
if ($ticket->isEmpty()) {
$this->error('工单不存在!');
}
$adminInfo = $this->request->session('user');
$instance = ApprovalInstance::query()->with('steps')->findOrEmpty($data['instance_id']);
if ($instance->isEmpty()) {
$this->error('审核流程不存在!');
}
if ($instance->status == 1) {
$this->error('工单已通过,请勿重复操作!');
} else if ($instance->status == 2) {
$this->error('工单已驳回,请勿重复操作!');
}
if ($instance->current_step != $data['step_index']) {
$this->error('当前步骤不正确!');
}
if ($instance->current->approver_id != $adminInfo['id']) {
$this->error('您不是当前审核人,请勿操作!');
}
ApprovalInstance::mk()->startTrans();
try {
$instance->current->status = $data['status'];
$instance->current->content = $data['content'];
$instance->current->save();
if ($data['status'] == 2) {
$instance->status = 2;
} else {
$instance->current_step++;
if ($instance->current_step >= count($instance->steps)) {
$instance->status = 1;
$ticket->status = 0;
$ticket->save();
} else {
$step = $instance->steps[$instance->current_step];
if ($step['approver_type'] == 3) {
$approve_data = $this->_vali([
'approver_id.require' => '请指定审核人!',
]);
$step->approver_id = $approve_data['approver_id'];
$step->save();
}
}
}
$instance->save();
ApprovalInstance::mk()->commit();
} catch (HttpResponseException $e) {
ApprovalInstance::mk()->rollback();
throw $e;
} catch (\Exception $e) {
ApprovalInstance::mk()->rollback();
// $this->error("审核失败");
throw $e;
}
$this->success('审核成功!');
}
public function my() {
$this->title = '待我审核';