作者 lyh

Merge branch 'dev' into develop

@@ -45,7 +45,6 @@ class RankData extends BaseCommands @@ -45,7 +45,6 @@ class RankData extends BaseCommands
45 if(!$site_res){ 45 if(!$site_res){
46 return false; 46 return false;
47 } 47 }
48 -  
49 foreach ($list as $item){ 48 foreach ($list as $item){
50 $model = GoogleRankModel::where('project_id', $item['project_id'])->where('lang', '')->first(); 49 $model = GoogleRankModel::where('project_id', $item['project_id'])->where('lang', '')->first();
51 if (!$model || $model->updated_date != date('Y-m-d')) { 50 if (!$model || $model->updated_date != date('Y-m-d')) {
@@ -61,7 +60,8 @@ class RankData extends BaseCommands @@ -61,7 +60,8 @@ class RankData extends BaseCommands
61 } 60 }
62 61
63 //有小语种的 62 //有小语种的
64 - if($item['minor_languages']){ 63 + $lang_list = $api->getLangList();
  64 + if(!empty($lang_list[$item['api_no']])){
65 $model = GoogleRankModel::where('project_id', $item['project_id'])->where('lang', '<>', '')->first(); 65 $model = GoogleRankModel::where('project_id', $item['project_id'])->where('lang', '<>', '')->first();
66 if (!$model || $model->updated_date != date('Y-m-d')) { 66 if (!$model || $model->updated_date != date('Y-m-d')) {
67 $res = $api->getGoogleRank($item['api_no'], 1); 67 $res = $api->getGoogleRank($item['api_no'], 1);
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 namespace App\Helper; 3 namespace App\Helper;
4 4
5 5
  6 +use Illuminate\Support\Collection;
  7 +
6 /** 8 /**
7 * 数组类函数 9 * 数组类函数
8 * Class Arrays 10 * Class Arrays
@@ -185,4 +187,29 @@ class Arr extends \Illuminate\Support\Arr @@ -185,4 +187,29 @@ class Arr extends \Illuminate\Support\Arr
185 } 187 }
186 return $str ?: []; 188 return $str ?: [];
187 } 189 }
  190 +
  191 +
  192 + /**
  193 + * 将数组设置成某个键的值
  194 + * @param $arr
  195 + * @param $key
  196 + * @return array
  197 + * @author zbj
  198 + * @date 2023/5/16
  199 + */
  200 + public static function setValueToKey($arr, $key)
  201 + {
  202 + $data = [];
  203 + if (!$arr) {
  204 + return $data;
  205 + }
  206 + foreach ($arr as $v) {
  207 + $data[$v[$key]] = $v;
  208 + }
  209 +
  210 + if ($arr instanceof Collection) {
  211 + $data = new Collection($data);
  212 + }
  213 + return $data;
  214 + }
188 } 215 }
@@ -202,5 +202,34 @@ class QuanqiusouApi @@ -202,5 +202,34 @@ class QuanqiusouApi
202 return $res; 202 return $res;
203 } 203 }
204 204
  205 + /**
  206 + * 获取项目小语种信息
  207 + * @return array|false|int|mixed|null
  208 + * @author zbj
  209 + * @date 2023/5/15
  210 + */
  211 + public function getLangRankData($api_no)
  212 + {
  213 + $key = "quanqiusou_get_language_rank_data_{$api_no}_" . date('Y-m-d');
  214 + $res = Cache::get($key);
  215 + if (!$res) {
  216 + $api_url = $this->url . '/api/index/get_language_rank_data';
  217 + $param = [
  218 + 'apino' => $api_no,
  219 + ];
  220 + try {
  221 + $res = HttpUtils::get($api_url, $param);
  222 + if($res){
  223 + $res = Arr::s2a($res);
  224 + Cache::put($key, $res, 24 * 3600);
  225 + }
  226 + } catch (\Exception | GuzzleException $e) {
  227 + errorLog('获取项目小语种数据失败', [], $e);
  228 + return false;
  229 + }
  230 + }
  231 + return $res;
  232 + }
  233 +
205 234
206 } 235 }
@@ -40,7 +40,7 @@ class AyrShareController extends BaseController @@ -40,7 +40,7 @@ class AyrShareController extends BaseController
40 } 40 }
41 } 41 }
42 } 42 }
43 - $lists['list']['share_list'] = $share_list; 43 + $lists['share_list'] = $share_list;
44 $this->response('列表',Code::SUCCESS,$lists); 44 $this->response('列表',Code::SUCCESS,$lists);
45 } 45 }
46 46
@@ -7,6 +7,7 @@ use App\Helper\GoogleSpeedApi; @@ -7,6 +7,7 @@ use App\Helper\GoogleSpeedApi;
7 use App\Helper\QuanqiusouApi; 7 use App\Helper\QuanqiusouApi;
8 use App\Http\Logic\Aside\Project\ProjectLogic; 8 use App\Http\Logic\Aside\Project\ProjectLogic;
9 use App\Http\Logic\Bside\RankDataLogic; 9 use App\Http\Logic\Bside\RankDataLogic;
  10 +use App\Models\RankData\RankData;
10 use App\Models\RankData\Speed as GoogleSpeedModel; 11 use App\Models\RankData\Speed as GoogleSpeedModel;
11 use App\Services\BatchExportService; 12 use App\Services\BatchExportService;
12 use Illuminate\Support\Facades\Storage; 13 use Illuminate\Support\Facades\Storage;
@@ -70,14 +71,25 @@ class RankDataController extends BaseController @@ -70,14 +71,25 @@ class RankDataController extends BaseController
70 * @date 2023/5/15 71 * @date 2023/5/15
71 */ 72 */
72 public function export(RankDataLogic $logic){ 73 public function export(RankDataLogic $logic){
  74 + $lang = $this->request['lang'] ??'';
73 $data = $logic->keywords_rank_list(true); 75 $data = $logic->keywords_rank_list(true);
  76 +
  77 + $img_position = $video_position= false;
74 foreach ($data as &$item){ 78 foreach ($data as &$item){
75 $item['domain'] = explode(':', $item['domain'])[1]; 79 $item['domain'] = explode(':', $item['domain'])[1];
76 $item['lang'] = $this->request['lang'] ?: 'en'; 80 $item['lang'] = $this->request['lang'] ?: 'en';
77 - $item['g_text'] = $item['g'] == 1 ? '主关键词' : '拓展关键词'; 81 + $item['g_text'] = RankData::gMap()[$item['g']]??'';
  82 + $item['img_position'] = $item['img_position'] ?? '';
  83 + $item['video_position'] = $item['video_position'] ?? '';
78 foreach ($item['position'] as $date => $position){ 84 foreach ($item['position'] as $date => $position){
79 $item[$date] = $position; 85 $item[$date] = $position;
80 } 86 }
  87 + if(isset($item['img_position'])){
  88 + $img_position = true;
  89 + }
  90 + if(isset($item['video_position'])){
  91 + $video_position = true;
  92 + }
81 } 93 }
82 94
83 $map = [ 95 $map = [
@@ -89,9 +101,11 @@ class RankDataController extends BaseController @@ -89,9 +101,11 @@ class RankDataController extends BaseController
89 foreach ($data[0]['position'] as $date => $position){ 101 foreach ($data[0]['position'] as $date => $position){
90 $map[$date] = $date; 102 $map[$date] = $date;
91 } 103 }
  104 + $img_position && $map['img_position'] = '图片';
  105 + $video_position && $map['video_position'] = '视频';
92 106
93 //生成文件,发送到客户端 107 //生成文件,发送到客户端
94 - $table = new BatchExportService("关键词数据导出"); 108 + $table = new BatchExportService($lang . "关键词数据导出");
95 $file = $table->head($map)->data($data)->save(); 109 $file = $table->head($map)->data($data)->save();
96 if (!$file) { 110 if (!$file) {
97 throw new \Exception('文件生成失败,请重试'); 111 throw new \Exception('文件生成失败,请重试');
@@ -102,7 +116,7 @@ class RankDataController extends BaseController @@ -102,7 +116,7 @@ class RankDataController extends BaseController
102 } 116 }
103 117
104 /** 118 /**
105 - * 数据导出 119 + * 历史数据导出
106 * @author zbj 120 * @author zbj
107 * @date 2023/5/15 121 * @date 2023/5/15
108 */ 122 */
@@ -29,7 +29,7 @@ class WebSettingReceivingController extends BaseController @@ -29,7 +29,7 @@ class WebSettingReceivingController extends BaseController
29 * @time :2023/5/8 16:23 29 * @time :2023/5/8 16:23
30 */ 30 */
31 public function save(WebSettingReceivingLogic $webSettingReceivingLogic){ 31 public function save(WebSettingReceivingLogic $webSettingReceivingLogic){
32 - $lists = $webSettingReceivingLogic->setting_receiving_save(); 32 + $webSettingReceivingLogic->setting_receiving_save();
33 $this->response('success'); 33 $this->response('success');
34 } 34 }
35 } 35 }
@@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside; @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside;
4 4
5 5
6 use App\Helper\Arr; 6 use App\Helper\Arr;
  7 +use App\Helper\QuanqiusouApi;
7 use App\Helper\Translate; 8 use App\Helper\Translate;
8 use App\Http\Logic\Aside\Project\DomainInfoLogic; 9 use App\Http\Logic\Aside\Project\DomainInfoLogic;
9 use App\Http\Logic\Aside\Project\ProjectLogic; 10 use App\Http\Logic\Aside\Project\ProjectLogic;
@@ -39,7 +40,7 @@ class RankDataLogic extends BaseLogic @@ -39,7 +40,7 @@ class RankDataLogic extends BaseLogic
39 $external_links = ExternalLinks::where('project_id', $project_id)->first(); 40 $external_links = ExternalLinks::where('project_id', $project_id)->first();
40 $indexed_pages = IndexedPages::where('project_id', $project_id)->first(); 41 $indexed_pages = IndexedPages::where('project_id', $project_id)->first();
41 $speed = Speed::where('project_id', $project_id)->first(); 42 $speed = Speed::where('project_id', $project_id)->first();
42 - 43 + $api_no = $project['deploy_optimize']['api_no'] ?? '';
43 //排名数据 44 //排名数据
44 $data = [ 45 $data = [
45 'first_num' => $rank['first_num'] ?? 0, 46 'first_num' => $rank['first_num'] ?? 0,
@@ -51,12 +52,6 @@ class RankDataLogic extends BaseLogic @@ -51,12 +52,6 @@ class RankDataLogic extends BaseLogic
51 'external_links_num' => $external_links['total'] ?? 0, 52 'external_links_num' => $external_links['total'] ?? 0,
52 ]; 53 ];
53 54
54 - //小语种列表  
55 - $langs = Arr::pluck($project['deploy_optimize']['minor_languages'], 'tl');  
56 - foreach ($langs as $lang) {  
57 - $data['langs'][$lang] = Translate::getTls($lang);  
58 - }  
59 -  
60 //项目信息 55 //项目信息
61 $data['project'] = [ 56 $data['project'] = [
62 'company' => $project['company'], 57 'company' => $project['company'],
@@ -69,6 +64,23 @@ class RankDataLogic extends BaseLogic @@ -69,6 +64,23 @@ class RankDataLogic extends BaseLogic
69 'remain_day' => $project['deploy_build']['service_duration'] - ($rank['compliance_day'] ?? 0), 64 'remain_day' => $project['deploy_build']['service_duration'] - ($rank['compliance_day'] ?? 0),
70 ]; 65 ];
71 66
  67 + //小语种列表
  68 + $quanqiusou_api = new QuanqiusouApi();
  69 + $lang_data = $quanqiusou_api->getLangRankData($api_no);
  70 + $lang_data = Arr::setValueToKey($lang_data, 'language');
  71 +
  72 + foreach($project['deploy_optimize']['minor_languages'] as $lang){
  73 + $remain_day = $lang_data[$lang['tl']]['dabiao_day'] ?? 0;
  74 + $data['langs'][$lang['tl'] ?? ''] = [
  75 + 'lang_text' => Translate::getTls($lang['tl'] ?? ''),
  76 + 'keyword_num' => $lang['keywords'] ?? 0,
  77 + 'reach_day' => $lang_data[$lang['tl']]['dabiao_day'] ?? 0,
  78 + 'remain_day' => ($lang['type']??0) == 1 ? $data['project']['remain_day'] : $lang['service_day'] - $remain_day,
  79 + 'type' => $lang['type'] ?? 0, //1 项目关键词 项目天数 2 保证首页关键词 项目达标天数
  80 + ];
  81 + }
  82 +
  83 +
72 //测速 84 //测速
73 $data['speed'] = $speed['data'] ?? []; 85 $data['speed'] = $speed['data'] ?? [];
74 86
@@ -172,8 +184,17 @@ class RankDataLogic extends BaseLogic @@ -172,8 +184,17 @@ class RankDataLogic extends BaseLogic
172 'keyword' => $key, 184 'keyword' => $key,
173 'domain' => $domain_text, 185 'domain' => $domain_text,
174 'g' => $last['g'], //1核心关键词 186 'g' => $last['g'], //1核心关键词
175 - 'position' => $data 187 + 'position' => $data,
176 ]; 188 ];
  189 + //图片排名
  190 + if(isset($last['p_img'])){
  191 + $v['img_position'] = $last['p_img'];
  192 + }
  193 + //视频排名
  194 + if(isset($last['p_vid'])){
  195 + $v['video_position'] = $last['p_vid'];
  196 + }
  197 +
177 if ($last['position'] == 0) { 198 if ($last['position'] == 0) {
178 $list0[] = $v; 199 $list0[] = $v;
179 } elseif ($last['position'] <= 30) { 200 } elseif ($last['position'] <= 30) {
@@ -17,6 +17,14 @@ class RankData extends Base @@ -17,6 +17,14 @@ class RankData extends Base
17 //设置关联表名 17 //设置关联表名
18 protected $table = 'gl_rank_data'; 18 protected $table = 'gl_rank_data';
19 19
  20 + public static function gMap(){
  21 + return [
  22 + 1 => '主关键词',
  23 + 2 => '拓展关键词',
  24 + 3 => '小语种关键词',
  25 + ];
  26 + }
  27 +
20 public function setDataAttribute($value) 28 public function setDataAttribute($value)
21 { 29 {
22 $this->attributes['data'] = Arr::a2s($value); 30 $this->attributes['data'] = Arr::a2s($value);