IndexController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. namespace App\Http\Controllers\App;
  3. use App\Filters\AreaFilter;
  4. use App\Filters\BikeFilter;
  5. use App\Handlers\BikeStatusInfoSyncHandler;
  6. use App\Http\Resources\App\BikeResource;
  7. use App\Models\AdminMerchant;
  8. use App\Models\AdminUser;
  9. use App\Models\Area;
  10. use App\Models\Bike;
  11. use App\Models\Order;
  12. use App\Models\Parking;
  13. use App\Models\WorkOrder;
  14. use App\Utils\Admin;
  15. use Illuminate\Http\Request;
  16. use Illuminate\Support\Facades\Log;
  17. use Illuminate\Support\Facades\Redis;
  18. use Illuminate\Support\Facades\Session;
  19. class IndexController extends AppBaseController
  20. {
  21. /**
  22. * index 首页 获取区域
  23. *
  24. * @return \Illuminate\Http\JsonResponse
  25. * @author Fx
  26. *
  27. */
  28. public function index()
  29. {
  30. // $area = Area::query()->whereIn('id', self::$areaIds)->pluck('name', 'id');
  31. $wx_area = Area::query()->where(AdminMerchant::getMerchantWhere())->whereIn('id', self::$areaIds)->get();
  32. $area = $wx_area->pluck('name', 'id');
  33. $wx_data = [];
  34. if ($wx_area) {
  35. foreach ($wx_area as $v) {
  36. $wx_data[] = ['areaID' => $v->id, 'text' => $v->name];
  37. }
  38. }
  39. $bikeStates = Bike::$bikeStatesMaps;
  40. $wx_bikeStates = [];
  41. foreach ($bikeStates as $k => $v) {
  42. $wx_bikeStates[] = ['areaID' => $k, 'text' => $v];
  43. }
  44. $data = [
  45. 'area' => $area,
  46. 'wx_area' => $wx_data,
  47. 'bike_states' => $bikeStates,
  48. 'wx_bikeStates' => $wx_bikeStates,
  49. ];
  50. return $this->ok($data);
  51. }
  52. /**
  53. * getBikes 首页搜索车辆
  54. *
  55. * @param BikeFilter $filter
  56. * @return \Illuminate\Http\JsonResponse
  57. * @author Fx
  58. *
  59. */
  60. public function getBikes(BikeFilter $filter)
  61. {
  62. $bikes = Bike::query()
  63. ->whereIn('put_area_id', self::$areaIds)
  64. ->whereNotNull('box_no')
  65. ->filter($filter)
  66. ->where(AdminMerchant::getMerchantWhere())
  67. ->orderByDesc('id')
  68. ->get();
  69. $worker_bikes = app()->redis->hkeys(BikeStatusInfoSyncHandler::REDIS_RIDE_BIKE_WORKER_ORDERS_TAG);
  70. $newBikes = [];
  71. foreach ($bikes as $key => $bike) {
  72. $location = $bike->last_location ? [json_decode($bike->last_location)->lng, json_decode($bike->last_location)->lat] : [113.801689, 34.815298];
  73. $newBike = [
  74. // 'bike_id' => $bike->id,
  75. 'id' => "B" . $bike->bike_no,
  76. 'iconPath' => '',
  77. 'typer' => '',
  78. 'width' => 28,
  79. 'height' => 28,
  80. 'zIndex' => 1111,
  81. 'latitude' => $location[1],
  82. 'longitude' => $location[0],
  83. ];
  84. if (is_array($worker_bikes) && in_array($bike->bike_no, $worker_bikes)) {
  85. $newBike['iconPath'] = self::$url . '/bike_yunwei/work.png';
  86. $newBike['typer'] = 'bike_worker_riding';
  87. } elseif (!(bool)$bike->is_link) {
  88. // 离线
  89. $newBike['iconPath'] = self::$url . '/bike_yunwei/outLi.png';
  90. $newBike['typer'] = 'lixian';
  91. } elseif ((bool)$bike->is_trouble) {
  92. // 故障上线
  93. if ((bool)$bike->put_status) {
  94. $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/repair_xbm.png';
  95. $newBike['typer'] = 'bike_trouble';
  96. } else {
  97. // 故障下线
  98. $newBike['iconPath'] = self::$url . '/trobole.png';
  99. $newBike['typer'] = 'trouble';
  100. }
  101. } elseif ((bool)$bike->is_riding) {
  102. //骑行中
  103. $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/riding_xbm.png';
  104. $newBike['typer'] = 'bike_riding';
  105. } elseif (!(bool)$bike->is_low_battery_power) {
  106. // 低电量
  107. $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/lowPower_xbm.png';
  108. $newBike['typer'] = 'bike_low_power';
  109. } elseif (!(bool)$bike->put_status) {
  110. // 下线 未投放
  111. $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/outline_xbm.png';
  112. $newBike['typer'] = 'bike_off_line';
  113. } elseif (!(bool)$bike->is_in_parking) {
  114. // 不在停车区
  115. $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/noInPark_xbm.png';
  116. $newBike['typer'] = 'bike_not_in_parking';
  117. } else {
  118. // 未骑行
  119. $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/noUser_xbm.png';
  120. $newBike['typer'] = 'bike_not_riding';
  121. }
  122. $newBikes[] = $newBike;
  123. }
  124. return $this->ok($newBikes);
  125. }
  126. /**
  127. * searchBikes 首页搜索
  128. *
  129. * @param BikeFilter $filter
  130. * @return \Illuminate\Http\JsonResponse
  131. * @author Fx
  132. *
  133. */
  134. public function searchBikes(BikeFilter $filter)
  135. {
  136. $bike = Bike::query()
  137. ->whereIn('put_area_id', self::$areaIds)
  138. ->where(AdminMerchant::getMerchantWhere())
  139. ->filter($filter)
  140. ->orderByDesc('id')
  141. ->get();
  142. return $this->ok(BikeResource::collection($bike));
  143. }
  144. /**
  145. * getAreas 还车点 骑行区
  146. *
  147. * @param Request $request
  148. * @param AreaFilter $areaFilter
  149. * @return \Illuminate\Http\JsonResponse
  150. * @author Fx
  151. */
  152. public function getAreas(Request $request, AreaFilter $areaFilter)
  153. {
  154. $areaIds = self::$areaIds;
  155. // 骑行区
  156. $ridding_area = Area::query()->filter($areaFilter)->whereIn('id', $areaIds)->where(AdminMerchant::getMerchantWhere());
  157. $is_with_parking = $request->get('is_with_parking', 1);
  158. if ($is_with_parking) {
  159. // 停车点
  160. $parking_area = Parking::query()->whereIn('area_id', $areaIds)->where('type', Parking::TYPE_STOP_BIKE)->where('status', Parking::STATUS_OK); //2为停车区
  161. //禁停区
  162. $no_parking_area = Parking::query()->whereIn('area_id', $areaIds)->where('type', Parking::TYPE_NO_STOP_BIKE)->where('status', Parking::STATUS_OK); //1为禁停
  163. }
  164. $area_id = $request->get('put_area_id') ?? '';
  165. if (!empty($area_id)) {
  166. $ridding_area = $ridding_area->where('id', $area_id);
  167. if ($is_with_parking) {
  168. $parking_area = $parking_area->where('area_id', $area_id);
  169. $no_parking_area = $no_parking_area->where('area_id', $area_id);
  170. }
  171. }
  172. $ridding_area = $ridding_area->get();
  173. $ridding_areas = [];
  174. foreach ($ridding_area as $v) {
  175. $area = [
  176. 'points' => json_decode($v->wx_area_fence),
  177. 'strokeWidth' => 4,
  178. 'strokeColor' => '#0000FF',
  179. 'fillColor' => '#0000FF10',
  180. 'zIndex' => 999,
  181. 'id' => 'A' . $v->id
  182. ];
  183. $ridding_areas[] = $area;
  184. }
  185. if (!$is_with_parking) {
  186. $data = [
  187. 'ridding_area' => $ridding_areas,
  188. ];
  189. return $this->ok($data);
  190. }
  191. $parking_area = $parking_area->orderByDesc('id')->get();
  192. $no_parking_area = $no_parking_area->orderByDesc('id')->get();
  193. $parink_areas = [];
  194. $parink_points = [];
  195. foreach ($parking_area as $key => $v1) {
  196. $parink_area = [
  197. 'points' => json_decode($v1->wx_parking_fence),
  198. 'strokeWidth' => 4,
  199. 'strokeColor' => '#ff00ff',
  200. 'fillColor' => '#ff00ff22',
  201. 'zIndex' => $key,
  202. 'id' => 'P' . $v1->id
  203. ];
  204. $center = json_decode($v1->wx_parking_centre, true);
  205. $point = [
  206. 'latitude' => $center['latitude'],
  207. 'longitude' => $center['longitude'],
  208. 'zIndex' => $key,
  209. 'id' => 'p' . $v1->id,
  210. 'width' => 24,
  211. 'height' => 28,
  212. 'iconPath' => self::$url . '/yunwei/parkShow.png',
  213. ];
  214. $parink_areas[] = $parink_area;
  215. $parink_points[] = $point;
  216. }
  217. $no_parink_areas = [];
  218. $no_parink_points = [];
  219. foreach ($no_parking_area as $key => $v2) {
  220. $parink_area = [
  221. 'points' => json_decode($v2->wx_parking_fence),
  222. 'strokeWidth' => 4,
  223. 'strokeColor' => '#ff0000',
  224. 'fillColor' => '#ff000022',
  225. 'zIndex' => $key,
  226. 'id' => 'N' . $v2->id
  227. ];
  228. $center = json_decode($v2->wx_parking_centre, true);
  229. $point = [
  230. 'latitude' => $center['latitude'],
  231. 'longitude' => $center['longitude'],
  232. 'zIndex' => $key,
  233. 'id' => 'n' . $v2->id,
  234. 'width' => 24,
  235. 'height' => 28,
  236. 'iconPath' => self::$url . '/yunwei/forbid.png',
  237. ];
  238. $no_parink_areas[] = $parink_area;
  239. $no_parink_points[] = $point;
  240. }
  241. $data = [
  242. 'ridding_area' => $ridding_areas,
  243. 'parking_area' => $parink_areas,
  244. 'parking_points' => $parink_points,
  245. 'no_parking_area' => $no_parink_areas,
  246. 'no_parking_points' => $no_parink_points,
  247. ];
  248. return $this->ok($data);
  249. }
  250. }