['name', 'data', 'store_id', '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 { $level = Request()->get('level', 1); $pid = $this->request->get('pid',0); // $this->searchWhere[] = ['stock', '>', 0]; $this->searchWhere[] = ['status', '=', 1]; if($pid && $level ==2){ $this->searchWhere[] = ['top_cate_id','=',$pid]; $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() ->column('two_cate_id'); }elseif($pid && $level ==3){ $this->searchWhere[] = ['two_cate_id','=',$pid]; $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() ->column('cate_id'); }else{ $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() ->column('top_cate_id'); } $lists = []; if ($cate_arr) { return Cate::where('id', 'in', $cate_arr) ->field(['id', 'pid', 'name', 'data', 'pic', 'sort']) ->limit($this->limitOffset, $this->limitLength) ->order(['sort' => 'desc', 'id' => 'desc']) ->select()->toArray(); } return $lists; } /** * @notes 获取商品分类数量 * @return int * @author likeadmin * @date 2024/04/23 10:27 */ public function count(): int { $level = Request()->get('level', 1); $pid = $this->request->get('pid',0); if($pid && $level ==2){ $this->searchWhere[] = ['top_cate_id','=',$pid]; $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() ->column('two_cate_id'); }elseif($pid && $level ==3){ $this->searchWhere[] = ['two_cate_id','=',$pid]; $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() ->column('cate_id'); }else{ $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() ->column('top_cate_id'); } return Cate::where('id', 'in', $cate_arr)->count(); } }