<?php

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

class CreateMallOrdersTable extends Migration
{

    /**
     * Run the migrations.
     * @return void
     */
    public function up()
    {
        Schema::create('mall_orders', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('shop_id')->index()->comment('所属店铺');
            $table->string('order_no', 32)->unique()->comment('订单编号');
            $table->unsignedInteger('user_id')->index()->comment('下单用户');

            $table->unsignedDecimal('amount', 20, 2)->comment('订单金额');
            $table->unsignedDecimal('freight', 10, 2)->default(0)->comment('运费');

            $table->timestamp('expired_at')->nullable()->comment('订单过期时间');
            $table->timestamp('paid_at')->nullable()->comment('支付时间');

            $table->string('state', 16)->comment('状态')->nullable();
            $table->boolean('type')->comment('订单类型：1 正常 2试用');
            $table->string('remark')->nullable()->comment('用户留言');
            $table->string('description')->nullable()->comment('备注');

            $table->json('source')->comment('附加数据')->nullable();

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

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

}