正在显示
3 个修改的文件
包含
63 行增加
和
2 行删除
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | namespace App\Http\Controllers\Bside; | 3 | namespace App\Http\Controllers\Bside; |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | +use App\Helper\Arr; | ||
| 6 | use App\Helper\GoogleSpeedApi; | 7 | use App\Helper\GoogleSpeedApi; |
| 7 | use App\Helper\QuanqiusouApi; | 8 | use App\Helper\QuanqiusouApi; |
| 8 | use App\Http\Logic\Aside\Project\ProjectLogic; | 9 | use App\Http\Logic\Aside\Project\ProjectLogic; |
| @@ -10,6 +11,9 @@ use App\Http\Logic\Bside\RankDataLogic; | @@ -10,6 +11,9 @@ use App\Http\Logic\Bside\RankDataLogic; | ||
| 10 | use App\Models\RankData\RankData; | 11 | use App\Models\RankData\RankData; |
| 11 | use App\Models\RankData\Speed as GoogleSpeedModel; | 12 | use App\Models\RankData\Speed as GoogleSpeedModel; |
| 12 | use App\Services\BatchExportService; | 13 | use App\Services\BatchExportService; |
| 14 | +use App\Utils\HttpUtils; | ||
| 15 | +use GuzzleHttp\Client; | ||
| 16 | +use GuzzleHttp\Promise\Utils; | ||
| 13 | use Illuminate\Support\Facades\Storage; | 17 | use Illuminate\Support\Facades\Storage; |
| 14 | 18 | ||
| 15 | /** | 19 | /** |
| @@ -162,4 +166,56 @@ class RankDataController extends BaseController | @@ -162,4 +166,56 @@ class RankDataController extends BaseController | ||
| 162 | // return Storage::disk('runtime')->download($file); //直接下载 | 166 | // return Storage::disk('runtime')->download($file); //直接下载 |
| 163 | return $this->success(['url' => $fileurl]); | 167 | return $this->success(['url' => $fileurl]); |
| 164 | } | 168 | } |
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * 实时获取关键词排名 | ||
| 172 | + * @author zbj | ||
| 173 | + * @date 2023/5/16 | ||
| 174 | + */ | ||
| 175 | + public function get_google_rank(){ | ||
| 176 | + $url_arr = parse_url($this->request['url']); | ||
| 177 | + $param = [ | ||
| 178 | + 'keyword' => trim($this->request['keyword']), | ||
| 179 | + 'url' => $url_arr['host'] ?? $url_arr['path'], | ||
| 180 | + 'extend_urls' => $this->request['extend_urls'], | ||
| 181 | + 'lang' => $this->request['lang'], | ||
| 182 | + 'use_groups' => 2 | ||
| 183 | + ]; | ||
| 184 | + | ||
| 185 | + | ||
| 186 | + if ($this->request['w']) { | ||
| 187 | + $data = [ | ||
| 188 | + 'position' => 0, | ||
| 189 | + 'image_position' => 0, | ||
| 190 | + 'video_position' => 0, | ||
| 191 | + ]; | ||
| 192 | + $client = new Client([ | ||
| 193 | + 'base_uri' => 'http://45.136.131.71:8000', | ||
| 194 | + 'timeout' => '20' | ||
| 195 | + ]); | ||
| 196 | + | ||
| 197 | + $promises['position'] = $client->getAsync('/luminati_rank?'.Arr::query($param)); | ||
| 198 | + $promises['image_position'] = $client->getAsync('/google_image?'.Arr::query($param)); | ||
| 199 | + $promises['video_position'] = $client->getAsync('/google_video?'.Arr::query($param)); | ||
| 200 | + | ||
| 201 | + // 等待所有请求响应完成 | ||
| 202 | + $results = Utils:: settle($promises)->wait(); | ||
| 203 | + foreach ($results as $key => $result) { | ||
| 204 | + if ($result['state'] == 'fulfilled') { | ||
| 205 | + $res = Arr::s2a($result['value']->getBody()->getContents()); | ||
| 206 | + $data[$key] = $res['position'] ?? 0; | ||
| 207 | + } | ||
| 208 | + } | ||
| 209 | + }else{ | ||
| 210 | + $data = [ | ||
| 211 | + 'position' => 0, | ||
| 212 | + ]; | ||
| 213 | + $res = HttpUtils::get('http://45.136.131.71:8000/luminati_rank', $param); | ||
| 214 | + if ($res) { | ||
| 215 | + $res = Arr::s2a($res); | ||
| 216 | + $data['position'] = $res['position']; | ||
| 217 | + } | ||
| 218 | + } | ||
| 219 | + return $this->success($data); | ||
| 220 | + } | ||
| 165 | } | 221 | } |
| @@ -68,13 +68,14 @@ class RankDataLogic extends BaseLogic | @@ -68,13 +68,14 @@ class RankDataLogic extends BaseLogic | ||
| 68 | $quanqiusou_api = new QuanqiusouApi(); | 68 | $quanqiusou_api = new QuanqiusouApi(); |
| 69 | $lang_data = $quanqiusou_api->getLangRankData($api_no); | 69 | $lang_data = $quanqiusou_api->getLangRankData($api_no); |
| 70 | $lang_data = Arr::setValueToKey($lang_data, 'language'); | 70 | $lang_data = Arr::setValueToKey($lang_data, 'language'); |
| 71 | - | 71 | + $data['langs'] = []; |
| 72 | foreach($project['deploy_optimize']['minor_languages'] as $lang){ | 72 | foreach($project['deploy_optimize']['minor_languages'] as $lang){ |
| 73 | $remain_day = $lang_data[$lang['tl']]['dabiao_day'] ?? 0; | 73 | $remain_day = $lang_data[$lang['tl']]['dabiao_day'] ?? 0; |
| 74 | $data['langs'][$lang['tl'] ?? ''] = [ | 74 | $data['langs'][$lang['tl'] ?? ''] = [ |
| 75 | 'lang_text' => Translate::getTls($lang['tl'] ?? ''), | 75 | 'lang_text' => Translate::getTls($lang['tl'] ?? ''), |
| 76 | 'keyword_num' => $lang['keywords'] ?? 0, | 76 | 'keyword_num' => $lang['keywords'] ?? 0, |
| 77 | 'reach_day' => $lang_data[$lang['tl']]['dabiao_day'] ?? 0, | 77 | 'reach_day' => $lang_data[$lang['tl']]['dabiao_day'] ?? 0, |
| 78 | + 'home_cnt' => $lang_data[$lang['tl']]['home_cnt'] ?? 0, | ||
| 78 | 'remain_day' => ($lang['type']??0) == 1 ? $data['project']['remain_day'] : $lang['service_day'] - $remain_day, | 79 | 'remain_day' => ($lang['type']??0) == 1 ? $data['project']['remain_day'] : $lang['service_day'] - $remain_day, |
| 79 | 'type' => $lang['type'] ?? 0, //1 项目关键词 项目天数 2 保证首页关键词 项目达标天数 | 80 | 'type' => $lang['type'] ?? 0, //1 项目关键词 项目天数 2 保证首页关键词 项目达标天数 |
| 80 | ]; | 81 | ]; |
| @@ -180,9 +181,12 @@ class RankDataLogic extends BaseLogic | @@ -180,9 +181,12 @@ class RankDataLogic extends BaseLogic | ||
| 180 | } | 181 | } |
| 181 | } | 182 | } |
| 182 | } | 183 | } |
| 184 | + $domain_arr = explode(':', $domain_text); | ||
| 183 | $v = [ | 185 | $v = [ |
| 184 | 'keyword' => $key, | 186 | 'keyword' => $key, |
| 185 | - 'domain' => $domain_text, | 187 | + 'domain_type' => $domain_arr[0], |
| 188 | + 'domain' => $domain_arr[1], | ||
| 189 | + 'domain_text' => $domain_text, | ||
| 186 | 'g' => $last['g'], //1核心关键词 | 190 | 'g' => $last['g'], //1核心关键词 |
| 187 | 'position' => $data, | 191 | 'position' => $data, |
| 188 | ]; | 192 | ]; |
| @@ -259,6 +259,7 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -259,6 +259,7 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 259 | Route::any('/speed', [\App\Http\Controllers\Bside\RankDataController::class, 'speed'])->name('rank_data_speed'); | 259 | Route::any('/speed', [\App\Http\Controllers\Bside\RankDataController::class, 'speed'])->name('rank_data_speed'); |
| 260 | Route::any('/export', [\App\Http\Controllers\Bside\RankDataController::class, 'export'])->name('rank_data_export'); | 260 | Route::any('/export', [\App\Http\Controllers\Bside\RankDataController::class, 'export'])->name('rank_data_export'); |
| 261 | Route::any('/export_history', [\App\Http\Controllers\Bside\RankDataController::class, 'export_history'])->name('rank_data_export_history'); | 261 | Route::any('/export_history', [\App\Http\Controllers\Bside\RankDataController::class, 'export_history'])->name('rank_data_export_history'); |
| 262 | + Route::any('/get_google_rank', [\App\Http\Controllers\Bside\RankDataController::class, 'get_google_rank'])->name('rank_data_get_google_rank'); | ||
| 262 | }); | 263 | }); |
| 263 | 264 | ||
| 264 | 265 |
-
请 注册 或 登录 后发表评论