DownloadFile.php 1.5 KB
<?php
/**
 * Created by PhpStorm.
 * User: zhl
 * Date: 2023/9/14
 * Time: 15:42
 */

namespace App\Console\Commands;

use App\Http\Controllers\Api\NoticeController;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;


class DownloadFile extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'handle_html';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '处理网站';

    public function handle()
    {
        while (true) {
            try {
                $this->websiteHandle();
                sleep(30);
            } catch (\Exception $e) {
                sleep(30);
            }
        }
        return true;
    }

    /**
     * 处理HTML
     */
    public function websiteHandle()
    {
        $info = Redis::get('handle_html');
        if (!empty($info)) {
            $this->output('网站更新开始');
            $noticeController = new NoticeController();
            $infoArr = json_decode($info, true);
            $noticeController->websiteHtmlHandle($infoArr["zip_count"], $infoArr["domain"]);
            $this->output('网站更新结束');
        }
        return true;
    }

    /**
     * 输出处理日志
     * @param $message
     * @return bool
     */
    public function output($message)
    {
        echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
        return true;
    }
}