<?php

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

class CreateDailySalesReportsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('daily_sales_reports')) {
            return;
        }
        Schema::create('daily_sales_reports', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->date('date');
            $table->unsignedInteger('goods_id');
            $table->unsignedInteger('goods_sku_id');
            $table->string('name');
            $table->string('external_sku_id', 64);
            $table->integer('inventory')->default(0)->comment('盘点数量');
            $table->integer('arrived_today_num')->default(0)->comment('今日到货');
            $table->integer('sales_num')->default(0)->comment('总销量');
            $table->integer('already_cancel_number')->default(0)->comment('已取消数量');
            $table->unsignedInteger('loss_num')->default(0)->comment('损耗');
            $table->decimal('goal_rate', 8, 4)->default(0)->comment('目标去化率');
            $table->integer('S1')->default(0)->comment('11-12');
            $table->integer('S2')->default(0)->comment('11-13:30');
            $table->integer('S3')->default(0)->comment('11-15');
            $table->integer('S4')->default(0)->comment('15-16');
            $table->integer('S5')->default(0)->comment('11-17:30');
            $table->integer('S6')->default(0)->comment('11-20');
            $table->integer('S7')->default(0)->comment('11-9:30');
            $table->decimal('S1_rate', 8, 4)->default(0);
            $table->decimal('S2_rate', 8, 4)->default(0);
            $table->decimal('S3_rate', 8, 4)->default(0);
            $table->decimal('S4_rate', 8, 4)->default(0);
            $table->decimal('S5_rate', 8, 4)->default(0);
            $table->decimal('S6_rate', 8, 4)->default(0);
            $table->decimal('S7_rate', 8, 4)->default(0);

            $table->timestamps();
        });
    }

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