This commit is contained in:
unknown 2023-08-17 11:30:23 +08:00
parent e353925644
commit 528580cfd1
7 changed files with 405 additions and 9 deletions

View File

@ -0,0 +1,106 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\vehicle;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\vehicle\VehicleLists;
use app\adminapi\logic\vehicle\VehicleLogic;
use app\adminapi\validate\vehicle\VehicleValidate;
/**
* Vehicle控制器
* Class VehicleController
* @package app\adminapi\controller
*/
class VehicleController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function lists()
{
return $this->dataLists(new VehicleLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function add()
{
$params = (new VehicleValidate())->post()->goCheck('add');
$result = VehicleLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(VehicleLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function edit()
{
$params = (new VehicleValidate())->post()->goCheck('edit');
$result = VehicleLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(VehicleLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function delete()
{
$params = (new VehicleValidate())->post()->goCheck('delete');
VehicleLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function detail()
{
$params = (new VehicleValidate())->goCheck('detail');
$result = VehicleLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,76 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\vehicle;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\vehicle\Vehicle;
use app\common\lists\ListsSearchInterface;
/**
* Vehicle列表
* Class VehicleLists
* @package app\adminapi\lists
*/
class VehicleLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function setSearch(): array
{
return [
'=' => ['license', 'gps_imei', 'gps_carid', 'status'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function lists(): array
{
return Vehicle::where($this->searchWhere)
->field(['id', 'license', 'gps_imei', 'gps_carid', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function count(): int
{
return Vehicle::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,114 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\vehicle;
use app\api\logic\GpsLogic;
use app\common\model\vehicle\Vehicle;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* Vehicle逻辑
* Class VehicleLogic
* @package app\adminapi\logic
*/
class VehicleLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/17 09:23
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
//获取gps_car_id
$car = (new GpsLogic()) -> info($params['gps_imei']);
if($car['code'] == 0) self::setError('添加失败');
Vehicle::create([
'license' => $params['license'],
'gps_imei' => $params['gps_imei'],
'gps_carid' => $car['data']['carId'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/17 09:23
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Vehicle::where('id', $params['id'])->update([
'license' => $params['license'],
'gps_imei' => $params['gps_imei'],
'gps_carid' => $params['gps_carid'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/17 09:23
*/
public static function delete(array $params): bool
{
return Vehicle::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/08/17 09:23
*/
public static function detail($params): array
{
return Vehicle::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,99 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\vehicle;
use app\common\validate\BaseValidate;
/**
* Vehicle验证器
* Class VehicleValidate
* @package app\adminapi\validate
*/
class VehicleValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'license' => 'require|unique:vehicle',
'gps_imei' => 'require|unique:vehicle',
'status' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'license' => '车辆牌照',
'gps_imei' => 'gps定位器设备标志',
'status' => '车辆状态0未出租 1一级出租 2二级出租',
];
/**
* @notes 添加场景
* @return VehicleValidate
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function sceneAdd()
{
return $this->only(['license','gps_imei','status']);
}
/**
* @notes 编辑场景
* @return VehicleValidate
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function sceneEdit()
{
return $this->only(['id','license','gps_imei','status'])->remove('license', 'unique')->remove('gps_imei', 'unique');
}
/**
* @notes 删除场景
* @return VehicleValidate
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return VehicleValidate
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -26,7 +26,12 @@ class GpsController extends BaseApiController
public array $notNeedLogin = ['getCarInfo','getCarStatus','getCarHistory','test'];
public function getCarInfo() {
$result = (new GpsLogic()) -> info();
//获取参数
$params = $this -> request -> get('imei');
//验证参数
if(empty($params)) return $this->fail('参数错误');
//获取数据
$result = (new GpsLogic()) -> info($params);
return $result['code'] == 1 ? $this->success($result['msg'],$result['data']) : $this->fail($result['msg']);
}
@ -57,11 +62,7 @@ class GpsController extends BaseApiController
}
public function test() {
$message = [
'title' => '测试消息',
'msg_content' => '这是一条新的推送消息'
];
$res = push_message('18071adc021402b58fb2','这是条测试信息');
$res = push_message('170976fa8b98aae6535','这是条测试信息');
dump($res);
return !($res['code'] == 0);
}

View File

@ -57,7 +57,7 @@ class GpsLogic extends BaseLogic
/*
* 获取车辆信息
*/
public function info():array {
public function info($imei):array {
//获取token
$token = $this->token();
//请求地址
@ -65,7 +65,7 @@ class GpsLogic extends BaseLogic
//请求参数
$data = [
'token' => $token,
'imei' => '863010000029350'
'imei' => $imei
];
//发起请求
$result = curl_post($url,[],$data);

View File

@ -348,7 +348,7 @@ class LogisticsLogic extends BaseLogic
//更改物流信息状态
Logistics::startTrans();
try {
Logistics::where('id', $params['logistics_id'])->update([
Logistics::where('id', $logistics['id'])->update([
'status' => 3,
'update_time' => time(),
'qx_time' => time(),