作者 lyh

Merge branch 'dev' into develop

... ... @@ -45,7 +45,6 @@ class RankData extends BaseCommands
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')) {
... ... @@ -61,7 +60,8 @@ class RankData extends BaseCommands
}
//有小语种的
if($item['minor_languages']){
$lang_list = $api->getLangList();
if(!empty($lang_list[$item['api_no']])){
$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);
... ...
... ... @@ -3,6 +3,8 @@
namespace App\Helper;
use Illuminate\Support\Collection;
/**
* 数组类函数
* Class Arrays
... ... @@ -185,4 +187,29 @@ class Arr extends \Illuminate\Support\Arr
}
return $str ?: [];
}
/**
* 将数组设置成某个键的值
* @param $arr
* @param $key
* @return array
* @author zbj
* @date 2023/5/16
*/
public static function setValueToKey($arr, $key)
{
$data = [];
if (!$arr) {
return $data;
}
foreach ($arr as $v) {
$data[$v[$key]] = $v;
}
if ($arr instanceof Collection) {
$data = new Collection($data);
}
return $data;
}
}
... ...
... ... @@ -202,5 +202,34 @@ class QuanqiusouApi
return $res;
}
/**
* 获取项目小语种信息
* @return array|false|int|mixed|null
* @author zbj
* @date 2023/5/15
*/
public function getLangRankData($api_no)
{
$key = "quanqiusou_get_language_rank_data_{$api_no}_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/api/index/get_language_rank_data';
$param = [
'apino' => $api_no,
];
try {
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取项目小语种数据失败', [], $e);
return false;
}
}
return $res;
}
}
... ...
... ... @@ -40,7 +40,7 @@ class AyrShareController extends BaseController
}
}
}
$lists['list']['share_list'] = $share_list;
$lists['share_list'] = $share_list;
$this->response('列表',Code::SUCCESS,$lists);
}
... ...
... ... @@ -7,6 +7,7 @@ use App\Helper\GoogleSpeedApi;
use App\Helper\QuanqiusouApi;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Logic\Bside\RankDataLogic;
use App\Models\RankData\RankData;
use App\Models\RankData\Speed as GoogleSpeedModel;
use App\Services\BatchExportService;
use Illuminate\Support\Facades\Storage;
... ... @@ -70,14 +71,25 @@ class RankDataController extends BaseController
* @date 2023/5/15
*/
public function export(RankDataLogic $logic){
$lang = $this->request['lang'] ??'';
$data = $logic->keywords_rank_list(true);
$img_position = $video_position= false;
foreach ($data as &$item){
$item['domain'] = explode(':', $item['domain'])[1];
$item['lang'] = $this->request['lang'] ?: 'en';
$item['g_text'] = $item['g'] == 1 ? '主关键词' : '拓展关键词';
$item['g_text'] = RankData::gMap()[$item['g']]??'';
$item['img_position'] = $item['img_position'] ?? '';
$item['video_position'] = $item['video_position'] ?? '';
foreach ($item['position'] as $date => $position){
$item[$date] = $position;
}
if(isset($item['img_position'])){
$img_position = true;
}
if(isset($item['video_position'])){
$video_position = true;
}
}
$map = [
... ... @@ -89,9 +101,11 @@ class RankDataController extends BaseController
foreach ($data[0]['position'] as $date => $position){
$map[$date] = $date;
}
$img_position && $map['img_position'] = '图片';
$video_position && $map['video_position'] = '视频';
//生成文件,发送到客户端
$table = new BatchExportService("关键词数据导出");
$table = new BatchExportService($lang . "关键词数据导出");
$file = $table->head($map)->data($data)->save();
if (!$file) {
throw new \Exception('文件生成失败,请重试');
... ... @@ -102,7 +116,7 @@ class RankDataController extends BaseController
}
/**
* 数据导出
* 历史数据导出
* @author zbj
* @date 2023/5/15
*/
... ...
... ... @@ -29,7 +29,7 @@ class WebSettingReceivingController extends BaseController
* @time :2023/5/8 16:23
*/
public function save(WebSettingReceivingLogic $webSettingReceivingLogic){
$lists = $webSettingReceivingLogic->setting_receiving_save();
$webSettingReceivingLogic->setting_receiving_save();
$this->response('success');
}
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside;
use App\Helper\Arr;
use App\Helper\QuanqiusouApi;
use App\Helper\Translate;
use App\Http\Logic\Aside\Project\DomainInfoLogic;
use App\Http\Logic\Aside\Project\ProjectLogic;
... ... @@ -39,7 +40,7 @@ class RankDataLogic extends BaseLogic
$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();
$api_no = $project['deploy_optimize']['api_no'] ?? '';
//排名数据
$data = [
'first_num' => $rank['first_num'] ?? 0,
... ... @@ -51,12 +52,6 @@ class RankDataLogic extends BaseLogic
'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'],
... ... @@ -69,6 +64,23 @@ class RankDataLogic extends BaseLogic
'remain_day' => $project['deploy_build']['service_duration'] - ($rank['compliance_day'] ?? 0),
];
//小语种列表
$quanqiusou_api = new QuanqiusouApi();
$lang_data = $quanqiusou_api->getLangRankData($api_no);
$lang_data = Arr::setValueToKey($lang_data, 'language');
foreach($project['deploy_optimize']['minor_languages'] as $lang){
$remain_day = $lang_data[$lang['tl']]['dabiao_day'] ?? 0;
$data['langs'][$lang['tl'] ?? ''] = [
'lang_text' => Translate::getTls($lang['tl'] ?? ''),
'keyword_num' => $lang['keywords'] ?? 0,
'reach_day' => $lang_data[$lang['tl']]['dabiao_day'] ?? 0,
'remain_day' => ($lang['type']??0) == 1 ? $data['project']['remain_day'] : $lang['service_day'] - $remain_day,
'type' => $lang['type'] ?? 0, //1 项目关键词 项目天数 2 保证首页关键词 项目达标天数
];
}
//测速
$data['speed'] = $speed['data'] ?? [];
... ... @@ -172,8 +184,17 @@ class RankDataLogic extends BaseLogic
'keyword' => $key,
'domain' => $domain_text,
'g' => $last['g'], //1核心关键词
'position' => $data
'position' => $data,
];
//图片排名
if(isset($last['p_img'])){
$v['img_position'] = $last['p_img'];
}
//视频排名
if(isset($last['p_vid'])){
$v['video_position'] = $last['p_vid'];
}
if ($last['position'] == 0) {
$list0[] = $v;
} elseif ($last['position'] <= 30) {
... ...
... ... @@ -17,6 +17,14 @@ class RankData extends Base
//设置关联表名
protected $table = 'gl_rank_data';
public static function gMap(){
return [
1 => '主关键词',
2 => '拓展关键词',
3 => '小语种关键词',
];
}
public function setDataAttribute($value)
{
$this->attributes['data'] = Arr::a2s($value);
... ...