Area.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Models;
  3. use App\Maps\CacheMap;
  4. use Carbon\Carbon;
  5. use Illuminate\Support\Facades\Cache;
  6. class Area extends Model
  7. {
  8. protected $guarded = [];
  9. const REDIS_AREAS_LOCATION_TAG = 'areas_locations';
  10. const REDIS_AREAS_TAG = 'areas';
  11. const STATUS_OK = 1;
  12. const STATUS_PAUSE = 0;
  13. public static $statusMaps = [
  14. self::STATUS_OK => '正常',
  15. self::STATUS_PAUSE => '暂停',
  16. ];
  17. public function setting()
  18. {
  19. return $this->hasOne(AreaSetting::class);
  20. }
  21. public function getAreaFenceAttribute($value)
  22. {
  23. return js2php($value);
  24. }
  25. public function getAreaCentreAttribute($value)
  26. {
  27. return js2php($value);
  28. }
  29. public function scopeActive($query)
  30. {
  31. return $query->where('status', self::STATUS_OK);
  32. }
  33. public static function byIdGetMerchantId($id)
  34. {
  35. if (CacheMap::IS_OPEN_DB_CACHE) {
  36. return Cache::remember(CacheMap::DB . "AreaModel:byIdGetMerchantId:" . $id, Carbon::now()->addHours(24), function () use ($id) {
  37. return self::where('id', $id)->value('merchant_id');
  38. });
  39. }
  40. return self::where('id', $id)->value('merchant_id');
  41. }
  42. }