WhiteHatLinkData.php 2.2 KB
<?php
/**
 * @remark :
 * @name   :AuthorityScore.php
 * @author :lyh
 * @method :post
 * @time   :2025/7/1 16:43
 */

namespace App\Console\Commands\WhiteHatProject;

use App\Models\AuthorityScore\AuthorityScore;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use Illuminate\Console\Command;

class WhiteHatLinkData extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'white_hat_link_data';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '白帽外链数据详情,每月统计一次';

    /**
     * @remark :执行方法
     * @name   :handle
     * @author :lyh
     * @method :post
     * @time   :2025/7/1 16:46
     */
    public function handle(){
        $projectModel = new Project();
        $projectIdArr = $projectModel->selectField(['project_type'=>1,'delete_status' => 0,'extend_type'=>0,'type'=>2],'id');
        $domainModel = new DomainInfo();
        $url = 'https://www.cmer.site/api/domain/organic?domain=';
        foreach ($projectIdArr as $item){
            $domainInfo = $domainModel->read(['project_id'=>$item],['domain']);
            if($domainInfo === false){
                continue;
            }
            $url = $url.$domainInfo['domain'];
            $data = http_get($url);
            if(!empty($data) && !empty($data['data'])){
                $data = $data['data'];
                $this->saveHandleData($data,$item);
            }
        }
        return true;
    }

    /**
     * @remark :保存数据
     * @name   :handleData
     * @author :lyh
     * @method :post
     * @time   :2025/7/1 17:23
     */
    public function saveHandleData($data,$project_id){
        $authorityScoreModel = new AuthorityScore();
        return $authorityScoreModel->addReturnId([
            'project_id'=>$project_id,
            'ascore'=>(int)$data['ascore'],
            'total'=>(int)$data['total'],
            'domains_num'=>(int)$data['domains_num'],
            'rank'=>(int)$data['rank'],
            'organic_keywords'=>(int)$data['organic_keywords'],
            'organic_traffic'=>(int)$data['organic_traffic'],
        ]);
    }
}