refactor(pay): 统一流水号,移除订单/流水/提现三类号码前缀
订单号、资金流水号、提现单号此前各自带前缀配置,同一笔业务在不同界面会
呈现多个号码口径,对账与客诉排查都要先做一次前缀换算。现收敛为单一流水号
分配器,不再按业务类型区分号码形态。
- 删除 payment_order_prefix / payment_flow_prefix /
payment_withdrawal_prefix 三项配置项及其生成、校验链路
- BusinessNumber::allocate() 成为唯一入口,输出 {YmdHis}{6 位随机},
共 20 位无前缀,满足 VARCHAR(32) 与网关 out_trade_no ≤ 32 的限制
- 订单、资金流水、提现、卡密渠道交易号四处生成点全部改走该分配器
- 后台支付中心表头「订单号 / 提现单号」统一为「流水号」
- 前台用户中心与订单卡片文案同步统一;前台订单详情合并为单行流水号,
账本流水号不再下发到前台,避免同一单据出现两个对外号码
- 同步更新 financial-flow / pay-card / card-pass-order-numbers 契约测试
与 BusinessNumberTest 断言
按用户要求不做双路逻辑与数据迁移,直接替换为统一方案,历史行不做转换。
验证:node --test tests/**/*.test.cjs 362/364 通过,新增 37 项契约;失败的
2 项在改动前的干净 HEAD 基线上同样失败(基线 327 项 / 失败 2 项),分别命中
遗留的 fa fa- 标记与 FA 版本号断言,与本次改动无关。phpunit 44 项 / 103
断言全部通过;php -l 全部改动的 PHP 文件通过。
This commit is contained in:
1 parent
8b999444b2
commit
aad83072a8
30 files changed
+126
-144
No files matched your search
@@ -7,30 +7,28 @@ namespace AKSRT\Finance;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* 统一业务流水号分配器。
|
||||
*
|
||||
* 订单号、资金流水号、提现单号共用同一套号码规则,不再按业务类型区分,
|
||||
* 也不再存在任何可配置前缀:{YmdHis}{6 位随机数},共 20 字符。
|
||||
* 该长度同时满足数据库 VARCHAR(32) 列与各网关 out_trade_no ≤32 字符的限制。
|
||||
*/
|
||||
final class BusinessNumber {
|
||||
|
||||
public const MAX_PREFIX_LENGTH = 12;
|
||||
|
||||
public static function normalize_prefix(mixed $value, string $fallback): string {
|
||||
$prefix = strtoupper(trim(sanitize_text_field(is_scalar($value) ? (string) $value : '')));
|
||||
$prefix = (string) preg_replace('/[^A-Z0-9_-]/', '', $prefix);
|
||||
$prefix = substr($prefix, 0, self::MAX_PREFIX_LENGTH);
|
||||
if ($prefix !== '') {
|
||||
return $prefix;
|
||||
}
|
||||
|
||||
$fallback = strtoupper((string) preg_replace('/[^A-Z0-9_-]/', '', $fallback));
|
||||
return substr($fallback !== '' ? $fallback : 'AK', 0, self::MAX_PREFIX_LENGTH);
|
||||
}
|
||||
|
||||
public static function candidate(string $prefix, ?\DateTimeInterface $now = null, ?int $random = null): string {
|
||||
$prefix = self::normalize_prefix($prefix, 'AK');
|
||||
/**
|
||||
* 生成一个统一流水号。
|
||||
*
|
||||
* @param \DateTimeInterface|null $now 分配时刻,默认取站内时区的当前时间。
|
||||
* @param int|null $random 0-999999 的随机后缀,默认随机取值。
|
||||
*/
|
||||
public static function allocate(?\DateTimeInterface $now = null, ?int $random = null): string {
|
||||
if ($now === null) {
|
||||
$now = new \DateTimeImmutable('now', wp_timezone());
|
||||
}
|
||||
$random = $random ?? random_int(0, 999999);
|
||||
$random = max(0, min(999999, $random));
|
||||
|
||||
return $prefix . $now->format('YmdHis') . str_pad((string) $random, 6, '0', STR_PAD_LEFT);
|
||||
return $now->format('YmdHis') . str_pad((string) $random, 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user