正在显示
6 个修改的文件
包含
88 行增加
和
10 行删除
| @@ -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 | } |
| @@ -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; |
| @@ -71,10 +72,11 @@ class RankDataController extends BaseController | @@ -71,10 +72,11 @@ class RankDataController extends BaseController | ||
| 71 | */ | 72 | */ |
| 72 | public function export(RankDataLogic $logic){ | 73 | public function export(RankDataLogic $logic){ |
| 73 | $data = $logic->keywords_rank_list(true); | 74 | $data = $logic->keywords_rank_list(true); |
| 75 | + | ||
| 74 | foreach ($data as &$item){ | 76 | foreach ($data as &$item){ |
| 75 | $item['domain'] = explode(':', $item['domain'])[1]; | 77 | $item['domain'] = explode(':', $item['domain'])[1]; |
| 76 | $item['lang'] = $this->request['lang'] ?: 'en'; | 78 | $item['lang'] = $this->request['lang'] ?: 'en'; |
| 77 | - $item['g_text'] = $item['g'] == 1 ? '主关键词' : '拓展关键词'; | 79 | + $item['g_text'] = RankData::gMap()[$item['g']]??''; |
| 78 | foreach ($item['position'] as $date => $position){ | 80 | foreach ($item['position'] as $date => $position){ |
| 79 | $item[$date] = $position; | 81 | $item[$date] = $position; |
| 80 | } | 82 | } |
| @@ -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 |
| @@ -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); |
-
请 注册 或 登录 后发表评论