<?php


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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('payment_orders', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->tinyInteger('type')->default(1)->comment('类型：1=代收，2=代付');
            $table->string('order_no', 64)->unique()->comment('订单号');
            $table->string('member_id', 64)->comment('会员ID');
            $table->decimal('amount', 18, 2)->comment('金额');
            $table->string('channel', 50)->nullable()->comment('渠道');
            // 代付字段（可选）
            $table->string('bank_name', 100)->nullable()->comment('银行名称（代付时使用）');
            $table->string('account', 100)->nullable()->comment('收款人姓名（代付时使用）');
            $table->string('card_no', 100)->nullable()->comment('收款银行卡号（代付时使用）');

            $table->tinyInteger('status')->default(0)->comment('状态：0待处理 1处理中 2成功 3失败');
            $table->string('callback_url', 255)->nullable()->comment('回调地址');
            $table->json('callback_data')->nullable()->comment('第三方回调返回的数据');

            $table->timestamps();
            $table->index(['type', 'status']);
            $table->index(['channel']);
        });
    }

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