You've already forked guangan
巡检接口
This commit is contained in:
@ -11,7 +11,8 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">7.1"
|
"php": ">7.1",
|
||||||
|
"jerryyan/think-plugs-ticket": "@dev"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\controller\api\auth;
|
||||||
|
|
||||||
|
use plugin\inspection\controller\api\Auth;
|
||||||
|
|
||||||
|
class Message extends Auth
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$pageData = $this->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('消息已读');
|
||||||
|
}
|
||||||
|
}
|
@ -3,8 +3,68 @@
|
|||||||
namespace plugin\inspection\controller\api\auth;
|
namespace plugin\inspection\controller\api\auth;
|
||||||
|
|
||||||
use 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
|
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('添加点成功');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\controller\api\auth;
|
||||||
|
|
||||||
|
use plugin\inspection\controller\api\Auth;
|
||||||
|
use plugin\inspection\model\InspectionRecord;
|
||||||
|
use plugin\ticket\model\TicketTicket;
|
||||||
|
|
||||||
|
class Ticket extends Auth
|
||||||
|
{
|
||||||
|
public function add()
|
||||||
|
{
|
||||||
|
$record_id = $this->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("工单创建成功");
|
||||||
|
}
|
||||||
|
}
|
23
plugs/think-plugs-inspection/src/model/InspectionMessage.php
Normal file
23
plugs/think-plugs-inspection/src/model/InspectionMessage.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\model;
|
||||||
|
|
||||||
|
use think\admin\Model;
|
||||||
|
|
||||||
|
class InspectionMessage extends Model
|
||||||
|
{
|
||||||
|
public function staff()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(InspectionStaff::class, 'staff_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeUnread($query)
|
||||||
|
{
|
||||||
|
return $query->where('status', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeRead($query)
|
||||||
|
{
|
||||||
|
return $query->where('status', 1);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace plugin\inspection\model;
|
namespace plugin\inspection\model;
|
||||||
|
|
||||||
|
use plugin\ticket\model\TicketTicket;
|
||||||
use think\admin\Model;
|
use think\admin\Model;
|
||||||
|
|
||||||
class InspectionRecord extends Model
|
class InspectionRecord extends Model
|
||||||
@ -43,4 +44,9 @@ class InspectionRecord extends Model
|
|||||||
return $distance;
|
return $distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ticket()
|
||||||
|
{
|
||||||
|
return $this->morphMany(TicketTicket::class, 'source');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,6 +4,10 @@ namespace plugin\inspection\model;
|
|||||||
|
|
||||||
use think\admin\Model;
|
use think\admin\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检修员工模型
|
||||||
|
* @property InspectionStaff $name
|
||||||
|
*/
|
||||||
class InspectionStaff extends Model
|
class InspectionStaff extends Model
|
||||||
{
|
{
|
||||||
public function tokens()
|
public function tokens()
|
||||||
@ -15,4 +19,9 @@ class InspectionStaff extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(InspectionRecord::class, 'staff_id', 'id');
|
return $this->hasMany(InspectionRecord::class, 'staff_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function messages()
|
||||||
|
{
|
||||||
|
return $this->hasMany(InspectionMessage::class, 'staff_id', 'id');
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user