diff --git a/app/adminapi/controller/vehicle/VehicleController.php b/app/adminapi/controller/vehicle/VehicleController.php new file mode 100644 index 00000000..0cf26fa1 --- /dev/null +++ b/app/adminapi/controller/vehicle/VehicleController.php @@ -0,0 +1,106 @@ +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); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/vehicle/VehicleLists.php b/app/adminapi/lists/vehicle/VehicleLists.php new file mode 100644 index 00000000..07f36340 --- /dev/null +++ b/app/adminapi/lists/vehicle/VehicleLists.php @@ -0,0 +1,76 @@ + ['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(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/vehicle/VehicleLogic.php b/app/adminapi/logic/vehicle/VehicleLogic.php new file mode 100644 index 00000000..4edc4d04 --- /dev/null +++ b/app/adminapi/logic/vehicle/VehicleLogic.php @@ -0,0 +1,114 @@ + 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(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/vehicle/VehicleValidate.php b/app/adminapi/validate/vehicle/VehicleValidate.php new file mode 100644 index 00000000..5dfa5a9a --- /dev/null +++ b/app/adminapi/validate/vehicle/VehicleValidate.php @@ -0,0 +1,99 @@ + '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']); + } + +} \ No newline at end of file diff --git a/app/api/controller/GpsController.php b/app/api/controller/GpsController.php index 0897e0ff..4799a206 100644 --- a/app/api/controller/GpsController.php +++ b/app/api/controller/GpsController.php @@ -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); } diff --git a/app/api/logic/GpsLogic.php b/app/api/logic/GpsLogic.php index 8304cfa0..37f01155 100644 --- a/app/api/logic/GpsLogic.php +++ b/app/api/logic/GpsLogic.php @@ -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); diff --git a/app/api/logic/LogisticsLogic.php b/app/api/logic/LogisticsLogic.php index 08b4e60d..3475d7bf 100644 --- a/app/api/logic/LogisticsLogic.php +++ b/app/api/logic/LogisticsLogic.php @@ -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(),