['pid', 'name', 'data', 'pic', 'sort'], ]; } /** * @notes 获取商品分类列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2024/04/23 10:27 */ public function lists(): array { $pid=Request()->get('pid',0); if($pid==0){ $lists = Cate::where($this->searchWhere) ->where('pid', 0) ->where('children','<>',null) ->field(['id', 'pid', 'name', 'data', 'pic', 'sort']) ->limit($this->limitOffset, $this->limitLength) ->order(['sort' => 'desc','id' => 'desc']) ->select()->toArray(); }else{ $three=Request()->get('three',0); if($three==0){ $where[]=['children','<>','']; $this->where=$where; } $lists = Cate::where($this->searchWhere) ->where($this->where) ->field(['id', 'pid', 'name', 'data', 'pic', 'sort']) ->limit($this->limitOffset, $this->limitLength) ->order(['sort' => 'desc','id' => 'desc']) ->select()->toArray(); } // ->each(function ($item) { // $a = Goodsclass::where('pid', $item['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select(); // $item['children'] = $a; // foreach ($a as $k => &$v) { // $b = Goodsclass::where('pid', $v['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select(); // $v['children'] = $b; // } // })->toArray(); return $lists; // return linear_to_tree($lists, 'children'); } /** * @notes 获取商品分类数量 * @return int * @author likeadmin * @date 2024/04/23 10:27 */ public function count(): int { $pid=Request()->get('pid',0); if($pid==0){ return Cate::where($this->searchWhere)->where('pid', 0) ->where('children','<>',null) ->count(); }else{ return Cate::where($this->searchWhere) ->where($this->where) ->count(); } } }