['delivery_type', 'shop_goods_type', 'goods_name', 'company_name', 'goods_status', 'is_recommend'], ]; } public function queryWhere() { $where = []; if (!empty($this->params['goods_category_id'])) { $goodsCategoryId = end($this->params['goods_category_id']); $goodsCategoryData = ShopCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc']) ->select()->toArray(); $ids =get_tree_ids($goodsCategoryData,$goodsCategoryId); $ids[] = $goodsCategoryId; $where[] = ['goods_category_id','in' ,$ids]; } return $where; } /** * @notes 获取列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2024/08/04 11:07 */ public function lists(): array { $lists = ShopGoods::with(['goodsCategory','goodSpecsInventory'=>function (Query $query) { $query->field(['specs', 'inventory','shop_goods_id','remaining_inventory','service_fee','service_total']); }]) ->where($this->searchWhere) ->where($this->queryWhere()) ->field(['id', 'delivery_type', 'shop_goods_type', 'goods_category_ids', 'goods_category_id', 'goods_name', 'company_name', 'goods_image', 'goods_banners', 'description', 'goods_status', 'is_recommend', 'recommend_weight','specs_type','custom_attribute_items']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->toArray(); foreach ($lists as &$item) { $item['goods_category_ids'] = array_map("intval",$item['goods_category_ids']); } return $lists; } /** * @notes 获取数量 * @return int * @author likeadmin * @date 2024/08/04 11:07 */ public function count(): int { return ShopGoods::where($this->searchWhere)->where($this->queryWhere())->count(); } }