完善接单平台上传与物品规则
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
import { query } from '../../../db/client.js'
|
||||
import { createOrder, findOrderByPlatformOrderId, getOrderById, updateOrder } from '../../../repositories/order-repo.js'
|
||||
import { listOrderItemsByOrderId, replaceOrderItems } from '../../../repositories/order-item-repo.js'
|
||||
import {
|
||||
createOrder,
|
||||
findOrderByPlatformOrderId,
|
||||
getOrderById,
|
||||
updateOrder,
|
||||
} from '../../../repositories/order-repo.js'
|
||||
import {
|
||||
listOrderItemsByOrderId,
|
||||
replaceOrderItems,
|
||||
} from '../../../repositories/order-item-repo.js'
|
||||
import { listTasksByOrderId } from '../../../repositories/task-repo.js'
|
||||
import { upsertOrderFromSource } from '../../order/order-service.js'
|
||||
import { syncWorkerOrdersForSourceOrder } from '../../worker-platform/worker-platform-service.js'
|
||||
import { bindKuaishouIndustryVouchersToOrderTasks } from '../kuaishou-industry/voucher-binding-service.js'
|
||||
import { asJsonObject, type JsonObject } from '../../../types/json.js'
|
||||
import {
|
||||
OPEN_91_PLATFORM,
|
||||
OPEN_91_PROVIDER,
|
||||
} from '../../open-91/config.js'
|
||||
import { asJsonObject, type JsonObject } from '../../../types/json.js'
|
||||
import { OPEN_91_PLATFORM, OPEN_91_PROVIDER } from '../../open-91/config.js'
|
||||
import { normalizeOpen91CreatePayload } from '../../open-91/payload.js'
|
||||
import { buildOpen91OutTradeNo } from '../../open-91/response.js'
|
||||
import { createHttpError } from '../../../utils/http.js'
|
||||
@@ -179,6 +185,10 @@ export async function upsertOpen91PendingOrder(payload: JsonObject = {}, config:
|
||||
source: 'open91_pending_order',
|
||||
now,
|
||||
})
|
||||
await syncWorkerOrdersForSourceOrder(order, orderItems, {
|
||||
source: 'open91_pending_order',
|
||||
autoOnly: true,
|
||||
})
|
||||
|
||||
return {
|
||||
order,
|
||||
@@ -243,14 +253,15 @@ export async function failOpen91Order(orderId: string | number, reason = '') {
|
||||
}
|
||||
}
|
||||
|
||||
export async function listOpen91Orders({ page = 1, pageSize = 20, status = 'pending_config' } = {}) {
|
||||
export async function listOpen91Orders({
|
||||
page = 1,
|
||||
pageSize = 20,
|
||||
status = 'pending_config',
|
||||
} = {}) {
|
||||
const normalizedPage = Math.max(1, Number(page) || 1)
|
||||
const normalizedPageSize = Math.min(100, Math.max(1, Number(pageSize) || 20))
|
||||
const normalizedStatus = String(status || 'pending_config').trim()
|
||||
const filters = [
|
||||
'o.provider = $1',
|
||||
'o.platform = $2',
|
||||
]
|
||||
const filters = ['o.provider = $1', 'o.platform = $2']
|
||||
const params: Array<string | number> = [OPEN_91_PROVIDER, OPEN_91_PLATFORM]
|
||||
|
||||
if (normalizedStatus && normalizedStatus !== 'all') {
|
||||
@@ -259,7 +270,10 @@ export async function listOpen91Orders({ page = 1, pageSize = 20, status = 'pend
|
||||
}
|
||||
|
||||
const whereClause = `WHERE ${filters.join(' AND ')}`
|
||||
const totalResult = await query(`SELECT COUNT(*)::int AS total FROM orders o ${whereClause}`, params)
|
||||
const totalResult = await query(
|
||||
`SELECT COUNT(*)::int AS total FROM orders o ${whereClause}`,
|
||||
params,
|
||||
)
|
||||
|
||||
params.push(normalizedPageSize)
|
||||
params.push((normalizedPage - 1) * normalizedPageSize)
|
||||
@@ -320,7 +334,9 @@ function buildOpen91SourceEventFromOrder(order: OrderRow, items: OrderItemRow[]
|
||||
const normalizedItems = Array.isArray(items) ? items : []
|
||||
const eventItems = normalizedItems.map((item: OrderItemRow) => {
|
||||
const snapshot = parseJsonObject(item.item_snapshot_json)
|
||||
const productNo = String(snapshot.productNo || snapshot.externalSkuCode || item.sku_code || '').trim()
|
||||
const productNo = String(
|
||||
snapshot.productNo || snapshot.externalSkuCode || item.sku_code || '',
|
||||
).trim()
|
||||
|
||||
return {
|
||||
itemId: productNo,
|
||||
@@ -339,9 +355,7 @@ function buildOpen91SourceEventFromOrder(order: OrderRow, items: OrderItemRow[]
|
||||
provider: order.provider,
|
||||
platform: order.platform,
|
||||
shopId: OPEN_91_PROVIDER,
|
||||
shopName: String(order.shop_id || '').trim() === OPEN_91_PROVIDER
|
||||
? order.shop_name
|
||||
: '91卡券',
|
||||
shopName: String(order.shop_id || '').trim() === OPEN_91_PROVIDER ? order.shop_name : '91卡券',
|
||||
platformOrderId: order.platform_order_id,
|
||||
orderStatus: 'paid',
|
||||
payStatus: 'paid',
|
||||
@@ -374,7 +388,9 @@ function mapOpen91AdminOrderRow(row: JsonObject) {
|
||||
payStatus: String(row.pay_status || '').trim(),
|
||||
shopId: String(row.shop_id || '').trim(),
|
||||
shopName: String(row.shop_name || '').trim(),
|
||||
productNo: String(firstSnapshot.productNo || firstSnapshot.externalSkuCode || firstItem.skuCode || '').trim(),
|
||||
productNo: String(
|
||||
firstSnapshot.productNo || firstSnapshot.externalSkuCode || firstItem.skuCode || '',
|
||||
).trim(),
|
||||
productName: String(firstSnapshot.externalSkuName || firstItem.skuName || '').trim(),
|
||||
buyNum: Number(firstItem.quantity || 0),
|
||||
taskCount: Number(row.task_count || 0),
|
||||
|
||||
Reference in New Issue
Block a user