first
This commit is contained in:
63
modules/Mall/Models/Region.php
Normal file
63
modules/Mall/Models/Region.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Mall\Models;
|
||||
|
||||
use App\Models\Model;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Region extends Model
|
||||
{
|
||||
|
||||
use Cachable;
|
||||
|
||||
protected $table = 'mall_regions';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Notes: 上级地区
|
||||
* @Author: <C.Jason>
|
||||
* @Date : 2019/11/19 3:01 下午
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(__CLASS__, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 下级地区
|
||||
* @Author: <C.Jason>
|
||||
* @Date : 2019/11/19 3:01 下午
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(__CLASS__, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 获取区划层级名称
|
||||
* @Date : 2021/5/6 1:47 下午
|
||||
* @Author : < Jason.C >
|
||||
* @return string
|
||||
*/
|
||||
public function getDepthNameAttribute(): string
|
||||
{
|
||||
switch ($this->depth) {
|
||||
case 0:
|
||||
return '国家级';
|
||||
case 1:
|
||||
return '省级';
|
||||
case 2:
|
||||
return '市级';
|
||||
case 3:
|
||||
return '区县';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user