Parking.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Parking extends Model
  6. {
  7. //
  8. use ModelHelpers;
  9. // 停车点中心点(redis)
  10. const REDIS_STOP_BIKE_SITES_TAG = 'stop_bike_sites';
  11. const REDIS_BAN_STOP_BIKE_SITE_TAG = 'stop_ban_bike_sites';
  12. // 正确示例
  13. const TYPE_STOP_BIKE = 2;
  14. const TYPE_NO_STOP_BIKE = 1;
  15. public static $typeMaps = [
  16. self::TYPE_STOP_BIKE => '停车区',
  17. self::TYPE_NO_STOP_BIKE => '禁停区'
  18. ];
  19. // 错误示例
  20. // protected $parkingType = [1 => '禁停区', 2 => '停车区'];
  21. const STATUS_OK = 1;
  22. const STATUS_NO = 0;
  23. public static $statusMaps = [
  24. self::STATUS_NO => '禁用',
  25. self::STATUS_OK => '启用',
  26. ];
  27. protected $fillable = ['area_id', 'name', 'max_number', 'parking_fence', 'parking_centre', 'description', 'parking_radius', 'type', 'status'];
  28. public function getParkingCentreAttribute($value)
  29. {
  30. return toGaodeCentreData($value);
  31. }
  32. public function getWxParkingCentreAttribute()
  33. {
  34. return $this->attributes['parking_centre'];
  35. }
  36. public function getWxParkingFenceAttribute($value)
  37. {
  38. return $this->attributes['parking_fence'];
  39. }
  40. public function getParkingFenceAttribute($value)
  41. {
  42. return toGaodeFenceData($value);
  43. }
  44. public function setParkingCentreAttribute($value)
  45. {
  46. $this->attributes['parking_centre'] = latToLatitude($value);
  47. }
  48. public function setParkingFenceAttribute($value)
  49. {
  50. $this->attributes['parking_fence'] = latToLatitude($value);
  51. }
  52. public function area()
  53. {
  54. return $this->belongsTo(Area::class, 'area_id', 'id');
  55. }
  56. }