feat: recycle system
This commit is contained in:
+247
-103
@@ -1,32 +1,38 @@
|
||||
import type { Attachment, Model, PageResult, User } from "timi-web-api";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { ProductSkuSpecSnapshot, StockRecord } from "@/types/Product";
|
||||
|
||||
/** 回收物与兑换规则的启用状态。配置没有删除,停用使用 INACTIVE。 */
|
||||
/** 回收物与兑换模板的启用状态。配置没有删除,停用使用 INACTIVE。 */
|
||||
export type RecycleStatus = "ACTIVE" | "INACTIVE";
|
||||
|
||||
/** 兑换单状态。 */
|
||||
export type RecycleExchangeStatus = "PENDING" | "VERIFIED" | "CANCELLED" | "REVOKED";
|
||||
/**
|
||||
* 兑换单状态。
|
||||
*
|
||||
* PENDING 待领取,COMPLETED 已完成,CANCELLED 已取消。
|
||||
*/
|
||||
export type RecycleExchangeStatus = "PENDING" | "COMPLETED" | "CANCELLED";
|
||||
|
||||
/** 兑换单操作类型。 */
|
||||
export type RecycleExchangeActionType = "VERIFY" | "CANCEL" | "REVOKE";
|
||||
/** 兑换单操作类型。核销与冲正由回收物支付承载,兑换单只剩取消。 */
|
||||
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;
|
||||
/** 来源产品 ID,仅用于识别,不影响库存 */
|
||||
productId?: string | null;
|
||||
/** 来源 SKU ID,填写时必须同时填写其所属 productId */
|
||||
skuId?: string | null;
|
||||
/** 回收数量是否允许小数。 */
|
||||
allowDecimalQuantity?: boolean;
|
||||
status?: RecycleStatus;
|
||||
remark?: string | null;
|
||||
/** 来源产品名称,服务端回填,仅展示用 */
|
||||
sourceProductName?: string | null;
|
||||
/** 来源 SKU 规格摘要,服务端回填,仅展示用 */
|
||||
sourceSkuName?: string | null;
|
||||
} & Model;
|
||||
|
||||
/** 回收物配置分页与筛选条件。 */
|
||||
@@ -39,24 +45,16 @@ export type RecycleItemPage = {
|
||||
limit: number;
|
||||
};
|
||||
|
||||
/** 回收兑换规则:单份回收数量兑换单份业务单位数量。 */
|
||||
export type RecycleExchangeRule = {
|
||||
storeId?: string;
|
||||
recycleItemId: string;
|
||||
/** 单份规则回收数量 */
|
||||
recycleQuantity: number | string;
|
||||
/** 兑换 SKU ID */
|
||||
/** 兑换模板明细:一条商品在这个模板里兑换多少业务单位。 */
|
||||
export type RecycleRuleItem = {
|
||||
id?: string;
|
||||
ruleId?: string;
|
||||
skuId: string;
|
||||
/** 兑换 SKU 业务单位 ID */
|
||||
skuUnitId: string;
|
||||
/** 单份规则兑换业务单位数量 */
|
||||
/** 单份模板兑换的业务单位数量 */
|
||||
exchangeQuantity: number | string;
|
||||
status?: RecycleStatus;
|
||||
sort?: number;
|
||||
remark?: string | null;
|
||||
/** 以下为服务端回填的展示字段,保存时无需提交 */
|
||||
recycleName?: string | null;
|
||||
recycleUnit?: string | null;
|
||||
/** 以下为服务端回填的展示字段 */
|
||||
productName?: string | null;
|
||||
productType?: string | null;
|
||||
skuCode?: string | null;
|
||||
@@ -65,9 +63,31 @@ export type RecycleExchangeRule = {
|
||||
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;
|
||||
@@ -79,48 +99,48 @@ export type RecycleExchangeRulePage = {
|
||||
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;
|
||||
sourceProductIdSnapshot?: string;
|
||||
sourceSkuIdSnapshot?: string;
|
||||
/** 回收物当前是否允许小数。 */
|
||||
allowDecimalQuantity?: boolean;
|
||||
/** 模板单份回收数量 */
|
||||
ruleRecycleQuantity?: number | string;
|
||||
ruleExchangeQuantity?: number | string;
|
||||
/** 规则倍数,正整数 */
|
||||
/** 模板份数,自由创建时为空 */
|
||||
multiple?: number;
|
||||
/** 预设回收数量 = 规则回收数量 × 倍数 */
|
||||
/** 模板预设回收数量 = 模板回收数量 × 份数 */
|
||||
defaultRecycleQuantity?: number | string;
|
||||
/** 预设兑换数量 = 规则兑换数量 × 倍数 */
|
||||
defaultExchangeQuantity?: number | string;
|
||||
/** 实际回收数量 */
|
||||
/** 约定支付回收物数量 */
|
||||
recycleQuantity?: number | string;
|
||||
/** 实际兑换数量 */
|
||||
exchangeQuantity?: number | string;
|
||||
productIdSnapshot?: string;
|
||||
skuIdSnapshot?: string;
|
||||
skuUnitIdSnapshot?: string;
|
||||
productNameSnapshot?: string;
|
||||
productTypeSnapshot?: string;
|
||||
skuCodeSnapshot?: string;
|
||||
skuNameSnapshot?: string;
|
||||
specSummarySnapshot?: string;
|
||||
skuSpecSnapshot?: ProductSkuSpecSnapshot[];
|
||||
unitSnapshot?: string;
|
||||
baseQuantityPerUnitSnapshot?: number | string;
|
||||
baseQuantity?: number | string;
|
||||
allowDecimalSnapshot?: boolean;
|
||||
/** true 为兑换 SKU 启用库存管理,创建时预占,撤销时释放 */
|
||||
stockEnabledSnapshot?: boolean;
|
||||
status?: RecycleExchangeStatus;
|
||||
operatorUserId?: string;
|
||||
/** 业务发生时间 */
|
||||
@@ -130,7 +150,7 @@ export type RecycleExchange = {
|
||||
operator?: Partial<User>;
|
||||
} & Model;
|
||||
|
||||
/** 兑换单操作记录。核销记录的退回字段为空。 */
|
||||
/** 兑换单操作记录。核销与冲正由回收物支付承载,只有取消。 */
|
||||
export type RecycleExchangeAction = {
|
||||
exchangeId?: string;
|
||||
actionType?: RecycleExchangeActionType;
|
||||
@@ -138,67 +158,191 @@ export type RecycleExchangeAction = {
|
||||
occurredAt?: number;
|
||||
reason?: string | null;
|
||||
remark?: string | null;
|
||||
/** true 为回收物全部退还客户 */
|
||||
recycleReturned?: boolean | null;
|
||||
/** true 为兑换商品已退回门店 */
|
||||
stockReturned?: boolean | null;
|
||||
stockRecordId?: string;
|
||||
sourceStockRecordId?: string;
|
||||
/** 取消后门店保留的回收物数量 */
|
||||
retainedRecycleQuantity?: number | string;
|
||||
operator?: Partial<User>;
|
||||
} & Model;
|
||||
|
||||
/** 兑换单详情。冲正照片按操作记录 ID 从 actionAttachments 读取。 */
|
||||
/** 兑换单详情。取消凭证按操作记录 ID 从 actionAttachments 读取。 */
|
||||
export type RecycleExchangeDetail = {
|
||||
exchange?: RecycleExchange;
|
||||
actionList?: RecycleExchangeAction[];
|
||||
attachmentList?: Attachment[];
|
||||
actionAttachments?: Record<string, Attachment[]>;
|
||||
stockRecordList?: StockRecord[];
|
||||
};
|
||||
|
||||
export type RecycleExchangeCreateRequest = {
|
||||
storeId?: string;
|
||||
customerId: string;
|
||||
ruleId: string;
|
||||
requestNo: string;
|
||||
multiple: number;
|
||||
/** 实际回收数量,不传使用预设值 */
|
||||
recycleQuantity?: string;
|
||||
/** 实际兑换数量,不传使用预设值 */
|
||||
exchangeQuantity?: string;
|
||||
occurredAt?: number;
|
||||
remark?: string | null;
|
||||
attachmentList?: Partial<Attachment>[];
|
||||
};
|
||||
|
||||
/** 兑换单动作请求。门店由服务端按兑换单归属解析,这里不需要也不应该传。 */
|
||||
export type RecycleExchangeActionRequest = {
|
||||
exchangeId: string;
|
||||
requestNo: string;
|
||||
occurredAt?: number;
|
||||
remark?: string | null;
|
||||
/** 冲正必填 */
|
||||
reason?: string;
|
||||
/** 撤销、冲正必填 */
|
||||
recycleReturned?: boolean;
|
||||
/** 库存商品冲正必填,必须为 true */
|
||||
stockReturned?: boolean;
|
||||
/** 库存商品冲正至少一张 PHOTO */
|
||||
attachmentList?: Partial<Attachment>[];
|
||||
};
|
||||
|
||||
export type RecycleExchangePage = {
|
||||
/** 客户回收物额度账户。可用额度 = 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;
|
||||
status?: RecycleExchangeStatus;
|
||||
/** 业务时间起点,包含 */
|
||||
beginAt?: number;
|
||||
/** 业务时间终点,包含 */
|
||||
endAt?: number;
|
||||
index: number;
|
||||
size: number;
|
||||
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>[];
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user