前面的ok了, 绑定与角色

This commit is contained in:
yml
2026-05-03 20:58:18 +08:00
parent dd2192b6ae
commit 0f0253bffe
30 changed files with 1900 additions and 409 deletions
@@ -42,6 +42,9 @@ export async function syncDeliveryTasksForOrder(order, orderItems) {
const primaryRequirement = requirements.find((requirement) => requirement.is_required !== false) || requirements[0] || null
const quantity = Math.max(1, Number(item.quantity || 1))
const fulfillmentConfig = parseJsonObject(profile.config_json)
const kuaishouShopConfig = fulfillmentConfig.kuaishouShop && typeof fulfillmentConfig.kuaishouShop === 'object'
? fulfillmentConfig.kuaishouShop
: {}
for (let index = 0; index < quantity; index += 1) {
const createdAt = nowIso()
@@ -93,8 +96,14 @@ export async function syncDeliveryTasksForOrder(order, orderItems) {
internalSkuName: item.sku_name,
ticket: {
code: '',
status: 'pending',
capturedAt: null,
capturedBy: null,
verifiedAt: null,
oid: '',
formToken: '',
leftCount: 0,
goodsTitle: '',
},
binding: {
prepareStatus: 'pending',
@@ -131,8 +140,10 @@ export async function syncDeliveryTasksForOrder(order, orderItems) {
},
consume: {
status: 'pending',
shopId: String(fulfillmentConfig.kuaishouConsume?.shopId || '').trim(),
shopId: String(fulfillmentConfig.kuaishouConsume?.shopId || kuaishouShopConfig.shopId || '').trim(),
autoConsumeEnabled: fulfillmentConfig.kuaishouConsume?.autoConsumeAfterDispatch === true,
consumedAt: null,
errorMessage: '',
},
notes: String(fulfillmentConfig.notes || '').trim(),
}
@@ -56,6 +56,8 @@ function normalizeOrderFulfillmentBinding(rawValue) {
const provider = String(rawValue.provider || 'agiso').trim() || 'agiso'
const platform = String(rawValue.platform || '').trim()
const shopId = String(rawValue.shopId || '').trim()
const shopName = String(rawValue.shopName || '').trim()
const khhaoShopId = String(rawValue.khhaoShopId || '').trim()
const skuCode = String(rawValue.skuCode || '').trim()
const skuName = String(rawValue.skuName || '').trim()
const profileKey = String(rawValue.profileKey || '').trim() || 'manual_review'
@@ -72,6 +74,8 @@ function normalizeOrderFulfillmentBinding(rawValue) {
provider,
platform,
shopId,
shopName,
khhaoShopId,
skuCode,
skuName,
profileKey,
@@ -1,4 +1,9 @@
import { createOrder, findOrderByPlatformOrderId, updateOrder } from '../../repositories/order-repo.js'
import {
createOrder,
findOrderByPlatformOrderId,
findOrderByPlatformOrderIdCandidates,
updateOrder,
} from '../../repositories/order-repo.js'
import { replaceOrderItems } from '../../repositories/order-item-repo.js'
import { getClaimTokenById } from '../../repositories/claim-token-repo.js'
import { buildClaimUrl } from '../claim/claim-service.js'
@@ -14,12 +19,18 @@ export async function upsertOrderFromWebhook(event) {
export async function upsertOrderFromSource(event, { sourceLabel = 'source' } = {}) {
const now = nowIso()
const existing = await findOrderByPlatformOrderId({
const exactExisting = await findOrderByPlatformOrderId({
provider: event.provider,
platform: event.platform,
shopId: event.shopId,
platformOrderId: event.platformOrderId,
})
const existing = exactExisting || await findOrderByPlatformOrderIdCandidates({
provider: event.provider,
platform: event.platform,
shopIds: resolveEventShopIdCandidates(event),
platformOrderId: event.platformOrderId,
})
logWebhook('[order-service]', `开始处理 ${sourceLabel} 订单 upsert`, {
provider: event.provider,
@@ -155,6 +166,13 @@ export async function upsertOrderFromSource(event, { sourceLabel = 'source' } =
}
}
function resolveEventShopIdCandidates(event) {
return [...new Set([
String(event?.shopId || '').trim(),
...(Array.isArray(event?.shopIdAliases) ? event.shopIdAliases : []).map((item) => String(item || '').trim()),
].filter(Boolean))]
}
const ORDER_STATUS_PRIORITY = {
created: 0,
paid: 1,