作者 lyh

变更数据

@@ -127,4 +127,21 @@ class GeoLinkController extends BaseController @@ -127,4 +127,21 @@ class GeoLinkController extends BaseController
127 } 127 }
128 $this->response('success',Code::SUCCESS,$data); 128 $this->response('success',Code::SUCCESS,$data);
129 } 129 }
  130 +
  131 + /**
  132 + * @remark :执行da值返回数据
  133 + * @name :daResultData
  134 + * @author :lyh
  135 + * @method :post
  136 + * @time :2025/10/9 09:39
  137 + */
  138 + public function daResultData(){
  139 + $this->request->validate([
  140 + 'id'=>'required',
  141 + ],[
  142 + 'id.required' => 'ID不能为空',
  143 + ]);
  144 + $data = $this->logic->daResultData();
  145 + $this->response('success',Code::SUCCESS,$data);
  146 + }
130 } 147 }
@@ -79,4 +79,21 @@ class LinkDataController extends BaseController @@ -79,4 +79,21 @@ class LinkDataController extends BaseController
79 $result = $linkData->del(['id'=>['in',$this->param['id']]]); 79 $result = $linkData->del(['id'=>['in',$this->param['id']]]);
80 $this->response('success',Code::SUCCESS,$result); 80 $this->response('success',Code::SUCCESS,$result);
81 } 81 }
  82 +
  83 + /**
  84 + * @remark :执行da值返回数据
  85 + * @name :daResultData
  86 + * @author :lyh
  87 + * @method :post
  88 + * @time :2025/10/9 09:39
  89 + */
  90 + public function daResultData(LinkDataLogic $logic){
  91 + $this->request->validate([
  92 + 'id'=>'required',
  93 + ],[
  94 + 'id.required' => 'ID不能为空',
  95 + ]);
  96 + $data = $logic->daResultData();
  97 + $this->response('success',Code::SUCCESS,$data);
  98 + }
82 } 99 }
@@ -11,6 +11,7 @@ namespace App\Http\Logic\Aside\Geo; @@ -11,6 +11,7 @@ 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\GeoLink; 13 use App\Models\Geo\GeoLink;
  14 +use App\Services\Geo\GeoService;
14 15
15 /** 16 /**
16 * @remark :geo权威新闻(链接数据) 17 * @remark :geo权威新闻(链接数据)
@@ -101,4 +102,64 @@ class GeoLinkLogic extends BaseLogic @@ -101,4 +102,64 @@ class GeoLinkLogic extends BaseLogic
101 } 102 }
102 return $this->success(); 103 return $this->success();
103 } 104 }
  105 +
  106 + /**
  107 + * @remark :返回数据data
  108 + * @name :daResultData
  109 + * @author :lyh
  110 + * @method :post
  111 + * @time :2025/10/9 09:43
  112 + */
  113 + public function daResultData()
  114 + {
  115 + $info = $this->model->read(['id'=>$this->param['id']]);
  116 + if($info === false){
  117 + $this->fail('当前数据不存在或者已被删除');
  118 + }
  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{
  128 + return $this->success($info);
  129 + }
  130 + }else{
  131 + $host = $this->getDomainWithWWW($info['url']);
  132 + $result = $geoService->daResult($host);
  133 + }
  134 + if(!isset($result['data']) || empty($result['data'])){
  135 + $this->model->edit(['time'=>date('Y-m-d')], ['id'=>$info['id']]);
  136 + return $this->success($info);
  137 + }
  138 + $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 +
  143 + /**
  144 + * @remark :获取域名
  145 + * @name :getDomainWithWWW
  146 + * @author :lyh
  147 + * @method :post
  148 + * @time :2025/10/9 10:28
  149 + */
  150 + public function getDomainWithWWW($url) {
  151 + // 获取 host
  152 + $host = parse_url($url, PHP_URL_HOST);
  153 + // 去掉端口号等情况
  154 + $host = preg_replace('/:\d+$/', '', $host);
  155 + // 分割域名
  156 + $parts = explode('.', $host);
  157 + // 判断是几段
  158 + $count = count($parts);
  159 + // 如果只有两段,比如 fox8.com、theamericawatch.com,就拼接 www.
  160 + if ($count === 2) {
  161 + return 'www.' . $host;
  162 + }
  163 + return $host;
  164 + }
104 } 165 }
@@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\SeoSetting; @@ -11,6 +11,7 @@ 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\SeoSetting\LinkData; 13 use App\Models\SeoSetting\LinkData;
  14 +use App\Services\Geo\GeoService;
14 15
15 /** 16 /**
16 * @remark :获取外链数据 17 * @remark :获取外链数据
@@ -50,4 +51,64 @@ class LinkDataLogic extends BaseLogic @@ -50,4 +51,64 @@ class LinkDataLogic extends BaseLogic
50 } 51 }
51 return $this->success(); 52 return $this->success();
52 } 53 }
  54 +
  55 + /**
  56 + * @remark :返回数据data
  57 + * @name :daResultData
  58 + * @author :lyh
  59 + * @method :post
  60 + * @time :2025/10/9 09:43
  61 + */
  62 + public function daResultData()
  63 + {
  64 + $info = $this->model->read(['id'=>$this->param['id']]);
  65 + if($info === false){
  66 + $this->fail('当前数据不存在或者已被删除');
  67 + }
  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{
  77 + return $this->success($info);
  78 + }
  79 + }else{
  80 + $host = $this->getDomainWithWWW($info['da_values']);
  81 + $result = $geoService->daResult($host);
  82 + }
  83 + if(!isset($result['data']) || empty($result['data'])){
  84 + $this->model->edit(['time'=>date('Y-m-d')], ['id'=>$info['id']]);
  85 + return $this->success($info);
  86 + }
  87 + $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);
  90 + }
  91 +
  92 + /**
  93 + * @remark :获取域名
  94 + * @name :getDomainWithWWW
  95 + * @author :lyh
  96 + * @method :post
  97 + * @time :2025/10/9 10:28
  98 + */
  99 + public function getDomainWithWWW($url) {
  100 + // 获取 host
  101 + $host = parse_url($url, PHP_URL_HOST);
  102 + // 去掉端口号等情况
  103 + $host = preg_replace('/:\d+$/', '', $host);
  104 + // 分割域名
  105 + $parts = explode('.', $host);
  106 + // 判断是几段
  107 + $count = count($parts);
  108 + // 如果只有两段,比如 fox8.com、theamericawatch.com,就拼接 www.
  109 + if ($count === 2) {
  110 + return 'www.' . $host;
  111 + }
  112 + return $host;
  113 + }
53 } 114 }
@@ -137,4 +137,18 @@ class GeoService @@ -137,4 +137,18 @@ class GeoService
137 $result = Http::post($url, $param); 137 $result = Http::post($url, $param);
138 return $result->json(); 138 return $result->json();
139 } 139 }
  140 +
  141 + /**
  142 + * @remark :根据域名获取da值
  143 + * @name :daResult
  144 + * @author :lyh
  145 + * @method :post
  146 + * @time :2025/10/9 09:33
  147 + */
  148 + public function daResult($domain)
  149 + {
  150 + $url = 'https://www.cmer.site/api/get_domain_da?domain='.$domain;
  151 + $result = http_get($url);
  152 + return $result;
  153 + }
140 } 154 }
@@ -583,6 +583,7 @@ Route::middleware(['aloginauth'])->group(function () { @@ -583,6 +583,7 @@ Route::middleware(['aloginauth'])->group(function () {
583 Route::any('/info', [Aside\Geo\GeoLinkController::class, 'info'])->name('admin.geo_link_info'); 583 Route::any('/info', [Aside\Geo\GeoLinkController::class, 'info'])->name('admin.geo_link_info');
584 Route::any('/del', [Aside\Geo\GeoLinkController::class, 'del'])->name('admin.geo_link_del'); 584 Route::any('/del', [Aside\Geo\GeoLinkController::class, 'del'])->name('admin.geo_link_del');
585 Route::any('/downloadGeoLink', [Aside\Geo\GeoLinkController::class, 'downloadGeoLink'])->name('admin.geo_link_downloadGeoLink'); 585 Route::any('/downloadGeoLink', [Aside\Geo\GeoLinkController::class, 'downloadGeoLink'])->name('admin.geo_link_downloadGeoLink');
  586 + Route::any('/daResultData', [Aside\Geo\GeoLinkController::class, 'daResultData'])->name('admin.geo_link_daResultData');
586 }); 587 });
587 }); 588 });
588 // 任务相关 589 // 任务相关
@@ -715,6 +715,7 @@ Route::middleware(['bloginauth'])->group(function () { @@ -715,6 +715,7 @@ Route::middleware(['bloginauth'])->group(function () {
715 Route::any('/batchSave', [\App\Http\Controllers\Bside\SeoSetting\LinkDataController::class, 'batchSave'])->name('link_data_batchSave'); 715 Route::any('/batchSave', [\App\Http\Controllers\Bside\SeoSetting\LinkDataController::class, 'batchSave'])->name('link_data_batchSave');
716 Route::any('/info', [\App\Http\Controllers\Bside\SeoSetting\LinkDataController::class, 'info'])->name('link_data_info'); 716 Route::any('/info', [\App\Http\Controllers\Bside\SeoSetting\LinkDataController::class, 'info'])->name('link_data_info');
717 Route::any('/del', [\App\Http\Controllers\Bside\SeoSetting\LinkDataController::class, 'del'])->name('link_data_del'); 717 Route::any('/del', [\App\Http\Controllers\Bside\SeoSetting\LinkDataController::class, 'del'])->name('link_data_del');
  718 + Route::any('/daResultData', [\App\Http\Controllers\Bside\SeoSetting\LinkDataController::class, 'daResultData'])->name('link_data_daResultData');
718 }); 719 });
719 720
720 //seo白帽 域名设置 721 //seo白帽 域名设置