47 lines
806 B
PHP
47 lines
806 B
PHP
<?php
|
|
|
|
|
|
|
|
namespace app\common\model\store;
|
|
|
|
|
|
use app\common\model\BaseModel;
|
|
|
|
class CityArea extends BaseModel
|
|
{
|
|
|
|
public static function tablePk(): ?string
|
|
{
|
|
return 'id';
|
|
}
|
|
|
|
public static function tableName(): string
|
|
{
|
|
return 'city_area';
|
|
}
|
|
|
|
public function parent()
|
|
{
|
|
return $this->hasOne(self::class,'id','parent_id');
|
|
}
|
|
|
|
public function getChildrenAttr()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function getHasChildrenAttr()
|
|
{
|
|
$count = self::where('parent_id',$this->id)->count();
|
|
return $count ? true : false;
|
|
}
|
|
|
|
/**
|
|
* @return \think\model\relation\HasMany|\think\model\relation\HasOne
|
|
*/
|
|
public function children()
|
|
{
|
|
return $this->hasMany(self::class, 'parent_id', 'id');
|
|
}
|
|
}
|