作者 lyh

gx

@@ -135,7 +135,6 @@ class VideoTask extends Command @@ -135,7 +135,6 @@ class VideoTask extends Command
135 ], 135 ],
136 'task_id' => $task_id, 136 'task_id' => $task_id,
137 'callback_url' => env('APP_URL') . '/api/video_task_callback', 137 'callback_url' => env('APP_URL') . '/api/video_task_callback',
138 -// 'callback_url' => url('a/getKeywordVideo?project_id='.$val->project_id.'&keyword_id='.$val->keyword_id.'&video='),  
139 ]; 138 ];
140 $result = Http::post('http://216.250.255.116:7866/create_task', $data); 139 $result = Http::post('http://216.250.255.116:7866/create_task', $data);
141 $val->task_id = $task_id; 140 $val->task_id = $task_id;
@@ -176,26 +175,9 @@ class VideoTask extends Command @@ -176,26 +175,9 @@ class VideoTask extends Command
176 */ 175 */
177 public function getKeywordImage($keyword_id,$project_id){ 176 public function getKeywordImage($keyword_id,$project_id){
178 $keywordModel = new Keyword(); 177 $keywordModel = new Keyword();
179 - $keywordInfo = $keywordModel->read(['id'=>$keyword_id]);  
180 - $productModel = new Product();  
181 - $productList = $productModel->list(['keyword_id'=>['like','%,'.$keywordInfo['id'].',%']],['thumb','title']);  
182 - if(count($productList) < 5){  
183 - $productList = $productModel->inRandomOrder()->take(100)->get()->toArray();  
184 - //获取7个产品主图  
185 - }  
186 - $product_image = [];  
187 - foreach ($productList as $v){  
188 - $v = (array)$v;  
189 - $image = [];  
190 - if(!empty($v['thumb']) && !empty($v['thumb']['url'])){  
191 - $image['image'] = getImageUrl($v['thumb']['url']);  
192 - $image['title'] = $v['title'];  
193 - $product_image[] = $image;  
194 - }  
195 - if(count($product_image) > 6){  
196 - break;  
197 - }  
198 - } 178 + $thumb = $keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
  179 + //TODO::所有产品
  180 + $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
199 $domainModel = new DomainInfo(); 181 $domainModel = new DomainInfo();
200 $domainInfo = $domainModel->read(['project_id'=>$project_id]); 182 $domainInfo = $domainModel->read(['project_id'=>$project_id]);
201 if(!empty($domainInfo)){ 183 if(!empty($domainInfo)){
@@ -206,8 +188,41 @@ class VideoTask extends Command @@ -206,8 +188,41 @@ class VideoTask extends Command
206 'title'=>$keywordInfo['title'], 188 'title'=>$keywordInfo['title'],
207 'keyword_title'=>$keywordInfo['keyword_title'], 189 'keyword_title'=>$keywordInfo['keyword_title'],
208 'keyword_content'=>$keywordInfo['keyword_content'], 190 'keyword_content'=>$keywordInfo['keyword_content'],
209 - 'product_list'=>$product_image 191 + 'product_list'=>$thumb ?? []
210 ]; 192 ];
211 return $data; 193 return $data;
212 } 194 }
  195 +
  196 + /**
  197 + * 关键词聚合页-推荐&热门产品
  198 + */
  199 + public function getRecommendAndHotProducts($project,$route): ?array
  200 + {
  201 + $productIds = [];
  202 + $productKeyword = Keyword::where("project_id",$project->id)->where("route",$route)->first();
  203 + if (!empty($productKeyword)){
  204 + $productsQuery = Product::where("project_id", $project->id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get();
  205 + if (!empty($productsQuery)){
  206 + foreach ($productsQuery as $item){
  207 + $productIds[] = $item->id;
  208 + }
  209 + if (count($productIds)<7){
  210 + $randomData = Product::where("project_id", $project->id)->where("status",1)->whereNotIn('id', $productIds)->inRandomOrder()->take(13-count($productIds))->get();
  211 + $products = $productsQuery->merge($randomData);
  212 + }else{
  213 + $products = $productsQuery;
  214 + }
  215 + }else{
  216 + $products = Product::where("project_id", $project->id)->where("status",1)->inRandomOrder()->take(13)->get();
  217 + }
  218 + }
  219 + $data = [];
  220 + if (!empty($products)){
  221 + foreach ($products as $item){
  222 + $data[] = !empty($item->thumb) && $item->thumb != "[]"? getImageUrl(json_decode($item->thumb)->url) : "";
  223 + }
  224 + }
  225 + return $data;
  226 + }
  227 +
213 } 228 }
@@ -79,24 +79,24 @@ class NoticeController extends BaseController @@ -79,24 +79,24 @@ class NoticeController extends BaseController
79 $all = $request->all(); 79 $all = $request->all();
80 // 获取子任务 80 // 获取子任务
81 $log = KeywordVideoTaskLog::where(['task_id' => $task_id])->first(); 81 $log = KeywordVideoTaskLog::where(['task_id' => $task_id])->first();
82 - if (empty($log)) 82 + if (empty($log)){
83 return 200; 83 return 200;
  84 + }
84 // 更新子任务状态 更新任务信息 85 // 更新子任务状态 更新任务信息
85 $log->status = KeywordVideoTaskLog::STATUS_FINISH; 86 $log->status = KeywordVideoTaskLog::STATUS_FINISH;
86 $log->result_status = $status; 87 $log->result_status = $status;
87 $log->result_info = json_encode($all); 88 $log->result_info = json_encode($all);
88 $log->save(); 89 $log->save();
89 -  
90 if ($status != 200) { 90 if ($status != 200) {
91 return 200; 91 return 200;
92 } 92 }
93 -  
94 // 更新关键词信息 93 // 更新关键词信息
95 ProjectServer::useProject($log->project_id); 94 ProjectServer::useProject($log->project_id);
96 $keyword = Keyword::where(['id' => $log->keyword_id])->first(); 95 $keyword = Keyword::where(['id' => $log->keyword_id])->first();
97 // 关键词可能已被删除 96 // 关键词可能已被删除
98 - if (empty($keyword)) 97 + if (empty($keyword)){
99 return 200; 98 return 200;
  99 + }
100 $keyword->video = $video; 100 $keyword->video = $video;
101 $keyword->embed_code = $embed_code; 101 $keyword->embed_code = $embed_code;
102 $keyword->video_thumb = $thumb; 102 $keyword->video_thumb = $thumb;
@@ -103,23 +103,4 @@ class IndexController extends BaseController @@ -103,23 +103,4 @@ class IndexController extends BaseController
103 } 103 }
104 $this->response('success'); 104 $this->response('success');
105 } 105 }
106 -  
107 - /**  
108 - * @remark :根据关键字获取产品主图  
109 - * @name :getKeywordList  
110 - * @author :lyh  
111 - * @method :post  
112 - * @time :2024/2/23 16:28  
113 - */  
114 - public function getKeywordVideo(){  
115 - ProjectServer::useProject($this->param['project_id']);  
116 - $keywordModel = new Keyword();  
117 - $rs = $keywordModel->edit(['video'=>$this->param['video']],['id'=>$this->param['keyword_id']]);  
118 - if($rs === false){  
119 - Log::info('回调失败.'.$this->param['project_id'].'video:'.$this->param['video']);  
120 - }  
121 - DB::disconnect('custom_mysql');  
122 - $this->response('success');  
123 - }  
124 -  
125 } 106 }
@@ -389,7 +389,6 @@ Route::group([], function () { @@ -389,7 +389,6 @@ Route::group([], function () {
389 Route::any('/collect', [Aside\Collect\CollectController::class, 'index'])->name('admin.collect'); 389 Route::any('/collect', [Aside\Collect\CollectController::class, 'index'])->name('admin.collect');
390 //同步询盘 390 //同步询盘
391 Route::any('/sync_inquiry', [Aside\Com\IndexController::class, 'sync_inquiry'])->name('admin.sync_inquiry'); 391 Route::any('/sync_inquiry', [Aside\Com\IndexController::class, 'sync_inquiry'])->name('admin.sync_inquiry');
392 - Route::any('/getKeywordVideo', [Aside\Com\IndexController::class, 'getKeywordVideo'])->name('admin.getKeywordVideo');  
393 }); 392 });
394 393
395 394