From 4046811b6d9509a6cd4367d669f113e9fd2fecca Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 20 Mar 2025 10:08:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/controller/Approval.php | 3 + .../src/controller/ApprovalInstance.php | 180 +++++++++++++++ .../src/controller/Ticket.php | 74 +------ .../src/model/ApprovalInstance.php | 9 +- .../src/view/approval_instance/detail.html | 207 ++++++++++++++++++ .../src/view/approval_instance/index.html | 77 +++++++ .../view/approval_instance/index_search.html | 27 +++ .../src/view/ticket/detail.html | 68 ------ .../src/view/ticket/index.html | 24 +- 9 files changed, 521 insertions(+), 148 deletions(-) create mode 100644 plugs/think-plugs-ticket/src/controller/ApprovalInstance.php create mode 100644 plugs/think-plugs-ticket/src/view/approval_instance/detail.html create mode 100644 plugs/think-plugs-ticket/src/view/approval_instance/index.html create mode 100644 plugs/think-plugs-ticket/src/view/approval_instance/index_search.html diff --git a/plugs/think-plugs-ticket/src/controller/Approval.php b/plugs/think-plugs-ticket/src/controller/Approval.php index dbe3aa3..ad03626 100644 --- a/plugs/think-plugs-ticket/src/controller/Approval.php +++ b/plugs/think-plugs-ticket/src/controller/Approval.php @@ -7,6 +7,9 @@ use think\admin\Controller; use think\admin\helper\QueryHelper; use think\admin\model\SystemUser; +/** + * 审核流程管理 + */ class Approval extends Controller { /** diff --git a/plugs/think-plugs-ticket/src/controller/ApprovalInstance.php b/plugs/think-plugs-ticket/src/controller/ApprovalInstance.php new file mode 100644 index 0000000..64194f0 --- /dev/null +++ b/plugs/think-plugs-ticket/src/controller/ApprovalInstance.php @@ -0,0 +1,180 @@ +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('审核成功!'); + } +} \ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/controller/Ticket.php b/plugs/think-plugs-ticket/src/controller/Ticket.php index a29e344..51b9c16 100644 --- a/plugs/think-plugs-ticket/src/controller/Ticket.php +++ b/plugs/think-plugs-ticket/src/controller/Ticket.php @@ -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 = '待我审核'; diff --git a/plugs/think-plugs-ticket/src/model/ApprovalInstance.php b/plugs/think-plugs-ticket/src/model/ApprovalInstance.php index 141827c..9f57f02 100644 --- a/plugs/think-plugs-ticket/src/model/ApprovalInstance.php +++ b/plugs/think-plugs-ticket/src/model/ApprovalInstance.php @@ -42,11 +42,10 @@ class ApprovalInstance extends Model public function getStatusTextAttr($value, $data) { $statusMap = [ - 0 => '待提交', - 1 => '进行中', - 2 => '已通过', - 3 => '已驳回', - 4 => '已取消' + -1 => '已取消', + 0 => '进行中', + 1 => '已通过', + 2 => '已驳回', ]; return $statusMap[$data['status']] ?? '未知'; } diff --git a/plugs/think-plugs-ticket/src/view/approval_instance/detail.html b/plugs/think-plugs-ticket/src/view/approval_instance/detail.html new file mode 100644 index 0000000..69d6d6f --- /dev/null +++ b/plugs/think-plugs-ticket/src/view/approval_instance/detail.html @@ -0,0 +1,207 @@ +
+ +
+
+
+
+
审核流程
+
+
+
+ +
+

提交审核

+
+
+ {foreach $instance.steps as $index=>$step} +
+ +
+

第{$index+1}步{if $instance.current_step == $index}(当前步骤){/if}

+

+ {$step.title} +

+ {if $step.status == 1} +
+
+ 已通过 + {$step.approver.nickname}于{$step.approve_time|date='Y-m-d H:i:s'}审核通过 +
+
+ {elseif $step.status == 2} +
+
+ 已驳回 + {$step.approver.nickname}于{$step.approve_time|date='Y-m-d H:i:s'}审核驳回 +
+
+ {else} +
+ 待审核 +
+ {/if} +
+
+ {/foreach} +
+
+
+
+
+
工单审核
+
+ {if $instance.current && $instance.current.status == 0} + {if $instance.current.approver_id == $user_id} +
+ + + +
+ +
+ + +
+
+
+ +
+ +
+
+ {if !($next_step->isEmpty()) && $next_step.approver_type == 3} +
+ +
+ +
+
+ {/if} +
+
+ + +
+
+
+ {else} +
+ + 当前工单正等待审核。 +
+ {/if} + {/if} + +
+
+
+
+
+
工单内容
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {if $ticket.lat && $ticket.lng} + + + + + {/if} + +
工单编号{$ticket.id|default=""}
工单标题{$ticket.title|default=""}
工单类型{$ticket.type_name|default=""}
工单地址{$ticket.ticket_region|default=""} {$ticket.ticket_address|default=""}
工单内容{$ticket.content|default=""}
反馈人信息{$ticket.contact_name|default="未填写名称"} {$ticket.contact_phone|default="未填写联系方式"}
工单图片 +
+ {if count($ticket.imgs_arr) > 0} + {foreach $ticket.imgs_arr as $img} + image +   + {/foreach} + {else} + 无图片 + {/if} +
+
位置 +
+
+
+ {if $ticket.lat && $ticket.lng} + + + {/if} +
+
+
+
+
\ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/view/approval_instance/index.html b/plugs/think-plugs-ticket/src/view/approval_instance/index.html new file mode 100644 index 0000000..ea541eb --- /dev/null +++ b/plugs/think-plugs-ticket/src/view/approval_instance/index.html @@ -0,0 +1,77 @@ +{extend name="table"} + +{block name="button"} +{/block} + +{block name="content"} +
+
+
+ {include file='approval_instance/index_search'} +
+
+
+
+ + +{/block} + + +{block name='style'} + +{/block} + +{block name='script'} + +{/block} \ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/view/approval_instance/index_search.html b/plugs/think-plugs-ticket/src/view/approval_instance/index_search.html new file mode 100644 index 0000000..e7ad406 --- /dev/null +++ b/plugs/think-plugs-ticket/src/view/approval_instance/index_search.html @@ -0,0 +1,27 @@ +
+ 条件搜索 + + +
diff --git a/plugs/think-plugs-ticket/src/view/ticket/detail.html b/plugs/think-plugs-ticket/src/view/ticket/detail.html index 2977f2d..1814971 100644 --- a/plugs/think-plugs-ticket/src/view/ticket/detail.html +++ b/plugs/think-plugs-ticket/src/view/ticket/detail.html @@ -1,7 +1,6 @@
@@ -106,73 +105,6 @@
-
-
-
审核情况
-
- {empty name='instance'} -
-
- - 该工单没有提交审核流程 -
-
- {else} -
-
- -
-

提交审核{if $step_index == -1}(当前步骤){/if}

-
-
- {foreach $instance.steps as $index=>$step} -
- -
-

第{$index+1}步{if $step_index == $index}(当前步骤){/if}

-

- {$step.title} -

- {if $step_index >= $index} - {if $step.status == 2} -
- - 审核未通过 -
- {elseif $step.status == 1} -
- - 审核通过 -
- {elseif $step.status == 0} -
- - 审核中 -
- {/if} -
- -
- {$step.approver.nickname|default=""} -
-
- {if $step.status != 0} -
- -
- {$step.content|default=""} -
-
- {/if} - {/if} -
-
- {/foreach} -
- {/empty} -
-
-
现场核实情况
diff --git a/plugs/think-plugs-ticket/src/view/ticket/index.html b/plugs/think-plugs-ticket/src/view/ticket/index.html index 03bd37c..ac5c583 100644 --- a/plugs/think-plugs-ticket/src/view/ticket/index.html +++ b/plugs/think-plugs-ticket/src/view/ticket/index.html @@ -72,9 +72,11 @@ if (item.view_process.status === 0) { return `正在审核` } else if (item.view_process.status === 1) { - return `已通过` + return `创建核验工单`; } else if (item.view_process.status === 2) { - return `提请核验`; + return `已驳回`; + } else if (item.view_process.status === -1) { + return `已取消` } } else { return `提请核验`; @@ -93,6 +95,15 @@ } if (item.repair_pid) { // 已有维修流程 + if (item.repair_process.status === 0) { + return `正在审核` + } else if (item.repair_process.status === 1) { + return `已通过` + } else if (item.repair_process.status === 2) { + return `提请维修`; + } else if (item.repair_process.status === -1) { + return `已取消` + } } else { return `提请维修`; } @@ -114,6 +125,15 @@ } if (item.verify_pid) { // 已有验收流程 + if (item.verify_process.status === 0) { + return `正在审核` + } else if (item.verify_process.status === 1) { + return `已通过` + } else if (item.verify_process.status === 2) { + return `提请验收`; + } else if (item.verify_process.status === -1) { + return `已取消` + } } else { return `提请验收`; }