作者 刘锟

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

... ... @@ -7,6 +7,7 @@ use App\Helper\SemrushApi;
use App\Models\Domain\DomainInfo;
use App\Models\RankData\ExternalLinks as ExternalLinksModel;
use App\Models\Project\DeployOptimize;
use App\Utils\HttpUtils;
use App\Utils\LogUtils;
/**
... ... @@ -40,9 +41,12 @@ class ExternalLinks extends BaseCommands
$error = 0;
$semrushApi = new SemrushApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray();
$list = DeployOptimize::where('api_no', '>', 0)->select('domain', 'api_no', 'project_id')->get()->toArray();
LogUtils::info('start rank_data_external_links:' . count($list));
foreach ($list as $project_id => $domain) {
foreach ($list as $item) {
$project_id = $item['project_id'];
$api_no = $item['api_no'];
$domain = $item['domain'];
if(!$domain){
continue;
}
... ... @@ -54,6 +58,16 @@ class ExternalLinks extends BaseCommands
$model = new ExternalLinksModel();
}
//5.0
try {
$data = HttpUtils::get("https://www.quanqiusou.cn/semrush-api/data_json/{$api_no}.json", []);
$data = Arr::s2a($data);
}catch (\Exception $e){
$data = [];
}
if(!$data){
//外链数据
$domain = (new DomainInfo())->getDomain($domain);
$res = $semrushApi->backlinks_overview($domain);
... ... @@ -63,6 +77,7 @@ class ExternalLinks extends BaseCommands
}
$data = $this->_data($project_id, $res['total']);
}
$model->project_id = $project_id;
$model->total = $data['total'];
... ...
... ... @@ -2,10 +2,12 @@
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\SemrushApi;
use App\Models\Domain\DomainInfo;
use App\Models\RankData\RecommDomain as RecommDomainModel;
use App\Models\Project\DeployOptimize;
use App\Utils\HttpUtils;
use App\Utils\LogUtils;
/**
... ... @@ -39,9 +41,12 @@ class RecommDomain extends BaseCommands
$error = 0;
$semrushApi = new SemrushApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray();
$list = DeployOptimize::where('api_no', '>', 0)->select('domain', 'api_no', 'project_id')->get()->toArray();
LogUtils::info('start rank_data_recomm_domain:' . count($list));
foreach ($list as $project_id => $domain) {
foreach ($list as $item) {
$project_id = $item['project_id'];
$api_no = $item['api_no'];
$domain = $item['domain'];
if(!$domain){
continue;
}
... ... @@ -53,9 +58,20 @@ class RecommDomain extends BaseCommands
$model = new RecommDomainModel();
}
//5.0
try {
$data = HttpUtils::get("https://www.quanqiusou.cn/semrush-api/data_json/{$api_no}.json", []);
$data = Arr::s2a($data)['list'];
}catch (\Exception $e){
$data = [];
}
if(!$data){
//外链引荐域名
$domain = (new DomainInfo())->getDomain($domain);
$data = $semrushApi->backlinks_refdomains($domain);
}
if (!$data) {
$error++;
continue;
... ...
... ... @@ -59,11 +59,11 @@ class UpdateMainHtml extends Command
*/
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['id'=>99]);
$list = $projectModel->list(['id'=>223]);
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->editRoute();
$this->setBlogCustomContent();
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
... ... @@ -85,8 +85,8 @@ class UpdateMainHtml extends Command
$data[] = [
'name'=>$v['name'],
'route'=>$v['alias'],
'project_id'=>99,
'operator_id'=>366,
'project_id'=>223,
'operator_id'=>569,
'seo_title'=>$v['seo_title'],
'seo_keywords'=>$v['seo_keywords'],
'seo_description'=>$v['seo_des'],
... ... @@ -118,8 +118,8 @@ class UpdateMainHtml extends Command
'remark'=>$v['remark'],
'route'=>$v['url'],
'image'=>$v['image'],
'project_id'=>99,
'operator_id'=>366,
'project_id'=>223,
'operator_id'=>569,
'seo_title'=>$v['seo_title'],
'seo_keywords'=>$v['seo_keywords'],
'seo_description'=>$v['seo_description'],
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Aside\Optimize;
use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Optimize\OptimizeLogic;
use App\Http\Logic\Aside\Project\ProjectLogic;
... ... @@ -47,6 +48,7 @@ class OptimizeController extends BaseController
$data = $rankDataModel->read(['project_id'=>$v['id'],'lang'=>''],['first_page_num','indexed_pages_num']);
$v['first_page_num'] = $data['first_page_num'] ?? 0;
$v['indexed_pages_num'] = $data['indexed_pages_num'] ?? 0;
$v['g'] = $this->getGNum($v['id']);
$v = $this->handleParam($v);
$lists['list'][$k] = $v;
}
... ... @@ -55,6 +57,27 @@ class OptimizeController extends BaseController
}
/**
* @remark :统计数量
* @name :getGNum
* @author :lyh
* @method :post
* @time :2024/1/6 11:12
*/
public function getGNum($project_id){
$num = 0;
$list = RankData::where('project_id', $project_id)->where('lang', '')->value('data') ?: [];
if(!empty($list)){
foreach ($list as $v) {
$last = Arr::last($v);
if(isset($last['g']) && ($last['g'] == 1)){
$num = $num+1;
}
}
}
return $num;
}
/**
* @remark :参数处理
* @name :handleParam
* @author :lyh
... ...
... ... @@ -264,12 +264,36 @@ class InitHtmlLogic extends BaseLogic
if($info === false){
$html = '';
}else{
$type = $this->getCustomizedType($this->param['type'],$is_list);
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read(['template_id' => 0,'type'=>$type]);
if($commonInfo !== false){
$info['main_html'] = $this->handleAllHtml($commonInfo,$info['main_html']);
}
$html = $info['main_html'];
}
//更新头部底部
return $this->success(['html'=>$html]);
}
/**
* @remark :返回整个html截取代码
* @name :handleAllHtml
* @author :lyh
* @method :post
* @time :2023/12/13 15:39
*/
public function handleAllHtml($commonInfo,$html){
if(!empty($commonInfo)){
$html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $commonInfo['head_html'], $html);
$html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $commonInfo['footer_html'], $html);
$html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $commonInfo['head_css'], $html);
$html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $commonInfo['footer_css'], $html);
}
return $html;
}
/**
* @remark :保存定制html
* @name :saveHtml
* @author :lyh
... ... @@ -292,6 +316,8 @@ class InitHtmlLogic extends BaseLogic
}else{
$bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
}
//更新头部底部
$this->saveCustomizeCommon($this->param['html'],$this->param['type'],$is_list);
}catch (\Exception $exception){
$this->fail('保存失败,请联系开发人员');
}
... ... @@ -299,6 +325,68 @@ class InitHtmlLogic extends BaseLogic
}
/**
* @remark :定制代码更新头部信息
* @name :saveCustomizeCommon
* @author :lyh
* @method :post
* @time :2024/1/6 10:29
*/
public function saveCustomizeCommon($html,$source,$is_list){
$type = $this->getCustomizedType($source,$is_list);
$templateCommonModel = new BTemplateCommon();
$commonInfo = $templateCommonModel->read(['template_id'=>0,'type'=>$type]);//查看当前头部是否存在
$handleInfo = $this->handleCommonParam($html);
if($commonInfo === false){
$data = [
'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],
'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
'type'=>$type,'template_id'=>0, 'project_id'=>$this->user['project_id'],
];
$templateCommonModel->add($data);
}else{
$data = [
'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],
'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
];
$templateCommonModel->edit($data,['id'=>$commonInfo['id']]);
}
return $this->success();
}
/**
* @remark :定制页面头部类型---根据source获取type类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/11/16 11:20
*/
public function getCustomizedType($source,$is_list){
$type = BTemplate::TYPE_HOME;
if($source == BTemplate::SOURCE_PRODUCT){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_PRODUCT_LIST;
}else{
$type = BTemplate::TYPE_PRODUCT_DETAIL;
}
}
if($source == BTemplate::SOURCE_BLOG){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_BLOG_LIST;
}else{
$type = BTemplate::TYPE_BLOG_DETAIL;
}
}
if($source == BTemplate::SOURCE_NEWS){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_NEWS_LIST;
}else{
$type = BTemplate::TYPE_NEWS_DETAIL;
}
}
return $type;
}
/**
* @remark :前端获取设置模块(侧边栏)
* @name :getInitModuleMain
* @author :lyh
... ...
... ... @@ -199,7 +199,9 @@ class KeywordLogic extends BaseLogic
RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
//生成一条删除路由记录
$info = $this->model->read(['id'=>$id],['id','route']);
if($info !== false){
$this->curlDelRoute(['route'=>$info['route']]);
}
return $this->success();
}
... ...