123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- <?php
- namespace App\Http\Controllers\App;
- use App\Filters\AreaFilter;
- use App\Filters\BikeFilter;
- use App\Handlers\BikeStatusInfoSyncHandler;
- use App\Http\Resources\App\BikeResource;
- use App\Models\AdminMerchant;
- use App\Models\AdminUser;
- use App\Models\Area;
- use App\Models\Bike;
- use App\Models\Order;
- use App\Models\Parking;
- use App\Models\WorkOrder;
- use App\Utils\Admin;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- use Illuminate\Support\Facades\Session;
- class IndexController extends AppBaseController
- {
- /**
- * index 首页 获取区域
- *
- * @return \Illuminate\Http\JsonResponse
- * @author Fx
- *
- */
- public function index()
- {
- // $area = Area::query()->whereIn('id', self::$areaIds)->pluck('name', 'id');
- $wx_area = Area::query()->where(AdminMerchant::getMerchantWhere())->whereIn('id', self::$areaIds)->get();
- $area = $wx_area->pluck('name', 'id');
- $wx_data = [];
- if ($wx_area) {
- foreach ($wx_area as $v) {
- $wx_data[] = ['areaID' => $v->id, 'text' => $v->name];
- }
- }
- $bikeStates = Bike::$bikeStatesMaps;
- $wx_bikeStates = [];
- foreach ($bikeStates as $k => $v) {
- $wx_bikeStates[] = ['areaID' => $k, 'text' => $v];
- }
- $data = [
- 'area' => $area,
- 'wx_area' => $wx_data,
- 'bike_states' => $bikeStates,
- 'wx_bikeStates' => $wx_bikeStates,
- ];
- return $this->ok($data);
- }
- /**
- * getBikes 首页搜索车辆
- *
- * @param BikeFilter $filter
- * @return \Illuminate\Http\JsonResponse
- * @author Fx
- *
- */
- public function getBikes(BikeFilter $filter)
- {
- $bikes = Bike::query()
- ->whereIn('put_area_id', self::$areaIds)
- ->whereNotNull('box_no')
- ->filter($filter)
- ->where(AdminMerchant::getMerchantWhere())
- ->orderByDesc('id')
- ->get();
- $worker_bikes = app()->redis->hkeys(BikeStatusInfoSyncHandler::REDIS_RIDE_BIKE_WORKER_ORDERS_TAG);
- $newBikes = [];
- foreach ($bikes as $key => $bike) {
- $location = $bike->last_location ? [json_decode($bike->last_location)->lng, json_decode($bike->last_location)->lat] : [113.801689, 34.815298];
- $newBike = [
- // 'bike_id' => $bike->id,
- 'id' => "B" . $bike->bike_no,
- 'iconPath' => '',
- 'typer' => '',
- 'width' => 28,
- 'height' => 28,
- 'zIndex' => 1111,
- 'latitude' => $location[1],
- 'longitude' => $location[0],
- ];
- if (is_array($worker_bikes) && in_array($bike->bike_no, $worker_bikes)) {
- $newBike['iconPath'] = self::$url . '/bike_yunwei/work.png';
- $newBike['typer'] = 'bike_worker_riding';
- } elseif (!(bool)$bike->is_link) {
- // 离线
- $newBike['iconPath'] = self::$url . '/bike_yunwei/outLi.png';
- $newBike['typer'] = 'lixian';
- } elseif ((bool)$bike->is_trouble) {
- // 故障上线
- if ((bool)$bike->put_status) {
- $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/repair_xbm.png';
- $newBike['typer'] = 'bike_trouble';
- } else {
- // 故障下线
- $newBike['iconPath'] = self::$url . '/trobole.png';
- $newBike['typer'] = 'trouble';
- }
- } elseif ((bool)$bike->is_riding) {
- //骑行中
- $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/riding_xbm.png';
- $newBike['typer'] = 'bike_riding';
- } elseif (!(bool)$bike->is_low_battery_power) {
- // 低电量
- $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/lowPower_xbm.png';
- $newBike['typer'] = 'bike_low_power';
- } elseif (!(bool)$bike->put_status) {
- // 下线 未投放
- $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/outline_xbm.png';
- $newBike['typer'] = 'bike_off_line';
- } elseif (!(bool)$bike->is_in_parking) {
- // 不在停车区
- $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/noInPark_xbm.png';
- $newBike['typer'] = 'bike_not_in_parking';
- } else {
- // 未骑行
- $newBike['iconPath'] = self::$url . '/xiaobanma_yunwei/noUser_xbm.png';
- $newBike['typer'] = 'bike_not_riding';
- }
- $newBikes[] = $newBike;
- }
- return $this->ok($newBikes);
- }
- /**
- * searchBikes 首页搜索
- *
- * @param BikeFilter $filter
- * @return \Illuminate\Http\JsonResponse
- * @author Fx
- *
- */
- public function searchBikes(BikeFilter $filter)
- {
- $bike = Bike::query()
- ->whereIn('put_area_id', self::$areaIds)
- ->where(AdminMerchant::getMerchantWhere())
- ->filter($filter)
- ->orderByDesc('id')
- ->get();
- return $this->ok(BikeResource::collection($bike));
- }
- /**
- * getAreas 还车点 骑行区
- *
- * @param Request $request
- * @param AreaFilter $areaFilter
- * @return \Illuminate\Http\JsonResponse
- * @author Fx
- */
- public function getAreas(Request $request, AreaFilter $areaFilter)
- {
- $areaIds = self::$areaIds;
- // 骑行区
- $ridding_area = Area::query()->filter($areaFilter)->whereIn('id', $areaIds)->where(AdminMerchant::getMerchantWhere());
- $is_with_parking = $request->get('is_with_parking', 1);
- if ($is_with_parking) {
- // 停车点
- $parking_area = Parking::query()->whereIn('area_id', $areaIds)->where('type', Parking::TYPE_STOP_BIKE)->where('status', Parking::STATUS_OK); //2为停车区
- //禁停区
- $no_parking_area = Parking::query()->whereIn('area_id', $areaIds)->where('type', Parking::TYPE_NO_STOP_BIKE)->where('status', Parking::STATUS_OK); //1为禁停
- }
- $area_id = $request->get('put_area_id') ?? '';
- if (!empty($area_id)) {
- $ridding_area = $ridding_area->where('id', $area_id);
- if ($is_with_parking) {
- $parking_area = $parking_area->where('area_id', $area_id);
- $no_parking_area = $no_parking_area->where('area_id', $area_id);
- }
- }
- $ridding_area = $ridding_area->get();
- $ridding_areas = [];
- foreach ($ridding_area as $v) {
- $area = [
- 'points' => json_decode($v->wx_area_fence),
- 'strokeWidth' => 4,
- 'strokeColor' => '#0000FF',
- 'fillColor' => '#0000FF10',
- 'zIndex' => 999,
- 'id' => 'A' . $v->id
- ];
- $ridding_areas[] = $area;
- }
- if (!$is_with_parking) {
- $data = [
- 'ridding_area' => $ridding_areas,
- ];
- return $this->ok($data);
- }
- $parking_area = $parking_area->orderByDesc('id')->get();
- $no_parking_area = $no_parking_area->orderByDesc('id')->get();
- $parink_areas = [];
- $parink_points = [];
- foreach ($parking_area as $key => $v1) {
- $parink_area = [
- 'points' => json_decode($v1->wx_parking_fence),
- 'strokeWidth' => 4,
- 'strokeColor' => '#ff00ff',
- 'fillColor' => '#ff00ff22',
- 'zIndex' => $key,
- 'id' => 'P' . $v1->id
- ];
- $center = json_decode($v1->wx_parking_centre, true);
- $point = [
- 'latitude' => $center['latitude'],
- 'longitude' => $center['longitude'],
- 'zIndex' => $key,
- 'id' => 'p' . $v1->id,
- 'width' => 24,
- 'height' => 28,
- 'iconPath' => self::$url . '/yunwei/parkShow.png',
- ];
- $parink_areas[] = $parink_area;
- $parink_points[] = $point;
- }
- $no_parink_areas = [];
- $no_parink_points = [];
- foreach ($no_parking_area as $key => $v2) {
- $parink_area = [
- 'points' => json_decode($v2->wx_parking_fence),
- 'strokeWidth' => 4,
- 'strokeColor' => '#ff0000',
- 'fillColor' => '#ff000022',
- 'zIndex' => $key,
- 'id' => 'N' . $v2->id
- ];
- $center = json_decode($v2->wx_parking_centre, true);
- $point = [
- 'latitude' => $center['latitude'],
- 'longitude' => $center['longitude'],
- 'zIndex' => $key,
- 'id' => 'n' . $v2->id,
- 'width' => 24,
- 'height' => 28,
- 'iconPath' => self::$url . '/yunwei/forbid.png',
- ];
- $no_parink_areas[] = $parink_area;
- $no_parink_points[] = $point;
- }
- $data = [
- 'ridding_area' => $ridding_areas,
- 'parking_area' => $parink_areas,
- 'parking_points' => $parink_points,
- 'no_parking_area' => $no_parink_areas,
- 'no_parking_points' => $no_parink_points,
- ];
- return $this->ok($data);
- }
- }
|