新增打手改昵称卡功能默认一张且一年冷却
This commit is contained in:
@@ -38,6 +38,8 @@ export type WorkerUserRow = {
|
||||
pending_unfreeze_amount?: number
|
||||
total_credited_amount?: number
|
||||
total_settled_amount?: number
|
||||
rename_cards?: number
|
||||
last_renamed_at?: string | null
|
||||
}
|
||||
|
||||
export type WorkerSessionRow = {
|
||||
|
||||
@@ -325,3 +325,28 @@ function buildWorkerUserWhere({
|
||||
params,
|
||||
}
|
||||
}
|
||||
|
||||
/** 消耗一张改名卡并更新昵称;条件更新保证并发下不会超发。 */
|
||||
export async function consumeWorkerRenameCard(input: {
|
||||
workerId: number
|
||||
displayName: string
|
||||
now: string
|
||||
}): Promise<WorkerUserRow | null> {
|
||||
const result = await query<{ id: number }>(
|
||||
`
|
||||
UPDATE worker_users
|
||||
SET
|
||||
display_name = $1,
|
||||
rename_cards = rename_cards - 1,
|
||||
last_renamed_at = $2,
|
||||
updated_at = $2
|
||||
WHERE id = $3 AND rename_cards > 0
|
||||
RETURNING id
|
||||
`,
|
||||
[input.displayName, input.now, input.workerId],
|
||||
)
|
||||
if (!result.rows[0]) {
|
||||
return null
|
||||
}
|
||||
return getWorkerUserById(input.workerId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user