<?php

namespace App\Console\Commands;

use App\Http\Logic\Aside\Project\DomainInfoLogic;
use App\Models\Com\UpdateNotify;
use App\Models\Devops\DevopsTask as DevopsTaskModel;
use App\Models\Devops\DevopsTaskLog;
use App\Models\Domain\DomainInfo;
use App\Models\File\File;
use App\Models\File\Image;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BCustomTemplate;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\DB;

/**
 * 测试
 * Class Traffic
 * @package App\Console\Commands
 * @author zbj
 * @date 2023/5/18
 */
class Test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test';

    /**
     * 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()
    {
        $projects = Project::all();
        foreach ($projects as $project){
            echo "project " . $project->id;

            if(!ProjectServer::useProject($project->id)){
                echo '-->' . '未配置数据库' . PHP_EOL;
                continue;
            }

            try {
                $page = BCustomTemplate::where('url', '404')->first();
                if(!$page){
                    $page = new BCustomTemplate();
                }
                $page->project_id = $project->id;
                $page->name = '404';
                $page->status = 1;
                $page->url = '404';
                $page->html = '<main>
        <section data-section="section" data-screen="screen-large" class="section-404-wrap-block section-block-error404"
            id="sectionIdyxqu938">
            <div class="layout" data-unable="demo01-error404">
                <img src="https://ecdn6.globalso.com/upload/m/image_other/2023-10/6528a87e594db30162.png" />
            </div>
            <p style="text-align: center">SORRY. THE PAGE HAS EITHER MOVED OR CANNOT BE FOUND.</p>
            <style>
                .section-block-error404 .layout {
                    height: 700px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                }
                .section-block-error404 img {
                    width: 400px;
                }
                @media only screen and (max-width:500) {
                    .section-block-error404 img {
                        max-width: 100%;
                    }
                }
            </style>
            <script>
            </script>
        </section>
    </main>';
                $page->html_style = '<style id="globalsojs-styles"></style>';
                $page->description = 'Sorry. The page has either moved or cannot be found.';
                $page->title = '404-Page not found';
                $page->save();

                $domain = (new DomainInfo())->getDomain($project['deploy_optimize']['domain']);
                $url = $domain.'api/delHtml/?project_id='.$project->id.'&route=404';
                curlGet($url);
            }catch (QueryException | \Exception $e){
                echo '-->' . $e->getMessage() . PHP_EOL;
                continue;
            }
            echo '-->成功:' . PHP_EOL;
        }
    }

}