IndexedPages.php 1.6 KB
<?php

namespace App\Console\Commands\RankData;

use App\Helper\QuanqiusouApi;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\IndexedPages as IndexedPagesModel;

/**
 * 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(){
        $error = 0;
        $api = new QuanqiusouApi();
        //有排名api编号的项目
        $list = DeployOptimize::where('api_no', '>', 0)->pluck('api_no', 'project_id')->toArray();

        foreach ($list as $project_id => $api_no) {
            $model = IndexedPagesModel::where('project_id', $project_id)->first();
            if($model && $model->updated_date == getThisWeekStarDate()){
                continue;
            }

            if(!$model){
                $model = new IndexedPagesModel();
            }

            $res = $api->getSiteResPer($api_no);
            if(!$res){
                $error++;
                continue;
            }

            $model->project_id = $project_id;
            $model->data = $res['data'];
            $model->updated_date = date('Y-m-d');
            $model->save();
        }

        return !$error;
    }

}