From b6ff9b1a6eb9de1e0ab0e0a95d4fd0aec8ca041a Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sun, 23 Mar 2025 13:21:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/controller/InspectionShare.php | 2 +- .../src/controller/Ticket.php | 18 +- .../src/controller/TicketInter.php | 515 +++++++++++++++++- .../src/controller/TicketOuter.php | 168 +++++- .../src/controller/UserShare.php | 2 +- .../src/model/TicketTicketInter.php | 84 --- .../src/model/TicketTicketOuter.php | 84 --- .../src/view/ticket/index.html | 112 +--- .../src/view/ticket_inter/index.html | 160 +++++- .../src/view/ticket_outer/index.html | 63 ++- 10 files changed, 863 insertions(+), 345 deletions(-) diff --git a/plugs/think-plugs-ticket/src/controller/InspectionShare.php b/plugs/think-plugs-ticket/src/controller/InspectionShare.php index 6539d35..3513a88 100644 --- a/plugs/think-plugs-ticket/src/controller/InspectionShare.php +++ b/plugs/think-plugs-ticket/src/controller/InspectionShare.php @@ -93,7 +93,7 @@ class InspectionShare extends Controller 'lat' => $share->ticket_lat, 'lng' => $share->ticket_lng, 'imgs' => $share->imgs, - 'status' => -1, // 先审核 + 'status' => 0, // 先审核 ]); $ticket->source = $share; $ticket->save(); diff --git a/plugs/think-plugs-ticket/src/controller/Ticket.php b/plugs/think-plugs-ticket/src/controller/Ticket.php index 783cbc6..695c0a7 100644 --- a/plugs/think-plugs-ticket/src/controller/Ticket.php +++ b/plugs/think-plugs-ticket/src/controller/Ticket.php @@ -148,6 +148,15 @@ class Ticket extends Controller } } + /** + * 工单分配 + * @auth true + * @menu true + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ public function move() { $this->title = "工单分配"; @@ -170,19 +179,12 @@ class Ticket extends Controller // 外部 $ticket->state = 2; } - if ($ticket->fz_user_id) { - $staff = InspectionStaff::query()->find($ticket->fz_user_id); - $staff->messages()->save([ - 'title' => "您有新的工单待处理", - 'content' => "您有新的工单待处理,请及时处理。", - ]); - } $ticket->status = 1; $ticket->save(); $this->success('工单分配成功!'); } else { $this->dept_list = TicketDept::query()->scope('avail')->select(); - $this->user_list = InspectionStaff::query()->select(); + $this->user_list = SystemUser::query()->select(); $this->fetch(); } } diff --git a/plugs/think-plugs-ticket/src/controller/TicketInter.php b/plugs/think-plugs-ticket/src/controller/TicketInter.php index 5c09d22..49900e7 100644 --- a/plugs/think-plugs-ticket/src/controller/TicketInter.php +++ b/plugs/think-plugs-ticket/src/controller/TicketInter.php @@ -2,10 +2,18 @@ namespace plugin\ticket\controller; +use plugin\inspection\model\InspectionStaff; +use plugin\ticket\model\ApprovalInstance; +use plugin\ticket\model\ApprovalProcess; +use plugin\ticket\model\ApprovalStep; +use plugin\ticket\model\TicketReply; +use plugin\ticket\model\TicketTicket; use plugin\ticket\model\TicketTicketInter; use plugin\ticket\model\TicketType; use think\admin\Controller; use think\admin\helper\QueryHelper; +use think\admin\model\SystemUser; +use think\exception\HttpResponseException; /** * 内部工单管理 @@ -32,23 +40,17 @@ class TicketInter 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', 'status_text', 'type_name']); + $query->append(['imgs_arr', 'source_type_name', 'type_name', 'last_reply'])->with(['user_shares', 'views', 'repairs', 'verifys', 'view_process', 'repair_process', 'verify_process']); }); } - public function my() + public function _form_filter(&$data) { - $this->title = '我的工单'; - $this->user_id = $this->request->session('user')['id']; - TicketTicketInter::mQuery()->layTable(function () { - - }, function (QueryHelper $query) { - $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', 'status_text', 'type_name']); - $query->where(['current_admin_id' => $this->user_id]); - }); + if ($this->request->isPost()) { + $data['user_id'] = 0; + } + ApprovalInstance::query()->where('oid', '=', $data['id'])->delete(); + $data['status'] = -1; } /** @@ -61,8 +63,493 @@ class TicketInter extends Controller { $this->title = '工单详情'; ['id' => $id] = $this->_vali(['id.require' => '请指定工单ID!']); - $this->vo = TicketTicketInter::mk()->with(['user', 'type', 'reply'])->append(['imgs_arr', 'status_text', 'type_name', 'last_reply'])->find($id); + $this->vo = TicketTicketInter::mk()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->find($id); + $this->ticket = $this->vo; + $process = ApprovalProcess::where('type', '=', 'GDSH')->order('id', 'asc')->findOrEmpty(); + $instance = ApprovalInstance::query()->with(['steps.approver', 'logs'])->where('process_id', '=', $process->id)->where('oid', '=', $id)->findOrEmpty(); + $this->instance = $instance; + if ($instance->isEmpty()) { + $this->step_index = -1; + } else { + $this->step_index = $instance->current_step; + } $this->fetch(); } + public function reply() + { + $this->title = '回复工单'; + [ + 'ticket_id'=>$ticket_id, + 'id'=>$id + ] = $this->_vali([ + 'ticket_id.require'=>'请指定工单ID!', + 'id.require'=>'请指定回复ID!' + ]); + $this->vo = TicketTicket::mk()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->find($ticket_id); + TicketReply::mForm('reply'); + } + + public function _reply_form_filter(&$data) + { + if ($this->request->isPost()) { + $this->_applyFormToken(); + $data['type'] = 1; + $adminInfo = $this->request->session('user'); + $data['user_id'] = $adminInfo['id']; + $data['username'] = $adminInfo['nickname']; + $data['contact'] = $adminInfo['contact_phone']; + } + } + + + /** + * 审核页面 + * @auth true + * @menu true + */ + public function approve() + { + $this->title = '审核流程'; + [ + 'id'=>$id + ] = $this->_vali([ + 'id.require'=>'请指定回复ID!' + ]); + $this->vo = TicketTicket::query()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->find($id); + $process = ApprovalProcess::where('type', '=', 'GDSH')->order('id', 'asc')->findOrEmpty(); + if ($process->isEmpty()) { + $this->error('未找到可用的审核流程'); + } + $this->process = $process; + $instance = ApprovalInstance::query()->with(['steps', 'logs'])->where('process_id', '=', $process->id)->where('oid', '=', $id)->findOrEmpty(); + $this->instance = $instance; + if ($instance->isEmpty()) { + $this->step_index = -1; + $this->current_step = $process->steps[0]; + } else { + $this->step_index = $instance->current_step; + if (sizeof($instance->steps) <= ($instance->current_step + 1)) { + $this->current_step = ['approver_type' => 0]; + } else { + $this->current_step = $instance->steps[$instance->current_step + 1]; + } + } + $this->users = SystemUser::query()->field('id,username,nickname')->select(); + $this->fetch(); + } + + /** + * @return void + * @throws \Exception + * 审核提交 + * @auth true + * @menu true + */ + public function create_approval() + { + $data = $this->_vali([ + 'id.require'=>'请指定工单ID!', + 'title.default'=>'工单审核', + 'content.default'=>'', + ]); + $process = ApprovalProcess::where('type', '=', 'GDSH')->order('id', 'asc')->findOrEmpty(); + if ($process->isEmpty()) { + $this->error('未找到可用的审核流程'); + } + $adminInfo = $this->request->session('user'); + ApprovalInstance::mk()->startTrans(); + try { + $instance = ApprovalInstance::create([ + 'process_id' => $process->id, + 'oid' => $data['id'], + 'title' => $data['title'], + 'content' => $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, + ]); + } + 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 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 view_ticket_create() + { + $data = $this->_vali([ + 'ticket_id.require'=>'请指定工单ID!', + ]); + $ticket = TicketTicket::query()->with(['view_process'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty(); + $staffs = InspectionStaff::query()->field('id,name,phone')->select(); + if ($ticket->isEmpty()) { + $this->error('未找到工单信息'); + } + if ($this->request->isPost()) { + $adminInfo = $this->request->session('user'); + $instance_data = $this->_vali([ + 'staff_id.require'=>'请指定维修人员!', + ]); + $view = $ticket->views()->save([ + 'staff_id'=>$instance_data['staff_id'], + 'status'=>0, + 'create_by'=>$adminInfo['id'], + ]); + $this->success('创建成功!', $view); + } else { + $this->vo = $ticket; + $this->staffs = $staffs; + $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->repair_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_ticket_create() + { + $data = $this->_vali([ + 'ticket_id.require'=>'请指定工单ID!', + ]); + $ticket = TicketTicket::query()->with(['repair_process'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty(); + $staffs = InspectionStaff::query()->field('id,name,phone')->select(); + if ($ticket->isEmpty()) { + $this->error('未找到工单信息'); + } + if ($this->request->isPost()) { + $adminInfo = $this->request->session('user'); + $instance_data = $this->_vali([ + 'staff_id.require'=>'请指定维修人员!', + ]); + $view = $ticket->repairs()->save([ + 'staff_id'=>$instance_data['staff_id'], + 'status'=>0, + 'create_by'=>$adminInfo['id'], + ]); + $this->success('创建成功!', $view); + } else { + $this->vo = $ticket; + $this->staffs = $staffs; + $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->verify_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_ticket_create() + { + $data = $this->_vali([ + 'ticket_id.require'=>'请指定工单ID!', + ]); + $ticket = TicketTicket::query()->with(['repair_process'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty(); + $staffs = InspectionStaff::query()->field('id,name,phone')->select(); + if ($ticket->isEmpty()) { + $this->error('未找到工单信息'); + } + if ($this->request->isPost()) { + $adminInfo = $this->request->session('user'); + $instance_data = $this->_vali([ + 'staff_id.require'=>'请指定维修人员!', + ]); + $view = $ticket->verifys()->save([ + 'staff_id'=>$instance_data['staff_id'], + 'status'=>0, + 'create_by'=>$adminInfo['id'], + ]); + $this->success('创建成功!', $view); + } else { + $this->vo = $ticket; + $this->staffs = $staffs; + $this->fetch(); + } + } + + + public function my() { + $this->title = '待我审核'; + $this->type_list = TicketType::getList(); + $this->user_id = $this->request->session('user')['id']; + TicketTicket::mQuery()->layTable(function () { + + }, function (QueryHelper $query) { + $query->like(['title|content|contact_name|ticket_address|contact_phone#keyword']) + ->dateBetween(['create_at']) + ->equal(['status', 'type_id']); + $query->whereIn("id", ApprovalStep::query()->where(['approver_id' => $this->user_id, 'status' => 0, 'approver_type' => 1, 'instance.status' => 0])->field("oid")->select()) + ->append(['imgs_arr', 'source_type_name', 'type_name', 'last_reply'])->with('approval'); + }); + } + + public function comment() + { + $data = $this->_vali([ + 'id.require'=>'请指定工单ID!', + ]); + $ticket = TicketTicketInter::query()->with(['user_shares'])->where('id', '=', $data['id'])->findOrEmpty(); + if ($ticket->isEmpty()) { + $this->error('未找到工单信息'); + } + if (!$ticket->user_shares || sizeof($ticket->user_shares) == 0) { + $this->error("该工单无需评论"); + } + if ($this->request->isPost()) { + $adminInfo = $this->request->session('user'); + $comment_data = $this->_vali([ + 'content.require'=>'请输入评论内容!', + ]); + TicketTicket::mk()->startTrans(); + try { + foreach ($ticket->user_shares as $share) { + $share->logs()->save([ + 'op_name' => $adminInfo["username"], + 'content' => $comment_data['content'], + 'result' => "后台用户反馈", + ]); + } + TicketTicket::mk()->commit(); + } catch (\Exception $e) { + TicketTicket::mk()->rollback(); + $this->error("保存失败"); + } + } else { + $this->vo = $ticket; + $this->ticket = $ticket; + $this->fetch(); + } + } + } \ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/controller/TicketOuter.php b/plugs/think-plugs-ticket/src/controller/TicketOuter.php index 2bd1bf6..607efc6 100644 --- a/plugs/think-plugs-ticket/src/controller/TicketOuter.php +++ b/plugs/think-plugs-ticket/src/controller/TicketOuter.php @@ -2,11 +2,19 @@ namespace plugin\ticket\controller; +use PhpOffice\PhpSpreadsheet\IOFactory; +use plugin\inspection\model\InspectionStaff; +use plugin\ticket\model\ApprovalInstance; +use plugin\ticket\model\ApprovalProcess; +use plugin\ticket\model\ApprovalStep; use plugin\ticket\model\TicketReply; +use plugin\ticket\model\TicketTicket; use plugin\ticket\model\TicketTicketOuter; use plugin\ticket\model\TicketType; use think\admin\Controller; use think\admin\helper\QueryHelper; +use think\admin\model\SystemUser; +use think\exception\HttpResponseException; /** * 外部工单管理 @@ -33,22 +41,7 @@ class TicketOuter 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', 'status_text', 'type_name', 'last_reply']); - }); - } - - public function my() - { - $this->title = '我的工单'; - $this->user_id = $this->request->session('user')['id']; - TicketTicketOuter::mQuery()->layTable(function () { - - }, function (QueryHelper $query) { - $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', 'status_text', 'type_name']); - $query->where(['current_admin_id' => $this->user_id]); + $query->append(['imgs_arr', 'source_type_name', 'type_name', 'last_reply'])->with(['user_shares', 'views', 'repairs', 'verifys', 'view_process', 'repair_process', 'verify_process']); }); } @@ -62,7 +55,148 @@ class TicketOuter extends Controller { $this->title = '工单详情'; ['id' => $id] = $this->_vali(['id.require' => '请指定工单ID!']); - $this->vo = TicketTicketOuter::mk()->with(['user', 'type', 'reply'])->append(['imgs_arr', 'status_text', 'type_name', 'last_reply'])->find($id); + $this->vo = TicketTicketOuter::mk()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->find($id); + $this->ticket = $this->vo; + $process = ApprovalProcess::where('type', '=', 'GDSH')->order('id', 'asc')->findOrEmpty(); + $instance = ApprovalInstance::query()->with(['steps.approver', 'logs'])->where('process_id', '=', $process->id)->where('oid', '=', $id)->findOrEmpty(); + $this->instance = $instance; + if ($instance->isEmpty()) { + $this->step_index = -1; + } else { + $this->step_index = $instance->current_step; + } $this->fetch(); } + + public function reply() + { + $this->title = '回复工单'; + [ + 'ticket_id'=>$ticket_id, + 'id'=>$id + ] = $this->_vali([ + 'ticket_id.require'=>'请指定工单ID!', + 'id.require'=>'请指定回复ID!' + ]); + $this->vo = TicketTicket::mk()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->find($ticket_id); + TicketReply::mForm('reply'); + } + + public function _reply_form_filter(&$data) + { + if ($this->request->isPost()) { + $this->_applyFormToken(); + $data['type'] = 1; + $adminInfo = $this->request->session('user'); + $data['user_id'] = $adminInfo['id']; + $data['username'] = $adminInfo['nickname']; + $data['contact'] = $adminInfo['contact_phone']; + } + } + + public function my() { + $this->title = '待我审核'; + $this->type_list = TicketType::getList(); + $this->user_id = $this->request->session('user')['id']; + TicketTicket::mQuery()->layTable(function () { + + }, function (QueryHelper $query) { + $query->like(['title|content|contact_name|ticket_address|contact_phone#keyword']) + ->dateBetween(['create_at']) + ->equal(['status', 'type_id']); + $query->whereIn("id", ApprovalStep::query()->where(['approver_id' => $this->user_id, 'status' => 0, 'approver_type' => 1, 'instance.status' => 0])->field("oid")->select()) + ->append(['imgs_arr', 'source_type_name', 'type_name', 'last_reply'])->with('approval'); + }); + } + + /** + * @return void + * @auth true + */ + public function import() { + $file = $this->app->request->post('file'); + if (!$file) { + // 创建一个临时Excel模板用于下载 + $this->redirect('/static/excel/ticket_import_template.xlsx'); + }; + $file = '.' . str_replace($this->app->request->domain(), '', $file); + //表格字段对应 + $fields = [ + 'A' => 'title', + 'B' => 'type_id', + 'C' => 'content', + 'D' => 'contact_name', + 'E' => 'contact_phone', + 'F' => 'contact_address', + 'G' => 'ticket_address', + ]; + //加载文件 + $spreadsheet = IOFactory::load($file); + + $sheet = $spreadsheet->getActiveSheet(); // 获取表格 + $highestRow = $sheet->getHighestRow(); // 取得总行数 + $sheetData = []; + for ($row = 2; $row <= $highestRow; $row++) { // $row表示从第几行开始读取 + foreach ($fields as $cell => $field) { + $value = $sheet->getCell($cell . $row)->getValue(); + $value = trim($value); + $sheetData[$row][$field] = $value; + } + } + $sheetData = array_values($sheetData); + foreach ($sheetData as $key => $value) { + if (!empty($value['type_id'])) { + $type = TicketType::query()->where(['id' => $value['type_id']])->find(); + if (empty($type)) { + $this->error('工单类型【'.$value['type_id'].'】不存在'); + } else { + $sheetData[$key]['type_id'] = $type['id']; + } + } + $sheetData[$key]['create_at'] = date('Y-m-d H:i:s'); + $sheetData[$key]['user_id'] = $this->request->session('user')['id']; + $sheetData[$key]['status'] = 0; + } + TicketTicket::mk()->saveAll($sheetData); + $this->success("成功"); + } + + public function comment() + { + $data = $this->_vali([ + 'id.require'=>'请指定工单ID!', + ]); + $ticket = TicketTicket::query()->with(['user_shares'])->where('id', '=', $data['id'])->findOrEmpty(); + if ($ticket->isEmpty()) { + $this->error('未找到工单信息'); + } + if (!$ticket->user_shares || sizeof($ticket->user_shares) == 0) { + $this->error("该工单无需评论"); + } + if ($this->request->isPost()) { + $adminInfo = $this->request->session('user'); + $comment_data = $this->_vali([ + 'content.require'=>'请输入评论内容!', + ]); + TicketTicket::mk()->startTrans(); + try { + foreach ($ticket->user_shares as $share) { + $share->logs()->save([ + 'op_name' => $adminInfo["username"], + 'content' => $comment_data['content'], + 'result' => "后台用户反馈", + ]); + } + TicketTicket::mk()->commit(); + } catch (\Exception $e) { + TicketTicket::mk()->rollback(); + $this->error("保存失败"); + } + } else { + $this->vo = $ticket; + $this->ticket = $ticket; + $this->fetch(); + } + } + } \ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/controller/UserShare.php b/plugs/think-plugs-ticket/src/controller/UserShare.php index 0d043ad..4c831d8 100644 --- a/plugs/think-plugs-ticket/src/controller/UserShare.php +++ b/plugs/think-plugs-ticket/src/controller/UserShare.php @@ -97,7 +97,7 @@ class UserShare extends Controller 'lat' => $share->ticket_lat, 'lng' => $share->ticket_lng, 'imgs' => $share->imgs, - 'status' => -1, + 'status' => 0, ]); $ticket->source = $share; $ticket->save(); diff --git a/plugs/think-plugs-ticket/src/model/TicketTicketInter.php b/plugs/think-plugs-ticket/src/model/TicketTicketInter.php index c189f0f..6999d4c 100644 --- a/plugs/think-plugs-ticket/src/model/TicketTicketInter.php +++ b/plugs/think-plugs-ticket/src/model/TicketTicketInter.php @@ -6,88 +6,4 @@ class TicketTicketInter extends TicketTicket { protected $globalScope = ['inter']; protected $table = 'ticket_ticket'; - public function type() - { - return $this->belongsTo(TicketType::class, 'type_id'); - } - - public function user() - { - return $this->morphTo('user'); - } - - public function reply() - { - return $this->hasMany(TicketReply::class, 'ticket_id')->order("create_at", 'asc'); - } - - public function getImgsArrAttr($value, $data) - { - if (!empty($data['imgs'])) { - return str2arr($data['imgs'] ?: '', '|'); - } else { - return []; - } - } - - public function getLastReplyAttr($value, $data) - { - return $this->reply()->order('create_at', 'desc')->find(); - } - - public function getSourceTypeNameAttr($value, $data) - { - if (!empty($this->getSourceTypeList()[$data['source_type']])) { - return $this->getSourceTypeList()[$data['source_type']]; - } else { - return '未知'; - } - } - - public function getSourceTypeList() - { - return [ - 0 => '其他', - 1 => '用户随手拍', - 2 => '工单', - ]; - } - - public function getTypeNameAttr($value, $data) - { - $type = $this->type()->find(); - if (!empty($type)) { - return $type['name']; - } else { - return '未知'; - } - } - - public function getStatusTextAttr($value, $data) - { - if (!empty($this->getStatusList()[$data['status']])) { - return $this->getStatusList()[$data['status']]; - } else { - return '未知'; - } - } - - private function getStatusList() - { - return [ - -1 => '已关闭', - 0 => '待处理', - 1 => '已作处理', - ]; - } - - public function scopeAvail($query) - { - return $query->where('status', '>=', '0'); - } - - public function userShares() - { - return $this->hasMany(TicketUserShare::class, 'linked_ticket_id'); - } } \ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/model/TicketTicketOuter.php b/plugs/think-plugs-ticket/src/model/TicketTicketOuter.php index 56fd27d..d5c1e69 100644 --- a/plugs/think-plugs-ticket/src/model/TicketTicketOuter.php +++ b/plugs/think-plugs-ticket/src/model/TicketTicketOuter.php @@ -6,88 +6,4 @@ class TicketTicketOuter extends TicketTicket { protected $globalScope = ['outer']; protected $table = 'ticket_ticket'; - public function type() - { - return $this->belongsTo(TicketType::class, 'type_id'); - } - - public function user() - { - return $this->morphTo('user'); - } - - public function reply() - { - return $this->hasMany(TicketReply::class, 'ticket_id')->order("create_at", 'asc'); - } - - public function getImgsArrAttr($value, $data) - { - if (!empty($data['imgs'])) { - return str2arr($data['imgs'] ?: '', '|'); - } else { - return []; - } - } - - public function getLastReplyAttr($value, $data) - { - return $this->reply()->order('create_at', 'desc')->find(); - } - - public function getSourceTypeNameAttr($value, $data) - { - if (!empty($this->getSourceTypeList()[$data['source_type']])) { - return $this->getSourceTypeList()[$data['source_type']]; - } else { - return '未知'; - } - } - - public function getSourceTypeList() - { - return [ - 0 => '其他', - 1 => '用户随手拍', - 2 => '工单', - ]; - } - - public function getTypeNameAttr($value, $data) - { - $type = $this->type()->find(); - if (!empty($type)) { - return $type['name']; - } else { - return '未知'; - } - } - - public function getStatusTextAttr($value, $data) - { - if (!empty($this->getStatusList()[$data['status']])) { - return $this->getStatusList()[$data['status']]; - } else { - return '未知'; - } - } - - private function getStatusList() - { - return [ - -1 => '已关闭', - 0 => '待处理', - 1 => '已作处理', - ]; - } - - public function scopeAvail($query) - { - return $query->where('status', '>=', '0'); - } - - public function userShares() - { - return $this->hasMany(TicketUserShare::class, 'linked_ticket_id'); - } } \ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/view/ticket/index.html b/plugs/think-plugs-ticket/src/view/ticket/index.html index 6c7fc66..fafbf16 100644 --- a/plugs/think-plugs-ticket/src/view/ticket/index.html +++ b/plugs/think-plugs-ticket/src/view/ticket/index.html @@ -71,108 +71,20 @@ return ''; } }}, - {field: 'view', title:'核验情况', width: 100, minWidth:100, templet:function(item){ - if (item.views && item.views.length > 0) { - // 已有核验工单 - const view = item.views[item.views.length - 1]; - if (view.status == 1) { - if (view.is_error == 1) { - return `存在异常`; - } else { - return `不存在异常`; - } - } else { - return `查看工单`; - } - } else 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 if (item.view_process.status === -1) { - return `已取消` - } + {field:'status', title:'状态', width:80, templet:function(item){ + if (item.status === 0) { + /** {if auth("move")} */ + return `分配` + /** {else} */ + return `待分配` + /** {/if} */ + } else { + if (item.state === 2) { + return `外部工单` } else { - return `提请核验`; - } - }}, - {field: 'repair', title:'维修情况', width: 100, minWidth:100, templet:function(item){ - 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) { - // 已有维修工单 - const repair = item.repairs[item.repairs.length - 1]; - if (repair.status == 1) { - return `维修完毕`; - } else { - return `查看工单`; - } - } else 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 `提请维修`; - } - }}, - {field: 'verify', title:'验收情况', width: 100, minWidth:100, templet:function(item){ - 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) { - // 还没有维修流程 - return `请先维修` - } - if (item.repairs[item.repairs.length - 1].status !== 1) { - return `请先完成维修` - } - if (item.verifys && item.verifys.length > 0) { - // 已有验收工单 - const verify = item.verifys[item.verifys.length - 1]; - if (verify.status == 1) { - return `验收完毕`; - } else { - return `查看工单`; - } - } else 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 `提请验收`; + return `内部工单` } + } }}, {fixed: 'right', title:'操作', toolbar: '#toolbar', width:200} ]], diff --git a/plugs/think-plugs-ticket/src/view/ticket_inter/index.html b/plugs/think-plugs-ticket/src/view/ticket_inter/index.html index e933420..d453b7e 100644 --- a/plugs/think-plugs-ticket/src/view/ticket_inter/index.html +++ b/plugs/think-plugs-ticket/src/view/ticket_inter/index.html @@ -1,6 +1,14 @@ {extend name="table"} {block name="button"} + + + + + +下载导入模板 + + {/block} {block name="content"} @@ -8,7 +16,7 @@