<?php

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

class CreateDailyReportsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('daily_reports')) {
            return;
        }
        Schema::create('daily_reports', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->date('date');
            $table->unsignedInteger('goods_id');
            $table->unsignedInteger('type_id');
            $table->unsignedInteger('brand_id');
            $table->unsignedInteger('goods_sku_id');
            $table->string('external_sku_id', 64);
            $table->unsignedInteger('total_goods_price')->default(0);
            $table->unsignedInteger('total_goods_cost_price')->default(0);
            $table->unsignedInteger('total_goods_amount')->default(0);
            $table->unsignedInteger('total_goods_number')->default(0);
            $table->unsignedInteger('total_cancel_number')->default(0);
            $table->unsignedDecimal('cost')->default(0);
            $table->text('shop_data');

            $table->timestamps();
            $table->index(['date', 'external_sku_id']);
        });
    }

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