377 lines
11 KiB
TypeScript
377 lines
11 KiB
TypeScript
import type { Attachment, Model, PageResult, User } from "timi-web-api";
|
||
import type { Customer } from "@/types/Customer";
|
||
|
||
/** 回收物与兑换模板的启用状态。配置没有删除,停用使用 INACTIVE。 */
|
||
export type RecycleStatus = "ACTIVE" | "INACTIVE";
|
||
|
||
/**
|
||
* 兑换单状态。
|
||
*
|
||
* PENDING 待领取,COMPLETED 已完成,CANCELLED 已取消。
|
||
*/
|
||
export type RecycleExchangeStatus = "PENDING" | "COMPLETED" | "CANCELLED";
|
||
|
||
/** 兑换单操作类型。核销与冲正由回收物支付承载,兑换单只剩取消。 */
|
||
export type RecycleExchangeActionType = "CANCEL";
|
||
|
||
/**
|
||
* 回收物支付状态。
|
||
*
|
||
* 冲正会生成一条新记录,`sourcePaymentId` 指向被冲正的原支付。
|
||
*/
|
||
export type RecyclePaymentStatus = "PENDING" | "VERIFIED" | "REJECTED" | "CANCELLED" | "REVOKED";
|
||
|
||
/** 回收物配置。回收物不是退货,不校验客户购买记录,也不累计客户余额。 */
|
||
export type RecycleItem = {
|
||
storeId?: string;
|
||
/** 回收物图片附件。 */
|
||
attachmentList?: Partial<Attachment>[];
|
||
name: string;
|
||
/** 回收计量单位,例如「个」「公斤」 */
|
||
unitName: string;
|
||
/** 回收数量是否允许小数。 */
|
||
allowDecimalQuantity?: boolean;
|
||
status?: RecycleStatus;
|
||
remark?: string | null;
|
||
} & Model;
|
||
|
||
/** 回收物配置分页与筛选条件。 */
|
||
export type RecycleItemPage = {
|
||
storeId?: string;
|
||
status?: RecycleStatus;
|
||
/** 名称关键字 */
|
||
keyword?: string;
|
||
offset: number;
|
||
limit: number;
|
||
};
|
||
|
||
/** 兑换模板明细:一条商品在这个模板里兑换多少业务单位。 */
|
||
export type RecycleRuleItem = {
|
||
id?: string;
|
||
ruleId?: string;
|
||
skuId: string;
|
||
skuUnitId: string;
|
||
/** 单份模板兑换的业务单位数量 */
|
||
exchangeQuantity: number | string;
|
||
sort?: number;
|
||
/** 以下为服务端回填的展示字段 */
|
||
productName?: string | null;
|
||
productType?: string | null;
|
||
skuCode?: string | null;
|
||
skuName?: string | null;
|
||
specSummary?: string | null;
|
||
unitName?: string | null;
|
||
stockEnabled?: boolean | null;
|
||
allowDecimalQuantity?: boolean | null;
|
||
};
|
||
|
||
/**
|
||
* 回收兑换模板。
|
||
*
|
||
* 模板只是开单的快捷配置,可随时修改或删除;兑换单创建时保存 `ruleSnapshot`,
|
||
* 不依赖模板继续履约。
|
||
*/
|
||
export type RecycleExchangeRule = {
|
||
storeId?: string;
|
||
recycleItemId: string;
|
||
/** 单份模板回收数量 */
|
||
recycleQuantity: number | string;
|
||
/** 商品明细,至少一条 */
|
||
itemList?: RecycleRuleItem[];
|
||
status?: RecycleStatus;
|
||
sort?: number;
|
||
remark?: string | null;
|
||
/** 以下为服务端回填的展示字段,保存时无需提交 */
|
||
recycleName?: string | null;
|
||
recycleUnit?: string | null;
|
||
recycleItemAttachments?: Partial<Attachment>[];
|
||
} & Model;
|
||
|
||
/** 兑换模板分页与筛选条件。 */
|
||
export type RecycleExchangeRulePage = {
|
||
storeId?: string;
|
||
status?: RecycleStatus;
|
||
recycleItemId?: string;
|
||
skuId?: string;
|
||
/** 回收物名称关键字 */
|
||
keyword?: string;
|
||
offset: number;
|
||
limit: number;
|
||
};
|
||
|
||
/** 保存模板请求。新增不传 id,修改必须提交完整明细。 */
|
||
export type RecycleRuleRequest = {
|
||
id?: string;
|
||
storeId?: string;
|
||
recycleItemId: string;
|
||
recycleQuantity: number | string;
|
||
itemList: RecycleRuleItem[];
|
||
status: RecycleStatus;
|
||
sort?: number;
|
||
remark?: string | null;
|
||
};
|
||
|
||
/**
|
||
* 兑换单。
|
||
*
|
||
* 兑换单本身只记录回收物与支付条件,商品明细在生成的销售订单里(`salesOrderId`)。
|
||
*/
|
||
export type RecycleExchange = {
|
||
storeId?: string;
|
||
customerId?: string;
|
||
requestNo?: string;
|
||
/** 模板 ID,自由创建时为空 */
|
||
ruleId?: string;
|
||
/** 生成的销售订单 ID,商品明细、支付与履约都用它 */
|
||
salesOrderId?: string;
|
||
/** 创建时模板快照,自由创建时为空 */
|
||
ruleSnapshot?: Partial<RecycleExchangeRule> | null;
|
||
recycleItemId?: string;
|
||
recycleNameSnapshot?: string;
|
||
/** 回收物当前图片附件。 */
|
||
recycleItemAttachments?: Partial<Attachment>[];
|
||
recycleUnitSnapshot?: string;
|
||
/** 回收物当前是否允许小数。 */
|
||
allowDecimalQuantity?: boolean;
|
||
/** 模板单份回收数量 */
|
||
ruleRecycleQuantity?: number | string;
|
||
/** 模板份数,自由创建时为空 */
|
||
multiple?: number;
|
||
/** 模板预设回收数量 = 模板回收数量 × 份数 */
|
||
defaultRecycleQuantity?: number | string;
|
||
/** 约定支付回收物数量 */
|
||
recycleQuantity?: number | string;
|
||
status?: RecycleExchangeStatus;
|
||
operatorUserId?: string;
|
||
/** 业务发生时间 */
|
||
occurredAt?: number;
|
||
remark?: string | null;
|
||
customer?: Customer;
|
||
operator?: Partial<User>;
|
||
} & Model;
|
||
|
||
/** 兑换单操作记录。核销与冲正由回收物支付承载,只有取消。 */
|
||
export type RecycleExchangeAction = {
|
||
exchangeId?: string;
|
||
actionType?: RecycleExchangeActionType;
|
||
operatorUserId?: string;
|
||
occurredAt?: number;
|
||
reason?: string | null;
|
||
remark?: string | null;
|
||
/** 取消后门店保留的回收物数量 */
|
||
retainedRecycleQuantity?: number | string;
|
||
operator?: Partial<User>;
|
||
} & Model;
|
||
|
||
/** 兑换单详情。取消凭证按操作记录 ID 从 actionAttachments 读取。 */
|
||
export type RecycleExchangeDetail = {
|
||
exchange?: RecycleExchange;
|
||
actionList?: RecycleExchangeAction[];
|
||
attachmentList?: Attachment[];
|
||
actionAttachments?: Record<string, Attachment[]>;
|
||
};
|
||
|
||
/** 客户回收物额度账户。可用额度 = balance - reserved。 */
|
||
export type RecycleAccount = {
|
||
id?: string;
|
||
storeId?: string;
|
||
customerId?: string;
|
||
recycleItemId?: string;
|
||
/** 额度余额 */
|
||
balance?: number | string;
|
||
/** 支付预占 */
|
||
reserved?: number | string;
|
||
/** 服务端回填的回收物名称与单位,仅展示用 */
|
||
recycleName?: string | null;
|
||
recycleUnit?: string | null;
|
||
createdAt?: number;
|
||
updatedAt?: number;
|
||
};
|
||
|
||
/**
|
||
* 额度流水。
|
||
*
|
||
* `bizType` 决定来源语义:履约产生、人工调整、支付预占与释放、支付核销、冲正返还。
|
||
*/
|
||
export type RecycleLedger = {
|
||
id?: string;
|
||
accountId?: string;
|
||
storeId?: string;
|
||
customerId?: string;
|
||
recycleItemId?: string;
|
||
bizType?: string;
|
||
bizId?: string | null;
|
||
requestNo?: string;
|
||
balanceDelta?: number | string;
|
||
reservedDelta?: number | string;
|
||
balanceAfter?: number | string;
|
||
reservedAfter?: number | string;
|
||
operatorUserId?: string | null;
|
||
reason?: string | null;
|
||
createdAt?: number;
|
||
};
|
||
|
||
/** 人工调整额度请求。 */
|
||
export type RecycleAccountAdjustRequest = {
|
||
storeId?: string;
|
||
customerId: string;
|
||
recycleItemId: string;
|
||
requestNo: string;
|
||
/** 可正可负,不能为零 */
|
||
quantity: number | string;
|
||
/** 调整原因,必填 */
|
||
reason: string;
|
||
};
|
||
|
||
/**
|
||
* 产品回收物产出配置。
|
||
*
|
||
* `quantityPerBase` 表示每个 SKU **基础单位**产生多少回收物,最多三位小数。
|
||
*/
|
||
export type RecycleProductYield = {
|
||
id?: string;
|
||
storeId?: string;
|
||
skuId?: string;
|
||
recycleItemId?: string;
|
||
/** 回收物是否允许小数数量。 */
|
||
allowDecimalQuantity?: boolean;
|
||
/** 回收物附件。 */
|
||
attachmentList?: Partial<Attachment>[];
|
||
quantityPerBase?: number | string;
|
||
/** 服务端回填的回收物名称与单位,仅展示用 */
|
||
recycleName?: string | null;
|
||
recycleUnit?: string | null;
|
||
/** 产品维度查询时回填的 SKU 名称与规格摘要,仅展示用 */
|
||
skuName?: string | null;
|
||
skuSpecSummary?: string | null;
|
||
};
|
||
|
||
/** 回收物支付。一笔订单可分批提交,已核销数量达到约定数量后结清。 */
|
||
export type RecyclePayment = {
|
||
id?: string;
|
||
storeId?: string;
|
||
customerId?: string;
|
||
/** 兑换生成的销售订单 ID */
|
||
orderId?: string;
|
||
recycleExchangeId?: string;
|
||
customer?: Customer;
|
||
recycleItemId?: string;
|
||
requestNo?: string;
|
||
quantity?: number | string;
|
||
/** 带方向的数量,支付为正、冲正为负,汇总时直接相加 */
|
||
signedQuantity?: number | string;
|
||
status?: RecyclePaymentStatus;
|
||
/** 冲正记录指向被冲正的原支付 */
|
||
sourcePaymentId?: string | null;
|
||
operatorUserId?: string;
|
||
verifierUserId?: string | null;
|
||
occurredAt?: number;
|
||
verifiedAt?: number | null;
|
||
reason?: string | null;
|
||
/** 冲正时实物是否已退还客户 */
|
||
returnedToCustomer?: boolean | null;
|
||
/** 服务端回填的回收物名称与单位,仅展示用 */
|
||
recycleName?: string | null;
|
||
recycleUnit?: string | null;
|
||
attachmentList?: Attachment[];
|
||
operator?: Partial<User>;
|
||
verifier?: Partial<User>;
|
||
} & Model;
|
||
|
||
/** 回收物支付请求。创建、核销、拒绝、撤销、冲正共用。 */
|
||
export type RecyclePaymentRequest = {
|
||
storeId?: string;
|
||
orderId?: string;
|
||
paymentId?: string;
|
||
requestNo?: string;
|
||
quantity?: number | string;
|
||
occurredAt?: number;
|
||
reason?: string;
|
||
returnedToCustomer?: boolean;
|
||
attachmentList?: Partial<Attachment>[];
|
||
};
|
||
|
||
/** 统一交易记录:资金流水与回收物支付混合展示,回收物数量不能当金额用。 */
|
||
export type OrderTransaction = {
|
||
type: "FUND" | "RECYCLE_PAYMENT";
|
||
occurredAt?: number;
|
||
fundRecord?: Record<string, unknown>;
|
||
recyclePayment?: RecyclePayment;
|
||
};
|
||
|
||
/** 兑换明细请求:创建兑换单与自由创建时提交的商品行。 */
|
||
export type RecycleExchangeItemRequest = {
|
||
skuId: string;
|
||
skuUnitId: string;
|
||
quantity: number | string;
|
||
};
|
||
|
||
/**
|
||
* 创建兑换单请求。
|
||
*
|
||
* 按模板创建传 `ruleId` 与可选 `multiple`;自由创建不传 `ruleId`,必须传
|
||
* `recycleItemId` 与 `itemList`,且需要调整权限。
|
||
*/
|
||
export type RecycleExchangeCreateRequest = {
|
||
storeId?: string;
|
||
customerId: string;
|
||
/** 模板 ID,自由创建时为空 */
|
||
ruleId?: string;
|
||
/** 自由创建时的回收物 ID */
|
||
recycleItemId?: string;
|
||
/** 兑换明细,按模板创建时可省略 */
|
||
itemList?: RecycleExchangeItemRequest[];
|
||
requestNo: string;
|
||
/** 兑换份数,按模板创建时使用,省略按 1 份处理 */
|
||
multiple?: number;
|
||
/** 约定支付回收数量,不传使用模板预设值 */
|
||
recycleQuantity?: number | string;
|
||
/**
|
||
* true 为创建时立即预占并核销全部应付回收物。
|
||
*
|
||
* 需要支付创建与核销权限、足够可用额度,并提供回收凭证。
|
||
*/
|
||
verifyPayment?: boolean;
|
||
/** 创建时核销的回收物数量 */
|
||
paymentQuantity?: number | string;
|
||
/** 创建时回收的凭证照片 */
|
||
paymentAttachmentList?: Partial<Attachment>[];
|
||
/** 创建时完成全部履约和核销 */
|
||
fulfillAll?: boolean;
|
||
/** 全部履约的凭证照片 */
|
||
fulfillmentAttachmentList?: Partial<Attachment>[];
|
||
occurredAt?: number;
|
||
remark?: string | null;
|
||
attachmentList?: Partial<Attachment>[];
|
||
};
|
||
|
||
/**
|
||
* 配置列表分页结果。
|
||
*
|
||
* 后端返回的 pages 按本次列表长度计算,末页可能不准,分页一律用 total 推算。
|
||
*/
|
||
export type RecyclePageResult<T> = PageResult<T> & {
|
||
pages?: number;
|
||
};
|
||
|
||
/** 回收统计行。同一回收物名称或单位变化后可能出现多行。 */
|
||
export type RecycleStatRow = {
|
||
recycleItemId?: string;
|
||
recycleName?: string;
|
||
recycleUnit?: string;
|
||
receivedQuantity?: number | string;
|
||
returnedQuantity?: number | string;
|
||
netQuantity?: number | string;
|
||
};
|
||
|
||
/** 兑换统计行。三项数量按创建、核销、冲正的业务时间分别归集。 */
|
||
export type RecycleExchangeStatRow = {
|
||
skuId?: string;
|
||
skuUnitId?: string;
|
||
productName?: string;
|
||
unit?: string;
|
||
createdQuantity?: number | string;
|
||
verifiedQuantity?: number | string;
|
||
revokedQuantity?: number | string;
|
||
};
|