feat: update appraisal ordering and payment flows

This commit is contained in:
wushumin
2026-06-03 18:14:40 +08:00
parent 0838db5aba
commit 6383ec5a2a
50 changed files with 6143 additions and 988 deletions

View File

@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
require dirname(__DIR__) . '/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
$dotenv->safeLoad();
$dsn = sprintf(
'mysql:host=%s;port=%s;dbname=%s;charset=%s',
$_ENV['DB_HOST'] ?? '127.0.0.1',
$_ENV['DB_PORT'] ?? '3306',
$_ENV['DB_DATABASE'] ?? '',
$_ENV['DB_CHARSET'] ?? 'utf8mb4'
);
$pdo = new PDO(
$dsn,
$_ENV['DB_USERNAME'] ?? '',
$_ENV['DB_PASSWORD'] ?? '',
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]
);
function hasTable(PDO $pdo, string $table): bool
{
$stmt = $pdo->prepare('SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?');
$stmt->execute([$table]);
return (int)$stmt->fetchColumn() > 0;
}
function hasSystemConfig(PDO $pdo, string $group, string $key): bool
{
$stmt = $pdo->prepare('SELECT COUNT(*) FROM system_configs WHERE config_group = ? AND config_key = ?');
$stmt->execute([$group, $key]);
return (int)$stmt->fetchColumn() > 0;
}
function hasColumn(PDO $pdo, string $table, string $column): bool
{
$stmt = $pdo->prepare('SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?');
$stmt->execute([$table, $column]);
return (int)$stmt->fetchColumn() > 0;
}
$now = date('Y-m-d H:i:s');
if (hasTable($pdo, 'orders') && !hasColumn($pdo, 'orders', 'cancelled_at')) {
$pdo->exec('ALTER TABLE orders ADD COLUMN cancelled_at DATETIME NULL DEFAULT NULL AFTER paid_at');
echo "ADD_COLUMN orders.cancelled_at\n";
}
if (!hasTable($pdo, 'shouqianba_payments')) {
$pdo->exec(<<<'SQL'
CREATE TABLE shouqianba_payments (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
order_id BIGINT UNSIGNED NOT NULL,
order_no VARCHAR(64) NOT NULL,
check_sn VARCHAR(32) NOT NULL,
order_sn VARCHAR(32) NOT NULL DEFAULT '',
order_token VARCHAR(64) NOT NULL DEFAULT '',
cashier_url VARCHAR(500) NOT NULL DEFAULT '',
order_image_url VARCHAR(500) NOT NULL DEFAULT '',
order_landing_url VARCHAR(500) NOT NULL DEFAULT '',
scene VARCHAR(8) NOT NULL DEFAULT '',
source_channel VARCHAR(32) NOT NULL DEFAULT '',
status VARCHAR(32) NOT NULL DEFAULT 'pending',
amount INT UNSIGNED NOT NULL DEFAULT 0,
currency VARCHAR(3) NOT NULL DEFAULT '156',
request_json LONGTEXT NULL,
response_json LONGTEXT NULL,
notify_json LONGTEXT NULL,
paid_at DATETIME NULL DEFAULT NULL,
cancelled_at DATETIME NULL DEFAULT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uk_shouqianba_payments_check_sn (check_sn),
KEY idx_shouqianba_payments_order_id (order_id),
KEY idx_shouqianba_payments_order_sn (order_sn),
KEY idx_shouqianba_payments_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='收钱吧支付流水'
SQL);
echo "CREATE_TABLE shouqianba_payments\n";
}
$configs = [
['payment', 'enabled', 'disabled'],
['payment', 'api_domain', ''],
['payment', 'appid', ''],
['payment', 'brand_code', ''],
['payment', 'store_sn', ''],
['payment', 'store_name', ''],
['payment', 'workstation_sn', '0'],
['payment', 'industry_code', '0'],
['payment', 'order_expire_minutes', '1440'],
['payment', 'merchant_private_key', ''],
['payment', 'shouqianba_public_key', ''],
['payment', 'notify_url', ''],
['payment', 'mini_program_plugin_version', ''],
];
$stmt = $pdo->prepare('INSERT INTO system_configs (config_group, config_key, config_value, remark, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)');
foreach ($configs as [$group, $key, $value]) {
if (hasSystemConfig($pdo, $group, $key)) {
continue;
}
$stmt->execute([$group, $key, $value, '后台系统配置', $now, $now]);
echo "ADD_CONFIG {$group}.{$key}\n";
}
echo "SCHEMA_UPGRADE_OK\n";