1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Models;
- use App\Maps\CacheMap;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Cache;
- class Area extends Model
- {
- protected $guarded = [];
- const REDIS_AREAS_LOCATION_TAG = 'areas_locations';
- const REDIS_AREAS_TAG = 'areas';
- const STATUS_OK = 1;
- const STATUS_PAUSE = 0;
- public static $statusMaps = [
- self::STATUS_OK => '正常',
- self::STATUS_PAUSE => '暂停',
- ];
- public function setting()
- {
- return $this->hasOne(AreaSetting::class);
- }
- public function getAreaFenceAttribute($value)
- {
- return js2php($value);
- }
- public function getAreaCentreAttribute($value)
- {
- return js2php($value);
- }
- public function scopeActive($query)
- {
- return $query->where('status', self::STATUS_OK);
- }
- public static function byIdGetMerchantId($id)
- {
- if (CacheMap::IS_OPEN_DB_CACHE) {
- return Cache::remember(CacheMap::DB . "AreaModel:byIdGetMerchantId:" . $id, Carbon::now()->addHours(24), function () use ($id) {
- return self::where('id', $id)->value('merchant_id');
- });
- }
- return self::where('id', $id)->value('merchant_id');
- }
- }
|