<?php

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

class AddFieldToWaybillsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasColumns('waybills', ["status"])) {
            return;
        }
        Schema::table('waybills', function (Blueprint $table) {
            $table->integer('status')->default(0)->comment('状态 0待申请物流单 1已申请物流 2已申请面单 3已打印');
            $table->index('order_id');
            $table->index('order_sn');
            $table->index('waybill_code');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('waybills', function (Blueprint $table) {
            //
            $table->dropColumn('status');
            $table->dropIndex('order_id');
            $table->dropIndex('order_sn');
            $table->dropIndex('waybill_code');
        });
    }
}
