ParkingResource.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace App\Http\Resources\App;
  3. use App\Models\Parking;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class ParkingResource extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @return array
  12. */
  13. public function toArray($request)
  14. {
  15. $model = $this->resource;
  16. $parking_fence = json_decode($model->parking_fence);
  17. $parking_centre = json_decode($model->parking_centre, true);
  18. $parking_fence_wx = [];
  19. foreach ($parking_fence as $v) {
  20. $parking_fence_wx[] = ['longitude' => $v[0], 'latitude' => $v[1]];
  21. }
  22. if ($model->type == Parking::TYPE_STOP_BIKE) {
  23. // 停车区
  24. $parink_area = [
  25. 'points' => $parking_fence_wx,
  26. 'strokeWidth' => 4,
  27. 'strokeColor' => '#ff00ff',
  28. 'fillColor' => '#ff00ff22',
  29. 'zIndex' => $model->id,
  30. 'id' => 'P' . $model->id
  31. ];
  32. $point = [
  33. 'latitude' => $parking_centre[1],
  34. 'longitude' => $parking_centre[0],
  35. 'zIndex' => $model->id,
  36. 'id' => 'p' . $model->id,
  37. 'width' => 24,
  38. 'height' => 28,
  39. 'iconPath' => 'http://resource.bike.hanyiyun.com/yunwei/parkShow.png',
  40. ];
  41. } else {
  42. // 禁停区
  43. $parink_area = [
  44. 'points' => $parking_fence_wx,
  45. 'strokeWidth' => 4,
  46. 'strokeColor' => '#ff0000',
  47. 'fillColor' => '#ff000022',
  48. 'zIndex' => $model->id,
  49. 'id' => 'N' . $model->id
  50. ];
  51. $point = [
  52. 'latitude' => $parking_centre[1],
  53. 'longitude' => $parking_centre[0],
  54. 'name' => $model->name,
  55. 'zIndex' => $model->id,
  56. 'id' => 'n' . $model->id,
  57. 'width' => 24,
  58. 'height' => 28,
  59. 'iconPath' => 'http://resource.bike.hanyiyun.com/yunwei/forbid.png',
  60. ];
  61. }
  62. return [
  63. 'id' => $model->id,
  64. 'area_id' => $model->area_id,
  65. 'name' => $model->name,
  66. 'area_name' => $model->area->name,
  67. 'max_number' => $model->max_number,
  68. 'parking_fence' => $parking_fence_wx,
  69. 'parking_centre' => ['longitude' => $parking_centre[0], 'latitude' => $parking_centre[1]],
  70. 'parking_radius' => $model->parking_radius,
  71. 'type' => $model->type,
  72. 'status' => (bool)$model->status,
  73. 'created_at' => (string)$model->created_at,
  74. 'updated_at' => (string)$model->updated_at,
  75. 'parking_area' => $parink_area,
  76. 'point' => $point,
  77. ];
  78. }
  79. // public function additional($request)
  80. // {
  81. //
  82. // $model = $this->resource;
  83. // $parking_fence = json_decode($model->parking_fence);
  84. // $parking_centre = json_decode($model->parking_centre, true);
  85. // $parking_fence_wx = [];
  86. // foreach ($parking_fence as $v) {
  87. // $parking_fence_wx[] = ['longitude' => $v[0], 'latitude' => $v[1]];
  88. // }
  89. // if ($model->type == Parking::TYPE_STOP_BIKE) {
  90. // // 停车区
  91. // $parink_area = [
  92. // 'points' => $parking_fence_wx,
  93. // 'strokeWidth' => 4,
  94. // 'strokeColor' => '#ff00ff',
  95. // 'fillColor' => '#ff00ff22',
  96. // 'zIndex' => $model->id,
  97. // 'id' => 'P' . $model->id
  98. // ];
  99. //
  100. // $point = [
  101. // 'latitude' => $parking_centre[1],
  102. // 'longitude' => $parking_centre[0],
  103. // 'zIndex' => $model->id,
  104. // 'id' => 'p' . $model->id,
  105. // 'width' => 24,
  106. // 'height' => 28,
  107. // 'iconPath' => 'http://resource.bike.hanyiyun.com/yunwei/parkShow.png',
  108. // ];
  109. // } else {
  110. // // 禁停区
  111. //
  112. // $parink_area = [
  113. // 'points' => $parking_fence_wx,
  114. // 'strokeWidth' => 4,
  115. // 'strokeColor' => '#ff0000',
  116. // 'fillColor' => '#ff000022',
  117. // 'zIndex' => $model->id,
  118. // 'id' => 'N' . $model->id
  119. // ];
  120. //
  121. // $point = [
  122. // 'latitude' => $parking_centre[1],
  123. // 'longitude' => $parking_centre[0],
  124. // 'zIndex' => $model->id,
  125. // 'id' => 'n' . $model->id,
  126. // 'width' => 24,
  127. // 'height' => 28,
  128. // 'iconPath' => 'http://resource.bike.hanyiyun.com/yunwei/forbid.png',
  129. // ];
  130. // }
  131. // return [
  132. // 'data' => [
  133. // 'parking_area' => $parink_area,
  134. // 'point' => $point,
  135. // ]
  136. //
  137. // ];
  138. // }
  139. }