oms/frontend/src/api/externalPrintAccount.ts
liufumingren 7c8e531362 feat(shop): 店铺/店铺商品关联货主与打单平台权限限制
- shops、shop_products 新增 subsidiary_id,店铺商品货主跟随店铺并按店铺回填历史数据
- 店铺列表/详情/新增/编辑/删除按货主范围隔离:货主权限仅可见/可维护自己所属公司的店铺,
  新增必须选货主,货主下拉仅自己所属公司;集团改店铺货主时店铺商品同步跟随
- 外部打单平台导入的店铺(type=2)在货主权限下只读:仅保留拉取订单、同步商品,不可编辑/删除
- 打单平台相关接口(平台资料、账号、商家、快递接口、外部发货)加集团权限门禁;添加店铺必须指定货主
- 货主权限菜单隐藏「外部打单平台」;店铺商品列表/绑定按货主范围隔离
- 店铺与店铺商品导出新增货主列并按范围收窄

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-05 02:15:42 +08:00

227 lines
7.1 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'
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 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
/** 平台已不存在、且未绑定未被订单引用 → 已删除的行数 */
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 },
)
}
/** 待补拉的商品(订单明细里的平台商品ID/规格ID) */
export interface PullShopProductItem {
outer_item_id: string
outer_sku_id?: string
}
/** 单品补拉结果里写入的店铺商品 */
export interface PulledShopProductRow {
id: number
shop_id: number
outer_item_id: string
outer_sku_id: string | null
title: string | null
spec: string | null
platform_type: string | null
status: number
bind_type: number
product_id: number | null
combo_product_id: number | null
}
/** 单品补拉结果(未命中的商品带原因返回) */
export interface PullShopProductsResult {
requested: number
matched: number
created: number
updated: number
hosts: string[]
missing: Array<{ outer_item_id: string; outer_sku_id: string; reason: string }>
products: PulledShopProductRow[]
}
/** 按平台商品ID单独补拉店铺商品(订单明细匹配不到店铺商品时使用) */
export function pullExternalPrintShopProducts(
accountId: number,
shopId: number,
items: PullShopProductItem[],
) {
return post<PullShopProductsResult>(
`/external-print-accounts/${accountId}/shops/${shopId}/pull-products`,
{ items },
{ 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[]
}
/** 手动拉取外部打单平台商家订单(按天数或时间窗) */
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 },
)
}