GeneratePage.php 2.3 KB
<?php
/**
 * @remark :
 * @name   :GeneratePage.php
 * @author :lyh
 * @method :post
 * @time   :2025/2/10 17:00
 */

namespace App\Console\Commands\Project;

use App\Helper\Translate;
use App\Models\Com\NoticeLog;
use App\Models\Product\Keyword;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '批量导入关键字生成路由';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @return bool
     */
    public function handle()
    {
        $noticeModel = new NoticeLog();
        while (true){
            $noticeInfo = $noticeModel->read(['status'=>0]);
            if (empty($noticeInfo)) {
                sleep(10);
                continue;
            }
            try {
                $this->output(' taskID: ' . $noticeInfo['id'] . ' start');
                $c_url = $noticeInfo['data']['c_url'];
                $c_params = $noticeInfo['data']['c_params'];
                try {
                    $re = http_post($c_url, $c_params, [], true);
                    if (isset($re['status']) && $re['status'] == 200) {
                        $this->output($c_url . ' | 请求成功');
                    } else {
                        $this->output($c_url . ' | ' . ($re['message'] ?? '未返回失败原因'));
                    }
                } catch (\Exception $e) {
                    $this->output($c_url . ' | 请求异常:' . $e->getMessage());
                }
                $this->output(' taskID: ' . $noticeInfo['id'] . ' end');
            } catch (\Exception $e) {
                $this->output(' taskID: ' . $noticeInfo['id'] . ', error: ' . $e->getMessage());
            }
            sleep(2);
        }
        return true;
    }


    /**
     * 输出message
     * @param $message
     */
    public function output($message)
    {
        echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
    }
}