<?php

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

class CreateVirtualOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('virtual_orders')) {
            return;
        }

        Schema::create("virtual_orders", function (Blueprint $table) {
            $table->increments('id')->comment('订单ID');
            $table->string('sn', 32)->comment('订单编号');
            $table->tinyInteger('source')->unsigned()->default(0)->comment('订单来源（0:用户订单 1:后台订单）');
            $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型（0:基础订单 1:套餐续费 2：续费包 3:加油包 4:可选包 5:附加包 6:组合包 7:套餐升级）');
            $table->integer('company_id')->unsigned()->default(0)->comment("企业ID");
            $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID');
            $table->string('transaction_no', 64)->default('')->comment('交易流水号');
            $table->string('pay_channel', 20)->default('')->comment('支付频道');
            $table->integer('unit_price')->unsigned()->default(0)->comment('单价');
            $table->integer('counts')->unsigned()->default(0)->comment('数量');
            $table->integer('total_price')->unsigned()->default(0)->comment('总价');
            $table->integer('custom_price')->unsigned()->default(0)->comment('自定义总价');
            $table->timestamp('order_at')->nullable()->comment('下单时间');
            $table->string('area')->default('')->comment('区域');
            $table->string('address')->default('')->comment('收货地址');
            $table->string('contacts')->default('')->comment('联系人');
            $table->string('mobile')->default('')->comment('电话');
            $table->string('logistics_company', '20')->default('')->comment('物流公司');
            $table->string('logistics_no', 64)->default('')->comment('物流单号');
            $table->tinyInteger('order_status')->unsigned()->default(0)->comment('订单状态(0:已下单 1:已取消 2:已排单 3:已出库 4:已发货 5:已签收)');
            $table->tinyInteger('transaction_status')->unsigned()->default(0)->comment('收款状态(0:未收款 1:已收款 2:已退款)');
            $table->text('logistics_remark')->nullable()->comment('物流备注');
            $table->text('remark')->nullable()->comment('订单备注');
            $table->text('extends')->nullable()->comment('扩展信息(cancel_remark:取消备注 refund_channel:退款频道 refund_account:退款账号 refund_remark:退款备注)');
            $table->tinyInteger('sign')->unsigned()->default(0)->comment('特殊标记 0:非特殊 -1:不在VD上的改企业转销售 -2：改企业的转销售');
            $table->timestamps();
            $table->softDeletes();

            $table->unique(['sn', 'deleted_at']);
            $table->index('type');
            $table->index('company_id');
            $table->index('order_at');
            $table->comment('VD订单');
        });
    }

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