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 @@ +
+ {$step.title} +
+ {if $step.status == 1} +工单编号 | +{$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}
+
+ |
+
位置 | ++ + | +
- {$step.title} -
- {if $step_index >= $index} - {if $step.status == 2} -