作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -63,7 +63,7 @@ class GeoQuestionRes extends Command @@ -63,7 +63,7 @@ class GeoQuestionRes extends Command
63 $geoQuestionModel->edit(['status'=>$geoQuestionModel::STATUS_CLOSE],['id'=>$task_id]); 63 $geoQuestionModel->edit(['status'=>$geoQuestionModel::STATUS_CLOSE],['id'=>$task_id]);
64 continue; 64 continue;
65 } 65 }
66 - if(empty($taskInfo['question']) || ($taskInfo['project_id'] != 4533) || (empty($taskInfo['keywords']) && empty($taskInfo['url']) && empty($taskInfo['expect_result']))){ 66 + if(empty($taskInfo['question']) || (empty($taskInfo['keywords']) && empty($taskInfo['url']) && empty($taskInfo['expect_result']))){
67 $this->output('task id: ' . $task_id . ', error: 任务数据缺失, continue!'); 67 $this->output('task id: ' . $task_id . ', error: 任务数据缺失, continue!');
68 $geoQuestionModel->edit(['status'=>$geoQuestionModel::STATUS_CLOSE],['id'=>$task_id]); 68 $geoQuestionModel->edit(['status'=>$geoQuestionModel::STATUS_CLOSE],['id'=>$task_id]);
69 continue; 69 continue;
@@ -337,12 +337,13 @@ class GeoQuestionRes extends Command @@ -337,12 +337,13 @@ class GeoQuestionRes extends Command
337 $key = 'geo_task_list'; 337 $key = 'geo_task_list';
338 $task_id = Redis::rpop($key); 338 $task_id = Redis::rpop($key);
339 if(empty($task_id)){ 339 if(empty($task_id)){
340 - $questionModel = new GeoQuestion();  
341 - $ids = $questionModel->selectField(['status'=>$questionModel::STATUS_OPEN,'next_time'=>['<=',date('Y-m-d')]],'id');  
342 - if(!empty($ids)){  
343 - foreach ($ids as $id) {  
344 - Redis::lpush($key, $id);  
345 - } 340 + # TODO 按照项目进行获取, 一个项目当天需要将所有跑完
  341 + $project_id = GeoQuestion::where('status', GeoQuestion::STATUS_OPEN)->where('next_time', '<=', date('Y-m-d'))->value('project_id');
  342 + if (empty($project_id))
  343 + return $task_id;
  344 + $ids = GeoQuestion::where(['project_id' => $project_id, 'status' => GeoQuestion::STATUS_OPEN])->where('current_time', '<>', date('Y-m-d'))->pluck('id');
  345 + foreach ($ids as $id) {
  346 + Redis::lpush($key, $id);
346 } 347 }
347 $task_id = Redis::rpop($key); 348 $task_id = Redis::rpop($key);
348 } 349 }
@@ -11,6 +11,7 @@ namespace App\Console\Commands\LyhTest; @@ -11,6 +11,7 @@ namespace App\Console\Commands\LyhTest;
11 11
12 use App\Helper\OaGlobalsoApi; 12 use App\Helper\OaGlobalsoApi;
13 use App\Models\Ai\AiBlog; 13 use App\Models\Ai\AiBlog;
  14 +use App\Models\Geo\GeoLink;
14 use App\Models\News\News; 15 use App\Models\News\News;
15 use App\Models\Product\Category; 16 use App\Models\Product\Category;
16 use App\Models\Project\AggregateKeywordAffix; 17 use App\Models\Project\AggregateKeywordAffix;
@@ -35,6 +36,7 @@ use App\Services\Geo\GeoService; @@ -35,6 +36,7 @@ use App\Services\Geo\GeoService;
35 use App\Services\MidJourneyService; 36 use App\Services\MidJourneyService;
36 use App\Services\ProjectServer; 37 use App\Services\ProjectServer;
37 use Illuminate\Console\Command; 38 use Illuminate\Console\Command;
  39 +use Illuminate\Support\Carbon;
38 use Illuminate\Support\Facades\DB; 40 use Illuminate\Support\Facades\DB;
39 41
40 class lyhDemo extends Command 42 class lyhDemo extends Command
@@ -57,6 +59,51 @@ class lyhDemo extends Command @@ -57,6 +59,51 @@ class lyhDemo extends Command
57 return $this->translate_action(); 59 return $this->translate_action();
58 } 60 }
59 61
  62 + public function _actionDa()
  63 + {
  64 + $geoLinkModel = new GeoLink();
  65 + $lists = $geoLinkModel->list(['da'=>0,'time'=>null]);
  66 + $geoService = new GeoService();
  67 + foreach ($lists as $info){
  68 + if(!empty($info['time'])){
  69 + $start = Carbon::parse($info['time']);
  70 + $end = Carbon::parse(date('Y-m-d'));
  71 + $diff = $start->diffInDays($end);
  72 + if($diff >= 60){
  73 + $host = $this->getDomainWithWWW($info['url']);
  74 + $result = $geoService->daResult($host);
  75 + }else{
  76 + continue;
  77 + }
  78 + }else{
  79 + $host = $this->getDomainWithWWW($info['url']);
  80 + $result = $geoService->daResult($host);
  81 + }
  82 + if(!isset($result['data']) || empty($result['data'])){
  83 + $this->model->edit(['time'=>date('Y-m-d')], ['id'=>$info['id']]);
  84 + continue;
  85 + }
  86 + $info['da'] = (int)$result['data']['mozDA'];//获取数据中的da值
  87 + $this->model->edit(['time'=>date('Y-m-d'),'da'=>$info['da']], ['id'=>$info['id']]);
  88 + }
  89 + }
  90 +
  91 + public function getDomainWithWWW($url) {
  92 + // 获取 host
  93 + $host = parse_url($url, PHP_URL_HOST);
  94 + // 去掉端口号等情况
  95 + $host = preg_replace('/:\d+$/', '', $host);
  96 + // 分割域名
  97 + $parts = explode('.', $host);
  98 + // 判断是几段
  99 + $count = count($parts);
  100 + // 如果只有两段,比如 fox8.com、theamericawatch.com,就拼接 www.
  101 + if ($count === 2) {
  102 + return 'www.' . $host;
  103 + }
  104 + return $host;
  105 + }
  106 +
60 /** 107 /**
61 * @remark :查看路由是否为空 108 * @remark :查看路由是否为空
62 * @name :_actionRoute 109 * @name :_actionRoute
@@ -54,7 +54,7 @@ class ExternalLinkMake extends Command @@ -54,7 +54,7 @@ class ExternalLinkMake extends Command
54 continue; 54 continue;
55 } 55 }
56 56
57 - $yesterday = RankDataLog::where(['project_id' => $project->id, 'date' => date('Y-m-d', '-1 day')])->first(); 57 + $yesterday = RankDataLog::where(['project_id' => $project->id, 'date' => date('Y-m-d', strtotime('-1 day'))])->first();
58 if (FALSE == empty($yesterday) && $yesterday->is_compliance == 1){ 58 if (FALSE == empty($yesterday) && $yesterday->is_compliance == 1){
59 $this->output('项目昨日达标: ' . $project->id . ', 跳过'); 59 $this->output('项目昨日达标: ' . $project->id . ', 跳过');
60 continue; 60 continue;
@@ -10,8 +10,10 @@ @@ -10,8 +10,10 @@
10 namespace App\Http\Logic\Aside\Geo; 10 namespace App\Http\Logic\Aside\Geo;
11 11
12 use App\Http\Logic\Aside\BaseLogic; 12 use App\Http\Logic\Aside\BaseLogic;
  13 +use App\Models\Geo\DomainDa;
13 use App\Models\Geo\GeoLink; 14 use App\Models\Geo\GeoLink;
14 use App\Services\Geo\GeoService; 15 use App\Services\Geo\GeoService;
  16 +use Illuminate\Support\Carbon;
15 17
16 /** 18 /**
17 * @remark :geo权威新闻(链接数据) 19 * @remark :geo权威新闻(链接数据)
@@ -116,28 +118,34 @@ class GeoLinkLogic extends BaseLogic @@ -116,28 +118,34 @@ class GeoLinkLogic extends BaseLogic
116 if($info === false){ 118 if($info === false){
117 $this->fail('当前数据不存在或者已被删除'); 119 $this->fail('当前数据不存在或者已被删除');
118 } 120 }
119 - $geoService = new GeoService();  
120 - if(!empty($info['time'])){  
121 - $date1 = new DateTime($info['time']);  
122 - $date2 = new DateTime(date('Y-m-d'));  
123 - $diff = $date1->diff($date2);  
124 - if($diff >= 60){  
125 - $host = $this->getDomainWithWWW($info['url']);  
126 - $result = $geoService->daResult($host);  
127 - }else{ 121 + $host = $this->getDomainWithWWW($info['url']);
  122 + $domainDaModel = new DomainDa();
  123 + $daInfo = $domainDaModel->read(['domain'=>$host]);
  124 + if($daInfo !== false){
  125 + //判断时间是否大于60天
  126 + $start = Carbon::parse(date('Y-m-d', strtotime($daInfo['updated_at'])));
  127 + $end = Carbon::parse(date('Y-m-d'));
  128 + $diff = $start->diffInDays($end);
  129 + if($diff <= 60){
  130 + $info['da'] = $daInfo['da'];
  131 + $this->model->edit(['da'=>$daInfo['da'],'time'=>date('Y-m-d')], ['id'=>$info['id']]);
128 return $this->success($info); 132 return $this->success($info);
129 } 133 }
130 - }else{  
131 - $host = $this->getDomainWithWWW($info['url']);  
132 - $result = $geoService->daResult($host);  
133 } 134 }
  135 + $geoService = new GeoService();
  136 + $result = $geoService->daResult($host);
134 if(!isset($result['data']) || empty($result['data'])){ 137 if(!isset($result['data']) || empty($result['data'])){
135 - $this->model->edit(['time'=>date('Y-m-d')], ['id'=>$info['id']]);  
136 return $this->success($info); 138 return $this->success($info);
137 } 139 }
138 $info['da'] = (int)$result['data']['mozDA'];//获取数据中的da值 140 $info['da'] = (int)$result['data']['mozDA'];//获取数据中的da值
139 - $this->model->edit(['time'=>date('Y-m-d'),'da'=>$info['da']], ['id'=>$info['id']]);  
140 - return $this->success($result); 141 + //保存数据
  142 + if($daInfo !== false){
  143 + $domainDaModel->edit(['da'=>$info['da'],'result'=>json_encode($result,true)],['id'=>$daInfo['id']]);
  144 + }else{
  145 + $domainDaModel->addReturnId(['da'=>$info['da'],'domain'=>$host,'result'=>json_encode($result,true)]);
  146 + }
  147 + $this->model->edit(['da'=>$info['da'],'time'=>date('Y-m-d')], ['id'=>$info['id']]);
  148 + return $this->success($info);
141 } 149 }
142 150
143 /** 151 /**
@@ -203,13 +203,13 @@ class TicketUploadDataLogic extends BaseLogic @@ -203,13 +203,13 @@ class TicketUploadDataLogic extends BaseLogic
203 'intro'=>$info['text']['remark'], 203 'intro'=>$info['text']['remark'],
204 'category_id'=>$category_id ?? '', 204 'category_id'=>$category_id ?? '',
205 'keyword_id'=>$keyword_id ?? '', 205 'keyword_id'=>$keyword_id ?? '',
206 - 'status'=>0, 206 + 'status'=>1,
207 ]; 207 ];
208 $id = $productModel->addReturnId($data); 208 $id = $productModel->addReturnId($data);
209 CategoryRelated::saveRelated($id, $info['text']['category_id'] ?? []);//分类关联 209 CategoryRelated::saveRelated($id, $info['text']['category_id'] ?? []);//分类关联
210 KeywordRelated::saveRelated($id,$info['text']['keyword_id'] ?? []);//关键字关联 210 KeywordRelated::saveRelated($id,$info['text']['keyword_id'] ?? []);//关键字关联
211 $route = RouteMap::setRoute($data['title'],RouteMap::SOURCE_PRODUCT,$id,$info['project_id']); 211 $route = RouteMap::setRoute($data['title'],RouteMap::SOURCE_PRODUCT,$id,$info['project_id']);
212 - $this->model->edit(['route'=>$route],['id'=>$id]); 212 + $productModel->edit(['route'=>$route],['id'=>$id]);
213 }catch (\Exception $e){ 213 }catch (\Exception $e){
214 $this->fail('保存失败,请联系管理员'); 214 $this->fail('保存失败,请联系管理员');
215 } 215 }
@@ -237,13 +237,13 @@ class TicketUploadDataLogic extends BaseLogic @@ -237,13 +237,13 @@ class TicketUploadDataLogic extends BaseLogic
237 'image'=>$info['text']['image'], 237 'image'=>$info['text']['image'],
238 'text'=>$info['text']['remark'], 238 'text'=>$info['text']['remark'],
239 'category_id'=>$category_id ?? '', 239 'category_id'=>$category_id ?? '',
240 - 'status'=>0, 240 + 'status'=>1,
241 ]; 241 ];
242 try { 242 try {
243 $blogModel = new Blog(); 243 $blogModel = new Blog();
244 $id = $blogModel->addReturnId($data); 244 $id = $blogModel->addReturnId($data);
245 $route = RouteMap::setRoute($data['name'],RouteMap::SOURCE_BLOG,$id,$info['project_id']); 245 $route = RouteMap::setRoute($data['name'],RouteMap::SOURCE_BLOG,$id,$info['project_id']);
246 - $this->model->edit(['url'=>$route],['id'=>$id]); 246 + $blogModel->edit(['url'=>$route],['id'=>$id]);
247 }catch (\Exception $e){ 247 }catch (\Exception $e){
248 $this->fail('保存失败,请联系管理员'); 248 $this->fail('保存失败,请联系管理员');
249 } 249 }
@@ -271,13 +271,13 @@ class TicketUploadDataLogic extends BaseLogic @@ -271,13 +271,13 @@ class TicketUploadDataLogic extends BaseLogic
271 'image'=>$info['text']['image'], 271 'image'=>$info['text']['image'],
272 'text'=>$info['text']['remark'], 272 'text'=>$info['text']['remark'],
273 'category_id'=>$category_id ?? '', 273 'category_id'=>$category_id ?? '',
274 - 'status'=>0, 274 + 'status'=>1,
275 ]; 275 ];
276 try { 276 try {
277 $newsModel = new News(); 277 $newsModel = new News();
278 $id = $newsModel->addReturnId($data); 278 $id = $newsModel->addReturnId($data);
279 $route = RouteMap::setRoute($data['name'],RouteMap::SOURCE_NEWS,$id,$info['project_id']); 279 $route = RouteMap::setRoute($data['name'],RouteMap::SOURCE_NEWS,$id,$info['project_id']);
280 - $this->model->edit(['route'=>$route],['id'=>$id]); 280 + $newsModel->edit(['url'=>$route],['id'=>$id]);
281 }catch (\Exception $e){ 281 }catch (\Exception $e){
282 $this->fail('保存失败,请联系管理员'); 282 $this->fail('保存失败,请联系管理员');
283 } 283 }
@@ -10,8 +10,11 @@ @@ -10,8 +10,11 @@
10 namespace App\Http\Logic\Bside\SeoSetting; 10 namespace App\Http\Logic\Bside\SeoSetting;
11 11
12 use App\Http\Logic\Bside\BaseLogic; 12 use App\Http\Logic\Bside\BaseLogic;
  13 +use App\Models\Geo\DomainDa;
13 use App\Models\SeoSetting\LinkData; 14 use App\Models\SeoSetting\LinkData;
14 use App\Services\Geo\GeoService; 15 use App\Services\Geo\GeoService;
  16 +use Illuminate\Support\Carbon;
  17 +use Nette\Utils\DateTime;
15 18
16 /** 19 /**
17 * @remark :获取外链数据 20 * @remark :获取外链数据
@@ -65,28 +68,34 @@ class LinkDataLogic extends BaseLogic @@ -65,28 +68,34 @@ class LinkDataLogic extends BaseLogic
65 if($info === false){ 68 if($info === false){
66 $this->fail('当前数据不存在或者已被删除'); 69 $this->fail('当前数据不存在或者已被删除');
67 } 70 }
68 - $geoService = new GeoService();  
69 - if(!empty($info['time'])){  
70 - $date1 = new DateTime($info['time']);  
71 - $date2 = new DateTime(date('Y-m-d'));  
72 - $diff = $date1->diff($date2);  
73 - if($diff >= 60){  
74 - $host = $this->getDomainWithWWW($info['da_values']);  
75 - $result = $geoService->daResult($host);  
76 - }else{ 71 + $host = $this->getDomainWithWWW($info['url']);
  72 + $domainDaModel = new DomainDa();
  73 + $daInfo = $domainDaModel->read(['domain'=>$host]);
  74 + if($daInfo !== false){
  75 + //判断时间是否大于60天
  76 + $start = Carbon::parse(date('Y-m-d', strtotime($daInfo['updated_at'])));
  77 + $end = Carbon::parse(date('Y-m-d'));
  78 + $diff = $start->diffInDays($end);
  79 + if($diff <= 60){
  80 + $info['da_values'] = $daInfo['da'];
  81 + $this->model->edit(['da_values'=>$daInfo['da'],'time'=>date('Y-m-d')], ['id'=>$info['id']]);
77 return $this->success($info); 82 return $this->success($info);
78 } 83 }
79 - }else{  
80 - $host = $this->getDomainWithWWW($info['da_values']);  
81 - $result = $geoService->daResult($host);  
82 } 84 }
  85 + $geoService = new GeoService();
  86 + $result = $geoService->daResult($host);
83 if(!isset($result['data']) || empty($result['data'])){ 87 if(!isset($result['data']) || empty($result['data'])){
84 - $this->model->edit(['time'=>date('Y-m-d')], ['id'=>$info['id']]);  
85 return $this->success($info); 88 return $this->success($info);
86 } 89 }
87 $info['da_values'] = (int)$result['data']['mozDA'];//获取数据中的da值 90 $info['da_values'] = (int)$result['data']['mozDA'];//获取数据中的da值
88 - $this->model->edit(['time'=>date('Y-m-d'),'da_values'=>$info['da_values']], ['id'=>$info['id']]);  
89 - return $this->success($result); 91 + //保存数据
  92 + if($daInfo !== false){
  93 + $domainDaModel->edit(['da'=>$info['da_values'],'result'=>json_encode($result,true)],['id'=>$daInfo['id']]);
  94 + }else{
  95 + $domainDaModel->addReturnId(['da'=>$info['da_values'],'domain'=>$host,'result'=>json_encode($result,true)]);
  96 + }
  97 + $this->model->edit(['da_values'=>$info['da_values'],'time'=>date('Y-m-d')], ['id'=>$info['id']]);
  98 + return $this->success($info);
90 } 99 }
91 100
92 /** 101 /**
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :DomainDa.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/10/11 10:18
  8 + */
  9 +
  10 +namespace App\Models\Geo;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +class DomainDa extends Base
  15 +{
  16 + protected $table = 'gl_domain_da';
  17 +}