when(isset($where['pid']) && $where['pid'] !== '', function ($query) use ($where) { $query->where('parent_id', $where['pid']); })->when(isset($where['address']) && $where['address'] !== '', function ($query) use ($where) { $address = explode('/', trim($where['address'], '/')); $p = array_shift($address); if (mb_strlen($p) - 1 === mb_strpos($p, '省')) { $p = mb_substr($p, 0, -1); } $pcity = $this->search([])->where('name', $p)->find(); if ($pcity) { $query->whereLike('path', "/{$pcity->id}/%"); } $query->where(function ($query) use ($address) { foreach ($address as $item) { if ($item) { $query->whereOr('name', $item); } } }); }); } public function getCityList(CityArea $city) { if (!$city->parent_id) return [$city]; $lst = $this->search([])->where('id', 'in', explode('/', trim($city->path, '/')))->order('id ASC')->select(); $lst[] = $city; return $lst; } }