作者 刘锟

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

... ... @@ -63,7 +63,7 @@ class GeoQuestionRes extends Command
$geoQuestionModel->edit(['status'=>$geoQuestionModel::STATUS_CLOSE],['id'=>$task_id]);
continue;
}
if(empty($taskInfo['question']) || ($taskInfo['project_id'] != 4533) || (empty($taskInfo['keywords']) && empty($taskInfo['url']) && empty($taskInfo['expect_result']))){
if(empty($taskInfo['question']) || (empty($taskInfo['keywords']) && empty($taskInfo['url']) && empty($taskInfo['expect_result']))){
$this->output('task id: ' . $task_id . ', error: 任务数据缺失, continue!');
$geoQuestionModel->edit(['status'=>$geoQuestionModel::STATUS_CLOSE],['id'=>$task_id]);
continue;
... ... @@ -337,13 +337,14 @@ class GeoQuestionRes extends Command
$key = 'geo_task_list';
$task_id = Redis::rpop($key);
if(empty($task_id)){
$questionModel = new GeoQuestion();
$ids = $questionModel->selectField(['status'=>$questionModel::STATUS_OPEN,'next_time'=>['<=',date('Y-m-d')]],'id');
if(!empty($ids)){
# TODO 按照项目进行获取, 一个项目当天需要将所有跑完
$project_id = GeoQuestion::where('status', GeoQuestion::STATUS_OPEN)->where('next_time', '<=', date('Y-m-d'))->value('project_id');
if (empty($project_id))
return $task_id;
$ids = GeoQuestion::where(['project_id' => $project_id, 'status' => GeoQuestion::STATUS_OPEN])->where('current_time', '<>', date('Y-m-d'))->pluck('id');
foreach ($ids as $id) {
Redis::lpush($key, $id);
}
}
$task_id = Redis::rpop($key);
}
return $task_id;
... ...
... ... @@ -11,6 +11,7 @@ namespace App\Console\Commands\LyhTest;
use App\Helper\OaGlobalsoApi;
use App\Models\Ai\AiBlog;
use App\Models\Geo\GeoLink;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Project\AggregateKeywordAffix;
... ... @@ -35,6 +36,7 @@ use App\Services\Geo\GeoService;
use App\Services\MidJourneyService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class lyhDemo extends Command
... ... @@ -57,6 +59,51 @@ class lyhDemo extends Command
return $this->translate_action();
}
public function _actionDa()
{
$geoLinkModel = new GeoLink();
$lists = $geoLinkModel->list(['da'=>0,'time'=>null]);
$geoService = new GeoService();
foreach ($lists as $info){
if(!empty($info['time'])){
$start = Carbon::parse($info['time']);
$end = Carbon::parse(date('Y-m-d'));
$diff = $start->diffInDays($end);
if($diff >= 60){
$host = $this->getDomainWithWWW($info['url']);
$result = $geoService->daResult($host);
}else{
continue;
}
}else{
$host = $this->getDomainWithWWW($info['url']);
$result = $geoService->daResult($host);
}
if(!isset($result['data']) || empty($result['data'])){
$this->model->edit(['time'=>date('Y-m-d')], ['id'=>$info['id']]);
continue;
}
$info['da'] = (int)$result['data']['mozDA'];//获取数据中的da值
$this->model->edit(['time'=>date('Y-m-d'),'da'=>$info['da']], ['id'=>$info['id']]);
}
}
public function getDomainWithWWW($url) {
// 获取 host
$host = parse_url($url, PHP_URL_HOST);
// 去掉端口号等情况
$host = preg_replace('/:\d+$/', '', $host);
// 分割域名
$parts = explode('.', $host);
// 判断是几段
$count = count($parts);
// 如果只有两段,比如 fox8.com、theamericawatch.com,就拼接 www.
if ($count === 2) {
return 'www.' . $host;
}
return $host;
}
/**
* @remark :查看路由是否为空
* @name :_actionRoute
... ...
... ... @@ -54,7 +54,7 @@ class ExternalLinkMake extends Command
continue;
}
$yesterday = RankDataLog::where(['project_id' => $project->id, 'date' => date('Y-m-d', '-1 day')])->first();
$yesterday = RankDataLog::where(['project_id' => $project->id, 'date' => date('Y-m-d', strtotime('-1 day'))])->first();
if (FALSE == empty($yesterday) && $yesterday->is_compliance == 1){
$this->output('项目昨日达标: ' . $project->id . ', 跳过');
continue;
... ...
... ... @@ -10,8 +10,10 @@
namespace App\Http\Logic\Aside\Geo;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Geo\DomainDa;
use App\Models\Geo\GeoLink;
use App\Services\Geo\GeoService;
use Illuminate\Support\Carbon;
/**
* @remark :geo权威新闻(链接数据)
... ... @@ -116,28 +118,34 @@ class GeoLinkLogic extends BaseLogic
if($info === false){
$this->fail('当前数据不存在或者已被删除');
}
$geoService = new GeoService();
if(!empty($info['time'])){
$date1 = new DateTime($info['time']);
$date2 = new DateTime(date('Y-m-d'));
$diff = $date1->diff($date2);
if($diff >= 60){
$host = $this->getDomainWithWWW($info['url']);
$result = $geoService->daResult($host);
}else{
$domainDaModel = new DomainDa();
$daInfo = $domainDaModel->read(['domain'=>$host]);
if($daInfo !== false){
//判断时间是否大于60天
$start = Carbon::parse(date('Y-m-d', strtotime($daInfo['updated_at'])));
$end = Carbon::parse(date('Y-m-d'));
$diff = $start->diffInDays($end);
if($diff <= 60){
$info['da'] = $daInfo['da'];
$this->model->edit(['da'=>$daInfo['da'],'time'=>date('Y-m-d')], ['id'=>$info['id']]);
return $this->success($info);
}
}else{
$host = $this->getDomainWithWWW($info['url']);
$result = $geoService->daResult($host);
}
$geoService = new GeoService();
$result = $geoService->daResult($host);
if(!isset($result['data']) || empty($result['data'])){
$this->model->edit(['time'=>date('Y-m-d')], ['id'=>$info['id']]);
return $this->success($info);
}
$info['da'] = (int)$result['data']['mozDA'];//获取数据中的da值
$this->model->edit(['time'=>date('Y-m-d'),'da'=>$info['da']], ['id'=>$info['id']]);
return $this->success($result);
//保存数据
if($daInfo !== false){
$domainDaModel->edit(['da'=>$info['da'],'result'=>json_encode($result,true)],['id'=>$daInfo['id']]);
}else{
$domainDaModel->addReturnId(['da'=>$info['da'],'domain'=>$host,'result'=>json_encode($result,true)]);
}
$this->model->edit(['da'=>$info['da'],'time'=>date('Y-m-d')], ['id'=>$info['id']]);
return $this->success($info);
}
/**
... ...
... ... @@ -203,13 +203,13 @@ class TicketUploadDataLogic extends BaseLogic
'intro'=>$info['text']['remark'],
'category_id'=>$category_id ?? '',
'keyword_id'=>$keyword_id ?? '',
'status'=>0,
'status'=>1,
];
$id = $productModel->addReturnId($data);
CategoryRelated::saveRelated($id, $info['text']['category_id'] ?? []);//分类关联
KeywordRelated::saveRelated($id,$info['text']['keyword_id'] ?? []);//关键字关联
$route = RouteMap::setRoute($data['title'],RouteMap::SOURCE_PRODUCT,$id,$info['project_id']);
$this->model->edit(['route'=>$route],['id'=>$id]);
$productModel->edit(['route'=>$route],['id'=>$id]);
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
... ... @@ -237,13 +237,13 @@ class TicketUploadDataLogic extends BaseLogic
'image'=>$info['text']['image'],
'text'=>$info['text']['remark'],
'category_id'=>$category_id ?? '',
'status'=>0,
'status'=>1,
];
try {
$blogModel = new Blog();
$id = $blogModel->addReturnId($data);
$route = RouteMap::setRoute($data['name'],RouteMap::SOURCE_BLOG,$id,$info['project_id']);
$this->model->edit(['url'=>$route],['id'=>$id]);
$blogModel->edit(['url'=>$route],['id'=>$id]);
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
... ... @@ -271,13 +271,13 @@ class TicketUploadDataLogic extends BaseLogic
'image'=>$info['text']['image'],
'text'=>$info['text']['remark'],
'category_id'=>$category_id ?? '',
'status'=>0,
'status'=>1,
];
try {
$newsModel = new News();
$id = $newsModel->addReturnId($data);
$route = RouteMap::setRoute($data['name'],RouteMap::SOURCE_NEWS,$id,$info['project_id']);
$this->model->edit(['route'=>$route],['id'=>$id]);
$newsModel->edit(['url'=>$route],['id'=>$id]);
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
... ...
... ... @@ -10,8 +10,11 @@
namespace App\Http\Logic\Bside\SeoSetting;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Geo\DomainDa;
use App\Models\SeoSetting\LinkData;
use App\Services\Geo\GeoService;
use Illuminate\Support\Carbon;
use Nette\Utils\DateTime;
/**
* @remark :获取外链数据
... ... @@ -65,28 +68,34 @@ class LinkDataLogic extends BaseLogic
if($info === false){
$this->fail('当前数据不存在或者已被删除');
}
$geoService = new GeoService();
if(!empty($info['time'])){
$date1 = new DateTime($info['time']);
$date2 = new DateTime(date('Y-m-d'));
$diff = $date1->diff($date2);
if($diff >= 60){
$host = $this->getDomainWithWWW($info['da_values']);
$result = $geoService->daResult($host);
}else{
$host = $this->getDomainWithWWW($info['url']);
$domainDaModel = new DomainDa();
$daInfo = $domainDaModel->read(['domain'=>$host]);
if($daInfo !== false){
//判断时间是否大于60天
$start = Carbon::parse(date('Y-m-d', strtotime($daInfo['updated_at'])));
$end = Carbon::parse(date('Y-m-d'));
$diff = $start->diffInDays($end);
if($diff <= 60){
$info['da_values'] = $daInfo['da'];
$this->model->edit(['da_values'=>$daInfo['da'],'time'=>date('Y-m-d')], ['id'=>$info['id']]);
return $this->success($info);
}
}else{
$host = $this->getDomainWithWWW($info['da_values']);
$result = $geoService->daResult($host);
}
$geoService = new GeoService();
$result = $geoService->daResult($host);
if(!isset($result['data']) || empty($result['data'])){
$this->model->edit(['time'=>date('Y-m-d')], ['id'=>$info['id']]);
return $this->success($info);
}
$info['da_values'] = (int)$result['data']['mozDA'];//获取数据中的da值
$this->model->edit(['time'=>date('Y-m-d'),'da_values'=>$info['da_values']], ['id'=>$info['id']]);
return $this->success($result);
//保存数据
if($daInfo !== false){
$domainDaModel->edit(['da'=>$info['da_values'],'result'=>json_encode($result,true)],['id'=>$daInfo['id']]);
}else{
$domainDaModel->addReturnId(['da'=>$info['da_values'],'domain'=>$host,'result'=>json_encode($result,true)]);
}
$this->model->edit(['da_values'=>$info['da_values'],'time'=>date('Y-m-d')], ['id'=>$info['id']]);
return $this->success($info);
}
/**
... ...
<?php
/**
* @remark :
* @name :DomainDa.php
* @author :lyh
* @method :post
* @time :2025/10/11 10:18
*/
namespace App\Models\Geo;
use App\Models\Base;
class DomainDa extends Base
{
protected $table = 'gl_domain_da';
}
... ...