作者 张关杰

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

@@ -81,6 +81,13 @@ class VideoTask extends Command @@ -81,6 +81,13 @@ class VideoTask extends Command
81 if (empty($task_project)){ 81 if (empty($task_project)){
82 break; 82 break;
83 } 83 }
  84 + $domainModel = new DomainInfo();
  85 + $domainInfo = $domainModel->read(['project_id'=>$task_project->project_id]);
  86 + if($domainInfo === false){
  87 + $task_project->status = KeywordVideoTask::STATUS_CLOSE;
  88 + $task_project->save();
  89 + continue;
  90 + }
84 ProjectServer::useProject($task_project->project_id); 91 ProjectServer::useProject($task_project->project_id);
85 $keyword = $this->getProjectKeyword(); 92 $keyword = $this->getProjectKeyword();
86 // 已经没有需要生成视频的关键词 93 // 已经没有需要生成视频的关键词
@@ -94,12 +101,12 @@ class VideoTask extends Command @@ -94,12 +101,12 @@ class VideoTask extends Command
94 if ($log){ 101 if ($log){
95 continue; 102 continue;
96 } 103 }
97 - $keywordInfo = $this->getKeywordImage($val->id,$task_project->project_id); 104 + $keywordInfo = $this->getKeywordImage($val->id,$task_project->project_id,$domainInfo['domain']);
98 $array = [ 105 $array = [
99 'project_id' => $task_project->project_id, 106 'project_id' => $task_project->project_id,
100 'keyword_id' => $val->id, 107 'keyword_id' => $val->id,
101 'keyword' => $val->title, 108 'keyword' => $val->title,
102 - 'data' => json_encode(['url' => $keywordInfo['url'],'title' => $keywordInfo['title'], 'description' => $keywordInfo['keyword_content'], 'images' => $keywordInfo['product_list'], 'keywords' => []]), 109 + 'data' => json_encode(['url' => $keywordInfo['url'],'title' => $keywordInfo['title'], 'description' => $keywordInfo['keyword_content'], 'images' => $keywordInfo['product_list'], 'keywords' => $keywordInfo['keyword_list']]),
103 'status' => KeywordVideoTaskLog::STATUS_INIT, 110 'status' => KeywordVideoTaskLog::STATUS_INIT,
104 'updated_at' => date('Y-m-d H:i:s'), 111 'updated_at' => date('Y-m-d H:i:s'),
105 'created_at' => date('Y-m-d H:i:s'), 112 'created_at' => date('Y-m-d H:i:s'),
@@ -129,7 +136,7 @@ class VideoTask extends Command @@ -129,7 +136,7 @@ class VideoTask extends Command
129 'project_data' => [ 136 'project_data' => [
130 'tag_url' => $valData['url'], 137 'tag_url' => $valData['url'],
131 'title' => $valData['title'], 138 'title' => $valData['title'],
132 - 'keywords' => [], 139 + 'keywords' => $valData['keywords'],
133 'description' => $valData['description'], 140 'description' => $valData['description'],
134 'images' => $valData['images'] 141 'images' => $valData['images']
135 ], 142 ],
@@ -173,22 +180,19 @@ class VideoTask extends Command @@ -173,22 +180,19 @@ class VideoTask extends Command
173 * @method :post 180 * @method :post
174 * @time :2024/2/23 16:28 181 * @time :2024/2/23 16:28
175 */ 182 */
176 - public function getKeywordImage($keyword_id,$project_id){ 183 + public function getKeywordImage($keyword_id,$project_id,$domain){
177 $keywordModel = new Keyword(); 184 $keywordModel = new Keyword();
178 - $thumb = $keywordInfo = $keywordModel->read(['id'=>$keyword_id]); 185 + $keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
179 //TODO::所有产品 186 //TODO::所有产品
180 - $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);  
181 - $domainModel = new DomainInfo();  
182 - $domainInfo = $domainModel->read(['project_id'=>$project_id]);  
183 - if(!empty($domainInfo)){  
184 - $keywordInfo['route'] = $domainInfo['domain'].'/'.$keywordInfo['route'];  
185 - } 187 + $thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
  188 + $keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray();;
186 $data = [ 189 $data = [
187 - 'url'=>$keywordInfo['route'], 190 + 'url'=>$domain.'/'.$keywordInfo['route'],
188 'title'=>$keywordInfo['title'], 191 'title'=>$keywordInfo['title'],
189 'keyword_title'=>$keywordInfo['keyword_title'], 192 'keyword_title'=>$keywordInfo['keyword_title'],
190 'keyword_content'=>$keywordInfo['keyword_content'], 193 'keyword_content'=>$keywordInfo['keyword_content'],
191 - 'product_list'=>$thumb ?? [] 194 + 'product_list'=>$thumb ?? [],
  195 + 'keyword_list'=>$keyword_arr ?? []
192 ]; 196 ];
193 return $data; 197 return $data;
194 } 198 }
@@ -196,7 +200,7 @@ class VideoTask extends Command @@ -196,7 +200,7 @@ class VideoTask extends Command
196 /** 200 /**
197 * 关键词聚合页-推荐&热门产品 201 * 关键词聚合页-推荐&热门产品
198 */ 202 */
199 - public function getRecommendAndHotProducts($project_id,$route): ?array 203 + public function getRecommendAndHotProducts($route,$project_id): ?array
200 { 204 {
201 $productIds = []; 205 $productIds = [];
202 $productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first(); 206 $productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first();
@@ -225,4 +229,6 @@ class VideoTask extends Command @@ -225,4 +229,6 @@ class VideoTask extends Command
225 return $data; 229 return $data;
226 } 230 }
227 231
  232 +
  233 +
228 } 234 }
@@ -64,10 +64,11 @@ class RankData extends BaseCommands @@ -64,10 +64,11 @@ class RankData extends BaseCommands
64 return false; 64 return false;
65 } 65 }
66 foreach ($list as $item){ 66 foreach ($list as $item){
  67 + echo $item['api_no'] . PHP_EOL;
67 try { 68 try {
68 (new RankDataLogic())->syncRankData($item['api_no'], $site_res); 69 (new RankDataLogic())->syncRankData($item['api_no'], $site_res);
69 }catch (\Exception $e){ 70 }catch (\Exception $e){
70 - Log::channel('rank_data')->error('RankData:失败 ' . $e->getMessage()); 71 + Log::channel('rank_data')->error('RankData:失败 ' . $item['api_no'] . $e->getMessage());
71 $error++; 72 $error++;
72 continue; 73 continue;
73 } 74 }
@@ -16,6 +16,8 @@ use App\Models\Manage\BelongingGroup; @@ -16,6 +16,8 @@ use App\Models\Manage\BelongingGroup;
16 use App\Models\Manage\Dept; 16 use App\Models\Manage\Dept;
17 use App\Models\Manage\EntryPosition; 17 use App\Models\Manage\EntryPosition;
18 use App\Models\Manage\ManageHr; 18 use App\Models\Manage\ManageHr;
  19 +use App\Models\Product\Keyword;
  20 +use App\Models\Product\Product;
19 use App\Models\Project\Project; 21 use App\Models\Project\Project;
20 use App\Models\WebSetting\WebSettingService; 22 use App\Models\WebSetting\WebSettingService;
21 use App\Services\ProjectServer; 23 use App\Services\ProjectServer;
@@ -260,17 +262,73 @@ class Demo extends Command @@ -260,17 +262,73 @@ class Demo extends Command
260 // } 262 // }
261 263
262 public function handle(){ 264 public function handle(){
263 - $projectModel = new Project();  
264 - $list = $projectModel->list(['delete_status'=>0]);  
265 - foreach ($list as $v){  
266 - ProjectServer::useProject($v['id']);  
267 - $webSettingServiceModel = new WebSettingService();  
268 - $info = $webSettingServiceModel->read(['values'=>['like','%+86%']]);  
269 - if($info !== false){  
270 - echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;  
271 - } 265 +// $projectModel = new Project();
  266 +// $list = $projectModel->list(['delete_status'=>0]);
  267 +// foreach ($list as $v){
  268 + ProjectServer::useProject(150);
  269 + $this->getKeywordImage();
272 DB::disconnect('custom_mysql'); 270 DB::disconnect('custom_mysql');
  271 +// }
  272 + }
  273 +
  274 + /**
  275 + * @remark :根据关键字获取产品主图
  276 + * @name :getKeywordList
  277 + * @author :lyh
  278 + * @method :post
  279 + * @time :2024/2/23 16:28
  280 + */
  281 + public function getKeywordImage($keyword_id = 1,$project_id = 150){
  282 + $keywordModel = new Keyword();
  283 + $keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
  284 + //TODO::所有产品
  285 + $thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
  286 + $domainModel = new DomainInfo();
  287 + $domainInfo = $domainModel->read(['project_id'=>$project_id]);
  288 + if(!empty($domainInfo)){
  289 + $keywordInfo['route'] = $domainInfo['domain'].'/'.$keywordInfo['route'];
  290 + }
  291 + $data = [
  292 + 'url'=>$keywordInfo['route'],
  293 + 'title'=>$keywordInfo['title'],
  294 + 'keyword_title'=>$keywordInfo['keyword_title'],
  295 + 'keyword_content'=>$keywordInfo['keyword_content'],
  296 + 'product_list'=>$thumb ?? []
  297 + ];
  298 + dd($data);
  299 + return $data;
  300 + }
  301 +
  302 + /**
  303 + * 关键词聚合页-推荐&热门产品
  304 + */
  305 + public function getRecommendAndHotProducts($route,$project_id): ?array
  306 + {
  307 + $productIds = [];
  308 + $productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first();
  309 + if (!empty($productKeyword)){
  310 + $productsQuery = Product::where("project_id", $project_id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get();
  311 + if (!empty($productsQuery)){
  312 + foreach ($productsQuery as $item){
  313 + $productIds[] = $item->id;
  314 + }
  315 + if (count($productIds)<7){
  316 + $randomData = Product::where("project_id", $project_id)->where("status",1)->whereNotIn('id', $productIds)->inRandomOrder()->take(13-count($productIds))->get();
  317 + $products = $productsQuery->merge($randomData);
  318 + }else{
  319 + $products = $productsQuery;
  320 + }
  321 + }else{
  322 + $products = Product::where("project_id", $project_id)->where("status",1)->inRandomOrder()->take(13)->get();
  323 + }
  324 + }
  325 + $data = [];
  326 + if (!empty($products)){
  327 + foreach ($products as $item){
  328 + $data[] = !empty($item->thumb) && $item->thumb['url'] != "" ? getImageUrl($item->thumb['url']) : "";
  329 + }
273 } 330 }
  331 + return $data;
274 } 332 }
275 public function printMessage() 333 public function printMessage()
276 { 334 {
@@ -75,13 +75,13 @@ class QuanqiusouApi @@ -75,13 +75,13 @@ class QuanqiusouApi
75 /** 75 /**
76 * 获取谷歌排名数据 76 * 获取谷歌排名数据
77 * @param $api_no 77 * @param $api_no
78 - * @param int $lang 78 + * @param string $lang
79 * @param int $day 79 * @param int $day
80 * @return array|false|mixed 80 * @return array|false|mixed
81 * @author zbj 81 * @author zbj
82 * @date 2023/5/11 82 * @date 2023/5/11
83 */ 83 */
84 - public function getGoogleRank($api_no, int $lang = 0, int $day = 7, $force = true) 84 + public function getGoogleRank($api_no, string $lang = '', int $day = 7, $force = true)
85 { 85 {
86 $key = "quanqiusou_api_rank_{$api_no}_{$lang}_{$day}_" . date('Y-m-d'); 86 $key = "quanqiusou_api_rank_{$api_no}_{$lang}_{$day}_" . date('Y-m-d');
87 $res = Cache::get($key); 87 $res = Cache::get($key);
@@ -12,6 +12,7 @@ namespace App\Http\Controllers\Aside\Com; @@ -12,6 +12,7 @@ namespace App\Http\Controllers\Aside\Com;
12 use App\Enums\Common\Code; 12 use App\Enums\Common\Code;
13 use App\Http\Controllers\Aside\BaseController; 13 use App\Http\Controllers\Aside\BaseController;
14 use App\Models\Com\KeywordVideoTask; 14 use App\Models\Com\KeywordVideoTask;
  15 +use App\Models\Domain\DomainInfo;
15 16
16 class KeywordVideoController extends BaseController 17 class KeywordVideoController extends BaseController
17 { 18 {
@@ -43,6 +44,12 @@ class KeywordVideoController extends BaseController @@ -43,6 +44,12 @@ class KeywordVideoController extends BaseController
43 'project_id.required' => '项目唯一标识不为空', 44 'project_id.required' => '项目唯一标识不为空',
44 'number.required' => 'number不为空', 45 'number.required' => 'number不为空',
45 ]); 46 ]);
  47 + //查看当前项目是否有正式域名
  48 + $domainModel = new DomainInfo();
  49 + $info = $domainModel->read(['project_id'=>$this->param['project_id']]);
  50 + if($info === false){
  51 + $this->response('请先设置域名',Code::SYSTEM_ERROR);
  52 + }
46 $keywordModel = new KeywordVideoTask(); 53 $keywordModel = new KeywordVideoTask();
47 $rs = $keywordModel->add($this->param); 54 $rs = $keywordModel->add($this->param);
48 if($rs === false){ 55 if($rs === false){
@@ -379,7 +379,7 @@ class RankDataLogic extends BaseLogic @@ -379,7 +379,7 @@ class RankDataLogic extends BaseLogic
379 379
380 $model = RankData::where('project_id', $project_id)->where('lang', '')->first(); 380 $model = RankData::where('project_id', $project_id)->where('lang', '')->first();
381 if (!$model || $model->updated_date != date('Y-m-d') || $force) { 381 if (!$model || $model->updated_date != date('Y-m-d') || $force) {
382 - $res = $api->getGoogleRank($api_no, 0, 7, $force); 382 + $res = $api->getGoogleRank($api_no, '', 7, $force);
383 if (!$res) { 383 if (!$res) {
384 throw new \Exception("接口数据获取失败,api_no:{$api_no}"); 384 throw new \Exception("接口数据获取失败,api_no:{$api_no}");
385 } 385 }
@@ -392,7 +392,7 @@ class RankDataLogic extends BaseLogic @@ -392,7 +392,7 @@ class RankDataLogic extends BaseLogic
392 if (!empty($lang_list[$api_no])) { 392 if (!empty($lang_list[$api_no])) {
393 $model = RankData::where('project_id', $project_id)->where('lang', '<>', '')->first(); 393 $model = RankData::where('project_id', $project_id)->where('lang', '<>', '')->first();
394 if (!$model || $model->updated_date != date('Y-m-d') || $force) { 394 if (!$model || $model->updated_date != date('Y-m-d') || $force) {
395 - $res = $api->getGoogleRank($api_no, $model->lang, 7, $force); 395 + $res = $api->getGoogleRank($api_no, $lang_list[$api_no], 7, $force);
396 if (!$res) { 396 if (!$res) {
397 throw new \Exception("接口数据获取失败,api_no:{$api_no},lang"); 397 throw new \Exception("接口数据获取失败,api_no:{$api_no},lang");
398 } 398 }
@@ -426,15 +426,15 @@ class RankDataLogic extends BaseLogic @@ -426,15 +426,15 @@ class RankDataLogic extends BaseLogic
426 if(!$lang){ 426 if(!$lang){
427 foreach ($data as &$ranks){ 427 foreach ($data as &$ranks){
428 ksort($ranks); 428 ksort($ranks);
429 - foreach ($ranks as &$rank){  
430 - //处理排名  
431 - if(!in_array($project_id, $without_project_ids)){  
432 - if($rank['position'] >= 10){  
433 - $rank['position'] -= 5;  
434 - }  
435 - //todo 需要特殊处理排名的项目  
436 - }  
437 - } 429 +// foreach ($ranks as &$rank){
  430 +// //处理排名
  431 +// if(!in_array($project_id, $without_project_ids)){
  432 +// if($rank['position'] >= 10){
  433 +// $rank['position'] -= 5;
  434 +// }
  435 +// //todo 需要特殊处理排名的项目
  436 +// }
  437 +// }
438 $last = Arr::last($ranks); 438 $last = Arr::last($ranks);
439 //第一名 439 //第一名
440 if($last['position'] == 1){ 440 if($last['position'] == 1){