|
@@ -89,9 +89,9 @@ class VideoTask extends Command |
|
@@ -89,9 +89,9 @@ class VideoTask extends Command |
|
89
|
}
|
89
|
}
|
|
90
|
ProjectServer::useProject($task_project->project_id);
|
90
|
ProjectServer::useProject($task_project->project_id);
|
|
91
|
if(!empty($task_project->keywords)){
|
91
|
if(!empty($task_project->keywords)){
|
|
92
|
- $task_project->keywords = explode(',',trim(',',$task_project->keywords));
|
92
|
+ $keywords = explode(',',trim(',',$task_project->keywords));
|
|
93
|
}
|
93
|
}
|
|
94
|
- $keyword = $this->getProjectKeyword($task_project->number,$task_project->keywords);
|
94
|
+ $keyword = $this->getProjectKeyword($task_project->number,$keywords ?? []);
|
|
95
|
// 已经没有需要生成视频的关键词
|
95
|
// 已经没有需要生成视频的关键词
|
|
96
|
if (!$keyword) {
|
96
|
if (!$keyword) {
|
|
97
|
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
|
97
|
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
|
|
@@ -176,24 +176,15 @@ class VideoTask extends Command |
|
@@ -176,24 +176,15 @@ class VideoTask extends Command |
|
176
|
*/
|
176
|
*/
|
|
177
|
public function getProjectKeyword($number,$keywords = [])
|
177
|
public function getProjectKeyword($number,$keywords = [])
|
|
178
|
{
|
178
|
{
|
|
179
|
- if(!empty($keywords)){
|
179
|
+
|
|
180
|
$keyword_id = Keyword::where('video', null)->whereIn("title", $keywords)
|
180
|
$keyword_id = Keyword::where('video', null)->whereIn("title", $keywords)
|
|
181
|
- ->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->pluck('id')->toArray();
|
|
|
|
182
|
- if(count($keyword_id) == 0){
|
|
|
|
183
|
- $keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')
|
|
|
|
184
|
- ->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number)->pluck('id')->toArray();
|
|
|
|
185
|
- }else{
|
|
|
|
186
|
- $keyword_arr_id = Keyword::where('video', null)->whereNotIn("title", $keywords)->where('route', 'not like', '%-tag')
|
|
|
|
187
|
- ->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number - count($keyword_id))->pluck('id')->toArray();
|
|
|
|
188
|
- $keyword_arr_id = array_merge($keyword_id,$keyword_arr_id);
|
|
|
|
189
|
- }
|
|
|
|
190
|
- }else{
|
181
|
+ ->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->limit($number)->pluck('id')->toArray();
|
|
|
|
182
|
+ $need = $number - count($keyword_id);
|
|
|
|
183
|
+ if ($need > 0) {
|
|
191
|
$keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')
|
184
|
$keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')
|
|
192
|
- ->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number)->pluck('id')->toArray();
|
|
|
|
193
|
- }
|
|
|
|
194
|
- if(count($keyword_arr_id) == 0){
|
|
|
|
195
|
- return [];
|
185
|
+ ->whereNotNull('keyword_content')->whereNotIn('id', $keyword_id)->orderBy('id','asc')->limit($need)->pluck('id')->toArray();
|
|
196
|
}
|
186
|
}
|
|
|
|
187
|
+ $keyword_arr_id = array_merge($keyword_id, $keyword_arr_id);
|
|
197
|
$keyword = Keyword::whereIn("id", $keyword_arr_id)->get();
|
188
|
$keyword = Keyword::whereIn("id", $keyword_arr_id)->get();
|
|
198
|
return $keyword;
|
189
|
return $keyword;
|
|
199
|
}
|
190
|
}
|
|
@@ -254,35 +245,42 @@ class VideoTask extends Command |
|
@@ -254,35 +245,42 @@ class VideoTask extends Command |
|
254
|
public function getRecommendAndHotProducts($keyword_id,$project_id): ?array
|
245
|
public function getRecommendAndHotProducts($keyword_id,$project_id): ?array
|
|
255
|
{
|
246
|
{
|
|
256
|
$productIds = [];
|
247
|
$productIds = [];
|
|
257
|
- $productKeyword = Keyword::where("project_id",$project_id)->where("id",$keyword_id)->first();
|
|
|
|
258
|
- $productsQuery = Product::where("project_id", $project_id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get();
|
248
|
+ $productKeyword = Keyword::where("id",$keyword_id)->first();
|
|
|
|
249
|
+ $productsQuery = Product::where("status",1)->where("keyword_id","like","%,".$keyword_id.",%")->limit(7)->get();
|
|
259
|
if (!empty($productsQuery)){
|
250
|
if (!empty($productsQuery)){
|
|
260
|
foreach ($productsQuery as $item){
|
251
|
foreach ($productsQuery as $item){
|
|
261
|
$productIds[] = $item->id;
|
252
|
$productIds[] = $item->id;
|
|
262
|
}
|
253
|
}
|
|
263
|
if (count($productIds)<7){
|
254
|
if (count($productIds)<7){
|
|
264
|
- $product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
|
255
|
+ $product_all_id = Product::where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
|
|
265
|
$number = 40;
|
256
|
$number = 40;
|
|
266
|
$array_count = count($product_all_id);
|
257
|
$array_count = count($product_all_id);
|
|
267
|
if ($array_count > 0) {
|
258
|
if ($array_count > 0) {
|
|
268
|
- $product_id = array_rand($product_all_id, min($array_count, $number - count($productIds)));
|
|
|
|
269
|
- $randomData = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
|
259
|
+ $product_id_key = array_rand($product_all_id, min($array_count, $number - count($productIds)));
|
|
|
|
260
|
+ foreach ($product_id_key as $value_key){
|
|
|
|
261
|
+ $project_id_arr = $product_all_id[$value_key];
|
|
|
|
262
|
+ }
|
|
|
|
263
|
+ $randomData = Product::whereIn("id", $project_id_arr)->get();
|
|
270
|
$products = $productsQuery->merge($randomData);
|
264
|
$products = $productsQuery->merge($randomData);
|
|
271
|
}
|
265
|
}
|
|
272
|
}else{
|
266
|
}else{
|
|
273
|
$products = $productsQuery;
|
267
|
$products = $productsQuery;
|
|
274
|
}
|
268
|
}
|
|
275
|
}else{
|
269
|
}else{
|
|
276
|
- $product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
|
270
|
+ $product_all_id = Product::where('thumb','!=',null)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
|
|
|
|
271
|
+ shuffle($product_all_id);
|
|
277
|
$number = 40;
|
272
|
$number = 40;
|
|
278
|
$array_count = count($product_all_id);
|
273
|
$array_count = count($product_all_id);
|
|
279
|
if ($array_count > 0)
|
274
|
if ($array_count > 0)
|
|
280
|
{
|
275
|
{
|
|
281
|
- $product_id = array_rand($product_all_id, min($array_count, $number-count($productIds)));
|
|
|
|
282
|
- $products = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
|
276
|
+ $project_id_arr = [];
|
|
|
|
277
|
+ $product_id_key = array_rand($product_all_id, min($array_count, $number-count($productIds)));
|
|
|
|
278
|
+ foreach ($product_id_key as $value_key){
|
|
|
|
279
|
+ $project_id_arr = $product_all_id[$value_key];
|
|
|
|
280
|
+ }
|
|
|
|
281
|
+ $products = Product::where("project_id", $project_id)->whereIn("id", $project_id_arr)->get();
|
|
283
|
}
|
282
|
}
|
|
284
|
}
|
283
|
}
|
|
285
|
-
|
|
|
|
286
|
$data = [];
|
284
|
$data = [];
|
|
287
|
if (!empty($products)){
|
285
|
if (!empty($products)){
|
|
288
|
foreach ($products as $item){
|
286
|
foreach ($products as $item){
|
|
@@ -292,11 +290,11 @@ class VideoTask extends Command |
|
@@ -292,11 +290,11 @@ class VideoTask extends Command |
|
292
|
if(count($data) > 13){
|
290
|
if(count($data) > 13){
|
|
293
|
break;
|
291
|
break;
|
|
294
|
}
|
292
|
}
|
|
295
|
- $keyword_id = implode(',',$item->keyword_id);
|
|
|
|
296
|
- if (strpos(','.$keyword_id.',', ','.$productKeyword->id.',') === false) {
|
293
|
+ $keyword_ids = implode(',',$item->keyword_id);
|
|
|
|
294
|
+ if (strpos(','.$keyword_ids.',', ','.$keyword_id.',') === false) {
|
|
297
|
//不包含
|
295
|
//不包含
|
|
298
|
$productModel = new Product();
|
296
|
$productModel = new Product();
|
|
299
|
- $keyword_id = ','.$keyword_id.',' . $productKeyword->id.',';
|
297
|
+ $keyword_id = ','.$keyword_ids.',' . $keyword_id.',';
|
|
300
|
$productModel->edit(['keyword_id'=>$keyword_id],['id'=>$item->id]);
|
298
|
$productModel->edit(['keyword_id'=>$keyword_id],['id'=>$item->id]);
|
|
301
|
}
|
299
|
}
|
|
302
|
$data[] = ['url'=>getImageUrl($item->thumb['url']),'title'=>$item->title];
|
300
|
$data[] = ['url'=>getImageUrl($item->thumb['url']),'title'=>$item->title];
|