feat:寄卖增加对接客服,db脚本迁移修复

This commit is contained in:
2026-10-27 13:56:08 +08:00
parent 622bd779dd
commit a53321ef30
16 changed files with 43 additions and 225 deletions
@@ -9,8 +9,6 @@ import { query } from '../../db/client.js'
export type ConsignmentContactRow = {
id: string | number
name: string
phone: string
wechat: string
note: string
enabled: boolean
sort_order: number
@@ -31,9 +29,7 @@ export async function listConsignmentContacts(filters: {
}
if (filters.keyword) {
values.push(`%${filters.keyword.trim()}%`)
conditions.push(
`(name ILIKE $${values.length} OR phone ILIKE $${values.length} OR wechat ILIKE $${values.length} OR note ILIKE $${values.length})`,
)
conditions.push(`(name ILIKE $${values.length} OR note ILIKE $${values.length})`)
}
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''
@@ -76,8 +72,6 @@ export async function findConsignmentContactByName(
export async function createConsignmentContact(input: {
name: string
phone?: string | undefined
wechat?: string | undefined
note?: string | undefined
enabled?: boolean | undefined
sortOrder?: number | undefined
@@ -85,18 +79,10 @@ export async function createConsignmentContact(input: {
}): Promise<ConsignmentContactRow> {
const res = await query<ConsignmentContactRow>(
`INSERT INTO consignment_contact_supporters (
name, phone, wechat, note, enabled, sort_order, created_at, updated_at
) VALUES ($1, $2, $3, $4, $5, $6, $7, $7)
name, note, enabled, sort_order, created_at, updated_at
) VALUES ($1, $2, $3, $4, $5, $5)
RETURNING *`,
[
input.name,
input.phone || '',
input.wechat || '',
input.note || '',
input.enabled !== false,
input.sortOrder || 0,
input.now,
],
[input.name, input.note || '', input.enabled !== false, input.sortOrder || 0, input.now],
)
return res.rows[0]!
}
@@ -105,8 +91,6 @@ export async function updateConsignmentContact(
id: number | string,
input: {
name?: string | undefined
phone?: string | undefined
wechat?: string | undefined
note?: string | undefined
sortOrder?: number | undefined
now: string
@@ -119,14 +103,6 @@ export async function updateConsignmentContact(
values.push(input.name)
updates.push(`name = $${values.length}`)
}
if (input.phone !== undefined) {
values.push(input.phone)
updates.push(`phone = $${values.length}`)
}
if (input.wechat !== undefined) {
values.push(input.wechat)
updates.push(`wechat = $${values.length}`)
}
if (input.note !== undefined) {
values.push(input.note)
updates.push(`note = $${values.length}`)
@@ -53,8 +53,6 @@ export type ConsignmentInventoryRow = {
/** 对接客服(发布/审核入库时选定,用于提成归属与联系) */
contact_supporter_id?: string | number | null
contact_supporter_name?: string
contact_supporter_phone?: string
contact_supporter_wechat?: string
inbound_at: string
consumed_at: string | null
created_at: string
@@ -87,8 +85,6 @@ export type ConsignmentSubmissionRow = {
/** 对接客服(发布时选定,用于提成归属与联系) */
contact_supporter_id?: string | number | null
contact_supporter_name?: string
contact_supporter_phone?: string
contact_supporter_wechat?: string
status: 'pending_review' | 'approved' | 'rejected'
review_note: string
reviewer_name: string
@@ -213,9 +209,7 @@ export async function listConsignmentInventories(filters: {
wo.friend_added_at AS gift_friend_added_at,
wo.material_json AS bound_work_order_material_json,
wo.requirement_json AS bound_work_order_requirement_json,
ccs.name AS contact_supporter_name,
ccs.phone AS contact_supporter_phone,
ccs.wechat AS contact_supporter_wechat
ccs.name AS contact_supporter_name
FROM consignment_inventories ci
LEFT JOIN work_categories wc ON wc.id = ci.category_id
LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id
@@ -336,9 +330,7 @@ export async function getConsignmentInventoryById(
wo.friend_added_at AS gift_friend_added_at,
wo.material_json AS bound_work_order_material_json,
wo.requirement_json AS bound_work_order_requirement_json,
ccs.name AS contact_supporter_name,
ccs.phone AS contact_supporter_phone,
ccs.wechat AS contact_supporter_wechat
ccs.name AS contact_supporter_name
FROM consignment_inventories ci
LEFT JOIN work_categories wc ON wc.id = ci.category_id
LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id
@@ -363,9 +355,7 @@ export async function listConsignmentInventoriesByIds(
wc.name AS category_name,
cs.submission_no AS source_submission_no,
cs.screenshots_json AS submission_screenshots_json,
ccs.name AS contact_supporter_name,
ccs.phone AS contact_supporter_phone,
ccs.wechat AS contact_supporter_wechat
ccs.name AS contact_supporter_name
FROM consignment_inventories ci
LEFT JOIN work_categories wc ON wc.id = ci.category_id
LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id
@@ -911,9 +901,7 @@ export async function listActiveConsignmentInventoriesForMatching(options?: {
SELECT
ci.*,
cs.submission_no AS source_submission_no,
ccs.name AS contact_supporter_name,
ccs.phone AS contact_supporter_phone,
ccs.wechat AS contact_supporter_wechat
ccs.name AS contact_supporter_name
FROM consignment_inventories ci
LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id
LEFT JOIN consignment_contact_supporters ccs ON ccs.id = ci.contact_supporter_id
@@ -969,9 +957,7 @@ export async function listConsignmentSubmissions(filters: {
wo.acceptance_json AS gift_evidence_json,
wo.work_order_no AS gift_work_order_no,
wo.status AS gift_work_order_status,
ccs.name AS contact_supporter_name,
ccs.phone AS contact_supporter_phone,
ccs.wechat AS contact_supporter_wechat
ccs.name AS contact_supporter_name
FROM consignment_submissions cs
LEFT JOIN work_categories wc ON wc.id = cs.category_id
LEFT JOIN consignment_contact_supporters ccs ON ccs.id = cs.contact_supporter_id
@@ -1191,9 +1177,7 @@ export async function listConsignmentSubmissionsByIds(
wo.acceptance_json AS gift_evidence_json,
wo.work_order_no AS gift_work_order_no,
wo.status AS gift_work_order_status,
ccs.name AS contact_supporter_name,
ccs.phone AS contact_supporter_phone,
ccs.wechat AS contact_supporter_wechat
ccs.name AS contact_supporter_name
FROM consignment_submissions cs
LEFT JOIN work_categories wc ON wc.id = cs.category_id
LEFT JOIN consignment_contact_supporters ccs ON ccs.id = cs.contact_supporter_id
@@ -1222,9 +1206,7 @@ export async function getConsignmentInventoryBySubmissionId(
ci.*,
wc.name AS category_name,
cs.submission_no AS source_submission_no,
ccs.name AS contact_supporter_name,
ccs.phone AS contact_supporter_phone,
ccs.wechat AS contact_supporter_wechat
ccs.name AS contact_supporter_name
FROM consignment_inventories ci
LEFT JOIN work_categories wc ON wc.id = ci.category_id
LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id
@@ -1248,9 +1230,7 @@ export async function getConsignmentSubmissionById(
wo.acceptance_json AS gift_evidence_json,
wo.work_order_no AS gift_work_order_no,
wo.status AS gift_work_order_status,
ccs.name AS contact_supporter_name,
ccs.phone AS contact_supporter_phone,
ccs.wechat AS contact_supporter_wechat
ccs.name AS contact_supporter_name
FROM consignment_submissions cs
LEFT JOIN work_categories wc ON wc.id = cs.category_id
LEFT JOIN consignment_contact_supporters ccs ON ccs.id = cs.contact_supporter_id