<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('spec', function (Blueprint $table) {
            $table->id();
            $table->string("name")->default("");
            $table->string("extra", 2000)->default("");
            $table->unsignedInteger("index_weight")->default(0);
            $table->unsignedInteger("category_weight")->default(0);
            $table->unsignedInteger("search_weight")->default(0);
            $table->unsignedTinyInteger("is_custom")->default(0)->comment("是否自定义");
            $table->timestamps();
            $table->softDeletes();
        });
        Schema::create("spec_attr", function (Blueprint $t) {
            $t->id();
            $t->unsignedInteger("spec_id");
            $t->string("name");
            $t->timestamps();
            $t->softDeletes();
        });

        Schema::create('category', function (Blueprint $table) {
            $table->id();
            $table->string("name")->default("");
            $table->string("thumb")->default("");
            $table->unsignedTinyInteger("level")->default(0)->comment("层级");
            $table->unsignedInteger("parent_id")->default(0)->comment("上级分类ID");
            $table->integer("weight")->default(0)->comment("权重");
            $table->integer("index_weight")->default(0)->comment("推荐位权重");
            $table->integer("category_weight")->default(0)->comment("推荐位权重");
            $table->integer("search_weight")->default(0)->comment("搜索页权重");
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('goods', function (Blueprint $table) {
            $table->id();
            $table->string("name")->default("");
            $table->string("image_list", 2000)->default("");
            $table->string("spec")->default("")->comment("商品的规格");
            $table->unsignedInteger("weight")->default(0);
            $table->text("desc_html")->nullable();
            $table->text("spec_attr_html")->nullable();
            $table->text("faq_html")->nullable();
            $table->unsignedTinyInteger("status")->default(1)->comment("1 上架 2下架");
            $table->unsignedInteger("view_total")->default(0)->comment("浏览量");
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('goods_category_map', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger("goods_id")->default(0);
            $table->unsignedInteger("category_id")->default(0);
            $table->unsignedTinyInteger("is_public")->default(1)->comment("是否对普通会员展示");
            $table->timestamps();
        });

        Schema::create('goods_sku', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger("goods_id")->default(0);
            $table->string("sn")->default("")->comment("型号");
            $table->string("url_3d")->default("")->comment("3D的跳转地址");
            $table->string("spec_attr_list", 2000)->default("")->comment("规格数据");
            $table->unsignedTinyInteger("is_use")->default(1)->comment("是否使用");
            $table->timestamps();
            $table->softDeletes();

            $table->index("goods_id");
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('spec');
        Schema::dropIfExists('spec_attr');
        Schema::dropIfExists('category');
        Schema::dropIfExists('goods');
        Schema::dropIfExists('goods_category_map');
        Schema::dropIfExists('goods_sku');
    }
};