|
...
|
...
|
@@ -80,6 +80,7 @@ class VideoTask extends Command |
|
|
|
if (empty($task_project)){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
echo '开始,项目id:'.$task_project->project_id.PHP_EOL;
|
|
|
|
$domainModel = new DomainInfo();
|
|
|
|
$domainInfo = $domainModel->read(['project_id'=>$task_project->project_id]);
|
|
|
|
if($domainInfo === false){
|
|
...
|
...
|
@@ -89,9 +90,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 +177,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{
|
|
|
|
->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 +227,7 @@ class VideoTask extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
//TODO::所有产品
|
|
|
|
$thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
|
|
|
|
$thumb = $this->getRecommendAndHotProducts($keyword_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,38 +243,24 @@ class VideoTask extends Command |
|
|
|
/**
|
|
|
|
* 关键词聚合页-推荐&热门产品
|
|
|
|
*/
|
|
|
|
public function getRecommendAndHotProducts($route,$project_id): ?array
|
|
|
|
public function getRecommendAndHotProducts($keyword_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)){
|
|
|
|
$productsQuery = Product::where("status",1)->where("keyword_id","like","%,".$keyword_id.",%")->limit(13)->get();
|
|
|
|
if (count($productsQuery) > 0){
|
|
|
|
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();
|
|
|
|
if (count($productIds) < 13){
|
|
|
|
$product_all_id = Product::where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20 - count($productIds))->pluck('id')->toArray();
|
|
|
|
$randomData = Product::whereIn("id", $product_all_id)->orderByRaw(DB::raw("FIELD(id, " . implode(',', $product_all_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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$product_all_id = Product::where('thumb','!=',null)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20)->pluck('id')->toArray();
|
|
|
|
$products = Product::whereIn("id", $product_all_id)->orderByRaw(DB::raw("FIELD(id, " . implode(',', $product_all_id) . ")"))->get();
|
|
|
|
}
|
|
|
|
$data = [];
|
|
|
|
if (!empty($products)){
|
|
...
|
...
|
@@ -293,12 +271,13 @@ 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.',';
|
|
|
|
$productModel->edit(['keyword_id'=>$keyword_id],['id'=>$item->id]);
|
|
|
|
$keyword_ids = !empty($keyword_ids) ? ','.$keyword_ids.',' : ',' ;
|
|
|
|
$keyword_id_str = $keyword_ids . $keyword_id.',';
|
|
|
|
$productModel->edit(['keyword_id'=>$keyword_id_str],['id'=>$item->id]);
|
|
|
|
}
|
|
|
|
$data[] = ['url'=>getImageUrl($item->thumb['url']),'title'=>$item->title];
|
|
|
|
}
|
...
|
...
|
|