123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace App\Models;
- use App\Traits\ModelHelpers;
- use Illuminate\Database\Eloquent\Model;
- class Area extends Model
- {
- //
- use ModelHelpers;
- const STATUS_OK = 1;
- const STATUS_PAUSE = 0;
- public static $statusMaps = [
- self::STATUS_OK => '正常',
- self::STATUS_PAUSE => '暂停',
- ];
- // 区域中心位置(redis)
- const REDIS_AREAS_LOCATION_TAG = 'areas_locations';
- const REDIS_AREAS_TAG = 'areas';
- protected $fillable = ['name', 'admin_id', 'area_fence', 'area_fushe_fence','area_centre', 'area_radius', 'customer_service_time', 'customer_service_phone', 'status','merchant_id'];
- // public function getCustomerServiceTimeAttribute($value){
- // $arr = json_decode($value);
- // $str = date('H:i:s',strtotime($arr[0])).'--'.date('H:i:s',strtotime($arr[1]));
- // return $str;
- // }
- public function getAreaCentreAttribute($value)
- {
- return toGaodeCentreData($value);
- }
- public function getWxAreaCentreAttribute()
- {
- return $this->attributes['area_centre'];
- }
- public function getAreaFenceAttribute($value)
- {
- return toGaodeFenceData($value);
- }
- public function getAreaFusheFenceAttribute($value)
- {
- return toGaodeFenceData($value);
- }
- public function getWxAreaFenceAttribute()
- {
- return $this->attributes['area_fence'];
- }
- public function setAreaCentreAttribute($value)
- {
- $this->attributes['area_centre'] = latToLatitude($value);
- }
- public function setAreaFenceAttribute($value)
- {
- $this->attributes['area_fence'] = latToLatitude($value);
- }
- public function setAreaFusheFenceAttribute($value)
- {
- $this->attributes['area_fushe_fence'] = latToLatitude($value);
- }
- public function parking()
- {
- return $this->hasMany(Parking::class, 'area_id', 'id');
- }
- public function areaSetting()
- {
- return $this->hasOne(AreaSetting::class, 'area_id', 'id');
- }
- // 关联商户表
- public function merchantData()
- {
- return $this->hasOne(AdminMerchant::class, 'id', 'merchant_id');
- }
- public function adminUser()
- {
- return $this->belongsToMany(AdminUser::class, 'admin_area', 'admin_id', 'area_id');
- }
- // protected static function boot()
- // {
- // parent::boot();
- //
- // static::deleting(function ($area) {
- // $area->parking()->delete();
- // $area->areaSetting()->delete();
- // });
- // }
- }
|