123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace App\Http\Resources\App;
- use App\Models\Parking;
- use Illuminate\Http\Resources\Json\JsonResource;
- class ParkingResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @param \Illuminate\Http\Request $request
- * @return array
- */
- public function toArray($request)
- {
- $model = $this->resource;
- $parking_fence = json_decode($model->parking_fence);
- $parking_centre = json_decode($model->parking_centre, true);
- $parking_fence_wx = [];
- foreach ($parking_fence as $v) {
- $parking_fence_wx[] = ['longitude' => $v[0], 'latitude' => $v[1]];
- }
- if ($model->type == Parking::TYPE_STOP_BIKE) {
- // 停车区
- $parink_area = [
- 'points' => $parking_fence_wx,
- 'strokeWidth' => 4,
- 'strokeColor' => '#ff00ff',
- 'fillColor' => '#ff00ff22',
- 'zIndex' => $model->id,
- 'id' => 'P' . $model->id
- ];
- $point = [
- 'latitude' => $parking_centre[1],
- 'longitude' => $parking_centre[0],
- 'zIndex' => $model->id,
- 'id' => 'p' . $model->id,
- 'width' => 24,
- 'height' => 28,
- 'iconPath' => 'http://resource.bike.hanyiyun.com/yunwei/parkShow.png',
- ];
- } else {
- // 禁停区
- $parink_area = [
- 'points' => $parking_fence_wx,
- 'strokeWidth' => 4,
- 'strokeColor' => '#ff0000',
- 'fillColor' => '#ff000022',
- 'zIndex' => $model->id,
- 'id' => 'N' . $model->id
- ];
- $point = [
- 'latitude' => $parking_centre[1],
- 'longitude' => $parking_centre[0],
- 'name' => $model->name,
- 'zIndex' => $model->id,
- 'id' => 'n' . $model->id,
- 'width' => 24,
- 'height' => 28,
- 'iconPath' => 'http://resource.bike.hanyiyun.com/yunwei/forbid.png',
- ];
- }
- return [
- 'id' => $model->id,
- 'area_id' => $model->area_id,
- 'name' => $model->name,
- 'area_name' => $model->area->name,
- 'max_number' => $model->max_number,
- 'parking_fence' => $parking_fence_wx,
- 'parking_centre' => ['longitude' => $parking_centre[0], 'latitude' => $parking_centre[1]],
- 'parking_radius' => $model->parking_radius,
- 'type' => $model->type,
- 'status' => (bool)$model->status,
- 'created_at' => (string)$model->created_at,
- 'updated_at' => (string)$model->updated_at,
- 'parking_area' => $parink_area,
- 'point' => $point,
- ];
- }
- // public function additional($request)
- // {
- //
- // $model = $this->resource;
- // $parking_fence = json_decode($model->parking_fence);
- // $parking_centre = json_decode($model->parking_centre, true);
- // $parking_fence_wx = [];
- // foreach ($parking_fence as $v) {
- // $parking_fence_wx[] = ['longitude' => $v[0], 'latitude' => $v[1]];
- // }
- // if ($model->type == Parking::TYPE_STOP_BIKE) {
- // // 停车区
- // $parink_area = [
- // 'points' => $parking_fence_wx,
- // 'strokeWidth' => 4,
- // 'strokeColor' => '#ff00ff',
- // 'fillColor' => '#ff00ff22',
- // 'zIndex' => $model->id,
- // 'id' => 'P' . $model->id
- // ];
- //
- // $point = [
- // 'latitude' => $parking_centre[1],
- // 'longitude' => $parking_centre[0],
- // 'zIndex' => $model->id,
- // 'id' => 'p' . $model->id,
- // 'width' => 24,
- // 'height' => 28,
- // 'iconPath' => 'http://resource.bike.hanyiyun.com/yunwei/parkShow.png',
- // ];
- // } else {
- // // 禁停区
- //
- // $parink_area = [
- // 'points' => $parking_fence_wx,
- // 'strokeWidth' => 4,
- // 'strokeColor' => '#ff0000',
- // 'fillColor' => '#ff000022',
- // 'zIndex' => $model->id,
- // 'id' => 'N' . $model->id
- // ];
- //
- // $point = [
- // 'latitude' => $parking_centre[1],
- // 'longitude' => $parking_centre[0],
- // 'zIndex' => $model->id,
- // 'id' => 'n' . $model->id,
- // 'width' => 24,
- // 'height' => 28,
- // 'iconPath' => 'http://resource.bike.hanyiyun.com/yunwei/forbid.png',
- // ];
- // }
- // return [
- // 'data' => [
- // 'parking_area' => $parink_area,
- // 'point' => $point,
- // ]
- //
- // ];
- // }
- }
|