feat: 迁移渠道激活列表和绑定期间流水

This commit is contained in:
Yvan
2026-11-03 20:53:25 +08:00
parent 838c2c496f
commit 8908430a89
28 changed files with 1180 additions and 9 deletions
+42
View File
@@ -0,0 +1,42 @@
"""查询运行实例的渠道激活接口,仅执行只读请求。"""
import argparse
import json
import urllib.parse
import urllib.request
from pathlib import Path
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--base-url", default="http://127.0.0.1:18000")
parser.add_argument("--token-file", required=True, type=Path)
parser.add_argument("--output", required=True, type=Path)
args = parser.parse_args()
token = args.token_file.read_text(encoding="utf-8").strip()
checks = []
paths = [
("/sw/promoteActivePool/bindList?pageNum=1&pageSize=10", 0),
("/sw/promoteActivePool/bindList?platformNames=lx,hw&statuses=reached", 0),
("/sw/promoteActivePool/bindList?" + urllib.parse.urlencode({"statuses": "已达标", "busierAccount": "does-not-exist"}), 0),
("/sw/promoteActivePool/bindSpendDetail?id=0", 7),
]
for path, expected in paths:
request = urllib.request.Request(args.base_url + path, headers={"x-token": token})
with urllib.request.urlopen(request, timeout=30) as response:
body = json.load(response)
item = {"method": "GET", "path": path, "http": response.status, "code": body.get("code"),
"msg": body.get("msg"), "passed": response.status == 200 and body.get("code") == expected}
if isinstance(body.get("data"), dict) and "rows" in body["data"]:
item.update(total=body["data"]["total"], available=body["data"].get("available"))
checks.append(item)
print(json.dumps(item, ensure_ascii=False))
report = {"scope": "当前 sw7 运行实例,只读请求;OA 未接入场景明确返回 available=false。完整 OA 与流水数据通过两个隔离数据库的 TCP HTTP 测试。",
"checks": checks, "passed": all(item["passed"] for item in checks)}
args.output.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
if not report["passed"]:
raise SystemExit(1)
if __name__ == "__main__":
main()
+75
View File
@@ -0,0 +1,75 @@
// 核对渠道激活页面的真实渲染;OA 数据与流水查询使用受控响应。
const fs = require('node:fs/promises')
const path = require('node:path')
const assert = require('node:assert/strict')
const { chromium } = require(process.env.SW_PLAYWRIGHT_MODULE || 'playwright')
;(async () => {
const token = (await fs.readFile(path.join(process.env.TEMP, 'sw-kra-http-test-token'), 'utf8')).trim()
const browser = await chromium.launch({ channel: 'chrome', headless: true })
try {
const context = await browser.newContext({ viewport: { width: 1500, height: 1000 } })
await context.addInitScript(value => localStorage.setItem('token', value), token)
const page = await context.newPage()
const errors = []
const queries = []
let unavailable = false
const rows = ['pending', 'in_progress', 'reached', 'rejected', 'unbound'].map((status, i) => ({
id: String(i + 1), promoteAccount: `测试渠道-${i + 1}`, busierAccount: '测试商务', platformName: 'lx', platformTitle: '龙翔',
bindAt: ['pending', 'rejected'].includes(status) ? null : '2026-11-01 00:00:00',
unbindAt: status === 'unbound' ? '2026-11-03 12:00:00' : null,
endAt: ['reached', 'unbound'].includes(status) ? '2026-11-03 12:00:00' : null,
accumAmount: '30.30', status, statusText: { pending: '待审核', in_progress: '进行中', reached: '已达标', rejected: '已驳回', unbound: '已解绑' }[status]
}))
page.on('pageerror', error => errors.push(error.message))
await page.route('http://127.0.0.1:8080/api/**', async route => {
const request = route.request()
const url = new URL(request.url())
const api = url.pathname.slice(4)
if (api === '/sw/promoteActivePool/bindList') {
queries.push(url.search)
return route.fulfill({ json: { code: 0, data: { rows: unavailable ? [] : rows, total: unavailable ? 0 : rows.length, available: !unavailable } } })
}
if (api === '/sw/promoteActivePool/bindSpendDetail') {
if (url.searchParams.get('id') === '1') return route.fulfill({ json: { code: 7, msg: '审核通过后可查看', data: {} } })
const row = rows.find(item => item.id === url.searchParams.get('id'))
return route.fulfill({ json: { code: 0, data: { promoteAccount: row.promoteAccount, bindAt: row.bindAt, endAt: row.endAt, list: [{ platformTitle: '龙翔', gameName: '测试游戏', totalAmount: '9007199254740993.10' }], totalAmount: '9007199254740993.10' } } })
}
const response = await route.fetch({ url: 'http://127.0.0.1:18000' + api + url.search, headers: { ...request.headers(), 'x-token': token } })
return route.fulfill({ response })
})
await page.goto('http://127.0.0.1:8080/#/layout/sw-BusMgmt/ChannelActivationList')
await page.getByText('测试渠道-1', { exact: true }).waitFor()
const row = id => page.locator('.el-table__body-wrapper tr').filter({ hasText: `测试渠道-${id}` })
assert.equal(await row(4).getByRole('button', { name: '流水明细', exact: true }).count(), 0)
for (const id of [1, 2, 3, 5]) assert.equal(await row(id).getByRole('button', { name: '流水明细', exact: true }).count(), 1)
const dialog = page.getByRole('dialog', { name: '流水明细', exact: true })
await row(3).getByRole('button', { name: '流水明细', exact: true }).click()
await dialog.getByText('测试游戏', { exact: true }).waitFor()
await dialog.getByText('2026-11-01 至 2026-11-03', { exact: true }).waitFor()
assert.equal(await dialog.getByText('¥9,007,199,254,740,993.10', { exact: true }).count(), 2)
await dialog.locator('.el-loading-mask').waitFor({ state: 'hidden' })
await page.screenshot({ path: path.join(process.env.TEMP, 'sw-activation-flow.png'), animations: 'disabled' })
await dialog.getByRole('button', { name: '关闭', exact: true }).click()
await dialog.waitFor({ state: 'hidden' })
await row(1).getByRole('button', { name: '流水明细', exact: true }).click()
await dialog.getByText('审核通过后可查看', { exact: true }).waitFor()
assert.equal(await dialog.getByText('绑定期间累计流水:', { exact: false }).count(), 0)
await dialog.getByRole('button', { name: '关闭', exact: true }).click()
await dialog.waitFor({ state: 'hidden' })
const form = page.locator('.kra-search-box')
await form.getByPlaceholder('渠道账号', { exact: true }).fill(' 渠道 ')
await form.getByRole('button', { name: '查询', exact: true }).click()
await page.waitForResponse(response => response.url().includes('/sw/promoteActivePool/bindList') && response.url().includes('promoteAccount='))
assert.equal(new URLSearchParams(queries.at(-1)).get('promoteAccount'), '渠道')
unavailable = true
await form.getByRole('button', { name: '重置', exact: true }).click()
await page.getByText('OA 渠道激活数据源尚未接入或暂不可用。', { exact: true }).waitFor()
assert.equal(new URLSearchParams(queries.at(-1)).get('promoteAccount'), '')
assert.deepEqual(errors, [])
const result = { passed: true, rejectedHidesFlow: true, pendingShowsReasonWithoutFakeTotal: true, reachedCutoffDisplayed: true, exactLargeAmount: true, filtersAndReset: true, unavailableSourceNotice: true, pageErrors: errors }
await fs.writeFile('docs/sw6-to-kra/activation-page-2026-11-03.json', JSON.stringify({ method: '真实 Chrome,受控 OA 和流水响应,无写入', ...result }, null, 2) + '\n')
console.log(JSON.stringify(result))
await context.close()
} finally { await browser.close() }
})().catch(error => { console.error(error); process.exitCode = 1 })