作者 lyh

gx

... ... @@ -16,6 +16,7 @@ use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
... ... @@ -87,7 +88,7 @@ class VideoTask extends Command
continue;
}
ProjectServer::useProject($task_project->project_id);
$keyword = $this->getProjectKeyword($task_project->num);
$keyword = $this->getProjectKeyword($task_project->number,$task_project->keywords);
// 已经没有需要生成视频的关键词
if (!$keyword) {
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
... ... @@ -95,13 +96,7 @@ class VideoTask extends Command
continue;
}
$logo_bg = $this->getImage($domainInfo);
$num = $task_project->num;
foreach ($keyword as $val) {
if($sub_task_num == 0){
$task_project->num = $num;
$task_project->save();
break;
}
$log = KeywordVideoTaskLog::where(['project_id' => $task_project->project_id, 'keyword_id' => $val->id])->first();
if ($log){
continue;
... ... @@ -120,19 +115,13 @@ class VideoTask extends Command
'created_at' => date('Y-m-d H:i:s'),
];
$rs = KeywordVideoTaskLog::insert($array);
if($rs){
$num--;
if($rs && ($sub_task_num > 0)){
$sub_task_num--;
}
}
}
if($sub_task_num != 0){
$task_project->num = $num;
if($num == 0){
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
}
$task_project->save();
}
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
$task_project->save();
}
return true;
}
... ... @@ -182,18 +171,25 @@ class VideoTask extends Command
* @param $number
* @return mixed
*/
public function getProjectKeyword($number)
public function getProjectKeyword($number,$keywords = [])
{
$keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->pluck('id')->toArray();
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_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 [];
}
if(count($keyword_arr_id) <= $number){
$keyword_id = array_rand($keyword_arr_id, count($keyword_arr_id));
}else{
$keyword_id = array_rand($keyword_arr_id, $number);
}
$keyword = Keyword::whereIn("id", $keyword_id)->get();
$keyword = Keyword::whereIn("id", $keyword_arr_id)->get();
return $keyword;
}
... ...