when($filter,function ($q){ $q->where("status",self::COMMON_ON); }) ->field("id,code,pcode,name,status") ->order(["sort"=>"desc","id"=>"desc"]) ->select(); } /** * * @param $PCode * @param $filter bool 是否过滤屏蔽的地区 * @return Area[]|array|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function getByPCodes($PCodes,bool $filter = false) { return self::where("pcode","in",$PCodes) ->when($filter,function ($q){ $q->where("status",self::COMMON_ON); }) ->field("id,code,pcode,name,status") ->order(["sort"=>"desc","id"=>"desc"]) ->select() ->toArray(); } // 获取列表 public static function getAllList(): Collection { return self::order('id', 'asc') ->select(); } }