<?php

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

class CreatePaymentPreCreatesTable extends Migration
{
    /**
     * 运行迁移
     *
     * @return void
     */
    public function up()
    {
        Schema::create('payment_pre_creates', function (Blueprint $table) {
            $table->id();
            $table->string('pre_create_no')->unique()->comment('预创建编号');
            $table->string('payment_type')->comment('支付类型');
            $table->text('params')->comment('预创建参数');
            $table->string('status')->default('pending')->comment('状态');
            $table->text('result')->nullable()->comment('结果');
            $table->text('error')->nullable()->comment('错误信息');
            $table->timestamp('expired_at')->comment('过期时间');
            $table->timestamps();
        });

        // 创建索引
        Schema::table('payment_pre_creates', function (Blueprint $table) {
            $table->index('pre_create_no');
            $table->index('payment_type');
            $table->index('status');
            $table->index('expired_at');
        });
    }

    /**
     * 回滚迁移
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('payment_pre_creates');
    }
}
