@pisell/pisellos 2.3.93 → 2.3.95
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/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
- package/dist/model/strategy/adapter/itemRule/adapter.js +135 -35
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
- package/dist/model/strategy/adapter/itemRule/evaluator.js +25 -1
- package/dist/model/strategy/adapter/itemRule/type.d.ts +44 -0
- package/dist/model/strategy/adapter/itemRule/type.js +19 -1
- package/dist/modules/Order/index.d.ts +18 -3
- package/dist/modules/Order/index.js +885 -485
- package/dist/modules/Order/salesNotes.d.ts +31 -0
- package/dist/modules/Order/salesNotes.js +492 -0
- package/dist/modules/Order/types.d.ts +91 -5
- package/dist/modules/Order/types.js +5 -0
- package/dist/modules/Order/utils.d.ts +12 -0
- package/dist/modules/Order/utils.js +75 -26
- package/dist/modules/ProductList/index.d.ts +2 -1
- package/dist/modules/ProductList/index.js +100 -20
- package/dist/modules/ProductList/types.d.ts +10 -0
- package/dist/modules/ResourcePlanner/planner.js +5 -3
- package/dist/modules/ResourcePlanner/types.d.ts +5 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +43 -3
- package/dist/solution/BaseSales/index.d.ts +9 -1
- package/dist/solution/BaseSales/index.js +894 -706
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/utils/orderCustomer.js +3 -2
- package/dist/solution/RegisterAndLogin/config.d.ts +9 -3
- package/dist/solution/RegisterAndLogin/config.js +95 -40
- package/dist/solution/RegisterAndLogin/index.js +4 -1
- package/dist/solution/ScanOrder/index.d.ts +1 -0
- package/dist/solution/ScanOrder/index.js +31 -27
- package/dist/solution/ScanOrder/utils.d.ts +1 -0
- package/dist/solution/ScanOrder/utils.js +2 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +15 -2
- package/dist/solution/UnifiedBookingSales/index.js +767 -488
- package/dist/solution/UnifiedBookingSales/types.d.ts +14 -1
- package/dist/solution/VenueBooking/index.d.ts +1 -0
- package/dist/solution/VenueBooking/index.js +8 -4
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
- package/lib/model/strategy/adapter/itemRule/adapter.js +73 -4
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
- package/lib/model/strategy/adapter/itemRule/evaluator.js +23 -1
- package/lib/model/strategy/adapter/itemRule/type.d.ts +44 -0
- package/lib/model/strategy/adapter/itemRule/type.js +19 -1
- package/lib/modules/Order/index.d.ts +18 -3
- package/lib/modules/Order/index.js +325 -28
- package/lib/modules/Order/salesNotes.d.ts +31 -0
- package/lib/modules/Order/salesNotes.js +382 -0
- package/lib/modules/Order/types.d.ts +91 -5
- package/lib/modules/Order/types.js +4 -0
- package/lib/modules/Order/utils.d.ts +12 -0
- package/lib/modules/Order/utils.js +68 -16
- package/lib/modules/ProductList/index.d.ts +2 -1
- package/lib/modules/ProductList/index.js +47 -2
- package/lib/modules/ProductList/types.d.ts +10 -0
- package/lib/modules/ResourcePlanner/planner.js +5 -3
- package/lib/modules/ResourcePlanner/types.d.ts +5 -0
- package/lib/server/index.d.ts +6 -0
- package/lib/server/index.js +37 -3
- package/lib/solution/BaseSales/index.d.ts +9 -1
- package/lib/solution/BaseSales/index.js +105 -1
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/utils/orderCustomer.js +2 -1
- package/lib/solution/RegisterAndLogin/config.d.ts +9 -3
- package/lib/solution/RegisterAndLogin/config.js +49 -8
- package/lib/solution/RegisterAndLogin/index.js +4 -1
- package/lib/solution/ScanOrder/index.d.ts +1 -0
- package/lib/solution/ScanOrder/index.js +5 -1
- package/lib/solution/ScanOrder/utils.d.ts +1 -0
- package/lib/solution/ScanOrder/utils.js +1 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +15 -2
- package/lib/solution/UnifiedBookingSales/index.js +140 -6
- package/lib/solution/UnifiedBookingSales/types.d.ts +14 -1
- package/lib/solution/VenueBooking/index.d.ts +1 -0
- package/lib/solution/VenueBooking/index.js +5 -1
- package/package.json +1 -1
|
@@ -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",
|
|
@@ -238,6 +245,72 @@ export interface OrderSummary {
|
|
|
238
245
|
tax_title?: string;
|
|
239
246
|
tax_rate?: number;
|
|
240
247
|
}
|
|
248
|
+
export type SalesNoteRelationType = 'about' | 'related_to';
|
|
249
|
+
export type SalesNoteTargetType = 'order' | 'order_detail';
|
|
250
|
+
export type SalesNoteLocalizedText = string | Record<string, string>;
|
|
251
|
+
export interface SalesNoteLocalizedSelection {
|
|
252
|
+
id: string;
|
|
253
|
+
label: SalesNoteLocalizedText;
|
|
254
|
+
}
|
|
255
|
+
export type SalesNoteTextInput = {
|
|
256
|
+
kind: 'localizedSelections';
|
|
257
|
+
selections: SalesNoteLocalizedSelection[];
|
|
258
|
+
locale: string;
|
|
259
|
+
input?: string;
|
|
260
|
+
} | {
|
|
261
|
+
kind: 'plain';
|
|
262
|
+
input: string;
|
|
263
|
+
} | {
|
|
264
|
+
kind: 'resolved';
|
|
265
|
+
text: Record<string, string>;
|
|
266
|
+
};
|
|
267
|
+
export interface SalesNoteRelation {
|
|
268
|
+
uuid: string;
|
|
269
|
+
relation_type: SalesNoteRelationType;
|
|
270
|
+
target_type: SalesNoteTargetType;
|
|
271
|
+
target_uuid: string;
|
|
272
|
+
is_primary: 0 | 1;
|
|
273
|
+
}
|
|
274
|
+
export interface SalesNote {
|
|
275
|
+
uuid: string;
|
|
276
|
+
note_type: string;
|
|
277
|
+
content: {
|
|
278
|
+
text: Record<string, string>;
|
|
279
|
+
};
|
|
280
|
+
importance: string;
|
|
281
|
+
note_relations: SalesNoteRelation[];
|
|
282
|
+
}
|
|
283
|
+
export interface SalesNoteTarget {
|
|
284
|
+
target_type: 'order_detail';
|
|
285
|
+
target_uuid: string;
|
|
286
|
+
}
|
|
287
|
+
export interface SetSalesNoteInput {
|
|
288
|
+
note_type: string;
|
|
289
|
+
target: SalesNoteTarget;
|
|
290
|
+
text: SalesNoteTextInput;
|
|
291
|
+
}
|
|
292
|
+
export interface SalesNoteDraftInput {
|
|
293
|
+
note_type: string;
|
|
294
|
+
text: SalesNoteTextInput;
|
|
295
|
+
}
|
|
296
|
+
export interface SalesNotesRuntimeState {
|
|
297
|
+
loaded: boolean;
|
|
298
|
+
dirty: boolean;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Sales Notes 乐观写入前的可恢复快照。
|
|
302
|
+
* 该对象应视为 opaque token,只用于原样传回 restoreSalesNotesMutationSnapshot。
|
|
303
|
+
*/
|
|
304
|
+
export interface SalesNotesMutationSnapshot {
|
|
305
|
+
orderIdentity: {
|
|
306
|
+
orderId: number | string | null;
|
|
307
|
+
externalSaleNumber: string;
|
|
308
|
+
};
|
|
309
|
+
notes: SalesNote[];
|
|
310
|
+
state: SalesNotesRuntimeState;
|
|
311
|
+
}
|
|
312
|
+
export type SalesNoteProtocolRelation = SalesNoteRelation;
|
|
313
|
+
export type SalesNoteProtocol = SalesNote;
|
|
241
314
|
export interface OrderTempOrder {
|
|
242
315
|
order_id: number | null;
|
|
243
316
|
external_sale_number: string;
|
|
@@ -277,6 +350,7 @@ export interface OrderTempOrder {
|
|
|
277
350
|
created_at: string | undefined;
|
|
278
351
|
request_unique_idempotency_token?: string;
|
|
279
352
|
products: OrderProduct[];
|
|
353
|
+
notes: SalesNote[];
|
|
280
354
|
bookings: any[];
|
|
281
355
|
payments: any[];
|
|
282
356
|
surcharges: any[];
|
|
@@ -289,6 +363,7 @@ export interface OrderTempOrder {
|
|
|
289
363
|
summary?: OrderSummary;
|
|
290
364
|
_extend?: {
|
|
291
365
|
productsByUid?: Record<string, Record<string, any>>;
|
|
366
|
+
salesNotesState?: SalesNotesRuntimeState;
|
|
292
367
|
[key: string]: any;
|
|
293
368
|
};
|
|
294
369
|
}
|
|
@@ -297,7 +372,7 @@ export interface OrderSubmitProduct extends Omit<OrderProduct, 'unique_identific
|
|
|
297
372
|
payment_price: string;
|
|
298
373
|
product_sku: OrderProductSku;
|
|
299
374
|
}
|
|
300
|
-
export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | '_extend' | 'customer' | 'discount_list' | 'created_at'> {
|
|
375
|
+
export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | 'notes' | '_extend' | 'customer' | 'discount_list' | 'created_at'> {
|
|
301
376
|
platform: string;
|
|
302
377
|
created_at?: string | undefined;
|
|
303
378
|
request_unique_idempotency_token?: string;
|
|
@@ -306,6 +381,7 @@ export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'p
|
|
|
306
381
|
form_record_id: number | string;
|
|
307
382
|
}>;
|
|
308
383
|
products: OrderSubmitProduct[];
|
|
384
|
+
notes?: SalesNoteProtocol[];
|
|
309
385
|
summary?: OrderSummary;
|
|
310
386
|
small_ticket_data_flag?: number;
|
|
311
387
|
}
|
|
@@ -334,6 +410,8 @@ export interface AddProductToOrderOptions {
|
|
|
334
410
|
insertAfterProductUid?: string;
|
|
335
411
|
/** 跳过同商品/规格匹配,始终新增购物车行。 */
|
|
336
412
|
disableMerge?: boolean;
|
|
413
|
+
/** 商品行 UID 落定后,由 OrderModule 原子绑定到该行的 Sales Notes 草稿。 */
|
|
414
|
+
salesNotes?: SalesNoteDraftInput[];
|
|
337
415
|
}
|
|
338
416
|
/**
|
|
339
417
|
* 删除商品后的可选位置保持策略。
|
|
@@ -749,9 +827,17 @@ export interface OrderModuleAPI {
|
|
|
749
827
|
updateTempOrderShopDiscount: (amount: string | number) => string;
|
|
750
828
|
updateTempOrderDepositAmount: (amount: string | number) => OrderSummary;
|
|
751
829
|
updateTempOrderCustomer: (customer: UpdateTempOrderCustomerInput) => OrderSnapshot['customer'];
|
|
830
|
+
updateTempOrderPickupReferenceMode: (mode: PickupReferenceMode) => ShopServiceData;
|
|
831
|
+
updateTempOrderServiceType: (serviceType: ShopServiceType) => ShopServiceData;
|
|
752
832
|
updateTempOrderBuzzer: (buzzer: string) => string;
|
|
753
833
|
updateTempOrderContactsInfo: (contactsInfo: Record<string, any> | null) => Record<string, any> | null;
|
|
754
834
|
addProductToOrder: (product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions) => Promise<OrderProduct[]>;
|
|
835
|
+
getSalesNotes: () => SalesNote[];
|
|
836
|
+
createSalesNotesMutationSnapshot: () => SalesNotesMutationSnapshot;
|
|
837
|
+
restoreSalesNotesMutationSnapshot: (snapshot: SalesNotesMutationSnapshot) => void;
|
|
838
|
+
setSalesNote: (input: SetSalesNoteInput) => Promise<SalesNote>;
|
|
839
|
+
removeSalesNote: (uuid: string) => Promise<void>;
|
|
840
|
+
clearSalesNotes: () => Promise<void>;
|
|
755
841
|
updateOrderProduct: (params: UpdateOrderProductParams) => Promise<OrderProduct[]>;
|
|
756
842
|
/** 批量更新购物车行,末尾仅触发一次促销重算与 summary 刷新 */
|
|
757
843
|
updateOrderProducts: (paramsList: UpdateOrderProductParams[]) => Promise<OrderProduct[]>;
|
|
@@ -899,10 +985,10 @@ export interface OrderModuleAPI {
|
|
|
899
985
|
/** 读取上次 applyPromotion 产出的赠品操作 diff(toAdd / toReduce / toRemove) */
|
|
900
986
|
getLastGiftActions: () => OrderLastGiftActions | null;
|
|
901
987
|
/**
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
988
|
+
* 取消订单
|
|
989
|
+
* @param params 取消订单参数
|
|
990
|
+
* @returns 后端返回结果
|
|
991
|
+
*/
|
|
906
992
|
cancelOrder: (params: CancelOrderParams) => Promise<any>;
|
|
907
993
|
/**
|
|
908
994
|
* 变更预约状态
|
|
@@ -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 尾部;预约数量同步可插入到既有预约组的最新行之后,
|
|
@@ -210,6 +210,18 @@ export interface SubmitPayloadEnhancerContext {
|
|
|
210
210
|
now: Date;
|
|
211
211
|
}
|
|
212
212
|
export type SubmitPayloadEnhancer = (payload: OrderSubmitPayload, ctx: SubmitPayloadEnhancerContext) => OrderSubmitPayload;
|
|
213
|
+
/**
|
|
214
|
+
* 解析 checkout 的订单类型。
|
|
215
|
+
* dine_in 普通落库单在新增桌台资源后,即使原类型仍是 virtual,也必须按 table-order 提交。
|
|
216
|
+
*/
|
|
217
|
+
export declare function resolveSubmitOrderType(params: {
|
|
218
|
+
requestedType?: string;
|
|
219
|
+
tempOrderType?: string;
|
|
220
|
+
orderId?: unknown;
|
|
221
|
+
businessCode?: string;
|
|
222
|
+
tempOrderBusinessCode?: string;
|
|
223
|
+
bookings?: unknown;
|
|
224
|
+
}): string;
|
|
213
225
|
export declare function buildSubmitPayload(params: {
|
|
214
226
|
tempOrder: OrderTempOrder;
|
|
215
227
|
cacheId?: string;
|