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 @@
+ {$step.title} +
++ {$step.title} +
++ {$step.title} +
+