作者 张关杰

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into bate

@@ -18,6 +18,7 @@ yarn-error.log @@ -18,6 +18,7 @@ yarn-error.log
18 /.vscode 18 /.vscode
19 composer.lock 19 composer.lock
20 app/Console/Commands/Test/Demo.php 20 app/Console/Commands/Test/Demo.php
  21 +app/Console/Commands/Test/DataRecovery.php
21 /public/upload 22 /public/upload
22 /public/runtime 23 /public/runtime
23 public/nginx.htaccess 24 public/nginx.htaccess
@@ -119,7 +119,7 @@ class VideoTask extends Command @@ -119,7 +119,7 @@ class VideoTask extends Command
119 */ 119 */
120 public function sendSubTask() 120 public function sendSubTask()
121 { 121 {
122 - $subTask = KeywordVideoTaskLog::where(['status' => TaskSub::STATUS_INIT])->orderBy('id', 'asc')->limit($this->max_sub_task)->get(); 122 + $subTask = KeywordVideoTaskLog::where(['status' => KeywordVideoTaskLog::STATUS_INIT])->orderBy('id', 'asc')->limit($this->max_sub_task)->get();
123 if ($subTask->isEmpty()) 123 if ($subTask->isEmpty())
124 return true; 124 return true;
125 foreach ($subTask as $val) { 125 foreach ($subTask as $val) {
@@ -134,11 +134,11 @@ class VideoTask extends Command @@ -134,11 +134,11 @@ class VideoTask extends Command
134 'images' => $valData['images'] 134 'images' => $valData['images']
135 ], 135 ],
136 'task_id' => $task_id, 136 'task_id' => $task_id,
137 - 'callback_url' => url('a/getKeywordVideo?project_id='.$val->project_id.'&keyword_id='.$val->keyword_id.'&video='), 137 + 'callback_url' => env('APP_URL') . '/api/video_task_callback',
138 ]; 138 ];
139 $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);
140 $val->task_id = $task_id; 140 $val->task_id = $task_id;
141 - $val->status = KeywordVideoTaskLog::STATUS_RUNING; 141 + $val->status = KeywordVideoTaskLog::STATUS_RUNNING;
142 $val->request_result = $result; 142 $val->request_result = $result;
143 $val->save(); 143 $val->save();
144 } 144 }
@@ -175,26 +175,9 @@ class VideoTask extends Command @@ -175,26 +175,9 @@ class VideoTask extends Command
175 */ 175 */
176 public function getKeywordImage($keyword_id,$project_id){ 176 public function getKeywordImage($keyword_id,$project_id){
177 $keywordModel = new Keyword(); 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->inRandomOrder()->take(100)->get()->toArray();  
183 - //获取7个产品主图  
184 - }  
185 - $product_image = [];  
186 - foreach ($productList as $v){  
187 - $v = (array)$v;  
188 - $image = [];  
189 - if(!empty($v['thumb']) && !empty($v['thumb']['url'])){  
190 - $image['image'] = getImageUrl($v['thumb']['url']);  
191 - $image['title'] = $v['title'];  
192 - $product_image[] = $image;  
193 - }  
194 - if(count($product_image) > 6){  
195 - break;  
196 - }  
197 - } 178 + $thumb = $keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
  179 + //TODO::所有产品
  180 + $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
198 $domainModel = new DomainInfo(); 181 $domainModel = new DomainInfo();
199 $domainInfo = $domainModel->read(['project_id'=>$project_id]); 182 $domainInfo = $domainModel->read(['project_id'=>$project_id]);
200 if(!empty($domainInfo)){ 183 if(!empty($domainInfo)){
@@ -205,8 +188,41 @@ class VideoTask extends Command @@ -205,8 +188,41 @@ class VideoTask extends Command
205 'title'=>$keywordInfo['title'], 188 'title'=>$keywordInfo['title'],
206 'keyword_title'=>$keywordInfo['keyword_title'], 189 'keyword_title'=>$keywordInfo['keyword_title'],
207 'keyword_content'=>$keywordInfo['keyword_content'], 190 'keyword_content'=>$keywordInfo['keyword_content'],
208 - 'product_list'=>$product_image 191 + 'product_list'=>$thumb ?? []
209 ]; 192 ];
210 return $data; 193 return $data;
211 } 194 }
  195 +
  196 + /**
  197 + * 关键词聚合页-推荐&热门产品
  198 + */
  199 + public function getRecommendAndHotProducts($project_id,$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['url'] != "" ? getImageUrl($item->thumb['url']) : "";
  223 + }
  224 + }
  225 + return $data;
  226 + }
  227 +
212 } 228 }
@@ -7,9 +7,13 @@ @@ -7,9 +7,13 @@
7 */ 7 */
8 namespace App\Http\Controllers\Api; 8 namespace App\Http\Controllers\Api;
9 9
  10 +use App\Models\Com\KeywordVideoTaskLog;
  11 +use App\Models\Product\Keyword;
10 use App\Models\Visit\SyncSubmitTask; 12 use App\Models\Visit\SyncSubmitTask;
11 use App\Models\Visit\Visit; 13 use App\Models\Visit\Visit;
  14 +use App\Services\ProjectServer;
12 use Illuminate\Http\Request; 15 use Illuminate\Http\Request;
  16 +use Illuminate\Support\Facades\DB;
13 17
14 /** 18 /**
15 * Class NoticeController 19 * Class NoticeController
@@ -58,4 +62,46 @@ class NoticeController extends BaseController @@ -58,4 +62,46 @@ class NoticeController extends BaseController
58 SyncSubmitTask::createTask($array, SyncSubmitTask::TYPE_VISIT); 62 SyncSubmitTask::createTask($array, SyncSubmitTask::TYPE_VISIT);
59 return $this->success([]); 63 return $this->success([]);
60 } 64 }
  65 +
  66 + /**
  67 + * 生成视频任务回调
  68 + * @param Request $request
  69 + * @return int
  70 + */
  71 + public function videoTaskCallback(Request $request)
  72 + {
  73 + // 获取参数
  74 + $task_id = $request->input('task_id');
  75 + $status = intval($request->input('status', 0));
  76 + $thumb = $request->input('video_thumb');
  77 + $video = $request->input('callback_resource');
  78 + $embed_code = $request->input('embed_code');
  79 + $all = $request->all();
  80 + // 获取子任务
  81 + $log = KeywordVideoTaskLog::where(['task_id' => $task_id])->first();
  82 + if (empty($log)){
  83 + return 200;
  84 + }
  85 + // 更新子任务状态 更新任务信息
  86 + $log->status = KeywordVideoTaskLog::STATUS_FINISH;
  87 + $log->result_status = $status;
  88 + $log->result_info = json_encode($all);
  89 + $log->save();
  90 + if ($status != 200) {
  91 + return 200;
  92 + }
  93 + // 更新关键词信息
  94 + ProjectServer::useProject($log->project_id);
  95 + $keyword = Keyword::where(['id' => $log->keyword_id])->first();
  96 + // 关键词可能已被删除
  97 + if (empty($keyword)){
  98 + return 200;
  99 + }
  100 + $keyword->video = $video;
  101 + $keyword->embed_code = $embed_code;
  102 + $keyword->video_thumb = $thumb;
  103 + $keyword->save();
  104 + DB::disconnect('custom_mysql');
  105 + return 200;
  106 + }
61 } 107 }
@@ -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 }
@@ -7,6 +7,8 @@ use App\Enums\Common\Code; @@ -7,6 +7,8 @@ use App\Enums\Common\Code;
7 use App\Http\Logic\Aside\LoginLogic; 7 use App\Http\Logic\Aside\LoginLogic;
8 use App\Models\Domain\DomainInfo; 8 use App\Models\Domain\DomainInfo;
9 use App\Models\Manage\Manage; 9 use App\Models\Manage\Manage;
  10 +use App\Models\Product\Keyword;
  11 +use App\Models\Product\Product;
10 use App\Models\Project\Project; 12 use App\Models\Project\Project;
11 use App\Models\Sms\SmsLog; 13 use App\Models\Sms\SmsLog;
12 use App\Rules\Mobile; 14 use App\Rules\Mobile;
@@ -82,16 +82,26 @@ class CreateKeywordLogic extends BaseLogic @@ -82,16 +82,26 @@ class CreateKeywordLogic extends BaseLogic
82 if(empty($this->param['keyword'])){ 82 if(empty($this->param['keyword'])){
83 return $this->success($data); 83 return $this->success($data);
84 } 84 }
85 - $prefix_keyword = $this->prefixKeyword($this->param['prefix'] ?? [],$this->param['keyword']);  
86 - $keyword_suffix = $this->keywordSuffix($this->param['suffix'] ?? [],$this->param['keyword']);  
87 - $prefix_keyword_suffix = $this->prefixKeywordSuffix($this->param['prefix'] ?? [],$this->param['suffix'] ?? [],$this->param['keyword']); 85 + $except_k = ['Quality','Philippines','USA','UK','America','China','Wholesale','Hot Sale','Cheap','cheap','price','pricelist','hot sale','Price','Pricelist','With ','For ','And ','Oem','Odm','Supplier','Manufacturer','CE Certification','Factory','Exporters','Company','Companies','Suppliers','Manufacturers','Factories','Company','Companies','Exporters','Exporter','Buy ',' Buy','Where ','What ','When ','How ','Which ','Producer','Producers','Best Selling','Hot Selling','Near','Chinese','India','use','high quality','discount','online','custom','customized','Enterprise','Agent','Plant','Refinery','Foundry','Maker','Distributor'];
  86 + $filterKeywords = [];
  87 + foreach ($this->param['keyword'] as $k=>$v){
  88 + if(in_array($v,$except_k)){
  89 + unset($this->param['keyword'][$k]);
  90 + $filterKeywords[] = $v;
  91 + }
  92 + }
  93 + $prefix_keyword = $this->prefixKeyword($this->param['prefix'] ?? [],$this->param['keyword'],$except_k);
  94 + $keyword_suffix = $this->keywordSuffix($this->param['suffix'] ?? [],$this->param['keyword'],$except_k);
  95 + $prefix_keyword_suffix = $this->prefixKeywordSuffix($this->param['prefix'] ?? [],$this->param['suffix'] ?? [],$this->param['keyword'],$except_k);
88 $data = [ 96 $data = [
89 'prefix_keyword'=>$prefix_keyword, 97 'prefix_keyword'=>$prefix_keyword,
90 'prefix_keyword_count'=>count($prefix_keyword), 98 'prefix_keyword_count'=>count($prefix_keyword),
91 'keyword_suffix'=>$keyword_suffix, 99 'keyword_suffix'=>$keyword_suffix,
92 'keyword_suffix_count'=>count($keyword_suffix), 100 'keyword_suffix_count'=>count($keyword_suffix),
93 'prefix_keyword_suffix'=>$prefix_keyword_suffix, 101 'prefix_keyword_suffix'=>$prefix_keyword_suffix,
94 - 'prefix_keyword_suffix_count'=>count($prefix_keyword_suffix) 102 + 'prefix_keyword_suffix_count'=>count($prefix_keyword_suffix),
  103 + 'filterKeywords'=>$filterKeywords,
  104 + 'filterKeywords_count'=>count($filterKeywords),
95 ]; 105 ];
96 return $this->success($data); 106 return $this->success($data);
97 } 107 }
@@ -103,7 +113,7 @@ class CreateKeywordLogic extends BaseLogic @@ -103,7 +113,7 @@ class CreateKeywordLogic extends BaseLogic
103 * @method :post 113 * @method :post
104 * @time :2023/12/19 11:11 114 * @time :2023/12/19 11:11
105 */ 115 */
106 - public function prefixKeyword($prefix,$keyword){ 116 + public function prefixKeyword($prefix,$keyword,$except_k){
107 $prefix_keyword = array(); 117 $prefix_keyword = array();
108 if(!empty($prefix)){//前缀+关键词 118 if(!empty($prefix)){//前缀+关键词
109 foreach ($keyword as $keywordItem){ 119 foreach ($keyword as $keywordItem){
@@ -96,7 +96,9 @@ class CountLogic extends BaseLogic @@ -96,7 +96,9 @@ class CountLogic extends BaseLogic
96 ]; 96 ];
97 $data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']); 97 $data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']);
98 if($data === false){ 98 if($data === false){
99 - $param['updated_date'] = Carbon::yesterday()->toDateString(); 99 + $param = [
  100 + 'project_id' => $this->user['project_id']
  101 + ];
100 $data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']); 102 $data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']);
101 if($data === false){ 103 if($data === false){
102 $data = []; 104 $data = [];
@@ -14,7 +14,8 @@ use App\Models\Base; @@ -14,7 +14,8 @@ 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 = 1; 17 + const STATUS_RUNNING = 1;
  18 + const STATUS_FINISH = 2;
18 19
19 protected $table = 'gl_keyword_video_task_log'; 20 protected $table = 'gl_keyword_video_task_log';
20 } 21 }
@@ -24,3 +24,4 @@ Route::get('get_project_route', [\App\Http\Controllers\Api\PrivateController::cl @@ -24,3 +24,4 @@ Route::get('get_project_route', [\App\Http\Controllers\Api\PrivateController::cl
24 Route::any('get_product_images', [\App\Http\Controllers\Api\ProductController::class, 'getImages'])->name('api.get_product_images'); 24 Route::any('get_product_images', [\App\Http\Controllers\Api\ProductController::class, 'getImages'])->name('api.get_product_images');
25 Route::post('inquiry_submit', [\App\Http\Controllers\Api\InquiryController::class, 'submit'])->name('api.inquiry_submit'); 25 Route::post('inquiry_submit', [\App\Http\Controllers\Api\InquiryController::class, 'submit'])->name('api.inquiry_submit');
26 26
  27 +Route::post('video_task_callback', [\App\Http\Controllers\Api\NoticeController::class, 'videoTaskCallback'])->name('api.video_task_callback');
@@ -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