<?php

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

class CreatePaymentsTable extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('payments', function (Blueprint $table) {
            $table->id();
            $table->morphs('order');
            $table->unsignedBigInteger('user_id')->index();
            $table->uuid('trade_id')->unique();
            $table->decimal('total', 20, 2)->unsigned()->comment('支付金额');
            $table->enum('driver', ['alipay', 'wechat', 'score'])->index()->comment('支付方式');
            $table->string('gateway', 16)->comment('支付渠道');
            $table->string('state', 16)->index()->comment('订单状态');
            $table->uuid('transaction_id')->nullable()->index()->comment('三方交易号');
            $table->timestamp('paid_at')->nullable()->comment('订单支付时间');
            $table->timestamps();

            $table->index('created_at');
        });
    }

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

}
