with(['store' => function($query) { return $query->select(['id', 'logo', 'name']); }]) ->where(['market_id' => $params['market_id']]) ->where('inventory', '>', 0); if (isset($params['type_id']) && $params['type_id']) { $builder->where(['category_id' => $params['type_id']]); } if (isset($params['keyword']) && $params['keyword']) { $builder->where('name', 'like', '%'.$params['keyword'].'%'); } if (isset($params['order_by']) && $params['order_by']) { $sort = $params['sort'] ?? 'desc'; switch ($params['order_by']) { case 'sales': $builder->orderBySales($sort); break; case 'price': $builder->orderByPrice($sort); break; default: $builder->orderByDefault($sort); break; } } $builder->select(['*'])->addSelect(['sales as total_sales']); $paginate = $builder->paginate($params['pagesize']); $goods = $paginate->toArray(); return ['has_more_pages' => $paginate->hasMorePages(), 'goods' => $goods['data']]; } public function doForStores($params) { $builder = Store::query() ->with(['goods' => function($query) { return $query->limit(5) ->select(['*'])->addSelect(['sales as total_sales']); }]) ->where(['market_id' => $params['market_id']]); if (isset($params['store_id']) && $params['store_id']) { $builder->where(['store_id' => $params['store_id']]); } if (isset($params['type_id']) && $params['type_id']) { $builder->where(['category_id' => $params['type_id']]); } if (isset($params['keyword']) && $params['keyword']) { $builder->where('name', 'like', '%'.$params['keyword'].'%'); } if (isset($params['order_by']) && $params['order_by']) { $sort = $params['sort'] ?? 'desc'; switch ($params['order_by']) { case 'sales': $builder->orderBySales($sort); break; default: $builder->orderByDefault($sort); break; } } $builder->select(['id', 'logo', 'name']); $paginate = $builder->paginate($params['pagesize']); $stores = $paginate->toArray(); return ['has_more_pages' => $paginate->hasMorePages(), 'stores' => $stores['data']]; } public function getHotKeywords($type) { $keywords = [ 'goods' => ['酱油','油','生蚝'], 'store' => ['黄姐','王姐','黄姐蔬菜摊'], ]; return $keywords[$type]; } public function do() { // TODO: Implement do() method. } public function check() { // TODO: Implement check() method. } public function undo() { // TODO: Implement undo() method. } }