作者 lyh

gx

... ... @@ -196,24 +196,24 @@ class VideoTask extends Command
/**
* 关键词聚合页-推荐&热门产品
*/
public function getRecommendAndHotProducts($project,$route): ?array
public function getRecommendAndHotProducts($project_id,$route): ?array
{
$productIds = [];
$productKeyword = Keyword::where("project_id",$project->id)->where("route",$route)->first();
$productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first();
if (!empty($productKeyword)){
$productsQuery = Product::where("project_id", $project->id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get();
$productsQuery = Product::where("project_id", $project_id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get();
if (!empty($productsQuery)){
foreach ($productsQuery as $item){
$productIds[] = $item->id;
}
if (count($productIds)<7){
$randomData = Product::where("project_id", $project->id)->where("status",1)->whereNotIn('id', $productIds)->inRandomOrder()->take(13-count($productIds))->get();
$randomData = Product::where("project_id", $project_id)->where("status",1)->whereNotIn('id', $productIds)->inRandomOrder()->take(13-count($productIds))->get();
$products = $productsQuery->merge($randomData);
}else{
$products = $productsQuery;
}
}else{
$products = Product::where("project_id", $project->id)->where("status",1)->inRandomOrder()->take(13)->get();
$products = Product::where("project_id", $project_id)->where("status",1)->inRandomOrder()->take(13)->get();
}
}
$data = [];
... ...
... ... @@ -7,6 +7,8 @@ use App\Enums\Common\Code;
use App\Http\Logic\Aside\LoginLogic;
use App\Models\Domain\DomainInfo;
use App\Models\Manage\Manage;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Models\Sms\SmsLog;
use App\Rules\Mobile;
... ...