ok('aa'); } /** * 绑定车辆 * */ public function addBike(Request $request) { // 验证参数 /* $validator = Validator::make($request->all(), [ 'bike_no' => 'bail|required|unique:bikes', 'box_no' => 'bail|required|unique:bikes', ], [ 'bike_no.required' => '车辆编号不能为空', 'bike_no.unique' => '车辆编号不可重复', 'box_no.required' => '控制器号不能为空', 'box_no.unique' => '控制器号不可重复', ]); if ($validator->fails()) { $res = $validator->getMessageBag(); $str = ''; foreach ($res->all() as $v) { $str .= $v . ','; } return $this->error(rtrim($str, ',')); }*/ $bike_no = $request->get('bike_no') ?? ''; $box_no = $request->get('box_no') ?? ''; if (empty($bike_no) || empty($box_no)) return $this->error('参数错误'); // 判断中控是否存在 $box = BoxBinding::query()->where('box_no', $box_no)->first(); if (empty($box)) return $this->error('找不到此设备信息,请联系管理员'); if ($box->is_binding == BoxBinding::BINDING_YES) return $this->error('此设备已经绑定过'); // 蓝牙信息'TBIT_WA205-7HBLE'; $blu_key = config('systemConfig.blu_key'); try { $blu_ase_key = Aes128Handler::genKey($blu_key, $box_no); } catch (\Exception $e) { return $this->error($e->getMessage()); } // 车辆信息 $bike = Bike::query()->where('bike_no', $bike_no)->first(); if (empty($bike)) return $this->error('找不到车辆信息'); // $update = [ // 'box_no' => $box_no, // 'blu_key' => $blu_key, // 'blu_ase_key' => $blu_ase_key // ]; try { DB::beginTransaction(); // 更新绑定表 $box->is_binding = BoxBinding::BINDING_YES; $box->save(); // 更新车辆信息 // $bike->update($update); $bike->box_no = $box_no; $bike->blu_key = $blu_key; $bike->blu_ase_key = $blu_ase_key; $bike->save(); DB::commit(); return $this->ok('绑定成功'); } catch (\Exception $e) { DB::rollBack(); Log::error($e->getMessage()); return $this->error('绑定失败,请联系管理员'); } } /** * 解绑车辆 * */ public function unbindingBike(Request $request) { // $bike_no = $request->get('bike_no') ?? ''; $box_no = $request->get('box_no') ?? ''; if (empty($box_no)) return $this->error('参数错误'); // 判断中控是否存在 $box = BoxBinding::query()->where('box_no', $box_no)->first(); if (empty($box)) return $this->error('找不到此设备信息,请联系管理员'); // if($box->is_binding == BoxBinding::BINDING_NO) return $this->error('此设备未绑定过,不需要解绑'); // 车辆信息 $bike = Bike::query()->where('box_no', $box_no)->first(); // if(empty($bike)) return $this->error('找不到车辆信息'); try { DB::beginTransaction(); // 更新绑定表 $box->is_binding = BoxBinding::BINDING_NO; $box->save(); // 更新车辆信息 // $bike->update($update); if (!empty($bike)) { $bike->box_no = ''; $bike->blu_key = ''; $bike->blu_ase_key = ''; $bike->save(); } DB::commit(); return $this->ok('解绑成功'); } catch (\Exception $e) { DB::rollBack(); Log::error($e->getMessage()); return $this->error('解绑失败,请联系管理员'); } } /** * 获取绑定后信息 * */ public function bikeInfoByBikeNo(Request $request) { $bike_no = $request->get('bike_no') ?? ''; if (empty($bike_no)) return $this->error('参数错误'); $bike = Bike::query()->where('bike_no', $bike_no)->first(['is_link', 'battery_power', 'bike_no', 'box_no'])->toArray(); if (empty($bike['box_no'])) { return $this->error('车辆未绑定,请先绑定'); } else { return $this->ok($bike); } } public function bikeInfo(Request $request) { $box_no = $request->get('box_no') ?? ''; if (empty($box_no)) return $this->error('参数错误'); $bike = Bike::query()->where('box_no', $box_no)->first(['is_link', 'battery_power', 'bike_no', 'box_no'])->toArray(); if (empty($bike)) { return $this->error('找不到车辆信息'); } else { return $this->ok($bike); } } /** * 获取蓝牙密钥 * */ public function getKey(Request $request) { $box_no = $request->get('box_no'); $bike = Bike::where('box_no', $box_no)->first(); $key = $bike->blu_ase_key ?? ''; return $this->ok(['key' => $key]); } /** * 响铃 * */ public function bikeBell(Request $request) { $bike_no = $request->get('bike_no') ?? ''; if (empty($bike_no)) return $this->error('参数错误'); $bike = Bike::query()->where('bike_no', $bike_no)->first(); if (empty($bike)) return $this->error('找不到车辆信息'); // $box_no = "003448483"; // 测试写死 $box_no = $bike->box_no; $bool = BikeControl::bellBike($box_no); if ($bool) { return $this->ok('操作成功,请寻找响铃车辆'); } else { return $this->error('操作失败,请联系管理员'); } } /** * 开电车锁 * */ public function bikeOpen(Request $request) { $bike_no = $request->get('bike_no') ?? ''; if (empty($bike_no)) return $this->error('参数错误'); $bike = Bike::query()->where('bike_no', $bike_no)->first(); if (empty($bike)) return $this->error('找不到车辆信息'); // $box_no = "003448483"; // 测试写死 $box_no = $bike->box_no; $bool = BikeControl::openLock($box_no); (new BikeStatusInfoSyncHandler())->toBikeRideStatus(BikeStatusInfoSyncHandler::ROLE_BIND, $bike_no, ['bike_id' => $bike->id, 'area_id' => $bike->put_area_id]); if ($bool) { return $this->ok('操作成功,请寻找响铃车辆'); } else { return $this->error('操作失败,请联系管理员'); } } /** * 关电车锁 * */ public function bikeClose(Request $request) { $bike_no = $request->get('bike_no') ?? ''; if (empty($bike_no)) return $this->error('参数错误'); $bike = Bike::query()->where('bike_no', $bike_no)->first(); if (empty($bike)) return $this->error('找不到车辆信息'); // $box_no = "003448483"; // 测试写死 $box_no = $bike->box_no; $bool = BikeControl::closeLock($box_no); $lastLocation = LocationsLog::getNewestLocationByBikeNo($bike_no); // 修改redis (new BikeStatusInfoSyncHandler())->toBikeWaitRideStatus($bike->bike_no, $lastLocation['lng'] ?? 0, $lastLocation['lat'] ?? 0, $bike->put_status); if ($bool) { return $this->ok('操作成功'); } else { return $this->error('操作失败,请联系管理员'); } } /** * 开电池锁 * */ public function bikeOpenBattery(Request $request) { $bike_no = $request->get('bike_no') ?? ''; if (empty($bike_no)) return $this->error('参数错误'); $bike = Bike::query()->where('bike_no', $bike_no)->first(); if (empty($bike)) return $this->error('找不到车辆信息'); // $box_no = "003448483"; // 测试写死 $box_no = $bike->box_no; $bool = BikeControl::openBatteryLock($box_no); if ($bool) { return $this->ok('操作成功'); } else { return $this->error('操作失败,请联系管理员'); } } /** * 关电池锁 * */ public function bikeCloseBattery(Request $request) { $bike_no = $request->get('bike_no') ?? ''; if (empty($bike_no)) return $this->error('参数错误'); $bike = Bike::query()->where('bike_no', $bike_no)->first(); if (empty($bike)) return $this->error('找不到车辆信息'); // $box_no = "003448483"; // 测试写死 $box_no = $bike->box_no; $bool = BikeControl::closeBatteryLock($box_no); if ($bool) { return $this->ok('操作成功'); } else { return $this->error('操作失败,请联系管理员'); } } /** * 重启中控 * */ public function rebootBox(Request $request) { $bike_no = $request->get('bike_no') ?? ''; if (empty($bike_no)) return $this->error('参数错误'); $bike = Bike::query()->where('bike_no', $bike_no)->first(); if (empty($bike)) return $this->error('找不到车辆'); // $box_no = "003448483"; // 测试写死 $box_no = $bike->box_no; $bool = BikeControl::rebootBox($box_no); if ($bool) { return $this->ok('重启中控成功'); } else { return $this->error('重启中控失败,请联系管理员'); } } /** * 立即定位 * */ public function newBikeLocation(Request $request) { $bike_no = $request->get('bike_no') ?? ''; if (empty($bike_no)) return $this->error('参数错误'); $bike = Bike::query()->where('bike_no', $bike_no)->first(); if (empty($bike)) return $this->error('找不到车辆'); // $box_no = "003448483"; // 测试写死 $box_no = $bike->box_no; $bool = BikeControl::nowBikeLocation($box_no); if ($bool) { return $this->ok('立即定位车辆成功'); } else { return $this->error('立即定位车辆失败,请联系管理员'); } } /** * 立即更新电池信息 * */ public function newBikeBatteryMSG(Request $request) { $bike_no = $request->get('bike_no') ?? ''; if (empty($bike_no)) return $this->error('参数错误'); $bike = Bike::query()->where('bike_no', $bike_no)->first(); if (empty($bike)) return $this->error('找不到车辆'); // $box_no = "003448483"; // 测试写死 $box_no = $bike->box_no; $bool = BikeControl::nowBikeBatteryMSG($box_no); if ($bool) { return $this->ok('立即更新电池信息成功'); } else { return $this->error('立即更新电池信息失败,请联系管理员'); } } }