<?php

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

class CreateGroupGoodsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('group_goods')) {
            return;
        }
        Schema::defaultStringLength(191);
        Schema::create('group_goods', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('group_id');
            $table->string('category_name');
            $table->unsignedBigInteger('type_id');
            $table->string('goods_desc')->nullable();
            $table->string('goods_name');
            $table->unsignedBigInteger('goods_id');
            $table->unsignedBigInteger('ktt_goods_id')->nullable();
            $table->unsignedInteger('limit_buy')->default(0);
            $table->unsignedBigInteger('market_price')->default(0);
            $table->text('pic_url_list')->nullable();
            $table->unsignedBigInteger('sku_id');
            $table->unsignedBigInteger('ktt_sku_id')->nullable();
            $table->string('external_sku_id');
            $table->unsignedBigInteger('price_in_fen');
            $table->unsignedTinyInteger('quantity_type')->default(0)->comment('库存类型，0-普通 1-无限，无限库存时会无视total_quantity字段');
            $table->text('spec_id_list')->nullable()->comment('规格id列表，无规格为空list，如果想规格为红色,M，调用生成规格的id，红色为1，M为3，则应传入[1,3]');
            $table->text('thumb_url')->nullable()->comment('sku图url，注意sku图格式必须是jpg、jpeg、png中的一个，且尺寸不得大于1200*1200，大小不大于1MB，可以不填');
            $table->unsignedInteger('total_quantity')->default(0)->comment('总库存,最多100w');
            $table->integer('sort')->default(0);
            $table->timestamps();

            $table->index(['group_id', 'sku_id']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('group_goods');
    }
}
