IndexedPages.php 2.0 KB
<?php

namespace App\Console\Commands\RankData;

use App\Helper\QuanqiusouApi;
use App\Http\Logic\Bside\RankData\RankDataLogic;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\RankData;
use Illuminate\Support\Facades\Log;

/**
 * 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(){
        $api = new QuanqiusouApi();
        $site_res = $api->getSiteRes();
        if (!$site_res) {
            Log::channel('rank_data')->error('谷歌收录数据获取失败');
        }else{
            foreach ($site_res as $api_no => $num){
                $project_ids = DeployOptimize::where('api_no', $api_no)->pluck('project_id');
                foreach ($project_ids as $project_id){
                    $rank_data = RankData::where('project_id', $project_id)->where('lang', '')->first();
                    if($rank_data){
                        $rank_data->indexed_pages_num = $num;
                        $rank_data->save();
                    }
                }
            }
        }

        //有排名api编号的项目
        $list = DeployOptimize::where('api_no', '>', 0)->pluck('api_no', 'project_id')->toArray();
        Log::channel('rank_data')->info('开始-页面收录数据-'.count($list));

        foreach ($list as $project_id => $api_no) {
            Log::channel('rank_data')->info('开始-页面收录数据-' . $project_id . '->' .$api_no);
            $rankDataLogic = new RankDataLogic();
            $rankDataLogic->syncIndexedPages($api_no, true);
        }

        return true;
    }
}