@pisell/pisellos 2.3.94 → 2.3.96
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/dataVariant/evaluator.js +13 -2
- 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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/Order/index.d.ts +20 -3
- package/dist/modules/Order/index.js +931 -508
- 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/SalesSummary/index.js +6 -4
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +57 -11
- package/dist/server/modules/products/index.d.ts +2 -2
- package/dist/server/modules/products/index.js +10 -9
- package/dist/server/utils/product.d.ts +1 -1
- package/dist/server/utils/product.js +186 -22
- package/dist/server/utils/small-ticket.js +23 -2
- package/dist/solution/BaseSales/index.d.ts +9 -1
- package/dist/solution/BaseSales/index.js +894 -706
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
- 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 +751 -483
- 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/dataVariant/evaluator.js +12 -2
- 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 +20 -3
- package/lib/modules/Order/index.js +358 -42
- 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/SalesSummary/index.js +3 -1
- package/lib/server/index.d.ts +6 -0
- package/lib/server/index.js +47 -9
- package/lib/server/modules/products/index.d.ts +2 -2
- package/lib/server/modules/products/index.js +5 -4
- package/lib/server/utils/product.d.ts +1 -1
- package/lib/server/utils/product.js +163 -3
- package/lib/server/utils/small-ticket.js +22 -1
- package/lib/solution/BaseSales/index.d.ts +9 -1
- package/lib/solution/BaseSales/index.js +105 -1
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
- 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 +125 -1
- 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
|
@@ -9,6 +9,7 @@ var _types = require("./types");
|
|
|
9
9
|
var _utils = require("./utils");
|
|
10
10
|
var _utils2 = require("../Product/utils");
|
|
11
11
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
12
|
+
var _salesNotes = require("./salesNotes");
|
|
12
13
|
var _paymentUtils = require("./payment-utils");
|
|
13
14
|
var _paymentNumber = require("../../utils/payment-number");
|
|
14
15
|
var _cartPromotion = require("../../solution/BaseSales/utils/cartPromotion");
|
|
@@ -904,6 +905,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
904
905
|
this.store.tempOrder = {
|
|
905
906
|
...this.store.tempOrder,
|
|
906
907
|
products: [...this.store.tempOrder.products],
|
|
908
|
+
notes: [...(this.store.tempOrder.notes || [])],
|
|
907
909
|
bookings: this.store.tempOrder.bookings ? [...this.store.tempOrder.bookings] : []
|
|
908
910
|
};
|
|
909
911
|
this.persistTempOrder();
|
|
@@ -1006,19 +1008,26 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1006
1008
|
normalizeDepositAmount(amount) {
|
|
1007
1009
|
return _decimal.default.max(new _decimal.default(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
|
|
1008
1010
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
if (
|
|
1012
|
-
|
|
1011
|
+
normalizeDepositFlag(value) {
|
|
1012
|
+
if (value === 0 || value === '0') return 0;
|
|
1013
|
+
if (value === 1 || value === '1') return 1;
|
|
1014
|
+
return null;
|
|
1015
|
+
}
|
|
1016
|
+
getHistoricalDepositSnapshot(source) {
|
|
1017
|
+
if (!source || typeof source !== 'object') return null;
|
|
1018
|
+
const record = source;
|
|
1019
|
+
const rawDepositAmount = record.deposit_amount ?? record.summary?.deposit_amount;
|
|
1013
1020
|
const depositAmount = this.normalizeDepositAmount(rawDepositAmount ?? 0);
|
|
1014
|
-
|
|
1015
|
-
const isDeposit = Number(lastOrderInfo.is_deposit) === 1 || hasDepositAmount;
|
|
1016
|
-
if (!isDeposit || !hasDepositAmount) return null;
|
|
1021
|
+
if (!new _decimal.default(depositAmount).gt(0)) return null;
|
|
1017
1022
|
return {
|
|
1018
|
-
|
|
1023
|
+
// 兼容历史数据:旧快照缺少 is_deposit 时,沿用正定金金额的推导规则。
|
|
1024
|
+
isDeposit: this.normalizeDepositFlag(record.is_deposit) ?? 1,
|
|
1019
1025
|
depositAmount
|
|
1020
1026
|
};
|
|
1021
1027
|
}
|
|
1028
|
+
getLastOrderDepositSnapshot() {
|
|
1029
|
+
return this.getHistoricalDepositSnapshot(this.store.lastOrderInfo);
|
|
1030
|
+
}
|
|
1022
1031
|
getLastOrderSubmitSnapshot() {
|
|
1023
1032
|
const lastOrderInfo = this.store.lastOrderInfo;
|
|
1024
1033
|
if (!lastOrderInfo || typeof lastOrderInfo !== 'object') return {};
|
|
@@ -1066,7 +1075,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1066
1075
|
}
|
|
1067
1076
|
};
|
|
1068
1077
|
tempOrder.deposit_amount = snapshot.depositAmount;
|
|
1069
|
-
tempOrder.is_deposit =
|
|
1078
|
+
tempOrder.is_deposit = snapshot.isDeposit;
|
|
1070
1079
|
return nextSummary;
|
|
1071
1080
|
}
|
|
1072
1081
|
isDepositOrder(tempOrder, depositAmount) {
|
|
@@ -1603,10 +1612,17 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1603
1612
|
...(0, _lodashEs.cloneDeep)(snapshot.summary || {})
|
|
1604
1613
|
};
|
|
1605
1614
|
const shouldUseManualDepositOverride = Boolean(manualDepositOverride && manualDepositOverride.productStructuralFingerprint === this.buildOrderProductsStructuralFingerprint(tempOrder.products));
|
|
1615
|
+
const historicalDepositSnapshot = this.getHistoricalDepositSnapshot(snapshot);
|
|
1606
1616
|
if (shouldUseManualDepositOverride) {
|
|
1607
1617
|
summary = this.applyDepositAmountToSummary(tempOrder, summary, manualDepositOverride.amount);
|
|
1608
|
-
} else
|
|
1609
|
-
|
|
1618
|
+
} else {
|
|
1619
|
+
if (manualDepositOverride) {
|
|
1620
|
+
this.clearManualDepositOverride(tempOrder);
|
|
1621
|
+
}
|
|
1622
|
+
if (historicalDepositSnapshot) {
|
|
1623
|
+
summary = this.applyDepositAmountToSummary(tempOrder, summary, historicalDepositSnapshot.depositAmount);
|
|
1624
|
+
tempOrder.is_deposit = historicalDepositSnapshot.isDeposit;
|
|
1625
|
+
}
|
|
1610
1626
|
}
|
|
1611
1627
|
const isPayableAmountUnchanged = this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary);
|
|
1612
1628
|
if (!isPayableAmountUnchanged) return null;
|
|
@@ -1623,8 +1639,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1623
1639
|
tempOrder.surcharges = (0, _lodashEs.cloneDeep)(snapshot.surcharges);
|
|
1624
1640
|
}
|
|
1625
1641
|
tempOrder.surcharge_fee = summary.surcharge_fee || tempOrder.surcharge_fee;
|
|
1626
|
-
tempOrder.deposit_amount = summary.deposit_amount ||
|
|
1627
|
-
tempOrder.is_deposit =
|
|
1642
|
+
tempOrder.deposit_amount = this.normalizeDepositAmount(summary.deposit_amount || 0);
|
|
1643
|
+
tempOrder.is_deposit = shouldUseManualDepositOverride ? new _decimal.default(tempOrder.deposit_amount).gt(0) ? 1 : 0 : historicalDepositSnapshot?.isDeposit ?? (new _decimal.default(tempOrder.deposit_amount).gt(0) ? 1 : 0);
|
|
1628
1644
|
const previousSummary = this.store.summary;
|
|
1629
1645
|
this.store.summary = summary;
|
|
1630
1646
|
this.updateTempOrderPaymentStatus(tempOrder, {
|
|
@@ -2081,7 +2097,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2081
2097
|
const isExistingDepositDisabled = tempOrder.is_deposit === 0 && new _decimal.default(tempOrder.deposit_amount || 0).gt(0);
|
|
2082
2098
|
tempOrder.deposit_amount = depositAmount;
|
|
2083
2099
|
tempOrder.is_deposit = hasDepositAmount && !isExistingDepositDisabled ? 1 : 0;
|
|
2084
|
-
return this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
|
|
2100
|
+
return shouldUseManualDepositOverride ? nextSummary : this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
|
|
2085
2101
|
}
|
|
2086
2102
|
async recalculateSummary(options) {
|
|
2087
2103
|
const tempOrder = options?.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
|
|
@@ -2222,6 +2238,179 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2222
2238
|
getTempOrderNote() {
|
|
2223
2239
|
return this.store.tempOrder?.note || '';
|
|
2224
2240
|
}
|
|
2241
|
+
ensureSalesNotesRuntimeState(tempOrder) {
|
|
2242
|
+
const hadNotesSnapshot = Array.isArray(tempOrder.notes);
|
|
2243
|
+
if (!Array.isArray(tempOrder.notes)) tempOrder.notes = [];
|
|
2244
|
+
if (!tempOrder._extend || typeof tempOrder._extend !== 'object') {
|
|
2245
|
+
tempOrder._extend = {
|
|
2246
|
+
productsByUid: {}
|
|
2247
|
+
};
|
|
2248
|
+
}
|
|
2249
|
+
if (!tempOrder._extend.salesNotesState) {
|
|
2250
|
+
tempOrder._extend.salesNotesState = {
|
|
2251
|
+
loaded: hadNotesSnapshot,
|
|
2252
|
+
dirty: false
|
|
2253
|
+
};
|
|
2254
|
+
}
|
|
2255
|
+
return tempOrder._extend.salesNotesState;
|
|
2256
|
+
}
|
|
2257
|
+
ensureSalesNotesLoadedForMutation(tempOrder) {
|
|
2258
|
+
const state = this.ensureSalesNotesRuntimeState(tempOrder);
|
|
2259
|
+
if (state.loaded) return;
|
|
2260
|
+
if (tempOrder.order_id === null || tempOrder.order_id === undefined) {
|
|
2261
|
+
state.loaded = true;
|
|
2262
|
+
tempOrder.notes = [];
|
|
2263
|
+
return;
|
|
2264
|
+
}
|
|
2265
|
+
throw new Error('[Order Notes] 当前订单 Notes 尚未完整加载,禁止提交部分快照');
|
|
2266
|
+
}
|
|
2267
|
+
normalizeSalesNoteUuid(value, field) {
|
|
2268
|
+
const uuid = String(value ?? '').trim();
|
|
2269
|
+
if (!uuid) throw new Error(`[Order Notes] ${field} 不能为空`);
|
|
2270
|
+
if (uuid.length > 255) {
|
|
2271
|
+
throw new Error(`[Order Notes] ${field} 不能超过 255 个字符`);
|
|
2272
|
+
}
|
|
2273
|
+
return uuid;
|
|
2274
|
+
}
|
|
2275
|
+
getSalesNotePrimaryRelation(note) {
|
|
2276
|
+
return note.note_relations.find(relation => relation.is_primary === 1) || null;
|
|
2277
|
+
}
|
|
2278
|
+
removeSalesNotesForMissingProductLines(tempOrder) {
|
|
2279
|
+
const state = this.ensureSalesNotesRuntimeState(tempOrder);
|
|
2280
|
+
if (!state.loaded || !Array.isArray(tempOrder.notes) || tempOrder.notes.length === 0) {
|
|
2281
|
+
return;
|
|
2282
|
+
}
|
|
2283
|
+
const remainingProductUids = new Set((tempOrder.products || []).map(product => product.metadata?.unique_identification_number || product.unique_identification_number).filter(uid => typeof uid === 'string' && uid.length > 0));
|
|
2284
|
+
const nextNotes = tempOrder.notes.filter(note => {
|
|
2285
|
+
const primary = this.getSalesNotePrimaryRelation(note);
|
|
2286
|
+
if (!primary || primary.target_type !== 'order_detail') return true;
|
|
2287
|
+
return remainingProductUids.has(primary.target_uuid);
|
|
2288
|
+
});
|
|
2289
|
+
if (nextNotes.length === tempOrder.notes.length) return;
|
|
2290
|
+
tempOrder.notes = nextNotes;
|
|
2291
|
+
state.dirty = true;
|
|
2292
|
+
}
|
|
2293
|
+
setSalesNoteOnTempOrder(tempOrder, input) {
|
|
2294
|
+
this.ensureSalesNotesLoadedForMutation(tempOrder);
|
|
2295
|
+
const note_type = String(input.note_type || '').trim();
|
|
2296
|
+
const policy = (0, _salesNotes.getSalesNotePolicy)(note_type);
|
|
2297
|
+
if (!policy) {
|
|
2298
|
+
throw new Error(`[Order Notes] 当前未注册备注类型: ${note_type || '(empty)'}`);
|
|
2299
|
+
}
|
|
2300
|
+
if (input.target?.target_type !== 'order_detail') {
|
|
2301
|
+
throw new Error('[Order Notes] 本期只支持 order_detail 作为主体');
|
|
2302
|
+
}
|
|
2303
|
+
const target_uuid = this.normalizeSalesNoteUuid(input.target.target_uuid, 'target_uuid');
|
|
2304
|
+
const targetProductExists = (tempOrder.products || []).some(product => {
|
|
2305
|
+
const productLineUid = product.metadata?.unique_identification_number || product.unique_identification_number;
|
|
2306
|
+
return String(productLineUid ?? '') === target_uuid;
|
|
2307
|
+
});
|
|
2308
|
+
if (!targetProductExists) {
|
|
2309
|
+
throw new Error('[Order Notes] 目标商品行不存在');
|
|
2310
|
+
}
|
|
2311
|
+
const text = (0, _salesNotes.buildSalesNoteText)(input.text);
|
|
2312
|
+
const notes = tempOrder.notes || [];
|
|
2313
|
+
// 当前 allergy policy 固定同一商品行只保留一条;业务调用方不参与去重规则。
|
|
2314
|
+
const existingIndex = policy.uniquePerPrimaryTarget ? notes.findIndex(note => {
|
|
2315
|
+
const primary = this.getSalesNotePrimaryRelation(note);
|
|
2316
|
+
return note.note_type === note_type && primary?.target_type === 'order_detail' && primary.target_uuid === target_uuid;
|
|
2317
|
+
}) : -1;
|
|
2318
|
+
const existing = existingIndex >= 0 ? notes[existingIndex] : null;
|
|
2319
|
+
const existingPrimary = existing?.note_relations.find(relation => relation.is_primary === 1 && relation.target_type === 'order_detail');
|
|
2320
|
+
const existingOrderRelation = existing?.note_relations.find(relation => relation.is_primary === 0 && relation.target_type === 'order');
|
|
2321
|
+
const note = {
|
|
2322
|
+
uuid: existing?.uuid || (0, _utils.createUuidV4)(),
|
|
2323
|
+
note_type: policy.note_type,
|
|
2324
|
+
content: {
|
|
2325
|
+
text
|
|
2326
|
+
},
|
|
2327
|
+
importance: policy.importance,
|
|
2328
|
+
note_relations: [{
|
|
2329
|
+
uuid: existingPrimary?.uuid || (0, _utils.createUuidV4)(),
|
|
2330
|
+
relation_type: policy.primary_relation_type,
|
|
2331
|
+
target_type: 'order_detail',
|
|
2332
|
+
target_uuid,
|
|
2333
|
+
is_primary: 1
|
|
2334
|
+
}, {
|
|
2335
|
+
uuid: existingOrderRelation?.uuid || (0, _utils.createUuidV4)(),
|
|
2336
|
+
relation_type: policy.secondary_order_relation_type,
|
|
2337
|
+
target_type: 'order',
|
|
2338
|
+
target_uuid: String(tempOrder.shop_order_number ?? ''),
|
|
2339
|
+
is_primary: 0
|
|
2340
|
+
}]
|
|
2341
|
+
};
|
|
2342
|
+
const duplicateIndex = notes.findIndex((item, index) => item.uuid === note.uuid && index !== existingIndex);
|
|
2343
|
+
if (duplicateIndex >= 0) {
|
|
2344
|
+
throw new Error('[Order Notes] uuid 已被其他 Note 使用');
|
|
2345
|
+
}
|
|
2346
|
+
tempOrder.notes = existingIndex >= 0 ? notes.map((item, index) => index === existingIndex ? note : item) : [...notes, note];
|
|
2347
|
+
const state = this.ensureSalesNotesRuntimeState(tempOrder);
|
|
2348
|
+
state.loaded = true;
|
|
2349
|
+
state.dirty = true;
|
|
2350
|
+
return note;
|
|
2351
|
+
}
|
|
2352
|
+
getSalesNotes() {
|
|
2353
|
+
const tempOrder = this.ensureTempOrder();
|
|
2354
|
+
this.ensureSalesNotesRuntimeState(tempOrder);
|
|
2355
|
+
return (0, _lodashEs.cloneDeep)(tempOrder.notes || []);
|
|
2356
|
+
}
|
|
2357
|
+
createSalesNotesMutationSnapshot() {
|
|
2358
|
+
const tempOrder = this.ensureTempOrder();
|
|
2359
|
+
const state = this.ensureSalesNotesRuntimeState(tempOrder);
|
|
2360
|
+
return {
|
|
2361
|
+
orderIdentity: {
|
|
2362
|
+
orderId: tempOrder.order_id ?? null,
|
|
2363
|
+
externalSaleNumber: String(tempOrder.external_sale_number || '')
|
|
2364
|
+
},
|
|
2365
|
+
notes: (0, _lodashEs.cloneDeep)(tempOrder.notes || []),
|
|
2366
|
+
state: (0, _lodashEs.cloneDeep)(state)
|
|
2367
|
+
};
|
|
2368
|
+
}
|
|
2369
|
+
restoreSalesNotesMutationSnapshot(snapshot) {
|
|
2370
|
+
if (!snapshot || !Array.isArray(snapshot.notes) || !snapshot.orderIdentity || typeof snapshot.orderIdentity.externalSaleNumber !== 'string' || typeof snapshot.state?.loaded !== 'boolean' || typeof snapshot.state?.dirty !== 'boolean') {
|
|
2371
|
+
throw new Error('[Order Notes] 无效的 mutation snapshot');
|
|
2372
|
+
}
|
|
2373
|
+
const tempOrder = this.store.tempOrder;
|
|
2374
|
+
if (!tempOrder) throw new Error('[Order Notes] 当前订单不存在');
|
|
2375
|
+
const snapshotOrderId = snapshot.orderIdentity.orderId;
|
|
2376
|
+
const currentOrderId = tempOrder.order_id;
|
|
2377
|
+
const hasSnapshotOrderId = snapshotOrderId !== null && snapshotOrderId !== undefined && String(snapshotOrderId).trim().length > 0;
|
|
2378
|
+
const hasCurrentOrderId = currentOrderId !== null && currentOrderId !== undefined && String(currentOrderId).trim().length > 0;
|
|
2379
|
+
const isSameOrder = hasSnapshotOrderId && hasCurrentOrderId ? String(snapshotOrderId) === String(currentOrderId) : Boolean(snapshot.orderIdentity.externalSaleNumber) && snapshot.orderIdentity.externalSaleNumber === String(tempOrder.external_sale_number || '');
|
|
2380
|
+
if (!isSameOrder) {
|
|
2381
|
+
throw new Error('[Order Notes] 当前订单已切换,拒绝恢复旧订单快照');
|
|
2382
|
+
}
|
|
2383
|
+
this.ensureSalesNotesRuntimeState(tempOrder);
|
|
2384
|
+
tempOrder.notes = (0, _lodashEs.cloneDeep)(snapshot.notes);
|
|
2385
|
+
tempOrder._extend.salesNotesState = (0, _lodashEs.cloneDeep)(snapshot.state);
|
|
2386
|
+
this.notifyTempOrderChanged();
|
|
2387
|
+
}
|
|
2388
|
+
async setSalesNote(input) {
|
|
2389
|
+
const tempOrder = this.ensureTempOrder();
|
|
2390
|
+
const note = this.setSalesNoteOnTempOrder(tempOrder, input);
|
|
2391
|
+
this.notifyTempOrderChanged();
|
|
2392
|
+
return (0, _lodashEs.cloneDeep)(note);
|
|
2393
|
+
}
|
|
2394
|
+
async removeSalesNote(uuid) {
|
|
2395
|
+
const tempOrder = this.ensureTempOrder();
|
|
2396
|
+
this.ensureSalesNotesLoadedForMutation(tempOrder);
|
|
2397
|
+
const normalizedUuid = this.normalizeSalesNoteUuid(uuid, 'uuid');
|
|
2398
|
+
const notes = tempOrder.notes || [];
|
|
2399
|
+
const nextNotes = notes.filter(note => note.uuid !== normalizedUuid);
|
|
2400
|
+
if (nextNotes.length === notes.length) return;
|
|
2401
|
+
tempOrder.notes = nextNotes;
|
|
2402
|
+
const state = this.ensureSalesNotesRuntimeState(tempOrder);
|
|
2403
|
+
state.dirty = true;
|
|
2404
|
+
this.notifyTempOrderChanged();
|
|
2405
|
+
}
|
|
2406
|
+
async clearSalesNotes() {
|
|
2407
|
+
const tempOrder = this.ensureTempOrder();
|
|
2408
|
+
tempOrder.notes = [];
|
|
2409
|
+
const state = this.ensureSalesNotesRuntimeState(tempOrder);
|
|
2410
|
+
state.loaded = true;
|
|
2411
|
+
state.dirty = true;
|
|
2412
|
+
this.notifyTempOrderChanged();
|
|
2413
|
+
}
|
|
2225
2414
|
updateTempOrderShopDiscount(amount) {
|
|
2226
2415
|
const tempOrder = this.ensureTempOrder();
|
|
2227
2416
|
const discount = _decimal.default.max(new _decimal.default(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
|
|
@@ -2261,6 +2450,31 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2261
2450
|
this.persistTempOrder();
|
|
2262
2451
|
return tempOrder.buzzer;
|
|
2263
2452
|
}
|
|
2453
|
+
updateTempOrderShopServiceData(patch) {
|
|
2454
|
+
const tempOrder = this.ensureTempOrder();
|
|
2455
|
+
const metadata = tempOrder.metadata && typeof tempOrder.metadata === 'object' && !Array.isArray(tempOrder.metadata) ? tempOrder.metadata : {};
|
|
2456
|
+
const currentShopServiceData = metadata.shop_service_data && typeof metadata.shop_service_data === 'object' && !Array.isArray(metadata.shop_service_data) ? metadata.shop_service_data : {};
|
|
2457
|
+
const shopServiceData = {
|
|
2458
|
+
...currentShopServiceData,
|
|
2459
|
+
...patch
|
|
2460
|
+
};
|
|
2461
|
+
tempOrder.metadata = {
|
|
2462
|
+
...metadata,
|
|
2463
|
+
shop_service_data: shopServiceData
|
|
2464
|
+
};
|
|
2465
|
+
this.persistTempOrder();
|
|
2466
|
+
return shopServiceData;
|
|
2467
|
+
}
|
|
2468
|
+
updateTempOrderPickupReferenceMode(mode) {
|
|
2469
|
+
return this.updateTempOrderShopServiceData({
|
|
2470
|
+
pickup_reference_mode: mode
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
updateTempOrderServiceType(serviceType) {
|
|
2474
|
+
return this.updateTempOrderShopServiceData({
|
|
2475
|
+
service_type: serviceType
|
|
2476
|
+
});
|
|
2477
|
+
}
|
|
2264
2478
|
updateTempOrderContactsInfo(contactsInfo) {
|
|
2265
2479
|
const tempOrder = this.ensureTempOrder();
|
|
2266
2480
|
tempOrder.contacts_info = contactsInfo && typeof contactsInfo === 'object' && !Array.isArray(contactsInfo) ? contactsInfo : null;
|
|
@@ -2850,6 +3064,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2850
3064
|
const matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
|
|
2851
3065
|
const existedFingerprint = matchedProduct ? (0, _utils3.buildProductLineFingerprint)((0, _utils.getProductSkuOptions)(matchedProduct), matchedProduct.product_bundle) : '';
|
|
2852
3066
|
const commitProductLine = shouldMerge => {
|
|
3067
|
+
let committedProduct;
|
|
2853
3068
|
if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
|
|
2854
3069
|
this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
|
|
2855
3070
|
if (linked) {
|
|
@@ -2865,6 +3080,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2865
3080
|
} else {
|
|
2866
3081
|
tempOrder.products = [...tempOrder.products, normalizedIncoming];
|
|
2867
3082
|
}
|
|
3083
|
+
committedProduct = normalizedIncoming;
|
|
2868
3084
|
} else {
|
|
2869
3085
|
const targetProduct = matchedProduct;
|
|
2870
3086
|
const targetUid = targetProduct.metadata?.unique_identification_number;
|
|
@@ -2900,6 +3116,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2900
3116
|
num: nextNum
|
|
2901
3117
|
};
|
|
2902
3118
|
this.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
|
|
3119
|
+
committedProduct = tempOrder.products[matchedIndex];
|
|
2903
3120
|
if (matchedIndex !== tempOrder.products.length - 1) {
|
|
2904
3121
|
const mergedProduct = tempOrder.products[matchedIndex];
|
|
2905
3122
|
tempOrder.products = [...tempOrder.products.slice(0, matchedIndex), ...tempOrder.products.slice(matchedIndex + 1), mergedProduct];
|
|
@@ -2908,10 +3125,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2908
3125
|
if (linked) {
|
|
2909
3126
|
tempOrder.bookings = [...(tempOrder.bookings || []), linked.booking];
|
|
2910
3127
|
}
|
|
3128
|
+
return committedProduct;
|
|
2911
3129
|
};
|
|
2912
3130
|
if (!matchedProduct) {
|
|
2913
|
-
commitProductLine(false);
|
|
2914
|
-
return;
|
|
3131
|
+
return commitProductLine(false);
|
|
2915
3132
|
}
|
|
2916
3133
|
const shouldMerge = this.shouldMergeProductToOrder({
|
|
2917
3134
|
incomingProduct: productToAdd,
|
|
@@ -2926,7 +3143,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2926
3143
|
if (shouldMerge && typeof shouldMerge === 'object' && typeof shouldMerge.then === 'function') {
|
|
2927
3144
|
return Promise.resolve(shouldMerge).then(commitProductLine);
|
|
2928
3145
|
}
|
|
2929
|
-
commitProductLine(shouldMerge);
|
|
3146
|
+
return commitProductLine(shouldMerge);
|
|
2930
3147
|
}
|
|
2931
3148
|
|
|
2932
3149
|
/**
|
|
@@ -2938,36 +3155,102 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2938
3155
|
*/
|
|
2939
3156
|
async addProductToOrder(product, booking, options) {
|
|
2940
3157
|
const tempOrder = this.ensureTempOrder();
|
|
3158
|
+
const salesNoteDrafts = (options?.salesNotes || []).map(draft => ({
|
|
3159
|
+
note_type: String(draft.note_type || '').trim(),
|
|
3160
|
+
text: {
|
|
3161
|
+
kind: 'resolved',
|
|
3162
|
+
text: (0, _salesNotes.buildSalesNoteText)(draft.text)
|
|
3163
|
+
}
|
|
3164
|
+
}));
|
|
3165
|
+
const mutationSnapshot = salesNoteDrafts.length > 0 ? {
|
|
3166
|
+
products: (0, _lodashEs.cloneDeep)(tempOrder.products || []),
|
|
3167
|
+
bookings: (0, _lodashEs.cloneDeep)(tempOrder.bookings || []),
|
|
3168
|
+
notes: (0, _lodashEs.cloneDeep)(tempOrder.notes || []),
|
|
3169
|
+
extend: (0, _lodashEs.cloneDeep)(tempOrder._extend || {})
|
|
3170
|
+
} : null;
|
|
3171
|
+
const attachSalesNoteDrafts = orderProduct => {
|
|
3172
|
+
if (!salesNoteDrafts.length) return;
|
|
3173
|
+
const productLineUid = orderProduct.metadata?.unique_identification_number || orderProduct.unique_identification_number;
|
|
3174
|
+
if (!productLineUid) {
|
|
3175
|
+
throw new Error('[Order Notes] 商品行缺少 unique_identification_number');
|
|
3176
|
+
}
|
|
3177
|
+
salesNoteDrafts.forEach(draft => {
|
|
3178
|
+
this.setSalesNoteOnTempOrder(tempOrder, {
|
|
3179
|
+
note_type: draft.note_type,
|
|
3180
|
+
target: {
|
|
3181
|
+
target_type: 'order_detail',
|
|
3182
|
+
target_uuid: String(productLineUid)
|
|
3183
|
+
},
|
|
3184
|
+
text: draft.text
|
|
3185
|
+
});
|
|
3186
|
+
});
|
|
3187
|
+
};
|
|
3188
|
+
const rollbackProductAndNotesMutation = () => {
|
|
3189
|
+
if (!mutationSnapshot) return;
|
|
3190
|
+
tempOrder.products = mutationSnapshot.products;
|
|
3191
|
+
tempOrder.bookings = mutationSnapshot.bookings;
|
|
3192
|
+
tempOrder.notes = mutationSnapshot.notes;
|
|
3193
|
+
tempOrder._extend = mutationSnapshot.extend;
|
|
3194
|
+
};
|
|
2941
3195
|
const insertAfterProductUid = options?.insertAfterProductUid;
|
|
2942
3196
|
const anchorIndex = booking && insertAfterProductUid ? tempOrder.products.findIndex(line => {
|
|
2943
3197
|
const uid = line.metadata?.unique_identification_number || line.unique_identification_number;
|
|
2944
3198
|
return uid !== undefined && uid !== null && String(uid) === String(insertAfterProductUid);
|
|
2945
3199
|
}) : -1;
|
|
2946
3200
|
let insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : undefined;
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
3201
|
+
try {
|
|
3202
|
+
if (booking) {
|
|
3203
|
+
const productRecord = product;
|
|
3204
|
+
const splitCount = (0, _utils3.getSafeProductNum)(productRecord.num ?? productRecord.product_quantity ?? 1);
|
|
3205
|
+
if (splitCount > 1) {
|
|
3206
|
+
for (let i = 0; i < splitCount; i += 1) {
|
|
3207
|
+
const singleLine = (0, _lodashEs.cloneDeep)(productRecord);
|
|
3208
|
+
const singleBooking = (0, _lodashEs.cloneDeep)(booking);
|
|
3209
|
+
singleLine.num = 1;
|
|
3210
|
+
delete singleLine.product_quantity;
|
|
3211
|
+
if (i > 0) {
|
|
3212
|
+
delete singleLine.unique_identification_number;
|
|
3213
|
+
delete singleLine.identity_key;
|
|
3214
|
+
if (singleLine.metadata) {
|
|
3215
|
+
singleLine.metadata = {
|
|
3216
|
+
...singleLine.metadata
|
|
3217
|
+
};
|
|
3218
|
+
delete singleLine.metadata.unique_identification_number;
|
|
3219
|
+
delete singleLine.metadata.identity_key;
|
|
3220
|
+
}
|
|
3221
|
+
delete singleBooking.booking_uid;
|
|
3222
|
+
if (singleBooking.metadata) {
|
|
3223
|
+
singleBooking.metadata = {
|
|
3224
|
+
...singleBooking.metadata
|
|
3225
|
+
};
|
|
3226
|
+
delete singleBooking.metadata.unique_identification_number;
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
const committedProduct = await this.appendProductLineToTempOrder(tempOrder, singleLine, singleBooking, {
|
|
3230
|
+
insertAtIndex,
|
|
3231
|
+
disableMerge: options?.disableMerge
|
|
3232
|
+
});
|
|
3233
|
+
attachSalesNoteDrafts(committedProduct);
|
|
3234
|
+
if (insertAtIndex !== undefined) insertAtIndex += 1;
|
|
3235
|
+
}
|
|
3236
|
+
} else {
|
|
3237
|
+
const committedProduct = await this.appendProductLineToTempOrder(tempOrder, product, (0, _lodashEs.cloneDeep)(booking), {
|
|
2956
3238
|
insertAtIndex,
|
|
2957
3239
|
disableMerge: options?.disableMerge
|
|
2958
3240
|
});
|
|
2959
|
-
|
|
2960
|
-
if (insertAtIndex !== undefined) insertAtIndex += 1;
|
|
3241
|
+
attachSalesNoteDrafts(committedProduct);
|
|
2961
3242
|
}
|
|
2962
|
-
|
|
2963
|
-
|
|
3243
|
+
} else {
|
|
3244
|
+
const committedProduct = await this.appendProductLineToTempOrder(tempOrder, product, undefined, {
|
|
3245
|
+
insertAtIndex,
|
|
3246
|
+
disableMerge: options?.disableMerge
|
|
3247
|
+
});
|
|
3248
|
+
attachSalesNoteDrafts(committedProduct);
|
|
2964
3249
|
}
|
|
3250
|
+
} catch (error) {
|
|
3251
|
+
rollbackProductAndNotesMutation();
|
|
3252
|
+
throw error;
|
|
2965
3253
|
}
|
|
2966
|
-
const appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking, {
|
|
2967
|
-
insertAtIndex,
|
|
2968
|
-
disableMerge: options?.disableMerge
|
|
2969
|
-
});
|
|
2970
|
-
if (appendResult) await appendResult;
|
|
2971
3254
|
await this.finalizeProductOrderMutation(tempOrder);
|
|
2972
3255
|
this.logInfo('addProductToOrder success', {
|
|
2973
3256
|
product_id: product.product_id,
|
|
@@ -3412,10 +3695,12 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3412
3695
|
*/
|
|
3413
3696
|
async removeProductsFromOrder(identities, options) {
|
|
3414
3697
|
const tempOrder = this.ensureTempOrder();
|
|
3415
|
-
this.repairDuplicateProductLineIdentities(tempOrder);
|
|
3416
3698
|
if (!identities.length) {
|
|
3417
3699
|
return tempOrder.products;
|
|
3418
3700
|
}
|
|
3701
|
+
// 商品删除会同步删除以商品行为主关系的 Notes;快照不完整时禁止产生孤儿 Relation。
|
|
3702
|
+
this.ensureSalesNotesLoadedForMutation(tempOrder);
|
|
3703
|
+
this.repairDuplicateProductLineIdentities(tempOrder);
|
|
3419
3704
|
const productsBeforeRemove = tempOrder.products || [];
|
|
3420
3705
|
const bookingsBeforeRemove = tempOrder.bookings || [];
|
|
3421
3706
|
const preserveDisplayPosition = options?.preserveDisplayPosition;
|
|
@@ -3475,6 +3760,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3475
3760
|
tempOrder.products = nextProductIndex >= 0 ? [...productsWithoutRemaining.slice(0, nextProductIndex), remainingProduct, ...productsWithoutRemaining.slice(nextProductIndex)] : [...productsWithoutRemaining, remainingProduct];
|
|
3476
3761
|
}
|
|
3477
3762
|
}
|
|
3763
|
+
this.removeSalesNotesForMissingProductLines(tempOrder);
|
|
3478
3764
|
await this.finalizeAfterProductsMutation(tempOrder);
|
|
3479
3765
|
this.logInfo('removeProductsFromOrder success', {
|
|
3480
3766
|
identities
|
|
@@ -3487,12 +3773,14 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3487
3773
|
|
|
3488
3774
|
/**
|
|
3489
3775
|
* 仅清空购物车行(products / bookings),不重置整单。
|
|
3490
|
-
*
|
|
3776
|
+
* 普通整单 note 保持不变;以商品行为主体的 Sales Notes 同步删除。
|
|
3491
3777
|
*/
|
|
3492
3778
|
async clearOrderCartLines() {
|
|
3493
3779
|
const tempOrder = this.ensureTempOrder();
|
|
3780
|
+
this.ensureSalesNotesLoadedForMutation(tempOrder);
|
|
3494
3781
|
tempOrder.products = [];
|
|
3495
3782
|
tempOrder.bookings = [];
|
|
3783
|
+
this.removeSalesNotesForMissingProductLines(tempOrder);
|
|
3496
3784
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
3497
3785
|
if (tempOrder._extend && typeof tempOrder._extend === 'object') {
|
|
3498
3786
|
tempOrder._extend = {
|
|
@@ -3695,6 +3983,12 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3695
3983
|
this.logSubmitBackendRejected(result, payload);
|
|
3696
3984
|
return result;
|
|
3697
3985
|
}
|
|
3986
|
+
const isLocalPendingSubmit = this.isLocalPendingSubmitResult(result);
|
|
3987
|
+
// need_sync=1 仅表示已进入本地同步队列,不能视为远端已确认 Notes。
|
|
3988
|
+
if (Object.prototype.hasOwnProperty.call(payload, 'notes') && !isLocalPendingSubmit) {
|
|
3989
|
+
const salesNotesState = this.ensureSalesNotesRuntimeState(tempOrder);
|
|
3990
|
+
salesNotesState.dirty = false;
|
|
3991
|
+
}
|
|
3698
3992
|
const submittedOrderId = this.extractOrderIdFromSubmitResult(result);
|
|
3699
3993
|
this.logInfo('runSubmitTempOrder: 提交成功', {
|
|
3700
3994
|
submittedOrderId,
|
|
@@ -3708,9 +4002,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3708
4002
|
tempOrder.order_id = submittedOrderId;
|
|
3709
4003
|
const resultRecord = result;
|
|
3710
4004
|
await this.markLocalOrderSynced(submittedOrderId, resultRecord?.data || resultRecord || {});
|
|
3711
|
-
}
|
|
4005
|
+
}
|
|
4006
|
+
if (isLocalPendingSubmit) {
|
|
3712
4007
|
this.store.syncState = 'local';
|
|
3713
|
-
} else {
|
|
4008
|
+
} else if (submittedOrderId === null || submittedOrderId === undefined) {
|
|
3714
4009
|
this.store.syncState = 'submitted';
|
|
3715
4010
|
}
|
|
3716
4011
|
return result;
|
|
@@ -4096,7 +4391,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4096
4391
|
params.forceRemote = false;
|
|
4097
4392
|
}
|
|
4098
4393
|
const res = await this.request.get(`/order/sales/${encodeURIComponent(lookup)}`, {
|
|
4099
|
-
with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds'],
|
|
4394
|
+
with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds', 'notes'],
|
|
4100
4395
|
...(params.forceRemote ? {
|
|
4101
4396
|
forceRemote: true
|
|
4102
4397
|
} : {})
|
|
@@ -4149,7 +4444,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4149
4444
|
const isMergedSalesDetailHydrate = options?.source === 'mergedSalesDetail';
|
|
4150
4445
|
const nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
|
|
4151
4446
|
// merge 前已只给远端商品补标记;这里不能把本地未提交商品一并变成 saved item。
|
|
4152
|
-
makeEditMark: !isSessionStorageHydrate && !isMergedSalesDetailHydrate
|
|
4447
|
+
makeEditMark: !isSessionStorageHydrate && !isMergedSalesDetailHydrate,
|
|
4448
|
+
allowUnresolvedSalesNotes: isSessionStorageHydrate
|
|
4153
4449
|
});
|
|
4154
4450
|
this.store.tempOrder = nextTempOrder;
|
|
4155
4451
|
if (isSessionStorageHydrate) {
|
|
@@ -4187,6 +4483,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4187
4483
|
externalSaleNumber: nextTempOrder.external_sale_number
|
|
4188
4484
|
};
|
|
4189
4485
|
const rawSummary = raw.summary && typeof raw.summary === 'object' ? raw.summary : {};
|
|
4486
|
+
const historicalDepositSnapshot = this.getHistoricalDepositSnapshot(sourceLastOrderInfo);
|
|
4190
4487
|
const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(s => ({
|
|
4191
4488
|
...(s || {})
|
|
4192
4489
|
})) : (0, _lodashEs.cloneDeep)(nextTempOrder.surcharges || []);
|
|
@@ -4205,6 +4502,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4205
4502
|
surcharges: (0, _lodashEs.cloneDeep)(nextTempOrder.surcharges || []),
|
|
4206
4503
|
shop_discount: nextTempOrder.shop_discount || '0.00',
|
|
4207
4504
|
productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || []),
|
|
4505
|
+
...(historicalDepositSnapshot ? {
|
|
4506
|
+
is_deposit: historicalDepositSnapshot.isDeposit,
|
|
4507
|
+
deposit_amount: historicalDepositSnapshot.depositAmount
|
|
4508
|
+
} : {}),
|
|
4208
4509
|
// merged record 的 summary 仍是远端旧值,保留快照仅用于完整重算的价格清理基线。
|
|
4209
4510
|
...(isMergedSalesDetailHydrate ? {
|
|
4210
4511
|
requiresFullSummaryRecalculation: true
|
|
@@ -4366,6 +4667,17 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4366
4667
|
nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map(p => ({
|
|
4367
4668
|
...(p || {})
|
|
4368
4669
|
})) : [];
|
|
4670
|
+
const rawHasSalesNotes = Object.prototype.hasOwnProperty.call(raw, 'notes');
|
|
4671
|
+
const restoredSalesNotesState = raw._extend?.salesNotesState;
|
|
4672
|
+
const allowUnresolvedSalesNotes = options?.allowUnresolvedSalesNotes === true || restoredSalesNotesState?.dirty === true || Number(raw.is_draft_order || 0) === 1;
|
|
4673
|
+
const decodedSalesNotes = rawHasSalesNotes ? (0, _salesNotes.decodeSalesNotesSnapshot)(raw.notes, {
|
|
4674
|
+
allowUnresolvedOrderTarget: allowUnresolvedSalesNotes
|
|
4675
|
+
}) : {
|
|
4676
|
+
notes: [],
|
|
4677
|
+
complete: false
|
|
4678
|
+
};
|
|
4679
|
+
const hasUnresolvedSalesNoteOrderTarget = decodedSalesNotes.notes.some(note => note.note_relations.some(relation => relation.is_primary === 0 && relation.relation_type === 'related_to' && relation.target_type === 'order' && relation.target_uuid === ''));
|
|
4680
|
+
nextTempOrder.notes = decodedSalesNotes.notes;
|
|
4369
4681
|
nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map(s => ({
|
|
4370
4682
|
...(s || {})
|
|
4371
4683
|
})) : [];
|
|
@@ -4385,6 +4697,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4385
4697
|
productsByUid: {}
|
|
4386
4698
|
};
|
|
4387
4699
|
const tempOrderExtend = nextTempOrder._extend;
|
|
4700
|
+
tempOrderExtend.salesNotesState = {
|
|
4701
|
+
loaded: rawHasSalesNotes ? decodedSalesNotes.complete : restoredSalesNotesState?.loaded === true,
|
|
4702
|
+
dirty: decodedSalesNotes.complete && (restoredSalesNotesState?.dirty === true || allowUnresolvedSalesNotes && hasUnresolvedSalesNoteOrderTarget)
|
|
4703
|
+
};
|
|
4388
4704
|
const productsByUid = tempOrderExtend.productsByUid || {};
|
|
4389
4705
|
for (const [index, product] of nextTempOrder.products.entries()) {
|
|
4390
4706
|
const uid = product.metadata?.unique_identification_number;
|
|
@@ -4559,7 +4875,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4559
4875
|
}
|
|
4560
4876
|
async getOrderInfo(order_id) {
|
|
4561
4877
|
const res = await this.request.get(`/order/sales/${order_id}`, {
|
|
4562
|
-
with: ['products', 'bookings']
|
|
4878
|
+
with: ['products', 'bookings', 'notes']
|
|
4563
4879
|
}, {
|
|
4564
4880
|
osServer: true
|
|
4565
4881
|
});
|
|
@@ -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[];
|