feat(cost-center): 统一接单模板成本并自动同步商品
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import type { PoolClient } from 'pg'
|
||||
|
||||
import { query, withTransaction } from '../../db/client.js'
|
||||
import { toPositiveInteger } from './shared.js'
|
||||
import {
|
||||
@@ -369,8 +371,10 @@ export async function upsertWorkProductRule(input: {
|
||||
matchJson?: string
|
||||
sortOrder: number
|
||||
now: string
|
||||
client?: Pick<PoolClient, 'query'>
|
||||
}): Promise<WorkProductRuleRow | null> {
|
||||
const result = await query<WorkProductRuleRow>(
|
||||
const db = input.client || { query }
|
||||
const result = await db.query<WorkProductRuleRow>(
|
||||
`
|
||||
INSERT INTO work_product_rules (
|
||||
rule_key, provider, platform, shop_id, sku_code, product_name,
|
||||
@@ -454,5 +458,10 @@ export async function upsertWorkProductRule(input: {
|
||||
input.now,
|
||||
],
|
||||
)
|
||||
return getWorkProductRuleByKey(result.rows[0]?.rule_key || input.ruleKey)
|
||||
const ruleKey = result.rows[0]?.rule_key || input.ruleKey
|
||||
const selected = await db.query<WorkProductRuleRow>(
|
||||
`${WORK_PRODUCT_RULE_SELECT} WHERE wpr.rule_key = $1 LIMIT 1`,
|
||||
[ruleKey],
|
||||
)
|
||||
return selected.rows[0] || null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user