作者 lyh

gx

@@ -9,11 +9,16 @@ namespace App\Console\Commands\KeywordInVideo; @@ -9,11 +9,16 @@ namespace App\Console\Commands\KeywordInVideo;
9 9
10 use App\Console\Commands\Model; 10 use App\Console\Commands\Model;
11 use App\Console\Commands\TaskSub; 11 use App\Console\Commands\TaskSub;
  12 +use App\Enums\Common\Code;
12 use App\Models\Com\KeywordVideoTask; 13 use App\Models\Com\KeywordVideoTask;
13 use App\Models\Com\KeywordVideoTaskLog; 14 use App\Models\Com\KeywordVideoTaskLog;
  15 +use App\Models\Domain\DomainInfo;
14 use App\Models\Product\Keyword; 16 use App\Models\Product\Keyword;
  17 +use App\Models\Product\Product;
  18 +use App\Models\RouteMap\RouteMap;
15 use App\Services\ProjectServer; 19 use App\Services\ProjectServer;
16 use Illuminate\Console\Command; 20 use Illuminate\Console\Command;
  21 +use Illuminate\Support\Facades\DB;
17 use Illuminate\Support\Facades\Http; 22 use Illuminate\Support\Facades\Http;
18 use Illuminate\Support\Facades\Log; 23 use Illuminate\Support\Facades\Log;
19 24
@@ -89,11 +94,12 @@ class VideoTask extends Command @@ -89,11 +94,12 @@ class VideoTask extends Command
89 if ($log){ 94 if ($log){
90 continue; 95 continue;
91 } 96 }
  97 + $keywordInfo = $this->getKeywordImage($val->id,$task_project->project_id);
92 $array = [ 98 $array = [
93 'project_id' => $task_project->project_id, 99 'project_id' => $task_project->project_id,
94 'keyword_id' => $val->id, 100 'keyword_id' => $val->id,
95 'keyword' => $val->title, 101 'keyword' => $val->title,
96 - 'data' => json_encode(['url' => '', 'description' => '', 'images' => [], 'keywords' => []]), 102 + 'data' => json_encode(['url' => $keywordInfo['url'],'title' => $keywordInfo['title'], 'description' => $keywordInfo['keyword_content'], 'images' => $keywordInfo['product_list'], 'keywords' => []]),
97 'status' => KeywordVideoTaskLog::STATUS_INIT, 103 'status' => KeywordVideoTaskLog::STATUS_INIT,
98 'updated_at' => date('Y-m-d H:i:s'), 104 'updated_at' => date('Y-m-d H:i:s'),
99 'created_at' => date('Y-m-d H:i:s'), 105 'created_at' => date('Y-m-d H:i:s'),
@@ -117,22 +123,22 @@ class VideoTask extends Command @@ -117,22 +123,22 @@ class VideoTask extends Command
117 if ($subTask->isEmpty()) 123 if ($subTask->isEmpty())
118 return true; 124 return true;
119 foreach ($subTask as $val) { 125 foreach ($subTask as $val) {
  126 + $valData = json_decode($val->data);
120 $task_id = 'v6-' . uniqid(); 127 $task_id = 'v6-' . uniqid();
121 $data = [ 128 $data = [
122 'project_data' => [ 129 'project_data' => [
123 - 'tag_url' => '',  
124 - 'title' => '', 130 + 'tag_url' => $valData['url'],
  131 + 'title' => $valData['title'],
125 'keywords' => [], 132 'keywords' => [],
126 - 'description' => '',  
127 - 'images' => '' 133 + 'description' => $valData['description'],
  134 + 'images' => $valData['images']
128 ], 135 ],
129 'task_id' => $task_id, 136 'task_id' => $task_id,
130 - 'callback_url' => '', 137 + 'callback_url' => url('a/getKeywordVideo?project_id='.$val->project_id.'&keyword_id='.$val->keyword_id.'&video='),
131 ]; 138 ];
132 $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);
133 -  
134 $val->task_id = $task_id; 140 $val->task_id = $task_id;
135 - $val->status = STATUS_RUNING::STATUS_RUNING; 141 + $val->status = KeywordVideoTaskLog::STATUS_RUNING;
136 $val->request_result = $result; 142 $val->request_result = $result;
137 $val->save(); 143 $val->save();
138 } 144 }
@@ -159,4 +165,47 @@ class VideoTask extends Command @@ -159,4 +165,47 @@ class VideoTask extends Command
159 $project_id = 110; 165 $project_id = 110;
160 return $project_id; 166 return $project_id;
161 } 167 }
  168 +
  169 + /**
  170 + * @remark :根据关键字获取产品主图
  171 + * @name :getKeywordList
  172 + * @author :lyh
  173 + * @method :post
  174 + * @time :2024/2/23 16:28
  175 + */
  176 + public function getKeywordImage($keyword_id,$project_id){
  177 + $keywordModel = new Keyword();
  178 + $keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
  179 + $productModel = new Product();
  180 + $productList = $productModel->list(['keyword_id'=>['like','%,'.$keywordInfo['id'].',%']],['thumb','title']);
  181 + if(count($productList) < 5){
  182 + $productList = $productModel->list([],'sort',['thumb','title']);
  183 + //获取7个产品主图
  184 + }
  185 + $product_image = [];
  186 + foreach ($productList as $v){
  187 + $image = [];
  188 + if(!empty($v['thumb']) && !empty($v['thumb']['url'])){
  189 + $image['image'] = getImageUrl($v['thumb']['url']);
  190 + $image['title'] = $v['title'];
  191 + $product_image[] = $image;
  192 + }
  193 + if(count($product_image) > 6){
  194 + break;
  195 + }
  196 + }
  197 + $domainModel = new DomainInfo();
  198 + $domainInfo = $domainModel->read(['project_id'=>$project_id]);
  199 + if(!empty($domainInfo)){
  200 + $keywordInfo['route'] = $domainInfo['domain'].'/'.$keywordInfo['route'];
  201 + }
  202 + $data = [
  203 + 'url'=>$keywordInfo['route'],
  204 + 'title'=>$keywordInfo['title'],
  205 + 'keyword_title'=>$keywordInfo['keyword_title'],
  206 + 'keyword_content'=>$keywordInfo['keyword_content'],
  207 + 'product_list'=>$product_image
  208 + ];
  209 + return $data;
  210 + }
162 } 211 }
@@ -17,6 +17,7 @@ use App\Services\ProjectServer; @@ -17,6 +17,7 @@ use App\Services\ProjectServer;
17 use Illuminate\Support\Facades\Cache; 17 use Illuminate\Support\Facades\Cache;
18 use Illuminate\Support\Facades\DB; 18 use Illuminate\Support\Facades\DB;
19 use Illuminate\Support\Facades\Hash; 19 use Illuminate\Support\Facades\Hash;
  20 +use Illuminate\Support\Facades\Log;
20 21
21 /** 22 /**
22 * Class IndexController 23 * Class IndexController
@@ -110,52 +111,15 @@ class IndexController extends BaseController @@ -110,52 +111,15 @@ class IndexController extends BaseController
110 * @method :post 111 * @method :post
111 * @time :2024/2/23 16:28 112 * @time :2024/2/23 16:28
112 */ 113 */
113 - public function getKeywordImage(){  
114 - $arr = explode('/',trim(str_replace('https://', '', $this->param['url']),'/'));  
115 - if(empty($arr) || !is_array($arr)){  
116 - $this->response('当前项目不存在..',Code::SYSTEM_ERROR);  
117 - }  
118 - $domainModel = new DomainInfo();  
119 - $domainInfo = $domainModel->read(['domain'=>$arr[0]]);  
120 - if($domainInfo === false){  
121 - $this->response('当前项目不存在.',Code::SYSTEM_ERROR);  
122 - }  
123 - ProjectServer::useProject($domainInfo['project_id']);  
124 - $routeMapModel = new RouteMap();  
125 - $routeInfo = $routeMapModel->read(['route'=>$arr[1]]);  
126 - if($domainInfo === false){  
127 - $this->response('当前路由不存在.',Code::SYSTEM_ERROR);  
128 - } 114 + public function getKeywordVideo(){
  115 + ProjectServer::useProject($this->param['project_id']);
129 $keywordModel = new Keyword(); 116 $keywordModel = new Keyword();
130 - $keywordInfo = $keywordModel->read(['id'=>$routeInfo['source_id']]);  
131 - $count = Product::where('keyword_id','like' ,'%,'.$keywordInfo['id'].',%')->count();  
132 - $productModel = new Product();  
133 - if($count < 5){  
134 - $productList = $productModel->list([],'sort',['thumb','title']);  
135 - //获取7个产品主图  
136 - }else{  
137 - $productList = $productModel->list(['keyword_id'=>['like','%,'.$keywordInfo['id'].',%']],['thumb','title']);  
138 - }  
139 - $product_image = [];  
140 - foreach ($productList as $k => $v){  
141 - $image = [];  
142 - if(!empty($v['thumb']) && !empty($v['thumb']['url'])){  
143 - $image['image'] = getImageUrl($v['thumb']['url']);  
144 - $image['title'] = $v['title'];  
145 - $product_image[] = $image;  
146 - }  
147 - if(count($product_image) > 6){  
148 - break;  
149 - } 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']);
150 } 120 }
151 - $data = [  
152 - 'title'=>$keywordInfo['title'],  
153 - 'keyword_title'=>$keywordInfo['keyword_title'],  
154 - 'keyword_content'=>$keywordInfo['keyword_content'],  
155 - 'product_list'=>$product_image  
156 - ];  
157 DB::disconnect('custom_mysql'); 121 DB::disconnect('custom_mysql');
158 - $this->response('success',Code::SUCCESS,$data); 122 + $this->response('success');
159 } 123 }
160 124
161 } 125 }
@@ -14,7 +14,7 @@ use App\Models\Base; @@ -14,7 +14,7 @@ use App\Models\Base;
14 class KeywordVideoTaskLog extends Base 14 class KeywordVideoTaskLog extends Base
15 { 15 {
16 const STATUS_INIT = 0; 16 const STATUS_INIT = 0;
17 - const STATUS_RUNING = 0; 17 + const STATUS_RUNING = 1;
18 18
19 protected $table = 'gl_keyword_video_task_log'; 19 protected $table = 'gl_keyword_video_task_log';
20 } 20 }
@@ -389,7 +389,7 @@ Route::group([], function () { @@ -389,7 +389,7 @@ 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('/getKeywordImage', [Aside\Com\IndexController::class, 'getKeywordImage'])->name('admin.getKeywordImage'); 392 + Route::any('/getKeywordVideo', [Aside\Com\IndexController::class, 'getKeywordVideo'])->name('admin.getKeywordVideo');
393 }); 393 });
394 394
395 395