@pisell/pisellos 2.2.263 → 2.2.265
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Order/index.d.ts +27 -8
- package/dist/modules/Order/index.js +736 -473
- package/dist/modules/Order/payment-utils.d.ts +26 -0
- package/dist/modules/Order/payment-utils.js +225 -0
- package/dist/modules/Order/types.d.ts +33 -1
- package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
- package/dist/modules/Order/utils.js +8 -5
- package/dist/modules/Payment/index.d.ts +2 -0
- package/dist/modules/Payment/index.js +78 -49
- package/dist/modules/Payment/types.d.ts +26 -24
- package/dist/modules/Payment/types.js +2 -0
- package/dist/server/index.d.ts +16 -0
- package/dist/server/index.js +1940 -1043
- package/dist/server/modules/order/index.d.ts +49 -4
- package/dist/server/modules/order/index.js +1577 -698
- package/dist/server/modules/order/types.d.ts +11 -3
- package/dist/server/modules/order/types.js +1 -1
- package/dist/solution/BaseSales/index.d.ts +33 -3
- package/dist/solution/BaseSales/index.js +653 -340
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +2 -1
- package/dist/solution/Sales/index.d.ts +1 -0
- package/dist/solution/Sales/index.js +10 -2
- package/dist/utils/payment-number.d.ts +9 -0
- package/dist/utils/payment-number.js +69 -0
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/modules/Order/index.d.ts +27 -8
- package/lib/modules/Order/index.js +180 -60
- package/lib/modules/Order/payment-utils.d.ts +26 -0
- package/lib/modules/Order/payment-utils.js +224 -0
- package/lib/modules/Order/types.d.ts +33 -1
- package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
- package/lib/modules/Order/utils.js +5 -3
- package/lib/modules/Payment/index.d.ts +2 -0
- package/lib/modules/Payment/index.js +33 -12
- package/lib/modules/Payment/types.d.ts +26 -24
- package/lib/server/index.d.ts +16 -0
- package/lib/server/index.js +670 -18
- package/lib/server/modules/order/index.d.ts +49 -4
- package/lib/server/modules/order/index.js +657 -66
- package/lib/server/modules/order/types.d.ts +11 -3
- package/lib/solution/BaseSales/index.d.ts +33 -3
- package/lib/solution/BaseSales/index.js +193 -9
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +2 -1
- package/lib/solution/Sales/index.d.ts +1 -0
- package/lib/solution/Sales/index.js +5 -3
- package/lib/utils/payment-number.d.ts +9 -0
- package/lib/utils/payment-number.js +64 -0
- package/package.json +1 -1
|
@@ -213,10 +213,12 @@ export interface OrderBookingItem {
|
|
|
213
213
|
[key: string]: unknown;
|
|
214
214
|
}[];
|
|
215
215
|
}
|
|
216
|
-
/** 支付记录 metadata
|
|
216
|
+
/** 支付记录 metadata */
|
|
217
217
|
export interface OrderPaymentMetadata {
|
|
218
|
-
/**
|
|
218
|
+
/** 三方支付交易流水号 */
|
|
219
219
|
unique_payment_number?: string;
|
|
220
|
+
/** 刷卡机设备快照;server 不解析内部字段,仅透传并持久化 */
|
|
221
|
+
card_reader_snapshot?: Record<string, unknown>;
|
|
220
222
|
[key: string]: unknown;
|
|
221
223
|
}
|
|
222
224
|
/**
|
|
@@ -225,6 +227,8 @@ export interface OrderPaymentMetadata {
|
|
|
225
227
|
export interface OrderPaymentItem {
|
|
226
228
|
/** 支付记录 ID;存量/更新时传。来源:OrderPayment.id */
|
|
227
229
|
order_payment_id?: number | null;
|
|
230
|
+
/** 支付项稳定唯一号;历史支付项允许缺失 */
|
|
231
|
+
payment_number?: string;
|
|
228
232
|
/** 支付方式 ID(设备端从本地支付方式配置取详情)。来源:OrderPayment.custom_payment_id */
|
|
229
233
|
custom_payment_id?: number;
|
|
230
234
|
/** 支付方式编码。来源:OrderPayment.payment_method */
|
|
@@ -249,11 +253,13 @@ export interface OrderPaymentItem {
|
|
|
249
253
|
created_at?: string | null;
|
|
250
254
|
/** 手续费配置。来源:OrderPayment.service_charge */
|
|
251
255
|
service_charge?: Record<string, unknown> | null;
|
|
256
|
+
/** 已计算的支付手续费。来源:OrderPayment.service_fee */
|
|
257
|
+
service_fee?: OrderMoneyString;
|
|
252
258
|
/** Wallet Pass 使用单位 */
|
|
253
259
|
wallet_pass_usage_unit?: unknown[] | null;
|
|
254
260
|
/** Wallet Pass 使用值 */
|
|
255
261
|
wallet_pass_use_value?: number | null;
|
|
256
|
-
/**
|
|
262
|
+
/** 元数据;三方支付成功后可含 unique_payment_number */
|
|
257
263
|
metadata?: OrderPaymentMetadata | null;
|
|
258
264
|
}
|
|
259
265
|
/**
|
|
@@ -413,6 +419,8 @@ export interface OrderData {
|
|
|
413
419
|
create_date?: string;
|
|
414
420
|
/** 本地待同步标记:1 表示需要后续同步到云端 */
|
|
415
421
|
need_sync?: 0 | 1 | number;
|
|
422
|
+
/** 本地草稿标记:1 表示仅为 POS 可恢复草稿,不代表已提交云端 */
|
|
423
|
+
is_draft_order?: 0 | 1 | number;
|
|
416
424
|
/** 兼容:部分场景仍使用顶层 total_amount */
|
|
417
425
|
total_amount?: OrderMoneyString | number;
|
|
418
426
|
/** 扩展字段(物流、标签等);使用 any 以便筛选与数据源扩展 */
|
|
@@ -2,7 +2,7 @@ import { Module, ModuleOptions, PisellCore } from '../../types';
|
|
|
2
2
|
import { BaseModule } from '../../modules/BaseModule';
|
|
3
3
|
import { BaseSalesOrderProduct, BaseSalesOrderProductIdentity, BaseSalesPaymentStatus, BaseSalesUpdateOrderProductQuantityParams, BaseSalesCalculateProductBookingPriceParams, BaseSalesPriceRecalculationContextChange, BaseSalesProductBookingPriceResult, BaseSalesQuotationCustomerScopeInfo, BaseSalesScanCodeResult } from './types';
|
|
4
4
|
import { OrderModule } from '../../modules/Order';
|
|
5
|
-
import type { AddProductBookingInput, LoadSalesDetailParams, OrderPaymentData, OrderPaymentSource, SendCustomerPayLinkParams, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, UpdateTempOrderCustomerInput, UpdateOrderBookingParams, UpdateOrderProductParams, OrderTempOrder, OrderSummary, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions } from '../../modules/Order/types';
|
|
5
|
+
import type { AddProductBookingInput, LoadSalesDetailParams, OrderPaymentData, OrderPaymentUpdateOptions, OrderPaymentUpdateResult, OrderPaymentSource, SendCustomerPayLinkParams, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, UpdateTempOrderCustomerInput, UpdateOrderBookingParams, UpdateOrderProductParams, OrderTempOrder, OrderSummary, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions } from '../../modules/Order/types';
|
|
6
6
|
import type { SubmitPayloadEnhancer } from '../../modules/Order/utils';
|
|
7
7
|
import type { Discount } from '../../modules/Discount/types';
|
|
8
8
|
import { RequestPlugin, WindowPlugin } from '../../plugins';
|
|
@@ -24,6 +24,19 @@ export interface BaseSalesState {
|
|
|
24
24
|
schedule?: ScheduleModule;
|
|
25
25
|
quotation?: QuotationModule;
|
|
26
26
|
}
|
|
27
|
+
export interface BaseSalesUpdateOrderPaymentOptions extends OrderPaymentUpdateOptions {
|
|
28
|
+
persistDraft?: boolean;
|
|
29
|
+
submitWhenPaid?: boolean;
|
|
30
|
+
forceSubmitIfPaid?: boolean;
|
|
31
|
+
/** 草稿恢复时,允许将新回调字段合并进已 paid 的支付项。 */
|
|
32
|
+
applyUpdatesWhenPaid?: boolean;
|
|
33
|
+
smallTicketDataFlag?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface BaseSalesUpdateOrderPaymentResult extends OrderPaymentUpdateResult {
|
|
36
|
+
draftResult?: unknown;
|
|
37
|
+
draftError?: unknown;
|
|
38
|
+
syncResult?: SyncPaymentsToOrderResult<any>;
|
|
39
|
+
}
|
|
27
40
|
export type BaseSalesPrintLocalOrderReceiptParams = string | number;
|
|
28
41
|
export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
29
42
|
protected defaultName: string;
|
|
@@ -128,6 +141,8 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
128
141
|
*/
|
|
129
142
|
protected readSessionCacheData(): Record<string, any>;
|
|
130
143
|
protected getAppData<T>(key: string): T | undefined;
|
|
144
|
+
private getPaymentNumberDevicePrefixSync;
|
|
145
|
+
private getPaymentNumberDevicePrefixAsync;
|
|
131
146
|
private syncAppDataToTempOrder;
|
|
132
147
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
133
148
|
destroy(): Promise<void>;
|
|
@@ -240,6 +255,13 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
240
255
|
confirmPendingVoucherPayments?: boolean;
|
|
241
256
|
enhancePayload?: SubmitPayloadEnhancer;
|
|
242
257
|
}): Promise<T>;
|
|
258
|
+
saveSalesOrderDraft<T = any>(params?: {
|
|
259
|
+
platform?: string;
|
|
260
|
+
businessCode?: string;
|
|
261
|
+
channel?: string;
|
|
262
|
+
type?: string;
|
|
263
|
+
enhancePayload?: SubmitPayloadEnhancer;
|
|
264
|
+
}): Promise<T>;
|
|
243
265
|
submitTempOrderAsync<T = any>(params?: {
|
|
244
266
|
payments?: OrderPaymentSource[];
|
|
245
267
|
paymentStatus?: BaseSalesPaymentStatus;
|
|
@@ -258,16 +280,24 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
258
280
|
private queueLatestAutoPaymentSync;
|
|
259
281
|
private scheduleQueuedAutoPaymentSyncFlush;
|
|
260
282
|
private flushQueuedAutoPaymentSync;
|
|
261
|
-
/**
|
|
283
|
+
/**
|
|
284
|
+
* 同步兼容入口。无法等待 IoT 短号时,按调用当下的 device_id 或 LOCAL 生成。
|
|
285
|
+
*/
|
|
262
286
|
addOrderPayment(payment: OrderPaymentSource): OrderPaymentData[];
|
|
287
|
+
/** 创建新支付项时读取最新设备短号,不缓存运行时设备信息。 */
|
|
288
|
+
addOrderPaymentAsync(payment: OrderPaymentSource): Promise<OrderPaymentData[]>;
|
|
289
|
+
private addOrderPaymentWithDevicePrefix;
|
|
263
290
|
/** 更新当前订单中的指定支付项。 */
|
|
264
|
-
updateOrderPayment(paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any
|
|
291
|
+
updateOrderPayment(paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>, options?: BaseSalesUpdateOrderPaymentOptions): Promise<BaseSalesUpdateOrderPaymentResult>;
|
|
265
292
|
/** 删除当前订单中的指定支付项。 */
|
|
266
293
|
deleteOrderPayment(paymentIdentity: string | number): OrderPaymentData[];
|
|
267
294
|
/** 覆盖 wallet pass 支付项,同时保留普通支付项。 */
|
|
268
295
|
updateVoucherOrderPayments(payments: OrderPaymentSource[], options?: {
|
|
269
296
|
status?: 'paid' | 'payment_pending';
|
|
270
297
|
}): OrderPaymentData[];
|
|
298
|
+
updateVoucherOrderPaymentsAsync(payments: OrderPaymentSource[], options?: {
|
|
299
|
+
status?: 'paid' | 'payment_pending';
|
|
300
|
+
}): Promise<OrderPaymentData[]>;
|
|
271
301
|
confirmPendingVoucherPayments(): OrderPaymentData[];
|
|
272
302
|
discardPendingVoucherPayments(): OrderPaymentData[];
|
|
273
303
|
private getWalletProductList;
|
|
@@ -40,6 +40,8 @@ var import_decimal = __toESM(require("decimal.js"));
|
|
|
40
40
|
var import_lodash_es = require("lodash-es");
|
|
41
41
|
var import_types2 = require("../BookingByStep/types");
|
|
42
42
|
var import_utils = require("../../modules/Order/utils");
|
|
43
|
+
var import_payment_utils = require("../../modules/Order/payment-utils");
|
|
44
|
+
var import_payment_number = require("../../utils/payment-number");
|
|
43
45
|
var import_orderCollectionIdentity = require("../../modules/Order/utils/orderCollectionIdentity");
|
|
44
46
|
var import_dayjs = __toESM(require("dayjs"));
|
|
45
47
|
__reExport(BaseSales_exports, require("./types"), module.exports);
|
|
@@ -77,6 +79,11 @@ function isBaseSalesHistoricalDiscountEntry(discount) {
|
|
|
77
79
|
(discount == null ? void 0 : discount.isEditMode) || (discount == null ? void 0 : discount.isDisabled) || (discount == null ? void 0 : discount.order_discount_id) != null
|
|
78
80
|
);
|
|
79
81
|
}
|
|
82
|
+
function getBaseSalesUniqueArrayMetadataKey(key) {
|
|
83
|
+
if (key === "products" || key === "bookings")
|
|
84
|
+
return "unique_identification_number";
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
80
87
|
var BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND = {
|
|
81
88
|
product: "order_detail_id",
|
|
82
89
|
booking: "schedule_event_id",
|
|
@@ -150,6 +157,15 @@ function mergeBaseSalesCollectionItem(kind, currentItem, incomingItem, uidRemaps
|
|
|
150
157
|
return kind === "product" ? mergeBaseSalesProductSnapshotFields(currentItem, mergedItem) : mergedItem;
|
|
151
158
|
}
|
|
152
159
|
function mergeBaseSalesOrderCollection(kind, currentValue, incomingValue, strategy, uidRemaps) {
|
|
160
|
+
if (kind === "payment") {
|
|
161
|
+
return (0, import_payment_utils.mergeOrderPaymentListsByIdentity)(
|
|
162
|
+
currentValue,
|
|
163
|
+
incomingValue,
|
|
164
|
+
strategy === "preserve-local" ? { preserveUnmatchedExisting: true } : {
|
|
165
|
+
preserveUnmatchedExistingWhen: (payment) => (0, import_payment_utils.isIdentifiedPendingOrderPayment)(payment) || !(0, import_orderCollectionIdentity.getOrderCollectionPersistentId)("payment", payment)
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
}
|
|
153
169
|
const currentItems = (0, import_orderCollectionIdentity.normalizeOrderCollection)(kind, currentValue, {
|
|
154
170
|
ensureUid: false
|
|
155
171
|
}).items;
|
|
@@ -209,6 +225,35 @@ function normalizeBaseSalesRecordCollections(sourceRecord, options) {
|
|
|
209
225
|
}
|
|
210
226
|
return normalizedRecord;
|
|
211
227
|
}
|
|
228
|
+
function getBaseSalesMetadataUid(item, metadataKey) {
|
|
229
|
+
var _a;
|
|
230
|
+
const uid = ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a[metadataKey]) ?? (item == null ? void 0 : item[metadataKey]);
|
|
231
|
+
if (uid === void 0 || uid === null || uid === "")
|
|
232
|
+
return null;
|
|
233
|
+
return String(uid);
|
|
234
|
+
}
|
|
235
|
+
function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
|
|
236
|
+
const result = [];
|
|
237
|
+
const indexByUid = /* @__PURE__ */ new Map();
|
|
238
|
+
const appendOrReplaceByUid = (item) => {
|
|
239
|
+
const clonedItem = (0, import_lodash_es.cloneDeep)(item);
|
|
240
|
+
const uid = getBaseSalesMetadataUid(clonedItem, metadataKey);
|
|
241
|
+
if (!uid) {
|
|
242
|
+
result.push(clonedItem);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const existingIndex = indexByUid.get(uid);
|
|
246
|
+
if (existingIndex !== void 0) {
|
|
247
|
+
result[existingIndex] = clonedItem;
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
indexByUid.set(uid, result.length);
|
|
251
|
+
result.push(clonedItem);
|
|
252
|
+
};
|
|
253
|
+
currentValue.forEach(appendOrReplaceByUid);
|
|
254
|
+
loadedValue.forEach(appendOrReplaceByUid);
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
212
257
|
function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, strategy) {
|
|
213
258
|
const normalizedLoadedRecord = normalizeBaseSalesRecordCollections(
|
|
214
259
|
loadedRecord || {},
|
|
@@ -237,6 +282,15 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, str
|
|
|
237
282
|
);
|
|
238
283
|
}
|
|
239
284
|
if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
|
|
285
|
+
if (key === "payments" || key === "payment") {
|
|
286
|
+
return (0, import_payment_utils.mergeOrderPaymentListsByIdentity)(currentValue, loadedValue, {
|
|
287
|
+
preserveUnmatchedExisting: true
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
const metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
|
|
291
|
+
if (metadataKey) {
|
|
292
|
+
return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
|
|
293
|
+
}
|
|
240
294
|
return [
|
|
241
295
|
...(0, import_lodash_es.cloneDeep)(currentValue),
|
|
242
296
|
...(0, import_lodash_es.cloneDeep)(loadedValue)
|
|
@@ -255,6 +309,18 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, str
|
|
|
255
309
|
(0, import_orderCollectionIdentity.applyOrderCollectionUidRemaps)(mergedRecord, uidRemaps)
|
|
256
310
|
);
|
|
257
311
|
}
|
|
312
|
+
function filterPendingPaymentsFromLoadedSalesDetail(sourceRecord) {
|
|
313
|
+
if (!sourceRecord || typeof sourceRecord !== "object")
|
|
314
|
+
return sourceRecord;
|
|
315
|
+
const record = { ...sourceRecord };
|
|
316
|
+
if (Array.isArray(sourceRecord.payments)) {
|
|
317
|
+
record.payments = sourceRecord.payments.filter((payment) => !(0, import_payment_utils.isPendingOrderPayment)(payment));
|
|
318
|
+
}
|
|
319
|
+
if (Array.isArray(sourceRecord.payment)) {
|
|
320
|
+
record.payment = sourceRecord.payment.filter((payment) => !(0, import_payment_utils.isPendingOrderPayment)(payment));
|
|
321
|
+
}
|
|
322
|
+
return record;
|
|
323
|
+
}
|
|
258
324
|
var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
259
325
|
constructor(name, version) {
|
|
260
326
|
super(name, version);
|
|
@@ -796,6 +862,16 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
796
862
|
const coreData = (_f = (_d = (_c = app == null ? void 0 : app.models) == null ? void 0 : _c.getStore) == null ? void 0 : (_e = _d.call(_c)).getDataByModel) == null ? void 0 : _f.call(_e, "core", "core");
|
|
797
863
|
return coreData == null ? void 0 : coreData[key];
|
|
798
864
|
}
|
|
865
|
+
getPaymentNumberDevicePrefixSync() {
|
|
866
|
+
if (!this.appPlugin)
|
|
867
|
+
return "LOCAL";
|
|
868
|
+
return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)((key) => this.getAppData(key));
|
|
869
|
+
}
|
|
870
|
+
getPaymentNumberDevicePrefixAsync() {
|
|
871
|
+
if (!this.appPlugin)
|
|
872
|
+
return Promise.resolve("LOCAL");
|
|
873
|
+
return (0, import_payment_number.resolvePaymentNumberDevicePrefix)((key) => this.getAppData(key));
|
|
874
|
+
}
|
|
799
875
|
syncAppDataToTempOrder(tempOrder) {
|
|
800
876
|
const isPriceIncludeTax = this.getAppData("is_price_include_tax");
|
|
801
877
|
const taxCountryCode = this.getAppData("tax_country_code");
|
|
@@ -930,13 +1006,16 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
930
1006
|
const message = loadedRecord && (loadedRecord.message || loadedRecord.msg) || `加载销售详情失败: ${lookup}`;
|
|
931
1007
|
throw new Error(message);
|
|
932
1008
|
}
|
|
933
|
-
const remoteRecord =
|
|
1009
|
+
const remoteRecord = filterPendingPaymentsFromLoadedSalesDetail(
|
|
1010
|
+
preloadedSalesDetail ?? loadedRecord.data
|
|
1011
|
+
);
|
|
934
1012
|
const currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
|
|
935
|
-
const
|
|
1013
|
+
const mergedRecord = params.merge ? mergeSalesDetailRecordWithTempOrder(
|
|
936
1014
|
currentTempOrder,
|
|
937
1015
|
remoteRecord,
|
|
938
1016
|
"preserve-local"
|
|
939
1017
|
) : remoteRecord;
|
|
1018
|
+
const record = filterPendingPaymentsFromLoadedSalesDetail(mergedRecord);
|
|
940
1019
|
return await this.hydrateLatestLoadedSalesDetail(record, loadSequence);
|
|
941
1020
|
} finally {
|
|
942
1021
|
this.salesDetailLoadInFlightCount = Math.max(
|
|
@@ -1727,6 +1806,20 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1727
1806
|
};
|
|
1728
1807
|
return this.store.order.submitTempOrder(submitParams);
|
|
1729
1808
|
}
|
|
1809
|
+
async saveSalesOrderDraft(params) {
|
|
1810
|
+
var _a, _b, _c, _d;
|
|
1811
|
+
if (!this.store.order) {
|
|
1812
|
+
throw new Error("BaseSales 解决方案需要 order 模块支持");
|
|
1813
|
+
}
|
|
1814
|
+
return this.store.order.saveTempOrderAsDraft({
|
|
1815
|
+
cacheId: this.cacheId,
|
|
1816
|
+
platform: (params == null ? void 0 : params.platform) ?? ((_a = this.otherParams) == null ? void 0 : _a.platform),
|
|
1817
|
+
businessCode: (params == null ? void 0 : params.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.businessCode) ?? ((_c = this.otherParams) == null ? void 0 : _c.business_code),
|
|
1818
|
+
channel: (params == null ? void 0 : params.channel) ?? this.getSubmitOrderSalesChannel(),
|
|
1819
|
+
type: (params == null ? void 0 : params.type) ?? ((_d = this.otherParams) == null ? void 0 : _d.type),
|
|
1820
|
+
...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1730
1823
|
async submitTempOrderAsync(params) {
|
|
1731
1824
|
var _a, _b, _c, _d;
|
|
1732
1825
|
if (!this.store.order) {
|
|
@@ -1927,8 +2020,26 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1927
2020
|
}
|
|
1928
2021
|
}
|
|
1929
2022
|
}
|
|
1930
|
-
/**
|
|
2023
|
+
/**
|
|
2024
|
+
* 同步兼容入口。无法等待 IoT 短号时,按调用当下的 device_id 或 LOCAL 生成。
|
|
2025
|
+
*/
|
|
1931
2026
|
addOrderPayment(payment) {
|
|
2027
|
+
const hasPaymentNumber = String(
|
|
2028
|
+
payment.payment_number || ""
|
|
2029
|
+
).trim() !== "";
|
|
2030
|
+
return this.addOrderPaymentWithDevicePrefix(
|
|
2031
|
+
payment,
|
|
2032
|
+
hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
|
|
2033
|
+
);
|
|
2034
|
+
}
|
|
2035
|
+
/** 创建新支付项时读取最新设备短号,不缓存运行时设备信息。 */
|
|
2036
|
+
async addOrderPaymentAsync(payment) {
|
|
2037
|
+
const paymentRecord = payment;
|
|
2038
|
+
const hasPaymentNumber = String(paymentRecord.payment_number || "").trim() !== "";
|
|
2039
|
+
const devicePrefix = hasPaymentNumber ? "LOCAL" : await this.getPaymentNumberDevicePrefixAsync();
|
|
2040
|
+
return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
|
|
2041
|
+
}
|
|
2042
|
+
addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
|
|
1932
2043
|
var _a;
|
|
1933
2044
|
if (!this.store.order)
|
|
1934
2045
|
throw new Error("order 模块未初始化");
|
|
@@ -1945,21 +2056,26 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1945
2056
|
if (shopWalletPassId !== void 0 && shopWalletPassId !== null) {
|
|
1946
2057
|
metadata.shop_wallet_pass_id = shopWalletPassId;
|
|
1947
2058
|
}
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
2059
|
+
const normalizedPaymentRecord = (0, import_payment_utils.ensureOrderPaymentNumber)(
|
|
2060
|
+
paymentRecord,
|
|
2061
|
+
devicePrefix,
|
|
2062
|
+
import_utils.createUuidV4
|
|
2063
|
+
);
|
|
1951
2064
|
const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
1952
2065
|
const paymentTime = paymentRecord.payment_time ?? paymentTimestamp;
|
|
1953
2066
|
const createdAt = paymentRecord.created_at ?? paymentTimestamp;
|
|
1954
2067
|
const serviceCharge = paymentRecord.service_charge && typeof paymentRecord.service_charge === "object" ? paymentRecord.service_charge : null;
|
|
1955
2068
|
const calculatedServiceFee = serviceCharge ? new import_decimal.default(paymentRecord.origin_amount ?? paymentRecord.amount ?? 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : void 0;
|
|
1956
2069
|
const payments = this.store.order.addOrderPayment({
|
|
1957
|
-
...
|
|
2070
|
+
...normalizedPaymentRecord,
|
|
1958
2071
|
...calculatedServiceFee !== void 0 ? { service_fee: calculatedServiceFee } : {},
|
|
1959
2072
|
metadata,
|
|
1960
2073
|
payment_time: paymentTime,
|
|
1961
2074
|
created_at: createdAt
|
|
1962
2075
|
});
|
|
2076
|
+
if (paymentRecord.status === "payment_pending") {
|
|
2077
|
+
return payments;
|
|
2078
|
+
}
|
|
1963
2079
|
const amountSnapshot = this.store.order.getOrderAmountSnapshot();
|
|
1964
2080
|
const syncState = this.store.order.getOrderSyncState();
|
|
1965
2081
|
if (amountSnapshot) {
|
|
@@ -1981,10 +2097,73 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1981
2097
|
return payments;
|
|
1982
2098
|
}
|
|
1983
2099
|
/** 更新当前订单中的指定支付项。 */
|
|
1984
|
-
updateOrderPayment(paymentIdentity, updates) {
|
|
2100
|
+
async updateOrderPayment(paymentIdentity, updates, options = {}) {
|
|
2101
|
+
var _a, _b, _c;
|
|
1985
2102
|
if (!this.store.order)
|
|
1986
2103
|
throw new Error("order 模块未初始化");
|
|
1987
|
-
|
|
2104
|
+
const matchMode = options.matchBy === "compat" || options.matchBy === "legacy" ? "compat" : "payment_number";
|
|
2105
|
+
const previousMatch = (0, import_payment_utils.resolveOrderPaymentIdentity)(
|
|
2106
|
+
this.store.order.getOrderPayments(),
|
|
2107
|
+
paymentIdentity,
|
|
2108
|
+
matchMode
|
|
2109
|
+
);
|
|
2110
|
+
const previousPayment = previousMatch == null ? void 0 : previousMatch.payment;
|
|
2111
|
+
if ((previousPayment == null ? void 0 : previousPayment.status) === "paid" && !options.applyUpdatesWhenPaid) {
|
|
2112
|
+
const currentPayments = this.store.order.getOrderPayments();
|
|
2113
|
+
let syncResult2;
|
|
2114
|
+
if (options.submitWhenPaid && options.forceSubmitIfPaid) {
|
|
2115
|
+
syncResult2 = await this.syncPaymentsToOrder({
|
|
2116
|
+
payments: currentPayments,
|
|
2117
|
+
paymentStatus: this.getPaymentStatusForSync(currentPayments),
|
|
2118
|
+
submitWhenPaid: true,
|
|
2119
|
+
smallTicketDataFlag: options.smallTicketDataFlag ?? 1
|
|
2120
|
+
});
|
|
2121
|
+
}
|
|
2122
|
+
return {
|
|
2123
|
+
updated: false,
|
|
2124
|
+
payment: previousPayment,
|
|
2125
|
+
payments: currentPayments,
|
|
2126
|
+
summary: ((_a = this.store.order.getOrderAmountSnapshot()) == null ? void 0 : _a.summary) || null,
|
|
2127
|
+
...syncResult2 !== void 0 ? { syncResult: syncResult2 } : {}
|
|
2128
|
+
};
|
|
2129
|
+
}
|
|
2130
|
+
const result = await this.store.order.updateOrderPayment(paymentIdentity, updates, {
|
|
2131
|
+
matchBy: matchMode
|
|
2132
|
+
});
|
|
2133
|
+
let draftResult;
|
|
2134
|
+
let draftError;
|
|
2135
|
+
if (options.persistDraft !== false) {
|
|
2136
|
+
try {
|
|
2137
|
+
draftResult = await this.saveSalesOrderDraft();
|
|
2138
|
+
} catch (error) {
|
|
2139
|
+
draftError = error;
|
|
2140
|
+
this.logError("updateOrderPayment: 保存支付草稿失败", {
|
|
2141
|
+
paymentIdentity,
|
|
2142
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2143
|
+
});
|
|
2144
|
+
if (!options.submitWhenPaid)
|
|
2145
|
+
throw error;
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
const becamePaid = (previousPayment == null ? void 0 : previousPayment.status) !== "paid" && ((_b = result.payment) == null ? void 0 : _b.status) === "paid";
|
|
2149
|
+
const shouldSubmit = Boolean(
|
|
2150
|
+
options.submitWhenPaid && ((_c = result.payment) == null ? void 0 : _c.status) === "paid" && (becamePaid || options.forceSubmitIfPaid)
|
|
2151
|
+
);
|
|
2152
|
+
let syncResult;
|
|
2153
|
+
if (shouldSubmit) {
|
|
2154
|
+
syncResult = await this.syncPaymentsToOrder({
|
|
2155
|
+
payments: result.payments,
|
|
2156
|
+
paymentStatus: this.getPaymentStatusForSync(result.payments),
|
|
2157
|
+
submitWhenPaid: true,
|
|
2158
|
+
smallTicketDataFlag: options.smallTicketDataFlag ?? 1
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
return {
|
|
2162
|
+
...result,
|
|
2163
|
+
...draftResult !== void 0 ? { draftResult } : {},
|
|
2164
|
+
...draftError !== void 0 ? { draftError } : {},
|
|
2165
|
+
...syncResult !== void 0 ? { syncResult } : {}
|
|
2166
|
+
};
|
|
1988
2167
|
}
|
|
1989
2168
|
/** 删除当前订单中的指定支付项。 */
|
|
1990
2169
|
deleteOrderPayment(paymentIdentity) {
|
|
@@ -1998,6 +2177,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1998
2177
|
throw new Error("order 模块未初始化");
|
|
1999
2178
|
return this.store.order.updateVoucherOrderPayments(payments, options);
|
|
2000
2179
|
}
|
|
2180
|
+
async updateVoucherOrderPaymentsAsync(payments, options) {
|
|
2181
|
+
if (!this.store.order)
|
|
2182
|
+
throw new Error("order 模块未初始化");
|
|
2183
|
+
return this.store.order.updateVoucherOrderPaymentsAsync(payments, options);
|
|
2184
|
+
}
|
|
2001
2185
|
confirmPendingVoucherPayments() {
|
|
2002
2186
|
if (!this.store.order)
|
|
2003
2187
|
throw new Error("order 模块未初始化");
|
|
@@ -82,8 +82,13 @@ export interface ISalesBooking {
|
|
|
82
82
|
metadata?: Record<string, any> | null;
|
|
83
83
|
[key: string]: any;
|
|
84
84
|
}
|
|
85
|
+
export interface ISalesPaymentMetadata extends Record<string, any> {
|
|
86
|
+
/** 刷卡机设备快照;OS 不解析内部字段 */
|
|
87
|
+
card_reader_snapshot?: Record<string, unknown>;
|
|
88
|
+
}
|
|
85
89
|
export interface ISalesPayment {
|
|
86
90
|
order_payment_id?: number | null;
|
|
91
|
+
payment_number?: string;
|
|
87
92
|
custom_payment_id?: number;
|
|
88
93
|
code?: string;
|
|
89
94
|
name?: string;
|
|
@@ -95,7 +100,7 @@ export interface ISalesPayment {
|
|
|
95
100
|
status?: string;
|
|
96
101
|
payment_time?: string | null;
|
|
97
102
|
service_charge?: Record<string, any> | null;
|
|
98
|
-
metadata?:
|
|
103
|
+
metadata?: ISalesPaymentMetadata | null;
|
|
99
104
|
[key: string]: any;
|
|
100
105
|
}
|
|
101
106
|
export interface ISalesSurcharge {
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -1153,7 +1153,8 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
|
|
|
1153
1153
|
}
|
|
1154
1154
|
/** 读取当前 booking config。 */
|
|
1155
1155
|
getBookingConfig() {
|
|
1156
|
-
|
|
1156
|
+
var _a;
|
|
1157
|
+
return (_a = this.store.bookingContext) == null ? void 0 : _a.getBookingConfig();
|
|
1157
1158
|
}
|
|
1158
1159
|
/** 写入资源全集(来源:`/form/schedule`),同步派生 resourcesOriginMap。 */
|
|
1159
1160
|
setResources(resources) {
|
|
@@ -83,6 +83,7 @@ export declare class SalesImpl extends BaseModule implements Module, SalesModule
|
|
|
83
83
|
private getBookingAppointmentStatus;
|
|
84
84
|
private isBookingIncludedInStats;
|
|
85
85
|
private getBookingOrderPaymentStatus;
|
|
86
|
+
private isUnpaidBooking;
|
|
86
87
|
private countBookingOrders;
|
|
87
88
|
private countCompletedBookings;
|
|
88
89
|
private groupBookingsByResource;
|
|
@@ -39,6 +39,7 @@ var import_dayjs = __toESM(require("dayjs"));
|
|
|
39
39
|
var import_BaseModule = require("../../modules/BaseModule");
|
|
40
40
|
var import_types = require("./types");
|
|
41
41
|
__reExport(Sales_exports, require("./types"), module.exports);
|
|
42
|
+
var UNPAID_PAYMENT_STATUSES = /* @__PURE__ */ new Set(["unpaid", "partially_paid", "payment_processing"]);
|
|
42
43
|
var SalesImpl = class extends import_BaseModule.BaseModule {
|
|
43
44
|
// LoggerManager 实例
|
|
44
45
|
constructor(name, version) {
|
|
@@ -258,6 +259,9 @@ var SalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
258
259
|
var _a;
|
|
259
260
|
return String(((_a = booking.order) == null ? void 0 : _a.payment_status) ?? "");
|
|
260
261
|
}
|
|
262
|
+
isUnpaidBooking(booking) {
|
|
263
|
+
return UNPAID_PAYMENT_STATUSES.has(this.getBookingOrderPaymentStatus(booking));
|
|
264
|
+
}
|
|
261
265
|
countBookingOrders(bookings) {
|
|
262
266
|
const orderIds = /* @__PURE__ */ new Set();
|
|
263
267
|
bookings.forEach((booking) => {
|
|
@@ -631,9 +635,7 @@ var SalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
631
635
|
const completedBookingList = matchedBookingList.filter(
|
|
632
636
|
(booking) => this.getBookingAppointmentStatus(booking) === "completed"
|
|
633
637
|
);
|
|
634
|
-
const unpaidBookingList = matchedBookingList.filter(
|
|
635
|
-
(booking) => this.getBookingOrderPaymentStatus(booking) === "unpaid" || this.getBookingOrderPaymentStatus(booking) === "payment_processing"
|
|
636
|
-
);
|
|
638
|
+
const unpaidBookingList = matchedBookingList.filter((booking) => this.isUnpaidBooking(booking));
|
|
637
639
|
const bookings = this.pickBookingsForCurrentPoint(
|
|
638
640
|
current,
|
|
639
641
|
this.normalizeResourceBookings(current, deviceCurrent, matchedBookingList)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type PaymentNumberAppDataGetter = (key: string) => unknown;
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the synchronous fallback without caching runtime device data.
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolvePaymentNumberDevicePrefixFromDeviceId(getAppData: PaymentNumberAppDataGetter): string;
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the latest device segment when a new payment number is generated.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolvePaymentNumberDevicePrefix(getAppData: PaymentNumberAppDataGetter): Promise<string>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/payment-number.ts
|
|
20
|
+
var payment_number_exports = {};
|
|
21
|
+
__export(payment_number_exports, {
|
|
22
|
+
resolvePaymentNumberDevicePrefix: () => resolvePaymentNumberDevicePrefix,
|
|
23
|
+
resolvePaymentNumberDevicePrefixFromDeviceId: () => resolvePaymentNumberDevicePrefixFromDeviceId
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(payment_number_exports);
|
|
26
|
+
function normalizeNonEmptyString(value) {
|
|
27
|
+
if (value === void 0 || value === null)
|
|
28
|
+
return null;
|
|
29
|
+
if (typeof value !== "string" && typeof value !== "number")
|
|
30
|
+
return null;
|
|
31
|
+
if (typeof value === "number" && !Number.isFinite(value))
|
|
32
|
+
return null;
|
|
33
|
+
const normalized = String(value).trim();
|
|
34
|
+
return normalized || null;
|
|
35
|
+
}
|
|
36
|
+
function resolvePaymentNumberDevicePrefixFromDeviceId(getAppData) {
|
|
37
|
+
try {
|
|
38
|
+
const deviceId = normalizeNonEmptyString(getAppData("device_id"));
|
|
39
|
+
if (deviceId && deviceId !== "0")
|
|
40
|
+
return deviceId.slice(-2);
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
return "LOCAL";
|
|
44
|
+
}
|
|
45
|
+
async function resolvePaymentNumberDevicePrefix(getAppData) {
|
|
46
|
+
try {
|
|
47
|
+
const getAsyncIotDeviceInfo = getAppData("async_iot_device_info");
|
|
48
|
+
if (typeof getAsyncIotDeviceInfo === "function") {
|
|
49
|
+
const info = await getAsyncIotDeviceInfo();
|
|
50
|
+
const shortNumber = normalizeNonEmptyString(
|
|
51
|
+
info == null ? void 0 : info.short_number
|
|
52
|
+
);
|
|
53
|
+
if (shortNumber && shortNumber !== "0")
|
|
54
|
+
return shortNumber;
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
return resolvePaymentNumberDevicePrefixFromDeviceId(getAppData);
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
resolvePaymentNumberDevicePrefix,
|
|
63
|
+
resolvePaymentNumberDevicePrefixFromDeviceId
|
|
64
|
+
});
|