diff --git a/plugs/think-plugs-inspection/src/controller/Banner.php b/plugs/think-plugs-inspection/src/controller/Banner.php new file mode 100644 index 0000000..eea6a7c --- /dev/null +++ b/plugs/think-plugs-inspection/src/controller/Banner.php @@ -0,0 +1,97 @@ +title = '轮播图管理'; + InspectionBanner::mQuery()->layTable(function () { + }, static function (QueryHelper $query) { + $query->equal('status')->like('title'); + $query->timeBetween('create_at'); + }); + } + + /** + * 添加轮播图 + * @auth true + * @menu true + * @login true + * @return void + */ + public function add() + { + $this->title = '添加轮播图'; + $this->_applyFormToken(); + InspectionBanner::mForm('form'); + } + + /** + * 编辑轮播图 + * @auth true + * @menu true + * @login true + * @return void + */ + public function edit() + { + $this->title = '编辑轮播图'; + $this->id = $this->request->param('id', 0, 'intval'); //当前轮播图ID + $this->_applyFormToken(); + InspectionBanner::mForm('form'); + } + + /** + * 删除轮播图 + * @auth true + * @menu true + * @login true + * @return void + */ + public function remove() + { + InspectionBanner::mDelete('id'); + } + + /** + * 状态切换 + * @auth true + * @menu true + * @login true + * @return void + */ + public function status() + { + InspectionBanner::mSave($this->_vali([ + 'id.require' => '轮播图ID不能为空', + 'status.in:0,1' => '状态值范围异常!', + 'status.require' => '状态值不能为空!', + ]), 'id'); + } + + public function sort() + { + InspectionBanner::mSave($this->_vali([ + 'id.require' => '轮播图ID不能为空', + 'sort.require' => '排序值不能为空!', + 'sort.number' => '排序必须为数字!', + 'sort.between:0,9999' => '排序值必须为0~9999之间!', + ]), 'id'); + } +} \ No newline at end of file diff --git a/plugs/think-plugs-inspection/src/controller/api/Banner.php b/plugs/think-plugs-inspection/src/controller/api/Banner.php new file mode 100644 index 0000000..2090535 --- /dev/null +++ b/plugs/think-plugs-inspection/src/controller/api/Banner.php @@ -0,0 +1,14 @@ +where('status', '=', 1)->field("id, image")->order('sort asc,id desc')->select(); + $this->success('获取轮播图列表', $banners); + } +} \ 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 8305d9c..ab6a4d8 100644 --- a/plugs/think-plugs-inspection/src/controller/api/auth/Record.php +++ b/plugs/think-plugs-inspection/src/controller/api/auth/Record.php @@ -10,18 +10,28 @@ class Record extends Auth { public function index() { - $pageData = $this->staff->records()->with(['points'])->order('create_at desc')->paginate(); + $pageData = $this->staff->records()->order('create_at desc')->paginate(); $this->success('获取记录成功', $pageData); } + public function info() + { + $record_id = $this->request->get('record_id'); + $record = InspectionRecord::mk()->where('id', $record_id)->with(['points'])->find(); + if (empty($record)) { + $this->error('记录不存在'); + } + $this->success('获取记录成功', $record); + } + public function create() { - $this->staff->records()->save([ - 'staff_id' => $this->staff->id, + $record = $this->staff->records()->save([ + 'no' => uniqid('XJ_' . date('YmdHis')), 'create_at' => date('Y-m-d H:i:s'), 'status' => 0, ]); - $this->success('创建记录成功'); + $this->success('创建记录成功', $record); } public function end() @@ -53,18 +63,38 @@ class Record extends Auth $lat = $this->request->post('lat'); $lng = $this->request->post('lng'); /** @var InspectionRecord $record */ - $record = InspectionRecord::mk()->where('id', $record_id)->find(); + $record = InspectionRecord::query()->where('id', $record_id)->find(); if (empty($record)) { $this->error('记录不存在'); } - $record->points()->save([ + $point = $record->points()->save([ + 'staff_id' => $this->staff->id, + 'is_pause' => $this->request->post('is_pause', 0), 'lat' => $lat, 'lng' => $lng, 'create_at' => date('Y-m-d H:i:s'), ]); - $record->distance = $record->calculateDistance(); + $record->autoFix(); $record->save(); - $this->success('添加点成功'); + $this->success('添加点成功', $point); + } + + public function update_point() + { + $record_id = $this->request->post('record_id'); + $point_id = $this->request->post('id'); + /** @var InspectionRecord $record */ + $record = InspectionRecord::query()->where('id', $record_id)->find(); + if (empty($record)) { + $this->error('记录不存在'); + } + $point = $record->points()->where('id', $point_id)->find(); + if (empty($point)) { + $this->error('点不存在'); + } + $point->is_pause = $this->request->post('is_pause', 0); + $point->save(); + $this->success("成功"); } } \ No newline at end of file diff --git a/plugs/think-plugs-inspection/src/model/InspectionBanner.php b/plugs/think-plugs-inspection/src/model/InspectionBanner.php new file mode 100644 index 0000000..c4025b7 --- /dev/null +++ b/plugs/think-plugs-inspection/src/model/InspectionBanner.php @@ -0,0 +1,10 @@ +hasMany(InspectionRecordPoint::class, 'record_id', 'id')->order('create_at', 'asc'); } + public function autoFix() + { + $this->distance = $this->calculateDistance(); + $this->duration = $this->calculateTime(); + } + + public function calculateTime() + { + $points = $this->points()->select(); + $startTime = null; + $endTime = null; + foreach ($points as $point) { + if ($point->is_pause) continue; + if ($startTime === null) { + $startTime = $point->create_at; + } + $endTime = $point->create_at; + } + if ($startTime && $endTime) { + $start = new \DateTime($startTime); + $end = new \DateTime($endTime); + return $end->diff($start)->format('%H:%I:%S'); + } + return '0:00:00'; + } + public function calculateDistance() { $points = $this->points()->select(); $distance = 0; $previousPoint = null; foreach ($points as $point) { - $lat = $point->latitude; - $lng = $point->longitude; + $lat = $point->lat; + $lng = $point->lng; if ($previousPoint) { $distance += $this->calculateDistanceBetweenPoints($previousPoint[0], $previousPoint[1], $lat, $lng); } @@ -38,10 +65,10 @@ class InspectionRecord extends Model $earthRadius = 6371000; // 地球半径,单位为米 $dLat = deg2rad($lat - $lat1); $dLng = deg2rad($lng - $lng1); - $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat)) * sin($dLng / 2) * sin($dLng / 2); - $c = 2 * atan2(sqrt($a), sqrt(1 - $a)); - $distance = $earthRadius * $c; - return $distance; + $lat1 = deg2rad($lat1); + $lat = deg2rad($lat); + $d = $earthRadius * 2 * asin(sqrt(pow(sin($dLat / 2), 2) + cos($lat1) * cos($lat) * pow(sin($dLng / 2), 2))); + return $d; } public function ticket() diff --git a/plugs/think-plugs-inspection/src/view/banner/form.html b/plugs/think-plugs-inspection/src/view/banner/form.html new file mode 100644 index 0000000..a4cf4d7 --- /dev/null +++ b/plugs/think-plugs-inspection/src/view/banner/form.html @@ -0,0 +1,33 @@ +
+
+
+ +
+ +
仅用于后台展示
+
+
+
+ +
+ +
建议尺寸:750*300
+
+
+
+ {notempty name='id'}{/notempty} +
+ + +
+
+ diff --git a/plugs/think-plugs-inspection/src/view/banner/index.html b/plugs/think-plugs-inspection/src/view/banner/index.html new file mode 100644 index 0000000..280589d --- /dev/null +++ b/plugs/think-plugs-inspection/src/view/banner/index.html @@ -0,0 +1,87 @@ +{extend name="table"} + +{block name="button"} + + + +{/block} + +{block name="content"} +
+
+ {include file='banner/index_search'} +
+
+
+ + + +{/block} + +{block name='style'} + +{/block} + +{block name='script'} + +{/block} \ No newline at end of file diff --git a/plugs/think-plugs-inspection/src/view/banner/index_search.html b/plugs/think-plugs-inspection/src/view/banner/index_search.html new file mode 100644 index 0000000..e547414 --- /dev/null +++ b/plugs/think-plugs-inspection/src/view/banner/index_search.html @@ -0,0 +1,16 @@ +
+ 条件搜索 + + +