74 lines
2.7 KiB
PHP
74 lines
2.7 KiB
PHP
<?php
|
|
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
|
|
if (file_exists(__DIR__ . '/.env')) {
|
|
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
|
|
$dotenv->load();
|
|
}
|
|
|
|
$capsule = new Capsule;
|
|
$capsule->addConnection([
|
|
'driver' => 'mysql',
|
|
'host' => $_ENV['DB_HOST'] ?? '127.0.0.1',
|
|
'port' => $_ENV['DB_PORT'] ?? '3306',
|
|
'database' => $_ENV['DB_DATABASE'] ?? '',
|
|
'username' => $_ENV['DB_USERNAME'] ?? '',
|
|
'password' => $_ENV['DB_PASSWORD'] ?? '',
|
|
'charset' => 'utf8mb4',
|
|
'collation' => 'utf8mb4_unicode_ci',
|
|
'prefix' => '',
|
|
]);
|
|
$capsule->setAsGlobal();
|
|
$capsule->bootEloquent();
|
|
|
|
if (Capsule::schema()->hasTable('orders')) {
|
|
if (!Capsule::schema()->hasColumn('orders', 'pay_channel')) {
|
|
Capsule::schema()->table('orders', function ($table) {
|
|
$table->string('pay_channel', 20)->nullable()->after('pay_time');
|
|
});
|
|
echo "Added 'pay_channel' to orders.\n";
|
|
}
|
|
if (!Capsule::schema()->hasColumn('orders', 'pay_status')) {
|
|
Capsule::schema()->table('orders', function ($table) {
|
|
$table->string('pay_status', 20)->default('unpaid')->after('pay_channel');
|
|
});
|
|
echo "Added 'pay_status' to orders.\n";
|
|
}
|
|
if (!Capsule::schema()->hasColumn('orders', 'pay_merchant_id')) {
|
|
Capsule::schema()->table('orders', function ($table) {
|
|
$table->unsignedBigInteger('pay_merchant_id')->default(0)->after('pay_status');
|
|
});
|
|
echo "Added 'pay_merchant_id' to orders.\n";
|
|
}
|
|
if (!Capsule::schema()->hasColumn('orders', 'pay_out_trade_no')) {
|
|
Capsule::schema()->table('orders', function ($table) {
|
|
$table->string('pay_out_trade_no', 64)->nullable()->after('pay_merchant_id');
|
|
});
|
|
echo "Added 'pay_out_trade_no' to orders.\n";
|
|
}
|
|
}
|
|
|
|
if (!Capsule::schema()->hasTable('payment_transactions')) {
|
|
Capsule::schema()->create('payment_transactions', function ($table) {
|
|
$table->id();
|
|
$table->unsignedBigInteger('order_id')->index();
|
|
$table->string('channel', 20)->default('wechat')->index();
|
|
$table->unsignedBigInteger('merchant_id')->default(0)->index();
|
|
$table->string('out_trade_no', 64)->unique();
|
|
$table->decimal('amount', 10, 2)->default(0.00);
|
|
$table->string('status', 20)->default('created')->index();
|
|
$table->string('prepay_id', 64)->nullable();
|
|
$table->string('code_url', 255)->nullable();
|
|
$table->json('raw_json')->nullable();
|
|
$table->timestamp('paid_at')->nullable();
|
|
$table->timestamps();
|
|
});
|
|
echo "Table 'payment_transactions' created successfully.\n";
|
|
}
|
|
|
|
echo "Alter orders_pay completed.\n";
|
|
|