fix(finance): 客服只能使用自己的备用金账户
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user