feat: recycle system

This commit is contained in:
Timi
2026-11-12 16:51:57 +08:00
parent b1ba681042
commit 7e221e745a
90 changed files with 5981 additions and 3542 deletions
+130 -27
View File
@@ -1,16 +1,22 @@
import { axios } from "timi-web-api";
import type {
OrderTransaction,
RecycleAccount,
RecycleAccountAdjustRequest,
RecycleExchange,
RecycleExchangeActionRequest,
RecycleExchangeCreateRequest,
RecycleExchangeDetail,
RecycleExchangePage,
RecycleExchangeRule,
RecycleExchangeRulePage,
RecycleExchangeStatRow,
RecycleItem,
RecycleItemPage,
RecycleLedger,
RecyclePageResult,
RecyclePayment,
RecyclePaymentRequest,
RecycleProductYield,
RecycleRuleRequest,
RecycleStatRow
} from "@/types/Recycle";
import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents";
@@ -18,6 +24,8 @@ import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store";
const CONFIG_URI = "/gao/recycle/config";
const EXCHANGE_URI = "/gao/recycle/exchange";
const ACCOUNT_URI = "/gao/recycle/account";
const PAYMENT_URI = "/gao/recycle/payment";
const STAT_URI = "/gao/recycle/stat";
/** 配置接口的 storeId 走查询参数,可省略时由后端按登录用户门店范围解析。 */
@@ -46,7 +54,7 @@ async function itemList(page: RecycleItemPage): Promise<RecyclePageResult<Recycl
return await axios.post(`${CONFIG_URI}/items`, undefined, { params: configParams(page) });
}
/** 回收物配置详情,回填服务端拼接好的来源产品与 SKU 名称。 */
/** 回收物配置详情。 */
async function itemDetail(id: string): Promise<RecycleItem> {
return await axios.post(`${CONFIG_URI}/item/detail`, undefined, {
params: { storeId: getCurrentStoreId() || undefined, id }
@@ -75,11 +83,18 @@ async function ruleDetail(id: string): Promise<RecycleExchangeRule> {
});
}
/** 保存规则配置:新增不传 id,修改必须提交完整配置。 */
async function ruleSave(rule: RecycleExchangeRule): Promise<RecycleExchangeRule> {
/** 保存模板:新增不传 id,修改必须提交完整明细。 */
async function ruleSave(rule: RecycleRuleRequest): Promise<RecycleExchangeRule> {
return await axios.post(`${CONFIG_URI}/rule/save`, withCurrentStoreId(rule));
}
/** 删除模板。已创建的兑换单保存了快照,不依赖模板继续履约。 */
async function ruleDelete(id: string): Promise<void> {
await axios.post(`${CONFIG_URI}/rule/delete`, undefined, {
params: { storeId: getCurrentStoreId() || undefined, id }
});
}
// ---------- 兑换单 ----------
/** 创建兑换单。requestNo 为幂等号,重试必须原样复用。 */
@@ -88,34 +103,109 @@ async function create(request: RecycleExchangeCreateRequest): Promise<RecycleExc
return notifyPendingNoticeChanged(result);
}
/** 兑换单分页,按业务时间、创建时间及 ID 倒序。 */
async function page(request: RecycleExchangePage): Promise<RecyclePageResult<RecycleExchange>> {
return await axios.post(`${EXCHANGE_URI}/page`, withCurrentStoreId(request));
}
/** 兑换单详情。兑换单列表已并入交易订单查询,这里只保留详情与动作。 */
async function detail(id: string): Promise<RecycleExchangeDetail> {
return await axios.post(`${EXCHANGE_URI}/detail`, undefined, { params: { id } });
}
// ---------- 客户额度 ----------
/** 客户额度账户列表,按回收物类型逐项返回余额与预占。 */
async function accountList(customerId: string): Promise<RecycleAccount[]> {
return await axios.post(`${ACCOUNT_URI}/list`, undefined, {
params: { storeId: getCurrentStoreId() || undefined, customerId }
});
}
/** 额度流水,服务端当前最多返回 100 条。 */
async function accountLedger(customerId: string): Promise<RecycleLedger[]> {
return await axios.post(`${ACCOUNT_URI}/ledger`, undefined, {
params: { storeId: getCurrentStoreId() || undefined, customerId }
});
}
/**
* 核销待核销单。成功返回的兑换单状态可能已被并发操作改变,页面应重新查询详情。
* 门店由服务端按兑换单自身归属解析,请求不需要带 storeId。
* 人工调整额度。
*
* 减少不能超过可用额度;调整只动账面,不代表门店收到实物。
*/
async function verify(request: RecycleExchangeActionRequest): Promise<RecycleExchange> {
const result = await axios.post(`${EXCHANGE_URI}/verify`, request);
return notifyPendingNoticeChanged(result);
async function accountAdjust(request: RecycleAccountAdjustRequest): Promise<void> {
await axios.post(`${ACCOUNT_URI}/adjust`, withCurrentStoreId(request));
}
/** 撤销待核销单,recycleReturned 决定回收物是否全部退还客户。门店同理由服务端取。 */
async function cancel(request: RecycleExchangeActionRequest): Promise<RecycleExchange> {
const result = await axios.post(`${EXCHANGE_URI}/cancel`, request);
return notifyPendingNoticeChanged(result);
/** 某 SKU 的回收物产出配置。 */
async function yieldList(skuId: string): Promise<RecycleProductYield[]> {
return await axios.post(`${ACCOUNT_URI}/yield/list`, undefined, {
params: { storeId: getCurrentStoreId() || undefined, skuId }
});
}
/** 冲正已核销单。库存商品必须 stockReturned 且至少一张 PHOTO。门店同理由服务端取。 */
async function revoke(request: RecycleExchangeActionRequest): Promise<RecycleExchange> {
const result = await axios.post(`${EXCHANGE_URI}/revoke`, request);
return notifyPendingNoticeChanged(result);
/** 某产品下所有 SKU 的回收物产出配置,产品详情里配置产出用。 */
async function yieldProductList(productId: string): Promise<RecycleProductYield[]> {
return await axios.post(`${ACCOUNT_URI}/yield/product/list`, undefined, {
params: { storeId: getCurrentStoreId() || undefined, productId }
});
}
/** 保存产出比例,同一 SKU 与回收物组合会覆盖。 */
async function yieldSave(skuId: string, recycleItemId: string, quantityPerBase: string): Promise<void> {
await axios.post(`${ACCOUNT_URI}/yield/save`, undefined, {
params: { storeId: getCurrentStoreId() || undefined, skuId, recycleItemId, quantityPerBase }
});
}
/** 删除产出配置。历史额度流水仍会保留来源。 */
async function yieldDelete(skuId: string, recycleItemId: string): Promise<void> {
await axios.post(`${ACCOUNT_URI}/yield/delete`, undefined, {
params: { storeId: getCurrentStoreId() || undefined, skuId, recycleItemId }
});
}
// ---------- 回收物支付 ----------
/** 登记一笔待核销支付,创建即预占客户额度。 */
async function paymentCreate(request: RecyclePaymentRequest): Promise<RecyclePayment> {
return await axios.post(`${PAYMENT_URI}/create`, withCurrentStoreId(request));
}
/** 创建并立即核销,预占转扣减并记录实物收到。 */
async function paymentCreateAndVerify(request: RecyclePaymentRequest): Promise<RecyclePayment> {
return await axios.post(`${PAYMENT_URI}/create-and-verify`, withCurrentStoreId(request));
}
/** 某订单的回收物支付记录。 */
async function paymentList(orderId: string): Promise<RecyclePayment[]> {
return await axios.post(`${PAYMENT_URI}/list`, undefined, { params: { orderId } });
}
/** 按客户、时间和状态分页查询回收流水。 */
async function paymentSearch(params: { customerId?: string; orderId?: string; status?: string; beginAt?: number; endAt?: number; offset: number; limit: number }): Promise<RecyclePayment[]> {
return await axios.post(`${PAYMENT_URI}/search`, undefined, { params: { ...params, storeId: getCurrentStoreId() || undefined } });
}
/** 某订单的统一交易视图,资金流水与回收物支付按权限混合返回。 */
async function paymentTransactions(orderId: string): Promise<OrderTransaction[]> {
return await axios.post(`${PAYMENT_URI}/transactions`, undefined, { params: { orderId } });
}
/** 核销待核销支付。 */
async function paymentVerify(paymentId: string): Promise<RecyclePayment> {
return await axios.post(`${PAYMENT_URI}/verify`, { paymentId });
}
/** 拒绝待核销支付并释放预占。 */
async function paymentReject(request: RecyclePaymentRequest): Promise<RecyclePayment> {
return await axios.post(`${PAYMENT_URI}/reject`, request);
}
/** 撤销待核销支付并释放预占,普通撤销仅限提交人。 */
async function paymentCancel(request: RecyclePaymentRequest): Promise<RecyclePayment> {
return await axios.post(`${PAYMENT_URI}/cancel`, request);
}
/** 整笔冲正已核销支付并返还额度。 */
async function paymentRevoke(request: RecyclePaymentRequest): Promise<RecyclePayment> {
return await axios.post(`${PAYMENT_URI}/revoke`, withCurrentStoreId(request));
}
// ---------- 统计 ----------
@@ -150,12 +240,25 @@ export default {
activeRuleList,
ruleDetail,
ruleSave,
ruleDelete,
create,
page,
detail,
verify,
cancel,
revoke,
accountList,
accountLedger,
accountAdjust,
yieldList,
yieldProductList,
yieldSave,
yieldDelete,
paymentCreate,
paymentCreateAndVerify,
paymentList,
paymentSearch,
paymentTransactions,
paymentVerify,
paymentReject,
paymentCancel,
paymentRevoke,
statRecycle,
statExchange
};