<?php

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

class CreateLossRecordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('loss_records', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('external_sku_id',60)->comment('唯一sku标识');
            $table->string('batch_number',60)->nullable()->comment('批次号');
            $table->date('date')->nullable()->comment('日期');
            $table->Integer('num')->default(0)->comment('报损数量');
            $table->unsignedDecimal('cost')->default(0)->comment('成本');
            $table->Integer('buyer_user_id')->default(0)->comment('购买人用户id');;
            $table->string('buyer_name')->nullable()->comment('采购人');
            $table->string('reason')->nullable()->comment('报损原因');
            $table->string('phenomenon')->nullable()->comment('报损现象');

            // 索引
            $table->index('external_sku_id');
            $table->index('created_at');
            $table->index('batch_number');
            $table->timestamps();
        });
    }

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