1. 清理预充值SQL

2. 查日志的脚本
This commit is contained in:
2026-05-25 14:30:09 +08:00
parent 226474b434
commit 20b5d70af9
6 changed files with 1779 additions and 11 deletions

View File

@@ -2387,7 +2387,7 @@ components:
DtoClientCreateOrderRequest:
properties:
app_type:
description: 应用类型(强充必传)(official_account:公众号, miniapp:小程序)
description: 应用类型(微信强充必传)(official_account:公众号, miniapp:小程序)
type: string
identifier:
description: 资产标识符SN/IMEI/虚拟号/ICCID/MSISDN
@@ -2401,6 +2401,9 @@ components:
type: integer
nullable: true
type: array
payment_method:
description: 支付方式(强充必传)(wechat:微信, alipay:支付宝)
type: string
required:
- identifier
- package_ids
@@ -2419,6 +2422,8 @@ components:
type: string
pay_config:
$ref: '#/components/schemas/DtoClientPayConfig'
payment_link:
$ref: '#/components/schemas/DtoClientPaymentLink'
recharge:
$ref: '#/components/schemas/DtoClientRechargeInfo'
type: object
@@ -2427,10 +2432,10 @@ components:
amount:
description: 充值金额(分)
maximum: 1e+07
minimum: 100
minimum: 1
type: integer
app_type:
description: 应用类型 (official_account:公众号, miniapp:小程序)
description: 应用类型(微信支付必传)(official_account:公众号, miniapp:小程序)
type: string
identifier:
description: 资产标识符SN/IMEI/虚拟号/ICCID/MSISDN
@@ -2438,13 +2443,12 @@ components:
minLength: 1
type: string
payment_method:
description: 支付方式 (wechat:微信支付)
description: 支付方式 (wechat:微信支付, alipay:支付宝)
type: string
required:
- identifier
- amount
- payment_method
- app_type
type: object
DtoClientExchangePendingResponse:
properties:
@@ -2656,7 +2660,7 @@ components:
description: 应用类型(微信支付必传)(official_account:公众号, miniapp:小程序)
type: string
payment_method:
description: 支付方式 (wallet:钱包, wechat:微信)
description: 支付方式 (wallet:钱包, wechat:微信, alipay:支付宝)
type: string
required:
- payment_method
@@ -2665,10 +2669,27 @@ components:
properties:
pay_config:
$ref: '#/components/schemas/DtoClientPayConfig'
payment_link:
$ref: '#/components/schemas/DtoClientPaymentLink'
payment_method:
description: 支付方式
type: string
type: object
DtoClientPaymentLink:
properties:
copy_link:
description: 复制到普通浏览器打开的支付链接(与 qr_link 相同)
type: string
pay_expire_at:
description: 支付链接过期时间RFC3339 格式)
type: string
payment_no:
description: 支付单号
type: string
qr_link:
description: 二维码内容链接,前端用该链接生成二维码
type: string
type: object
DtoClientRechargeCheckResponse:
properties:
force_recharge_amount:
@@ -2780,6 +2801,8 @@ components:
properties:
pay_config:
$ref: '#/components/schemas/DtoClientRechargePayConfig'
payment_link:
$ref: '#/components/schemas/DtoClientPaymentLink'
recharge:
$ref: '#/components/schemas/DtoClientRechargeResult'
type: object
@@ -3602,6 +3625,32 @@ components:
type: object
DtoCreateWechatConfigRequest:
properties:
ali_app_id:
description: 支付宝应用ID
maxLength: 100
type: string
ali_notify_url:
description: 支付宝异步通知地址
maxLength: 500
type: string
ali_pay_expire_minutes:
description: 支付过期分钟数 (默认30分钟)
maximum: 1440
minimum: 1
type: integer
ali_private_key:
description: 支付宝应用私钥(PEM格式)
type: string
ali_production:
description: 是否生产环境 (true:生产, false:沙箱)
type: boolean
ali_public_key:
description: 支付宝公钥(PEM格式用于验签)
type: string
ali_return_url:
description: 支付宝同步跳转地址
maxLength: 500
type: string
description:
description: 配置描述
maxLength: 500
@@ -3666,7 +3715,7 @@ components:
maxLength: 200
type: string
provider_type:
description: 支付渠道类型 (wechat:微信直连, fuiou:富友)
description: 支付渠道类型 (wechat:微信直连v3, wechat_v2:微信直连v2, fuiou:富友)
type: string
wx_api_v2_key:
description: 微信APIv2密钥
@@ -8626,6 +8675,39 @@ components:
type: object
DtoUpdateWechatConfigParams:
properties:
ali_app_id:
description: 支付宝应用ID
maxLength: 100
nullable: true
type: string
ali_notify_url:
description: 支付宝异步通知地址
maxLength: 500
nullable: true
type: string
ali_pay_expire_minutes:
description: 支付过期分钟数
maximum: 1440
minimum: 1
nullable: true
type: integer
ali_private_key:
description: 支付宝应用私钥(PEM格式)
nullable: true
type: string
ali_production:
description: 是否生产环境 (true:生产, false:沙箱)
nullable: true
type: boolean
ali_public_key:
description: 支付宝公钥(PEM格式用于验签)
nullable: true
type: string
ali_return_url:
description: 支付宝同步跳转地址
maxLength: 500
nullable: true
type: string
description:
description: 配置描述
maxLength: 500
@@ -8706,7 +8788,7 @@ components:
nullable: true
type: string
provider_type:
description: 支付渠道类型 (wechat:微信直连, fuiou:富友)
description: 支付渠道类型 (wechat:微信直连v3, wechat_v2:微信直连v2, fuiou:富友)
nullable: true
type: string
wx_api_v2_key:
@@ -8890,6 +8972,27 @@ components:
type: object
DtoWechatConfigResponse:
properties:
ali_app_id:
description: 支付宝应用ID
type: string
ali_notify_url:
description: 支付宝异步通知地址
type: string
ali_pay_expire_minutes:
description: 支付过期分钟数
type: integer
ali_private_key:
description: 支付宝应用私钥(配置状态)
type: string
ali_production:
description: 是否生产环境
type: boolean
ali_public_key:
description: 支付宝公钥(配置状态)
type: string
ali_return_url:
description: 支付宝同步跳转地址
type: string
created_at:
description: 创建时间
type: string
@@ -8949,7 +9052,7 @@ components:
description: 公众号Token(已脱敏)
type: string
provider_type:
description: 支付渠道类型 (wechat:微信直连, fuiou:富友)
description: 支付渠道类型 (wechat:微信直连v3, wechat_v2:微信直连v2, fuiou:富友)
type: string
updated_at:
description: 更新时间
@@ -23253,11 +23356,11 @@ paths:
maximum: 100
minimum: 1
type: integer
- description: 支付渠道类型 (wechat:微信直连, fuiou:富友)
- description: 支付渠道类型 (wechat:微信直连v3, wechat_v2:微信直连v2, fuiou:富友)
in: query
name: provider_type
schema:
description: 支付渠道类型 (wechat:微信直连, fuiou:富友)
description: 支付渠道类型 (wechat:微信直连v3, wechat_v2:微信直连v2, fuiou:富友)
nullable: true
type: string
- description: 是否激活 (true:已激活, false:未激活)

View File

@@ -0,0 +1,155 @@
# 支付宝支付链接前端对接说明
## 1. 对接范围
本次新增的是 **C 端支付宝支付链接能力**。前端无需接入支付宝 SDK后端会返回已签名的支付宝 WAP 支付链接。
覆盖场景:
1. 套餐订单支付
2. 钱包充值
3. 强制充值购包场景
微信支付原逻辑保持不变:微信返回 `pay_config`,支付宝返回 `payment_link`
具体接口路径、完整请求字段、响应结构、错误码请以前端接口文档 / OpenAPI 文档为准。
## 2. 支付方式取值
前端统一使用 `payment_method` 区分支付方式:
| 值 | 含义 | 前端处理 |
| --- | --- | --- |
| `wallet` | 钱包支付 | 仅订单支付支持,无第三方跳转 |
| `wechat` | 微信支付 | 使用返回的 `pay_config` 调起微信支付 |
| `alipay` | 支付宝支付 | 使用返回的 `payment_link` 打开或展示支付链接 |
注意事项:
- `app_type` 只在微信支付时需要。
- 支付宝支付时不需要传 `app_type`
- 支付宝支付返回的是支付链接,不是 JSAPI 参数。
## 3. 前端需要关注的响应字段
当选择支付宝支付时,接口响应中会返回 `payment_link`
```json
{
"payment_link": {
"payment_no": "支付单号",
"qr_link": "支付宝支付链接,可用于生成二维码",
"copy_link": "支付宝支付链接,可复制或直接打开",
"pay_expire_at": "支付链接过期时间RFC3339 格式"
}
}
```
字段说明:
| 字段 | 用途 |
| --- | --- |
| `payment_no` | 支付单号,问题排查 / 客服查询使用 |
| `qr_link` | 前端可用该链接生成二维码 |
| `copy_link` | 用户复制或浏览器打开的支付链接,当前与 `qr_link` 一致 |
| `pay_expire_at` | 支付链接过期时间,前端可用于倒计时展示 |
## 4. 推荐交互流程
### 4.1 支付宝支付流程
前端拿到 `payment_link` 后:
1. H5 / 浏览器场景:直接跳转 `copy_link`
2. PC 场景:使用 `qr_link` 生成二维码。
3. App / WebView 场景:在外部浏览器或支付宝可识别环境中打开 `copy_link`
支付成功后:
- 不要只依赖支付宝返回页判断支付成功。
- 最终支付状态以服务端订单 / 充值记录状态为准。
- 用户返回页面后,前端应轮询订单详情、订单列表或充值记录接口。
## 5. 各业务场景说明
### 5.1 套餐订单支付
普通套餐下单后,如果需要支付,前端调用订单支付接口,并传:
```json
{
"payment_method": "alipay"
}
```
支付宝支付响应示例:
```json
{
"payment_method": "alipay",
"payment_link": {
"payment_no": "...",
"qr_link": "...",
"copy_link": "...",
"pay_expire_at": "..."
}
}
```
前端根据 `payment_link` 发起支付宝支付。
### 5.2 钱包充值
创建钱包充值单时传:
```json
{
"payment_method": "alipay"
}
```
支付宝场景返回 `payment_link`;微信场景返回 `pay_config`
### 5.3 强制充值购包
创建订单时,如果后端判断需要强制充值,前端可指定:
```json
{
"payment_method": "alipay"
}
```
如果是支付宝强充,响应中会返回:
```json
{
"order_type": "recharge",
"recharge": {},
"payment_link": {}
}
```
前端按支付宝支付链接流程处理。
## 6. 前端展示建议
支付宝支付页面建议展示:
- 支付金额
- 支付宝二维码或“去支付宝支付”按钮
- 支付链接过期倒计时
- “我已完成支付”按钮
- “重新获取支付链接”按钮
点击“我已完成支付”时,不直接判定成功,应查询服务端状态。
## 7. 注意事项
1. 金额单位仍然是 **分**
2. 支付宝支付不需要 `app_type`
3. `pay_config` 只用于微信支付。
4. `payment_link` 只用于支付宝支付。
5. 支付状态以服务端为准,不以前端跳转结果为准。
6. 支付链接过期后,前端应重新调用对应支付 / 充值接口获取新链接。
7. 具体接口路径、完整字段、错误码请以前端接口文档 / OpenAPI 文档为准。

View File

@@ -56,6 +56,47 @@ redis-cli HGETALL polling:stats:package
redis-cli HGETALL polling:init:progress
```
### 4. 跨 Worker 日志查询
线上多实例 Worker 日志分散时,使用仓库内 Rust 工具统一扫描普通日志和 `.gz` 轮转日志。工具默认只输出汇总、命中文件和少量样例,不会把窗口刷满。
```bash
rustc scripts/ops/search-worker-logs.rs -O -o /tmp/jh-logq
/tmp/jh-logq \
--roots "/data/worker-1/logs:/data/worker-2/logs:/data/worker-3/logs:/data/worker-4/logs" \
--iccid 8986000000000000000 \
--date 2026-05-24 \
--interface realname
```
常用接口别名:
| 别名 | 匹配内容 |
|------|----------|
| `realname` | 实名接口、`realStatus`、实名相关业务日志 |
| `flow` / `carddata` | 流量接口、`used`、流量相关业务日志 |
| `card_status` | 卡状态接口、`cardStatus`、卡状态业务日志 |
| `stop` | 停机接口或停机业务日志 |
| `start` / `resume` | 复机接口或复机业务日志 |
排查“23 号有实名同步24 号没有”的建议顺序:
```bash
# 对比两天命中数,先确认是不是所有 Worker 都没有
/tmp/jh-logq --roots "/data/worker-1/logs:/data/worker-2/logs:/data/worker-3/logs:/data/worker-4/logs" \
--iccid 8986000000000000000 --date 2026-05-23 --interface realname --count-only
/tmp/jh-logq --roots "/data/worker-1/logs:/data/worker-2/logs:/data/worker-3/logs:/data/worker-4/logs" \
--iccid 8986000000000000000 --date 2026-05-24 --interface realname --count-only
# 如果 24 号实名没有命中,再看这张卡当天是否仍在跑其他轮询
/tmp/jh-logq --roots "/data/worker-1/logs:/data/worker-2/logs:/data/worker-3/logs:/data/worker-4/logs" \
--iccid 8986000000000000000 --date 2026-05-24
```
注意:旧版本 Gateway 成功请求日志没有稳定输出接口 `path`,脚本对历史日志的 `realname` 匹配会同时使用 `realStatus` 和“实名”业务日志推断。若需要严格按 Gateway 路径查询,生产版本需要在 Gateway 请求/响应日志中输出 `path`
## 告警配置
### 1. 默认告警规则

View File

@@ -0,0 +1,66 @@
BEGIN;
-- 锁定代理主钱包,确认余额和冻结余额
SELECT *
FROM tb_agent_wallet
WHERE shop_id = :shop_id
AND wallet_type = 'main'
AND deleted_at IS NULL
FOR UPDATE;
-- 确认 frozen_balance = 0 且 balance > 0 后执行
INSERT INTO tb_agent_wallet_transaction (
agent_wallet_id,
shop_id,
user_id,
transaction_type,
amount,
balance_before,
balance_after,
status,
reference_type,
reference_id,
remark,
metadata,
creator,
shop_id_tag,
enterprise_id_tag,
created_at,
updated_at
)
SELECT
id,
shop_id,
:operator_user_id,
'deduct',
-balance,
balance,
0,
1,
NULL,
NULL,
'平台清理代理预充值剩余余额,历史消费流水保留',
jsonb_build_object('reason', 'clear_agent_main_wallet_balance'),
:operator_user_id,
shop_id_tag,
enterprise_id_tag,
NOW(),
NOW()
FROM tb_agent_wallet
WHERE shop_id = :shop_id
AND wallet_type = 'main'
AND deleted_at IS NULL
AND balance > 0
AND frozen_balance = 0;
UPDATE tb_agent_wallet
SET balance = 0,
version = version + 1,
updated_at = NOW()
WHERE shop_id = :shop_id
AND wallet_type = 'main'
AND deleted_at IS NULL
AND balance > 0
AND frozen_balance = 0;
COMMIT;