init
This commit is contained in:
1
application/api/common.php
Normal file
1
application/api/common.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php
|
||||
6
application/api/config.php
Normal file
6
application/api/config.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
//配置文件
|
||||
return [
|
||||
'exception_handle' => '\\app\\api\\library\\ExceptionHandle',
|
||||
];
|
||||
166
application/api/controller/Common.php
Normal file
166
application/api/controller/Common.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\exception\UploadException;
|
||||
use app\common\library\Upload;
|
||||
use app\common\model\Area;
|
||||
use app\common\model\Version;
|
||||
use fast\Random;
|
||||
use think\captcha\Captcha;
|
||||
use think\Config;
|
||||
use think\Hook;
|
||||
|
||||
/**
|
||||
* 公共接口
|
||||
*/
|
||||
class Common extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['init', 'captcha'];
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
|
||||
if (isset($_SERVER['HTTP_ORIGIN'])) {
|
||||
header('Access-Control-Expose-Headers: __token__');//跨域让客户端获取到
|
||||
}
|
||||
//跨域检测
|
||||
check_cors_request();
|
||||
|
||||
if (!isset($_COOKIE['PHPSESSID'])) {
|
||||
Config::set('session.id', $this->request->server("HTTP_SID"));
|
||||
}
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载初始化
|
||||
*
|
||||
* @ApiParams (name="version", type="string", required=true, description="版本号")
|
||||
* @ApiParams (name="lng", type="string", required=true, description="经度")
|
||||
* @ApiParams (name="lat", type="string", required=true, description="纬度")
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($version = $this->request->request('version')) {
|
||||
$lng = $this->request->request('lng');
|
||||
$lat = $this->request->request('lat');
|
||||
|
||||
//配置信息
|
||||
$upload = Config::get('upload');
|
||||
//如果非服务端中转模式需要修改为中转
|
||||
if ($upload['storage'] != 'local' && isset($upload['uploadmode']) && $upload['uploadmode'] != 'server') {
|
||||
//临时修改上传模式为服务端中转
|
||||
set_addon_config($upload['storage'], ["uploadmode" => "server"], false);
|
||||
|
||||
$upload = \app\common\model\Config::upload();
|
||||
// 上传信息配置后
|
||||
Hook::listen("upload_config_init", $upload);
|
||||
|
||||
$upload = Config::set('upload', array_merge(Config::get('upload'), $upload));
|
||||
}
|
||||
|
||||
$upload['cdnurl'] = $upload['cdnurl'] ? $upload['cdnurl'] : cdnurl('', true);
|
||||
$upload['uploadurl'] = preg_match("/^((?:[a-z]+:)?\/\/)(.*)/i", $upload['uploadurl']) ? $upload['uploadurl'] : url($upload['storage'] == 'local' ? '/api/common/upload' : $upload['uploadurl'], '', false, true);
|
||||
|
||||
$content = [
|
||||
'citydata' => Area::getCityFromLngLat($lng, $lat),
|
||||
'versiondata' => Version::check($version),
|
||||
'uploaddata' => $upload,
|
||||
'coverdata' => Config::get("cover"),
|
||||
];
|
||||
$this->success('', $content);
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="file", type="file", required=true, description="文件流")
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
Config::set('default_return_type', 'json');
|
||||
//必须设定cdnurl为空,否则cdnurl函数计算错误
|
||||
Config::set('upload.cdnurl', '');
|
||||
$chunkid = $this->request->post("chunkid");
|
||||
if ($chunkid) {
|
||||
if (!Config::get('upload.chunking')) {
|
||||
$this->error(__('Chunk file disabled'));
|
||||
}
|
||||
$action = $this->request->post("action");
|
||||
$chunkindex = $this->request->post("chunkindex/d");
|
||||
$chunkcount = $this->request->post("chunkcount/d");
|
||||
$filename = $this->request->post("filename");
|
||||
$method = $this->request->method(true);
|
||||
if ($action == 'merge') {
|
||||
$attachment = null;
|
||||
//合并分片文件
|
||||
try {
|
||||
$upload = new Upload();
|
||||
$attachment = $upload->merge($chunkid, $chunkcount, $filename);
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
||||
} elseif ($method == 'clean') {
|
||||
//删除冗余的分片文件
|
||||
try {
|
||||
$upload = new Upload();
|
||||
$upload->clean($chunkid);
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
//上传分片文件
|
||||
//默认普通上传文件
|
||||
$file = $this->request->file('file');
|
||||
try {
|
||||
$upload = new Upload($file);
|
||||
$upload->chunk($chunkid, $chunkindex, $chunkcount);
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
} else {
|
||||
$attachment = null;
|
||||
//默认普通上传文件
|
||||
$file = $this->request->file('file');
|
||||
try {
|
||||
$upload = new Upload($file);
|
||||
$attachment = $upload->upload();
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
* @ApiParams (name="id", type="string", required=true, description="要生成验证码的标识")
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function captcha($id = "")
|
||||
{
|
||||
\think\Config::set([
|
||||
'captcha' => array_merge(config('captcha'), [
|
||||
'fontSize' => 44,
|
||||
'imageH' => 150,
|
||||
'imageW' => 350,
|
||||
])
|
||||
]);
|
||||
$captcha = new Captcha((array)Config::get('captcha'));
|
||||
return $captcha->entry($id);
|
||||
}
|
||||
}
|
||||
73
application/api/controller/Demo.php
Normal file
73
application/api/controller/Demo.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
|
||||
/**
|
||||
* 示例接口
|
||||
*/
|
||||
class Demo extends Api
|
||||
{
|
||||
|
||||
//如果$noNeedLogin为空表示所有接口都需要登录才能请求
|
||||
//如果$noNeedRight为空表示所有接口都需要验证权限才能请求
|
||||
//如果接口已经设置无需登录,那也就无需鉴权了
|
||||
//
|
||||
// 无需登录的接口,*表示全部
|
||||
protected $noNeedLogin = ['test', 'test1'];
|
||||
// 无需鉴权的接口,*表示全部
|
||||
protected $noNeedRight = ['test2'];
|
||||
|
||||
/**
|
||||
* 测试方法
|
||||
*
|
||||
* @ApiTitle (测试名称)
|
||||
* @ApiSummary (测试描述信息)
|
||||
* @ApiMethod (POST)
|
||||
* @ApiRoute (/api/demo/test/id/{id}/name/{name})
|
||||
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
||||
* @ApiParams (name="id", type="integer", required=true, description="会员ID")
|
||||
* @ApiParams (name="name", type="string", required=true, description="用户名")
|
||||
* @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
|
||||
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
||||
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
||||
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
|
||||
* @ApiReturn ({
|
||||
'code':'1',
|
||||
'msg':'返回成功'
|
||||
})
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
$this->success('返回成功', $this->request->param());
|
||||
}
|
||||
|
||||
/**
|
||||
* 无需登录的接口
|
||||
*
|
||||
*/
|
||||
public function test1()
|
||||
{
|
||||
$this->success('返回成功', ['action' => 'test1']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要登录的接口
|
||||
*
|
||||
*/
|
||||
public function test2()
|
||||
{
|
||||
$this->success('返回成功', ['action' => 'test2']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要登录且需要验证有相应组的权限
|
||||
*
|
||||
*/
|
||||
public function test3()
|
||||
{
|
||||
$this->success('返回成功', ['action' => 'test3']);
|
||||
}
|
||||
|
||||
}
|
||||
132
application/api/controller/Ems.php
Normal file
132
application/api/controller/Ems.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\Ems as Emslib;
|
||||
use app\common\model\User;
|
||||
use think\Hook;
|
||||
|
||||
/**
|
||||
* 邮箱验证码接口
|
||||
*/
|
||||
class Ems extends Api
|
||||
{
|
||||
protected $noNeedLogin = '*';
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="email", type="string", required=true, description="邮箱")
|
||||
* @ApiParams (name="event", type="string", required=true, description="事件名称")
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$email = $this->request->post("email");
|
||||
$event = $this->request->post("event");
|
||||
$event = $event ? $event : 'register';
|
||||
|
||||
if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$this->error(__('邮箱格式错误'));
|
||||
}
|
||||
if (!preg_match("/^[a-z0-9_\-]{3,30}\$/i", $event)) {
|
||||
$this->error(__('事件名称错误'));
|
||||
}
|
||||
|
||||
//发送前验证码
|
||||
if (config('fastadmin.user_api_captcha')) {
|
||||
|
||||
if (!preg_match("/^[a-z0-9]{4,6}\$/i", $captcha)) {
|
||||
$this->error(__('验证码格式错误'));
|
||||
}
|
||||
|
||||
if (!\think\Validate::is($captcha, 'captcha')) {
|
||||
$this->error("验证码不正确");
|
||||
}
|
||||
}
|
||||
|
||||
$last = Emslib::get($email, $event);
|
||||
if ($last && time() - $last['createtime'] < 60) {
|
||||
$this->error(__('发送频繁'));
|
||||
}
|
||||
|
||||
$ipSendTotal = \app\common\model\Ems::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count();
|
||||
if ($ipSendTotal >= 5) {
|
||||
$this->error(__('发送频繁'));
|
||||
}
|
||||
|
||||
if ($event) {
|
||||
$userinfo = User::getByEmail($email);
|
||||
if ($event == 'register' && $userinfo) {
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
} elseif (in_array($event, ['changeemail']) && $userinfo) {
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
$ret = Emslib::send($email, null, $event);
|
||||
if ($ret) {
|
||||
$this->success(__('发送成功'));
|
||||
} else {
|
||||
$this->error(__('发送失败'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="email", type="string", required=true, description="邮箱")
|
||||
* @ApiParams (name="event", type="string", required=true, description="事件名称")
|
||||
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$email = $this->request->post("email");
|
||||
$event = $this->request->post("event");
|
||||
$event = $event ? $event : 'register';
|
||||
$captcha = $this->request->post("captcha");
|
||||
|
||||
if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$this->error(__('邮箱格式错误'));
|
||||
}
|
||||
if (!preg_match("/^[a-z0-9_\-]{3,30}\$/i", $event)) {
|
||||
$this->error(__('事件名称错误'));
|
||||
}
|
||||
|
||||
if (!preg_match("/^[a-z0-9]{4,6}\$/i", $captcha)) {
|
||||
$this->error(__('验证码格式错误'));
|
||||
}
|
||||
|
||||
if ($event) {
|
||||
$userinfo = User::getByEmail($email);
|
||||
if ($event == 'register' && $userinfo) {
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
} elseif (in_array($event, ['changeemail']) && $userinfo) {
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
$ret = Emslib::check($email, $captcha, $event);
|
||||
if ($ret) {
|
||||
$this->success(__('成功'));
|
||||
} else {
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
}
|
||||
}
|
||||
62
application/api/controller/Index.php
Normal file
62
application/api/controller/Index.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
/**
|
||||
* 首页接口
|
||||
*/
|
||||
class Index extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
/**
|
||||
* 首页
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
exit();
|
||||
$mobile = '19123397891,18983232803,18100874425,18402300888,18723290293,13272679110,18502381971,18523881166,18696567826,18696519998,15523078058,18584585755,17623620828,18623452863,15696222758,13251315431,18581297078,13272881170,13002344877,13618259900,13290038820,15683594996,16623034699,13101259586,15523756271,13272722880,15523500575,18581190907,17623328238,17623083080';
|
||||
|
||||
$mobile_arr = explode(',',$mobile);
|
||||
|
||||
$res = Db::name('dudu')->select();
|
||||
foreach ($res as $key=>$value){
|
||||
$mobile_key = $value['id']%30;
|
||||
$mobile_key = $mobile_key == 0 ? 30 :$mobile_key;
|
||||
$value['F'] = $mobile_arr[$mobile_key - 1];
|
||||
|
||||
$time1 = mt_rand(10,17);
|
||||
$time2 = mt_rand(0,60);
|
||||
$time2 = $time2 < 10 ? '0'.$time2 : $time2;
|
||||
|
||||
$time3 = $this->getTime();
|
||||
|
||||
$time = $time1.':'.$time2.':'.$time3;
|
||||
$timee = $time1.':'.$time2.':'.($time3+5 < 10 ? '0'.($time3+5) : $time3 +5);
|
||||
|
||||
$value['W'] = $value['W'].' '.$time;
|
||||
$value['X'] = $value['X'].' '.$timee;
|
||||
|
||||
|
||||
Db::name('dudu')->where('id',$value['id'])->update(['F'=>$mobile_arr[$mobile_key-1],'W'=>$value['W'].' '.$time,'X'=>$value['X'].' '.$timee]);
|
||||
}
|
||||
|
||||
|
||||
$this->success('请求成功');
|
||||
}
|
||||
|
||||
public function getTime(){
|
||||
$time3 = mt_rand(0,60);
|
||||
if($time3 >= 54){
|
||||
$this->getTime();
|
||||
}
|
||||
$time3 = $time3 < 10 ? '0'.$time3 : $time3;
|
||||
return $time3;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
104
application/api/controller/Sms.php
Normal file
104
application/api/controller/Sms.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\Sms as Smslib;
|
||||
use app\common\model\User;
|
||||
use think\Hook;
|
||||
|
||||
/**
|
||||
* 手机短信接口
|
||||
*/
|
||||
class Sms extends Api
|
||||
{
|
||||
protected $noNeedLogin = '*';
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="event", type="string", required=true, description="事件名称")
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$mobile = $this->request->post("mobile");
|
||||
$event = $this->request->post("event");
|
||||
$event = $event ? $event : 'register';
|
||||
|
||||
if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('手机号不正确'));
|
||||
}
|
||||
$last = Smslib::get($mobile, $event);
|
||||
if ($last && time() - $last['createtime'] < 60) {
|
||||
$this->error(__('发送频繁'));
|
||||
}
|
||||
$ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count();
|
||||
if ($ipSendTotal >= 5) {
|
||||
$this->error(__('发送频繁'));
|
||||
}
|
||||
if ($event) {
|
||||
$userinfo = User::getByMobile($mobile);
|
||||
if ($event == 'register' && $userinfo) {
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
} elseif (in_array($event, ['changemobile']) && $userinfo) {
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
if (!Hook::get('sms_send')) {
|
||||
$this->error(__('请在后台插件管理安装短信验证插件'));
|
||||
}
|
||||
$ret = Smslib::send($mobile, null, $event);
|
||||
if ($ret) {
|
||||
$this->success(__('发送成功'));
|
||||
} else {
|
||||
$this->error(__('发送失败,请检查短信配置是否正确'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="event", type="string", required=true, description="事件名称")
|
||||
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$mobile = $this->request->post("mobile");
|
||||
$event = $this->request->post("event");
|
||||
$event = $event ? $event : 'register';
|
||||
$captcha = $this->request->post("captcha");
|
||||
|
||||
if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('手机号不正确'));
|
||||
}
|
||||
if ($event) {
|
||||
$userinfo = User::getByMobile($mobile);
|
||||
if ($event == 'register' && $userinfo) {
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
} elseif (in_array($event, ['changemobile']) && $userinfo) {
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
$ret = Smslib::check($mobile, $captcha, $event);
|
||||
if ($ret) {
|
||||
$this->success(__('成功'));
|
||||
} else {
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
}
|
||||
}
|
||||
42
application/api/controller/Token.php
Normal file
42
application/api/controller/Token.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use fast\Random;
|
||||
|
||||
/**
|
||||
* Token接口
|
||||
*/
|
||||
class Token extends Api
|
||||
{
|
||||
protected $noNeedLogin = [];
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
/**
|
||||
* 检测Token是否过期
|
||||
*
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$token = $this->auth->getToken();
|
||||
$tokenInfo = \app\common\library\Token::get($token);
|
||||
$this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新Token
|
||||
*
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
//删除源Token
|
||||
$token = $this->auth->getToken();
|
||||
\app\common\library\Token::delete($token);
|
||||
//创建新Token
|
||||
$token = Random::uuid();
|
||||
\app\common\library\Token::set($token, $this->auth->id, 2592000);
|
||||
$tokenInfo = \app\common\library\Token::get($token);
|
||||
$this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
|
||||
}
|
||||
}
|
||||
348
application/api/controller/User.php
Normal file
348
application/api/controller/User.php
Normal file
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\Ems;
|
||||
use app\common\library\Sms;
|
||||
use fast\Random;
|
||||
use think\Config;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 会员接口
|
||||
*/
|
||||
class User extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
if (!Config::get('fastadmin.usercenter')) {
|
||||
$this->error(__('User center already closed'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员中心
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->success('', ['welcome' => $this->auth->nickname]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员登录
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="account", type="string", required=true, description="账号")
|
||||
* @ApiParams (name="password", type="string", required=true, description="密码")
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$account = $this->request->post('account');
|
||||
$password = $this->request->post('password');
|
||||
if (!$account || !$password) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$ret = $this->auth->login($account, $password);
|
||||
if ($ret) {
|
||||
$data = ['userinfo' => $this->auth->getUserinfo()];
|
||||
$this->success(__('Logged in successful'), $data);
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机验证码登录
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
|
||||
*/
|
||||
public function mobilelogin()
|
||||
{
|
||||
$mobile = $this->request->post('mobile');
|
||||
$captcha = $this->request->post('captcha');
|
||||
if (!$mobile || !$captcha) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
$user = \app\common\model\User::getByMobile($mobile);
|
||||
if ($user) {
|
||||
if ($user->status != 'normal') {
|
||||
$this->error(__('Account is locked'));
|
||||
}
|
||||
//如果已经有账号则直接登录
|
||||
$ret = $this->auth->direct($user->id);
|
||||
} else {
|
||||
$ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
|
||||
}
|
||||
if ($ret) {
|
||||
Sms::flush($mobile, 'mobilelogin');
|
||||
$data = ['userinfo' => $this->auth->getUserinfo()];
|
||||
$this->success(__('Logged in successful'), $data);
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册会员
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="username", type="string", required=true, description="用户名")
|
||||
* @ApiParams (name="password", type="string", required=true, description="密码")
|
||||
* @ApiParams (name="email", type="string", required=true, description="邮箱")
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="code", type="string", required=true, description="验证码")
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$username = $this->request->post('username');
|
||||
$password = $this->request->post('password');
|
||||
$email = $this->request->post('email');
|
||||
$mobile = $this->request->post('mobile');
|
||||
$code = $this->request->post('code');
|
||||
if (!$username || !$password) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
if ($email && !Validate::is($email, "email")) {
|
||||
$this->error(__('Email is incorrect'));
|
||||
}
|
||||
if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
$ret = Sms::check($mobile, $code, 'register');
|
||||
if (!$ret) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
$ret = $this->auth->register($username, $password, $email, $mobile, []);
|
||||
if ($ret) {
|
||||
$data = ['userinfo' => $this->auth->getUserinfo()];
|
||||
$this->success(__('Sign up successful'), $data);
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$this->auth->logout();
|
||||
$this->success(__('Logout successful'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会员个人信息
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="avatar", type="string", required=true, description="头像地址")
|
||||
* @ApiParams (name="username", type="string", required=true, description="用户名")
|
||||
* @ApiParams (name="nickname", type="string", required=true, description="昵称")
|
||||
* @ApiParams (name="bio", type="string", required=true, description="个人简介")
|
||||
*/
|
||||
public function profile()
|
||||
{
|
||||
$user = $this->auth->getUser();
|
||||
$username = $this->request->post('username');
|
||||
$nickname = $this->request->post('nickname');
|
||||
$bio = $this->request->post('bio');
|
||||
$avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
||||
if ($username) {
|
||||
$exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
|
||||
if ($exists) {
|
||||
$this->error(__('Username already exists'));
|
||||
}
|
||||
$user->username = $username;
|
||||
}
|
||||
if ($nickname) {
|
||||
$exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
|
||||
if ($exists) {
|
||||
$this->error(__('Nickname already exists'));
|
||||
}
|
||||
$user->nickname = $nickname;
|
||||
}
|
||||
$user->bio = $bio;
|
||||
$user->avatar = $avatar;
|
||||
$user->save();
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改邮箱
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="email", type="string", required=true, description="邮箱")
|
||||
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
|
||||
*/
|
||||
public function changeemail()
|
||||
{
|
||||
$user = $this->auth->getUser();
|
||||
$email = $this->request->post('email');
|
||||
$captcha = $this->request->post('captcha');
|
||||
if (!$email || !$captcha) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
if (!Validate::is($email, "email")) {
|
||||
$this->error(__('Email is incorrect'));
|
||||
}
|
||||
if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
|
||||
$this->error(__('Email already exists'));
|
||||
}
|
||||
$result = Ems::check($email, $captcha, 'changeemail');
|
||||
if (!$result) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
$verification = $user->verification;
|
||||
$verification->email = 1;
|
||||
$user->verification = $verification;
|
||||
$user->email = $email;
|
||||
$user->save();
|
||||
|
||||
Ems::flush($email, 'changeemail');
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改手机号
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
|
||||
*/
|
||||
public function changemobile()
|
||||
{
|
||||
$user = $this->auth->getUser();
|
||||
$mobile = $this->request->post('mobile');
|
||||
$captcha = $this->request->post('captcha');
|
||||
if (!$mobile || !$captcha) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
|
||||
$this->error(__('Mobile already exists'));
|
||||
}
|
||||
$result = Sms::check($mobile, $captcha, 'changemobile');
|
||||
if (!$result) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
$verification = $user->verification;
|
||||
$verification->mobile = 1;
|
||||
$user->verification = $verification;
|
||||
$user->mobile = $mobile;
|
||||
$user->save();
|
||||
|
||||
Sms::flush($mobile, 'changemobile');
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方登录
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="platform", type="string", required=true, description="平台名称")
|
||||
* @ApiParams (name="code", type="string", required=true, description="Code码")
|
||||
*/
|
||||
public function third()
|
||||
{
|
||||
$url = url('user/index');
|
||||
$platform = $this->request->post("platform");
|
||||
$code = $this->request->post("code");
|
||||
$config = get_addon_config('third');
|
||||
if (!$config || !isset($config[$platform])) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$app = new \addons\third\library\Application($config);
|
||||
//通过code换access_token和绑定会员
|
||||
$result = $app->{$platform}->getUserInfo(['code' => $code]);
|
||||
if ($result) {
|
||||
$loginret = \addons\third\library\Service::connect($platform, $result);
|
||||
if ($loginret) {
|
||||
$data = [
|
||||
'userinfo' => $this->auth->getUserinfo(),
|
||||
'thirdinfo' => $result
|
||||
];
|
||||
$this->success(__('Logged in successful'), $data);
|
||||
}
|
||||
}
|
||||
$this->error(__('Operation failed'), $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="newpassword", type="string", required=true, description="新密码")
|
||||
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
|
||||
*/
|
||||
public function resetpwd()
|
||||
{
|
||||
$type = $this->request->post("type", "mobile");
|
||||
$mobile = $this->request->post("mobile");
|
||||
$email = $this->request->post("email");
|
||||
$newpassword = $this->request->post("newpassword");
|
||||
$captcha = $this->request->post("captcha");
|
||||
if (!$newpassword || !$captcha) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
//验证Token
|
||||
if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
|
||||
$this->error(__('Password must be 6 to 30 characters'));
|
||||
}
|
||||
if ($type == 'mobile') {
|
||||
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
$user = \app\common\model\User::getByMobile($mobile);
|
||||
if (!$user) {
|
||||
$this->error(__('User not found'));
|
||||
}
|
||||
$ret = Sms::check($mobile, $captcha, 'resetpwd');
|
||||
if (!$ret) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
Sms::flush($mobile, 'resetpwd');
|
||||
} else {
|
||||
if (!Validate::is($email, "email")) {
|
||||
$this->error(__('Email is incorrect'));
|
||||
}
|
||||
$user = \app\common\model\User::getByEmail($email);
|
||||
if (!$user) {
|
||||
$this->error(__('User not found'));
|
||||
}
|
||||
$ret = Ems::check($email, $captcha, 'resetpwd');
|
||||
if (!$ret) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
Ems::flush($email, 'resetpwd');
|
||||
}
|
||||
//模拟一次登录
|
||||
$this->auth->direct($user->id);
|
||||
$ret = $this->auth->changepwd($newpassword, '', true);
|
||||
if ($ret) {
|
||||
$this->success(__('Reset password successful'));
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
}
|
||||
163
application/api/controller/Validate.php
Normal file
163
application/api/controller/Validate.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\model\User;
|
||||
|
||||
/**
|
||||
* 验证接口
|
||||
*/
|
||||
class Validate extends Api
|
||||
{
|
||||
protected $noNeedLogin = '*';
|
||||
protected $layout = '';
|
||||
protected $error = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测邮箱
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="email", type="string", required=true, description="邮箱")
|
||||
* @ApiParams (name="id", type="string", required=true, description="排除会员ID")
|
||||
*/
|
||||
public function check_email_available()
|
||||
{
|
||||
$email = $this->request->post('email');
|
||||
$id = (int)$this->request->post('id');
|
||||
$count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
|
||||
if ($count > 0) {
|
||||
$this->error(__('邮箱已经被占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户名
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="username", type="string", required=true, description="用户名")
|
||||
* @ApiParams (name="id", type="string", required=true, description="排除会员ID")
|
||||
*/
|
||||
public function check_username_available()
|
||||
{
|
||||
$username = $this->request->post('username');
|
||||
$id = (int)$this->request->post('id');
|
||||
$count = User::where('username', '=', $username)->where('id', '<>', $id)->count();
|
||||
if ($count > 0) {
|
||||
$this->error(__('用户名已经被占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测昵称
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="nickname", type="string", required=true, description="昵称")
|
||||
* @ApiParams (name="id", type="string", required=true, description="排除会员ID")
|
||||
*/
|
||||
public function check_nickname_available()
|
||||
{
|
||||
$nickname = $this->request->post('nickname');
|
||||
$id = (int)$this->request->post('id');
|
||||
$count = User::where('nickname', '=', $nickname)->where('id', '<>', $id)->count();
|
||||
if ($count > 0) {
|
||||
$this->error(__('昵称已经被占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="id", type="string", required=true, description="排除会员ID")
|
||||
*/
|
||||
public function check_mobile_available()
|
||||
{
|
||||
$mobile = $this->request->post('mobile');
|
||||
$id = (int)$this->request->post('id');
|
||||
$count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count();
|
||||
if ($count > 0) {
|
||||
$this->error(__('该手机号已经占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
*/
|
||||
public function check_mobile_exist()
|
||||
{
|
||||
$mobile = $this->request->post('mobile');
|
||||
$count = User::where('mobile', '=', $mobile)->count();
|
||||
if (!$count) {
|
||||
$this->error(__('手机号不存在'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测邮箱
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="email", type="string", required=true, description="邮箱")
|
||||
*/
|
||||
public function check_email_exist()
|
||||
{
|
||||
$email = $this->request->post('email');
|
||||
$count = User::where('email', '=', $email)->count();
|
||||
if (!$count) {
|
||||
$this->error(__('邮箱不存在'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
|
||||
* @ApiParams (name="event", type="string", required=true, description="事件")
|
||||
*/
|
||||
public function check_sms_correct()
|
||||
{
|
||||
$mobile = $this->request->post('mobile');
|
||||
$captcha = $this->request->post('captcha');
|
||||
$event = $this->request->post('event');
|
||||
if (!\app\common\library\Sms::check($mobile, $captcha, $event)) {
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测邮箱验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="email", type="string", required=true, description="邮箱")
|
||||
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
|
||||
* @ApiParams (name="event", type="string", required=true, description="事件")
|
||||
*/
|
||||
public function check_ems_correct()
|
||||
{
|
||||
$email = $this->request->post('email');
|
||||
$captcha = $this->request->post('captcha');
|
||||
$event = $this->request->post('event');
|
||||
if (!\app\common\library\Ems::check($email, $captcha, $event)) {
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
844
application/api/controller/YqCes.php
Normal file
844
application/api/controller/YqCes.php
Normal file
File diff suppressed because one or more lines are too long
1154
application/api/controller/YqDataHandle.php
Normal file
1154
application/api/controller/YqDataHandle.php
Normal file
File diff suppressed because it is too large
Load Diff
130
application/api/controller/YqDatainfo.php
Normal file
130
application/api/controller/YqDatainfo.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 数据信息
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
|
||||
class YqDatainfo extends Api {
|
||||
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
//车辆运单上报
|
||||
public function waybill_reporting(){
|
||||
$map['tow_license'] = input('tow_license');
|
||||
$map['is_del'] = 1;
|
||||
$waybill_id = Db::name($this->bcapi_waybill)->whereTime('waybill_date','d')->where($map)->value('id');
|
||||
if ($waybill_id){
|
||||
$this->alertMsg(300,'该牵引车当日运单已上报,请勿重复上报');
|
||||
}
|
||||
$arr = [
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'waybill_order' => input('waybill_order'),
|
||||
'tow_license' => input('tow_license'),
|
||||
'mount_license' => input('mount_license'),
|
||||
'driver_tel' => input('driver_tel'),
|
||||
'sale_product' => input('sale_product'),
|
||||
'waybill_name' => input('waybill_name'),
|
||||
'waybill_date' => input('waybill_date'),
|
||||
'waybill_loading' => input('waybill_loading'),
|
||||
'waybill_unloading' => input('waybill_unloading'),
|
||||
'carriers_code' => input('carriers_code'),
|
||||
'vehicle_type' => input('vehicle_type'),
|
||||
'cargocount' => input('cargocount'),
|
||||
'cargocategory' => input('cargocategory'),
|
||||
'waybill_cas' => input('waybill_cas'),
|
||||
];
|
||||
$driver_id = Db::name($this->bcapi_driver)->where('phone',input('driver_tel'))->value('id');
|
||||
if (!$driver_id){
|
||||
$this->alertMsg(300,'该司机暂未注册,请先在APP上注册');
|
||||
}
|
||||
$arr['driverid'] = $driver_id;
|
||||
if (input('w_mission') == 1){
|
||||
$arr['w_mission'] = '装货';
|
||||
}else{
|
||||
$arr['w_mission'] = '卸货';
|
||||
}
|
||||
$waybill_id = Db::name($this->bcapi_waybill)->insertGetId($arr);
|
||||
if ($waybill_id !== false){
|
||||
$data['waybill_id'] = $waybill_id;
|
||||
$this->alertMsg(200,'上报成功',$data);
|
||||
}else{
|
||||
$this->alertMsg(300,'网络异常,请稍后再试');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//车辆绑定
|
||||
public function vehicle_binding($param){
|
||||
if (empty($param['tel'])){
|
||||
$this->alertMsg(300,'缺少参数');
|
||||
}
|
||||
$driver_where['phone'] = $param['tel'];
|
||||
$driver_where['status'] = 1;
|
||||
$driver_id = Db::name($this->bcapi_driver)->where($driver_where)->value('id');
|
||||
if (!$driver_id){
|
||||
$this->alertMsg(300,'账号不存在,请先注册');
|
||||
}
|
||||
|
||||
Db::name($this->bcapi_driver_vehicle)->where('license',$param['vehicle_no'])->update(['is_del'=>0]);
|
||||
$vehicle_where['driver_id'] = $driver_id;
|
||||
$vehicle_where['license'] = $param['vehicle_no'];
|
||||
$vehicle_id = Db::name($this->bcapi_driver_vehicle)->where($vehicle_where)->value('id');
|
||||
if ($vehicle_id){
|
||||
$rse = Db::name($this->bcapi_driver_vehicle)->where($vehicle_where)->update(['is_del'=>1]);
|
||||
}else{
|
||||
$arr = [
|
||||
'license' => $param['vehicle_no'],
|
||||
'driver_id' => $driver_id,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'is_del' => 1,
|
||||
];
|
||||
$rse = Db::name($this->bcapi_driver_vehicle)->insert($arr);
|
||||
}
|
||||
if($rse !== false){
|
||||
$this->alertMsg(200,'绑定成功');
|
||||
}else{
|
||||
$this->alertMsg(300,'网络异常,请稍后再试');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//查验结果提交
|
||||
public function check_submit($param){
|
||||
if (empty($param['waybill_order']) || empty($param['check_uid'])){
|
||||
$this->alertMsg(300,'缺少参数');
|
||||
}
|
||||
$waybill_id = Db::name($this->bcapi_waybill)->where('waybill_order',$param['waybill_order'])->value('id');
|
||||
if (!$waybill_id){
|
||||
$this->alertMsg(300,'异常操作,请稍后再试');
|
||||
}
|
||||
$id = Db::name($this->bcapi_check_record)->where('waybill_id',$waybill_id)->value('id');
|
||||
if ($id){
|
||||
$this->alertMsg(300,'该车辆信息已审核,请勿重复操作');
|
||||
}
|
||||
$arr = [
|
||||
'waybill_id' => $waybill_id,
|
||||
'check_uid' => 3,//重庆宝丞炭材有限公司
|
||||
'check_status' => 1,
|
||||
'check_where' => '1,2,3,4,5,6',
|
||||
'check_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
Db::startTrans();
|
||||
try{
|
||||
Db::name($this->bcapi_waybill)->where('id',$waybill_id)->update(['check_status'=>1]);
|
||||
Db::name($this->bcapi_check_record)->insert($arr);
|
||||
$see = true;
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
$see = false;
|
||||
Db::rollback();
|
||||
}
|
||||
if($see) {
|
||||
$this->alertMsg(200,'操作成功');
|
||||
}else{
|
||||
$this->alertMsg(300,'网络异常,请稍后再试');
|
||||
}
|
||||
}
|
||||
}
|
||||
645
application/api/controller/YqDriver.php
Normal file
645
application/api/controller/YqDriver.php
Normal file
@@ -0,0 +1,645 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\admin\model\Article;
|
||||
use app\admin\model\yq\alarm\Alarm;
|
||||
use app\admin\model\yq\base_config\Cargo;
|
||||
use app\admin\model\yq\base_config\Early;
|
||||
use app\admin\model\yq\driver\Driver;
|
||||
use app\admin\model\yq\driver\Trouble;
|
||||
use app\admin\model\yq\electronic_waybill\Waybill;
|
||||
use app\admin\model\yq\message\Message;
|
||||
use app\admin\model\yq\park\Park;
|
||||
use app\common\controller\Api;
|
||||
use app\common\exception\UploadException;
|
||||
use app\common\library\Upload;
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\Loader;
|
||||
|
||||
|
||||
/**
|
||||
* 司机端接口管理
|
||||
*/
|
||||
class YqDriver extends Api
|
||||
{
|
||||
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
protected $driver_id = null;
|
||||
protected $key = "A273781DBF8B7657";
|
||||
protected $method = 'AES-128-CBC';
|
||||
protected $iv = "E3041CDBBD37CC50";
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
if (!$this->driver_id) {
|
||||
if (!isset(getallheaders()['Token'])) {
|
||||
$this->error('非法请求~');
|
||||
}
|
||||
$this->driver_id = $this->decrypt(getallheaders()['Token']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** 获取基础配置信息 */
|
||||
public function index()
|
||||
{
|
||||
$data = [];
|
||||
|
||||
$this->success('success', $data);
|
||||
|
||||
}
|
||||
|
||||
//入园目的
|
||||
public function mission()
|
||||
{
|
||||
$data = (new Park())->getMissionList();
|
||||
$this->success('success', $data);
|
||||
|
||||
}
|
||||
|
||||
//载货品类
|
||||
public function getProductCate()
|
||||
{
|
||||
$data = Cargo::list();
|
||||
$this->success('success', $data);
|
||||
|
||||
}
|
||||
|
||||
//报警等级
|
||||
public function getEarlyList()
|
||||
{
|
||||
$data = Early::select();
|
||||
$this->success('success', $data);
|
||||
}
|
||||
|
||||
//企业信息
|
||||
public function getEnterpriseList()
|
||||
{
|
||||
$data = \app\admin\model\yq\perimeter\Enterprise::select();
|
||||
$this->success('success', $data);
|
||||
|
||||
}
|
||||
/** 司机信息 */
|
||||
//登录
|
||||
public function login()
|
||||
{
|
||||
$params = input();
|
||||
|
||||
if (empty($params['account']) || strlen($params['account']) > 10) {
|
||||
$this->error('请输入正确的账号');
|
||||
}
|
||||
|
||||
if (empty($params['password'])) {
|
||||
$this->error('请输入正确的密码');
|
||||
}
|
||||
|
||||
$driver = Driver::where('account', $params['account'])->find();
|
||||
if (!$driver) {
|
||||
$this->error('账号不存在,请先注册');
|
||||
}
|
||||
if ($driver['password'] != md5($params['password'])) {
|
||||
$this->error('密码错误');
|
||||
}
|
||||
|
||||
|
||||
$this->driver_id = $driver['id'];
|
||||
|
||||
$this->success('正在登录...', ['token' => $this->encrypt($driver['id'])]);
|
||||
|
||||
}
|
||||
|
||||
//注册
|
||||
public function register()
|
||||
{
|
||||
$params = input();
|
||||
|
||||
if (empty($params['account']) || strlen($params['account']) > 10) {
|
||||
$this->error('请输入正确的真实姓名');
|
||||
}
|
||||
|
||||
|
||||
if (empty($params['phone']) || !preg_match("/^1\d{10}$/", trim($params['phone']))) {
|
||||
$this->error('请输入正确的手机号码');
|
||||
}
|
||||
|
||||
$default_password = "123456";
|
||||
$params['password'] = md5($default_password);
|
||||
|
||||
$driver = Driver::where('account', $params['account'])->find();
|
||||
if ($driver) {
|
||||
$this->error('真实姓名已被注册');
|
||||
}
|
||||
|
||||
$driver = Driver::where('phone', $params['phone'])->find();
|
||||
if ($driver) {
|
||||
$this->error('手机号已被注册');
|
||||
}
|
||||
|
||||
$res = Driver::create([
|
||||
'account' => $params['account'],
|
||||
'phone' => $params['phone'],
|
||||
'password' => $params['password'],
|
||||
]);
|
||||
if ($res) {
|
||||
$this->driver_id = $res->id;
|
||||
$this->success('注册成功,正在自动登录...', ['token' => $this->encrypt($res->id)]);
|
||||
}
|
||||
$this->error('注册失败,请检查');
|
||||
}
|
||||
|
||||
//退出
|
||||
public function logout()
|
||||
{
|
||||
$this->driver_id = null;
|
||||
$this->success('退出成功');
|
||||
}
|
||||
|
||||
//自动登录
|
||||
public function autoLogin()
|
||||
{
|
||||
|
||||
$driver = Driver::where('id', $this->driver_id)->find();
|
||||
if ($driver) {
|
||||
$this->driver_id = $driver['id'];
|
||||
|
||||
$this->success('正在自动登录...', ['token' => $this->encrypt($driver['id'])]);
|
||||
}
|
||||
$this->error('自动登录失败');
|
||||
}
|
||||
|
||||
//修改信息
|
||||
public function updateDriverInfo()
|
||||
{
|
||||
$params = input();
|
||||
$driver = Driver::where('id', $this->driver_id)->find();
|
||||
if (!$driver) {
|
||||
$this->error('未找到');
|
||||
}
|
||||
if (empty($params['password'])) {
|
||||
unset($params['password']);
|
||||
} else {
|
||||
$params['password'] = md5($params['password']);
|
||||
}
|
||||
unset($params['mouth']);
|
||||
unset($params['lv']);
|
||||
unset($params['onPassage']);
|
||||
unset($params['status_text']);
|
||||
unset($params['create_time']);
|
||||
$res = Driver::update($params);
|
||||
if ($res) {
|
||||
$driver = Driver::where('id', $this->driver_id)->find();
|
||||
$this->success('修改成功', $driver);
|
||||
}
|
||||
$this->error('修改失败');
|
||||
|
||||
}
|
||||
|
||||
//司机信息
|
||||
public function getDriverInfo()
|
||||
{
|
||||
$driver = Driver::where('id', $this->driver_id)->find();
|
||||
if ($driver) {
|
||||
$driver['mouth'] = Waybill::where('driverid', $this->driver_id)->whereTime('create_time', 'month')->count('*');
|
||||
$driver['onPassage'] = 0;
|
||||
$driver['lv'] = $driver['mouth'] == 0 ? '0.00%' : (floor($driver['onPassage'] / $driver['mouth'] * 100) / 100) . '%';
|
||||
$this->success('', $driver);
|
||||
}
|
||||
$this->error('未找到');
|
||||
}
|
||||
/** 车辆信息 */
|
||||
//车辆列表
|
||||
public function carList()
|
||||
{
|
||||
$driver = \app\admin\model\yq\driver\Vehicle::where('driver_id', $this->driver_id)->column('license');
|
||||
|
||||
$list = \app\admin\model\yq\vehicle\Vehicle::where('vehicleNo', 'in', $driver)->select();
|
||||
|
||||
$this->success('获取成功', $list);
|
||||
|
||||
}
|
||||
|
||||
//绑定车辆
|
||||
public function bindVehicle()
|
||||
{
|
||||
$params = input();
|
||||
if (empty($params['vehicleNo']) || !isset($params['vehicleNo'])) {
|
||||
$this->error('请输入车牌号');
|
||||
}
|
||||
$info = \app\admin\model\yq\vehicle\Vehicle::where('vehicleNo', $params['vehicleNo'])->find();
|
||||
if ($info) {
|
||||
$this->error('该车牌已被绑定');
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
\app\admin\model\yq\vehicle\Vehicle::create(['vehicleNo' => $params['vehicleNo']]);
|
||||
\app\admin\model\yq\driver\Vehicle::create(['license' => $params['vehicleNo'], 'driver_id' => $this->driver_id]);
|
||||
|
||||
Db::commit();
|
||||
$this->success('添加成功');
|
||||
} catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
$this->error('添加失败' . $exception->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//解除绑定
|
||||
public function unbindVehicle()
|
||||
{
|
||||
$params = input();
|
||||
|
||||
$info = \app\admin\model\yq\driver\Vehicle::where(['license' => $params['vehicleNo'], 'driver_id' => $this->driver_id])->find();
|
||||
if (!$info) {
|
||||
$this->error('不存在');
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
\app\admin\model\yq\vehicle\Vehicle::where('vehicleNo', $params['vehicleNo'])->delete();
|
||||
\app\admin\model\yq\driver\Vehicle::where(['license' => $params['vehicleNo'], 'driver_id' => $this->driver_id])->delete();
|
||||
|
||||
Db::commit();
|
||||
$this->success('删除成功');
|
||||
} catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
$this->error('删除失败' . $exception->getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//修改车辆信息
|
||||
public function updateBindVehicle()
|
||||
{
|
||||
$params = input();
|
||||
if (empty($params['vehicleNo']) || !isset($params['vehicleNo'])) {
|
||||
$this->error('请输入车牌号');
|
||||
}
|
||||
$info = \app\admin\model\yq\vehicle\Vehicle::where('vehicleNo', $params['vehicleNo'])->find();
|
||||
if ($info) {
|
||||
$this->error('该车牌已被绑定');
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$id = $params['id'];
|
||||
$info = \app\admin\model\yq\vehicle\Vehicle::where('id', $id)->find();
|
||||
\app\admin\model\yq\driver\Vehicle::update(['license' => $params['vehicleNo']], ['license' => $info['vehicleNo'], 'driver_id' => $this->driver_id]);
|
||||
\app\admin\model\yq\vehicle\Vehicle::update(['vehicleNo' => $params['vehicleNo']], ['id' => $id]);
|
||||
|
||||
Db::commit();
|
||||
$this->success('修改成功');
|
||||
} catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
$this->error('修改失败' . $exception->getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/** 园区入园 */
|
||||
//列表
|
||||
public function parkList()
|
||||
{
|
||||
$res = Park::where('reporter_id', $this->driver_id)->order('create_time desc')->select();
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
|
||||
//上报
|
||||
public function enParkReport()
|
||||
{
|
||||
$params = input();
|
||||
$data = [];
|
||||
$data['reporter_id'] = $this->driver_id;
|
||||
$data['has_mount'] = $params['has_mount'];
|
||||
$data['mission'] = $params['mission'];
|
||||
$data['tractor_license'] = $params['tractor_license'];
|
||||
$data['mount_license'] = $params['mount_license'];
|
||||
$data['phone_num'] = $params['phone_num'];
|
||||
$data['reporter_name'] = $params['reporter_name'];
|
||||
$data['create_time'] = date('Y-m-d H:i:s', time());
|
||||
|
||||
|
||||
$rule = [
|
||||
'mission' => 'require',
|
||||
'phone_num' => 'require|mobile',
|
||||
'tractor_license' => 'require|max:8|min:7',
|
||||
'mount_license' => 'requireIf:has_mount,1',
|
||||
];
|
||||
|
||||
$message = [
|
||||
'mission.require' => '请选择入园目的',
|
||||
'phone_num.require' => '请填写手机号',
|
||||
'tractor_license.require' => '请填写牵引车车牌号',
|
||||
|
||||
'phone_num.mobile' => '手机号格式错误',
|
||||
'tractor_license.max' => '车牌号最多8位',
|
||||
'tractor_license.min' => '车牌号最少7位',
|
||||
|
||||
'mount_license.requireIf' => '请填写挂车车牌号',
|
||||
];
|
||||
|
||||
$validate = new \think\Validate($rule, $message);
|
||||
if (!$validate->check($data)) {
|
||||
$this->error($validate->getError());
|
||||
}
|
||||
|
||||
$res = Park::create($data);
|
||||
if ($res) {
|
||||
$this->success('上报成功');
|
||||
}
|
||||
$this->error('上报失败');
|
||||
}
|
||||
|
||||
//详情
|
||||
public function enParkInfo()
|
||||
{
|
||||
$params = input();
|
||||
$res = Park::get($params['id']);
|
||||
if ($res) {
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
$this->error('不存在');
|
||||
}
|
||||
|
||||
/** 电子运单 */
|
||||
public function waybillList()
|
||||
{
|
||||
$where = [];
|
||||
$where['driverid'] = $this->driver_id;
|
||||
$params = input();
|
||||
if (!empty($params['current']) && isset($params['current'])) {
|
||||
$where['check_status'] = $params['current'] - 1;
|
||||
}
|
||||
$res = Waybill::where($where)->order('create_time desc')->select();
|
||||
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
|
||||
//上报
|
||||
public function waybillReport()
|
||||
{
|
||||
$params = input();
|
||||
$data = [
|
||||
'cargocategory' => $params['cargocategory'],
|
||||
'cargocount' => $params['cargocount'],
|
||||
'driver_tel' => $params['driver_tel'],
|
||||
'mount_license' => $params['mount_license'] ?? '无',
|
||||
'sale_product' => $params['sale_product'],
|
||||
'tow_license' => $params['tow_license'],
|
||||
'w_mission' => $params['w_mission'],
|
||||
'waybill_date' => $params['waybill_date'],
|
||||
'waybill_loading' => $params['waybill_loading'],
|
||||
'waybill_name' => $params['waybill_name'],
|
||||
'waybill_unloading' => $params['waybill_unloading'],
|
||||
'driverid' => $this->driver_id,
|
||||
'create_time' => date('Y-m-d H:i:s', time()),
|
||||
'waybill_order' => 'CS' . date('Ymd', time()) . 'DD' . substr(time(), 2, 8)
|
||||
];
|
||||
|
||||
$rule = [
|
||||
'cargocategory' => 'require',
|
||||
'cargocount' => 'require',
|
||||
'driver_tel' => 'require|mobile',
|
||||
'sale_product' => 'require|max:20',
|
||||
'tow_license' => 'require|max:8|min:7',
|
||||
'w_mission' => 'require',
|
||||
'waybill_name' => 'require',
|
||||
'waybill_unloading' => 'requireIf:w_mission,卸货',
|
||||
'waybill_loading' => 'requireIf:w_mission,装货',
|
||||
];
|
||||
|
||||
$message = [
|
||||
'cargocategory.require' => '请填写装/卸货品类',
|
||||
'cargocount.require' => '请填写装/卸货数量',
|
||||
'driver_tel.require' => '请填写司机电话',
|
||||
'sale_product.require' => '请填写销售产品',
|
||||
'tow_license.require' => '请填写牵引车牌',
|
||||
'w_mission.require' => '请填写入园目的',
|
||||
'waybill_name.require' => '请填写运单人',
|
||||
|
||||
'driver_tel.mobile' => '司机电话格式错误',
|
||||
'sale_product.max' => '销售产品名称控制在20个字符内',
|
||||
'tow_license.max' => '车牌号最多8位',
|
||||
'tow_license.min' => '车牌号最少7位',
|
||||
|
||||
'waybill_unloading.requireIf' => '卸货时必须填写卸货信息',
|
||||
'waybill_loading.requireIf' => '装货时必须填写装货单位',
|
||||
];
|
||||
|
||||
$validate = new \think\Validate($rule, $message);
|
||||
if (!$validate->check($data)) {
|
||||
$this->error($validate->getError());
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$res = Waybill::create($data);
|
||||
|
||||
//写入一条提示信息
|
||||
Message::create([
|
||||
'driver_id' => $this->driver_id,
|
||||
'type' => 3,
|
||||
'event_id' => $res->id,
|
||||
'vehicle_no' => $params['tow_license'] ?? '',
|
||||
'create_time' => date('Y-m-d H:i:s', time()),
|
||||
]);
|
||||
Db::commit();
|
||||
$this->success('上报成功');
|
||||
} catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
// 记录详细错误日志
|
||||
\think\Log::error('运单上报失败: ' . $exception->getMessage() . PHP_EOL . $exception->getTraceAsString());
|
||||
\think\Log::error('上报参数: ' . json_encode($params, JSON_UNESCAPED_UNICODE));
|
||||
$this->error('上报失败: ' . $exception->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//详情
|
||||
public function waybillInfo()
|
||||
{
|
||||
$params = input();
|
||||
$res = Waybill::get($params['id']);
|
||||
if ($res) {
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
$this->error('不存在');
|
||||
}
|
||||
|
||||
/** 车辆事故 */
|
||||
public function troubleList()
|
||||
{
|
||||
$res = Alarm::where('reporter_id', $this->driver_id)->order('create_time desc')->select();
|
||||
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
|
||||
//上报
|
||||
public function troubleReport()
|
||||
{
|
||||
$params = input();
|
||||
$data = [
|
||||
|
||||
'reporter_id' => $this->driver_id,
|
||||
'license' => $params['license'],
|
||||
'mount_license' => $params['mount_license'],
|
||||
'has_mount' => $params['has_mount'],
|
||||
'phone' => $params['phone'],
|
||||
'perimeter_location' => $params['perimeter_location'],
|
||||
'perimeter_point' => $params['perimeter_point'],
|
||||
'type' => $params['type'],
|
||||
'describe' => $params['describe'],
|
||||
'id_card' => $params['id_card'],
|
||||
'trigger_type' => 2,
|
||||
'name' => $params['name'],
|
||||
'create_time' => date('Y-m-d H:i:s',time()),
|
||||
|
||||
];
|
||||
|
||||
|
||||
$rule = [
|
||||
'license' => 'require|max:8|min:7',
|
||||
'phone' => 'require|mobile',
|
||||
'perimeter_location' => 'require|max:50',
|
||||
'type' => 'require',
|
||||
'id_card' => 'require',
|
||||
'mount_license' => 'requireIf:has_mount,1',
|
||||
];
|
||||
|
||||
$message = [
|
||||
'license.require' => '请填写牵引车车牌',
|
||||
'phone.require' => '请填写手机号',
|
||||
'id_card.require' => '请填写身份证号',
|
||||
'perimeter_location.require' => '请填写位置信息',
|
||||
|
||||
'phone.mobile' => '司机电话格式错误',
|
||||
'latlng_address.max' => '位置信息控制在50个字符内',
|
||||
'license.min' => '牵引车牌号最少7位',
|
||||
'license.max' => '牵引车牌号最多8位',
|
||||
|
||||
'mount_license.requireIf' => '有挂车时请填写挂车车牌号',
|
||||
];
|
||||
|
||||
$validate = new \think\Validate($rule, $message);
|
||||
if (!$validate->check($data)) {
|
||||
$this->error($validate->getError());
|
||||
}
|
||||
|
||||
$data['lv'] = Early::where('id', $params['type'])->value('lv');
|
||||
$data['reporter_name'] = Driver::where('id', $this->driver_id)->value('account');
|
||||
|
||||
$res = Alarm::create($data);
|
||||
if ($res) {
|
||||
$this->success('上报成功');
|
||||
}
|
||||
$this->error('上报失败');
|
||||
}
|
||||
|
||||
//详情
|
||||
public function troubleInfo()
|
||||
{
|
||||
$params = input();
|
||||
$res = Alarm::get($params['id']);
|
||||
if ($res) {
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
$this->error('不存在');
|
||||
}
|
||||
/** 报警信息 */
|
||||
//列表
|
||||
public function alarmList()
|
||||
{
|
||||
$params = input();
|
||||
$where = [];
|
||||
if (!empty($params['cate_id']) && isset($params['cate_id'])) {
|
||||
$where['type'] = $params['cate_id'] == 0 ? 3 : 1;
|
||||
}
|
||||
|
||||
$res = Message::where('driver_id', $this->driver_id)->where($where)->select();
|
||||
foreach ($res as $k => $v) {
|
||||
$res[$k]['car'] = Cargo::get($v['m_id']);
|
||||
}
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
|
||||
//详情
|
||||
public function alarmInfo()
|
||||
{
|
||||
$params = input();
|
||||
$res = Message::where(['driver_id' => $this->driver_id, 'id' => $params['id']])->find();
|
||||
$res['car'] = Cargo::get($res['m_id']);
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
/** 帮助中心 */
|
||||
//列表
|
||||
public function articleList()
|
||||
{
|
||||
$res = Article::select();
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
|
||||
//详情
|
||||
public function articleInfo()
|
||||
{
|
||||
$params = input();
|
||||
$res = Article::where(['id' => $params['id']])->find();
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
|
||||
/** 上传图片 */
|
||||
public function upload()
|
||||
{
|
||||
$attachment = null;
|
||||
//默认普通上传文件
|
||||
$file = $this->request->file('file');
|
||||
try {
|
||||
$upload = new Upload($file);
|
||||
$attachment = $upload->upload();
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
||||
|
||||
}
|
||||
|
||||
//token解密
|
||||
public function decrypt($input)
|
||||
{
|
||||
$encrypted = base64_decode($input);
|
||||
|
||||
return openssl_decrypt(
|
||||
$encrypted,
|
||||
$this->method,
|
||||
$this->key,
|
||||
OPENSSL_RAW_DATA,
|
||||
$this->iv
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
//token加密
|
||||
public function encrypt($input)
|
||||
{
|
||||
|
||||
$encryptedText = openssl_encrypt(
|
||||
$input,
|
||||
$this->method,
|
||||
$this->key,
|
||||
OPENSSL_RAW_DATA,
|
||||
$this->iv
|
||||
);
|
||||
|
||||
return base64_encode($encryptedText);
|
||||
}
|
||||
|
||||
}
|
||||
510
application/api/controller/YqEnterprise.php
Normal file
510
application/api/controller/YqEnterprise.php
Normal file
@@ -0,0 +1,510 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 企业端
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
|
||||
class YqEnterprise extends Api {
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
// 表名定义
|
||||
protected $api_perimeter = 'perimeter';
|
||||
protected $api_enterprise_record = 'enterprise_record';
|
||||
protected $api_vehicle = 'vehicle';
|
||||
protected $api_waybill = 'waybill';
|
||||
protected $api_check_record = 'check_record';
|
||||
|
||||
//保存登录
|
||||
public function save_login($param){
|
||||
if (empty($param['code'])){
|
||||
$this->alertMsg(300,'异常操作!');
|
||||
}
|
||||
$map['login_time'] = array('elt',date("Y-m-d H:i:s", strtotime("+7 day")));
|
||||
$map['code'] = $param['code'];
|
||||
$enterprise_id = Db::name($this->api_enterprise_record)->where($map)->value('enterprise_id');
|
||||
$data['login_status'] = false;
|
||||
$data['check_uid'] = '';
|
||||
if ($enterprise_id){
|
||||
$data['login_status'] = true;
|
||||
$data['check_uid'] = $enterprise_id;
|
||||
}
|
||||
$this->alertMsg(200,'成功!',$data);
|
||||
}
|
||||
|
||||
|
||||
//登录
|
||||
public function login($param = null){
|
||||
// 如果没有传递参数,从 input() 获取
|
||||
if ($param === null) {
|
||||
$param = input();
|
||||
}
|
||||
|
||||
if (empty($param['account']) || empty($param['password'])){
|
||||
$this->alertMsg(300,'异常操作!');
|
||||
}
|
||||
$info = Db::name($this->api_perimeter)->where('account',$param['account'])->field('id,password')->find();
|
||||
if (!$info['id']) {
|
||||
$this->alertMsg(300,'用户不存在或被禁用!');
|
||||
} else {
|
||||
if (md5($param['password']) !== $info['password']) {
|
||||
$this->alertMsg(300,'密码错误!');
|
||||
} else {
|
||||
// code 参数可选,如果没有提供则生成一个
|
||||
$code = isset($param['code']) ? $param['code'] : 'web_' . time() . '_' . uniqid();
|
||||
$arr = [
|
||||
'enterprise_id' => $info['id'],
|
||||
'code' => $code,
|
||||
'login_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
$enterprise_id = Db::name($this->api_enterprise_record)->where('code',$code)->value('enterprise_id');
|
||||
if (!$enterprise_id){
|
||||
Db::name($this->api_enterprise_record)->insert($arr);
|
||||
}else{
|
||||
Db::name($this->api_enterprise_record)->where('enterprise_id',$enterprise_id)->update($arr);
|
||||
}
|
||||
$this->alertMsg(200,'登录成功!',$info['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//修改密码
|
||||
public function updata_pwd($param){
|
||||
if (empty($param['check_uid']) || empty($param['old_pwd']) || empty($param['pwd']) ||empty($param['secondary_pwd'])){
|
||||
$this->alertMsg(300,'异常操作!');
|
||||
}
|
||||
$password = Db::name($this->api_perimeter)->where('id',$param['check_uid'])->value('password');
|
||||
if (md5($param['old_pwd']) !== $password) {
|
||||
$this->alertMsg(300,'旧密码错误!');
|
||||
} else {
|
||||
if ($param['pwd'] != $param['secondary_pwd']){
|
||||
$this->alertMsg(300,'两次新密码不匹配!');
|
||||
}
|
||||
$rse = Db::name($this->api_perimeter)->where('id',$param['check_uid'])->update(['password'=>md5($param['pwd'])]);
|
||||
if($rse) {
|
||||
$this->alertMsg(200,'修改成功!');
|
||||
}else{
|
||||
$this->alertMsg(300,'网络异常,请稍后再试!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//查验车辆码
|
||||
public function check_vehicle_no($param){
|
||||
if (empty($param['info'])){
|
||||
$this->alertMsg(300,'异常操作!');
|
||||
}
|
||||
$info = explode(',',$param['info']);
|
||||
$vehicle_info = Db::name($this->api_vehicle)->where('vehicleNo',$info[0])->field('id,plateColor,qr_color')->find();
|
||||
if (empty($vehicle_info['qr_color'])){
|
||||
$this->alertMsg(300,'园区内未检测到该车信息,请先绑定后再试!');
|
||||
}
|
||||
if ($vehicle_info['qr_color'] != 1){
|
||||
if ($vehicle_info['qr_color'] == 2){
|
||||
$mag = '未查到该车有最新电子运单信息,请进行电子运单预约上报!';
|
||||
}else{
|
||||
$mag = '该车有违章,请到停车场或检查站进行红码消除后再进行电子运单预约上报!';
|
||||
}
|
||||
$this->alertMsg(201,$mag,$vehicle_info['qr_color']);
|
||||
}else{
|
||||
$where['tow_license'] = $info[0];
|
||||
$where['is_del'] = 1;
|
||||
$field = 'id,tow_license,mount_license,driver_tel,sale_product,create_time,waybill_date,waybill_loading,waybill_unloading,check_status';
|
||||
$waybill = Db::name($this->api_waybill)->whereTime('waybill_date','d')->where($where)->order('id desc')->field($field)->find();//(当天内有效)
|
||||
if (empty($waybill)){
|
||||
$this->alertMsg(202,'未查到该车有最新电子运单信息,请进行电子运单预约上报!');
|
||||
}else{
|
||||
$vehicle_status = '正常,已获取到车辆GPS定位';
|
||||
$vehicle_id = true;
|
||||
if (!$vehicle_info['plateColor']){//车辆表是否存在该车GPS定位
|
||||
$vehicle_status = '异常,未获取到车辆GPS定位';
|
||||
$vehicle_id = false;
|
||||
$waybill['plateColor'] = '';
|
||||
}else{
|
||||
$waybill['plateColor'] = $vehicle_info['plateColor'];
|
||||
}
|
||||
$waybill['vehicle_status'] = $vehicle_status;
|
||||
$waybill['vehicle_id'] = $vehicle_id;
|
||||
}
|
||||
$data['waybill'] = $waybill;
|
||||
$this->alertMsg(200,'操作成功!',$data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//查验结果提交
|
||||
public function check_submit($param){
|
||||
if (empty($param['waybill_id']) || empty($param['check_uid']) || empty($param['check_status'])){
|
||||
$this->alertMsg(300,'异常操作!');
|
||||
}
|
||||
$id = Db::name($this->api_check_record)->where('waybill_id',$param['waybill_id'])->value('id');
|
||||
if ($id){
|
||||
$this->alertMsg(300,'该车辆信息已审核,请勿重复操作!');
|
||||
}
|
||||
$arr = [
|
||||
'waybill_id' => $param['waybill_id'],
|
||||
'check_uid' => $param['check_uid'],
|
||||
'check_status' => $param['check_status'],
|
||||
'check_where' => $param['check_where']?$param['check_where']:'',
|
||||
'check_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
Db::startTrans();
|
||||
try{
|
||||
Db::name($this->api_waybill)->where('id',$param['waybill_id'])->setField(['check_status'=>$param['check_status']]);
|
||||
Db::name($this->api_check_record)->insert($arr);
|
||||
$see = true;
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
$see = false;
|
||||
Db::rollback();
|
||||
}
|
||||
if($see) {
|
||||
$this->alertMsg(200,'提交成功!');
|
||||
}else{
|
||||
$this->alertMsg(300,'网络异常,请稍后再试!');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//查验列表
|
||||
public function check_list($param){
|
||||
$page = input('page',$this->pageNum);
|
||||
$limit = input('limit',$this->pernumber);
|
||||
$map['check_uid'] = $param['check_uid'];
|
||||
$map['is_del'] = 1;
|
||||
//模糊搜索
|
||||
if (input('key')) {
|
||||
$where['tow_license'] = array('like', "%" . input('key') . "%");
|
||||
$ids = Db::name($this->api_waybill)->where($where)->field('id')->select();
|
||||
if (!empty($ids)){
|
||||
foreach ($ids as $v) {
|
||||
$v = join(',',$v);
|
||||
$temp[] = $v;
|
||||
}
|
||||
$t = '';
|
||||
foreach($temp as $v){
|
||||
$t .= $v.',';
|
||||
}
|
||||
$t = substr($t,0,-1);
|
||||
$map['waybill_id'] = array('in',$t);
|
||||
}else{
|
||||
$map['waybill_id'] = '';
|
||||
}
|
||||
}
|
||||
//时间筛选
|
||||
$sldate = input('reservation','');
|
||||
$arr = explode(" - ",$sldate);
|
||||
if(count($arr) == 2){
|
||||
$map['check_time'] = array(array('egt',$arr[0]),array('elt',$arr[1]),'AND');
|
||||
}
|
||||
$field = 'id,waybill_id,check_uid,check_status,check_time';
|
||||
$list = Db::name($this->api_check_record)->where($map)->field($field)->order('check_time desc')->page($page)->limit($limit)->select();
|
||||
$conut = Db::name($this->api_check_record)->where($map)->field('id')->count();
|
||||
if ($list){
|
||||
foreach ($list as $k => $v){
|
||||
$list[$k]['check_name'] = Db::name($this->api_perimeter)->where('id',$v['check_uid'])->value('name');
|
||||
$waybill = Db::name($this->api_waybill)->where('id',$v['waybill_id'])->field('tow_license,mount_license,waybill_date')->find();
|
||||
$list[$k]['tow_license'] = $waybill['tow_license'];
|
||||
$list[$k]['mount_license'] = $waybill['mount_license'];
|
||||
$list[$k]['waybill_date'] = date('Y-m-d',strtotime($waybill['waybill_date']));
|
||||
}
|
||||
}
|
||||
$data['pages'] = ceil($conut/$limit);
|
||||
$data['list'] = $list;
|
||||
$this->alertMsg(300,'请求成功!',$data);
|
||||
}
|
||||
|
||||
|
||||
//查验详情
|
||||
public function check_detail($param){
|
||||
if (empty($param['waybill_id'])){
|
||||
$this->alertMsg(300,'异常操作!');
|
||||
}
|
||||
$field = 'id,tow_license,mount_license,driver_tel,sale_product,create_time,waybill_date,waybill_loading,waybill_unloading,check_status';
|
||||
$waybill = Db::name($this->api_waybill)->where('id',$param['waybill_id'])->field($field)->find();
|
||||
$vehicle_status = '正常,已获取到车辆GPS定位';
|
||||
$vehicle_id = true;
|
||||
$vehicle_info = Db::name($this->api_vehicle)->where('vehicleNo',$waybill['tow_license'])->field('id,plateColor')->find();
|
||||
if (!$vehicle_info['plateColor']){//车辆表是否存在该车GPS定位
|
||||
$vehicle_status = '异常,未获取到车辆GPS定位';
|
||||
$vehicle_id = false;
|
||||
$waybill['plateColor'] = '';
|
||||
}else{
|
||||
$waybill['plateColor'] = $vehicle_info['plateColor'];
|
||||
}
|
||||
$waybill['vehicle_status'] = $vehicle_status;
|
||||
$waybill['vehicle_id'] = $vehicle_id;
|
||||
$data['waybill'] = $waybill;
|
||||
$this->alertMsg(200,'操作成功!',$data);
|
||||
}
|
||||
|
||||
|
||||
//车辆信息
|
||||
public function vehicle_info($param){
|
||||
if (empty($param['vehicleNo'])){
|
||||
$this->alertMsg(300,'异常操作!');
|
||||
}
|
||||
if (empty($param['plateColor'])){
|
||||
$this->alertMsg(300,'该车暂未获取到GPS,车辆信息无法显示!');
|
||||
}
|
||||
$url = 'http://47.108.219.88:5000/api/httpserver/vehicleInfo?vehicleNo='.rawurlencode($param['vehicleNo']).'&plateColor='.$param['plateColor'];
|
||||
$header = array();
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$json = json_decode($output,true);
|
||||
if (empty($json['body'])){
|
||||
$list = [
|
||||
'vehicleNo' => '',
|
||||
'ownerName' => '',
|
||||
'licenseIssueOrganCode' => '',
|
||||
'transCertificateCode' => '',
|
||||
'transCertificateWord' => '',
|
||||
'businessScopeName' => '',
|
||||
];
|
||||
$data['list'] = $list;
|
||||
}else{
|
||||
$data['list'] = $json['body'];
|
||||
}
|
||||
$this->alertMsg(200,'操作成功!',$data);
|
||||
}
|
||||
|
||||
//获取统计数据(用于移动端首页展示)
|
||||
public function statistics($param = null){
|
||||
if ($param === null) {
|
||||
$param = input();
|
||||
}
|
||||
|
||||
if (empty($param['check_uid'])){
|
||||
$this->alertMsg(300,'异常操作!');
|
||||
}
|
||||
|
||||
$check_uid = $param['check_uid'];
|
||||
$today = date('Y-m-d');
|
||||
|
||||
// 先检查是否有该企业的查验记录(不限制 is_del,因为可能数据中 is_del 的值不同)
|
||||
$hasRecords = Db::name($this->api_check_record)
|
||||
->where('check_uid', $check_uid)
|
||||
->count();
|
||||
|
||||
// 1. 园区车辆总数:统计该企业查验过的车辆总数(去重)
|
||||
// 先获取所有去重的车牌号,然后统计数量
|
||||
// 注意:如果关联失败,可能是因为 waybill_id 不存在,需要先检查
|
||||
$vehicleList = [];
|
||||
if ($hasRecords > 0) {
|
||||
try {
|
||||
$vehicleList = Db::name($this->api_check_record)
|
||||
->alias('cr')
|
||||
->join($this->api_waybill . ' w', 'cr.waybill_id = w.id', 'LEFT')
|
||||
->where('cr.check_uid', $check_uid)
|
||||
->where('cr.is_del', 1)
|
||||
->where('w.tow_license', '<>', '')
|
||||
->where('w.tow_license', 'not null')
|
||||
->group('w.tow_license')
|
||||
->column('w.tow_license');
|
||||
} catch (\Exception $e) {
|
||||
// 如果关联查询失败,尝试直接查询
|
||||
$vehicleList = [];
|
||||
}
|
||||
}
|
||||
$vehicleCount = count(array_filter($vehicleList)); // 过滤空值
|
||||
|
||||
// 2. 今日入园申请数:今日该企业的查验记录数
|
||||
$todayApplications = Db::name($this->api_check_record)
|
||||
->where('check_uid', $check_uid)
|
||||
->where('is_del', 1)
|
||||
->whereTime('check_time', 'today')
|
||||
->count();
|
||||
|
||||
// 如果 todayApplications 为 0,尝试不限制 is_del
|
||||
if ($todayApplications == 0) {
|
||||
$todayApplications = Db::name($this->api_check_record)
|
||||
->where('check_uid', $check_uid)
|
||||
->whereTime('check_time', 'today')
|
||||
->count();
|
||||
}
|
||||
|
||||
// 3. 今日已批准数:今日已通过的查验记录数
|
||||
$todayApproved = Db::name($this->api_check_record)
|
||||
->where('check_uid', $check_uid)
|
||||
->where('check_status', 1)
|
||||
->where('is_del', 1)
|
||||
->whereTime('check_time', 'today')
|
||||
->count();
|
||||
|
||||
// 4. 今日待审批数:今日未通过的查验记录数
|
||||
$todayPending = Db::name($this->api_check_record)
|
||||
->where('check_uid', $check_uid)
|
||||
->where('check_status', '<>', 1)
|
||||
->where('is_del', 1)
|
||||
->whereTime('check_time', 'today')
|
||||
->count();
|
||||
|
||||
// 5. 有运单车辆数:统计有运单的车辆数(今日有运单的车辆)
|
||||
$waybillVehicleList = [];
|
||||
if ($hasRecords > 0) {
|
||||
try {
|
||||
$waybillVehicleList = Db::name($this->api_waybill)
|
||||
->alias('w')
|
||||
->join($this->api_check_record . ' cr', 'w.id = cr.waybill_id', 'LEFT')
|
||||
->where('cr.check_uid', $check_uid)
|
||||
->where('cr.is_del', 1)
|
||||
->whereTime('w.waybill_date', 'today')
|
||||
->where('w.tow_license', '<>', '')
|
||||
->where('w.tow_license', 'not null')
|
||||
->group('w.tow_license')
|
||||
->column('w.tow_license');
|
||||
} catch (\Exception $e) {
|
||||
$waybillVehicleList = [];
|
||||
}
|
||||
}
|
||||
$waybillVehicles = count(array_filter($waybillVehicleList));
|
||||
|
||||
// 6. 运输中车辆数:今日有运单且状态为运输中的车辆(可以根据实际情况调整判断条件)
|
||||
$transportingVehicles = $waybillVehicles; // 简化处理,实际可以根据运单状态判断
|
||||
|
||||
// 7. 待装卸车辆数:可以根据运单状态判断,这里简化处理
|
||||
$loadingVehicles = 0;
|
||||
|
||||
// 8. 今日新增车辆数:今日首次查验的车辆数(该车辆在今天之前没有查验记录)
|
||||
$allVehicles = [];
|
||||
$todayVehicles = [];
|
||||
|
||||
if ($hasRecords > 0) {
|
||||
try {
|
||||
// 先获取所有该企业查验过的车辆(今天之前的)
|
||||
$allVehicles = Db::name($this->api_check_record)
|
||||
->alias('cr')
|
||||
->join($this->api_waybill . ' w', 'cr.waybill_id = w.id', 'LEFT')
|
||||
->where('cr.check_uid', $check_uid)
|
||||
->where('cr.is_del', 1)
|
||||
->where('cr.check_time', '<', date('Y-m-d 00:00:00'))
|
||||
->where('w.tow_license', '<>', '')
|
||||
->where('w.tow_license', 'not null')
|
||||
->group('w.tow_license')
|
||||
->column('w.tow_license');
|
||||
|
||||
// 获取今日查验的所有车辆
|
||||
$todayVehicles = Db::name($this->api_check_record)
|
||||
->alias('cr')
|
||||
->join($this->api_waybill . ' w', 'cr.waybill_id = w.id', 'LEFT')
|
||||
->where('cr.check_uid', $check_uid)
|
||||
->where('cr.is_del', 1)
|
||||
->whereTime('cr.check_time', 'today')
|
||||
->where('w.tow_license', '<>', '')
|
||||
->where('w.tow_license', 'not null')
|
||||
->group('w.tow_license')
|
||||
->column('w.tow_license');
|
||||
} catch (\Exception $e) {
|
||||
$allVehicles = [];
|
||||
$todayVehicles = [];
|
||||
}
|
||||
}
|
||||
|
||||
// 今日新增 = 今日查验的车辆中,不在历史车辆列表中的
|
||||
$todayNewVehicles = 0;
|
||||
if (!empty($todayVehicles)) {
|
||||
$allVehicles = array_filter($allVehicles);
|
||||
$todayVehicles = array_filter($todayVehicles);
|
||||
foreach ($todayVehicles as $vehicle) {
|
||||
if ($vehicle && !in_array($vehicle, $allVehicles)) {
|
||||
$todayNewVehicles++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'total_vehicles' => intval($vehicleCount),
|
||||
'today_applications' => intval($todayApplications),
|
||||
'today_approved' => intval($todayApproved),
|
||||
'today_pending' => intval($todayPending),
|
||||
'active_orders' => intval($waybillVehicles),
|
||||
'transporting' => intval($transportingVehicles),
|
||||
'loading' => intval($loadingVehicles),
|
||||
'today_new' => intval($todayNewVehicles)
|
||||
];
|
||||
|
||||
$this->alertMsg(200,'请求成功!',$data);
|
||||
}
|
||||
|
||||
//获取当前账户的园区记录列表(简化版,用于移动端首页展示)
|
||||
public function park_records($param = null){
|
||||
if ($param === null) {
|
||||
$param = input();
|
||||
}
|
||||
|
||||
if (empty($param['check_uid'])){
|
||||
$this->alertMsg(300,'异常操作!');
|
||||
}
|
||||
|
||||
$page = isset($param['page']) ? intval($param['page']) : 1;
|
||||
$limit = isset($param['limit']) ? intval($param['limit']) : 10;
|
||||
|
||||
$map['check_uid'] = $param['check_uid'];
|
||||
$map['is_del'] = 1;
|
||||
|
||||
// 获取总数
|
||||
$count = Db::name($this->api_check_record)->where($map)->count();
|
||||
|
||||
// 获取列表数据
|
||||
$field = 'id,waybill_id,check_uid,check_status,check_time,check_where';
|
||||
$list = Db::name($this->api_check_record)
|
||||
->where($map)
|
||||
->field($field)
|
||||
->order('check_time desc')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
|
||||
// 补充关联信息
|
||||
if ($list){
|
||||
foreach ($list as $k => $v){
|
||||
// 获取运单信息
|
||||
$waybill = Db::name($this->api_waybill)
|
||||
->where('id',$v['waybill_id'])
|
||||
->field('tow_license,mount_license,waybill_date,waybill_loading,waybill_unloading')
|
||||
->find();
|
||||
|
||||
if ($waybill) {
|
||||
$list[$k]['tow_license'] = $waybill['tow_license'];
|
||||
$list[$k]['mount_license'] = $waybill['mount_license'];
|
||||
$list[$k]['waybill_date'] = $waybill['waybill_date'];
|
||||
$list[$k]['waybill_loading'] = $waybill['waybill_loading'];
|
||||
$list[$k]['waybill_unloading'] = $waybill['waybill_unloading'];
|
||||
} else {
|
||||
$list[$k]['tow_license'] = '';
|
||||
$list[$k]['mount_license'] = '';
|
||||
$list[$k]['waybill_date'] = '';
|
||||
$list[$k]['waybill_loading'] = '';
|
||||
$list[$k]['waybill_unloading'] = '';
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
$list[$k]['check_time_formatted'] = date('Y-m-d H:i:s', strtotime($v['check_time']));
|
||||
$list[$k]['check_date'] = date('Y-m-d', strtotime($v['check_time']));
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'list' => $list ? $list : [],
|
||||
'total' => $count,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'pages' => ceil($count / $limit)
|
||||
];
|
||||
|
||||
$this->alertMsg(200,'请求成功!',$data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
85
application/api/controller/YqPerimeter.php
Normal file
85
application/api/controller/YqPerimeter.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 监管平台 [ WE CAN DO IT MORE SIMPLE ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2018-2019 http://www.rainfer.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 无【周界接口】
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
|
||||
use app\admin\model\Admin;
|
||||
use app\admin\model\yq\alarm\Alarm;
|
||||
use app\admin\model\yq\alarm\Trend;
|
||||
use app\admin\model\yq\electronic_waybill\Waybill;
|
||||
use app\admin\model\yq\park\Park;
|
||||
use app\admin\model\yq\perimeter\EnterpriseCheck;
|
||||
use app\admin\model\yq\vehicle\LineLog;
|
||||
use app\admin\model\yq\vehicle\ParkLineLog;
|
||||
use app\admin\model\yq\vehicle\Vehicle;
|
||||
use app\admin\model\yq\base_config\Perimeter;
|
||||
|
||||
use think\Db;
|
||||
|
||||
|
||||
class YqPerimeter extends Api {
|
||||
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
//周界列表
|
||||
public function perimeter_list(){
|
||||
$perimeter_list = Perimeter::where('is_del',1)->select();
|
||||
$this->success('请求成功!',$perimeter_list);
|
||||
}
|
||||
|
||||
|
||||
//周界详情
|
||||
public function perimeter_detail(){
|
||||
// $id = input('id');
|
||||
// if (!$id) {
|
||||
// $this->error('异常操作!');
|
||||
// }
|
||||
$name = input('name');
|
||||
if (!$name) {
|
||||
$this->error('异常操作!');
|
||||
}
|
||||
$perimeter_info['space'] = 0;
|
||||
$perimeter_info['place_car'] = 0;
|
||||
$perimeter_info['remainder_car'] = 0;
|
||||
$perimeter_info['in_car'] = 0;
|
||||
$perimeter_info['out_car'] = 0;
|
||||
|
||||
$perimeter_info = Perimeter::where('name',$name)->find();
|
||||
// if($perimeter_info){
|
||||
// $perimeter_info['space'] = mt_rand(1000,2000);
|
||||
// $perimeter_info['place_car'] = mt_rand(100,1000);
|
||||
// $perimeter_info['remainder_car'] = mt_rand(100,1000);
|
||||
// $perimeter_info['in_car'] = mt_rand(100,1000);
|
||||
// $perimeter_info['out_car'] = mt_rand(100,1000);
|
||||
// }
|
||||
$this->success('查询成功!',$perimeter_info);
|
||||
}
|
||||
|
||||
|
||||
//编辑周界
|
||||
public function perimeter_edit(){
|
||||
$id = input('id');
|
||||
if (!$id) {
|
||||
$this->error('异常操作!');
|
||||
}
|
||||
$data = array(
|
||||
'info' => input('info'),
|
||||
);
|
||||
$res = Perimeter::where('id',$id)->update($data);
|
||||
if($res){
|
||||
$this->success('操作成功!');
|
||||
}else{
|
||||
$this->error('操作失败!');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
1630
application/api/controller/YqScreen.php
Normal file
1630
application/api/controller/YqScreen.php
Normal file
File diff suppressed because it is too large
Load Diff
869
application/api/controller/YqVehicle.php
Normal file
869
application/api/controller/YqVehicle.php
Normal file
@@ -0,0 +1,869 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
|
||||
|
||||
class YqVehicle extends Api {
|
||||
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
//动态添加车辆记录表
|
||||
public function add_vehicle_table(){
|
||||
$time = 's_vehicle_'.date('Ymd',strtotime("+1 day"));
|
||||
Db::query('CREATE TABLE '.$time.' LIKE s_vehicle_table');
|
||||
$this->pre($time.'添加成功!');
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
//园区车辆进出统计
|
||||
public function vehicle_statistics(){
|
||||
$map['is_del'] = array('in','1');
|
||||
$vehicle_count = Db::name('vehicle')->where($map)->field('id')->count();
|
||||
$park_info = Db::name('perimeter')->where('id',1)->field('vehicle_count,enter_vehicle,out_vehicle')->find();
|
||||
$count = $vehicle_count - $park_info['vehicle_count'];
|
||||
$arr['vehicle_count'] = $vehicle_count;
|
||||
if ($count >= 0){
|
||||
$arr['enter_vehicle'] = $park_info['enter_vehicle'] + $count;
|
||||
}else{
|
||||
$arr['out_vehicle'] = $park_info['out_vehicle'] + abs($count);
|
||||
}
|
||||
if (100 >= $count){
|
||||
Db::name('perimeter')->where('id',1)->update($arr);//增加入园车次或出园车次
|
||||
}else{
|
||||
$arr['enter_vehicle'] = $park_info['enter_vehicle'] + 0;
|
||||
$arr['out_vehicle'] = $park_info['out_vehicle'] + 0;
|
||||
Db::name('perimeter')->where('id',1)->update($arr);//增加入园车次或出园车次
|
||||
}
|
||||
$enterprise_list = Db::name('perimeter')->where(['region_type'=>6,'is_del'=>1])->field('id,stop_vehicle,vehicle_count,enter_vehicle,out_vehicle')->select();
|
||||
foreach ($enterprise_list as $k => $v){
|
||||
$map['perimeter_id'] = $v['id'];
|
||||
$vehicle_per_count = Db::name('vehicle')->where($map)->field('id')->count();
|
||||
$per_count = $vehicle_per_count - $v['vehicle_count'];
|
||||
$per_arr['vehicle_count'] = $vehicle_per_count;
|
||||
if ($per_count >= 0){
|
||||
$per_arr['enter_vehicle'] = $v['enter_vehicle'] + $per_count;
|
||||
$per_arr['out_vehicle'] = $v['out_vehicle'];
|
||||
}else{
|
||||
$per_arr['enter_vehicle'] = $v['enter_vehicle'];
|
||||
$per_arr['out_vehicle'] = $v['out_vehicle'] + abs($per_count);
|
||||
}
|
||||
if (100 >= $per_count){
|
||||
Db::name('perimeter')->where('id',$v['id'])->update($per_arr);
|
||||
}
|
||||
if ($vehicle_per_count > $v['stop_vehicle']){
|
||||
$info = Db::name('vehicle')->where($map)->field('id,vehicleNo,longitude,latitude')->find();
|
||||
$id = Db::name('enterprise_police')->whereTime('create_time','d')->where('mount_license',$info['vehicleNo'])->value('id');
|
||||
if (!$id){
|
||||
$police_arr = [
|
||||
'name' => '企业超最大可进入数',
|
||||
'mount_license' => $info['vehicleNo'],
|
||||
'perimeter' => $v['id'],//周界id
|
||||
'stop_number' => $v['stop_vehicle'],//企业区域可停车辆数
|
||||
'current_number' => $vehicle_per_count,//当前停止车辆数
|
||||
'perimeter_point' => $info['longitude'].','.$info['latitude'],
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
Db::name('enterprise_police')->insert($police_arr);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->pre('更新成功!');
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
public function vehicle_statistics_log(){
|
||||
$perimeter_list = Db::name('perimeter')->field('id,name,region_type,vehicle_count,enter_vehicle,out_vehicle')->select();
|
||||
$arr = [
|
||||
'content' => json_encode($perimeter_list),
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
Db::name('perimeter_log')->insert($arr);
|
||||
$up_arr = [
|
||||
'vehicle_count' => 0,
|
||||
'enter_vehicle' => 0,
|
||||
'out_vehicle' => 0,
|
||||
];
|
||||
Db::name('perimeter')->where('is_del',1)->update($up_arr);
|
||||
$this->pre('更新成功!');
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
//定时更新车辆信息
|
||||
public function update_info(){
|
||||
$map['is_del'] = array('in','1,2');
|
||||
$vehicle_list = Db::name('vehicle')->field('vehicleNo,positionTime')->where($map)->select();
|
||||
if ($vehicle_list){
|
||||
foreach ($vehicle_list as $k => $v){
|
||||
$where['vehicleNo'] = $v['vehicleNo'];
|
||||
$where['positionTime'] = array('egt',date("Y-m-d H:i:s", strtotime("-3 day")));
|
||||
$is_exist = Db::name('vehicle')->where($where)->value('id');
|
||||
if (!$is_exist){
|
||||
Db::name('vehicle')->where('vehicleNo',$v['vehicleNo'])->update(['is_del'=>3]);
|
||||
}else{
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->pre('操作成功!');
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
//定时更新小围栏车辆信息(清除1)
|
||||
public function enclosure_info(){
|
||||
$vehicle_list = Db::name('vehicle')->field('vehicleNo,longitude,latitude')->select();
|
||||
//小围栏坐标集
|
||||
$max_path = "107.01527,29.895601;106.997876,29.89281;106.991391,29.887939;106.985853,29.880405;106.981835,29.871026;106.960543,29.849142;106.950737,29.83564;106.945862,29.824089;106.943563,29.814148;106.945054,29.799754;106.942764,29.783607;106.970332,29.766519;106.983273,29.751322;107.017612,29.737776;107.050425,29.734115;107.064458,29.737683;107.064744,29.739318;107.058942,29.748447;107.055205,29.762378;107.071581,29.77504;107.086248,29.789923;107.088111,29.796775;107.084106,29.807387;107.080959,29.81142;107.068298,29.813474;107.06422,29.813406;107.060435,29.82112;107.050628,29.827207;107.04726,29.828623;107.046543,29.829966;107.04701,29.830878;107.04712,29.834263;107.044827,29.838826;107.053757,29.842875;107.056479,29.849047;107.057124,29.85153;107.056802,29.853468;107.060415,29.86047;107.061665,29.864841;107.054919,29.881592;107.052508,29.894119;107.040451,29.898403;107.028579,29.89536;107.014946,29.895825;106.997804,29.89278";
|
||||
foreach ($vehicle_list as $k => $v) {
|
||||
$jc_point = [
|
||||
'lng' => $v['longitude'],
|
||||
'lat' => $v['latitude'],
|
||||
];
|
||||
$big = explode(';',$max_path);
|
||||
$jc_arr = [];
|
||||
foreach ($big as $bigK => $bigV) {
|
||||
$arr = explode(',', $bigV);
|
||||
$jc_arr[] = [
|
||||
'lng' => $arr[0],
|
||||
'lat' => $arr[1],
|
||||
|
||||
];
|
||||
}
|
||||
$jcs = $this->is_point_in_polygon($jc_point,$jc_arr);
|
||||
if ($jcs){
|
||||
}else{
|
||||
Db::name('vehicle')->where('vehicleNo',$v['vehicleNo'])->update(['is_del'=>3]);
|
||||
}
|
||||
}
|
||||
$this->pre('操作成功!');
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
//定时记录园区围栏进出日志(暂未用)
|
||||
public function vehicle_log(){
|
||||
//园区区域围栏
|
||||
$max_path_json = '[{"lng":"107.01527","lat":"29.895601"},{"lng":"106.997876","lat":"29.89281"},{"lng":"106.991391","lat":"29.887939"},{"lng":"106.985853","lat":"29.880405"},{"lng":"106.981835","lat":"29.871026"},{"lng":"106.960543","lat":"29.849142"},{"lng":"106.950737","lat":"29.83564"},{"lng":"106.945862","lat":"29.824089"},{"lng":"106.943563","lat":"29.814148"},{"lng":"106.945054","lat":"29.799754"},{"lng":"106.942764","lat":"29.783607"},{"lng":"106.970332","lat":"29.766519"},{"lng":"106.983273","lat":"29.751322"},{"lng":"107.017612","lat":"29.737776"},{"lng":"107.050425","lat":"29.734115"},{"lng":"107.064458","lat":"29.737683"},{"lng":"107.064744","lat":"29.739318"},{"lng":"107.058942","lat":"29.748447"},{"lng":"107.055205","lat":"29.762378"},{"lng":"107.071581","lat":"29.77504"},{"lng":"107.086248","lat":"29.789923"},{"lng":"107.088111","lat":"29.796775"},{"lng":"107.084106","lat":"29.807387"},{"lng":"107.080959","lat":"29.81142"},{"lng":"107.068298","lat":"29.813474"},{"lng":"107.06422","lat":"29.813406"},{"lng":"107.060435","lat":"29.82112"},{"lng":"107.050628","lat":"29.827207"},{"lng":"107.04726","lat":"29.828623"},{"lng":"107.046543","lat":"29.829966"},{"lng":"107.04701","lat":"29.830878"},{"lng":"107.04712","lat":"29.834263"},{"lng":"107.044827","lat":"29.838826"},{"lng":"107.053757","lat":"29.842875"},{"lng":"107.056479","lat":"29.849047"},{"lng":"107.057124","lat":"29.85153"},{"lng":"107.056802","lat":"29.853468"},{"lng":"107.060415","lat":"29.86047"},{"lng":"107.061665","lat":"29.864841"},{"lng":"107.054919","lat":"29.881592"},{"lng":"107.052508","lat":"29.894119"},{"lng":"107.040451","lat":"29.898403"},{"lng":"107.028579","lat":"29.89536"},{"lng":"107.014946","lat":"29.895825"},{"lng":"106.997804","lat":"29.89278"}]';
|
||||
$max_path_arr = json_decode($max_path_json,true);
|
||||
|
||||
//当日围栏车辆
|
||||
$line_info = Db::name('vehicle_line')->whereTime('create_time','d')->where('is_del',1)->select();
|
||||
if ($line_info){
|
||||
$processedCount = 0;
|
||||
$inParkCount = 0; // 在园区内的车辆数
|
||||
$outParkCount = 0; // 在园区外的车辆数
|
||||
|
||||
foreach ($line_info as $k => $v){
|
||||
//当日车辆坐标集
|
||||
$vehicle_coordinate = json_decode($v['line'],true);
|
||||
if (!is_array($vehicle_coordinate) || empty($vehicle_coordinate)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 遍历每个坐标点,判断进出状态
|
||||
foreach ($vehicle_coordinate as $o => $i) {
|
||||
if (empty($i['coordinate'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$vehicle_arr = explode(',', $i['coordinate']);
|
||||
if (count($vehicle_arr) < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$point = [
|
||||
'lng' => floatval($vehicle_arr[0]),
|
||||
'lat' => floatval($vehicle_arr[1]),
|
||||
];
|
||||
|
||||
// 判断当前点是否在园区内
|
||||
$vehicle_exist = $this->is_point_in_polygon($point, $max_path_arr);
|
||||
|
||||
if ($vehicle_exist) {
|
||||
$inParkCount++;
|
||||
} else {
|
||||
$outParkCount++;
|
||||
}
|
||||
|
||||
// 判断上一个点是否在园区内
|
||||
$up_exist = false;
|
||||
if ($o > 0 && isset($vehicle_coordinate[$o-1]['coordinate'])) {
|
||||
$up_arr = explode(',', $vehicle_coordinate[$o-1]['coordinate']);
|
||||
if (count($up_arr) >= 2) {
|
||||
$up_point = [
|
||||
'lng' => floatval($up_arr[0]),
|
||||
'lat' => floatval($up_arr[1]),
|
||||
];
|
||||
$up_exist = $this->is_point_in_polygon($up_point, $max_path_arr);
|
||||
}
|
||||
}
|
||||
|
||||
// 检查该车辆今天是否已有进出记录
|
||||
$hasEnterLog = Db::name('vehicle_park_line_log')
|
||||
->where('vehicleNo', $v['vehicleNo'])
|
||||
->where('type', 1)
|
||||
->whereTime('create_time', 'd')
|
||||
->where('is_del', 'in', '1,2')
|
||||
->count();
|
||||
|
||||
$hasOutLog = Db::name('vehicle_park_line_log')
|
||||
->where('vehicleNo', $v['vehicleNo'])
|
||||
->where('type', 2)
|
||||
->whereTime('create_time', 'd')
|
||||
->where('is_del', 'in', '1,2')
|
||||
->count();
|
||||
|
||||
// 判断是否发生进出变化
|
||||
if ($vehicle_exist && !$up_exist) {
|
||||
// 从园区外进入园区内 - 进园
|
||||
// 如果是第一个点且在园区内,也记录为进园(假设是从园区外进入的)
|
||||
// 或者如果状态是2但没有记录,说明之前处理失败,重新处理
|
||||
$shouldProcess = false;
|
||||
if ($o == 0) {
|
||||
// 第一个点且在园区内
|
||||
$shouldProcess = true;
|
||||
} elseif (isset($vehicle_coordinate[$o-1]['max_enter_status'])) {
|
||||
if ($vehicle_coordinate[$o-1]['max_enter_status'] == 1) {
|
||||
// 状态为1,正常处理
|
||||
$shouldProcess = true;
|
||||
} elseif ($vehicle_coordinate[$o-1]['max_enter_status'] == 2 && !$hasEnterLog) {
|
||||
// 状态为2但没有记录,说明之前处理失败,重新处理
|
||||
$shouldProcess = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($shouldProcess && !$hasEnterLog) {
|
||||
$up_coord = $o > 0 ? $vehicle_coordinate[$o-1]['coordinate'] : '初始位置';
|
||||
|
||||
$vehicle_log_arr = [
|
||||
'vehicleNo' => $v['vehicleNo'],
|
||||
'up_coordinate' => $up_coord,
|
||||
'coordinate' => $i['coordinate'],
|
||||
'type' => 1, // 进园
|
||||
'create_time' => isset($i['create_time']) ? $i['create_time'] : date('Y-m-d H:i:s'),
|
||||
'is_del' => 1,
|
||||
];
|
||||
try {
|
||||
Db::name('vehicle_park_line_log')->insert($vehicle_log_arr);
|
||||
if ($o > 0) {
|
||||
$vehicle_coordinate[$o-1]['max_enter_status'] = 2;
|
||||
}
|
||||
$processedCount++;
|
||||
} catch (\Exception $e) {
|
||||
// 插入失败,记录错误但继续处理
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} elseif (!$vehicle_exist && $up_exist && $o > 0) {
|
||||
// 从园区内离开到园区外 - 出园
|
||||
// 检查该车辆今天是否已有出园记录(避免重复记录)
|
||||
// 注意:这里允许同一车辆多次出园,只要不是同一个轨迹点重复记录
|
||||
$shouldProcess = false;
|
||||
if (isset($vehicle_coordinate[$o-1]['max_out_status'])) {
|
||||
if ($vehicle_coordinate[$o-1]['max_out_status'] == 1) {
|
||||
// 状态为1,正常处理
|
||||
$shouldProcess = true;
|
||||
} elseif ($vehicle_coordinate[$o-1]['max_out_status'] == 2 && !$hasOutLog) {
|
||||
// 状态为2但没有记录,说明之前处理失败,重新处理
|
||||
$shouldProcess = true;
|
||||
}
|
||||
} else {
|
||||
// 如果没有设置状态,默认可以处理
|
||||
$shouldProcess = true;
|
||||
}
|
||||
|
||||
if ($shouldProcess) {
|
||||
$up_coord = $vehicle_coordinate[$o-1]['coordinate'];
|
||||
|
||||
// 检查是否已记录过这个出园点(避免重复)
|
||||
$existingOutLog = Db::name('vehicle_park_line_log')
|
||||
->where('vehicleNo', $v['vehicleNo'])
|
||||
->where('type', 2)
|
||||
->where('up_coordinate', $up_coord)
|
||||
->where('coordinate', $i['coordinate'])
|
||||
->whereTime('create_time', 'd')
|
||||
->where('is_del', 'in', '1,2')
|
||||
->find();
|
||||
|
||||
if (!$existingOutLog) {
|
||||
$vehicle_log_arr = [
|
||||
'vehicleNo' => $v['vehicleNo'],
|
||||
'up_coordinate' => $up_coord,
|
||||
'coordinate' => $i['coordinate'],
|
||||
'type' => 2, // 出园
|
||||
'create_time' => isset($i['create_time']) ? $i['create_time'] : date('Y-m-d H:i:s'),
|
||||
'is_del' => 1,
|
||||
];
|
||||
try {
|
||||
Db::name('vehicle_park_line_log')->insert($vehicle_log_arr);
|
||||
$vehicle_coordinate[$o-1]['max_out_status'] = 2;
|
||||
$processedCount++;
|
||||
} catch (\Exception $e) {
|
||||
// 插入失败,记录错误但继续处理
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新当前点的状态
|
||||
if ($vehicle_exist) {
|
||||
if (!isset($vehicle_coordinate[$o]['max_enter_status']) || $vehicle_coordinate[$o]['max_enter_status'] == 1) {
|
||||
$vehicle_coordinate[$o]['max_enter_status'] = 2;
|
||||
}
|
||||
} else {
|
||||
if (!isset($vehicle_coordinate[$o]['max_out_status']) || $vehicle_coordinate[$o]['max_out_status'] == 1) {
|
||||
$vehicle_coordinate[$o]['max_out_status'] = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新轨迹数据
|
||||
Db::name('vehicle_line')
|
||||
->where('id', $v['id'])
|
||||
->update(['line' => json_encode($vehicle_coordinate)]);
|
||||
}
|
||||
|
||||
$result = [
|
||||
'processed_count' => $processedCount,
|
||||
'in_park_count' => $inParkCount,
|
||||
'out_park_count' => $outParkCount,
|
||||
'total_vehicles' => count($line_info)
|
||||
];
|
||||
$this->success('更新成功,处理了' . $processedCount . '条进出记录,时间:'.date("Y-m-d H:i:s"), $result);
|
||||
}else{
|
||||
$this->success('当天无车辆记录', ['processed_count' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//定时记录企业围栏进出日志(暂未用)
|
||||
public function enclosure_log(){
|
||||
//企业区域围栏
|
||||
$enterprise_region = Db::name('perimeter')->where(['region_type'=>6,'is_del'=>1])->whereNotNull('info')->field('id,name,info')->select();
|
||||
|
||||
//当日围栏车辆
|
||||
$line_info = Db::name('vehicle_line')->whereTime('create_time','d')->where('is_del',1)->select();
|
||||
if ($line_info){
|
||||
foreach ($line_info as $k => $v){
|
||||
//当日车辆坐标集
|
||||
$vehicle_coordinate = json_decode($v['line'],true);
|
||||
foreach ($vehicle_coordinate as $o => $i) {
|
||||
$vehicle_arr = explode(',', $i['coordinate']);
|
||||
$point = [
|
||||
'lng' => $vehicle_arr[0],
|
||||
'lat' => $vehicle_arr[1],
|
||||
];
|
||||
foreach ($enterprise_region as $key => $value){
|
||||
$arr = [];
|
||||
if (!empty($value['info'])){
|
||||
$region_arr = explode(';',$value['info']);
|
||||
foreach ($region_arr as $regionK => $regionV){
|
||||
$ar = explode(',',$regionV);
|
||||
$arr[] = [
|
||||
'lng' => $ar[0],
|
||||
'lat' => $ar[1],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$is_exist = $this->is_point_in_polygon($point,$arr);
|
||||
if ($is_exist){
|
||||
//TODO 是否是首个下标(是则直接为进入处理)
|
||||
if ($o == 0){
|
||||
//是否处理(如last_coordinate_status为2则当前坐标已处理)
|
||||
if ($vehicle_coordinate[$o]['last_coordinate_status'] == 1){
|
||||
$vehicle_log_arr = [
|
||||
'vehicleNo' => $v['vehicleNo'],
|
||||
'up_coordinate' => '初始值',
|
||||
'coordinate' => $vehicle_coordinate[$o]['coordinate'],
|
||||
'perimeter_id' => $value['id'],
|
||||
'type' => 1,//入园
|
||||
'create_time' =>$i['create_time'],
|
||||
];
|
||||
//新增进入日志
|
||||
Db::name('vehicle_line_log')->insert($vehicle_log_arr);
|
||||
//更新当前坐标状态
|
||||
$vehicle_coordinate[$o]['last_coordinate_status'] = 2;
|
||||
Db::name('vehicle_line')->where('vehicleNo',$v['vehicleNo'])->whereTime('create_time','d')->update(['line'=>json_encode($vehicle_coordinate)]);
|
||||
}
|
||||
}else{
|
||||
if ($vehicle_coordinate[$o-1]['last_coordinate_status'] == 1){
|
||||
$up_arr = explode(',',$vehicle_coordinate[$o-1]['coordinate']);
|
||||
$up_point = [
|
||||
'lng' => $up_arr[0],
|
||||
'lat' => $up_arr[1],
|
||||
];
|
||||
$up_exist = $this->is_point_in_polygon($up_point,$arr);
|
||||
if ($up_exist){
|
||||
//更新当前坐标状态
|
||||
$vehicle_coordinate[$o]['last_coordinate_status'] = 2;
|
||||
Db::name('vehicle_line')->where('vehicleNo',$v['vehicleNo'])->whereTime('create_time','d')->update(['line'=>json_encode($vehicle_coordinate)]);
|
||||
}else{
|
||||
$vehicle_log_arr = [
|
||||
'vehicleNo' => $v['vehicleNo'],
|
||||
'up_coordinate' => $up_arr[0].','.$up_arr[1],
|
||||
'coordinate' => $i['coordinate'],
|
||||
'perimeter_id' => $value['id'],
|
||||
'type' => 1,//入园
|
||||
'create_time' => $i['create_time'],
|
||||
];
|
||||
//新增进入日志
|
||||
Db::name('vehicle_line_log')->insert($vehicle_log_arr);
|
||||
//更新上一个坐标状态
|
||||
$vehicle_coordinate[$o-1]['last_coordinate_status'] = 2;
|
||||
Db::name('vehicle_line')->where('vehicleNo',$v['vehicleNo'])->whereTime('create_time','d')->update(['line'=>json_encode($vehicle_coordinate)]);
|
||||
}
|
||||
}
|
||||
}//入园流程处理
|
||||
}
|
||||
|
||||
//TODO 是否超出最后一个坐标
|
||||
if ($o+1 != count($vehicle_coordinate)){
|
||||
if ($vehicle_coordinate[$o+1]['next_coordinate_status'] == 1){
|
||||
//当前坐标点(下标+1)
|
||||
$_arr = explode(',',$vehicle_coordinate[$o+1]['coordinate']);
|
||||
$_point = [
|
||||
'lng' => $_arr[0],
|
||||
'lat' => $_arr[1],
|
||||
];
|
||||
$_exist = $this->is_point_in_polygon($_point,$arr);
|
||||
if (!$_exist){
|
||||
//上个坐标点位置
|
||||
$up_arr = explode(',',$vehicle_coordinate[$o]['coordinate']);
|
||||
$up_point = [
|
||||
'lng' => $up_arr[0],
|
||||
'lat' => $up_arr[1],
|
||||
];
|
||||
$up_exist = $this->is_point_in_polygon($up_point,$arr);
|
||||
if ($up_exist){
|
||||
$vehicle_log_arr = [
|
||||
'vehicleNo' => $v['vehicleNo'],
|
||||
'up_coordinate' => $up_arr[0].','.$up_arr[1],
|
||||
'coordinate' => $_arr[0].','.$_arr[1],
|
||||
'perimeter_id' => $value['id'],
|
||||
'type' => 2,//出园
|
||||
'create_time' =>$i['create_time'],
|
||||
];
|
||||
//新增出去日志
|
||||
Db::name('vehicle_line_log')->insert($vehicle_log_arr);
|
||||
//更新下一个坐标状态
|
||||
$vehicle_coordinate[$o+1]['next_coordinate_status'] = 2;
|
||||
Db::name('vehicle_line')->where('vehicleNo',$v['vehicleNo'])->whereTime('create_time','d')->update(['line'=>json_encode($vehicle_coordinate)]);
|
||||
//消除车辆
|
||||
Db::name('vehicle')->where('vehicleNo',$v['vehicleNo'])->update(['is_del'=>3]);
|
||||
}
|
||||
}
|
||||
|
||||
}//出去流程处理
|
||||
|
||||
}//出园入园流程处理
|
||||
}//企业围栏判断
|
||||
}//车辆列表判断
|
||||
|
||||
|
||||
}
|
||||
$this->pre('更新成功,时间:'.date("Y-m-d H:i:s"));
|
||||
}else{
|
||||
$this->pre('当天无车辆记录,更新失败,时间:'.date("Y-m-d H:i:s"));
|
||||
}
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
//定时更新车辆二维码状态
|
||||
public function update_vehicle_code(){
|
||||
$map['is_del'] = array('in','1,2');
|
||||
$vehicle_list = Db::name($this->api_vehicle)->where($map)->field('vehicleNo,qr_color')->select();
|
||||
foreach ($vehicle_list as $k => $v){
|
||||
$police_where['license'] = $v['vehicleNo'];
|
||||
$police_where['is_reset'] = 0;
|
||||
$police_where['type'] = array('in','1,2,3,4,5,6');
|
||||
$count = Db::name($this->api_call_the_police)->where($police_where)->count();
|
||||
if ($count >= 2){
|
||||
if ($v['qr_color'] != 3){
|
||||
if ($v['qr_color'] == 1){
|
||||
$name = '将绿码更新为红码';
|
||||
}elseif ($v['qr_color'] == 2){
|
||||
$name = '将黄码更新为红码';
|
||||
}
|
||||
$code_arr = [
|
||||
'os_type' => 'web',
|
||||
'os_record' => $name,
|
||||
'os_time' => date('Y-m-d H:i:s'),
|
||||
'os_vehicleNo' => $v['vehicleNo'],
|
||||
];
|
||||
Db::name('qrrecord')->insert($code_arr);
|
||||
Db::name($this->api_vehicle)->where('vehicleNo',$v['vehicleNo'])->update(['qr_color'=>3]);
|
||||
}
|
||||
}else{
|
||||
if ($v['qr_color'] == 2){
|
||||
$waybill_id = Db::name($this->api_waybill)->where('tow_license',$v['vehicleNo'])->whereTime('waybill_date','d')->value('id');
|
||||
$apply_time = Db::name($this->api_apply)->whereTime('apply_time','d')->where(['tractor_license'=>$v['vehicleNo'],'status'=>1,'mission'=>1])->order('id desc')->value('apply_time');//是否存在装/卸货入园申请(当天内有效)
|
||||
$apply_arr['tractor_license'] = $v['vehicleNo'];
|
||||
$apply_arr['status'] = 1;
|
||||
$apply_arr['mission'] = array('in',[2,5,6,7,8]);
|
||||
$apply_clean_apply_time = Db::name($this->api_apply)->where($apply_arr)->order('id desc')->value('apply_time');//是否存在清洗/维修入园申请(3天内有效)
|
||||
$apply_permanent_apply_time = Db::name($this->api_apply)->where(['tractor_license'=>$v['vehicleNo'],'status'=>1,'mission'=>3])->order('id desc')->value('apply_time');//是否存在清洗/维修入园申请(7天内有效)
|
||||
$name = '';
|
||||
if ($waybill_id || $apply_time){
|
||||
$name = '将黄码更新为绿码';
|
||||
}else{
|
||||
if (time() < strtotime($apply_clean_apply_time)){
|
||||
$name = '将黄码更新为绿码';
|
||||
}
|
||||
if (time() < strtotime($apply_permanent_apply_time)){
|
||||
$name = '将黄码更新为绿码';
|
||||
}
|
||||
}
|
||||
if ($name){
|
||||
$code_arr = [
|
||||
'os_type' => 'web',
|
||||
'os_record' => $name,
|
||||
'os_time' => date('Y-m-d H:i:s'),
|
||||
'os_vehicleNo' => $v['vehicleNo'],
|
||||
];
|
||||
Db::name('qrrecord')->insert($code_arr);
|
||||
Db::name($this->api_vehicle)->where('vehicleNo',$v['vehicleNo'])->update(['qr_color'=>1]);
|
||||
}
|
||||
}else{
|
||||
$waybill_id = Db::name($this->api_waybill)->where('tow_license',$v['vehicleNo'])->whereTime('waybill_date','d')->value('id');
|
||||
$apply_time = Db::name($this->api_apply)->whereTime('apply_time','d')->where(['tractor_license'=>$v['vehicleNo'],'status'=>1,'mission'=>1])->order('id desc')->value('apply_time');//是否存在装/卸货入园申请(当天内有效)
|
||||
$apply_arr['tractor_license'] = $v['vehicleNo'];
|
||||
$apply_arr['status'] = 1;
|
||||
$apply_arr['mission'] = array('in',[2,5,6,7,8]);
|
||||
$apply_clean_apply_time = Db::name($this->api_apply)->where($apply_arr)->order('id desc')->value('apply_time');//是否存在清洗/维修入园申请(3天内有效)
|
||||
$apply_permanent_apply_time = Db::name($this->api_apply)->where(['tractor_license'=>$v['vehicleNo'],'status'=>1,'mission'=>3])->order('id desc')->value('apply_time');//是否存在清洗/维修入园申请(3天内有效)
|
||||
|
||||
if (time() > strtotime($apply_clean_apply_time)){
|
||||
$apply_clean_apply_time = '';
|
||||
}
|
||||
if (time() > strtotime($apply_permanent_apply_time)){
|
||||
$apply_permanent_apply_time = '';
|
||||
}
|
||||
if (!$waybill_id && !$apply_time && !$apply_clean_apply_time && !$apply_permanent_apply_time){
|
||||
$code_arr = [
|
||||
'os_type' => 'web',
|
||||
'os_record' => '将绿码更新为黄码',
|
||||
'os_time' => date('Y-m-d H:i:s'),
|
||||
'os_vehicleNo' => $v['vehicleNo'],
|
||||
];
|
||||
Db::name('qrrecord')->insert($code_arr);
|
||||
Db::name($this->api_vehicle)->where('vehicleNo',$v['vehicleNo'])->update(['qr_color'=>2]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$this->pre('操作成功!');
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
//定时更新车辆二维码状态(隐藏车辆)
|
||||
public function update_vehicle_code_hide(){
|
||||
$map['is_del'] = array('in','3');
|
||||
$vehicle_list = Db::name($this->api_vehicle)->where($map)->field('vehicleNo,qr_color')->select();
|
||||
foreach ($vehicle_list as $k => $v){
|
||||
$count = Db::name($this->api_call_the_police)->where(['license'=>$v['vehicleNo'],'is_reset'=>0])->count();
|
||||
if ($count >= 5){
|
||||
if ($v['qr_color'] != 3){
|
||||
if ($v['qr_color'] == 1){
|
||||
$name = '将绿码更新为红码';
|
||||
}elseif ($v['qr_color'] == 2){
|
||||
$name = '将黄码更新为红码';
|
||||
}
|
||||
$code_arr = [
|
||||
'os_type' => 'web',
|
||||
'os_record' => $name,
|
||||
'os_time' => date('Y-m-d H:i:s'),
|
||||
'os_vehicleNo' => $v['vehicleNo'],
|
||||
];
|
||||
Db::name('qrrecord')->insert($code_arr);
|
||||
Db::name($this->api_vehicle)->where('vehicleNo',$v['vehicleNo'])->update(['qr_color'=>3]);
|
||||
}
|
||||
}else{
|
||||
if ($v['qr_color'] == 2){
|
||||
$waybill_id = Db::name($this->api_waybill)->where('tow_license',$v['vehicleNo'])->whereTime('waybill_date','d')->value('id');
|
||||
$apply_time = Db::name($this->api_apply)->whereTime('apply_time','d')->where(['tractor_license'=>$v['vehicleNo'],'status'=>1,'mission'=>1])->order('id desc')->value('apply_time');//是否存在装/卸货入园申请(当天内有效)
|
||||
$apply_arr['tractor_license'] = $v['vehicleNo'];
|
||||
$apply_arr['status'] = 1;
|
||||
$apply_arr['mission'] = array('in',[2,5,6,7,8]);
|
||||
$apply_clean_apply_time = Db::name($this->api_apply)->where($apply_arr)->order('id desc')->value('apply_time');//是否存在清洗/维修入园申请(3天内有效)
|
||||
$apply_permanent_apply_time = Db::name($this->api_apply)->where(['tractor_license'=>$v['vehicleNo'],'status'=>1,'mission'=>3])->order('id desc')->value('apply_time');//是否存在清洗/维修入园申请(7天内有效)
|
||||
$name = '';
|
||||
if ($waybill_id || $apply_time){
|
||||
$name = '将黄码更新为绿码';
|
||||
}else{
|
||||
if (time() < strtotime($apply_clean_apply_time)){
|
||||
$name = '将黄码更新为绿码';
|
||||
}
|
||||
if (time() < strtotime($apply_permanent_apply_time)){
|
||||
$name = '将黄码更新为绿码';
|
||||
}
|
||||
}
|
||||
if ($name){
|
||||
$code_arr = [
|
||||
'os_type' => 'web',
|
||||
'os_record' => $name,
|
||||
'os_time' => date('Y-m-d H:i:s'),
|
||||
'os_vehicleNo' => $v['vehicleNo'],
|
||||
];
|
||||
Db::name('qrrecord')->insert($code_arr);
|
||||
Db::name($this->api_vehicle)->where('vehicleNo',$v['vehicleNo'])->update(['qr_color'=>1]);
|
||||
}
|
||||
}else{
|
||||
$waybill_id = Db::name($this->api_waybill)->where('tow_license',$v['vehicleNo'])->whereTime('waybill_date','d')->value('id');
|
||||
$apply_time = Db::name($this->api_apply)->whereTime('apply_time','d')->where(['tractor_license'=>$v['vehicleNo'],'status'=>1,'mission'=>1])->order('id desc')->value('apply_time');//是否存在装/卸货入园申请(当天内有效)
|
||||
$apply_arr['tractor_license'] = $v['vehicleNo'];
|
||||
$apply_arr['status'] = 1;
|
||||
$apply_arr['mission'] = array('in',[2,5,6,7,8]);
|
||||
$apply_clean_apply_time = Db::name($this->api_apply)->where($apply_arr)->order('id desc')->value('apply_time');//是否存在清洗/维修入园申请(3天内有效)
|
||||
$apply_permanent_apply_time = Db::name($this->api_apply)->where(['tractor_license'=>$v['vehicleNo'],'status'=>1,'mission'=>3])->order('id desc')->value('apply_time');//是否存在清洗/维修入园申请(3天内有效)
|
||||
if (time() > strtotime($apply_clean_apply_time)){
|
||||
$apply_clean_apply_time = '';
|
||||
}
|
||||
if (time() > strtotime($apply_permanent_apply_time)){
|
||||
$apply_permanent_apply_time = '';
|
||||
}
|
||||
if (!$waybill_id && !$apply_time && !$apply_clean_apply_time && !$apply_permanent_apply_time){
|
||||
$code_arr = [
|
||||
'os_type' => 'web',
|
||||
'os_record' => '将绿码更新为黄码',
|
||||
'os_time' => date('Y-m-d H:i:s'),
|
||||
'os_vehicleNo' => $v['vehicleNo'],
|
||||
];
|
||||
Db::name('qrrecord')->insert($code_arr);
|
||||
Db::name($this->api_vehicle)->where('vehicleNo',$v['vehicleNo'])->update(['qr_color'=>2]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$this->pre('操作成功!');
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
//定时更新高速路段车辆信息(清除2)
|
||||
public function update_high_speed(){
|
||||
$map['is_del'] = array('in','1,2');
|
||||
$vehicle_list = Db::name('vehicle')->where($map)->field('vehicleNo,longitude,latitude')->select();
|
||||
//高速坐标集(右边)
|
||||
$right_path = '107.031761,29.822778;107.032247,29.822289;107.035775,29.824699;107.036981,29.825839;107.038996,29.827026;107.040038,29.826995;107.040828,29.827026;107.041439,29.827450;107.041368,29.828358;107.041081,29.828593;107.044727,29.830701;107.044834,29.829636;107.045174,29.828416;107.045927,29.827432;107.047128,29.826749;107.048114,29.826443;107.049154,29.826168;107.049405,29.826906;107.047290,29.827440;107.046340,29.828092;107.045677,29.829421;107.045606,29.830893;107.048297,29.830800;107.050789,29.830694;107.053082,29.831045;107.054874,29.832053;107.055340,29.832638;107.054821,29.833086;107.053980,29.832309;107.052993,29.831766;107.051112,29.831402;107.048513,29.831475;107.046289,29.831555;107.045661,29.831474;107.045501,29.832382;107.046506,29.833060;107.046632,29.833797;107.046219,29.834422;107.045036,29.834948;107.043926,29.838344;107.044159,29.839598;107.044519,29.840727;107.045991,29.841564;107.049058,29.842022;107.051961,29.842565;107.053233,29.843189;107.053591,29.843568;107.052947,29.844188;107.052087,29.843333;107.049936,29.842766;107.047103,29.842322;107.045058,29.841827;107.044645,29.841558;107.044196,29.841227;107.043388,29.840018;107.043208,29.838812;107.043405,29.838029;107.044192,29.835008;107.044479,29.833803;107.044317,29.833050;107.044011,29.832610;107.043508,29.832123;107.042826,29.831792;107.041927,29.831477;107.041047,29.831053;107.040472,29.830677;107.039914,29.830097;107.039734,29.828968;107.039518,29.828389;107.038888,29.827716;107.035489,29.825343;107.032643,29.823352;107.031761,29.822794';
|
||||
//高速坐标集(左边)
|
||||
$left_path = '106.951213,29.776296;106.951678,29.776187;106.951874,29.777295;106.952490,29.779036;106.953258,29.780960;106.954357,29.782953;106.955402,29.784420;106.956690,29.786094;106.958443,29.787884;106.959668,29.788725;106.961234,29.789273;106.962604,29.790278;106.962872,29.792069;106.963114,29.793090;106.963750,29.794078;106.963123,29.794383;106.962290,29.793385;106.960805,29.792009;106.959614,29.790879;106.956913,29.789733;106.956600,29.789038;106.956762,29.786871;106.955322,29.785163;106.954661,29.784259;106.953517,29.782406;106.952766,29.780898;106.951864,29.778610;106.951204,29.776296';
|
||||
foreach ($vehicle_list as $k => $v) {
|
||||
$point = [
|
||||
'lng' => $v['longitude'],
|
||||
'lat' => $v['latitude'],
|
||||
];
|
||||
$right_high_speed = explode(';',$right_path);
|
||||
$right_high_speed_arr = [];
|
||||
foreach ($right_high_speed as $rK => $rV) {
|
||||
$arr = explode(',', $rV);
|
||||
$right_high_speed_arr[] = [
|
||||
'lng' => $arr[0],
|
||||
'lat' => $arr[1],
|
||||
];
|
||||
}
|
||||
$r_exist = $this->is_point_in_polygon($point,$right_high_speed_arr);
|
||||
|
||||
$left_high_speed = explode(';',$left_path);
|
||||
$left_high_speed_arr = [];
|
||||
foreach ($left_high_speed as $rK => $rV) {
|
||||
$arr = explode(',', $rV);
|
||||
$left_high_speed_arr[] = [
|
||||
'lng' => $arr[0],
|
||||
'lat' => $arr[1],
|
||||
];
|
||||
}
|
||||
$l_exist = $this->is_point_in_polygon($point,$left_high_speed_arr);
|
||||
if ($r_exist || $l_exist){
|
||||
Db::name('vehicle')->where('vehicleNo',$v['vehicleNo'])->update(['is_del'=>3]);
|
||||
}
|
||||
}
|
||||
$this->pre('操作成功!');
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//经开区大围栏坐标集
|
||||
public function submit_test_paper(){
|
||||
$str = '(107.012211,29.812966)
|
||||
(107.012211,29.811595)
|
||||
(107.012242,29.811529)
|
||||
(107.012278,29.811497)
|
||||
(107.01235,29.811474)
|
||||
(107.012481,29.811466)
|
||||
(107.012602,29.811462)
|
||||
(107.012723,29.811466)
|
||||
(107.01447,29.81147)
|
||||
(107.014529,29.81147)
|
||||
(107.014623,29.811501)
|
||||
(107.014663,29.811525)
|
||||
(107.014722,29.811572)
|
||||
(107.014767,29.811627)
|
||||
(107.014798,29.811662)
|
||||
(107.014857,29.8129)
|
||||
(107.014857,29.812919)
|
||||
(107.014825,29.812939)
|
||||
(107.014785,29.812947)
|
||||
(107.012287,29.812959)
|
||||
(107.012216,29.812966)
|
||||
';
|
||||
$str = str_replace('(','',$str);
|
||||
$str = str_replace(')','',$str);
|
||||
$result = array(); // 转换后的结果
|
||||
$tokens = preg_split('/[\r\n]+/', $str);
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
if (false !== strpos($token, '=')) {
|
||||
list($key, $value) = explode('=', $token, 2);
|
||||
$result[$key] = $value;
|
||||
} else
|
||||
$result[] = $token;
|
||||
}
|
||||
//
|
||||
$path = '';
|
||||
foreach ($result as $k => $v){
|
||||
if ($v){
|
||||
$Varr = explode(',',$v);
|
||||
$res = $this->bd_decrypt($Varr[0],$Varr[1]);
|
||||
$url = number_format($res['gg_lon'],6).','.number_format($res['gg_lat'],6);
|
||||
$path .= $url.';';
|
||||
// $this->pre($res);die;
|
||||
// $path += $url.';';
|
||||
}
|
||||
}
|
||||
$path_arr = explode(';',$path);
|
||||
$this->pre($path);die;
|
||||
foreach ($path_arr as $k => $v){
|
||||
// $this->pre($v);
|
||||
$aa['content'] = $v;
|
||||
// $this->pre($aa);
|
||||
// Db::name('abc')->insert($aa);
|
||||
}
|
||||
$this->pre(123);
|
||||
die;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//BD-09(百度) 坐标转换成 GCJ-02(火星,高德) 坐标
|
||||
//@param bd_lon 百度经度
|
||||
//@param bd_lat 百度纬度
|
||||
public function bd_decrypt($bd_lon,$bd_lat)
|
||||
{
|
||||
$x_pi = 3.14159265358979324 * 3000.0 / 180.0;
|
||||
$x = $bd_lon - 0.0065;
|
||||
$y = $bd_lat - 0.006;
|
||||
$z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
|
||||
$theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
|
||||
$data['gg_lon'] = $z * cos($theta);
|
||||
$data['gg_lat'] = $z * sin($theta);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function sss(){
|
||||
$start = date('Y-m-01',strtotime('-1 month'));
|
||||
$end = date('Y-m-t',strtotime('-1 month'));
|
||||
$arrdateone = $start;
|
||||
$arrdatetwo = $end.' 23:59:59';
|
||||
$map['create_time'] = array(array('egt',$arrdateone),array('elt',$arrdatetwo),'AND');
|
||||
$map['is_del'] = array('neq', -1);
|
||||
$count = Db::name($this->api_call_the_police)->where($map)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断一个坐标是否在一个多边形内(由多个坐标围成的)
|
||||
* 基本思想是利用射线法,计算射线与多边形各边的交点,如果是偶数,则点在多边形外,否则在多边形内
|
||||
* @param $point //指定点坐标
|
||||
* @param $pts //多边形坐标,顺时针方向
|
||||
* @return bool
|
||||
*/
|
||||
public function is_point_in_polygon($point, $pts) {
|
||||
$N = count($pts);
|
||||
$boundOrVertex = true; //如果点位于多边形的顶点或边上,也算做点在多边形内,直接返回true
|
||||
$intersectCount = 0;//cross points count of x
|
||||
$precision = 2e-10; //浮点类型计算时候与0比较时候的容差
|
||||
$p1 = 0;//neighbour bound vertices
|
||||
$p2 = 0;
|
||||
$p = $point; //测试点
|
||||
|
||||
$p1 = $pts[0];//left vertex
|
||||
for ($i = 1; $i <= $N; ++$i) {//check all rays
|
||||
if ($p['lng'] == $p1['lng'] && $p['lat'] == $p1['lat']) {
|
||||
return $boundOrVertex;//p is an vertex
|
||||
}
|
||||
|
||||
$p2 = $pts[$i % $N];//right vertex
|
||||
if ($p['lat'] < min($p1['lat'], $p2['lat']) || $p['lat'] > max($p1['lat'], $p2['lat'])) {//ray is outside of our interests
|
||||
$p1 = $p2;
|
||||
continue;//next ray left point
|
||||
}
|
||||
|
||||
if ($p['lat'] > min($p1['lat'], $p2['lat']) && $p['lat'] < max($p1['lat'], $p2['lat'])) {//ray is crossing over by the algorithm (common part of)
|
||||
if($p['lng'] <= max($p1['lng'], $p2['lng'])){//x is before of ray
|
||||
if ($p1['lat'] == $p2['lat'] && $p['lng'] >= min($p1['lng'], $p2['lng'])) {//overlies on a horizontal ray
|
||||
return $boundOrVertex;
|
||||
}
|
||||
|
||||
if ($p1['lng'] == $p2['lng']) {//ray is vertical
|
||||
if ($p1['lng'] == $p['lng']) {//overlies on a vertical ray
|
||||
return $boundOrVertex;
|
||||
} else {//before ray
|
||||
++$intersectCount;
|
||||
}
|
||||
} else {//cross point on the left side
|
||||
$xinters = ($p['lat'] - $p1['lat']) * ($p2['lng'] - $p1['lng']) / ($p2['lat'] - $p1['lat']) + $p1['lng'];//cross point of lng
|
||||
if (abs($p['lng'] - $xinters) < $precision) {//overlies on a ray
|
||||
return $boundOrVertex;
|
||||
}
|
||||
|
||||
if ($p['lng'] < $xinters) {//before ray
|
||||
++$intersectCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {//special case when ray is crossing through the vertex
|
||||
if ($p['lat'] == $p2['lat'] && $p['lng'] <= $p2['lng']) {//p crossing over p2
|
||||
$p3 = $pts[($i+1) % $N]; //next vertex
|
||||
if ($p['lat'] >= min($p1['lat'], $p3['lat']) && $p['lat'] <= max($p1['lat'], $p3['lat'])) { //p.lat lies between p1.lat & p3.lat
|
||||
++$intersectCount;
|
||||
} else {
|
||||
$intersectCount += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$p1 = $p2;//next ray left point
|
||||
}
|
||||
|
||||
if ($intersectCount % 2 == 0) {//偶数在多边形外
|
||||
return false;
|
||||
} else { //奇数在多边形内
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
102
application/api/lang/zh-cn.php
Normal file
102
application/api/lang/zh-cn.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'Keep login' => '保持会话',
|
||||
'Username' => '用户名',
|
||||
'User id' => '会员ID',
|
||||
'Nickname' => '昵称',
|
||||
'Password' => '密码',
|
||||
'Sign up' => '注 册',
|
||||
'Sign in' => '登 录',
|
||||
'Sign out' => '退 出',
|
||||
'Guest' => '游客',
|
||||
'Welcome' => '%s,你好!',
|
||||
'Add' => '添加',
|
||||
'Edit' => '编辑',
|
||||
'Delete' => '删除',
|
||||
'Move' => '移动',
|
||||
'Name' => '名称',
|
||||
'Status' => '状态',
|
||||
'Weigh' => '权重',
|
||||
'Operate' => '操作',
|
||||
'Warning' => '温馨提示',
|
||||
'Default' => '默认',
|
||||
'Article' => '文章',
|
||||
'Page' => '单页',
|
||||
'OK' => '确定',
|
||||
'Cancel' => '取消',
|
||||
'Loading' => '加载中',
|
||||
'More' => '更多',
|
||||
'Normal' => '正常',
|
||||
'Hidden' => '隐藏',
|
||||
'Submit' => '提交',
|
||||
'Reset' => '重置',
|
||||
'Execute' => '执行',
|
||||
'Close' => '关闭',
|
||||
'Search' => '搜索',
|
||||
'Refresh' => '刷新',
|
||||
'First' => '首页',
|
||||
'Previous' => '上一页',
|
||||
'Next' => '下一页',
|
||||
'Last' => '末页',
|
||||
'None' => '无',
|
||||
'Home' => '主页',
|
||||
'Online' => '在线',
|
||||
'Logout' => '退出',
|
||||
'Profile' => '个人资料',
|
||||
'Index' => '首页',
|
||||
'Hot' => '热门',
|
||||
'Recommend' => '推荐',
|
||||
'Dashboard' => '控制台',
|
||||
'Code' => '编号',
|
||||
'Message' => '内容',
|
||||
'Line' => '行号',
|
||||
'File' => '文件',
|
||||
'Menu' => '菜单',
|
||||
'Type' => '类型',
|
||||
'Title' => '标题',
|
||||
'Content' => '内容',
|
||||
'Append' => '追加',
|
||||
'Memo' => '备注',
|
||||
'Parent' => '父级',
|
||||
'Params' => '参数',
|
||||
'Permission' => '权限',
|
||||
'Advance search' => '高级搜索',
|
||||
'Check all' => '选中全部',
|
||||
'Expand all' => '展开全部',
|
||||
'Begin time' => '开始时间',
|
||||
'End time' => '结束时间',
|
||||
'Create time' => '创建时间',
|
||||
'Flag' => '标志',
|
||||
'Please login first' => '请登录后操作',
|
||||
'Uploaded successful' => '上传成功',
|
||||
'You can upload up to %d file%s' => '你最多还可以上传%d个文件',
|
||||
'You can choose up to %d file%s' => '你最多还可以选择%d个文件',
|
||||
'Chunk file write error' => '分片写入失败',
|
||||
'Chunk file info error' => '分片文件错误',
|
||||
'Chunk file merge error' => '分片合并错误',
|
||||
'Chunk file disabled' => '未开启分片上传功能',
|
||||
'Cancel upload' => '取消上传',
|
||||
'Upload canceled' => '上传已取消',
|
||||
'No file upload or server upload limit exceeded' => '未上传文件或超出服务器上传限制',
|
||||
'Uploaded file format is limited' => '上传文件格式受限制',
|
||||
'Uploaded file is not a valid image' => '上传文件不是有效的图片文件',
|
||||
'Are you sure you want to cancel this upload?' => '确定取消上传?',
|
||||
'Remove file' => '移除文件',
|
||||
'You can only upload a maximum of %s files' => '你最多允许上传 %s 个文件',
|
||||
'You can\'t upload files of this type' => '不允许上传的文件类型',
|
||||
'Server responded with %s code' => '服务端响应(Code:%s)',
|
||||
'File is too big (%sMiB), Max filesize: %sMiB.' => '当前上传(%sM),最大允许上传文件大小:%sM',
|
||||
'Redirect now' => '立即跳转',
|
||||
'Operation completed' => '操作成功!',
|
||||
'Operation failed' => '操作失败!',
|
||||
'Unknown data format' => '未知的数据格式!',
|
||||
'Network error' => '网络错误!',
|
||||
'Advanced search' => '高级搜索',
|
||||
'Invalid parameters' => '未知参数',
|
||||
'No results were found' => '记录未找到',
|
||||
'Parameter %s can not be empty' => '参数%s不能为空',
|
||||
'You have no permission' => '你没有权限访问',
|
||||
'An unexpected error occurred' => '发生了一个意外错误,程序猿正在紧急处理中',
|
||||
'This page will be re-directed in %s seconds' => '页面将在 %s 秒后自动跳转',
|
||||
];
|
||||
3
application/api/lang/zh-cn/common.php
Normal file
3
application/api/lang/zh-cn/common.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
return [];
|
||||
39
application/api/lang/zh-cn/user.php
Normal file
39
application/api/lang/zh-cn/user.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'User center' => '会员中心',
|
||||
'Register' => '注册',
|
||||
'Login' => '登录',
|
||||
'Sign up successful' => '注册成功',
|
||||
'Username can not be empty' => '用户名不能为空',
|
||||
'Username must be 3 to 30 characters' => '用户名必须3-30个字符',
|
||||
'Username must be 6 to 30 characters' => '用户名必须6-30个字符',
|
||||
'Password can not be empty' => '密码不能为空',
|
||||
'Password must be 6 to 30 characters' => '密码必须6-30个字符',
|
||||
'Mobile is incorrect' => '手机格式不正确',
|
||||
'Username already exist' => '用户名已经存在',
|
||||
'Nickname already exist' => '昵称已经存在',
|
||||
'Email already exist' => '邮箱已经存在',
|
||||
'Mobile already exist' => '手机号已经存在',
|
||||
'Username is incorrect' => '用户名不正确',
|
||||
'Email is incorrect' => '邮箱不正确',
|
||||
'Account is locked' => '账户已经被锁定',
|
||||
'Password is incorrect' => '密码不正确',
|
||||
'Account is incorrect' => '账户不正确',
|
||||
'Account not exist' => '账户不存在',
|
||||
'Account can not be empty' => '账户不能为空',
|
||||
'Username or password is incorrect' => '用户名或密码不正确',
|
||||
'You are not logged in' => '你当前还未登录',
|
||||
'You\'ve logged in, do not login again' => '你已经存在,请不要重复登录',
|
||||
'Profile' => '个人资料',
|
||||
'Verify email' => '邮箱验证',
|
||||
'Change password' => '修改密码',
|
||||
'Captcha is incorrect' => '验证码不正确',
|
||||
'Logged in successful' => '登录成功',
|
||||
'Logout successful' => '退出成功',
|
||||
'Operation failed' => '操作失败',
|
||||
'Invalid parameters' => '参数不正确',
|
||||
'Change password failure' => '修改密码失败',
|
||||
'Change password successful' => '修改密码成功',
|
||||
'Reset password successful' => '重置密码成功',
|
||||
];
|
||||
37
application/api/library/ExceptionHandle.php
Normal file
37
application/api/library/ExceptionHandle.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\library;
|
||||
|
||||
use Exception;
|
||||
use think\exception\Handle;
|
||||
|
||||
/**
|
||||
* 自定义API模块的错误显示
|
||||
*/
|
||||
class ExceptionHandle extends Handle
|
||||
{
|
||||
|
||||
public function render(Exception $e)
|
||||
{
|
||||
// 在生产环境下返回code信息
|
||||
if (!\think\Config::get('app_debug')) {
|
||||
$statuscode = $code = 500;
|
||||
$msg = 'An error occurred';
|
||||
// 验证异常
|
||||
if ($e instanceof \think\exception\ValidateException) {
|
||||
$code = 0;
|
||||
$statuscode = 200;
|
||||
$msg = $e->getError();
|
||||
}
|
||||
// Http异常
|
||||
if ($e instanceof \think\exception\HttpException) {
|
||||
$statuscode = $code = $e->getStatusCode();
|
||||
}
|
||||
return json(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => null], $statuscode);
|
||||
}
|
||||
|
||||
//其它此交由系统处理
|
||||
return parent::render($e);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user