oms/frontend/src/api/externalPrintAccount.ts
liufumingren b7da68a40c feat(shop-product): 移除「按商品ID拉取」,统一走同步商品 + 自动重匹配
按商品ID单品补拉会绕开分区声明与 SelectAgentId 过滤,容易把同一账号下别的商家的
同款商品写进本店铺(线上已确认拉错过别家商品),且与订单明细匹配口径
(店铺 + 平台商品ID + 平台规格ID)不是同一套数据来源。改为只保留全量快照同步。

- 前端店铺商品页:去掉「按商品ID拉取」按钮与弹窗,删除 pullExternalPrintShopProducts
  及 PullShopProducts* 类型
- 后端:删除 controller/externalPrintAccount.pullShopProducts + findSavedShopProducts、
  MAX_PULL_PRODUCT_ITEMS、路由 POST …/shops/:shopId/pull-products
- 平台层:删除 dgj.listProductsByIds 与 base.listProductsByIds 约定
- contract:删除 pullShopProducts* / externalPrintShopProductPull* 定义
- 文档 §4.2.5 补移除原因与替代做法(同步商品后自动重匹配,接口返回 rematched)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-07 21:45:50 +08:00

196 lines
6.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { get, post, put, del } from '@/utils/request'
import type { ExternalPrintPlatformItem } from '@/api/externalPrintPlatform'
import type { ShopAreaRefreshResult } from '@/api/shop'
export interface ExternalPrintAccountItem {
id: number
principal_id: number
platform_id: number
account: string
/** 后端不回显密码,仅标识是否已设置 */
has_password: boolean
/** 后端不回显会话 cookie,仅标识是否已保存 */
has_cookie?: boolean
/** 后端不回显登录 token,仅标识是否已保存 */
has_token?: boolean
/** 登录状态:1 已登录 0 未登录/已失效(最近一次平台交互结果) */
login_status: number
platform?: Pick<ExternalPrintPlatformItem, 'id' | 'code' | 'name' | 'url' | 'fetch_waybill_no'> | null
created_at?: string
updated_at?: string
}
export interface ExternalPrintAccountPayload {
platform_id: number
account: string
/** 修改时留空表示不修改密码 */
password?: string
}
/** 当前主体下的外部打单账号列表 */
export function getExternalPrintAccounts(params?: object) {
return get<{ list: ExternalPrintAccountItem[]; total: number; page: number; pageSize: number }>(
'/external-print-accounts',
params,
)
}
/** 新增外部打单账号 */
export function createExternalPrintAccount(data: ExternalPrintAccountPayload & { password: string }) {
return post<{ id: number }>('/external-print-accounts', data)
}
/** 修改外部打单账号(password 留空表示不修改) */
export function updateExternalPrintAccount(id: number, data: ExternalPrintAccountPayload) {
return put<{ id: number }>(`/external-print-accounts/${id}`, data)
}
/** 删除外部打单账号 */
export function deleteExternalPrintAccount(id: number) {
return del<{ id: number }>(`/external-print-accounts/${id}`)
}
export interface ExternalPrintAccountCheckResult {
logged_in: boolean
message: string
url?: string
/** 平台账号昵称(登录态有效时返回) */
nickname?: string
/** 平台当前店铺名称(登录态有效时返回) */
shop_name?: string
}
/** 检查账号登录态:用已保存的 cookie 访问平台门户 */
export function checkExternalPrintAccount(id: number) {
return post<ExternalPrintAccountCheckResult>(`/external-print-accounts/${id}/check`, undefined, {
timeout: 60000,
})
}
/** 登录账号:cookie 有效时复用,否则用账号密码登录并把 cookie 写回 */
export function loginExternalPrintAccount(id: number) {
return post<{ logged_in: boolean; reused: boolean; shop_name?: string }>(
`/external-print-accounts/${id}/login`,
undefined,
{ timeout: 60000 },
)
}
/** 平台侧店铺(商家)列表项:统一结构,不直接依赖具体平台字段 */
export interface ExternalPrintMerchantItem {
external_id: string
name: string
contact_name?: string
contact_phone?: string
/** 1 正常 0 停用 */
status: number
remark?: string
/** 是否已创建到 OMS 店铺 */
added?: boolean
/** 平台返回的原始结构,创建店铺时原样保存 */
raw?: unknown
}
/** 拉取账号在外部打单平台的店铺(商家)列表(后端按平台分发,不直连平台) */
export function getExternalPrintMerchants(id: number, params?: object) {
return get<{ list: ExternalPrintMerchantItem[]; total: number; page: number; pageSize: number }>(
`/external-print-accounts/${id}/merchants`,
params,
)
}
/** 刷新账号下店铺的「所在区」:一次拉取账号全部商家,商家已解绑的店铺自动禁用 */
export function refreshExternalPrintShopsArea(id: number) {
return post<ShopAreaRefreshResult>(`/external-print-accounts/${id}/refresh-shops-area`, undefined, {
timeout: 120000,
})
}
/** 商品同步时单个分区的拉取明细(同一域名下可能有多套库,如「新系统区」) */
export interface ExternalPrintShopProductSyncArea {
dbname: string
name: string
total: number
unique: number
pages: number
verified: boolean
}
/** 商品同步时单个域名的拉取明细 */
export interface ExternalPrintShopProductSyncHost {
host: string
total: number
unique: number
pages: number
verified: boolean
areas?: ExternalPrintShopProductSyncArea[]
}
/** 商家店铺商品同步结果 */
export interface ExternalPrintShopProductSyncResult {
total: number
unique: number
created: number
updated: number
/** 平台规格ID 统一取 SkuId 后就地改键的行数(同商品同规格名唯一命中才改) */
rekeyed?: number
/** 本次写入后补匹配上的订单明细行数(原本未采集到店铺商品) */
rematched?: number
/** 平台已不存在、且未绑定未被订单引用 → 已删除的行数 */
removed: number
/** 平台已不存在、但已绑定或被订单引用 → 保留并标为下架的行数 */
offline: number
verified: boolean
hosts: ExternalPrintShopProductSyncHost[]
}
/** 同步外部打单平台商家的店铺商品(后端按商家分区逐域名拉取全量快照) */
export function syncExternalPrintShopProducts(accountId: number, shopId: number) {
return post<ExternalPrintShopProductSyncResult>(
`/external-print-accounts/${accountId}/shops/${shopId}/sync-products`,
undefined,
{ timeout: 120000 },
)
}
/** 拉取订单结果(手动与定时共用同一后端逻辑) */
export interface SyncShopOrdersResult {
start_time: string
end_time: string
orders: number
/** 跳过数量:平台侧已发货/已终结,不需要本系统处理的订单 */
skipped: number
/** 自动作废数量:本地待审核、平台侧已发货的订单 */
voided: number
created: number
updated: number
items: number
items_bound: number
items_unbound: number
hosts: string[]
/** 0 单时的排查提示(平台侧未出现本店商家,多半是换绑导致 FxUserId 过期) */
hint?: string
}
/** 手动拉取外部打单平台商家订单(按天数或时间窗) */
export function syncExternalPrintShopOrders(
accountId: number,
shopId: number,
params: { days?: number; start_time?: string; end_time?: string } = {},
) {
return post<SyncShopOrdersResult>(
`/external-print-accounts/${accountId}/shops/${shopId}/sync-orders`,
params,
{ timeout: 300000 },
)
}
/** 把选中的平台店铺(商家)创建到 OMS 店铺:需指定所属货主(下属公司) */
export function createShopsFromMerchants(id: number, merchants: ExternalPrintMerchantItem[], subsidiaryId: number) {
return post<{ created: number; skipped: number; shops: Array<{ id: number; code: string; name: string }> }>(
`/external-print-accounts/${id}/shops`,
{ merchants, subsidiary_id: subsidiaryId },
{ timeout: 60000 },
)
}