正在显示
1 个修改的文件
包含
20 行增加
和
24 行删除
| @@ -16,6 +16,7 @@ use App\Models\Product\Keyword; | @@ -16,6 +16,7 @@ use App\Models\Product\Keyword; | ||
| 16 | use App\Models\Product\Product; | 16 | use App\Models\Product\Product; |
| 17 | use App\Services\ProjectServer; | 17 | use App\Services\ProjectServer; |
| 18 | use Illuminate\Console\Command; | 18 | use Illuminate\Console\Command; |
| 19 | +use Illuminate\Support\Facades\DB; | ||
| 19 | use Illuminate\Support\Facades\Http; | 20 | use Illuminate\Support\Facades\Http; |
| 20 | use Illuminate\Support\Facades\Log; | 21 | use Illuminate\Support\Facades\Log; |
| 21 | 22 | ||
| @@ -87,7 +88,7 @@ class VideoTask extends Command | @@ -87,7 +88,7 @@ class VideoTask extends Command | ||
| 87 | continue; | 88 | continue; |
| 88 | } | 89 | } |
| 89 | ProjectServer::useProject($task_project->project_id); | 90 | ProjectServer::useProject($task_project->project_id); |
| 90 | - $keyword = $this->getProjectKeyword($task_project->num); | 91 | + $keyword = $this->getProjectKeyword($task_project->number,$task_project->keywords); |
| 91 | // 已经没有需要生成视频的关键词 | 92 | // 已经没有需要生成视频的关键词 |
| 92 | if (!$keyword) { | 93 | if (!$keyword) { |
| 93 | $task_project->status = KeywordVideoTask::STATUS_CLOSE; | 94 | $task_project->status = KeywordVideoTask::STATUS_CLOSE; |
| @@ -95,13 +96,7 @@ class VideoTask extends Command | @@ -95,13 +96,7 @@ class VideoTask extends Command | ||
| 95 | continue; | 96 | continue; |
| 96 | } | 97 | } |
| 97 | $logo_bg = $this->getImage($domainInfo); | 98 | $logo_bg = $this->getImage($domainInfo); |
| 98 | - $num = $task_project->num; | ||
| 99 | foreach ($keyword as $val) { | 99 | foreach ($keyword as $val) { |
| 100 | - if($sub_task_num == 0){ | ||
| 101 | - $task_project->num = $num; | ||
| 102 | - $task_project->save(); | ||
| 103 | - break; | ||
| 104 | - } | ||
| 105 | $log = KeywordVideoTaskLog::where(['project_id' => $task_project->project_id, 'keyword_id' => $val->id])->first(); | 100 | $log = KeywordVideoTaskLog::where(['project_id' => $task_project->project_id, 'keyword_id' => $val->id])->first(); |
| 106 | if ($log){ | 101 | if ($log){ |
| 107 | continue; | 102 | continue; |
| @@ -120,19 +115,13 @@ class VideoTask extends Command | @@ -120,19 +115,13 @@ class VideoTask extends Command | ||
| 120 | 'created_at' => date('Y-m-d H:i:s'), | 115 | 'created_at' => date('Y-m-d H:i:s'), |
| 121 | ]; | 116 | ]; |
| 122 | $rs = KeywordVideoTaskLog::insert($array); | 117 | $rs = KeywordVideoTaskLog::insert($array); |
| 123 | - if($rs){ | ||
| 124 | - $num--; | 118 | + if($rs && ($sub_task_num > 0)){ |
| 125 | $sub_task_num--; | 119 | $sub_task_num--; |
| 126 | } | 120 | } |
| 127 | } | 121 | } |
| 128 | } | 122 | } |
| 129 | - if($sub_task_num != 0){ | ||
| 130 | - $task_project->num = $num; | ||
| 131 | - if($num == 0){ | ||
| 132 | - $task_project->status = KeywordVideoTask::STATUS_CLOSE; | ||
| 133 | - } | ||
| 134 | - $task_project->save(); | ||
| 135 | - } | 123 | + $task_project->status = KeywordVideoTask::STATUS_CLOSE; |
| 124 | + $task_project->save(); | ||
| 136 | } | 125 | } |
| 137 | return true; | 126 | return true; |
| 138 | } | 127 | } |
| @@ -182,18 +171,25 @@ class VideoTask extends Command | @@ -182,18 +171,25 @@ class VideoTask extends Command | ||
| 182 | * @param $number | 171 | * @param $number |
| 183 | * @return mixed | 172 | * @return mixed |
| 184 | */ | 173 | */ |
| 185 | - public function getProjectKeyword($number) | 174 | + public function getProjectKeyword($number,$keywords = []) |
| 186 | { | 175 | { |
| 187 | - $keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->pluck('id')->toArray(); | 176 | + if(!empty($keywords)){ |
| 177 | + $keyword_id = Keyword::where('video', null)->whereIn("title", $keywords)->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->pluck('id')->toArray(); | ||
| 178 | + if(count($keyword_id) == 0){ | ||
| 179 | + $keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag') | ||
| 180 | + ->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number)->pluck('id')->toArray(); | ||
| 181 | + }else{ | ||
| 182 | + $keyword_arr_id = Keyword::where('video', null)->whereNotIn("title", $keywords)->where('route', 'not like', '%-tag')->whereNotNull('keyword_content') | ||
| 183 | + ->orderBy('id','asc')->limit($number - count($keyword_id))->pluck('id')->toArray(); | ||
| 184 | + $keyword_arr_id = array_merge($keyword_id,$keyword_arr_id); | ||
| 185 | + } | ||
| 186 | + }else{ | ||
| 187 | + $keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number)->pluck('id')->toArray(); | ||
| 188 | + } | ||
| 188 | if(count($keyword_arr_id) == 0){ | 189 | if(count($keyword_arr_id) == 0){ |
| 189 | return []; | 190 | return []; |
| 190 | } | 191 | } |
| 191 | - if(count($keyword_arr_id) <= $number){ | ||
| 192 | - $keyword_id = array_rand($keyword_arr_id, count($keyword_arr_id)); | ||
| 193 | - }else{ | ||
| 194 | - $keyword_id = array_rand($keyword_arr_id, $number); | ||
| 195 | - } | ||
| 196 | - $keyword = Keyword::whereIn("id", $keyword_id)->get(); | 192 | + $keyword = Keyword::whereIn("id", $keyword_arr_id)->get(); |
| 197 | return $keyword; | 193 | return $keyword; |
| 198 | } | 194 | } |
| 199 | 195 |
-
请 注册 或 登录 后发表评论