<?php

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

class CreatePaymentRecordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('payment_records', function (Blueprint $table) {
            $table->id();
            $table->string('payment_type', 50)->comment('支付类型');
            $table->string('payment_name', 50)->comment('支付方式名称');
            $table->string('out_trade_no', 100)->comment('商户订单号');
            $table->string('trade_no', 100)->nullable()->comment('支付平台订单号');
            $table->decimal('amount', 10, 2)->comment('支付金额');
            $table->string('currency', 10)->default('CNY')->comment('货币类型');
            $table->string('status', 20)->default('pending')->comment('支付状态');
            $table->json('payload')->nullable()->comment('支付请求参数');
            $table->json('result')->nullable()->comment('支付响应结果');
            $table->json('callback_data')->nullable()->comment('回调数据');
            $table->timestamp('paid_at')->nullable()->comment('支付完成时间');
            $table->timestamp('refunded_at')->nullable()->comment('退款完成时间');
            $table->timestamp('closed_at')->nullable()->comment('订单关闭时间');
            $table->text('remark')->nullable()->comment('备注');
            $table->timestamps();
            $table->index('payment_type');
            $table->index('out_trade_no');
            $table->index('trade_no');
            $table->index('status');
        });
    }

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