<?php

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

class AddFieldsWithDailyStockRecordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasColumns('daily_stock_records', ['order_goods_num', 'inventory_time'])) {
            return;
        }
        Schema::table('daily_stock_records', function (Blueprint $table) {
            $table->integer('order_goods_num')->default(0)->comment('截止盘点时间订单商品数量');
            $table->timestamp('inventory_time')->nullable()->comment('盘点时间');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('daily_stock_records', function (Blueprint $table) {
            $table->dropColumn('order_goods_num');
            $table->dropColumn('inventory_time');
        });
    }
}
