作者 刘锟

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

@@ -7,6 +7,7 @@ use App\Helper\SemrushApi; @@ -7,6 +7,7 @@ use App\Helper\SemrushApi;
7 use App\Models\Domain\DomainInfo; 7 use App\Models\Domain\DomainInfo;
8 use App\Models\RankData\ExternalLinks as ExternalLinksModel; 8 use App\Models\RankData\ExternalLinks as ExternalLinksModel;
9 use App\Models\Project\DeployOptimize; 9 use App\Models\Project\DeployOptimize;
  10 +use App\Utils\HttpUtils;
10 use App\Utils\LogUtils; 11 use App\Utils\LogUtils;
11 12
12 /** 13 /**
@@ -40,9 +41,12 @@ class ExternalLinks extends BaseCommands @@ -40,9 +41,12 @@ class ExternalLinks extends BaseCommands
40 $error = 0; 41 $error = 0;
41 $semrushApi = new SemrushApi(); 42 $semrushApi = new SemrushApi();
42 //有排名api编号的项目 43 //有排名api编号的项目
43 - $list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray(); 44 + $list = DeployOptimize::where('api_no', '>', 0)->select('domain', 'api_no', 'project_id')->get()->toArray();
44 LogUtils::info('start rank_data_external_links:' . count($list)); 45 LogUtils::info('start rank_data_external_links:' . count($list));
45 - foreach ($list as $project_id => $domain) { 46 + foreach ($list as $item) {
  47 + $project_id = $item['project_id'];
  48 + $api_no = $item['api_no'];
  49 + $domain = $item['domain'];
46 if(!$domain){ 50 if(!$domain){
47 continue; 51 continue;
48 } 52 }
@@ -54,6 +58,16 @@ class ExternalLinks extends BaseCommands @@ -54,6 +58,16 @@ class ExternalLinks extends BaseCommands
54 $model = new ExternalLinksModel(); 58 $model = new ExternalLinksModel();
55 } 59 }
56 60
  61 +
  62 + //5.0
  63 + try {
  64 + $data = HttpUtils::get("https://www.quanqiusou.cn/semrush-api/data_json/{$api_no}.json", []);
  65 + $data = Arr::s2a($data);
  66 + }catch (\Exception $e){
  67 + $data = [];
  68 + }
  69 +
  70 + if(!$data){
57 //外链数据 71 //外链数据
58 $domain = (new DomainInfo())->getDomain($domain); 72 $domain = (new DomainInfo())->getDomain($domain);
59 $res = $semrushApi->backlinks_overview($domain); 73 $res = $semrushApi->backlinks_overview($domain);
@@ -63,6 +77,7 @@ class ExternalLinks extends BaseCommands @@ -63,6 +77,7 @@ class ExternalLinks extends BaseCommands
63 } 77 }
64 78
65 $data = $this->_data($project_id, $res['total']); 79 $data = $this->_data($project_id, $res['total']);
  80 + }
66 81
67 $model->project_id = $project_id; 82 $model->project_id = $project_id;
68 $model->total = $data['total']; 83 $model->total = $data['total'];
@@ -2,10 +2,12 @@ @@ -2,10 +2,12 @@
2 2
3 namespace App\Console\Commands\RankData; 3 namespace App\Console\Commands\RankData;
4 4
  5 +use App\Helper\Arr;
5 use App\Helper\SemrushApi; 6 use App\Helper\SemrushApi;
6 use App\Models\Domain\DomainInfo; 7 use App\Models\Domain\DomainInfo;
7 use App\Models\RankData\RecommDomain as RecommDomainModel; 8 use App\Models\RankData\RecommDomain as RecommDomainModel;
8 use App\Models\Project\DeployOptimize; 9 use App\Models\Project\DeployOptimize;
  10 +use App\Utils\HttpUtils;
9 use App\Utils\LogUtils; 11 use App\Utils\LogUtils;
10 12
11 /** 13 /**
@@ -39,9 +41,12 @@ class RecommDomain extends BaseCommands @@ -39,9 +41,12 @@ class RecommDomain extends BaseCommands
39 $error = 0; 41 $error = 0;
40 $semrushApi = new SemrushApi(); 42 $semrushApi = new SemrushApi();
41 //有排名api编号的项目 43 //有排名api编号的项目
42 - $list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray(); 44 + $list = DeployOptimize::where('api_no', '>', 0)->select('domain', 'api_no', 'project_id')->get()->toArray();
43 LogUtils::info('start rank_data_recomm_domain:' . count($list)); 45 LogUtils::info('start rank_data_recomm_domain:' . count($list));
44 - foreach ($list as $project_id => $domain) { 46 + foreach ($list as $item) {
  47 + $project_id = $item['project_id'];
  48 + $api_no = $item['api_no'];
  49 + $domain = $item['domain'];
45 if(!$domain){ 50 if(!$domain){
46 continue; 51 continue;
47 } 52 }
@@ -53,9 +58,20 @@ class RecommDomain extends BaseCommands @@ -53,9 +58,20 @@ class RecommDomain extends BaseCommands
53 $model = new RecommDomainModel(); 58 $model = new RecommDomainModel();
54 } 59 }
55 60
  61 + //5.0
  62 + try {
  63 + $data = HttpUtils::get("https://www.quanqiusou.cn/semrush-api/data_json/{$api_no}.json", []);
  64 + $data = Arr::s2a($data)['list'];
  65 + }catch (\Exception $e){
  66 + $data = [];
  67 + }
  68 +
  69 + if(!$data){
56 //外链引荐域名 70 //外链引荐域名
57 $domain = (new DomainInfo())->getDomain($domain); 71 $domain = (new DomainInfo())->getDomain($domain);
58 $data = $semrushApi->backlinks_refdomains($domain); 72 $data = $semrushApi->backlinks_refdomains($domain);
  73 + }
  74 +
59 if (!$data) { 75 if (!$data) {
60 $error++; 76 $error++;
61 continue; 77 continue;
@@ -59,11 +59,11 @@ class UpdateMainHtml extends Command @@ -59,11 +59,11 @@ class UpdateMainHtml extends Command
59 */ 59 */
60 public function handle(){ 60 public function handle(){
61 $projectModel = new Project(); 61 $projectModel = new Project();
62 - $list = $projectModel->list(['id'=>99]); 62 + $list = $projectModel->list(['id'=>223]);
63 foreach ($list as $v){ 63 foreach ($list as $v){
64 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; 64 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
65 ProjectServer::useProject($v['id']); 65 ProjectServer::useProject($v['id']);
66 - $this->editRoute(); 66 + $this->setBlogCustomContent();
67 DB::disconnect('custom_mysql'); 67 DB::disconnect('custom_mysql');
68 } 68 }
69 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 69 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
@@ -85,8 +85,8 @@ class UpdateMainHtml extends Command @@ -85,8 +85,8 @@ class UpdateMainHtml extends Command
85 $data[] = [ 85 $data[] = [
86 'name'=>$v['name'], 86 'name'=>$v['name'],
87 'route'=>$v['alias'], 87 'route'=>$v['alias'],
88 - 'project_id'=>99,  
89 - 'operator_id'=>366, 88 + 'project_id'=>223,
  89 + 'operator_id'=>569,
90 'seo_title'=>$v['seo_title'], 90 'seo_title'=>$v['seo_title'],
91 'seo_keywords'=>$v['seo_keywords'], 91 'seo_keywords'=>$v['seo_keywords'],
92 'seo_description'=>$v['seo_des'], 92 'seo_description'=>$v['seo_des'],
@@ -118,8 +118,8 @@ class UpdateMainHtml extends Command @@ -118,8 +118,8 @@ class UpdateMainHtml extends Command
118 'remark'=>$v['remark'], 118 'remark'=>$v['remark'],
119 'route'=>$v['url'], 119 'route'=>$v['url'],
120 'image'=>$v['image'], 120 'image'=>$v['image'],
121 - 'project_id'=>99,  
122 - 'operator_id'=>366, 121 + 'project_id'=>223,
  122 + 'operator_id'=>569,
123 'seo_title'=>$v['seo_title'], 123 'seo_title'=>$v['seo_title'],
124 'seo_keywords'=>$v['seo_keywords'], 124 'seo_keywords'=>$v['seo_keywords'],
125 'seo_description'=>$v['seo_description'], 125 'seo_description'=>$v['seo_description'],
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace App\Http\Controllers\Aside\Optimize; 3 namespace App\Http\Controllers\Aside\Optimize;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
  6 +use App\Helper\Arr;
6 use App\Http\Controllers\Aside\BaseController; 7 use App\Http\Controllers\Aside\BaseController;
7 use App\Http\Logic\Aside\Optimize\OptimizeLogic; 8 use App\Http\Logic\Aside\Optimize\OptimizeLogic;
8 use App\Http\Logic\Aside\Project\ProjectLogic; 9 use App\Http\Logic\Aside\Project\ProjectLogic;
@@ -47,6 +48,7 @@ class OptimizeController extends BaseController @@ -47,6 +48,7 @@ class OptimizeController extends BaseController
47 $data = $rankDataModel->read(['project_id'=>$v['id'],'lang'=>''],['first_page_num','indexed_pages_num']); 48 $data = $rankDataModel->read(['project_id'=>$v['id'],'lang'=>''],['first_page_num','indexed_pages_num']);
48 $v['first_page_num'] = $data['first_page_num'] ?? 0; 49 $v['first_page_num'] = $data['first_page_num'] ?? 0;
49 $v['indexed_pages_num'] = $data['indexed_pages_num'] ?? 0; 50 $v['indexed_pages_num'] = $data['indexed_pages_num'] ?? 0;
  51 + $v['g'] = $this->getGNum($v['id']);
50 $v = $this->handleParam($v); 52 $v = $this->handleParam($v);
51 $lists['list'][$k] = $v; 53 $lists['list'][$k] = $v;
52 } 54 }
@@ -55,6 +57,27 @@ class OptimizeController extends BaseController @@ -55,6 +57,27 @@ class OptimizeController extends BaseController
55 } 57 }
56 58
57 /** 59 /**
  60 + * @remark :统计数量
  61 + * @name :getGNum
  62 + * @author :lyh
  63 + * @method :post
  64 + * @time :2024/1/6 11:12
  65 + */
  66 + public function getGNum($project_id){
  67 + $num = 0;
  68 + $list = RankData::where('project_id', $project_id)->where('lang', '')->value('data') ?: [];
  69 + if(!empty($list)){
  70 + foreach ($list as $v) {
  71 + $last = Arr::last($v);
  72 + if(isset($last['g']) && ($last['g'] == 1)){
  73 + $num = $num+1;
  74 + }
  75 + }
  76 + }
  77 + return $num;
  78 + }
  79 +
  80 + /**
58 * @remark :参数处理 81 * @remark :参数处理
59 * @name :handleParam 82 * @name :handleParam
60 * @author :lyh 83 * @author :lyh
@@ -264,12 +264,36 @@ class InitHtmlLogic extends BaseLogic @@ -264,12 +264,36 @@ class InitHtmlLogic extends BaseLogic
264 if($info === false){ 264 if($info === false){
265 $html = ''; 265 $html = '';
266 }else{ 266 }else{
  267 + $type = $this->getCustomizedType($this->param['type'],$is_list);
  268 + $commonTemplateModel = new BTemplateCommon();
  269 + $commonInfo = $commonTemplateModel->read(['template_id' => 0,'type'=>$type]);
  270 + if($commonInfo !== false){
  271 + $info['main_html'] = $this->handleAllHtml($commonInfo,$info['main_html']);
  272 + }
267 $html = $info['main_html']; 273 $html = $info['main_html'];
268 } 274 }
  275 + //更新头部底部
269 return $this->success(['html'=>$html]); 276 return $this->success(['html'=>$html]);
270 } 277 }
271 278
272 /** 279 /**
  280 + * @remark :返回整个html截取代码
  281 + * @name :handleAllHtml
  282 + * @author :lyh
  283 + * @method :post
  284 + * @time :2023/12/13 15:39
  285 + */
  286 + public function handleAllHtml($commonInfo,$html){
  287 + if(!empty($commonInfo)){
  288 + $html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $commonInfo['head_html'], $html);
  289 + $html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $commonInfo['footer_html'], $html);
  290 + $html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $commonInfo['head_css'], $html);
  291 + $html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $commonInfo['footer_css'], $html);
  292 + }
  293 + return $html;
  294 + }
  295 +
  296 + /**
273 * @remark :保存定制html 297 * @remark :保存定制html
274 * @name :saveHtml 298 * @name :saveHtml
275 * @author :lyh 299 * @author :lyh
@@ -292,6 +316,8 @@ class InitHtmlLogic extends BaseLogic @@ -292,6 +316,8 @@ class InitHtmlLogic extends BaseLogic
292 }else{ 316 }else{
293 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]); 317 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
294 } 318 }
  319 + //更新头部底部
  320 + $this->saveCustomizeCommon($this->param['html'],$this->param['type'],$is_list);
295 }catch (\Exception $exception){ 321 }catch (\Exception $exception){
296 $this->fail('保存失败,请联系开发人员'); 322 $this->fail('保存失败,请联系开发人员');
297 } 323 }
@@ -299,6 +325,68 @@ class InitHtmlLogic extends BaseLogic @@ -299,6 +325,68 @@ class InitHtmlLogic extends BaseLogic
299 } 325 }
300 326
301 /** 327 /**
  328 + * @remark :定制代码更新头部信息
  329 + * @name :saveCustomizeCommon
  330 + * @author :lyh
  331 + * @method :post
  332 + * @time :2024/1/6 10:29
  333 + */
  334 + public function saveCustomizeCommon($html,$source,$is_list){
  335 + $type = $this->getCustomizedType($source,$is_list);
  336 + $templateCommonModel = new BTemplateCommon();
  337 + $commonInfo = $templateCommonModel->read(['template_id'=>0,'type'=>$type]);//查看当前头部是否存在
  338 + $handleInfo = $this->handleCommonParam($html);
  339 + if($commonInfo === false){
  340 + $data = [
  341 + 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],
  342 + 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
  343 + 'type'=>$type,'template_id'=>0, 'project_id'=>$this->user['project_id'],
  344 + ];
  345 + $templateCommonModel->add($data);
  346 + }else{
  347 + $data = [
  348 + 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],
  349 + 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
  350 + ];
  351 + $templateCommonModel->edit($data,['id'=>$commonInfo['id']]);
  352 + }
  353 + return $this->success();
  354 + }
  355 +
  356 + /**
  357 + * @remark :定制页面头部类型---根据source获取type类型
  358 + * @name :getType
  359 + * @author :lyh
  360 + * @method :post
  361 + * @time :2023/11/16 11:20
  362 + */
  363 + public function getCustomizedType($source,$is_list){
  364 + $type = BTemplate::TYPE_HOME;
  365 + if($source == BTemplate::SOURCE_PRODUCT){
  366 + if($is_list == BTemplate::IS_LIST){
  367 + $type = BTemplate::TYPE_PRODUCT_LIST;
  368 + }else{
  369 + $type = BTemplate::TYPE_PRODUCT_DETAIL;
  370 + }
  371 + }
  372 + if($source == BTemplate::SOURCE_BLOG){
  373 + if($is_list == BTemplate::IS_LIST){
  374 + $type = BTemplate::TYPE_BLOG_LIST;
  375 + }else{
  376 + $type = BTemplate::TYPE_BLOG_DETAIL;
  377 + }
  378 + }
  379 + if($source == BTemplate::SOURCE_NEWS){
  380 + if($is_list == BTemplate::IS_LIST){
  381 + $type = BTemplate::TYPE_NEWS_LIST;
  382 + }else{
  383 + $type = BTemplate::TYPE_NEWS_DETAIL;
  384 + }
  385 + }
  386 + return $type;
  387 + }
  388 +
  389 + /**
302 * @remark :前端获取设置模块(侧边栏) 390 * @remark :前端获取设置模块(侧边栏)
303 * @name :getInitModuleMain 391 * @name :getInitModuleMain
304 * @author :lyh 392 * @author :lyh
@@ -199,7 +199,9 @@ class KeywordLogic extends BaseLogic @@ -199,7 +199,9 @@ class KeywordLogic extends BaseLogic
199 RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); 199 RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
200 //生成一条删除路由记录 200 //生成一条删除路由记录
201 $info = $this->model->read(['id'=>$id],['id','route']); 201 $info = $this->model->read(['id'=>$id],['id','route']);
  202 + if($info !== false){
202 $this->curlDelRoute(['route'=>$info['route']]); 203 $this->curlDelRoute(['route'=>$info['route']]);
  204 + }
203 return $this->success(); 205 return $this->success();
204 } 206 }
205 207