feat(consignment): 苏尔南寄卖接入打手端押金履约

打手可直接提报寄卖,关联 worker 与履约押金后指派交枪;后台去掉旧收集链接管理,提报审核与库存/工单流程对齐接单平台。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yml2213
2026-09-15 16:00:33 +08:00
co-authored by Cursor
parent 7672360875
commit 4a6215e816
23 changed files with 2218 additions and 677 deletions
@@ -32,6 +32,10 @@ export type ConsignmentInventoryRow = {
shop_name: string
source_type: 'manual' | 'collection_link' | 'recycle'
source_submission_id: string | number | null
worker_id?: string | number | null
worker_name?: string
worker_phone?: string
deposit_amount_fen?: number
inbound_at: string
consumed_at: string | null
created_at: string
@@ -83,6 +87,10 @@ export type ConsignmentSubmissionRow = {
content_json: string | Record<string, unknown>
screenshots_json: string | unknown[]
asking_price_fen: number
worker_id?: string | number | null
worker_name?: string
worker_phone?: string
deposit_amount_fen?: number
status: 'pending_review' | 'approved' | 'rejected'
review_note: string
reviewer_name: string
@@ -121,6 +129,7 @@ export async function listConsignmentInventories(filters: {
series?: string | undefined
diamondLevel?: number | undefined
allowMatching?: boolean | undefined
workerId?: number | undefined
keyword?: string | undefined
page?: number | undefined
pageSize?: number | undefined
@@ -132,6 +141,10 @@ export async function listConsignmentInventories(filters: {
values.push(filters.status)
conditions.push(`ci.status = $${values.length}`)
}
if (filters.workerId) {
values.push(filters.workerId)
conditions.push(`ci.worker_id = $${values.length}`)
}
if (filters.buyerName) {
values.push(filters.buyerName)
conditions.push(`ci.buyer_name = $${values.length}`)
@@ -329,6 +342,10 @@ export async function createConsignmentInventory(input: {
allowMatching?: boolean
sourceType?: 'manual' | 'collection_link' | 'recycle'
sourceSubmissionId?: number | null
workerId?: number | null
workerName?: string
workerPhone?: string
depositAmountFen?: number
now: string
}): Promise<ConsignmentInventoryRow> {
const sql = `
@@ -338,14 +355,16 @@ export async function createConsignmentInventory(input: {
inbound_batch, seller_contact, seller_game_id, seller_payment_info,
seller_phone, credentials_json, screenshots_json, remark,
allow_matching, status, allocation_status, source_type,
source_submission_id, inbound_at, created_at, updated_at
source_submission_id, worker_id, worker_name, worker_phone, deposit_amount_fen,
inbound_at, created_at, updated_at
) VALUES (
$1, $2, $3, $4, $5, $6,
$7, $8, $9, $10, $11,
$12, $13, $14, $15,
$16, $17::jsonb, $18::jsonb, $19,
$20, 'in_stock', '待安排', $21,
$22, $23, $23, $23
$22, $23, $24, $25, $26,
$27, $27, $27
)
RETURNING *
`
@@ -372,6 +391,10 @@ export async function createConsignmentInventory(input: {
input.allowMatching !== false,
input.sourceType || 'manual',
input.sourceSubmissionId || null,
input.workerId || null,
input.workerName || '',
input.workerPhone || '',
input.depositAmountFen || 0,
input.now,
]
const res = await query<ConsignmentInventoryRow>(sql, values)
@@ -400,6 +423,10 @@ export async function updateConsignmentInventory(
allowMatching?: boolean | undefined
status?: 'in_stock' | 'consumed' | 'archived' | undefined
allocationStatus?: string | undefined
workerId?: number | null | undefined
workerName?: string | undefined
workerPhone?: string | undefined
depositAmountFen?: number | undefined
now: string
},
): Promise<ConsignmentInventoryRow | null> {
@@ -482,6 +509,22 @@ export async function updateConsignmentInventory(
values.push(input.allocationStatus)
updates.push(`allocation_status = $${values.length}`)
}
if (input.workerId !== undefined) {
values.push(input.workerId)
updates.push(`worker_id = $${values.length}`)
}
if (input.workerName !== undefined) {
values.push(input.workerName)
updates.push(`worker_name = $${values.length}`)
}
if (input.workerPhone !== undefined) {
values.push(input.workerPhone)
updates.push(`worker_phone = $${values.length}`)
}
if (input.depositAmountFen !== undefined) {
values.push(input.depositAmountFen)
updates.push(`deposit_amount_fen = $${values.length}`)
}
if (updates.length === 0) return getConsignmentInventoryById(id)
@@ -681,6 +724,7 @@ export async function updateConsignmentCollectLink(
export async function listConsignmentSubmissions(filters: {
status?: string | undefined
linkId?: number | undefined
workerId?: number | undefined
keyword?: string | undefined
page?: number | undefined
pageSize?: number | undefined
@@ -696,6 +740,10 @@ export async function listConsignmentSubmissions(filters: {
values.push(filters.linkId)
conditions.push(`cs.link_id = $${values.length}`)
}
if (filters.workerId) {
values.push(filters.workerId)
conditions.push(`cs.worker_id = $${values.length}`)
}
if (filters.keyword) {
values.push(`%${filters.keyword.trim()}%`)
conditions.push(
@@ -765,6 +813,10 @@ export async function createConsignmentSubmission(input: {
contentJson?: Record<string, unknown>
screenshotsJson?: unknown[]
askingPriceFen?: number
workerId?: number | null
workerName?: string
workerPhone?: string
depositAmountFen?: number
now: string
}): Promise<ConsignmentSubmissionRow> {
const sql = `
@@ -773,13 +825,15 @@ export async function createConsignmentSubmission(input: {
system, server_zone, series, diamond_level, brilliance_count,
seller_game_id, seller_payment_info, seller_phone, contact_info,
content_json, screenshots_json, asking_price_fen,
worker_id, worker_name, worker_phone, deposit_amount_fen,
status, created_at, updated_at
) VALUES (
$1, $2, $3, $4, $5,
$6, $7, $8, $9, $10,
$11, $12, $13, $14,
$15::jsonb, $16::jsonb, $17,
'pending_review', $18, $18
$18, $19, $20, $21,
'pending_review', $22, $22
)
RETURNING *
`
@@ -801,6 +855,10 @@ export async function createConsignmentSubmission(input: {
toJsonString(input.contentJson || {}),
toJsonString(input.screenshotsJson || []),
input.askingPriceFen || 0,
input.workerId || null,
input.workerName || '',
input.workerPhone || '',
input.depositAmountFen || 0,
input.now,
])
return res.rows[0]!
@@ -852,6 +910,10 @@ export async function approveConsignmentSubmissionWithInbound(input: {
credentialsJson?: Record<string, unknown> | undefined
screenshotsJson?: unknown[] | undefined
reviewNote?: string | undefined
workerId?: number | null | undefined
workerName?: string | undefined
workerPhone?: string | undefined
depositAmountFen?: number | undefined
now: string
}): Promise<{ submission: ConsignmentSubmissionRow; inventory: ConsignmentInventoryRow }> {
return withTransaction(async (client: PoolClient) => {
@@ -863,6 +925,16 @@ export async function approveConsignmentSubmissionWithInbound(input: {
if (!submission) throw new Error('提报单不存在')
if (submission.status !== 'pending_review') throw new Error('提报单已被处理')
const workerId = input.workerId !== undefined ? input.workerId : submission.worker_id || null
const workerName =
input.workerName !== undefined ? input.workerName : submission.worker_name || ''
const workerPhone =
input.workerPhone !== undefined ? input.workerPhone : submission.worker_phone || ''
const depositAmountFen =
input.depositAmountFen !== undefined
? input.depositAmountFen
: submission.deposit_amount_fen || 0
const invSql = `
INSERT INTO consignment_inventories (
inventory_no, game_name, category_id, item_name, system, server_zone,
@@ -870,14 +942,16 @@ export async function approveConsignmentSubmissionWithInbound(input: {
inbound_batch, seller_contact, seller_game_id, seller_payment_info,
seller_phone, credentials_json, screenshots_json, remark,
allow_matching, status, allocation_status, source_type,
source_submission_id, inbound_at, created_at, updated_at
source_submission_id, worker_id, worker_name, worker_phone, deposit_amount_fen,
inbound_at, created_at, updated_at
) VALUES (
$1, $2, $3, $4, $5, $6,
$7, $8, $9, $10, $11,
$12, $13, $14, $15,
$16, $17::jsonb, $18::jsonb, $19,
TRUE, 'in_stock', '待安排', 'collection_link',
$20, $21, $21, $21
$20, $21, $22, $23, $24,
$25, $25, $25
)
RETURNING *
`
@@ -902,6 +976,10 @@ export async function approveConsignmentSubmissionWithInbound(input: {
toJsonString(input.screenshotsJson || submission.screenshots_json || []),
input.reviewNote || '',
submission.id,
workerId,
workerName,
workerPhone,
depositAmountFen,
input.now,
]
const invRes = await client.query<ConsignmentInventoryRow>(invSql, invValues)
@@ -914,15 +992,23 @@ export async function approveConsignmentSubmissionWithInbound(input: {
result_inventory_id = $1,
reviewer_name = $2,
review_note = $3,
reviewed_at = $4,
updated_at = $4
WHERE id = $5
worker_id = COALESCE($4, worker_id),
worker_name = COALESCE($5, worker_name),
worker_phone = COALESCE($6, worker_phone),
deposit_amount_fen = COALESCE($7, deposit_amount_fen),
reviewed_at = $8,
updated_at = $8
WHERE id = $9
RETURNING *
`
const updateSubRes = await client.query<ConsignmentSubmissionRow>(updateSubSql, [
inventory.id,
input.buyerName,
input.reviewNote || '',
workerId,
workerName,
workerPhone,
depositAmountFen,
input.now,
submission.id,
])