前面的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
@@ -1,6 +1,7 @@
// @ts-check
import { parseAmountToFen } from '../../../utils/money.js'
import { resolveKuaishouEticketShopConfig } from '../kuaishou-eticket/source-config-service.js'
export function mapKhhaoOrderPreviewList(items = []) {
return (Array.isArray(items) ? items : []).map((item) => mapKhhaoOrderPreview(item))
@@ -10,11 +11,13 @@ export function mapKhhaoOrderToSourceEvent(item = {}) {
const preview = mapKhhaoOrderPreview(item)
const orderStatus = resolveKhhaoOrderStatus(preview.status)
const payStatus = resolveKhhaoPayStatus(preview.status)
const sourceShopId = String(preview.khhaoShopId || preview.shopId || '').trim()
return {
provider: 'khhao',
platform: preview.platform || 'unknown',
shopId: preview.shopId,
shopId: sourceShopId,
shopIdAliases: uniqueNonEmptyValues([sourceShopId, preview.shopId, ...(preview.shopIdAliases || [])]),
shopName: preview.shopName,
platformOrderId: preview.platformOrderId,
orderStatus,
@@ -46,14 +49,25 @@ export function mapKhhaoOrderPreview(item = {}) {
const raw = isPlainObject(item) ? item : {}
const platform = resolveKhhaoPlatform(raw.pingtai)
const quantity = normalizeQuantity(raw.num)
const internalShopId = String(raw.shopid || '').trim()
const shopName = String(raw.shopName || '').trim()
const resolvedShopIdentity = resolveKhhaoShopIdentity({
platform,
internalShopId,
shopName,
})
return {
provider: 'khhao',
platform,
platformLabel: String(raw.pingtaiName || '').trim(),
platformOrderId: String(raw.ordersn || '').trim(),
shopId: String(raw.shopid || '').trim(),
shopName: String(raw.shopName || '').trim(),
shopId: resolvedShopIdentity.shopId,
kuaishouShopId: resolvedShopIdentity.officialShopId,
shopIdAliases: resolvedShopIdentity.shopIdAliases,
khhaoShopId: internalShopId,
internalShopId,
shopName,
itemId: String(raw.goodid || '').trim(),
itemTitle: String(raw.goodName || '').trim(),
skuCode: String(raw.sku || '').trim(),
@@ -66,6 +80,32 @@ export function mapKhhaoOrderPreview(item = {}) {
}
}
function resolveKhhaoShopIdentity({ platform = '', internalShopId = '', shopName = '' } = {}) {
const fallbackShopId = String(internalShopId || '').trim()
const normalizedShopName = String(shopName || '').trim()
if (String(platform || '').trim() !== 'kuaishou') {
return {
shopId: fallbackShopId,
officialShopId: '',
shopIdAliases: fallbackShopId ? [fallbackShopId] : [],
}
}
const matchedShop = resolveKuaishouEticketShopConfig({
shopId: fallbackShopId,
shopName: normalizedShopName,
})
const resolvedShopId = String(matchedShop?.shopId || '').trim() || fallbackShopId
const shopIdAliases = uniqueNonEmptyValues([resolvedShopId, fallbackShopId])
return {
shopId: resolvedShopId,
officialShopId: String(matchedShop?.shopId || '').trim(),
shopIdAliases,
}
}
export function resolveKhhaoPlatform(value) {
const normalized = String(value || '').trim()
@@ -121,3 +161,9 @@ function normalizePaidAt(value) {
function isPlainObject(value) {
return Object.prototype.toString.call(value) === '[object Object]'
}
function uniqueNonEmptyValues(values) {
return [...new Set((Array.isArray(values) ? values : [])
.map((value) => String(value || '').trim())
.filter(Boolean))]
}
@@ -36,6 +36,32 @@ export function findKuaishouEticketShopConfig(shopId, source = getKuaishouEticke
return listKuaishouEticketShopConfigs(source).find((item) => String(item.shopId || '').trim() === normalizedShopId) || null
}
export function findKuaishouEticketShopConfigByName(kshopName, source = getKuaishouEticketSourceConfig()) {
const normalizedName = String(kshopName || '').trim()
if (!normalizedName) {
return null
}
return listKuaishouEticketShopConfigs(source).find((item) => String(item.kshopName || '').trim() === normalizedName) || null
}
export function resolveKuaishouEticketShopConfig(
{ shopId = '', kshopName = '', shopName = '' } = {},
source = getKuaishouEticketSourceConfig(),
) {
const byId = findKuaishouEticketShopConfig(shopId, source)
if (byId) {
return byId
}
const normalizedName = String(kshopName || shopName || '').trim()
if (!normalizedName) {
return null
}
return findKuaishouEticketShopConfigByName(normalizedName, source)
}
export function getFirstAvailableKuaishouEticketShop(source = getKuaishouEticketSourceConfig()) {
return listKuaishouEticketShopConfigs(source).find((item) => item.enabled !== false && String(item.cookie || '').trim()) || null
}