|
...
|
...
|
@@ -235,7 +235,7 @@ class VideoTask extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
//TODO::所有产品
|
|
|
|
$thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
|
|
|
|
$thumb = $this->getRecommendAndHotProducts($keyword_id,$project_id);
|
|
|
|
$keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray();
|
|
|
|
$data = [
|
|
|
|
'url'=> 'https://' . $domain.'/'.$keywordInfo['route'],
|
|
...
|
...
|
@@ -251,39 +251,38 @@ class VideoTask extends Command |
|
|
|
/**
|
|
|
|
* 关键词聚合页-推荐&热门产品
|
|
|
|
*/
|
|
|
|
public function getRecommendAndHotProducts($route,$project_id): ?array
|
|
|
|
public function getRecommendAndHotProducts($keyword_id,$project_id): ?array
|
|
|
|
{
|
|
|
|
$productIds = [];
|
|
|
|
$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();
|
|
|
|
if (!empty($productsQuery)){
|
|
|
|
foreach ($productsQuery as $item){
|
|
|
|
$productIds[] = $item->id;
|
|
|
|
}
|
|
|
|
if (count($productIds)<7){
|
|
|
|
$product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
|
|
|
|
$number = 40;
|
|
|
|
$array_count = count($product_all_id);
|
|
|
|
if ($array_count > 0) {
|
|
|
|
$product_id = array_rand($product_all_id, min($array_count, $number - count($productIds)));
|
|
|
|
$randomData = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
|
|
|
|
$products = $productsQuery->merge($randomData);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$products = $productsQuery;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
|
|
|
|
$productKeyword = Keyword::where("project_id",$project_id)->where("id",$keyword_id)->first();
|
|
|
|
$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){
|
|
|
|
$product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
|
|
|
|
$number = 40;
|
|
|
|
$array_count = count($product_all_id);
|
|
|
|
if ($array_count > 0)
|
|
|
|
{
|
|
|
|
$product_id = array_rand($product_all_id, min($array_count, $number-count($productIds)));
|
|
|
|
$products = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
|
|
|
|
if ($array_count > 0) {
|
|
|
|
$product_id = array_rand($product_all_id, min($array_count, $number - count($productIds)));
|
|
|
|
$randomData = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
|
|
|
|
$products = $productsQuery->merge($randomData);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$products = $productsQuery;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
|
|
|
|
$number = 40;
|
|
|
|
$array_count = count($product_all_id);
|
|
|
|
if ($array_count > 0)
|
|
|
|
{
|
|
|
|
$product_id = array_rand($product_all_id, min($array_count, $number-count($productIds)));
|
|
|
|
$products = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
if (!empty($products)){
|
|
|
|
foreach ($products as $item){
|
...
|
...
|
|