hasMany(self::class, 'parent_id','city_id')->order('id ASC'); } /** * 获取城市数据列表 * @param array $where * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function getList($where = []) { $list = self::withAttr('parent_id', function($value) { if($value == 0){ return '中国'; }else{ return self::where('city_id',$value)->value('name'); } })->where('parent_id', $where['parent_id'])->select()->toArray(); return $list; } }