feat(worker-platform): add worker withdrawal blacklist and admin actions

This commit is contained in:
yml2213
2026-09-13 11:32:42 +08:00
parent 18ac95ca27
commit 061a5d897f
15 changed files with 405 additions and 7 deletions
@@ -42,6 +42,9 @@ export type WorkerUserRow = {
total_settled_amount?: number
rename_cards?: number
last_renamed_at?: string | null
is_withdrawal_blacklisted?: boolean
withdrawal_blacklist_reason?: string | null
withdrawal_blacklisted_at?: string | null
}
export type WorkerUserStatistics = {
@@ -453,6 +456,8 @@ export type ListInput = {
/** 后台待验收筛选:普通单按接单人,拼单按参与打手等级。 */
workerLevelIds?: number[]
categoryId?: number
/** 后台打手列表按提现黑名单筛选。 */
isWithdrawalBlacklisted?: boolean | null | undefined
workerSharingId?: number
/** 大厅候选集合的总展示上限;筛选与分页在候选集合内执行。 */
hallCandidateLimit?: number
@@ -240,6 +240,7 @@ export async function listWorkerUsers({
workerType = '',
workerId = 0,
levelId = 0,
isWithdrawalBlacklisted,
}: ListInput = {}): Promise<{ items: WorkerUserRow[]; total: number }> {
const { whereClause, params } = buildWorkerUserWhere({
status,
@@ -247,6 +248,7 @@ export async function listWorkerUsers({
workerType,
workerId,
levelId,
isWithdrawalBlacklisted,
})
const totalResult = await query<{ total: number }>(
`SELECT COUNT(*)::int AS total FROM worker_users wu ${whereClause}`,
@@ -267,7 +269,10 @@ export async function listWorkerUsers({
/** 按筛选条件汇总打手,统计范围不受当前分页影响。 */
export async function getWorkerUserStatistics(
input: Pick<ListInput, 'status' | 'keyword' | 'workerType' | 'workerId' | 'levelId'> = {},
input: Pick<
ListInput,
'status' | 'keyword' | 'workerType' | 'workerId' | 'levelId' | 'isWithdrawalBlacklisted'
> = {},
): Promise<WorkerUserStatistics> {
const { whereClause, params } = buildWorkerUserWhere(input)
const statisticsResult = await query<{
@@ -373,13 +378,17 @@ async function getWorkerUserByIdWithClient(
return result.rows[0] || null
}
function buildWorkerUserWhere({
export function buildWorkerUserWhere({
status = '',
keyword = '',
workerType = '',
workerId = 0,
levelId = 0,
}: Pick<ListInput, 'status' | 'keyword' | 'workerType' | 'workerId' | 'levelId'>) {
isWithdrawalBlacklisted,
}: Pick<
ListInput,
'status' | 'keyword' | 'workerType' | 'workerId' | 'levelId' | 'isWithdrawalBlacklisted'
>) {
const filters: string[] = []
const params: unknown[] = []
if (status) {
@@ -404,12 +413,47 @@ function buildWorkerUserWhere({
params.push(levelId)
filters.push(`wu.level_id = $${params.length}`)
}
if (isWithdrawalBlacklisted !== undefined && isWithdrawalBlacklisted !== null) {
params.push(Boolean(isWithdrawalBlacklisted))
filters.push(`wu.is_withdrawal_blacklisted = $${params.length}`)
}
return {
whereClause: filters.length > 0 ? `WHERE ${filters.join(' AND ')}` : '',
params,
}
}
export async function updateWorkerWithdrawalBlacklist(input: {
workerId: number | string
isWithdrawalBlacklisted: boolean
reason: string
now: string
}): Promise<WorkerUserRow | null> {
const result = await query<{ id: number }>(
`
UPDATE worker_users
SET
is_withdrawal_blacklisted = $1,
withdrawal_blacklist_reason = $2,
withdrawal_blacklisted_at = $3,
updated_at = $4
WHERE id = $5
RETURNING id
`,
[
input.isWithdrawalBlacklisted,
input.isWithdrawalBlacklisted ? input.reason : null,
input.isWithdrawalBlacklisted ? input.now : null,
input.now,
Number(input.workerId),
],
)
if (!result.rows[0]) {
return null
}
return getWorkerUserById(input.workerId)
}
/** 消耗一张改名卡并更新昵称;条件更新保证并发下不会超发。 */
export async function consumeWorkerRenameCard(input: {
workerId: number