|
...
|
...
|
@@ -89,9 +89,9 @@ class VideoTask extends Command |
|
|
|
}
|
|
|
|
ProjectServer::useProject($task_project->project_id);
|
|
|
|
if(!empty($task_project->keywords)){
|
|
|
|
$task_project->keywords = explode(',',trim(',',$task_project->keywords));
|
|
|
|
$keywords = explode(',',trim(',',$task_project->keywords));
|
|
|
|
}
|
|
|
|
$keyword = $this->getProjectKeyword($task_project->number,$task_project->keywords);
|
|
|
|
$keyword = $this->getProjectKeyword($task_project->number,$keywords ?? []);
|
|
|
|
// 已经没有需要生成视频的关键词
|
|
|
|
if (!$keyword) {
|
|
|
|
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
|
|
...
|
...
|
@@ -176,24 +176,15 @@ class VideoTask extends Command |
|
|
|
*/
|
|
|
|
public function getProjectKeyword($number,$keywords = [])
|
|
|
|
{
|
|
|
|
if(!empty($keywords)){
|
|
|
|
$keyword_id = Keyword::where('video', null)->whereIn("title", $keywords)
|
|
|
|
->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->pluck('id')->toArray();
|
|
|
|
if(count($keyword_id) == 0){
|
|
|
|
$keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')
|
|
|
|
->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number)->pluck('id')->toArray();
|
|
|
|
}else{
|
|
|
|
$keyword_arr_id = Keyword::where('video', null)->whereNotIn("title", $keywords)->where('route', 'not like', '%-tag')
|
|
|
|
->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number - count($keyword_id))->pluck('id')->toArray();
|
|
|
|
$keyword_arr_id = array_merge($keyword_id,$keyword_arr_id);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$keyword_id = Keyword::where('video', null)->whereIn("title", $keywords)
|
|
|
|
->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->limit($number)->pluck('id')->toArray();
|
|
|
|
$need = $number - count($keyword_id);
|
|
|
|
if ($need > 0) {
|
|
|
|
$keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')
|
|
|
|
->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number)->pluck('id')->toArray();
|
|
|
|
}
|
|
|
|
if(count($keyword_arr_id) == 0){
|
|
|
|
return [];
|
|
|
|
->whereNotNull('keyword_content')->whereNotIn('id', $keyword_id)->orderBy('id','asc')->limit($need)->pluck('id')->toArray();
|
|
|
|
}
|
|
|
|
$keyword_arr_id = array_merge($keyword_id, $keyword_arr_id);
|
|
|
|
$keyword = Keyword::whereIn("id", $keyword_arr_id)->get();
|
|
|
|
return $keyword;
|
|
|
|
}
|
|
...
|
...
|
@@ -235,7 +226,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,37 +242,43 @@ 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);
|
|
|
|
$productKeyword = Keyword::where("id",$keyword_id)->first();
|
|
|
|
$productsQuery = Product::where("status",1)->where("keyword_id","like","%,".$keyword_id.",%")->limit(7)->get();
|
|
|
|
if (!empty($productsQuery)){
|
|
|
|
foreach ($productsQuery as $item){
|
|
|
|
$productIds[] = $item->id;
|
|
|
|
}
|
|
|
|
if (count($productIds)<7){
|
|
|
|
$product_all_id = Product::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_key = array_rand($product_all_id, min($array_count, $number - count($productIds)));
|
|
|
|
foreach ($product_id_key as $value_key){
|
|
|
|
$project_id_arr = $product_all_id[$value_key];
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$products = $productsQuery;
|
|
|
|
$randomData = Product::whereIn("id", $project_id_arr)->get();
|
|
|
|
$products = $productsQuery->merge($randomData);
|
|
|
|
}
|
|
|
|
}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();
|
|
|
|
$products = $productsQuery;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$product_all_id = Product::where('thumb','!=',null)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
|
|
|
|
shuffle($product_all_id);
|
|
|
|
$number = 40;
|
|
|
|
$array_count = count($product_all_id);
|
|
|
|
if ($array_count > 0)
|
|
|
|
{
|
|
|
|
$project_id_arr = [];
|
|
|
|
$product_id_key = array_rand($product_all_id, min($array_count, $number-count($productIds)));
|
|
|
|
foreach ($product_id_key as $value_key){
|
|
|
|
$project_id_arr = $product_all_id[$value_key];
|
|
|
|
}
|
|
|
|
$products = Product::where("project_id", $project_id)->whereIn("id", $project_id_arr)->get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$data = [];
|
|
...
|
...
|
@@ -293,11 +290,11 @@ class VideoTask extends Command |
|
|
|
if(count($data) > 13){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$keyword_id = implode(',',$item->keyword_id);
|
|
|
|
if (strpos(','.$keyword_id.',', ','.$productKeyword->id.',') === false) {
|
|
|
|
$keyword_ids = implode(',',$item->keyword_id);
|
|
|
|
if (strpos(','.$keyword_ids.',', ','.$keyword_id.',') === false) {
|
|
|
|
//不包含
|
|
|
|
$productModel = new Product();
|
|
|
|
$keyword_id = ','.$keyword_id.',' . $productKeyword->id.',';
|
|
|
|
$keyword_id = ','.$keyword_ids.',' . $keyword_id.',';
|
|
|
|
$productModel->edit(['keyword_id'=>$keyword_id],['id'=>$item->id]);
|
|
|
|
}
|
|
|
|
$data[] = ['url'=>getImageUrl($item->thumb['url']),'title'=>$item->title];
|
...
|
...
|
|