From 00688ebe3584cb7630e05afdf8f4821fd21f5a77 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 28 Nov 2024 14:41:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A1=E6=A3=80=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugs/think-plugs-inspection/composer.json | 3 +- .../src/controller/api/auth/Message.php | 32 ++++++++++ .../src/controller/api/auth/Record.php | 60 +++++++++++++++++++ .../src/controller/api/auth/Ticket.php | 57 ++++++++++++++++++ .../src/model/InspectionMessage.php | 23 +++++++ .../src/model/InspectionRecord.php | 6 ++ .../src/model/InspectionStaff.php | 9 +++ 7 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 plugs/think-plugs-inspection/src/controller/api/auth/Message.php create mode 100644 plugs/think-plugs-inspection/src/controller/api/auth/Ticket.php create mode 100644 plugs/think-plugs-inspection/src/model/InspectionMessage.php diff --git a/plugs/think-plugs-inspection/composer.json b/plugs/think-plugs-inspection/composer.json index 592264b..3efae88 100644 --- a/plugs/think-plugs-inspection/composer.json +++ b/plugs/think-plugs-inspection/composer.json @@ -11,7 +11,8 @@ } ], "require": { - "php": ">7.1" + "php": ">7.1", + "jerryyan/think-plugs-ticket": "@dev" }, "autoload": { "psr-4": { diff --git a/plugs/think-plugs-inspection/src/controller/api/auth/Message.php b/plugs/think-plugs-inspection/src/controller/api/auth/Message.php new file mode 100644 index 0000000..c4e0358 --- /dev/null +++ b/plugs/think-plugs-inspection/src/controller/api/auth/Message.php @@ -0,0 +1,32 @@ +staff->messages()->order('create_at desc')->paginate(); + $this->success('获取消息成功', $pageData); + } + + public function unread_count() + { + $count = $this->staff->messages()->scope('unread')->count(); + $this->success('获取未读消息数量成功', $count); + } + + public function read() + { + $message_id = $this->request->post('message_id'); + $message = $this->staff->messages()->where('id', $message_id)->find(); + if (empty($message)) { + $this->error('消息不存在'); + } + $message->status = 1; + $message->save(); + $this->success('消息已读'); + } +} \ No newline at end of file diff --git a/plugs/think-plugs-inspection/src/controller/api/auth/Record.php b/plugs/think-plugs-inspection/src/controller/api/auth/Record.php index 63daf73..8305d9c 100644 --- a/plugs/think-plugs-inspection/src/controller/api/auth/Record.php +++ b/plugs/think-plugs-inspection/src/controller/api/auth/Record.php @@ -3,8 +3,68 @@ namespace plugin\inspection\controller\api\auth; use plugin\inspection\controller\api\Auth; +use plugin\inspection\model\InspectionRecord; +use plugin\ticket\model\TicketTicket; class Record extends Auth { + public function index() + { + $pageData = $this->staff->records()->with(['points'])->order('create_at desc')->paginate(); + $this->success('获取记录成功', $pageData); + } + + public function create() + { + $this->staff->records()->save([ + 'staff_id' => $this->staff->id, + 'create_at' => date('Y-m-d H:i:s'), + 'status' => 0, + ]); + $this->success('创建记录成功'); + } + + public function end() + { + $record_id = $this->request->post('record_id'); + $record = InspectionRecord::mk()->where('id', $record_id)->find(); + if (empty($record)) { + $this->error('记录不存在'); + } + $lat = $this->request->post('lat'); + $lng = $this->request->post('lng'); + $imgs = $this->request->post('imgs'); + $content = $this->request->post('content'); + $record->status = 1; + $record->imgs = $imgs; + $record->content = $content; + $record->points()->save([ + 'lat' => $lat, + 'lng' => $lng, + 'create_at' => date('Y-m-d H:i:s'), + ]); + $record->save(); + $this->success('结束记录成功'); + } + + public function add_point() + { + $record_id = $this->request->post('record_id'); + $lat = $this->request->post('lat'); + $lng = $this->request->post('lng'); + /** @var InspectionRecord $record */ + $record = InspectionRecord::mk()->where('id', $record_id)->find(); + if (empty($record)) { + $this->error('记录不存在'); + } + $record->points()->save([ + 'lat' => $lat, + 'lng' => $lng, + 'create_at' => date('Y-m-d H:i:s'), + ]); + $record->distance = $record->calculateDistance(); + $record->save(); + $this->success('添加点成功'); + } } \ No newline at end of file diff --git a/plugs/think-plugs-inspection/src/controller/api/auth/Ticket.php b/plugs/think-plugs-inspection/src/controller/api/auth/Ticket.php new file mode 100644 index 0000000..89e19c4 --- /dev/null +++ b/plugs/think-plugs-inspection/src/controller/api/auth/Ticket.php @@ -0,0 +1,57 @@ +request->post('record_id'); + $record = null; + if (!empty($record_id)) { + /** @var InspectionRecord $record */ + $record = InspectionRecord::mk()->where('id', $record_id)->find(); + if (empty($record)) { + $this->error('记录不存在'); + } + } + $lat = $this->request->post('lat'); + $lng = $this->request->post('lng'); + $type_id = $this->request->post('type_id'); + $title = $this->request->post('title'); + $content = $this->request->post('content'); + $ticket_region = $this->request->post('ticket_region'); + $ticket_address = $this->request->post('ticket_address'); + $imgs = $this->request->post('imgs'); + $ticket_project_use = $this->request->post('ticket_project_use'); + $ticket_work_use = $this->request->post('ticket_work_use'); + $ticket_price =$this->request->post('ticket_price'); + $data = [ + 'uid' => $this->staff->id, + 'utype' => $this->staff->id, + 'type_id' => $type_id, + 'title' => $title, + 'content' => $content, + 'contact_name' => $this->staff->name, + 'contact_phone' => $this->staff->phone, + 'ticket_region' => $ticket_region, + 'ticket_address' => $ticket_address, + 'lat' => $lat, + 'lng' => $lng, + 'imgs' => $imgs, + 'ticket_project_use' =>$ticket_project_use, + 'ticket_work_use' => $ticket_work_use, + 'ticket_price' => $ticket_price, + ]; + if (!empty($record)) { + $record->ticket()->create($data); + } else { + TicketTicket::create($data); + } + $this->success("工单创建成功"); + } +} \ No newline at end of file diff --git a/plugs/think-plugs-inspection/src/model/InspectionMessage.php b/plugs/think-plugs-inspection/src/model/InspectionMessage.php new file mode 100644 index 0000000..8dd7e85 --- /dev/null +++ b/plugs/think-plugs-inspection/src/model/InspectionMessage.php @@ -0,0 +1,23 @@ +belongsTo(InspectionStaff::class, 'staff_id', 'id'); + } + + public function scopeUnread($query) + { + return $query->where('status', 0); + } + + public function scopeRead($query) + { + return $query->where('status', 1); + } +} \ No newline at end of file diff --git a/plugs/think-plugs-inspection/src/model/InspectionRecord.php b/plugs/think-plugs-inspection/src/model/InspectionRecord.php index c921ca0..62e4b1a 100644 --- a/plugs/think-plugs-inspection/src/model/InspectionRecord.php +++ b/plugs/think-plugs-inspection/src/model/InspectionRecord.php @@ -2,6 +2,7 @@ namespace plugin\inspection\model; +use plugin\ticket\model\TicketTicket; use think\admin\Model; class InspectionRecord extends Model @@ -43,4 +44,9 @@ class InspectionRecord extends Model return $distance; } + public function ticket() + { + return $this->morphMany(TicketTicket::class, 'source'); + } + } \ No newline at end of file diff --git a/plugs/think-plugs-inspection/src/model/InspectionStaff.php b/plugs/think-plugs-inspection/src/model/InspectionStaff.php index f300f11..6402930 100644 --- a/plugs/think-plugs-inspection/src/model/InspectionStaff.php +++ b/plugs/think-plugs-inspection/src/model/InspectionStaff.php @@ -4,6 +4,10 @@ namespace plugin\inspection\model; use think\admin\Model; +/** + * 检修员工模型 + * @property InspectionStaff $name + */ class InspectionStaff extends Model { public function tokens() @@ -15,4 +19,9 @@ class InspectionStaff extends Model { return $this->hasMany(InspectionRecord::class, 'staff_id', 'id'); } + + public function messages() + { + return $this->hasMany(InspectionMessage::class, 'staff_id', 'id'); + } } \ No newline at end of file