params['city_id'] ?? ''; $keyword = $this->params['keyword'] ?? ''; $orderSales = $this->params['order_sales'] ?? ''; $commentSales = $this->params['comment_sales'] ?? ''; $price = $this->params['price'] ?? ''; $coachId = $this->params['coach_id'] ?? ''; $sort = []; if($keyword){ $where[] = ['name','like','%'.$keyword.'%']; } if($orderSales){ $sort = ['order_num',$orderSales]; } if($price){ $sort = ['price',$price]; } if($coachId){ $goodsIds = CoachGoodsIndex::where(['coach_id'=>$coachId])->column('goods_id'); $where = ['id','in',$goodsIds]; }else{ $allCityGoodsIds = Goods::alias('G') ->leftjoin('goods_city_index GCI','G.id = GCI.goods_id') ->where(['GCI.id '=>null,'status'=>1]) ->column('G.id'); $cityGoodsIds = Goods::alias('G') ->leftjoin('goods_city_index GCI','G.id = GCI.goods_id') ->where(['status'=>1,'city_id'=>$cityId]) ->column('G.id'); $goodsIds = array_merge($allCityGoodsIds,$cityGoodsIds); empty($goodsIds) && $goodsIds = []; $where[] = ['id','in',implode(',',$goodsIds)]; } if($sort){ $this->sortRaw = implode(' ',$sort); } if($commentSales){ $commentGoodsIds = GoodsComment::where('service_comment','>',3)->column('goods_id'); $goodsIds = Goods::where('id','not in',$commentGoodsIds)->order('sort desc,id desc')->column('id'); $goodsIds = array_merge($commentGoodsIds,$goodsIds); $this->sortRaw = 'field(id,'.implode(',',$goodsIds).')'; } // $sort['sort'] = 'desc'; $this->wehre = $where; } /** * @notes 获取列表 * @return array * @author cjhao * @date 2024/9/3 23:13 */ public function lists(): array { $this->setWhere(); $lists = Goods::where($this->wehre) ->field('id,name,image,price,scribing_price,duration,order_num+virtual_order_num as order_num') ->limit($this->limitOffset, $this->limitLength) ->orderRaw($this->sortRaw) // ->order($this->sort) ->select() ->toArray(); $keyword = $this->params['keyword'] ?? ''; //记录搜索记录 if($this->userId && $keyword){ GoodsSearchLog::create([ 'user_id' => $this->userId, 'keyword' => $keyword ]); } return $lists; } /** * @notes 获取数量 * @return int * @author cjhao * @date 2024/9/3 23:13 */ public function count(): int { return Goods::where($this->wehre) ->count(); } }