InitTemplateData.php 2.62 KB
<?php

namespace App\Console\Commands;

use App\Models\OnePoem;
use App\Models\PackPoem;
use App\Models\VideoTemp;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;

class InitTemplateData extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'init:temp';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '初始化模板数据';

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        // 一言表
        OnePoem::query()->truncate();
        $one_poem = new OnePoem();

        $one_poem->id = 1;
        $one_poem->title = '诉衷情2';
        $one_poem->author = '欧阳修';
        $one_poem->content = '清晨帘幕卷轻霜。';
        $one_poem->annotate = '诉衷情 --清晨帘幕卷轻霜。';
        $one_poem->spelling = 'qing chen lian mu  juan qing shuang';
        $one_poem->en = 'morning ...';
        $one_poem->state = 0;
        $one_poem->created_at = Carbon::now();
        $one_poem->updated_at = Carbon::now();

        $one_poem->save();


        // 众妙表
        PackPoem::query()->truncate();
        $pack_poem = new PackPoem();

        $pack_poem->id = 1;
        $pack_poem->title = '辛丑年 庚子月 已酉时 巳时';
        $pack_poem->subtitle = '2022年01月12日13点22分';
        $pack_poem->left_text = '欧阳修';
        $pack_poem->right_text = '冬';
        $pack_poem->poem_id = 1;
        $pack_poem->state = 0;
        $pack_poem->created_at = Carbon::now();
        $pack_poem->updated_at = Carbon::now();

        $pack_poem->save();


        // 模板表
        VideoTemp::query()->truncate();
        $video_temp = new VideoTemp();

        $video_temp->title = 'test';
        $video_temp->bgm_url = 'files/ce1f0f0a995f93ff2e6d68451ab0873e.png';
        $video_temp->bg_music = 0;
        $video_temp->state = 0;

        $video_temp->save();


        // 菜单初始化
        \Dcat\Admin\Models\Menu::query()->truncate();
        $admin_menu = json_decode(Storage::disk('public')->get('PoemData/admin_menu.json'), true);
        $data = $admin_menu['RECORDS'];
        foreach ($data as $item){
            $item['created_at'] = Carbon::now();
            $item['updated_at'] = Carbon::now();

            \Dcat\Admin\Models\Menu::query()->create($item);
        }

        return 0;
    }
}