diff --git a/plugs/think-plugs-ticket/src/controller/Ticket.php b/plugs/think-plugs-ticket/src/controller/Ticket.php index 248971a..a29e344 100644 --- a/plugs/think-plugs-ticket/src/controller/Ticket.php +++ b/plugs/think-plugs-ticket/src/controller/Ticket.php @@ -41,7 +41,7 @@ class Ticket extends Controller $query->like(['title|content|contact_name|ticket_address|contact_phone#keyword']) ->dateBetween(['create_at']) ->equal(['status', 'type_id']); - $query->append(['imgs_arr', 'source_type_name', 'type_name', 'last_reply'])->with(['views', 'repairs', 'verifys']); + $query->append(['imgs_arr', 'source_type_name', 'type_name', 'last_reply'])->with(['views', 'repairs', 'verifys', 'view_process', 'repair_process', 'verify_process']); }); } @@ -283,6 +283,219 @@ class Ticket extends Controller $this->success('创建成功!'); } + public function view_process_create() + { + $data = $this->_vali([ + 'ticket_id.require'=>'请指定工单ID!', + ]); + $process = ApprovalProcess::where('type', '=', 'HSSH')->order('id', 'asc')->findOrEmpty(); + if ($process->isEmpty()) { + $this->error('未找到可用的审核流程'); + } + $adminInfo = $this->request->session('user'); + $ticket = TicketTicket::query()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty(); + if ($ticket->isEmpty()) { + $this->error('未找到工单信息'); + } + if ($this->request->isPost()) { + $instance_data = $this->_vali([ + 'title.default'=>'核验工单审核', + 'content.default'=>'', + ]); + ApprovalInstance::mk()->startTrans(); + try { + $instance = ApprovalInstance::create([ + 'process_id' => $process->id, + 'oid' => $ticket->id, + 'title' => $instance_data['title'], + 'content' => $instance_data['content'], + 'status' => 0, + 'current_step' => 0, + 'create_time' => date('Y-m-d H:i:s'), + 'create_by' => $adminInfo['id'], + 'create_name' => $adminInfo['username'], + ]); + foreach ($process->steps as $index => $step) { + $approver_id = $step['approver_id'] ?? 0; + if ($index == 0) { + if ($step['approver_type'] == 3) { + $approve_data = $this->_vali([ + 'approver_id.require' => '请指定审核人!', + ]); + $approver_id = $approve_data['approver_id']; + } + } + ApprovalStep::create([ + 'instance_id' => $instance->id, + 'step_number' => $index, + 'approver_type' => $step['approver_type'], + 'approver_id' => $approver_id, + 'status' => 0, + ]); + } + $ticket->view_pid = $instance->id; + $ticket->save(); + ApprovalInstance::mk()->commit(); + } catch (HttpResponseException $e) { + ApprovalInstance::mk()->rollback(); + throw $e; + } catch (\Exception $e) { + ApprovalInstance::mk()->rollback(); + $this->error("创建失败"); + } + $this->success('创建成功!'); + } else { + $this->vo = $ticket; + $this->process = $process; + $this->step_index = -1; + $this->current_step = $process->steps[0]; + $this->users = SystemUser::query()->field('id,username,nickname')->select(); + $this->fetch(); + } + } + + public function repair_process_create() + { + $data = $this->_vali([ + 'ticket_id.require'=>'请指定工单ID!', + ]); + $process = ApprovalProcess::where('type', '=', 'WXSH')->order('id', 'asc')->findOrEmpty(); + if ($process->isEmpty()) { + $this->error('未找到可用的审核流程'); + } + $adminInfo = $this->request->session('user'); + $ticket = TicketTicket::query()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty(); + if ($ticket->isEmpty()) { + $this->error('未找到工单信息'); + } + if ($this->request->isPost()) { + $instance_data = $this->_vali([ + 'title.default'=>'核验工单审核', + 'content.default'=>'', + ]); + ApprovalInstance::mk()->startTrans(); + try { + $instance = ApprovalInstance::create([ + 'process_id' => $process->id, + 'oid' => $ticket->id, + 'title' => $instance_data['title'], + 'content' => $instance_data['content'], + 'status' => 0, + 'current_step' => 0, + 'create_time' => date('Y-m-d H:i:s'), + 'create_by' => $adminInfo['id'], + 'create_name' => $adminInfo['username'], + ]); + foreach ($process->steps as $index => $step) { + $approver_id = $step['approver_id'] ?? 0; + if ($index == 0) { + if ($step['approver_type'] == 3) { + $approve_data = $this->_vali([ + 'approver_id.require' => '请指定审核人!', + ]); + $approver_id = $approve_data['approver_id']; + } + } + ApprovalStep::create([ + 'instance_id' => $instance->id, + 'step_number' => $index, + 'approver_type' => $step['approver_type'], + 'approver_id' => $approver_id, + 'status' => 0, + ]); + } + $ticket->view_pid = $instance->id; + $ticket->save(); + ApprovalInstance::mk()->commit(); + } catch (HttpResponseException $e) { + ApprovalInstance::mk()->rollback(); + throw $e; + } catch (\Exception $e) { + ApprovalInstance::mk()->rollback(); + $this->error("创建失败"); + } + $this->success('创建成功!'); + } else { + $this->vo = $ticket; + $this->process = $process; + $this->step_index = -1; + $this->current_step = $process->steps[0]; + $this->users = SystemUser::query()->field('id,username,nickname')->select(); + $this->fetch(); + } + } + + public function verify_process_create() + { + $data = $this->_vali([ + 'ticket_id.require'=>'请指定工单ID!', + ]); + $process = ApprovalProcess::where('type', '=', 'YSSH')->order('id', 'asc')->findOrEmpty(); + if ($process->isEmpty()) { + $this->error('未找到可用的审核流程'); + } + $adminInfo = $this->request->session('user'); + $ticket = TicketTicket::query()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty(); + if ($ticket->isEmpty()) { + $this->error('未找到工单信息'); + } + if ($this->request->isPost()) { + $instance_data = $this->_vali([ + 'title.default'=>'核验工单审核', + 'content.default'=>'', + ]); + ApprovalInstance::mk()->startTrans(); + try { + $instance = ApprovalInstance::create([ + 'process_id' => $process->id, + 'oid' => $ticket->id, + 'title' => $instance_data['title'], + 'content' => $instance_data['content'], + 'status' => 0, + 'current_step' => 0, + 'create_time' => date('Y-m-d H:i:s'), + 'create_by' => $adminInfo['id'], + 'create_name' => $adminInfo['username'], + ]); + foreach ($process->steps as $index => $step) { + $approver_id = $step['approver_id'] ?? 0; + if ($index == 0) { + if ($step['approver_type'] == 3) { + $approve_data = $this->_vali([ + 'approver_id.require' => '请指定审核人!', + ]); + $approver_id = $approve_data['approver_id']; + } + } + ApprovalStep::create([ + 'instance_id' => $instance->id, + 'step_number' => $index, + 'approver_type' => $step['approver_type'], + 'approver_id' => $approver_id, + 'status' => 0, + ]); + } + $ticket->view_pid = $instance->id; + $ticket->save(); + ApprovalInstance::mk()->commit(); + } catch (HttpResponseException $e) { + ApprovalInstance::mk()->rollback(); + throw $e; + } catch (\Exception $e) { + ApprovalInstance::mk()->rollback(); + $this->error("创建失败"); + } + $this->success('创建成功!'); + } else { + $this->vo = $ticket; + $this->process = $process; + $this->step_index = -1; + $this->current_step = $process->steps[0]; + $this->users = SystemUser::query()->field('id,username,nickname')->select(); + $this->fetch(); + } + } + /** * 进行审核 * @return void diff --git a/plugs/think-plugs-ticket/src/model/ApprovalInstance.php b/plugs/think-plugs-ticket/src/model/ApprovalInstance.php index 791872c..141827c 100644 --- a/plugs/think-plugs-ticket/src/model/ApprovalInstance.php +++ b/plugs/think-plugs-ticket/src/model/ApprovalInstance.php @@ -24,7 +24,7 @@ class ApprovalInstance extends Model // 关联审批步骤 public function steps() { - return $this->hasMany(ApprovalStep::class, 'instance_id', 'id'); + return $this->hasMany(ApprovalStep::class, 'instance_id', 'id')->with('approver'); } public function getCurrentAttr($value, $data) diff --git a/plugs/think-plugs-ticket/src/model/ApprovalStep.php b/plugs/think-plugs-ticket/src/model/ApprovalStep.php index 77981a7..4d10739 100644 --- a/plugs/think-plugs-ticket/src/model/ApprovalStep.php +++ b/plugs/think-plugs-ticket/src/model/ApprovalStep.php @@ -31,7 +31,8 @@ class ApprovalStep extends Model public function getApproverTypeTextAttr($value, $data) { $typeMap = [ - 0 => '指定用户', + 0 => '固定用户', + 3 => '指定用户', // 1 => '指定部门', // 2 => '角色审批' ]; diff --git a/plugs/think-plugs-ticket/src/model/TicketTicket.php b/plugs/think-plugs-ticket/src/model/TicketTicket.php index 7352be5..a44f94e 100644 --- a/plugs/think-plugs-ticket/src/model/TicketTicket.php +++ b/plugs/think-plugs-ticket/src/model/TicketTicket.php @@ -113,16 +113,16 @@ class TicketTicket extends Model return $this->hasMany(TicketView::class, 'ticket_id')->order('create_at', 'desc'); } - public function view_process() { + public function viewProcess() { return $this->belongsTo(ApprovalInstance::class, 'view_pid', 'id'); } - public function repair_process() + public function repairProcess() { return $this->belongsTo(ApprovalInstance::class, 'repair_pid', 'id'); } - public function verify_process() + public function verifyProcess() { return $this->belongsTo(ApprovalInstance::class, 'verify_pid', 'id'); } diff --git a/plugs/think-plugs-ticket/src/view/approval/form.html b/plugs/think-plugs-ticket/src/view/approval/form.html index 2e02e72..484f82d 100644 --- a/plugs/think-plugs-ticket/src/view/approval/form.html +++ b/plugs/think-plugs-ticket/src/view/approval/form.html @@ -12,6 +12,9 @@
@@ -69,7 +72,7 @@ $(function () { cols: [[ {field:'title', title:'步骤名称', width:160, edit: true}, {field:'approver_type', title:'审批人类型', width:160, templet: '#approverType'}, - {field:'approver_id', title:'审批人类型', width:160, templet: '#approverId'}, + {field:'approver_id', title:'选择审批人', width:160, templet: '#approverId'}, {align: 'center', toolbar: '#editToolbar', title: '操作', width: 200} ]], data: stepsData, diff --git a/plugs/think-plugs-ticket/src/view/ticket/index.html b/plugs/think-plugs-ticket/src/view/ticket/index.html index 3498598..03bd37c 100644 --- a/plugs/think-plugs-ticket/src/view/ticket/index.html +++ b/plugs/think-plugs-ticket/src/view/ticket/index.html @@ -69,14 +69,27 @@ {field: 'view', title:'核验情况', width: 100, minWidth:100, templet:function(item){ if (item.view_pid) { // 已有核验流程 + if (item.view_process.status === 0) { + return `正在审核` + } else if (item.view_process.status === 1) { + return `已通过` + } else if (item.view_process.status === 2) { + return `提请核验`; + } } else { return `提请核验`; } }}, {field: 'repair', title:'维修情况', width: 100, minWidth:100, templet:function(item){ - if (!item.views || item.views.length === 0) { - // 还没有核验流程 - return `请先核验` + if (item.source_type === 1) { + // 用户随手拍 + if (!item.views || item.views.length === 0) { + // 还没有核验流程 + return `请先核验` + } + if (item.views[item.views.length - 1].status !== 1) { + return `请先完成核验` + } } if (item.repair_pid) { // 已有维修流程 @@ -85,9 +98,15 @@ } }}, {field: 'verify', title:'验收情况', width: 100, minWidth:100, templet:function(item){ - if (!item.views || item.views.length === 0) { - // 还没有核验流程 - return `请先核验` + if (item.source_type === 1) { + // 用户随手拍 + if (!item.views || item.views.length === 0) { + // 还没有核验流程 + return `请先核验` + } + if (item.views[item.views.length - 1].status !== 1) { + return `请先完成核验` + } } if (!item.repairs || item.repairs.length === 0) { // 还没有维修流程 diff --git a/plugs/think-plugs-ticket/src/view/ticket/repair_process_create.html b/plugs/think-plugs-ticket/src/view/ticket/repair_process_create.html new file mode 100644 index 0000000..743e4e0 --- /dev/null +++ b/plugs/think-plugs-ticket/src/view/ticket/repair_process_create.html @@ -0,0 +1,59 @@ +
+
+
审核流程
+
+
+
+ +
+

提交审核

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

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

+

+ {$step.title} +

+
+
+ {/foreach} +
+
+
+
+
+
创建审核单
+
+
+ +
+ +
+ +
+
+ {if $current_step.approver_type == 3} +
+ +
+ +
+
+ {/if} +
+
+ + +
+
+
+
+
\ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/view/ticket/verify_process_create.html b/plugs/think-plugs-ticket/src/view/ticket/verify_process_create.html new file mode 100644 index 0000000..743e4e0 --- /dev/null +++ b/plugs/think-plugs-ticket/src/view/ticket/verify_process_create.html @@ -0,0 +1,59 @@ +
+
+
审核流程
+
+
+
+ +
+

提交审核

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

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

+

+ {$step.title} +

+
+
+ {/foreach} +
+
+
+
+
+
创建审核单
+
+
+ +
+ +
+ +
+
+ {if $current_step.approver_type == 3} +
+ +
+ +
+
+ {/if} +
+
+ + +
+
+
+
+
\ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/view/ticket/view_process_create.html b/plugs/think-plugs-ticket/src/view/ticket/view_process_create.html new file mode 100644 index 0000000..743e4e0 --- /dev/null +++ b/plugs/think-plugs-ticket/src/view/ticket/view_process_create.html @@ -0,0 +1,59 @@ +
+
+
审核流程
+
+
+
+ +
+

提交审核

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

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

+

+ {$step.title} +

+
+
+ {/foreach} +
+
+
+
+
+
创建审核单
+
+
+ +
+ +
+ +
+
+ {if $current_step.approver_type == 3} +
+ +
+ +
+
+ {/if} +
+
+ + +
+
+
+
+
\ No newline at end of file