You've already forked guangan
巡检
This commit is contained in:
@ -25,6 +25,7 @@
|
|||||||
"jerryyan/think-plugs-cms": "@dev",
|
"jerryyan/think-plugs-cms": "@dev",
|
||||||
"jerryyan/think-plugs-points-mall": "@dev",
|
"jerryyan/think-plugs-points-mall": "@dev",
|
||||||
"jerryyan/think-plugs-ticket": "@dev",
|
"jerryyan/think-plugs-ticket": "@dev",
|
||||||
|
"jerryyan/think-plugs-inspection": "@dev",
|
||||||
"zoujingli/think-plugs-admin": "^1.0",
|
"zoujingli/think-plugs-admin": "^1.0",
|
||||||
"zoujingli/think-plugs-wechat": "^1.0",
|
"zoujingli/think-plugs-wechat": "^1.0",
|
||||||
"zoujingli/think-plugs-center": "^1.0",
|
"zoujingli/think-plugs-center": "^1.0",
|
||||||
@ -43,6 +44,10 @@
|
|||||||
"jerryyan/think-plugs-ticket": {
|
"jerryyan/think-plugs-ticket": {
|
||||||
"type": "path",
|
"type": "path",
|
||||||
"url": "./plugs/think-plugs-ticket"
|
"url": "./plugs/think-plugs-ticket"
|
||||||
|
},
|
||||||
|
"jerryyan/think-plugs-inspection": {
|
||||||
|
"type": "path",
|
||||||
|
"url": "./plugs/think-plugs-inspection"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
41
plugs/think-plugs-inspection/composer.json
Normal file
41
plugs/think-plugs-inspection/composer.json
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"type": "think-admin-plugin",
|
||||||
|
"name": "jerryyan/think-plugs-inspection",
|
||||||
|
"license": "WTFPL",
|
||||||
|
"homepage": "https://thinkadmin.top",
|
||||||
|
"description": "Inspection Plugin for ThinkAdmin",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Jerry Yan",
|
||||||
|
"email": "jerryyan0912@qq.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">7.1"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"plugin\\ticket\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"config": {
|
||||||
|
"type": "module",
|
||||||
|
"name": "巡检端",
|
||||||
|
"document": "https://thinkadmin.top/plugin/think-plugs-wechat.html",
|
||||||
|
"description": "巡检端"
|
||||||
|
},
|
||||||
|
"think": {
|
||||||
|
"services": [
|
||||||
|
"plugin\\inspection\\Service"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"config": {
|
||||||
|
"sort-packages": true,
|
||||||
|
"allow-plugins": {
|
||||||
|
"zoujingli/think-install": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
plugs/think-plugs-inspection/src/Service.php
Normal file
36
plugs/think-plugs-inspection/src/Service.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection;
|
||||||
|
|
||||||
|
|
||||||
|
use think\admin\Plugin;
|
||||||
|
|
||||||
|
class Service extends Plugin
|
||||||
|
{
|
||||||
|
protected $appName = '巡检端';
|
||||||
|
protected $appCode = 'inspection';
|
||||||
|
protected $package = 'jerryyan/think-plugs-inspection';
|
||||||
|
|
||||||
|
public static function register(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function menu(): array
|
||||||
|
{
|
||||||
|
$code = app(static::class)->appCode;
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'name' => '巡检管理',
|
||||||
|
'subs' => [
|
||||||
|
['name' => '巡检记录', 'icon' => 'layui-icon layui-icon-template-1', 'node' => "{$code}/record/index"],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => '巡检人员',
|
||||||
|
'subs' => [
|
||||||
|
['name' => '人员列表', 'icon' => 'layui-icon layui-icon-template-1', 'node' => "{$code}/user/index"],
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
23
plugs/think-plugs-inspection/src/controller/Staff.php
Normal file
23
plugs/think-plugs-inspection/src/controller/Staff.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\controller;
|
||||||
|
|
||||||
|
use plugin\inspection\model\InspectionStaff;
|
||||||
|
use think\admin\Controller;
|
||||||
|
use think\admin\helper\QueryHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 巡检人员管理
|
||||||
|
*/
|
||||||
|
class Staff extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$this->title = '巡检人员管理';
|
||||||
|
InspectionStaff::mQuery()->layTable(function () {
|
||||||
|
|
||||||
|
}, function (QueryHelper $query) {
|
||||||
|
$query->like(['name|phone|address#keyword'])->equal(['status']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
43
plugs/think-plugs-inspection/src/controller/api/Auth.php
Normal file
43
plugs/think-plugs-inspection/src/controller/api/Auth.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\controller\api;
|
||||||
|
|
||||||
|
use plugin\inspection\model\InspectionStaff;
|
||||||
|
use plugin\inspection\model\InspectionStaffToken;
|
||||||
|
use think\admin\Controller;
|
||||||
|
use think\exception\HttpResponseException;
|
||||||
|
|
||||||
|
class Auth extends Controller
|
||||||
|
{
|
||||||
|
/** @var InspectionStaff 检修员工 */
|
||||||
|
protected $staff;
|
||||||
|
protected $tokenInfo;
|
||||||
|
public function initialize()
|
||||||
|
{
|
||||||
|
parent::initialize();
|
||||||
|
try {
|
||||||
|
// 获取请求令牌内容
|
||||||
|
// 优先识别 Bearer Token 机制,再识别 api-token 字段
|
||||||
|
$token = $this->request->header('Authorization', '');
|
||||||
|
if (!empty($token) && stripos($token, 'Bearer ') === 0) {
|
||||||
|
$token = substr($token, 7);
|
||||||
|
}
|
||||||
|
if (empty($token)) {
|
||||||
|
$token = $this->request->header('api-token', '');
|
||||||
|
}
|
||||||
|
if (empty($token)) $this->error('需要登录授权', [], 401);
|
||||||
|
// 读取用户账号数据
|
||||||
|
$tokenInfo = InspectionStaffToken::query()->where('token', "=", $token)->with("staff")->find();
|
||||||
|
if (empty($tokenInfo)) {
|
||||||
|
$this->error('无效的登录令牌', [], 401);
|
||||||
|
}
|
||||||
|
$this->tokenInfo = $tokenInfo;
|
||||||
|
$this->staff = $tokenInfo->staff;
|
||||||
|
} catch (HttpResponseException $exception) {
|
||||||
|
throw $exception;
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
$this->error($exception->getMessage(), [], $exception->getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
26
plugs/think-plugs-inspection/src/controller/api/Login.php
Normal file
26
plugs/think-plugs-inspection/src/controller/api/Login.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\controller\api;
|
||||||
|
|
||||||
|
use plugin\inspection\model\InspectionStaff;
|
||||||
|
use think\admin\Controller;
|
||||||
|
|
||||||
|
class Login extends Controller
|
||||||
|
{
|
||||||
|
public function login()
|
||||||
|
{
|
||||||
|
$this->title = '登录';
|
||||||
|
$this->staff = InspectionStaff::mk()->where('phone', $this->request->post('phone'))->find();
|
||||||
|
if (empty($this->staff)) {
|
||||||
|
$this->error('用户不存在');
|
||||||
|
}
|
||||||
|
if ($this->staff->password !== md5($this->request->post('password'))) {
|
||||||
|
$this->error('密码错误');
|
||||||
|
}
|
||||||
|
$this->staff->save(['last_login_at' => date('Y-m-d H:i:s')]);
|
||||||
|
// $this->staff->tokens()->where('token', '<>', '')->delete();
|
||||||
|
$this->success('登录成功', [
|
||||||
|
'token' => $this->staff->tokens()->save(['token' => md5(uniqid())])->token,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\controller\api\auth;
|
||||||
|
|
||||||
|
use plugin\inspection\controller\api\Auth;
|
||||||
|
|
||||||
|
class Record extends Auth
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\controller\api\auth;
|
||||||
|
|
||||||
|
use plugin\inspection\controller\api\Auth;
|
||||||
|
|
||||||
|
class Staff extends Auth
|
||||||
|
{
|
||||||
|
public function logout() {
|
||||||
|
$this->staff->tokens()->delete();
|
||||||
|
$this->success('退出成功');
|
||||||
|
}
|
||||||
|
}
|
46
plugs/think-plugs-inspection/src/model/InspectionRecord.php
Normal file
46
plugs/think-plugs-inspection/src/model/InspectionRecord.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\model;
|
||||||
|
|
||||||
|
use think\admin\Model;
|
||||||
|
|
||||||
|
class InspectionRecord extends Model
|
||||||
|
{
|
||||||
|
public function staff()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(InspectionStaff::class, 'staff_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function points()
|
||||||
|
{
|
||||||
|
return $this->hasMany(InspectionRecordPoint::class, 'record_id', 'id')->order('create_at', 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function calculateDistance()
|
||||||
|
{
|
||||||
|
$points = $this->points()->select();
|
||||||
|
$distance = 0;
|
||||||
|
$previousPoint = null;
|
||||||
|
foreach ($points as $point) {
|
||||||
|
$lat = $point->latitude;
|
||||||
|
$lng = $point->longitude;
|
||||||
|
if ($previousPoint) {
|
||||||
|
$distance += $this->calculateDistanceBetweenPoints($previousPoint[0], $previousPoint[1], $lat, $lng);
|
||||||
|
}
|
||||||
|
$previousPoint = [$lat, $lng];
|
||||||
|
}
|
||||||
|
return $distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateDistanceBetweenPoints($lat1, $lng1, $lat, $lng)
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\model;
|
||||||
|
|
||||||
|
use think\admin\Model;
|
||||||
|
|
||||||
|
class InspectionRecordPoint extends Model
|
||||||
|
{
|
||||||
|
public function staff()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(InspectionStaff::class, 'staff_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function record()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(InspectionRecord::class, 'record_id', 'id');
|
||||||
|
}
|
||||||
|
}
|
18
plugs/think-plugs-inspection/src/model/InspectionStaff.php
Normal file
18
plugs/think-plugs-inspection/src/model/InspectionStaff.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\model;
|
||||||
|
|
||||||
|
use think\admin\Model;
|
||||||
|
|
||||||
|
class InspectionStaff extends Model
|
||||||
|
{
|
||||||
|
public function tokens()
|
||||||
|
{
|
||||||
|
return $this->hasMany(InspectionStaffToken::class, 'staff_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function records()
|
||||||
|
{
|
||||||
|
return $this->hasMany(InspectionRecord::class, 'staff_id', 'id');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\model;
|
||||||
|
|
||||||
|
use think\admin\Model;
|
||||||
|
|
||||||
|
class InspectionStaffToken extends Model
|
||||||
|
{
|
||||||
|
public function staff()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(InspectionStaff::class, 'id', 'staff_id');
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user