@pisell/pisellos 2.3.28 → 2.3.30

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.
Files changed (57) hide show
  1. package/dist/modules/Order/index.d.ts +32 -8
  2. package/dist/modules/Order/index.js +883 -521
  3. package/dist/modules/Order/payment-utils.d.ts +23 -0
  4. package/dist/modules/Order/payment-utils.js +203 -0
  5. package/dist/modules/Order/types.d.ts +33 -1
  6. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  7. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  8. package/dist/modules/Order/utils.d.ts +2 -1
  9. package/dist/modules/Order/utils.js +6 -12
  10. package/dist/modules/Payment/index.d.ts +2 -0
  11. package/dist/modules/Payment/index.js +78 -49
  12. package/dist/modules/Payment/types.d.ts +26 -24
  13. package/dist/modules/Payment/types.js +2 -0
  14. package/dist/modules/Product/index.d.ts +1 -1
  15. package/dist/server/index.d.ts +14 -0
  16. package/dist/server/index.js +1826 -1000
  17. package/dist/server/modules/order/index.d.ts +47 -4
  18. package/dist/server/modules/order/index.js +1415 -711
  19. package/dist/server/modules/order/types.d.ts +11 -3
  20. package/dist/server/modules/order/types.js +1 -1
  21. package/dist/solution/BaseSales/index.d.ts +40 -4
  22. package/dist/solution/BaseSales/index.js +1268 -749
  23. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  24. package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
  25. package/dist/solution/BookingByStep/index.d.ts +1 -1
  26. package/dist/solution/BookingTicket/index.d.ts +13 -1
  27. package/dist/solution/BookingTicket/index.js +2 -1
  28. package/dist/utils/payment-number.d.ts +9 -0
  29. package/dist/utils/payment-number.js +69 -0
  30. package/lib/modules/Order/index.d.ts +32 -8
  31. package/lib/modules/Order/index.js +270 -64
  32. package/lib/modules/Order/payment-utils.d.ts +23 -0
  33. package/lib/modules/Order/payment-utils.js +193 -0
  34. package/lib/modules/Order/types.d.ts +33 -1
  35. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  36. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  37. package/lib/modules/Order/utils.d.ts +2 -1
  38. package/lib/modules/Order/utils.js +6 -14
  39. package/lib/modules/Payment/index.d.ts +2 -0
  40. package/lib/modules/Payment/index.js +33 -12
  41. package/lib/modules/Payment/types.d.ts +26 -24
  42. package/lib/modules/Product/index.d.ts +1 -1
  43. package/lib/server/index.d.ts +14 -0
  44. package/lib/server/index.js +604 -8
  45. package/lib/server/modules/order/index.d.ts +47 -4
  46. package/lib/server/modules/order/index.js +578 -116
  47. package/lib/server/modules/order/types.d.ts +11 -3
  48. package/lib/solution/BaseSales/index.d.ts +40 -4
  49. package/lib/solution/BaseSales/index.js +363 -37
  50. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  51. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
  52. package/lib/solution/BookingByStep/index.d.ts +1 -1
  53. package/lib/solution/BookingTicket/index.d.ts +13 -1
  54. package/lib/solution/BookingTicket/index.js +2 -1
  55. package/lib/utils/payment-number.d.ts +9 -0
  56. package/lib/utils/payment-number.js +64 -0
  57. package/package.json +1 -1
@@ -0,0 +1,193 @@
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/modules/Order/payment-utils.ts
20
+ var payment_utils_exports = {};
21
+ __export(payment_utils_exports, {
22
+ ensureOrderPaymentNumber: () => ensureOrderPaymentNumber,
23
+ getOrderPaymentIdentityKeys: () => getOrderPaymentIdentityKeys,
24
+ hasOrderPaymentIdentityOverlap: () => hasOrderPaymentIdentityOverlap,
25
+ mergeOrderPaymentListsByIdentity: () => mergeOrderPaymentListsByIdentity,
26
+ mergeOrderPaymentRecord: () => mergeOrderPaymentRecord,
27
+ mergeOrderPaymentSnapshot: () => mergeOrderPaymentSnapshot,
28
+ mergeOrderPaymentTransactions: () => mergeOrderPaymentTransactions,
29
+ resolveOrderPaymentIdentity: () => resolveOrderPaymentIdentity
30
+ });
31
+ module.exports = __toCommonJS(payment_utils_exports);
32
+ var PAYMENT_IDENTITY_TYPES = [
33
+ "payment_number",
34
+ "order_payment_id",
35
+ "unique_payment_number"
36
+ ];
37
+ function normalizePaymentIdentityValue(value) {
38
+ if (value === void 0 || value === null || value === "")
39
+ return null;
40
+ return String(value);
41
+ }
42
+ function getPaymentIdentityValue(payment, type) {
43
+ var _a;
44
+ if (type === "unique_payment_number") {
45
+ return (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
46
+ }
47
+ return payment == null ? void 0 : payment[type];
48
+ }
49
+ function getOrderPaymentIdentityKeys(payment) {
50
+ const record = payment;
51
+ if (!record)
52
+ return [];
53
+ return PAYMENT_IDENTITY_TYPES.flatMap((type) => {
54
+ const value = normalizePaymentIdentityValue(getPaymentIdentityValue(record, type));
55
+ return value === null ? [] : [`${type}:${value}`];
56
+ });
57
+ }
58
+ function hasOrderPaymentIdentityOverlap(left, right) {
59
+ const leftKeys = new Set(getOrderPaymentIdentityKeys(left));
60
+ if (leftKeys.size === 0)
61
+ return false;
62
+ return getOrderPaymentIdentityKeys(right).some((key) => leftKeys.has(key));
63
+ }
64
+ function resolveOrderPaymentIdentity(payments, identity, mode = "payment_number") {
65
+ const target = String(identity);
66
+ const identityTypes = mode === "payment_number" ? ["payment_number"] : PAYMENT_IDENTITY_TYPES;
67
+ const matchesByIndex = /* @__PURE__ */ new Map();
68
+ for (const type of identityTypes) {
69
+ (payments || []).forEach((payment, index) => {
70
+ const value = normalizePaymentIdentityValue(getPaymentIdentityValue(payment, type));
71
+ if (value === target && !matchesByIndex.has(index)) {
72
+ matchesByIndex.set(index, { index, payment, matchedBy: type });
73
+ }
74
+ });
75
+ }
76
+ const matches = [...matchesByIndex.values()];
77
+ if (matches.length > 1) {
78
+ throw new Error(`支付项身份存在歧义: ${target}`);
79
+ }
80
+ return matches[0] || null;
81
+ }
82
+ function ensureOrderPaymentNumber(payment, devicePrefix, createPaymentNumber) {
83
+ const existing = normalizePaymentIdentityValue(payment.payment_number);
84
+ if (existing)
85
+ return { ...payment, payment_number: existing };
86
+ const uuid = normalizePaymentIdentityValue(payment.uuid) || createPaymentNumber();
87
+ const prefix = normalizePaymentIdentityValue(devicePrefix) || "LOCAL";
88
+ return { ...payment, payment_number: `${prefix}_${uuid}` };
89
+ }
90
+ function mergeOrderPaymentTransactions(current, incoming) {
91
+ const records = /* @__PURE__ */ new Map();
92
+ const append = (value) => {
93
+ if (!Array.isArray(value))
94
+ return;
95
+ value.forEach((item) => {
96
+ const number = item && typeof item === "object" ? String(item.number || "") : "";
97
+ const status = item && typeof item === "object" ? item.status : void 0;
98
+ if (!number || status !== "success" && status !== "fail")
99
+ return;
100
+ const previous = records.get(number);
101
+ if ((previous == null ? void 0 : previous.status) === "success" && status === "fail")
102
+ return;
103
+ records.set(number, { number, status });
104
+ });
105
+ };
106
+ append(current);
107
+ append(incoming);
108
+ return [...records.values()];
109
+ }
110
+ function mergeOrderPaymentRecord(payment, updates) {
111
+ const currentMetadata = payment.metadata || {};
112
+ const incomingMetadata = updates.metadata || {};
113
+ const transactions = mergeOrderPaymentTransactions(
114
+ currentMetadata.transactions,
115
+ incomingMetadata.transactions
116
+ );
117
+ const currentPaid = payment.status === "paid";
118
+ const nextStatus = currentPaid && updates.status !== "paid" ? "paid" : updates.status ?? payment.status;
119
+ return {
120
+ ...payment,
121
+ ...updates,
122
+ status: nextStatus,
123
+ updated_at: updates.updated_at ?? payment.updated_at,
124
+ metadata: {
125
+ ...currentMetadata,
126
+ ...incomingMetadata,
127
+ ...transactions.length > 0 || Array.isArray(incomingMetadata.transactions) ? { transactions } : {}
128
+ }
129
+ };
130
+ }
131
+ function mergeOrderPaymentSnapshot(current, incoming) {
132
+ const currentMetadata = current.metadata || {};
133
+ const incomingMetadata = incoming.metadata || {};
134
+ const transactions = mergeOrderPaymentTransactions(
135
+ currentMetadata.transactions,
136
+ incomingMetadata.transactions
137
+ );
138
+ return {
139
+ ...current,
140
+ ...incoming,
141
+ payment_number: incoming.payment_number || current.payment_number,
142
+ metadata: {
143
+ ...currentMetadata,
144
+ ...incomingMetadata,
145
+ ...transactions.length > 0 ? { transactions } : {}
146
+ }
147
+ };
148
+ }
149
+ function compactOrderPaymentList(payments) {
150
+ const result = [];
151
+ for (const payment of payments) {
152
+ const matchingIndexes = result.flatMap((existing, index) => hasOrderPaymentIdentityOverlap(existing, payment) ? [index] : []);
153
+ if (matchingIndexes.length === 0) {
154
+ result.push(mergeOrderPaymentSnapshot({}, payment));
155
+ continue;
156
+ }
157
+ const firstIndex = matchingIndexes[0];
158
+ let merged = result[firstIndex];
159
+ for (const index of matchingIndexes.slice(1)) {
160
+ merged = mergeOrderPaymentSnapshot(merged, result[index]);
161
+ }
162
+ result[firstIndex] = mergeOrderPaymentSnapshot(merged, payment);
163
+ for (const index of matchingIndexes.slice(1).sort((a, b) => b - a)) {
164
+ result.splice(index, 1);
165
+ }
166
+ }
167
+ return result;
168
+ }
169
+ function mergeOrderPaymentListsByIdentity(existing, incoming, options = {}) {
170
+ const existingList = compactOrderPaymentList([...existing || []]);
171
+ const incomingList = compactOrderPaymentList([...incoming || []]);
172
+ if (options.preserveUnmatchedExisting) {
173
+ return compactOrderPaymentList([...existingList, ...incomingList]);
174
+ }
175
+ return compactOrderPaymentList(incomingList.map((incomingPayment) => {
176
+ const matchingExisting = existingList.filter((existingPayment) => hasOrderPaymentIdentityOverlap(existingPayment, incomingPayment));
177
+ return matchingExisting.reduce(
178
+ (merged, existingPayment) => mergeOrderPaymentSnapshot(existingPayment, merged),
179
+ incomingPayment
180
+ );
181
+ }));
182
+ }
183
+ // Annotate the CommonJS export names for ESM import in node:
184
+ 0 && (module.exports = {
185
+ ensureOrderPaymentNumber,
186
+ getOrderPaymentIdentityKeys,
187
+ hasOrderPaymentIdentityOverlap,
188
+ mergeOrderPaymentListsByIdentity,
189
+ mergeOrderPaymentRecord,
190
+ mergeOrderPaymentSnapshot,
191
+ mergeOrderPaymentTransactions,
192
+ resolveOrderPaymentIdentity
193
+ });
@@ -467,6 +467,8 @@ export interface SubmitSalesOrderParams {
467
467
  export interface PaymentItemData {
468
468
  /** 当前支付项的唯一 ID */
469
469
  uuid: string;
470
+ /** 支付项稳定唯一号 */
471
+ payment_number?: string;
470
472
  /** 当前支付方式付出去多少钱 */
471
473
  amount: string;
472
474
  /** 支付类型代码 */
@@ -489,13 +491,22 @@ export interface PaymentItemData {
489
491
  export interface OrderPaymentMetadata {
490
492
  rounding_rule?: Record<string, any>;
491
493
  unique_payment_number?: string;
494
+ /** 刷卡机设备快照;OS 不解析内部字段,仅透传并持久化 */
495
+ card_reader_snapshot?: Record<string, unknown>;
492
496
  shop_wallet_pass_id?: number | string;
493
497
  actual_paid_amount?: number | string;
494
498
  change_given_amount?: number | string;
499
+ transactions?: OrderPaymentTransaction[];
495
500
  [key: string]: any;
496
501
  }
502
+ export interface OrderPaymentTransaction {
503
+ number: string;
504
+ status: 'success' | 'fail';
505
+ }
497
506
  export interface OrderPaymentData {
498
507
  order_payment_id?: number | string;
508
+ /** 支付项稳定唯一号;历史支付项允许缺失 */
509
+ payment_number?: string;
499
510
  amount: string;
500
511
  code: string;
501
512
  custom_payment_id: number;
@@ -522,6 +533,15 @@ export interface OrderPaymentData {
522
533
  created_at?: string;
523
534
  updated_at?: string;
524
535
  }
536
+ export interface OrderPaymentUpdateOptions {
537
+ matchBy?: 'payment_number' | 'compat' | 'legacy';
538
+ }
539
+ export interface OrderPaymentUpdateResult {
540
+ updated: boolean;
541
+ payment: OrderPaymentData | null;
542
+ payments: OrderPaymentData[];
543
+ summary: OrderSummary | null;
544
+ }
525
545
  export type OrderPaymentSource = PaymentItem | OrderPaymentData | Record<string, any>;
526
546
  export interface MapOrderPaymentsOptions {
527
547
  includeVoided?: boolean;
@@ -672,6 +692,14 @@ export interface OrderModuleAPI {
672
692
  channel?: string;
673
693
  type?: string;
674
694
  }) => OrderSubmitPayload;
695
+ saveTempOrderAsDraft: <T = any>(params?: {
696
+ cacheId?: string;
697
+ platform?: string;
698
+ businessCode?: string;
699
+ channel?: string;
700
+ type?: string;
701
+ enhancePayload?: SubmitPayloadEnhancer;
702
+ }) => Promise<T>;
675
703
  applyLocalPrintOrderNumbers: (order?: Record<string, any> | null) => Promise<OrderTempOrder>;
676
704
  getTempOrderNote: () => string;
677
705
  updateTempOrderNote: {
@@ -729,11 +757,15 @@ export interface OrderModuleAPI {
729
757
  getOrderPayments: () => OrderPaymentData[];
730
758
  setOrderPayments: (payments: OrderPaymentSource[]) => OrderPaymentData[];
731
759
  addOrderPayment: (payment: OrderPaymentSource) => OrderPaymentData[];
732
- updateOrderPayment: (paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>) => OrderPaymentData[];
760
+ addOrderPaymentAsync: (payment: OrderPaymentSource) => Promise<OrderPaymentData[]>;
761
+ updateOrderPayment: (paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>, options?: OrderPaymentUpdateOptions) => Promise<OrderPaymentUpdateResult>;
733
762
  deleteOrderPayment: (paymentIdentity: string | number) => OrderPaymentData[];
734
763
  updateVoucherOrderPayments: (payments: OrderPaymentSource[], options?: {
735
764
  status?: 'paid' | 'payment_pending';
736
765
  }) => OrderPaymentData[];
766
+ updateVoucherOrderPaymentsAsync: (payments: OrderPaymentSource[], options?: {
767
+ status?: 'paid' | 'payment_pending';
768
+ }) => Promise<OrderPaymentData[]>;
737
769
  confirmPendingVoucherPayments: (options?: {
738
770
  persist?: boolean;
739
771
  recalculateSummary?: boolean;
@@ -0,0 +1,53 @@
1
+ export type OrderCollectionKind = 'product' | 'booking' | 'payment';
2
+ export interface OrderCollectionIdentityStats {
3
+ backfilledUidCount: number;
4
+ collapsedDuplicateCount: number;
5
+ uidConflictCount: number;
6
+ anonymousRowCount: number;
7
+ }
8
+ export interface OrderCollectionUidRemap {
9
+ kind: OrderCollectionKind;
10
+ from: string;
11
+ to: string;
12
+ persistentId: string | null;
13
+ /** 默认全局迁移;UID 冲突时只能迁移能由另一侧 UID 明确定位的引用。 */
14
+ scope?: 'global' | 'linked-owner';
15
+ referenceOwnerUid?: string | null;
16
+ }
17
+ export interface NormalizeOrderCollectionResult<T> {
18
+ items: T[];
19
+ stats: OrderCollectionIdentityStats;
20
+ uidRemaps: OrderCollectionUidRemap[];
21
+ }
22
+ export interface NormalizeOrderCollectionsResult<T> {
23
+ order: T;
24
+ stats: Record<OrderCollectionKind, OrderCollectionIdentityStats>;
25
+ uidRemaps: OrderCollectionUidRemap[];
26
+ }
27
+ export declare function createUuidV4(): string;
28
+ export declare function isBlankOrderCollectionIdentity(value: unknown): boolean;
29
+ export declare function getOrderCollectionPersistentId(kind: OrderCollectionKind, item: unknown): string | null;
30
+ export declare function getOrderCollectionUid(kind: OrderCollectionKind, item: unknown): string | null;
31
+ export declare function buildOrderCollectionFallbackUid(kind: OrderCollectionKind, persistentId: string | number): string;
32
+ export declare function getOrderCollectionReferenceUid(kind: OrderCollectionKind, item: unknown): string | null;
33
+ export declare function setOrderCollectionUid<T>(kind: OrderCollectionKind, item: T, uid: string): T;
34
+ /**
35
+ * 持久化行 ID 是服务端事实主键;只有至少一侧尚未持久化时,才允许用 runtime UID 对齐。
36
+ */
37
+ export declare function isSameOrderCollectionItem(kind: OrderCollectionKind, left: unknown, right: unknown): boolean;
38
+ export declare function mergeOrderCollectionItems<T>(kind: OrderCollectionKind, currentItem: T, incomingItem: T, options?: {
39
+ ensureUid?: boolean;
40
+ createAnonymousUid?: () => string;
41
+ }): T;
42
+ /**
43
+ * 规范化单一数组:强身份重复时保留首次位置、用最后一条业务字段覆盖,并统一补 UID。
44
+ */
45
+ export declare function normalizeOrderCollection<T>(kind: OrderCollectionKind, items: T[] | null | undefined, options?: {
46
+ ensureUid?: boolean;
47
+ createAnonymousUid?: () => string;
48
+ }): NormalizeOrderCollectionResult<T>;
49
+ export declare function applyOrderCollectionUidRemaps<T extends Record<string, any>>(sourceOrder: T, uidRemaps: OrderCollectionUidRemap[]): T;
50
+ export declare function normalizeOrderCollections<T extends Record<string, any>>(sourceOrder: T, options?: {
51
+ ensureUid?: boolean;
52
+ createAnonymousUid?: () => string;
53
+ }): NormalizeOrderCollectionsResult<T>;