Area.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Area extends Model
  6. {
  7. //
  8. use ModelHelpers;
  9. const STATUS_OK = 1;
  10. const STATUS_PAUSE = 0;
  11. public static $statusMaps = [
  12. self::STATUS_OK => '正常',
  13. self::STATUS_PAUSE => '暂停',
  14. ];
  15. // 区域中心位置(redis)
  16. const REDIS_AREAS_LOCATION_TAG = 'areas_locations';
  17. const REDIS_AREAS_TAG = 'areas';
  18. protected $fillable = ['name', 'admin_id', 'area_fence', 'area_fushe_fence','area_centre', 'area_radius', 'customer_service_time', 'customer_service_phone', 'status','merchant_id'];
  19. // public function getCustomerServiceTimeAttribute($value){
  20. // $arr = json_decode($value);
  21. // $str = date('H:i:s',strtotime($arr[0])).'--'.date('H:i:s',strtotime($arr[1]));
  22. // return $str;
  23. // }
  24. public function getAreaCentreAttribute($value)
  25. {
  26. return toGaodeCentreData($value);
  27. }
  28. public function getWxAreaCentreAttribute()
  29. {
  30. return $this->attributes['area_centre'];
  31. }
  32. public function getAreaFenceAttribute($value)
  33. {
  34. return toGaodeFenceData($value);
  35. }
  36. public function getAreaFusheFenceAttribute($value)
  37. {
  38. return toGaodeFenceData($value);
  39. }
  40. public function getWxAreaFenceAttribute()
  41. {
  42. return $this->attributes['area_fence'];
  43. }
  44. public function setAreaCentreAttribute($value)
  45. {
  46. $this->attributes['area_centre'] = latToLatitude($value);
  47. }
  48. public function setAreaFenceAttribute($value)
  49. {
  50. $this->attributes['area_fence'] = latToLatitude($value);
  51. }
  52. public function setAreaFusheFenceAttribute($value)
  53. {
  54. $this->attributes['area_fushe_fence'] = latToLatitude($value);
  55. }
  56. public function parking()
  57. {
  58. return $this->hasMany(Parking::class, 'area_id', 'id');
  59. }
  60. public function areaSetting()
  61. {
  62. return $this->hasOne(AreaSetting::class, 'area_id', 'id');
  63. }
  64. // 关联商户表
  65. public function merchantData()
  66. {
  67. return $this->hasOne(AdminMerchant::class, 'id', 'merchant_id');
  68. }
  69. public function adminUser()
  70. {
  71. return $this->belongsToMany(AdminUser::class, 'admin_area', 'admin_id', 'area_id');
  72. }
  73. // protected static function boot()
  74. // {
  75. // parent::boot();
  76. //
  77. // static::deleting(function ($area) {
  78. // $area->parking()->delete();
  79. // $area->areaSetting()->delete();
  80. // });
  81. // }
  82. }