BikeController.php 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580
  1. <?php
  2. namespace App\Http\Controllers\App;
  3. use App\Filters\BikeFilter;
  4. use App\Handlers\Aes128Handler;
  5. use App\Handlers\BaseBikeControl;
  6. use App\Handlers\BikeStatusInfoSyncHandler;
  7. use App\Http\Requests\RemarkRequest;
  8. use App\Http\Resources\App\BikeOnlineResource;
  9. use App\Http\Resources\App\BikeResource;
  10. use App\Http\Resources\App\OrderRentResource;
  11. use App\Http\Resources\App\OrderResource;
  12. use App\Jobs\AutoCloseBikeLockJob;
  13. use App\Models\AdminMerchant;
  14. use App\Models\AdminRole;
  15. use App\Models\AdminUser;
  16. use App\Models\Area;
  17. use App\Models\Bike;
  18. // use App\Models\BikeTrouble;
  19. use App\Models\BoxBinding;
  20. use App\Models\LocationsLog;
  21. use App\Models\Order;
  22. use App\Models\OrderBikeOperate;
  23. use App\Models\OrderRent;
  24. use App\Models\User;
  25. use App\Models\WorkerBikeOperate;
  26. use App\Models\WorkOrder;
  27. use App\Utils\Admin;
  28. use App\Utils\GaodeMaps;
  29. use App\Utils\Runtime;
  30. use Carbon\Carbon;
  31. use Illuminate\Http\Request;
  32. use App\Http\Controllers\Controller;
  33. use Illuminate\Support\Facades\DB;
  34. use Illuminate\Support\Facades\Log;
  35. use Illuminate\Support\Facades\Redis;
  36. use Matrix\Exception;
  37. class BikeController extends AppBaseController
  38. {
  39. public function searchBike(Request $request)
  40. {
  41. $bike_no = $request->get('bike_no') ?? '';
  42. if (empty($bike_no)) return $this->error('请输入正确车牌号');
  43. $bikeInfo = Bike::query()->where('bike_no', 'like', "%{$bike_no}")->where(AdminMerchant::getMerchantWhere());
  44. if (!Admin::isAdministrator()) {
  45. $bikeInfo = $bikeInfo->whereIn('put_area_id', self::$areaIds);
  46. }
  47. $bikes = $bikeInfo->pluck('bike_no', 'id');
  48. if (!$bikes) {
  49. $this->error('找不到车辆信息,请检查车牌号');
  50. }
  51. return $this->ok([
  52. 'bikes' => $bikes,
  53. 'is_one' => count($bikes) ? false : true
  54. ]);
  55. }
  56. /**
  57. * getBikeInfoByBikeNo 根据车辆编号查找车辆基础信息
  58. *
  59. * @param Request $request
  60. * @return \Illuminate\Http\JsonResponse
  61. * @author Fx
  62. *
  63. */
  64. public function getBikeInfoByBikeNo(Request $request)
  65. {
  66. $bike_no = $request->get('bike_no') ?? '';
  67. if (empty($bike_no)) return $this->error('请输入正确车牌号');
  68. $bikeInfo = Bike::query()->where('bike_no', $bike_no)->where(AdminMerchant::getMerchantWhere());
  69. if (!Admin::isAdministrator()) {
  70. // if (!Admin::isAdministrator() && !Admin::isNormalAdministrator()) {
  71. $bikeInfo = $bikeInfo->whereIn('put_area_id', self::$areaIds);
  72. }
  73. $bikeInfo = $bikeInfo->first();
  74. if (empty($bikeInfo)) return $this->error('找不到车辆信息,请检查车牌号');
  75. $data = [];
  76. $model = $bikeInfo;
  77. $tab_name = '';
  78. if (!(bool)$model->is_link) {
  79. // 离线
  80. $tab_name = '中控离线';
  81. } elseif ((bool)$model->is_trouble) {
  82. // 故障上线
  83. if ((bool)$model->put_status) {
  84. $tab_name = '故障';
  85. } else {
  86. // 故障下线
  87. $tab_name = '故障下线';
  88. }
  89. } elseif (!(bool)$model->is_low_battery_power) {
  90. // 低电量
  91. $tab_name = '低电量';
  92. } elseif (!(bool)$model->put_status) {
  93. // 下线 未投放
  94. $tab_name = '未投放';
  95. } elseif ((bool)$model->is_riding) {
  96. //骑行中
  97. $tab_name = '骑行中';
  98. } elseif (!(bool)$model->is_in_parking) {
  99. // 不在停车区
  100. $tab_name = '不在停车区';
  101. } else {
  102. // 未骑行
  103. $tab_name = '未骑行';
  104. }
  105. $lastLocation = LocationsLog::getNewestLocationTimeByBikeNo($bike_no);
  106. $workInfo = [];
  107. if (app()->redis->hexists(BikeStatusInfoSyncHandler::REDIS_RIDE_BIKE_WORKER_ORDERS_TAG, $bikeInfo->bike_no)) {
  108. $work_id = app()->redis->hget(BikeStatusInfoSyncHandler::REDIS_RIDE_BIKE_WORKER_ORDERS_TAG, $bikeInfo->bike_no);
  109. $work = AdminUser::find($work_id);
  110. $workInfo = [
  111. 'name' => $work->name,
  112. 'phone' => $work->phone,
  113. ];
  114. }
  115. // 车辆信息
  116. $data['bike_info']['bike_no'] = $bike_no;
  117. $data['bike_info']['box_no'] = $bikeInfo->box_no;
  118. $data['bike_info']['id'] = $bikeInfo->id;
  119. $data['bike_info']['is_lock'] = $bikeInfo->is_lock;
  120. $data['bike_info']['battery_power'] = $bikeInfo->battery_power;
  121. $data['bike_info']['is_trouble'] = $bikeInfo->is_trouble; // 是否故障
  122. $data['bike_info']['is_link'] = $bikeInfo->put_status; // 是否在线
  123. $data['bike_info']['area_name'] = Area::query()->find($bikeInfo->put_area_id)->name ?? ''; //车辆区域地址
  124. $data['bike_info']['tab_name'] = $tab_name; //状态
  125. $data['bike_info']['last_location'] = GaodeMaps::getAddress([$lastLocation['location']['lng'], $lastLocation['location']['lat']]); //最后定位位置
  126. $data['bike_info']['last_time'] = $lastLocation['time']; //最后定位时间
  127. $data['bike_info']['workInfo'] = $workInfo; //最后定位时间
  128. $data['bike_info']['remark'] = $bikeInfo->remark ?? ''; //最后定位时间
  129. //最近订单 取最
  130. $order = Order::query()->where(AdminMerchant::getMerchantWhere())->where('bike_id', $bikeInfo->id)->orderByDesc('id')->with('users')->first();
  131. $orderRent = OrderRent::query()->where(AdminMerchant::getMerchantWhere())->where('bike_id', $bikeInfo->id)->orderByDesc('id')->with('users')->first();
  132. $data2 = [];
  133. if (!empty($order) && !empty($orderRent)) {
  134. if ($orderRent->start_use_bike_time > $order->start_use_bike_time) {
  135. // $user = User::query()->find($v->user_id);
  136. $data1['bike_no'] = $orderRent->bike_no;
  137. $data1['username'] = $orderRent->users->nickname . "(" . $orderRent->users->truename . ")" ?? '';
  138. $data1['mobile'] = $orderRent->users->mobile ?? '';
  139. $data1['order_status'] = OrderRent::$statusMaps[$orderRent->status];
  140. $data1['start_use_bike_time'] = $orderRent->start_use_bike_time;
  141. $data1['end_use_bike_time'] = $orderRent->end_use_bike_time;
  142. $data1['start_use_bike_time_app'] = date('m/d H:i', strtotime($orderRent->start_use_bike_time));
  143. $data1['end_use_bike_time_app'] = $orderRent->end_use_bike_time ? date('m/d H:i', strtotime($orderRent->end_use_bike_time)) : '';
  144. } else {
  145. $data1['bike_no'] = $order->bike_no;
  146. $data1['username'] = $order->users->nickname . "(" . $order->users->truename . ")" ?? '';
  147. $data1['mobile'] = $order->users->mobile ?? '';
  148. $data1['order_status'] = Order::$statusMaps[$order->status];
  149. $data1['start_use_bike_time'] = $order->start_use_bike_time;
  150. $data1['end_use_bike_time'] = $order->end_use_bike_time;
  151. $data1['start_use_bike_time_app'] = date('m/d H:i', strtotime($order->start_use_bike_time));
  152. $data1['end_use_bike_time_app'] = $order->end_use_bike_time ? date('m/d H:i', strtotime($order->end_use_bike_time)) : '';
  153. }
  154. $data2[] = $data1;
  155. } else if (!empty($order)) {
  156. $data1['bike_no'] = $order->bike_no;
  157. $data1['username'] = $order->users->nickname . "(" . $order->users->truename . ")" ?? '';
  158. $data1['mobile'] = $order->users->mobile ?? '';
  159. $data1['order_status'] = Order::$statusMaps[$order->status];
  160. $data1['start_use_bike_time'] = $order->start_use_bike_time;
  161. $data1['end_use_bike_time'] = $order->end_use_bike_time;
  162. $data1['start_use_bike_time_app'] = date('m/d H:i', strtotime($order->start_use_bike_time));
  163. $data1['end_use_bike_time_app'] = $order->end_use_bike_time ? date('m/d H:i', strtotime($order->end_use_bike_time)) : '';
  164. $data2[] = $data1;
  165. } else if (!empty($orderRent)) {
  166. $data1['bike_no'] = $orderRent->bike_no;
  167. $data1['username'] = $orderRent->users->nickname . "(" . $orderRent->users->truename . ")" ?? '';
  168. $data1['mobile'] = $orderRent->users->mobile ?? '';
  169. $data1['order_status'] = OrderRent::$statusMaps[$orderRent->status];
  170. $data1['start_use_bike_time'] = $orderRent->start_use_bike_time;
  171. $data1['end_use_bike_time'] = $orderRent->end_use_bike_time;
  172. $data1['start_use_bike_time_app'] = date('m/d H:i', strtotime($orderRent->start_use_bike_time));
  173. $data1['end_use_bike_time_app'] = $orderRent->end_use_bike_time ? date('m/d H:i', strtotime($orderRent->end_use_bike_time)) : '';
  174. $data2[] = $data1;
  175. }
  176. $data['bike_order'] = $data2;
  177. return $this->ok($data);
  178. }
  179. /**
  180. * updateBikeInfo 根据车辆id 修改车辆信息
  181. *
  182. * @param Request $request
  183. * @return \Illuminate\Http\JsonResponse
  184. * @author Fx
  185. *
  186. */
  187. public function updateBikeInfo(Request $request)
  188. {
  189. $admin_id = Admin::user()->id;
  190. if (!Admin::isAdministrator() and !Admin::user()->isRole(AdminRole::MERCHANTSADMIN)) {
  191. return $this->error('暂无权限');
  192. }
  193. $bike_id = $request->get('bike_id') ?? '';
  194. if (empty($bike_id)) return $this->error('参数错误');
  195. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->whereIn('put_area_id', self::$areaIds)->find($bike_id);
  196. if (empty($bike)) return $this->error('找不到该车辆信息,请检查车牌号');
  197. $bike_no = $request->get('bike_no') ?? '';
  198. $box_no = $request->get('box_no') ?? '';
  199. $bike_remarks = $request->get('bike_remarks') ?? '';
  200. if (empty($bike_no) && empty($box_no) && empty($bike_remarks)) {
  201. // 都为空
  202. return $this->error('请输入要修改的内容');
  203. }
  204. // 不为空修改
  205. if (!empty($bike_no)) {
  206. $verifyBikeNo = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('bike_no', $bike_no)->first();
  207. if (!empty($verifyBikeNo)) {
  208. if ($verifyBikeNo->id !== $bike->id) {
  209. return $this->error('车辆编号已存在,不可修改');
  210. }
  211. }
  212. $bike->bike_no = $bike_no;
  213. }
  214. $date = Carbon::now();
  215. if (!empty($bike_remarks)) {
  216. $bike->remark = $bike_remarks . $date;
  217. }
  218. if (!empty($box_no)) {
  219. $verifyBikeNo = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('box_no', $box_no)->first();
  220. if (!empty($verifyBikeNo)) {
  221. if ($verifyBikeNo->id !== $bike->id) {
  222. return $this->error('中控编号已存在,不可修改');
  223. }
  224. }
  225. // 中控绑定操作
  226. $box = BoxBinding::query()->where(AdminMerchant::getMerchantWhere())->where('box_no', $box_no)->first();
  227. if (empty($box)) return $this->error('找不到此设备信息,请联系管理员');
  228. if ($box->is_binding == BoxBinding::BINDING_YES) return $this->error('此设备已经绑定过');
  229. $blu_key = $blu_ase_key = '';
  230. switch ((int)$box->manufacturer) {
  231. case BoxBinding::TBT:
  232. $blu_key = config('systemConfig.blu_key');
  233. try {
  234. $blu_ase_key = Aes128Handler::genKey($blu_key, $box_no);
  235. } catch (\Exception $e) {
  236. return $this->error($e->getMessage());
  237. }
  238. break;
  239. case BoxBinding::WKM:
  240. $blu_key = $box->bluetooth_token;
  241. $blu_ase_key = $box->bluetooth_token;
  242. break;
  243. }
  244. $inputs['blu_key'] = $blu_key;
  245. $inputs['blu_ase_key'] = $blu_ase_key;
  246. try {
  247. DB::beginTransaction();
  248. $bike->blu_key = $blu_key;
  249. $bike->blu_ase_key = $blu_ase_key;
  250. $box->is_binding = BoxBinding::BINDING_YES;
  251. $box->save();
  252. $bike->save();
  253. DB::commit();
  254. return $this->ok(BikeResource::make($bike));
  255. } catch (\Exception $e) {
  256. DB::rollBack();
  257. Log::error($e->getMessage());
  258. return $this->error('修改失败,请联系管理员');
  259. }
  260. }
  261. $bool = $bike->save();
  262. if ($bool) {
  263. return $this->ok('修改成功');
  264. } else {
  265. return $this->error('修改失败,请联系管理员');
  266. }
  267. }
  268. /**
  269. * bikeLocation 车辆位置轨迹
  270. *
  271. * @param Request $request
  272. * @return \Illuminate\Http\JsonResponse
  273. * @author Fx
  274. *
  275. */
  276. public function bikeLocation(Request $request)
  277. {
  278. $bike_no = $request->get('bike_no') ?? '';
  279. $time_between = $request->get('time_between') ?? []; // time_between 时间区间
  280. if (empty($bike_no) || empty($time_between)) return $this->error('参数错误');
  281. $locationLog = LocationsLog::where('bike_no', $bike_no)
  282. ->where('created_at', '>=', Carbon::parse($time_between[0])->toDateString())
  283. ->where('created_at', '<=', Carbon::parse($time_between[1])->toDateString())
  284. ->whereBetween('latitude', [3, 53])->whereBetween('longitude', [73, 136])->orderBy('box_time', 'asc')
  285. ->get(['longitude', 'latitude', 'type']);
  286. $data = [];
  287. $userLocation = [];
  288. $workerLocation = [];
  289. $noLocatioin = [];
  290. $old_type = '';
  291. $item = [];
  292. $Locations = [];
  293. foreach ($locationLog as $v) {
  294. $data[] = [$v->longitude, $v->latitude];
  295. if (empty($old_type)) {
  296. $old_type = $v->type;
  297. }
  298. if ($v->type !== $old_type) {
  299. if ($old_type == LocationsLog::USER_LOCATION) {
  300. $userLocation[] = $item;
  301. $Locations[] = [
  302. 'points' => $item,
  303. 'role' => LocationsLog::USER_LOCATION,
  304. 'borderColor' => '#18D3B8',
  305. 'borderWidth' => '3',
  306. 'color' => '#18D3B8',
  307. 'width' => '4'];
  308. } else if ($old_type == LocationsLog::WORKER_LOCATION) {
  309. $workerLocation[] = $item;
  310. $Locations[] = [
  311. 'role' => LocationsLog::WORKER_LOCATION,
  312. 'points' => $item,
  313. 'borderColor' => '#ff6477',
  314. 'borderWidth' => '3',
  315. 'color' => '#ff6477',
  316. 'width' => '4'
  317. ];
  318. } else {
  319. $noLocatioin[] = $item;
  320. $Locations[] = [
  321. 'points' => $item,
  322. 'borderColor' => '#d684dd',
  323. 'borderWidth' => '3',
  324. 'color' => '#d684dd',
  325. 'width' => '4',
  326. 'role' => LocationsLog::NO_LOCATION
  327. ];
  328. }
  329. $old_type = '';
  330. $item = [];
  331. $item[] = ['longitude' => $v->longitude, 'latitude' => $v->latitude];
  332. } else {
  333. $item[] = ['longitude' => $v->longitude, 'latitude' => $v->latitude];
  334. }
  335. unset($v->_id);
  336. }
  337. if (empty($data)) return $this->ok($data);
  338. $wx_data = $locationLog->toArray();
  339. $start_point = [
  340. 'zIndex' => 100,
  341. 'id' => 'start',
  342. 'width' => 32,
  343. 'height' => 32,
  344. 'iconPath' => 'http://resource.bike.hanyiyun.com/common/start-location-mark.png',
  345. ];
  346. $end_point = [
  347. 'zIndex' => 100,
  348. 'id' => 'end',
  349. 'width' => 32,
  350. 'height' => 32,
  351. 'iconPath' => 'http://resource.bike.hanyiyun.com/common/end-location-mark.png',
  352. ];
  353. $res = [
  354. 'points' => [array_merge($wx_data[0], $start_point), array_merge(end($wx_data), $end_point)],
  355. 'all_locations' => $Locations
  356. ];
  357. return $this->ok($res);
  358. }
  359. /**
  360. * bikePosition 获取车辆真实位置点(mongodb)
  361. *
  362. * @param Request $request
  363. * @return \Illuminate\Http\JsonResponse
  364. * @author Fx
  365. *
  366. */
  367. public function bikePosition(Request $request)
  368. {
  369. $bike_no = $request->get('bike_no') ?? '';
  370. if (empty($bike_no)) return $this->error('参数错误');
  371. $position = LocationsLog::getNewestLocationByBikeNo($bike_no);
  372. if (empty($position)) return $this->ok([]);
  373. return $this->ok([$position['lng'], $position['lat']]);
  374. }
  375. /**
  376. * sweepCodeLocation 扫码位置 近200条
  377. *
  378. * @param Request $request
  379. * @return \Illuminate\Http\JsonResponse
  380. * @author Fx
  381. *
  382. */
  383. public function sweepCodeLocation(Request $request)
  384. {
  385. $bike_id = $request->get('bike_id') ?? '';
  386. if (empty($bike_id)) return $this->error('参数错误');
  387. $threeAgo = Carbon::today()->subDays(3);
  388. $order = Order::query()
  389. ->where(AdminMerchant::getMerchantWhere())
  390. ->where('bike_id', $bike_id)
  391. // ->where('created_at','>',$threeAgo)
  392. ->orderByDesc('id')
  393. ->limit(100)
  394. ->get(['start_use_bike_time', 'start_use_bike_location']);
  395. $data = [];
  396. if (!empty($order)) {
  397. foreach ($order as $v) {
  398. $dataItem['time'] = $v->start_use_bike_time;
  399. $obj = json_decode($v->start_use_bike_location);
  400. $dataItem['location'] = [$obj->longitude, $obj->latitude];
  401. $data[] = $dataItem;
  402. }
  403. }
  404. $orderRent = OrderRent::query()
  405. ->where(AdminMerchant::getMerchantWhere())
  406. ->where('bike_id', $bike_id)
  407. // ->where('created_at','>',$threeAgo)
  408. ->orderByDesc('id')
  409. ->limit(100)
  410. ->get(['start_use_bike_time', 'start_use_bike_location']);
  411. $dataRent = [];
  412. if (!empty($orderRent)) {
  413. foreach ($orderRent as $v) {
  414. $dataRentItem['time'] = $v->start_use_bike_time;
  415. $objRent = json_decode($v->start_use_bike_location);
  416. $dataRentItem['location'] = [$objRent->longitude, $objRent->latitude];
  417. $dataRent[] = $dataRentItem;
  418. }
  419. }
  420. return $this->ok(array_merge($data, $dataRent));
  421. }
  422. public function updateRemark(RemarkRequest $request, $id)
  423. {
  424. //
  425. $bike = Bike::find($id);
  426. $inputs = $request->validated();
  427. // Log::info($id);
  428. $bike->update($inputs);
  429. return $this->ok('修改成功');
  430. }
  431. /**
  432. * latelyOrders 车辆最近订单
  433. *
  434. * @param Request $request
  435. * @return \Illuminate\Http\JsonResponse
  436. * @author Fx
  437. *
  438. */
  439. public function latelyOrders(Request $request)
  440. {
  441. $bike_id = $request->get('bike_id') ?? '';
  442. if (empty($bike_id)) return $this->error('参数错误');
  443. $order = Order::query()
  444. ->where(AdminMerchant::getMerchantWhere())
  445. ->where('bike_id', $bike_id)
  446. ->with('users')
  447. ->orderByDesc('id')
  448. ->paginate();
  449. // $data = [];
  450. // if (!empty($order)) {
  451. // foreach ($order as $v) {
  452. // // $user = User::query()->find($v->user_id);
  453. // $data1['bike_no'] = $v->bike_no;
  454. // $data1['username'] = $v->users->nickname ?? '';
  455. // $data1['mobile'] = $v->users->mobile ?? '';
  456. // $data1['order_status'] = Order::$statusMaps[$v->status];
  457. // $data1['start_use_bike_time'] = $v->start_use_bike_time;
  458. // $data1['end_use_bike_time'] = $v->end_use_bike_time;
  459. // $data[] = $data1;
  460. // }
  461. // }
  462. return $this->ok(OrderResource::collection($order));
  463. }
  464. /**
  465. * latelyOrderRent 最近日租订单
  466. *
  467. * @param Request $request
  468. * @return \Illuminate\Http\JsonResponse
  469. * @author Fx
  470. *
  471. */
  472. public function latelyOrderRent(Request $request)
  473. {
  474. $bike_id = $request->get('bike_id') ?? '';
  475. if (empty($bike_id)) return $this->error('参数错误');
  476. $order = OrderRent::query()
  477. ->where(AdminMerchant::getMerchantWhere())
  478. ->where('bike_id', $bike_id)
  479. ->with('users')
  480. ->orderByDesc('id')
  481. ->paginate();
  482. return $this->ok(OrderRentResource::collection($order));
  483. }
  484. /**
  485. * locksLog 车辆开锁关锁记录 近3天
  486. *
  487. * @param Request $request
  488. * @return \Illuminate\Http\JsonResponse
  489. * @author Fx
  490. *
  491. */
  492. public function locksLog(Request $request)
  493. {
  494. $bike_id = $request->get('bike_id') ?? '';
  495. if (empty($bike_id)) return $this->error('参数错误');
  496. $typeArr = [OrderBikeOperate::TYPE_OPEN_BIKE,
  497. OrderBikeOperate::TYPE_CLONE_BIKE,
  498. OrderBikeOperate::TYPE_PAUSE_OPEN_BIKE,
  499. OrderBikeOperate::TYPE_PAUSE_CLONE_BIKE];
  500. // 普通用户操作
  501. $threeAgo = Carbon::today()->subDays(3);
  502. $lock1 = OrderBikeOperate::query()
  503. ->where(AdminMerchant::getMerchantWhere())
  504. ->whereIn('type', $typeArr)
  505. ->where('is_admin', OrderBikeOperate::IS_ADMIN_NO)
  506. ->where('bike_id', $bike_id)
  507. ->where('created_at', '>', $threeAgo)
  508. ->with('users')
  509. ->orderByDesc('id')
  510. ->get();
  511. $data1 = [];
  512. $open_bike = [];
  513. $close_bike = [];
  514. $open_pause_bike = [];
  515. $close_pause_bike = [];
  516. if (!empty($lock1)) {
  517. foreach ($lock1 as $v) {
  518. // $user = User::query()->find($v->user_id);
  519. $dataItem1['username'] = $v->users->nickname ?? '';
  520. $dataItem1['mobile'] = $v->users->mobile ?? '';
  521. $dataItem1['operate_time'] = date("Y/m/d H:i:s", strtotime($v->created_at));
  522. $dataItem1['name'] = $v->name;
  523. $dataItem1['location'] = [$v->longitude, $v->latitude];
  524. if ($v->type == OrderBikeOperate::TYPE_OPEN_BIKE) {
  525. $open_bike[] = $dataItem1;
  526. } elseif ($v->type == OrderBikeOperate::TYPE_CLONE_BIKE) {
  527. $close_bike[] = $dataItem1;
  528. } elseif ($v->type == OrderBikeOperate::TYPE_PAUSE_OPEN_BIKE) {
  529. $open_pause_bike[] = $dataItem1;
  530. } elseif ($v->type == OrderBikeOperate::TYPE_PAUSE_CLONE_BIKE) {
  531. $close_pause_bike[] = $dataItem1;
  532. }
  533. }
  534. }
  535. // 管理员操作
  536. $lock2 = OrderBikeOperate::query()
  537. ->where(AdminMerchant::getMerchantWhere())
  538. ->whereIn('type', $typeArr)
  539. ->where('is_admin', OrderBikeOperate::IS_ADMIN_YES)
  540. ->where('bike_id', $bike_id)
  541. ->where('created_at', '>', $threeAgo)
  542. ->with('adminUsers')
  543. ->orderByDesc('id')
  544. ->get();
  545. $data2 = [];
  546. if (!empty($lock2)) {
  547. foreach ($lock2 as $v) {
  548. // $user = AdminUser::query()->find($v->user_id);
  549. $dataItem2['username'] = $v->adminUsers->name ?? '';
  550. $dataItem2['mobile'] = $v->adminUsers->phone ?? '';
  551. $dataItem2['operate_time'] = date("Y/m/d H:i:s", strtotime($v->created_at));
  552. $dataItem2['name'] = $v->name;
  553. $dataItem2['location'] = [$v->longitude, $v->latitude];
  554. if ($v->type == OrderBikeOperate::TYPE_OPEN_BIKE) {
  555. $open_bike[] = $dataItem2;
  556. } elseif ($v->type == OrderBikeOperate::TYPE_CLONE_BIKE) {
  557. $close_bike[] = $dataItem2;
  558. } elseif ($v->type == OrderBikeOperate::TYPE_PAUSE_OPEN_BIKE) {
  559. $open_pause_bike[] = $dataItem2;
  560. } elseif ($v->type == OrderBikeOperate::TYPE_PAUSE_CLONE_BIKE) {
  561. $close_pause_bike[] = $dataItem2;
  562. }
  563. }
  564. }
  565. // $data = array_merge($data1, $data2);
  566. $data = [
  567. 'open_bike' => $open_bike,
  568. 'close_bike' => $close_bike,
  569. 'open_pause_bike' => $open_pause_bike,
  570. 'close_pause_bike' => $close_pause_bike
  571. ];
  572. return $this->ok($data);
  573. }
  574. /**
  575. * bikeOnLineLog 车辆上线下线记录
  576. *
  577. * @param Request $request
  578. * @return \Illuminate\Http\JsonResponse
  579. * @author Fx
  580. *
  581. */
  582. public function bikeOnLineLog(Request $request)
  583. {
  584. $bike_id = $request->get('bike_id') ?? '';
  585. if (empty($bike_id)) return $this->error('参数错误');
  586. $bikeOnLine = WorkerBikeOperate::query()
  587. ->where(AdminMerchant::getMerchantWhere())
  588. ->where('bike_id', $bike_id)
  589. ->whereIn('type', [WorkerBikeOperate::TYPE_ONLINE, WorkerBikeOperate::TYPE_OFFLINE])
  590. ->with('workers')
  591. ->orderByDesc('id')
  592. ->paginate();
  593. // $data = [];
  594. // if (!empty($bikeOnLine)) {
  595. // foreach ($bikeOnLine as $v) {
  596. // $item['reason'] = $v->reason;
  597. // $item['name'] = $v->name;
  598. // $item['created_at'] = date("Y/m/d H:i:s", strtotime($v->created_at));
  599. // $item['username'] = $v->workers->name;
  600. // $item['mobile'] = $v->workers->phone;
  601. // $data[] = $item;
  602. // }
  603. // }
  604. return $this->ok(BikeOnlineResource::collection($bikeOnLine));
  605. }
  606. /**
  607. * repairOptions 可报修选项
  608. *
  609. * @return \Illuminate\Http\JsonResponse
  610. * @author Fx
  611. *
  612. */
  613. public function repairOptions()
  614. {
  615. // $repair_part = BikeTrouble::$troublePartMaps;
  616. $repair_part = WorkOrder::$typeMaps;
  617. $data = [];
  618. foreach ($repair_part as $k => $v) {
  619. $dateItem['id'] = $k;
  620. $dateItem['name'] = $v;
  621. $dateItem['select'] = false;
  622. $data[] = $dateItem;
  623. }
  624. return $this->ok($data);
  625. }
  626. /**
  627. * bikeRepair 车辆报修
  628. *
  629. * @param Request $request
  630. * @return \Illuminate\Http\JsonResponse
  631. * @author Fx
  632. *
  633. */
  634. public function bikeRepair(Request $request)
  635. {
  636. $bike_no = $request->get('bike_no') ?? '';
  637. $box_no = $request->get('box_no') ?? '';
  638. $trouble_part = $request->get('trouble_part') ?? ''; // 报修部位
  639. $reason = $request->get('reason') ?? ''; // 原因
  640. if (empty($trouble_part)) return $this->error('请选择报修部位');
  641. if (empty($reason) || empty($bike_no)) return $this->error('请填写报修原因');
  642. if (!empty($bike_no)) {
  643. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('bike_no', $bike_no)->first();
  644. if (!empty($bike)) {
  645. if ($bike->put_status == Bike::PUT_STATUS_NO) {
  646. return $this->error('车辆已下线,无需报修,如需报修请先手动上线');
  647. }
  648. DB::beginTransaction();
  649. try {
  650. // 更新车辆状态 下线
  651. $bike->put_status = Bike::PUT_STATUS_NO;
  652. $bike->is_trouble = Bike::TROUBLE_YES;
  653. $bool1 = $bike->save();
  654. // 更新redis
  655. (new BikeStatusInfoSyncHandler())->toBikeOffLineStatus($bike->bike_no);
  656. if (!$bool1) {
  657. DB::rollBack();
  658. Log::error('更新车辆状态失败');
  659. }
  660. // 插入下线记录
  661. $worker_bike_operate = new WorkerBikeOperate();
  662. $worker_bike_operate->type = WorkerBikeOperate::TYPE_OFFLINE;
  663. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_OFFLINE];
  664. $worker_bike_operate->bike_id = $bike->id;
  665. $last_location = json_decode($bike->last_location);
  666. $worker_bike_operate->latitude = empty($last_location->lat) ? 0 : $last_location->lat;
  667. $worker_bike_operate->longitude = empty($last_location->lng) ? 0 : $last_location->lng;
  668. $worker_bike_operate->worker_id = Admin::user()->id;
  669. $worker_bike_operate->merchant_id = AdminMerchant::putMerchantId();
  670. // foreach ($trouble_part as $v){
  671. // $reason .= BikeTrouble::$troublePartMaps[$v] . ',';
  672. // }
  673. $worker_bike_operate->reason = $reason;
  674. $bool2 = $worker_bike_operate->save();
  675. if (!$bool2) {
  676. DB::rollBack();
  677. Log::error('插入下线记录失败');
  678. }
  679. // 插入报修信息
  680. // $bike_trouble = new BikeTrouble();
  681. // $bike_trouble->trouble_no = 'T-'.$this->generateTroubleNo(); //故障号
  682. // $bike_trouble->user_id = Admin::user()->id;
  683. // $bike_trouble->bike_id = $bike->id;
  684. // $bike_trouble->area_id = $bike->put_area_id;// 区域id
  685. // $bike_trouble->trouble_part = json_encode($trouble_part);
  686. // $bike_trouble->trouble_grade = count($trouble_part)==1 ? BikeTrouble::getTroubleGrade($trouble_part[0]): BikeTrouble::TROUBLE_GRADE_TWO ;// 故障等级 故障部位大于1 默认高级故障
  687. // // $bike_trouble->up_trouble_type = 0 // 上报问题类型
  688. // $bool3 = $bike_trouble->save();
  689. //生成工单
  690. //插入工单
  691. $work_order_data = [
  692. 'work_no' => WorkOrder::makeWorkNo(),
  693. 'type' => $trouble_part,
  694. 'type_name' => WorkOrder::$typeMaps[$trouble_part],
  695. 'bike_no' => $bike->bike_no,
  696. 'bike_id' => $bike->id,
  697. 'source' => WorkOrder::SOURCE_REPAIR,
  698. 'area_id' => $bike->put_area_id,
  699. 'admin_id' => Admin::user()->id,
  700. 'reason' => $reason,
  701. 'merchant_id' => AdminMerchant::putMerchantId()
  702. ];
  703. $work_order_verify = [
  704. 'bike_id' => $bike->id,
  705. 'type' => $trouble_part, // 工单类型
  706. 'status' => WorkOrder::STATUS_NO,
  707. 'merchant_id' => AdminMerchant::putMerchantId()
  708. ];
  709. WorkOrder::firstOrCreate($work_order_verify, $work_order_data);
  710. DB::commit();
  711. return $this->ok('报修成功');
  712. } catch (\Exception $exception) {
  713. DB::rollBack();
  714. Log::info($exception->getMessage());
  715. return $this->error('操作失败请联系管理员');
  716. }
  717. }
  718. }
  719. if (!empty($box_no)) {
  720. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('box_no', $box_no)->first();
  721. if (!empty($bike)) {
  722. try {
  723. // 更新车辆状态 下线
  724. $bike->put_status = Bike::PUT_STATUS_NO;
  725. $bike->is_trouble = Bike::TROUBLE_YES;
  726. $bool1 = $bike->save();
  727. // 更新redis
  728. (new BikeStatusInfoSyncHandler())->toBikeOffLineStatus($bike->bike_no);
  729. if (!$bool1) {
  730. DB::rollBack();
  731. Log::error('更新车辆状态失败');
  732. }
  733. // 插入下线记录
  734. $worker_bike_operate = new WorkerBikeOperate();
  735. $worker_bike_operate->type = WorkerBikeOperate::TYPE_OFFLINE;
  736. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_OFFLINE];
  737. $worker_bike_operate->bike_id = $bike->id;
  738. $last_location = json_decode($bike->last_location);
  739. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  740. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  741. $worker_bike_operate->worker_id = Admin::user()->id;
  742. $worker_bike_operate->merchant_id = AdminMerchant::putMerchantId();
  743. $worker_bike_operate->reason = $reason;
  744. $bool2 = $worker_bike_operate->save();
  745. if (!$bool2) {
  746. DB::rollBack();
  747. Log::error('插入下线记录失败');
  748. }
  749. // 插入报修信息
  750. // $bike_trouble = new BikeTrouble();
  751. // $bike_trouble->trouble_no = 'T-' . $this->generateTroubleNo(); //故障号
  752. // $bike_trouble->user_id = Admin::user()->id;
  753. // $bike_trouble->bike_id = $bike->id;
  754. // $bike_trouble->area_id = $bike->put_area_id;// 区域id
  755. // $bike_trouble->trouble_part = json_encode($trouble_part);
  756. // $bike_trouble->trouble_grade = 3; // 故障等级
  757. // // $bike_trouble->up_trouble_type = 0 // 上报问题类型
  758. // $bool3 = $bike_trouble->save();
  759. //生成工单
  760. // 插入工单
  761. $work_order_data = [
  762. 'work_no' => WorkOrder::makeWorkNo(),
  763. 'type' => $trouble_part,
  764. 'type_name' => WorkOrder::$typeMaps[$trouble_part],
  765. 'bike_no' => $bike->bike_no,
  766. 'bike_id' => $bike->id,
  767. 'source' => WorkOrder::SOURCE_REPAIR,
  768. 'area_id' => $bike->put_area_id,
  769. 'admin_id' => Admin::user()->id,
  770. 'reason' => $reason,
  771. 'merchant_id' => AdminMerchant::putMerchantId()
  772. ];
  773. $work_order_verify = [
  774. 'bike_id' => $bike->id,
  775. 'type' => $trouble_part,
  776. 'status' => WorkOrder::STATUS_NO,
  777. 'merchant_id' => AdminMerchant::putMerchantId()
  778. ];
  779. WorkOrder::firstOrCreate($work_order_verify, $work_order_data);
  780. DB::commit();
  781. return $this->ok('报修成功');
  782. } catch (\Exception $exception) {
  783. DB::rollBack();
  784. Log::info($exception->getMessage());
  785. return $this->error('操作失败请联系管理员');
  786. }
  787. } else {
  788. return $this->error('找不到该车辆信息');
  789. }
  790. } else {
  791. return $this->error('参数错误');
  792. }
  793. }
  794. /**
  795. * generateTroubleNo 生成故障号
  796. *
  797. * @return string
  798. * @author Fx
  799. *
  800. */
  801. private function generateTroubleNo()
  802. {
  803. $time = date('YmdHis', time());
  804. $randNum = mt_rand(1111, 9999);
  805. return $time . $randNum;
  806. }
  807. /**
  808. * bikeList 车辆列表
  809. *
  810. * @param BikeFilter $filter
  811. * @return \Illuminate\Http\JsonResponse
  812. * @author Fx
  813. *
  814. */
  815. public function bikeList(BikeFilter $filter)
  816. {
  817. $area_ids = self::$areaIds;
  818. $bikelist = Bike::query()
  819. ->where(AdminMerchant::getMerchantWhere())
  820. ->whereIn('put_area_id', $area_ids)
  821. ->whereNotNull('box_no')
  822. ->filter($filter)
  823. ->orderByDesc('id')
  824. ->paginate();
  825. return $this->ok(BikeResource::collection($bikelist));
  826. }
  827. /**
  828. * bikeStatistics 车辆统计
  829. *
  830. * @param BikeFilter $filter
  831. * @return \Illuminate\Http\JsonResponse
  832. * @author Fx
  833. *
  834. */
  835. public function bikeStatistics(BikeFilter $filter)
  836. {
  837. $data = [];
  838. $area_ids = self::$areaIds;
  839. // 总车辆数
  840. $data['total_bikes'] = Bike::query()
  841. ->where(AdminMerchant::getMerchantWhere())
  842. ->whereIn('put_area_id', $area_ids)
  843. ->filter($filter)
  844. ->count('id');
  845. // 上线车辆数
  846. $data['put_total_bikes'] = Bike::query()
  847. ->whereIn('put_area_id', $area_ids)
  848. ->where(AdminMerchant::getMerchantWhere())
  849. ->filter($filter)
  850. ->where('put_status', Bike::PUT_STATUS_YES)
  851. ->count('id');
  852. // 在线车辆数
  853. $data['line_total_bikes'] = Bike::query()
  854. ->where(AdminMerchant::getMerchantWhere())
  855. ->whereIn('put_area_id', $area_ids)
  856. ->filter($filter)
  857. ->where('is_link', Bike::LINK_ONLINE)
  858. ->count('id');
  859. //故障车辆
  860. $data['trouble_total_bikes'] = Bike::query()
  861. ->where(AdminMerchant::getMerchantWhere())
  862. ->whereIn('put_area_id', $area_ids)
  863. ->filter($filter)
  864. ->where('is_trouble', Bike::TROUBLE_YES)
  865. ->count('id');
  866. //今日使用
  867. $data['today_use_total_bikes'] = Bike::query()
  868. ->where(AdminMerchant::getMerchantWhere())
  869. ->whereIn('put_area_id', $area_ids)
  870. ->filter($filter)
  871. ->where('last_use_bike_end_time', '>', Carbon::today())
  872. ->count('id');
  873. //低电量
  874. $data['low_battery_total_bikes'] = Bike::query()
  875. ->where(AdminMerchant::getMerchantWhere())
  876. ->whereIn('put_area_id', $area_ids)
  877. ->filter($filter)
  878. ->where('is_low_battery_power', Bike::BATTERY_POWER_LOW)
  879. ->count('id');
  880. //骑行中
  881. $data['riding_total_bikes'] = Bike::query()
  882. ->where(AdminMerchant::getMerchantWhere())
  883. ->whereIn('put_area_id', $area_ids)
  884. ->filter($filter)
  885. ->where('is_riding', Bike::RIDING_YES)
  886. ->count('id');
  887. //未使用
  888. $data['not_riding_total_bikes'] = Bike::query()
  889. ->where(AdminMerchant::getMerchantWhere())
  890. ->whereIn('put_area_id', $area_ids)
  891. ->filter($filter)
  892. ->where('is_riding', Bike::RIDING_NO)
  893. ->count('id');
  894. return $this->ok($data);
  895. }
  896. /**
  897. * bikeLogin 车辆上线 (投放)
  898. *
  899. * @param Request $request
  900. * @return \Illuminate\Http\JsonResponse
  901. * @author Fx
  902. *
  903. */
  904. public function bikeLogin(Request $request)
  905. {
  906. $bike_id = $request->get('bike_id') ?? '';
  907. if (empty($bike_id)) return $this->error('参数错误');
  908. try {
  909. DB::beginTransaction();
  910. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->find($bike_id);
  911. if (empty($bike)) return $this->error('找不到车辆');
  912. if ($bike->put_status == Bike::PUT_STATUS_YES) return $this->error('车辆已在线');
  913. // 更新车辆上线
  914. $bike->put_status = Bike::PUT_STATUS_YES;
  915. $bike->save();
  916. // 插入上线记录
  917. $worker_bike_operate = new WorkerBikeOperate();
  918. $worker_bike_operate->type = WorkerBikeOperate::TYPE_ONLINE;
  919. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_ONLINE];
  920. $worker_bike_operate->reason = "工作人员操作上线";
  921. $last_location = object_array(json_decode($bike->last_location));
  922. $worker_bike_operate->bike_id = $bike_id;
  923. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  924. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  925. $worker_bike_operate->worker_id = Admin::user()->id;
  926. $worker_bike_operate->merchant_id = AdminMerchant::putMerchantId();
  927. $worker_bike_operate->save();
  928. //更新redis
  929. $lastLocation = LocationsLog::getNewestLocationByBikeNo($bike->bike_no);
  930. (new BikeStatusInfoSyncHandler())->toBikeOnLineStatus($bike->bike_no, $lastLocation['lng'], $lastLocation['lat'], $bike->merchant_id);
  931. DB::commit();
  932. return $this->ok('操作成功');
  933. } catch (\Exception $e) {
  934. DB::rollBack();
  935. Log::error($e->getMessage());
  936. return $this->error('操作失败,请联系管理员');
  937. }
  938. }
  939. /**
  940. * bikeLogout 车辆下线(不投放)
  941. *
  942. * @param Request $request
  943. * @return \Illuminate\Http\JsonResponse
  944. * @author Fx
  945. *
  946. */
  947. public function bikeLogout(Request $request)
  948. {
  949. $bike_id = $request->get('bike_id') ?? '';
  950. if (empty($bike_id)) return $this->error('参数错误');
  951. try {
  952. DB::beginTransaction();
  953. $bike = Bike::query()->find($bike_id);
  954. if (empty($bike)) return $this->error('找不到车辆');
  955. if ($bike->put_status == Bike::PUT_STATUS_NO) return $this->error('车辆已下线');
  956. // 更新车辆下线
  957. $bike->put_status = Bike::PUT_STATUS_NO;
  958. $bike->save();
  959. // 插入下线记录
  960. $worker_bike_operate = new WorkerBikeOperate();
  961. $worker_bike_operate->type = WorkerBikeOperate::TYPE_OFFLINE;
  962. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_OFFLINE];
  963. $worker_bike_operate->reason = "工作人员操作下线";
  964. $last_location = object_array(json_decode($bike->last_location));
  965. $worker_bike_operate->bike_id = $bike_id;
  966. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  967. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  968. $worker_bike_operate->worker_id = Admin::user()->id;
  969. $worker_bike_operate->merchant_id = AdminMerchant::putMerchantId();
  970. $worker_bike_operate->save();
  971. // 更新redis
  972. (new BikeStatusInfoSyncHandler())->toBikeOffLineStatus($bike->bike_no);
  973. DB::commit();
  974. return $this->ok('操作成功');
  975. } catch (\Exception $e) {
  976. DB::rollBack();
  977. Log::error($e->getMessage());
  978. return $this->error('操作失败,请联系管理员');
  979. }
  980. }
  981. /**
  982. * bikeBell 响铃
  983. *
  984. * @param Request $request
  985. * @return \Illuminate\Http\JsonResponse
  986. * @author Fx
  987. *
  988. */
  989. public function bikeBell(Request $request)
  990. {
  991. $bike_id = $request->get('bike_id') ?? '';
  992. if (empty($bike_id)) return $this->error('参数错误');
  993. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('id', $bike_id)->first();
  994. if (empty($bike)) return $this->error('找不到车辆');
  995. // $box_no = "003448483"; // 测试写死
  996. $box_no = $bike->box_no;
  997. $bool = (new BaseBikeControl($box_no))::bellBike();
  998. if ($bool) {
  999. return $this->ok('操作成功,请寻找响铃车辆');
  1000. } else {
  1001. return $this->error('操作失败,请联系管理员');
  1002. }
  1003. }
  1004. /**
  1005. * openBikeLock 开锁
  1006. *
  1007. * @param Request $request
  1008. * @return \Illuminate\Http\JsonResponse
  1009. * @author Fx
  1010. *
  1011. */
  1012. public function openBikeLock(Request $request)
  1013. {
  1014. $bike_id = $request->get('bike_id') ?? '';
  1015. if (empty($bike_id)) return $this->error('参数错误');
  1016. $bike = Bike::query()->find($bike_id);
  1017. if (empty($bike)) return $this->error('找不到车辆');
  1018. $box_no = $bike->box_no;
  1019. try {
  1020. // 增加worker操作车辆记录
  1021. $worker_bike_operate = new WorkerBikeOperate();
  1022. $worker_bike_operate->type = WorkerBikeOperate::TYPE_OPEN_BIKE_LOCK;
  1023. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_OPEN_BIKE_LOCK];
  1024. $worker_bike_operate->bike_id = $bike_id;
  1025. $last_location = object_array(json_decode($bike->last_location));
  1026. // Log::info($last_location);
  1027. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  1028. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  1029. $worker_bike_operate->reason = "工作人员开锁";
  1030. $worker_bike_operate->worker_id = Admin::user()->id;
  1031. $worker_bike_operate->merchant_id = AdminMerchant::getMchId();
  1032. $worker_bike_operate->save();
  1033. } catch (\Exception $e) {
  1034. Log::error($e);
  1035. return $this->error('开锁失败,请联系管理员');
  1036. }
  1037. $bool = (new BaseBikeControl($box_no))::openLock();
  1038. if ($bool) {
  1039. // DB::beginTransaction();
  1040. try {
  1041. $bike->is_lock = Bike::LOCK_NO;
  1042. $bike->save();
  1043. AutoCloseBikeLockJob::dispatch($bike)->delay(Carbon::now()->addMinutes(config('queue.delay.autoCloseBikeLock')));
  1044. // 修改redis
  1045. $is_riding = $bike->is_riding;
  1046. if (!(bool)$is_riding) {
  1047. (new BikeStatusInfoSyncHandler())->toBikeRideStatus(BikeStatusInfoSyncHandler::ROLE_WORKER, $bike->bike_no, ['id' => Admin::user()->id, 'area_id' => $bike->put_area_id, 'bike_id' => $bike_id]);
  1048. }
  1049. /* // 更新orders redis
  1050. Redis::connection()->hset('ride_orders', $order->bike_no, serialize([
  1051. 'id' => $order->id,
  1052. 'bike_no' => $order->bike_no,
  1053. 'bike_id' => $order->bike_id,
  1054. 'area_id' => $order->area_id
  1055. ]));
  1056. DB::commit();*/
  1057. } catch (\Exception $e) {
  1058. // DB::rollBack();
  1059. Log::error('车辆状态骑行更新失败');
  1060. }
  1061. return $this->ok('操作成功,请寻找响铃车辆');
  1062. } else {
  1063. return $this->error('开锁失败,请联系管理员');
  1064. }
  1065. }
  1066. /**
  1067. * closeBikeLock 关锁
  1068. *
  1069. * @param Request $request
  1070. * @return \Illuminate\Http\JsonResponse
  1071. * @author Fx
  1072. *
  1073. */
  1074. public function closeBikeLock(Request $request)
  1075. {
  1076. $bike_id = $request->get('bike_id') ?? '';
  1077. if (empty($bike_id)) return $this->error('参数错误');
  1078. $bike = Bike::query()->find($bike_id);
  1079. if (empty($bike)) return $this->error('找不到车辆');
  1080. if ((bool)$bike->is_riding) {
  1081. return $this->error('车辆骑行中,不可关锁');
  1082. }
  1083. try {
  1084. // 增加worker操作车辆记录
  1085. $worker_bike_operate = new WorkerBikeOperate();
  1086. $worker_bike_operate->type = WorkerBikeOperate::TYPE_CLOSE_BIKE_LOCK;
  1087. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_CLOSE_BIKE_LOCK];
  1088. $worker_bike_operate->bike_id = $bike_id;
  1089. $last_location = object_array(json_decode($bike->last_location));
  1090. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  1091. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  1092. $worker_bike_operate->reason = "工作人员关锁";
  1093. $worker_bike_operate->worker_id = Admin::user()->id;
  1094. $worker_bike_operate->merchant_id = AdminMerchant::putMerchantId();
  1095. $worker_bike_operate->save();
  1096. } catch (\Exception $e) {
  1097. Log::error('关锁记录生成失败');
  1098. return $this->error('关锁失败,请联系管理员');
  1099. }
  1100. // $box_no = "003448483"; // 测试写死
  1101. $box_no = $bike->box_no;
  1102. //添加工作人员操作车辆记录
  1103. // 删除redis订单
  1104. $bike_location = LocationsLog::getNewestLocationByBikeNo($bike->bike_no);
  1105. (new BikeStatusInfoSyncHandler())->toBikeWaitRideStatus($bike->bike_no, $bike_location['lng'], $bike_location['lat'], $bike->put_status);
  1106. $bool = (new BaseBikeControl($box_no))::closeLock();
  1107. if ($bool) {
  1108. try {
  1109. // 车辆改为未骑行
  1110. // $bike->is_riding = Bike::RIDING_NO;
  1111. $bike->last_use_bike_end_time = Carbon::now();
  1112. $bike->is_lock = Bike::LOCK_YES;
  1113. $bike->save();
  1114. $lastLocation = LocationsLog::getNewestLocationByBikeNo($bike->bike_no);
  1115. // 修改redis
  1116. (new BikeStatusInfoSyncHandler())->toBikeWaitRideStatus($bike->bike_no, $lastLocation['lng'], $lastLocation['lat'], $bike->put_status);
  1117. } catch (\Exception $e) {
  1118. Log::error('车辆状态未骑行更新失败');
  1119. }
  1120. return $this->ok('操作成功');
  1121. } else {
  1122. return $this->error('操作失败,请联系管理员');
  1123. }
  1124. }
  1125. /**
  1126. * openBatteryLock 开电池锁
  1127. *
  1128. * @param Request $request
  1129. * @return \Illuminate\Http\JsonResponse
  1130. * @author Fx
  1131. *
  1132. */
  1133. public function openBatteryLock(Request $request)
  1134. {
  1135. $bike_id = $request->get('bike_id') ?? '';
  1136. if (empty($bike_id)) return $this->error('参数错误');
  1137. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('id', $bike_id)->first();
  1138. if (empty($bike)) return $this->error('找不到车辆');
  1139. try {
  1140. // 增加worker操作车辆记录
  1141. $worker_bike_operate = new WorkerBikeOperate();
  1142. $worker_bike_operate->type = WorkerBikeOperate::TYPE_OPEN_BATTERY_LOCK;
  1143. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_OPEN_BATTERY_LOCK];
  1144. $worker_bike_operate->bike_id = $bike_id;
  1145. $last_location = object_array(json_decode($bike->last_location));
  1146. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  1147. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  1148. $worker_bike_operate->reason = "工作人员开电池锁";
  1149. $worker_bike_operate->worker_id = Admin::user()->id;
  1150. $worker_bike_operate->merchant_id = AdminMerchant::putMerchantId();
  1151. $worker_bike_operate->save();
  1152. } catch (\Exception $e) {
  1153. Log::error('开电池锁记录生成失败');
  1154. return $this->error('开电池锁失败,请联系管理员');
  1155. }
  1156. // $box_no = "003448483"; // 测试写死
  1157. $box_no = $bike->box_no;
  1158. $bool = (new BaseBikeControl($box_no))::openBatteryLock();
  1159. if ($bool) {
  1160. return $this->ok('操作开电池锁成功');
  1161. } else {
  1162. return $this->error('开电池锁失败,请联系管理员');
  1163. }
  1164. }
  1165. /**
  1166. * rebootBox 重启中控
  1167. *
  1168. * @param Request $request
  1169. * @return \Illuminate\Http\JsonResponse
  1170. * @author Fx
  1171. *
  1172. */
  1173. public function rebootBox(Request $request)
  1174. {
  1175. $bike_id = $request->get('bike_id') ?? '';
  1176. if (empty($bike_id)) return $this->error('参数错误');
  1177. // $bike = Bike::query()->find($bike_id);
  1178. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('id', $bike_id)->first();
  1179. if (empty($bike)) return $this->error('找不到车辆');
  1180. try {
  1181. // 增加worker操作车辆记录
  1182. $worker_bike_operate = new WorkerBikeOperate();
  1183. $worker_bike_operate->type = WorkerBikeOperate::TYPE_REBOOT_BOX;
  1184. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_REBOOT_BOX];
  1185. $worker_bike_operate->bike_id = $bike_id;
  1186. $last_location = object_array(json_decode($bike->last_location));
  1187. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  1188. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  1189. $worker_bike_operate->reason = "工作人员重启中控";
  1190. $worker_bike_operate->worker_id = Admin::user()->id;
  1191. $worker_bike_operate->merchant_id = AdminMerchant::putMerchantId();
  1192. $worker_bike_operate->save();
  1193. } catch (\Exception $e) {
  1194. Log::error('工作人员重启中控失败');
  1195. return $this->error('工作人员重启中控失败,请联系管理员');
  1196. }
  1197. // $box_no = "003448483"; // 测试写死
  1198. $box_no = $bike->box_no;
  1199. $bool = (new BaseBikeControl($box_no))::rebootBox();
  1200. if ($bool) {
  1201. return $this->ok('重启中控成功');
  1202. } else {
  1203. return $this->error('重启中控失败,请联系管理员');
  1204. }
  1205. }
  1206. /**
  1207. * repairInParking 设为在停车区
  1208. *
  1209. * @param Request $request
  1210. * @return \Illuminate\Http\JsonResponse
  1211. * @author Fx
  1212. *
  1213. */
  1214. public function repairInParking(Request $request)
  1215. {
  1216. $bike_id = $request->get('bike_id') ?? '';
  1217. if (empty($bike_id)) return $this->error('参数错误');
  1218. // $bike = Bike::query()->find($bike_id);
  1219. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('id', $bike_id)->first();
  1220. if (empty($bike)) return $this->error('找不到车辆');
  1221. try {
  1222. $bike->is_in_parking = Bike::IN_PARKING_YES;
  1223. $bike->save();
  1224. return $this->ok('操作成功');
  1225. } catch (\Exception $e) {
  1226. Log::error($e->getMessage());
  1227. return $this->error('操作失败,请联系管理员');
  1228. }
  1229. }
  1230. /**
  1231. * newBikeLocation 立即定位
  1232. *
  1233. * @param Request $request
  1234. * @return \Illuminate\Http\JsonResponse
  1235. * @author Fx
  1236. *
  1237. */
  1238. public function newBikeLocation(Request $request)
  1239. {
  1240. $bike_id = $request->get('bike_id') ?? '';
  1241. if (empty($bike_id)) return $this->error('参数错误');
  1242. // $bike = Bike::query()->find($bike_id);
  1243. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('id', $bike_id)->first();
  1244. if (empty($bike)) return $this->error('找不到车辆');
  1245. try {
  1246. // 增加worker操作车辆记录
  1247. $worker_bike_operate = new WorkerBikeOperate();
  1248. $worker_bike_operate->type = WorkerBikeOperate::TYPE_NOW_BIKE_LOCATION;
  1249. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_NOW_BIKE_LOCATION];
  1250. $worker_bike_operate->bike_id = $bike_id;
  1251. $last_location = object_array(json_decode($bike->last_location));
  1252. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  1253. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  1254. $worker_bike_operate->reason = "工作人员立即定位车辆";
  1255. $worker_bike_operate->worker_id = Admin::user()->id;
  1256. $worker_bike_operate->merchant_id = AdminMerchant::putMerchantId();
  1257. $worker_bike_operate->save();
  1258. } catch (\Exception $e) {
  1259. Log::error('工作人员立即定位车辆失败');
  1260. return $this->error('工作人员立即定位车辆失败,请联系管理员');
  1261. }
  1262. // $box_no = "003448483"; // 测试写死
  1263. $box_no = $bike->box_no;
  1264. $bool = (new BaseBikeControl($box_no))::nowBikeLocation();
  1265. if ($bool) {
  1266. return $this->ok('立即定位车辆成功');
  1267. } else {
  1268. return $this->error('立即定位车辆失败,请联系管理员');
  1269. }
  1270. }
  1271. /**
  1272. * newBikeBatteryMSG 立即更新电池信息
  1273. *
  1274. * @param Request $request
  1275. * @return \Illuminate\Http\JsonResponse
  1276. * @author Fx
  1277. *
  1278. */
  1279. public function newBikeBatteryMSG(Request $request)
  1280. {
  1281. $bike_id = $request->get('bike_id') ?? '';
  1282. if (empty($bike_id)) return $this->error('参数错误');
  1283. // $bike = Bike::query()->find($bike_id);
  1284. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('id', $bike_id)->first();
  1285. if (empty($bike)) return $this->error('找不到车辆');
  1286. try {
  1287. // 增加worker操作车辆记录
  1288. $worker_bike_operate = new WorkerBikeOperate();
  1289. $worker_bike_operate->type = WorkerBikeOperate::TYPE_NOW_BIKE_BATTERY_MSG;
  1290. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_NOW_BIKE_BATTERY_MSG];
  1291. $worker_bike_operate->bike_id = $bike_id;
  1292. $last_location = object_array(json_decode($bike->last_location));
  1293. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  1294. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  1295. $worker_bike_operate->reason = "工作人员立即更新电池信息";
  1296. $worker_bike_operate->worker_id = Admin::user()->id;
  1297. $worker_bike_operate->merchant_id = AdminMerchant::putMerchantId();
  1298. $worker_bike_operate->save();
  1299. } catch (\Exception $e) {
  1300. Log::error('工作人员立即更新电池信息失败');
  1301. return $this->error('工作人员立即更新电池信息失败,请联系管理员');
  1302. }
  1303. // $box_no = "003448483"; // 测试写死
  1304. $box_no = $bike->box_no;
  1305. $bool = (new BaseBikeControl($box_no))::nowBikeBatteryMSG();
  1306. if ($bool) {
  1307. return $this->ok('立即更新电池信息成功');
  1308. } else {
  1309. return $this->error('立即更新电池信息失败,请联系管理员');
  1310. }
  1311. }
  1312. /**
  1313. * closeBatteryLock 关电池锁
  1314. *
  1315. * @param Request $request
  1316. * @return \Illuminate\Http\JsonResponse
  1317. * @author Fx
  1318. *
  1319. */
  1320. public function closeBatteryLock(Request $request)
  1321. {
  1322. $bike_id = $request->get('bike_id') ?? '';
  1323. if (empty($bike_id)) return $this->error('参数错误');
  1324. // $bike = Bike::query()->find($bike_id);
  1325. $bike = Bike::query()->where(AdminMerchant::getMerchantWhere())->where('id', $bike_id)->first();
  1326. if (empty($bike)) return $this->error('找不到车辆');
  1327. try {
  1328. // 增加worker操作车辆记录
  1329. $worker_bike_operate = new WorkerBikeOperate();
  1330. $worker_bike_operate->type = WorkerBikeOperate::TYPE_CLOSE_BATTERY_LOCK;
  1331. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_CLOSE_BATTERY_LOCK];
  1332. $worker_bike_operate->bike_id = $bike_id;
  1333. $last_location = object_array(json_decode($bike->last_location));
  1334. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  1335. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  1336. $worker_bike_operate->reason = "工作人员开电池锁";
  1337. $worker_bike_operate->worker_id = Admin::user()->id;
  1338. $worker_bike_operate->merchant_id = AdminMerchant::putMerchantId();
  1339. $worker_bike_operate->save();
  1340. } catch (\Exception $e) {
  1341. Log::error('关电池锁记录生成失败');
  1342. return $this->error('关电池锁失败,请联系管理员');
  1343. }
  1344. // $box_no = "003448483"; // 测试写死
  1345. $box_no = $bike->box_no;
  1346. $bool = (new BaseBikeControl($box_no))::closeBatteryLock();
  1347. if ($bool) {
  1348. return $this->ok('操作关电池锁成功');
  1349. } else {
  1350. return $this->error('关电池锁失败,请联系管理员');
  1351. }
  1352. }
  1353. /**
  1354. * getKey 获取蓝牙密钥
  1355. *
  1356. * @param Request $request
  1357. * @return \Illuminate\Http\JsonResponse
  1358. * @author Fx
  1359. *
  1360. */
  1361. public function getKey(Request $request)
  1362. {
  1363. $box_no = $request->get('box_no');
  1364. $bike = Bike::where('box_no', $box_no)->where(AdminMerchant::getMerchantWhere())->first();
  1365. $key = $bike->blu_ase_key ?? '';
  1366. return $this->ok(['key' => $key]);
  1367. }
  1368. /**
  1369. * orderLocation 订单轨迹
  1370. *
  1371. * @param Request $request
  1372. * @return \Illuminate\Http\JsonResponse
  1373. * @author Fx
  1374. *
  1375. */
  1376. public function getLocationByBikeNoAndTime(Request $request)
  1377. {
  1378. // $order_id = $request->get('order_id') ?? '';
  1379. $bike_no = $request->get('bike_no') ?? '';
  1380. $time_between = $request->get('time_between') ?? []; // time_between 时间区间
  1381. if (empty($bike_no) || empty($time_between)) return $this->error('参数错误');
  1382. // if (empty($order_id)) return $this->error('参数错误');
  1383. $orderLocations = [];
  1384. $locationsTimes = [];
  1385. try {
  1386. $locationsLog = LocationsLog::where('bike_no', $bike_no)
  1387. ->where('created_at', '>=', Carbon::parse($time_between[0])->toDateString())
  1388. ->where('created_at', '<=', Carbon::parse($time_between[1])->toDateString())
  1389. ->whereBetween('latitude', [3, 53])->whereBetween('longitude', [73, 136])->orderBy('created_at', 'asc')
  1390. ->get();
  1391. // $locationsLog = LocationsLog::query()
  1392. // ->where('order_id', (int)$order_id)
  1393. // ->where('is_rent', LocationsLog::RENT_NO)
  1394. // ->whereBetween('latitude', [3, 53])
  1395. // ->whereBetween('longitude', [73, 136])
  1396. // ->orderBy('created_at', 'asc')->get();
  1397. } catch (\Exception $exception) {
  1398. Log::info($exception->getMessage());
  1399. }
  1400. if (!empty($locationsLog)) {
  1401. // foreach ($locationsLog as $vv) {
  1402. // $orderLocations[] = [$vv->longitude, $vv->latitude];
  1403. // $locationsTimes[] = Carbon::parse($vv->created_at)->format('Y-m-d H:i:s');
  1404. // }
  1405. $data = [];
  1406. $dataTimes = [];
  1407. $userLocation = [];
  1408. $workerLocation = [];
  1409. $noLocatioin = [];
  1410. $old_type = '';
  1411. $item = [];
  1412. $timesData = [];
  1413. $Locations = [];
  1414. foreach ($locationsLog as $v) {
  1415. $data[] = [$v->longitude, $v->latitude];
  1416. $dataTimes[] = Carbon::parse($v->created_at)->format('Y-m-d H:i:s');
  1417. if (empty($old_type)) {
  1418. $old_type = $v->type;
  1419. }
  1420. if ($v->type !== $old_type) {
  1421. if ($old_type == LocationsLog::USER_LOCATION) {
  1422. $userLocation[] = ['locations' => $item, 'times' => $timesData];
  1423. $Locations[] = ['data' => ['locations' => $item, 'times' => $timesData], 'role' => LocationsLog::USER_LOCATION];
  1424. } else if ($old_type == LocationsLog::WORKER_LOCATION) {
  1425. $workerLocation[] = ['locations' => $item, 'times' => $timesData];
  1426. $Locations[] = ['data' => ['locations' => $item, 'times' => $timesData], 'role' => LocationsLog::WORKER_LOCATION];
  1427. } else {
  1428. $noLocatioin[] = ['locations' => $item, 'times' => $timesData];
  1429. $Locations[] = ['data' => ['locations' => $item, 'times' => $timesData], 'role' => LocationsLog::NO_LOCATION];
  1430. }
  1431. $old_type = '';
  1432. $item = [];
  1433. $timesData = [];
  1434. $item[] = [$v->longitude, $v->latitude];
  1435. $timesData[] = Carbon::parse($v->created_at)->format('Y-m-d H:i:s');
  1436. } else {
  1437. $item[] = [$v->longitude, $v->latitude];
  1438. $timesData[] = Carbon::parse($v->created_at)->format('Y-m-d H:i:s');
  1439. }
  1440. unset($v->_id);
  1441. }
  1442. }
  1443. if (empty($data)) return $this->ok($data);
  1444. $wx_data = $locationsLog->toArray();
  1445. $res = [
  1446. 'locations' => $data,
  1447. 'locationsTimes' => $dataTimes,
  1448. 'start_location' => $data[0],
  1449. 'end_location' => end($data),
  1450. 'wx_locations' => $wx_data,
  1451. 'wx_start_location' => $wx_data[0],
  1452. 'wx_end_location' => end($wx_data),
  1453. 'user_location' => $userLocation,
  1454. 'worker_location' => $workerLocation,
  1455. 'no_locatioin' => $noLocatioin,
  1456. 'all_locations' => $Locations
  1457. ];
  1458. return $this->ok($res);
  1459. }
  1460. }