作者 lyh

修改服務器配置

... ... @@ -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;
}
... ... @@ -254,35 +245,42 @@ class VideoTask extends Command
public function getRecommendAndHotProducts($keyword_id,$project_id): ?array
{
$productIds = [];
$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();
$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("project_id", $project_id)->where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
$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 = array_rand($product_all_id, min($array_count, $number - count($productIds)));
$randomData = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
$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];
}
$randomData = Product::whereIn("id", $project_id_arr)->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();
$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)
{
$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();
$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 = [];
if (!empty($products)){
foreach ($products as $item){
... ... @@ -292,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];
... ...
... ... @@ -422,7 +422,6 @@ class OptimizeController extends BaseController
if($info === false){
$this->response('请先创建视频任务,才能开启',Code::SYSTEM_ERROR);
}
$keywordVideoModel->edit(['status'=>$this->param['status']],['project_id'=>$this->param['project_id']]);
$optimizeModel = new DeployOptimize();
$optimizeModel->edit(['ai_video'=>$this->param['status']],['project_id'=>$this->param['project_id']]);
$this->response('success');
... ...