作者 赵彬吉

rank data

<?php
namespace App\Console\Commands\RankData;
use Illuminate\Console\Command;
/**
* Class BaseCommands
* @package App\Console\Commands\RankData
* @author zbj
* @date 2023/5/11
*/
abstract class BaseCommands extends Command
{
/**
* @author zbj
* @date 2023/5/11
*/
public function handle()
{
$try = 3;
do{
$try--;
if($try == 0){
break;
}
$error = 0;
try {
if(!$this->do()){
$error = 1;
}
}catch (\Exception $e){
errorLog($this->signature . ' error', [], $e);
$error = 1;
}
if($error){
echo 'error';
}
$error && sleep(60);
}while($error);
}
abstract function do();
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\SemrushApi;
use App\Models\RankData\ExternalLinks as ExternalLinksModel;
use App\Models\Project\DeployOptimize;
/**
* Class ExternalLinks
* @package App\Console\Commands
* @author zbj
* @date 2023/5/9
*/
class ExternalLinks extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_external_links';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-外链数据';
/**
* @author zbj
* @date 2023/5/6
*/
public function do()
{
$error = 0;
$semrushApi = new SemrushApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray();
foreach ($list as $project_id => $domain) {
if(!$domain){
continue;
}
$model = ExternalLinksModel::where('project_id', $project_id)->first();
if ($model && $model->updated_date == getThisWeekStarDate()) {
continue;
}
if (!$model) {
$model = new ExternalLinksModel();
}
//外链数据
$res = $semrushApi->backlinks_overview($domain);
if (!$res) {
$error++;
continue;
}
$data = $this->_data($project_id, $res['total']);
$model->project_id = $project_id;
$model->total = $data['total'];
$model->data = $data['data'];
$model->updated_date = date('Y-m-d');
$model->save();
}
return !$error;
}
/**
* 构造chat数据
* @param $project_id
* @param $total
* @return array|mixed
* @author zbj
* @date 2023/5/10
*/
public function _data($project_id, $total)
{
// //外链数
$data['total'] = intval($total);
$model = ExternalLinksModel::where('project_id', $project_id)->first();
if ($model) {
//特殊处理的外链数
// $data['total'] = ($total > $model->total) ? intval($total) : $model->total; //特殊处理的
//chat数据
$chat_data = Arr::s2a($model['data']);
if (empty($chat_data[date('Y-m-d')])) {
array_shift($chat_data);
}
} else {
//chat数据
for ($i = 1; $i < 12; $i++) {
$date = date("Y-m-d", strtotime(-7 * $i . 'days'));
$chat_data[$date] = ceil($total - ($total * rand(5, 10) / 100));
}
}
$chat_data[date('Y-m-d')] = $data['total'];
$data['data'] = $chat_data;
return $data;
}
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\QuanqiusouApi;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\IndexedPages as IndexedPagesModel;
/**
* Class IndexedPages
* @package App\Console\Commands
* @author zbj
* @date 2023/5/11
*/
class IndexedPages extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_indexed_pages';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-页面收录数';
/**
* @throws \Exception
* @author zbj
* @date 2023/5/11
*/
public function do(){
$error = 0;
$api = new QuanqiusouApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('api_no', 'project_id')->toArray();
foreach ($list as $project_id => $api_no) {
$model = IndexedPagesModel::where('project_id', $project_id)->first();
if($model && $model->updated_date == getThisWeekStarDate()){
continue;
}
if(!$model){
$model = new IndexedPagesModel();
}
$res = $api->getSiteResPer($api_no);
if(!$res){
$error++;
continue;
}
$model->project_id = $project_id;
$model->data = $res['data'];
$model->updated_date = date('Y-m-d');
$model->save();
}
return !$error;
}
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\QuanqiusouApi;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\RankData as GoogleRankModel;
/**
* Class GoogleRank
* @package App\Console\Commands
* @author zbj
* @date 2023/5/6
*/
class RankData extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data';
/**
* The console command description.
*
* @var string
*/
protected $description = '谷歌排名数据';
/**
* @author zbj
* @date 2023/5/6
*/
public function do()
{
$error = 0;
$api = new QuanqiusouApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>' , 0)->select('api_no','minor_languages','project_id')->get();
//当日所有站点谷歌收录数据
$site_res = $api->getSiteRes();
if(!$site_res){
return false;
}
foreach ($list as $item){
$model = GoogleRankModel::where('project_id', $item['project_id'])->where('lang', '')->first();
if (!$model || $model->updated_date == date('Y-m-d')) {
$res = $api->getGoogleRank($item['api_no']);
if(!$res){
$error++;
continue;
}
//收录数
$indexed_pages_num = $site_res[$item['api_no']];
$this->save_rank($item['project_id'], $res, $indexed_pages_num);
}
//有小语种的
if($item['minor_languages']){
$model = GoogleRankModel::where('project_id', $item['project_id'])->where('lang', '<>', '')->first();
if (!$model || $model->updated_date == date('Y-m-d')) {
$res = $api->getGoogleRank($item['api_no'], 1);
if(!$res){
$error++;
continue;
}
$data = [];
//不同的小语种取出来
foreach ($res as $keyword => $v){
$data[Arr::last($v)['lang']][$keyword] = $v;
}
foreach ($data as $lang => $rank){
$this->save_rank($item['project_id'], $rank, 0, $lang);
}
}
}
}
return !$error;
}
/**
* @param $project_id
* @param int $indexed_pages_num
* @param $data
* @param string $lang
* @author zbj
* @date 2023/5/8
*/
public function save_rank($project_id, $data, int $indexed_pages_num = 0, string $lang = ''){
$without_project_ids = []; //不用处理排名的项目
$first_num = $first_page_num = $first_three_pages_num = $first_five_pages_num = $first_ten_pages_num = 0;
if(!$lang){
foreach ($data as &$ranks){
foreach ($ranks as &$rank){
//处理排名
if(!in_array($project_id, $without_project_ids)){
if($rank['position'] >= 10){
$rank['position'] -= 5;
}
//todo 需要特殊处理排名的项目
}
}
$last = Arr::last($ranks);
//第一名
if($last['position'] == 1){
$first_num ++;
}
//排名第一页
if($last['position'] > 0 && $last['position'] <= 10){
$first_page_num ++;
}
//排名前三页
if($last['position'] > 0 && $last['position'] <= 30){
$first_three_pages_num ++;
}
//排名前五页
if($last['position'] > 0 && $last['position'] <= 50){
$first_five_pages_num ++;
}
//排名前十页
if($last['position'] > 0 && $last['position'] <= 100){
$first_ten_pages_num ++;
}
}
}
$where = [
'project_id' => $project_id,
'lang' => $lang
];
$model = GoogleRankModel::where($where)->first();
if(!$model){
$model = new GoogleRankModel();
}
//关键词达标天数
if($model->updated_date != date('Y-m-d')){
//保证关键词数
$keyword_num = DeployBuild::where('project_id', $project_id)->value('keyword_num');
if($first_page_num >= $keyword_num){
$model->compliance_day = $model->compliance_day + 1;
}
}
$model->project_id = $project_id;
$model->first_num = $first_num;
$model->first_page_num = $first_page_num;
$model->first_three_pages_num = $first_three_pages_num;
$model->first_five_pages_num = $first_five_pages_num;
$model->first_ten_pages_num = $first_ten_pages_num;
$model->indexed_pages_num = $indexed_pages_num;
$model->lang = $lang;
$model->data = $data;
$model->updated_date = date('Y-m-d');
$model->save();
}
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\QuanqiusouApi;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\RankWeek as RankWeekModel;
/**
* Class WeekRank
* @package App\Console\Commands
* @author zbj
* @date 2023/5/11
*/
class RankWeek extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_week';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-每周排名数据';
/**
* @author zbj
* @date 2023/5/6
*/
public function do()
{
$error = 0;
//获取每周排名数据
$api = new QuanqiusouApi();
$res = $api->getGoogleRankWeek();
if (!$res) {
return false;
}
$res = Arr::s2a($res);
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('api_no', 'project_id')->toArray();
foreach ($list as $project_id => $api_no) {
$rank_week = RankWeekModel::where('project_id', $project_id)->first();
if ($rank_week && $rank_week->updated_date == getThisWeekStarDate()) {
//本周数据已更新
continue;
}
if (!$rank_week) {
$rank_week = new RankWeekModel();
}
$rank_week->project_id = $project_id;
$rank_week->data = $res['data'][$api_no];
$rank_week->date = $res['date'];
$rank_week->updated_date = date('Y-m-d');
$rank_week->save();
}
return !$error;
}
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\SemrushApi;
use App\Models\RankData\RecommDomain as RecommDomainModel;
use App\Models\Project\DeployOptimize;
/**
* Class RecommDomain
* @package App\Console\Commands
* @author zbj
* @date 2023/5/9
*/
class RecommDomain extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_recomm_domain';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-外链引荐域名数据';
/**
* @author zbj
* @date 2023/5/6
*/
public function do()
{
$error = 0;
$semrushApi = new SemrushApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray();
foreach ($list as $project_id => $domain) {
if(!$domain){
continue;
}
$model = RecommDomainModel::where('project_id', $project_id)->first();
if ($model && $model->updated_date == getThisWeekStarDate()) {
continue;
}
if (!$model) {
$model = new RecommDomainModel();
}
//外链引荐域名
$data = $semrushApi->backlinks_refdomains($domain);
if (!$data) {
$error++;
continue;
}
$model->project_id = $project_id;
$model->data = $data;
$model->updated_date = date('Y-m-d');
$model->save();
}
return !$error;
}
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\GoogleSpeedApi;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\Speed as GoogleSpeedModel;
/**
* Class GoogleSpeed
* @package App\Console\Commands
* @author zbj
* @date 2023/5/10
*/
class Speed extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_speed';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-测速数据';
/**
* @author zbj
* @date 2023/5/10
*/
public function do()
{
$error = 0;
$googleSpeedApi = new GoogleSpeedApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray();
foreach ($list as $project_id => $domain) {
$model = GoogleSpeedModel::where('project_id', $project_id)->first();
if ($model && $model->updated_date == getThisWeekStarDate()) {
//今周已更新 跳过
continue;
}
$res = $googleSpeedApi->run($domain);
if (!$res) {
$error++;
}
if (!$model) {
$model = new GoogleSpeedModel;
}
$model->project_id = $project_id;
$model->data = $res;
$model->updated_date = date('Y-m-d');
$model->save();
}
return !$error;
}
}
... ...
... ... @@ -16,6 +16,12 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->command('rank_data')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每天凌晨执行一次
$schedule->command('rank_data_speed')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-测速数据,每周一凌晨执行一次
$schedule->command('rank_data_external_links')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-外链,每周一凌晨执行一次
$schedule->command('rank_data_indexed_pages')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-页面收录,每周一凌晨执行一次
$schedule->command('rank_data_recomm_domain')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-引荐域名,每周一凌晨执行一次
$schedule->command('rank_data_week')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次
}
/**
... ...
<?php
namespace App\Helper;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class PageSpeed
* @package App\Helper
* @author zbj
* @date 2023/5/10
*/
class GoogleSpeedApi
{
protected $areas = [
[
"area" => "洛杉矶",
"numericValue" => 0,
],
[
"area" => "圣地亚哥",
"numericValue" => 0,
],
[
"area" => "伦敦",
"numericValue" => 0,
],
[
"area" => "西雅图",
"numericValue" => 0,
],
[
"area" => "吉隆坡",
"numericValue" => 0,
],
[
"area" => "雅加达",
"numericValue" => 0,
],
[
"area" => "孟买",
"numericValue" => 0,
],
[
"area" => "迪拜",
"numericValue" => 0,
],
[
"area" => "法兰克福",
"numericValue" => 0,
],
[
"area" => "新加坡",
"numericValue" => 0,
],
[
"area" => "悉尼",
"numericValue" => 0,
],
[
"area" => "东京",
"numericValue" => 0,
],
[
"area" => "硅谷",
"numericValue" => 0,
],
[
"area" => "弗吉尼亚",
"numericValue" => 0,
],
[
"area" => "香港",
"numericValue" => 0,
],
[
"area" => "圣保罗",
"numericValue" => 0,
],
[
"area" => "雅典",
"numericValue" => 0,
],
[
"area" => "巴黎",
"numericValue" => 0,
],
[
"area" => "罗马",
"numericValue" => 0,
],
[
"area" => "马德里",
"numericValue" => 0,
],
];
/**
* @param $url
* @return array|false
* @author zbj
* @date 2023/5/10
*/
function run($url)
{
try {
$params = [
'url' => $url
];
$res = HttpUtils::get('http://45.136.131.72/api.php', $params);
if ($res) {
$res = Arr::s2a($res);
$area_data = Arr::s2a($res['area_data']);
}
$numericValue = $area_data[0]['numericValue'] ?? rand(500, 1000);
foreach ($this->areas as &$area) {
$start = -$numericValue * 0.5;
$end = $numericValue * 0.5;
$numer = rand($start, $end);
$area["numericValue"] = ceil($numericValue - $numer);
}
return [
"url" => $url,
"area_data" => $this->areas,
"created_at" => date("Y-m-d H:i:s")
];
} catch (\Exception | GuzzleException $e) {
errorLog('测速失败', $params, $e);
return false;
}
}
}
... ...
<?php
namespace App\Helper;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Cache;
/**
* Class QuanqiusouApi
* @package App\Helper
* @author zbj
* @date 2023/5/11
*/
class QuanqiusouApi
{
//接口地址
protected $url = 'http://api.quanqiusou.cn';
/**
* 所有站点收录页面数
* @author zbj
* @date 2023/5/11
*/
public function getSiteRes()
{
$key = 'quanqiusou_api_site_res_' . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/google-rank/echo_site_res.php';
try {
$res = HttpUtils::get($api_url, []);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取站点收录页面数', [], $e);
return false;
}
}
return $res;
}
/**
* 指定站点收录页面数
* @param $api_no
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getSiteResPer($api_no){
$key = 'quanqiusou_api_site_res_per_' . $api_no . '_' . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/google-rank/echo_site_res_per.php';
try {
$res = HttpUtils::get($api_url, ['apino' => $api_no]);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取站点收录页面数', [], $e);
return false;
}
}
return $res;
}
/**
* 获取谷歌排名数据
* @param $api_no
* @param int $lang
* @param int $day
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getGoogleRank($api_no, int $lang = 0, int $day = 7)
{
$key = "quanqiusou_api_rank_{$api_no}_{$lang}_{$day}_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$param = [
'key' => '289c1fc81c89d79c04ed4fd72822948e',
'w' => $api_no,
'type' => $day
];
if ($lang) {
$param['lang'] = $lang;
}
$api_url = $this->url . '/api';
try {
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取谷歌排名数据失败', $api_no, $e);
return false;
}
}
return $res;
}
/**
* 获取每周谷歌排名数据
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getGoogleRankWeek()
{
$key = "quanqiusou_api_week_data_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/google-rank/echo_week_data.php';
try {
$res = HttpUtils::get($api_url, []);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取每周谷歌排名数据失败', [], $e);
return false;
}
}
return $res;
}
}
... ...
<?php
namespace App\Helper;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class SemrushApi
* @package App\Helper
* @author zbj
* @date 2023/5/9
*/
class SemrushApi
{
//接口地址
protected $url = 'https://api.semrush.com';
protected $key = '2927058317c47207e4a8c4cacf10acfd';
/**
* 反链概述
*/
function backlinks_overview($target,$target_type = "root_domain"){
if($target){
$url = $this->url."/analytics/v1/?";
$params = [
"type"=>"backlinks_overview",
"key"=>$this->key,
"target"=>$target,
"target_type"=>$target_type,
"export_columns"=>"ascore,total,domains_num,urls_num,ips_num,ipclassc_num,follows_num,nofollows_num,sponsored_num,ugc_num,texts_num,images_num,forms_num,frames_num"
];
try {
$res = HttpUtils::get($url, $params);
return $this->data($res)[0];
}catch (\Exception|GuzzleException $e){
errorLog('获取站点外链数据', $params, $e);
return false;
}
}
return [];
}
/**
* 引荐域名
*/
public function backlinks_refdomains($target,$target_type = "root_domain",$offset = 0){
if($target){
$url = $this->url."/analytics/v1/?";
$params = [
"type"=>"backlinks_refdomains",
"key"=>$this->key,
"target"=>$target,
"target_type"=>$target_type,
"export_columns"=>"domain_ascore,domain,backlinks_num,ip,country,first_seen,last_seen",
"display_limit"=>10,
"display_offset"=>$offset
];
try {
$res = HttpUtils::get($url, $params);
return $this->data($res);
}catch (\Exception|GuzzleException $e){
errorLog('获取站点外链数据', $params, $e);
return false;
}
}
return [];
}
/**
* 处理结果
* @param $res
* @return array
* @author zbj
* @date 2023/5/9
*/
protected function data($res){
$temp = explode("\n",$res);
$arr =array_map(function ($v){
return explode(";",$v);
}, $temp);
$data = [];
for ($i = 1; $i < count($arr) - 1; $i++) {
$tmp = [];
foreach($arr[0] as $k =>$v){
$tmp[trim($v)] = trim($arr[$i][$k]);
}
$data[] = $tmp;
}
return $data;
}
}
... ...
<?php
use App\Utils\LogUtils;
use Illuminate\Support\Carbon;
define('HTTP_OPENAI_URL','http://openai.waimaoq.com/');
/**
... ... @@ -144,3 +145,16 @@ if (!function_exists('checkDomain')) {
}
}
}
if (!function_exists('getThisWeekStarDate')) {
/**
* 获取本周一的日期
* @return mixed
* @author zbj
* @date 2023/5/11
*/
function getThisWeekStarDate()
{
return Carbon::now()->startOfWeek()->toDateString();
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
use App\Http\Logic\Bside\RankDataLogic;
use Illuminate\Http\Request;
/**
* Class GoogleRankController
* @package App\Http\Controllers\Bside
* @author zbj
* @date 2023/5/9
*/
class RankDataController extends BaseController
{
public function index(RankDataLogic $logic)
{
$data = $logic->index();
return $this->success($data);
}
public function keywords_rank_list(RankDataLogic $logic){
$data = $logic->keywords_rank_list();
return $this->success($data);
}
}
... ...
<?php
namespace App\Http\Logic\Bside;
use App\Helper\Arr;
use App\Helper\Translate;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Models\RankData\ExternalLinks;
use App\Models\RankData\IndexedPages;
use App\Models\RankData\RankData;
use App\Models\RankData\RankWeek;
use App\Models\RankData\RecommDomain;
use App\Models\RankData\Speed;
use Illuminate\Support\Str;
class RankDataLogic extends BaseLogic
{
/**
* 统计数据
* @author zbj
* @date 2023/5/11
*/
public function index()
{
$project_id = $this->user['project_id'];
//查数据
$project = app(ProjectLogic::class)->getInfo($project_id);
$rank = RankData::where('project_id', $project_id)->first();
$rank_week = RankWeek::where('project_id', $project_id)->first();
$recomm_domain = RecommDomain::where('project_id', $project_id)->first();
$external_links = ExternalLinks::where('project_id', $project_id)->first();
$indexed_pages = IndexedPages::where('project_id', $project_id)->first();
$speed = Speed::where('project_id', $project_id)->first();
//排名数据
$data = [
'first_num' => $rank['first_num'] ?? 0,
'first_page_num' => $rank['first_page_num'] ?? 0,
'first_three_pages_num' => $rank['first_three_pages_num'] ?? 0,
'first_five_pages_num' => $rank['first_five_pages_num'] ?? 0,
'first_ten_pages_num' => $rank['first_ten_pages_num'] ?? 0,
'indexed_pages_num' => $rank['indexed_pages_num'] ?? 0,
'external_links_num' => $external_links['total'] ?? 0,
];
//小语种列表
$langs = Arr::pluck($project['deploy_optimize']['minor_languages'], 'tl');
foreach ($langs as $lang){
$data['langs'][$lang] = Translate::getTls($lang);
}
//项目信息
$data['project'] = [
'company' => $project['company'],
'domain' => $project['deploy_optimize']['domain'],
'domain_info' => '',
'cert_info' => '',
'plan' => str_replace('营销大师-', '全球搜-', $project['deploy_build']['plan'][0]),
'keyword_num' => $project['deploy_build']['keyword_num'],
'compliance_day' => $rank['compliance_day'] ?? 0,
'remain_day' => $project['deploy_build']['service_duration'] - ($rank['compliance_day'] ?? 0),
];
//测速
$data['speed'] = $speed['data'] ?? [];
//seo基础设置
$data['seo'] = [
'H1,H2,H3标签',
'TDK设置(Title, Description, Keywords)',
'Google 收录提交',
'Sitemap.xml Google站长地图',
'Robots.txt文件优化',
'Google站长工具优化设置'
];
//外链引荐域名
$data['external_links_domain_chat'] = [
'labels' => array_map(function ($item) {
return Str::substrReplace($item, '***', 2, 3);
}, Arr::pluck($recomm_domain['data'] ?? [], 'domain')),
'data' => Arr::pluck($recomm_domain['data'] ?? [], 'backlinks_num'),
'list_date' => $recomm_domain['updated_at'] ?? '',
];
//SEO数据周期分析图 外链数
$data['external_links_chat'] = [
'labels' => array_keys($external_links['data'] ?? []),
'data' => array_values($external_links['data'] ?? []),
];
//SEO数据周期分析图 收录数
$data['indexed_pages_chat'] = [
'labels' => array_keys($indexed_pages['data'] ?? []),
'data' => array_values($indexed_pages['data'] ?? []),
];
//收录数加上当日数据
if((Arr::last($data['indexed_pages_chat']['labels'])) != date('Y-m-d')){
$data['indexed_pages_chat']['labels'][] = date('Y-m-d');
$data['indexed_pages_chat']['data'][] = $data['indexed_pages_num'];
}
//关键词排名分析图
$data['rank_chat'] = [
'data' => $rank_week['data'],
'labels' => $rank_week['date'],
];
return $data;
}
/**
* 关键词排名
* @author zbj
* @date 2023/5/12
*/
public function keywords_rank_list(){
$lang = $this->request['lang'];
}
}
... ...
... ... @@ -13,11 +13,11 @@ class DeployBuild extends Base
public function setPlanAttribute($value){
$this->attributes['plan'] = Arr::arrToSet($value);
$this->attributes['plan'] = Arr::arrToSet($value, 'trim');
}
public function getPlanAttribute($value){
return Arr::setToArr($value);
return Arr::setToArr($value, 'trim');
}
public static function clearCache($row){
... ...
... ... @@ -50,6 +50,26 @@ class Project extends Base
];
}
public static function planMap(){
return [
'营销大师-体验版',
'营销大师-标准版',
'营销大师-商务版',
'营销大师-旗舰版',
'数据大师-体验版',
'数据大师-智能版',
'数据大师-智慧版',
'PLUS-尊享版',
'PLUS-尊贵版',
'PLUS-至尊版',
'防疫物质推广方案',
'疫情期间免费版',
'建站大师定制优化方案',
'星链网站(1年版)',
'星链网站(2年版)',
];
}
/**
* 项目部署服务器信息
* @return \Illuminate\Database\Eloquent\Relations\HasOne
... ...
<?php
namespace App\Models\RankData;
use App\Helper\Arr;
use App\Models\Base;
/**
* Class ExternalLinks
* @package App\Models
* @author zbj
* @date 2023/5/10
*/
class ExternalLinks extends Base
{
//设置关联表名
protected $table = 'gl_rank_data_external_links';
public function setDataAttribute($value)
{
$this->attributes['data'] = Arr::a2s($value);
}
public function getDataAttribute($value)
{
return Arr::s2a($value);
}
}
... ...
<?php
namespace App\Models\RankData;
use App\Helper\Arr;
use App\Models\Base;
/**
* Class IndexedPages
* @package App\Models
* @author zbj
* @date 2023/5/10
*/
class IndexedPages extends Base
{
//设置关联表名
protected $table = 'gl_rank_data_indexed_pages';
public function setDataAttribute($value)
{
$this->attributes['data'] = Arr::a2s($value);
}
public function getDataAttribute($value)
{
return Arr::s2a($value);
}
}
... ...
<?php
namespace App\Models\RankData;
use App\Helper\Arr;
use App\Models\Base;
/**
* Class GoogleRank
* @package App\Models
* @author zbj
* @date 2023/5/6
*/
class RankData extends Base
{
//设置关联表名
protected $table = 'gl_rank_data';
public function setDataAttribute($value)
{
$this->attributes['data'] = Arr::a2s($value);
}
public function getDataAttribute($value)
{
return Arr::s2a($value);
}
}
... ...
<?php
namespace App\Models\RankData;
use App\Helper\Arr;
use App\Models\Base;
/**
* Class GoogleRank
* @package App\Models
* @author zbj
* @date 2023/5/6
*/
class RankWeek extends Base
{
//设置关联表名
protected $table = 'gl_rank_data_week';
public function setDataAttribute($value)
{
$this->attributes['data'] = Arr::a2s($value);
}
public function getDataAttribute($value)
{
return Arr::s2a($value);
}
public function setDateAttribute($value)
{
$this->attributes['date'] = Arr::a2s($value);
}
public function getDateAttribute($value)
{
return Arr::s2a($value);
}
}
... ...
<?php
namespace App\Models\RankData;
use App\Helper\Arr;
use App\Models\Base;
/**
* Class RecommDomain
* @package App\Models
* @author zbj
* @date 2023/5/10
*/
class RecommDomain extends Base
{
//设置关联表名
protected $table = 'gl_rank_data_recomm_domain';
public function setDataAttribute($value)
{
$this->attributes['data'] = Arr::a2s($value);
}
public function getDataAttribute($value)
{
return Arr::s2a($value);
}
}
... ...
<?php
namespace App\Models\RankData;
use App\Helper\Arr;
use App\Models\Base;
/**
* Class GoogleSpeed
* @package App\Models
* @author zbj
* @date 2023/5/10
*/
class Speed extends Base
{
//设置关联表名
protected $table = 'gl_rank_data_speed';
public function setDataAttribute($value)
{
$this->attributes['data'] = Arr::a2s($value);
}
public function getDataAttribute($value)
{
return Arr::s2a($value);
}
}
... ...
... ... @@ -242,7 +242,11 @@ Route::middleware(['bloginauth'])->group(function () {
Route::delete('/delete', [\App\Http\Controllers\Bside\NavController::class, 'delete'])->name('bside_nav_delete');
});
//排名数据
Route::prefix('rank_data')->group(function () {
Route::any('/index', [\App\Http\Controllers\Bside\RankDataController::class, 'index'])->name('rank_data');
Route::any('/keywords_rank_list', [\App\Http\Controllers\Bside\RankDataController::class, 'keywords_rank_list'])->name('rank_data_keywords_rank_list');
});
});
... ...