@pisell/pisellos 0.10.43 → 0.10.44

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 (87) hide show
  1. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  2. package/dist/model/strategy/adapter/itemRule/adapter.js +135 -35
  3. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  4. package/dist/model/strategy/adapter/itemRule/evaluator.js +25 -1
  5. package/dist/model/strategy/adapter/itemRule/type.d.ts +44 -0
  6. package/dist/model/strategy/adapter/itemRule/type.js +19 -1
  7. package/dist/modules/Order/index.d.ts +41 -9
  8. package/dist/modules/Order/index.js +1438 -878
  9. package/dist/modules/Order/salesNotes.d.ts +31 -0
  10. package/dist/modules/Order/salesNotes.js +492 -0
  11. package/dist/modules/Order/types.d.ts +105 -8
  12. package/dist/modules/Order/types.js +6 -1
  13. package/dist/modules/Order/utils.d.ts +3 -1
  14. package/dist/modules/Order/utils.js +191 -71
  15. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +4 -5
  16. package/dist/modules/Payment/cashRecommendationAlgorithm.js +17 -367
  17. package/dist/modules/ProductList/index.d.ts +2 -1
  18. package/dist/modules/ProductList/index.js +100 -20
  19. package/dist/modules/ProductList/types.d.ts +10 -0
  20. package/dist/server/index.d.ts +7 -0
  21. package/dist/server/index.js +45 -3
  22. package/dist/server/modules/order/index.js +6 -0
  23. package/dist/server/modules/order/types.d.ts +9 -0
  24. package/dist/server/utils/small-ticket.d.ts +1 -0
  25. package/dist/server/utils/small-ticket.js +142 -14
  26. package/dist/solution/BaseSales/index.d.ts +15 -1
  27. package/dist/solution/BaseSales/index.js +1240 -877
  28. package/dist/solution/BookingByStep/index.d.ts +1 -1
  29. package/dist/solution/BookingTicket/index.d.ts +1 -0
  30. package/dist/solution/BookingTicket/index.js +37 -16
  31. package/dist/solution/BookingTicket/utils/orderCustomer.js +3 -2
  32. package/dist/solution/RegisterAndLogin/config.d.ts +9 -3
  33. package/dist/solution/RegisterAndLogin/config.js +95 -40
  34. package/dist/solution/RegisterAndLogin/index.js +4 -1
  35. package/dist/solution/ScanOrder/index.d.ts +1 -0
  36. package/dist/solution/ScanOrder/index.js +31 -27
  37. package/dist/solution/ScanOrder/utils.d.ts +1 -0
  38. package/dist/solution/ScanOrder/utils.js +2 -0
  39. package/dist/solution/UnifiedBookingSales/index.d.ts +15 -2
  40. package/dist/solution/UnifiedBookingSales/index.js +777 -510
  41. package/dist/solution/UnifiedBookingSales/types.d.ts +14 -1
  42. package/dist/solution/VenueBooking/index.d.ts +1 -0
  43. package/dist/solution/VenueBooking/index.js +8 -4
  44. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  45. package/lib/model/strategy/adapter/itemRule/adapter.js +73 -4
  46. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  47. package/lib/model/strategy/adapter/itemRule/evaluator.js +23 -1
  48. package/lib/model/strategy/adapter/itemRule/type.d.ts +44 -0
  49. package/lib/model/strategy/adapter/itemRule/type.js +19 -1
  50. package/lib/modules/Order/index.d.ts +41 -9
  51. package/lib/modules/Order/index.js +434 -61
  52. package/lib/modules/Order/salesNotes.d.ts +31 -0
  53. package/lib/modules/Order/salesNotes.js +382 -0
  54. package/lib/modules/Order/types.d.ts +105 -8
  55. package/lib/modules/Order/types.js +5 -1
  56. package/lib/modules/Order/utils.d.ts +3 -1
  57. package/lib/modules/Order/utils.js +114 -1
  58. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +4 -5
  59. package/lib/modules/Payment/cashRecommendationAlgorithm.js +9 -354
  60. package/lib/modules/ProductList/index.d.ts +2 -1
  61. package/lib/modules/ProductList/index.js +47 -2
  62. package/lib/modules/ProductList/types.d.ts +10 -0
  63. package/lib/server/index.d.ts +7 -0
  64. package/lib/server/index.js +39 -3
  65. package/lib/server/modules/order/index.js +6 -0
  66. package/lib/server/modules/order/types.d.ts +9 -0
  67. package/lib/server/utils/small-ticket.d.ts +1 -0
  68. package/lib/server/utils/small-ticket.js +136 -12
  69. package/lib/solution/BaseSales/index.d.ts +15 -1
  70. package/lib/solution/BaseSales/index.js +192 -22
  71. package/lib/solution/BookingByStep/index.d.ts +1 -1
  72. package/lib/solution/BookingTicket/index.d.ts +1 -0
  73. package/lib/solution/BookingTicket/index.js +23 -5
  74. package/lib/solution/BookingTicket/utils/orderCustomer.js +2 -1
  75. package/lib/solution/RegisterAndLogin/config.d.ts +9 -3
  76. package/lib/solution/RegisterAndLogin/config.js +49 -8
  77. package/lib/solution/RegisterAndLogin/index.js +4 -1
  78. package/lib/solution/ScanOrder/index.d.ts +1 -0
  79. package/lib/solution/ScanOrder/index.js +5 -1
  80. package/lib/solution/ScanOrder/utils.d.ts +1 -0
  81. package/lib/solution/ScanOrder/utils.js +1 -0
  82. package/lib/solution/UnifiedBookingSales/index.d.ts +15 -2
  83. package/lib/solution/UnifiedBookingSales/index.js +125 -1
  84. package/lib/solution/UnifiedBookingSales/types.d.ts +14 -1
  85. package/lib/solution/VenueBooking/index.d.ts +1 -0
  86. package/lib/solution/VenueBooking/index.js +5 -1
  87. package/package.json +1 -1
@@ -0,0 +1,31 @@
1
+ import type { SalesNote, SalesNoteProtocol, SalesNoteTextInput } from './types';
2
+ export interface SalesNotePolicy {
3
+ note_type: string;
4
+ importance: string;
5
+ uniquePerPrimaryTarget: boolean;
6
+ primary_relation_type: 'about';
7
+ secondary_order_relation_type: 'related_to';
8
+ }
9
+ export declare function getSalesNotePolicy(note_type: string): SalesNotePolicy | null;
10
+ export declare function buildSalesNoteText(input: SalesNoteTextInput): Record<string, string>;
11
+ export interface SalesNoteValidationOptions {
12
+ allowUnresolvedOrderTarget?: boolean;
13
+ expectedOrderTargetUuid?: string;
14
+ productTargetUuids?: ReadonlySet<string>;
15
+ }
16
+ export type EncodeSalesNotesOptions = SalesNoteValidationOptions;
17
+ export declare function encodeSalesNotes(notes: SalesNote[], options?: EncodeSalesNotesOptions): SalesNoteProtocol[];
18
+ export interface DecodedSalesNotesSnapshot {
19
+ notes: SalesNote[];
20
+ complete: boolean;
21
+ }
22
+ export interface DecodeSalesNotesOptions {
23
+ allowUnresolvedOrderTarget?: boolean;
24
+ }
25
+ export declare function decodeSalesNotesSnapshot(value: unknown, options?: DecodeSalesNotesOptions): DecodedSalesNotesSnapshot;
26
+ export declare function decodeSalesNotes(value: unknown, options?: DecodeSalesNotesOptions): SalesNote[];
27
+ export declare function finalizeSalesNotesForCheckout(params: {
28
+ notes: unknown;
29
+ shopOrderNumber: unknown;
30
+ productTargetUuids: string[];
31
+ }): SalesNoteProtocol[];
@@ -0,0 +1,382 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.buildSalesNoteText = buildSalesNoteText;
7
+ exports.decodeSalesNotes = decodeSalesNotes;
8
+ exports.decodeSalesNotesSnapshot = decodeSalesNotesSnapshot;
9
+ exports.encodeSalesNotes = encodeSalesNotes;
10
+ exports.finalizeSalesNotesForCheckout = finalizeSalesNotesForCheckout;
11
+ exports.getSalesNotePolicy = getSalesNotePolicy;
12
+ const MAX_UUID_LENGTH = 255;
13
+ const LOCALIZED_NOTE_LOCALES = ['en', 'zh-CN', 'zh-HK', 'ja', 'pt'];
14
+ const UUID_V4_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
15
+ /**
16
+ * 备注业务规则统一注册在 OS;调用方只传 note_type、目标行和原始文本。
17
+ * 后续新增备注类型时在这里增加 policy,不把 importance / Relation 规则下放给 UI。
18
+ */
19
+ const SALES_NOTE_POLICIES = {
20
+ allergy: {
21
+ note_type: 'allergy',
22
+ importance: 'high',
23
+ uniquePerPrimaryTarget: true,
24
+ primary_relation_type: 'about',
25
+ secondary_order_relation_type: 'related_to'
26
+ }
27
+ };
28
+ function getSalesNotePolicy(note_type) {
29
+ return SALES_NOTE_POLICIES[note_type] || null;
30
+ }
31
+ function normalizeUuid(value, field, options) {
32
+ const uuid = String(value ?? '').trim();
33
+ if (!uuid && !options?.allowEmpty) {
34
+ throw new Error(`[Order Notes] ${field} 不能为空`);
35
+ }
36
+ if (uuid.length > MAX_UUID_LENGTH) {
37
+ throw new Error(`[Order Notes] ${field} 不能超过 ${MAX_UUID_LENGTH} 个字符`);
38
+ }
39
+ return uuid;
40
+ }
41
+ function normalizeEntityUuid(value, field) {
42
+ const uuid = normalizeUuid(value, field);
43
+ if (!UUID_V4_PATTERN.test(uuid)) {
44
+ throw new Error(`[Order Notes] ${field} 必须为 UUID v4`);
45
+ }
46
+ return uuid;
47
+ }
48
+ function normalizeTextRecord(value) {
49
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return {};
50
+ return Object.entries(value).reduce((result, [locale, text]) => {
51
+ if (typeof text === 'string') result[locale] = text;
52
+ return result;
53
+ }, {});
54
+ }
55
+ function normalizeLocalizedLabel(label) {
56
+ if (typeof label === 'string') {
57
+ const text = label.trim();
58
+ return text ? {
59
+ default: text
60
+ } : {};
61
+ }
62
+ return Object.entries(label || {}).reduce((result, [locale, value]) => {
63
+ const text = String(value ?? '').trim();
64
+ if (text) result[locale] = text;
65
+ return result;
66
+ }, {});
67
+ }
68
+ function getLocaleCandidates(locale) {
69
+ const raw = String(locale || '').trim();
70
+ const normalized = raw.replace(/_/g, '-');
71
+ const base = normalized.split('-')[0];
72
+ return Array.from(new Set([raw, normalized, base].filter(Boolean)));
73
+ }
74
+ function normalizeLocaleLookupKey(locale) {
75
+ return String(locale || '').trim().replace(/_/g, '-').toLowerCase();
76
+ }
77
+ function resolveLocalizedLabel(label, locale) {
78
+ if (typeof label === 'string') return label.trim();
79
+ const normalized = normalizeLocalizedLabel(label);
80
+ const entries = Object.entries(normalized);
81
+ const lowerCaseLookup = new Map(entries.map(([key, value]) => [normalizeLocaleLookupKey(key), value]));
82
+ for (const candidate of getLocaleCandidates(locale)) {
83
+ const matched = lowerCaseLookup.get(normalizeLocaleLookupKey(candidate));
84
+ if (matched) return matched;
85
+ }
86
+ const localeBase = normalizeLocaleLookupKey(locale).split('-')[0];
87
+ const sameLanguage = entries.find(([key]) => normalizeLocaleLookupKey(key).split('-')[0] === localeBase)?.[1];
88
+ return sameLanguage || lowerCaseLookup.get('en') || lowerCaseLookup.get('zh-cn') || lowerCaseLookup.get('default') || entries[0]?.[1] || '';
89
+ }
90
+ function joinNoteParts(parts) {
91
+ return parts.map(part => String(part ?? '')).filter(part => part.trim().length > 0).join(',');
92
+ }
93
+ function buildSalesNoteText(input) {
94
+ if (input.kind === 'plain') {
95
+ const text = String(input.input ?? '');
96
+ if (!text.trim()) throw new Error('[Order Notes] 备注输入不能为空');
97
+ return {
98
+ 'zh-CN': '',
99
+ original: text
100
+ };
101
+ }
102
+ if (input.kind === 'resolved') {
103
+ const text = normalizeTextRecord(input.text);
104
+ if (!Object.values(text).some(value => value.trim())) {
105
+ throw new Error('[Order Notes] 备注文本不能为空');
106
+ }
107
+ return text;
108
+ }
109
+ const inputText = String(input.input ?? '');
110
+ const seenIds = new Set();
111
+ const selections = (input.selections || []).filter(selection => {
112
+ const id = String(selection?.id ?? '').trim();
113
+ if (!id || seenIds.has(id)) return false;
114
+ seenIds.add(id);
115
+ return true;
116
+ });
117
+ if (!selections.length && !inputText.trim()) {
118
+ throw new Error('[Order Notes] 过敏选项和补充说明不能同时为空');
119
+ }
120
+ const result = {};
121
+ for (const locale of LOCALIZED_NOTE_LOCALES) {
122
+ result[locale] = joinNoteParts([...selections.map(selection => resolveLocalizedLabel(selection.label, locale)), inputText]);
123
+ }
124
+ result.original = joinNoteParts([...selections.map(selection => resolveLocalizedLabel(selection.label, input.locale)), inputText]);
125
+ return result;
126
+ }
127
+ function validateSalesNote(note, options = {}) {
128
+ normalizeEntityUuid(note.uuid, 'Note uuid');
129
+ const note_type = String(note.note_type || '').trim();
130
+ const policy = getSalesNotePolicy(note_type);
131
+ if (!policy) {
132
+ throw new Error(`[Order Notes] 当前未注册备注类型: ${note_type || '(empty)'}`);
133
+ }
134
+ if (note.importance !== policy.importance) {
135
+ throw new Error(`[Order Notes] ${note_type} importance 必须为 ${policy.importance}`);
136
+ }
137
+ const text = note.content?.text;
138
+ if (!text || typeof text !== 'object' || Array.isArray(text) || Object.values(text).some(value => typeof value !== 'string') || !Object.values(text).some(value => value.trim())) {
139
+ throw new Error('[Order Notes] content.text 不能为空');
140
+ }
141
+ if (!Array.isArray(note.note_relations) || note.note_relations.length === 0) {
142
+ throw new Error('[Order Notes] note_relations 不能为空');
143
+ }
144
+ const relationUuids = new Set();
145
+ let primaryCount = 0;
146
+ let orderRelationCount = 0;
147
+ for (const relation of note.note_relations) {
148
+ const relationUuid = normalizeEntityUuid(relation.uuid, 'Relation uuid');
149
+ if (relationUuids.has(relationUuid)) {
150
+ throw new Error('[Order Notes] 同一 Note 内 Relation uuid 不能重复');
151
+ }
152
+ relationUuids.add(relationUuid);
153
+ if (relation.is_primary !== 0 && relation.is_primary !== 1) {
154
+ throw new Error('[Order Notes] is_primary 只允许整数 0 或 1');
155
+ }
156
+ if (relation.relation_type !== 'about' && relation.relation_type !== 'related_to') {
157
+ throw new Error('[Order Notes] relation_type 不合法');
158
+ }
159
+ if (relation.target_type !== 'order' && relation.target_type !== 'order_detail') {
160
+ throw new Error('[Order Notes] target_type 不合法');
161
+ }
162
+ if (relation.is_primary === 1) {
163
+ primaryCount += 1;
164
+ if (relation.relation_type !== policy.primary_relation_type || relation.target_type !== 'order_detail') {
165
+ throw new Error('[Order Notes] 主关系必须使用 about + order_detail');
166
+ }
167
+ const targetUuid = normalizeUuid(relation.target_uuid, 'Relation target_uuid');
168
+ if (options.productTargetUuids && !options.productTargetUuids.has(targetUuid)) {
169
+ throw new Error('[Order Notes] 商品 Relation target_uuid 不属于当前订单');
170
+ }
171
+ continue;
172
+ }
173
+ if (relation.target_type === 'order' && relation.relation_type === policy.secondary_order_relation_type) {
174
+ orderRelationCount += 1;
175
+ const targetUuid = normalizeUuid(relation.target_uuid, 'Relation target_uuid', {
176
+ allowEmpty: options.allowUnresolvedOrderTarget === true
177
+ });
178
+ if (options.expectedOrderTargetUuid !== undefined && targetUuid !== options.expectedOrderTargetUuid) {
179
+ throw new Error('[Order Notes] 订单 Relation target_uuid 与 shop_order_number 不一致');
180
+ }
181
+ continue;
182
+ }
183
+ throw new Error('[Order Notes] 非主体关系必须使用 related_to + order');
184
+ }
185
+ if (primaryCount !== 1) {
186
+ throw new Error('[Order Notes] 每条 Note 必须且只能有一个主关系');
187
+ }
188
+ if (orderRelationCount !== 1) {
189
+ throw new Error('[Order Notes] 每条商品 Note 必须且只能有一个订单冗余关系');
190
+ }
191
+ }
192
+ function encodeSalesNotes(notes, options = {}) {
193
+ const entityUuids = new Set();
194
+ const uniquePolicyTargets = new Set();
195
+ return (notes || []).map(note => {
196
+ validateSalesNote(note, options);
197
+ const noteUuid = normalizeEntityUuid(note.uuid, 'Note uuid');
198
+ if (entityUuids.has(noteUuid)) {
199
+ throw new Error('[Order Notes] Note/Relation uuid 不能重复');
200
+ }
201
+ entityUuids.add(noteUuid);
202
+ const note_type = String(note.note_type).trim();
203
+ const noteRelations = note.note_relations.map(relation => {
204
+ const relationUuid = normalizeEntityUuid(relation.uuid, 'Relation uuid');
205
+ if (entityUuids.has(relationUuid)) {
206
+ throw new Error('[Order Notes] Note/Relation uuid 不能重复');
207
+ }
208
+ entityUuids.add(relationUuid);
209
+ const allowEmptyTarget = options.allowUnresolvedOrderTarget === true && relation.is_primary === 0 && relation.relation_type === 'related_to' && relation.target_type === 'order';
210
+ return {
211
+ uuid: relationUuid,
212
+ relation_type: relation.relation_type,
213
+ target_type: relation.target_type,
214
+ target_uuid: normalizeUuid(relation.target_uuid, 'Relation target_uuid', {
215
+ allowEmpty: allowEmptyTarget
216
+ }),
217
+ is_primary: relation.is_primary
218
+ };
219
+ });
220
+ const primaryRelation = noteRelations.find(relation => relation.is_primary === 1);
221
+ const policy = getSalesNotePolicy(note_type);
222
+ if (policy.uniquePerPrimaryTarget) {
223
+ const policyTargetKey = [note_type, primaryRelation.target_type, primaryRelation.target_uuid].join(':');
224
+ if (uniquePolicyTargets.has(policyTargetKey)) {
225
+ throw new Error('[Order Notes] 同一商品行不能重复提交同类型 Note');
226
+ }
227
+ uniquePolicyTargets.add(policyTargetKey);
228
+ }
229
+ return {
230
+ uuid: noteUuid,
231
+ note_type,
232
+ content: {
233
+ text: {
234
+ ...(note.content?.text || {})
235
+ }
236
+ },
237
+ importance: note.importance,
238
+ note_relations: noteRelations
239
+ };
240
+ });
241
+ }
242
+ function decodeRelation(value) {
243
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
244
+ const raw = value;
245
+ const uuid = String(raw.uuid ?? '').trim();
246
+ const target_uuid = String(raw.target_uuid ?? '').trim();
247
+ const relation_type = raw.relation_type;
248
+ const target_type = raw.target_type;
249
+ const is_primary = raw.is_primary;
250
+ if (!uuid || relation_type !== 'about' && relation_type !== 'related_to' || target_type !== 'order' && target_type !== 'order_detail' || is_primary !== 0 && is_primary !== 1) {
251
+ return null;
252
+ }
253
+ return {
254
+ uuid,
255
+ relation_type,
256
+ target_type,
257
+ target_uuid,
258
+ is_primary
259
+ };
260
+ }
261
+ function decodeSalesNotesSnapshot(value, options = {}) {
262
+ if (!Array.isArray(value)) return {
263
+ notes: [],
264
+ complete: false
265
+ };
266
+ const notes = [];
267
+ const entityUuids = new Set();
268
+ const uniquePolicyTargets = new Set();
269
+ let complete = true;
270
+ for (const item of value) {
271
+ if (!item || typeof item !== 'object' || Array.isArray(item)) {
272
+ complete = false;
273
+ continue;
274
+ }
275
+ const raw = item;
276
+ const uuid = String(raw.uuid ?? '').trim();
277
+ const note_type = String(raw.note_type ?? '').trim();
278
+ const importance = String(raw.importance ?? '').trim();
279
+ const rawText = raw.content?.text;
280
+ const text = normalizeTextRecord(rawText);
281
+ if (!rawText || typeof rawText !== 'object' || Array.isArray(rawText) || Object.keys(text).length !== Object.keys(rawText).length) {
282
+ complete = false;
283
+ continue;
284
+ }
285
+ const rawNoteRelations = Array.isArray(raw.note_relations) ? raw.note_relations : null;
286
+ const noteRelations = rawNoteRelations ? rawNoteRelations.map(relation => decodeRelation(relation)).filter(relation => relation !== null) : [];
287
+ if (!rawNoteRelations || noteRelations.length !== rawNoteRelations.length) {
288
+ complete = false;
289
+ continue;
290
+ }
291
+ const note = {
292
+ uuid,
293
+ note_type,
294
+ content: {
295
+ text
296
+ },
297
+ importance,
298
+ note_relations: noteRelations
299
+ };
300
+ try {
301
+ validateSalesNote(note, {
302
+ allowUnresolvedOrderTarget: options.allowUnresolvedOrderTarget
303
+ });
304
+ if (entityUuids.has(note.uuid)) {
305
+ complete = false;
306
+ continue;
307
+ }
308
+ entityUuids.add(note.uuid);
309
+ let hasDuplicateRelationUuid = false;
310
+ for (const relation of note.note_relations) {
311
+ if (entityUuids.has(relation.uuid)) {
312
+ hasDuplicateRelationUuid = true;
313
+ break;
314
+ }
315
+ }
316
+ if (hasDuplicateRelationUuid) {
317
+ complete = false;
318
+ continue;
319
+ }
320
+ note.note_relations.forEach(relation => entityUuids.add(relation.uuid));
321
+ const policy = getSalesNotePolicy(note.note_type);
322
+ const primaryRelation = note.note_relations.find(relation => relation.is_primary === 1);
323
+ if (policy?.uniquePerPrimaryTarget && primaryRelation) {
324
+ const policyTargetKey = [note.note_type, primaryRelation.target_type, primaryRelation.target_uuid].join(':');
325
+ if (uniquePolicyTargets.has(policyTargetKey)) {
326
+ complete = false;
327
+ continue;
328
+ }
329
+ uniquePolicyTargets.add(policyTargetKey);
330
+ }
331
+ notes.push(note);
332
+ } catch {
333
+ complete = false;
334
+ }
335
+ }
336
+ return {
337
+ notes,
338
+ complete
339
+ };
340
+ }
341
+ function decodeSalesNotes(value, options = {}) {
342
+ return decodeSalesNotesSnapshot(value, options).notes;
343
+ }
344
+ function finalizeSalesNotesForCheckout(params) {
345
+ if (!Array.isArray(params.notes)) {
346
+ throw new Error('[Order Notes] checkout notes 必须为数组');
347
+ }
348
+ if (params.notes.length === 0) return [];
349
+ const shopOrderNumber = normalizeUuid(params.shopOrderNumber, 'shop_order_number');
350
+ const productTargetUuids = new Set();
351
+ for (const rawTargetUuid of params.productTargetUuids || []) {
352
+ const targetUuid = normalizeUuid(rawTargetUuid, '商品 target_uuid');
353
+ if (productTargetUuids.has(targetUuid)) {
354
+ throw new Error('[Order Notes] 商品行业务标识不能重复');
355
+ }
356
+ productTargetUuids.add(targetUuid);
357
+ }
358
+ const decoded = decodeSalesNotesSnapshot(params.notes, {
359
+ allowUnresolvedOrderTarget: true
360
+ });
361
+ if (!decoded.complete || decoded.notes.length !== params.notes.length) {
362
+ throw new Error('[Order Notes] checkout Notes 快照不完整');
363
+ }
364
+ const finalizedNotes = decoded.notes.map(note => ({
365
+ ...note,
366
+ content: {
367
+ text: {
368
+ ...note.content.text
369
+ }
370
+ },
371
+ note_relations: note.note_relations.map(relation => ({
372
+ ...relation,
373
+ ...(relation.is_primary === 0 && relation.relation_type === 'related_to' && relation.target_type === 'order' ? {
374
+ target_uuid: shopOrderNumber
375
+ } : {})
376
+ }))
377
+ }));
378
+ return encodeSalesNotes(finalizedNotes, {
379
+ expectedOrderTargetUuid: shopOrderNumber,
380
+ productTargetUuids
381
+ });
382
+ }
@@ -8,6 +8,13 @@ import type { PaymentItem } from '../Payment/types';
8
8
  import type { ICustomer } from '../AccountList/types';
9
9
  import type { OrderProductDiscountItem } from '../../server/modules/order/types';
10
10
  export type { OrderProductDiscountItem } from '../../server/modules/order/types';
11
+ export type PickupReferenceMode = 'counter_pickup' | 'table_service';
12
+ export type ShopServiceType = 'dine_in' | 'takeaway';
13
+ export interface ShopServiceData {
14
+ pickup_reference_mode?: PickupReferenceMode;
15
+ service_type?: ShopServiceType | '';
16
+ [key: string]: any;
17
+ }
11
18
  export declare enum OrderHooks {
12
19
  OnOrderCreate = "order:onOrderCreate",
13
20
  OnOrderUpdate = "order:onOrderUpdate",
@@ -110,7 +117,7 @@ export interface OrderLastGiftActions {
110
117
  }>;
111
118
  toRemove: string[];
112
119
  }
113
- /** onPromotionApplied 事件 payload */
120
+ /** onPromotionApplied 稳定态事件 payload(促销、折扣与 summary 均已完成)。 */
114
121
  export interface OrderPromotionAppliedPayload {
115
122
  unfulfilledPromotions: OrderUnfulfilledPromotion[];
116
123
  giftActions: OrderLastGiftActions;
@@ -124,7 +131,7 @@ export interface OrderPromotionAppliedPayload {
124
131
  product_variant_id: number;
125
132
  }>;
126
133
  }>;
127
- /** 处理后的商品列表 */
134
+ /** 折扣重算后的最终商品列表 */
128
135
  products: OrderProduct[];
129
136
  }
130
137
  /**
@@ -196,8 +203,18 @@ export interface PointCardSnapshotItem {
196
203
  par_value: string;
197
204
  used_par_value: string;
198
205
  }
206
+ export interface VirtualCurrencySnapshotItem {
207
+ id: number | string;
208
+ tag: 'virtual_currency';
209
+ product_id?: number | string;
210
+ product_name: string;
211
+ par_value: string;
212
+ used_par_value: string;
213
+ name: Record<string, string>;
214
+ }
199
215
  export interface OrderMetaList {
200
216
  point_cards_snapshot?: PointCardSnapshotItem[];
217
+ virtual_currency_snapshot?: VirtualCurrencySnapshotItem[];
201
218
  }
202
219
  export interface OrderProduct extends OrderProductIdentity {
203
220
  order_detail_id: number | null;
@@ -250,6 +267,72 @@ export interface OrderSummary {
250
267
  tax_title?: string;
251
268
  tax_rate?: number;
252
269
  }
270
+ export type SalesNoteRelationType = 'about' | 'related_to';
271
+ export type SalesNoteTargetType = 'order' | 'order_detail';
272
+ export type SalesNoteLocalizedText = string | Record<string, string>;
273
+ export interface SalesNoteLocalizedSelection {
274
+ id: string;
275
+ label: SalesNoteLocalizedText;
276
+ }
277
+ export type SalesNoteTextInput = {
278
+ kind: 'localizedSelections';
279
+ selections: SalesNoteLocalizedSelection[];
280
+ locale: string;
281
+ input?: string;
282
+ } | {
283
+ kind: 'plain';
284
+ input: string;
285
+ } | {
286
+ kind: 'resolved';
287
+ text: Record<string, string>;
288
+ };
289
+ export interface SalesNoteRelation {
290
+ uuid: string;
291
+ relation_type: SalesNoteRelationType;
292
+ target_type: SalesNoteTargetType;
293
+ target_uuid: string;
294
+ is_primary: 0 | 1;
295
+ }
296
+ export interface SalesNote {
297
+ uuid: string;
298
+ note_type: string;
299
+ content: {
300
+ text: Record<string, string>;
301
+ };
302
+ importance: string;
303
+ note_relations: SalesNoteRelation[];
304
+ }
305
+ export interface SalesNoteTarget {
306
+ target_type: 'order_detail';
307
+ target_uuid: string;
308
+ }
309
+ export interface SetSalesNoteInput {
310
+ note_type: string;
311
+ target: SalesNoteTarget;
312
+ text: SalesNoteTextInput;
313
+ }
314
+ export interface SalesNoteDraftInput {
315
+ note_type: string;
316
+ text: SalesNoteTextInput;
317
+ }
318
+ export interface SalesNotesRuntimeState {
319
+ loaded: boolean;
320
+ dirty: boolean;
321
+ }
322
+ /**
323
+ * Sales Notes 乐观写入前的可恢复快照。
324
+ * 该对象应视为 opaque token,只用于原样传回 restoreSalesNotesMutationSnapshot。
325
+ */
326
+ export interface SalesNotesMutationSnapshot {
327
+ orderIdentity: {
328
+ orderId: number | string | null;
329
+ externalSaleNumber: string;
330
+ };
331
+ notes: SalesNote[];
332
+ state: SalesNotesRuntimeState;
333
+ }
334
+ export type SalesNoteProtocolRelation = SalesNoteRelation;
335
+ export type SalesNoteProtocol = SalesNote;
253
336
  export interface OrderTempOrder {
254
337
  order_id: number | null;
255
338
  external_sale_number: string;
@@ -289,6 +372,7 @@ export interface OrderTempOrder {
289
372
  created_at: string | undefined;
290
373
  request_unique_idempotency_token?: string;
291
374
  products: OrderProduct[];
375
+ notes: SalesNote[];
292
376
  bookings: any[];
293
377
  payments: any[];
294
378
  refunds?: any[];
@@ -303,6 +387,7 @@ export interface OrderTempOrder {
303
387
  summary?: OrderSummary;
304
388
  _extend?: {
305
389
  productsByUid?: Record<string, Record<string, any>>;
390
+ salesNotesState?: SalesNotesRuntimeState;
306
391
  [key: string]: any;
307
392
  };
308
393
  }
@@ -311,7 +396,7 @@ export interface OrderSubmitProduct extends Omit<OrderProduct, 'unique_identific
311
396
  payment_price: string;
312
397
  product_sku: OrderProductSku;
313
398
  }
314
- export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | '_extend' | 'customer' | 'discount_list' | 'created_at' | 'payment_status'> {
399
+ export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | 'notes' | '_extend' | 'customer' | 'discount_list' | 'created_at' | 'payment_status'> {
315
400
  platform: string;
316
401
  payment_status?: string;
317
402
  created_at?: string | undefined;
@@ -321,6 +406,7 @@ export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'p
321
406
  form_record_id: number | string;
322
407
  }>;
323
408
  products: OrderSubmitProduct[];
409
+ notes?: SalesNoteProtocol[];
324
410
  summary?: OrderSummary;
325
411
  small_ticket_data_flag?: number;
326
412
  }
@@ -350,6 +436,8 @@ export interface AddProductToOrderOptions {
350
436
  insertAfterProductUid?: string;
351
437
  /** 跳过同商品/规格匹配,始终新增购物车行。 */
352
438
  disableMerge?: boolean;
439
+ /** 商品行 UID 落定后,由 OrderModule 原子绑定到该行的 Sales Notes 草稿。 */
440
+ salesNotes?: SalesNoteDraftInput[];
353
441
  }
354
442
  /**
355
443
  * 删除商品后的可选位置保持策略。
@@ -768,9 +856,17 @@ export interface OrderModuleAPI {
768
856
  updateTempOrderShopDiscount: (amount: string | number) => string;
769
857
  updateTempOrderDepositAmount: (amount: string | number) => OrderSummary;
770
858
  updateTempOrderCustomer: (customer: UpdateTempOrderCustomerInput) => OrderSnapshot['customer'];
859
+ updateTempOrderPickupReferenceMode: (mode: PickupReferenceMode) => ShopServiceData;
860
+ updateTempOrderServiceType: (serviceType: ShopServiceType) => ShopServiceData;
771
861
  updateTempOrderBuzzer: (buzzer: string) => string;
772
862
  updateTempOrderContactsInfo: (contactsInfo: Record<string, any> | null) => Record<string, any> | null;
773
863
  addProductToOrder: (product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions) => Promise<OrderProduct[]>;
864
+ getSalesNotes: () => SalesNote[];
865
+ createSalesNotesMutationSnapshot: () => SalesNotesMutationSnapshot;
866
+ restoreSalesNotesMutationSnapshot: (snapshot: SalesNotesMutationSnapshot) => void;
867
+ setSalesNote: (input: SetSalesNoteInput) => Promise<SalesNote>;
868
+ removeSalesNote: (uuid: string) => Promise<void>;
869
+ clearSalesNotes: () => Promise<void>;
774
870
  updateOrderProduct: (params: UpdateOrderProductParams) => Promise<OrderProduct[]>;
775
871
  /** 批量更新购物车行,末尾仅触发一次促销重算与 summary 刷新 */
776
872
  updateOrderProducts: (paramsList: UpdateOrderProductParams[]) => Promise<OrderProduct[]>;
@@ -878,6 +974,7 @@ export interface OrderModuleAPI {
878
974
  }) => Promise<Discount[]>;
879
975
  getDiscountList: () => Discount[];
880
976
  getAvailableWalletIds: () => number[];
977
+ getCustomerWalletPrepareConfigEpoch: () => number;
881
978
  applyDiscount: () => void;
882
979
  /**
883
980
  * 注入促销评估器。
@@ -906,7 +1003,7 @@ export interface OrderModuleAPI {
906
1003
  */
907
1004
  appendPromotionTags: <T extends Record<string, any>>(products: T[]) => T[];
908
1005
  /**
909
- * 应用购物车促销(评估 → 差异化赠品 → 写回 tempOrder.products → emit onPromotionApplied)。
1006
+ * 应用购物车促销(评估 → 差异化赠品 → 折扣/summary 重算 → emit onPromotionApplied)。
910
1007
  *
911
1008
  * 自动在 addProductToOrder / updateOrderProductQuantity / removeProductFromOrder /
912
1009
  * clearOrderCartLines / setOrderCustomer 等写路径末尾触发,业务一般无需手动调用。
@@ -920,10 +1017,10 @@ export interface OrderModuleAPI {
920
1017
  /** 读取上次 applyPromotion 产出的赠品操作 diff(toAdd / toReduce / toRemove) */
921
1018
  getLastGiftActions: () => OrderLastGiftActions | null;
922
1019
  /**
923
- * 取消订单
924
- * @param params 取消订单参数
925
- * @returns 后端返回结果
926
- */
1020
+ * 取消订单
1021
+ * @param params 取消订单参数
1022
+ * @returns 后端返回结果
1023
+ */
927
1024
  cancelOrder: (params: CancelOrderParams) => Promise<any>;
928
1025
  /**
929
1026
  * 变更预约状态
@@ -40,7 +40,7 @@ let OrderHooks = exports.OrderHooks = /*#__PURE__*/function (OrderHooks) {
40
40
  */
41
41
  /** 未满足的促销策略(购物车底部 alert 渲染源) */
42
42
  /** 上一次 applyPromotion 计算出的赠品操作(仅供调试/读取使用) */
43
- /** onPromotionApplied 事件 payload */
43
+ /** onPromotionApplied 稳定态事件 payload(促销、折扣与 summary 均已完成)。 */
44
44
  /**
45
45
  * tempOrder 上的下单客户协议字段视图。
46
46
  * 这些字段会随订单提交到后端。
@@ -59,6 +59,10 @@ let OrderHooks = exports.OrderHooks = /*#__PURE__*/function (OrderHooks) {
59
59
  * - `source`:缺省表示真实业务变更;`detailHydrate` 仅表示打开详情时快照已就绪
60
60
  * 清空时整个 payload 为 null。
61
61
  */
62
+ /**
63
+ * Sales Notes 乐观写入前的可恢复快照。
64
+ * 该对象应视为 opaque token,只用于原样传回 restoreSalesNotesMutationSnapshot。
65
+ */
62
66
  /**
63
67
  * 添加商品行时的顺序控制。
64
68
  * 默认追加到 products 尾部;预约数量同步可插入到既有预约组的最新行之后,
@@ -1,6 +1,6 @@
1
1
  import Decimal from 'decimal.js';
2
2
  import type { CartItem } from '../Cart';
3
- import type { OrderProductDiscountItem, OrderMetaList, OrderProduct, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder, PointCardSnapshotItem } from './types';
3
+ import type { OrderProductDiscountItem, OrderMetaList, OrderProduct, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder, PointCardSnapshotItem, VirtualCurrencySnapshotItem } from './types';
4
4
  import type { RulesParamsHooks } from '../Rules/types';
5
5
  import type { MapOrderPaymentsOptions, OrderPaymentData, OrderPaymentSource } from './types';
6
6
  import { createUuidV4 } from './utils/orderCollectionIdentity';
@@ -18,6 +18,8 @@ export interface OrderProductsDepositSummary {
18
18
  import type { WindowPlugin } from '../../plugins';
19
19
  export declare function normalizePointCardSnapshotItem(value: unknown): PointCardSnapshotItem | null;
20
20
  export declare function buildPointCardSnapshotFromWalletPassList(value: unknown): PointCardSnapshotItem[];
21
+ export declare function normalizeVirtualCurrencySnapshotItem(value: unknown): VirtualCurrencySnapshotItem | null;
22
+ export declare function buildVirtualCurrencySnapshotFromList(value: unknown): VirtualCurrencySnapshotItem[];
21
23
  export declare function normalizeOrderMetaList(value: unknown): OrderMetaList | undefined;
22
24
  /**
23
25
  * 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。