<?php
/**
 * @remark :
 * @name   :Demo.php
 * @author :lyh
 * @method :post
 * @time   :2025/2/20 9:19
 */

namespace App\Console\Commands\Test;

use Illuminate\Console\Command;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '';

    public function handle(){
        return $this->getExtendProjects();
    }

    public function getExtendProjects($api_no = null)
    {
        $key = 'extend_projects_list';
        $data = Cache::get($key);
        if (!$data) {
            $api_url = 'http://api.quanqiusou.cn/google-rank/api/extend_projects.php';
            try {
                $data = HttpUtils::get($api_url, []);
                if ($data) {
                    $data = Arr::s2a($data);
                    Cache::put($key, $data, 4 * 3600);
                }
            } catch (\Exception | GuzzleException $e) {
                errorLog('复制站点项目获取失败', [], $e);
                return false;
            }
        }
        if ($api_no !== null) {
            $data = collect($data)->where('apino', $api_no)->first();
            return $data ?: [];
        }
        echo date('Y-m-d H:i:s') . 'end'.json_encode($data) . PHP_EOL;
        return $data;
    }

}