fix(finance): 客服只能使用自己的备用金账户

This commit is contained in:
yml2213
2026-10-23 11:44:04 +08:00
parent 2aeb789e20
commit a7f60414a4
6 changed files with 126 additions and 57 deletions
@@ -1507,19 +1507,24 @@ export async function createAdminFundReturn(payload: JsonObject, session: AdminS
})
}
export async function getOwnAgentAccountId(userId: number): Promise<number> {
const own = await query<FundAccountRow>(
"SELECT * FROM fund_accounts WHERE owner_admin_user_id = $1 AND account_type = 'agent' AND status <> 'closed' ORDER BY id LIMIT 1",
[userId],
)
return own.rows[0] ? Number(own.rows[0].id) : 0
}
async function resolveAgentAccountId(payload: JsonObject, session: AdminSession): Promise<number> {
if (session.role === 'support') {
const own = await query<FundAccountRow>(
"SELECT * FROM fund_accounts WHERE owner_admin_user_id = $1 AND account_type = 'agent' LIMIT 1",
[session.userId],
)
if (!own.rows[0]) {
const ownAccountId = await getOwnAgentAccountId(session.userId)
if (!ownAccountId) {
throw createHttpError('当前账号还没有备用金账户', {
statusCode: 404,
errorCode: 'fund_agent_account_not_found',
})
}
return Number(own.rows[0].id)
return ownAccountId
}
const accountId = toId(payload.agentAccountId)