Parking.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. protected $guarded = [];
  29. public function getParkingCentreAttribute($value)
  30. {
  31. return toGaodeCentreData($value);
  32. }
  33. public function getWxParkingCentreAttribute()
  34. {
  35. return $this->attributes['parking_centre'];
  36. }
  37. public function getWxParkingFenceAttribute($value)
  38. {
  39. return $this->attributes['parking_fence'];
  40. }
  41. public function getParkingFenceAttribute($value)
  42. {
  43. return toGaodeFenceData($value);
  44. }
  45. public function setParkingCentreAttribute($value)
  46. {
  47. $this->attributes['parking_centre'] = latToLatitude($value);
  48. }
  49. public function setParkingFenceAttribute($value)
  50. {
  51. $this->attributes['parking_fence'] = latToLatitude($value);
  52. }
  53. public function area()
  54. {
  55. return $this->belongsTo(Area::class, 'area_id', 'id');
  56. }
  57. }