From 1b80b6ffd579c0c9c6db9ea9cb9cda344c7032d9 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 5 Dec 2024 10:55:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/controller/api/auth/Ticket.php | 65 +++++++++++++++++++ .../src/model/TicketRepair.php | 1 + .../src/model/TicketTicket.php | 8 ++- .../src/model/TicketVerify.php | 1 + 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/plugs/think-plugs-inspection/src/controller/api/auth/Ticket.php b/plugs/think-plugs-inspection/src/controller/api/auth/Ticket.php index 8851961..37c8b6d 100644 --- a/plugs/think-plugs-inspection/src/controller/api/auth/Ticket.php +++ b/plugs/think-plugs-inspection/src/controller/api/auth/Ticket.php @@ -60,4 +60,69 @@ class Ticket extends Auth $ticket->save(); $this->success("工单创建成功", $ticket); } + + public function list() + { + $status = $this->request->get('status', null); + $query = TicketTicket::query(); // ->where(['fz_user_id'=>$this->staff->id]) + if ($status) { + $query->where('staff_status', $status); + } + $pageData = $query->paginate(); + $this->success('获取工单列表', $pageData); + } + + public function info() + { + $id = $this->request->get('id'); + $ticket = TicketTicket::query() +// ->where(['fz_user_id'=>$this->staff->id]) + ->with(['verify', 'repair'])->findOrEmpty($id); + if ($ticket->isEmpty()) $this->error('工单不存在'); + $this->success('获取工单详情', $ticket); + } + + public function verify() + { + $id = $this->request->get('id'); + /** @var TicketTicket $ticket */ + $ticket = TicketTicket::query()->where(['fz_user_id'=>$this->staff->id])->findOrEmpty($id); + if ($ticket->isEmpty()) $this->error('工单不存在'); + $data = $this->_vali([ + 'content.require' => '现场核实内容不能为空', + 'imgs.default' => '', + 'work_days.default' => '', + ]); + $ticket->verify()->save([ + 'staff_id' => $this->staff->id, + 'content' => $data['content'], + 'imgs' => $data['imgs'], + 'work_days' => $data['work_days'] + ]); + // 已现场核实 + $ticket->staff_status = 1; + $ticket->save(); + $this->success('工单现场核实成功'); + } + + public function repair() + { + $id = $this->request->get('id'); + /** @var TicketTicket $ticket */ + $ticket = TicketTicket::query()->where(['fz_user_id'=>$this->staff->id])->findOrEmpty($id); + if ($ticket->isEmpty()) $this->error('工单不存在'); + $data = $this->_vali([ + 'content.require' => '维修内容不能为空', + 'imgs.default' => '', + ]); + $ticket->repair()->save([ + 'staff_id' => $this->staff->id, + 'content' => $data['content'], + 'imgs' => $data['imgs'], + ]); + // 已维修 + $ticket->staff_status = 2; + $ticket->save(); + $this->success('工单维修成功'); + } } \ No newline at end of file diff --git a/plugs/think-plugs-ticket/src/model/TicketRepair.php b/plugs/think-plugs-ticket/src/model/TicketRepair.php index 8c7ca1f..d66060f 100644 --- a/plugs/think-plugs-ticket/src/model/TicketRepair.php +++ b/plugs/think-plugs-ticket/src/model/TicketRepair.php @@ -7,6 +7,7 @@ use think\admin\Model; class TicketRepair extends Model { + protected $append = ['imgs_arr']; public function ticket() { return $this->belongsTo(TicketTicket::class, 'ticket_id'); diff --git a/plugs/think-plugs-ticket/src/model/TicketTicket.php b/plugs/think-plugs-ticket/src/model/TicketTicket.php index 752df37..0da2d5e 100644 --- a/plugs/think-plugs-ticket/src/model/TicketTicket.php +++ b/plugs/think-plugs-ticket/src/model/TicketTicket.php @@ -2,11 +2,12 @@ namespace plugin\ticket\model; +use plugin\inspection\model\InspectionStaff; use think\admin\Model; class TicketTicket extends Model { - protected $append = ['status_text', 'type_name', 'dept_name']; + protected $append = ['status_text', 'type_name', 'dept_name', 'imgs_arr']; protected $globalScope = ['unConf']; protected $table = 'ticket_ticket'; public function type() @@ -105,6 +106,11 @@ class TicketTicket extends Model return $this->belongsTo(TicketDept::class, 'dept_id'); } + public function fzUser() + { + return $this->belongsTo(InspectionStaff::class, 'fz_user_id'); + } + public function verify() { return $this->hasMany(TicketVerify::class, 'ticket_id')->order('create_at', 'desc'); diff --git a/plugs/think-plugs-ticket/src/model/TicketVerify.php b/plugs/think-plugs-ticket/src/model/TicketVerify.php index 9ee7917..4a7213e 100644 --- a/plugs/think-plugs-ticket/src/model/TicketVerify.php +++ b/plugs/think-plugs-ticket/src/model/TicketVerify.php @@ -7,6 +7,7 @@ use think\admin\Model; class TicketVerify extends Model { + protected $append = ['imgs_arr']; public function ticket() { return $this->belongsTo(TicketTicket::class, 'ticket_id');