@pisell/pisellos 0.10.88 → 0.10.91
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 +3 -1
- package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
- package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
- package/dist/model/strategy/adapter/itemRule/type.js +10 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
- package/dist/model/strategy/adapter/promotion/evaluator.js +103 -112
- package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
- package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
- package/dist/modules/BookingContext/utils/index.d.ts +1 -0
- package/dist/modules/BookingContext/utils/index.js +1 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +21 -0
- package/dist/modules/BookingContext/utils/productExtend.js +132 -33
- package/dist/modules/BookingContext/utils/resources.js +1 -1
- package/dist/modules/Cart/index.js +4 -3
- package/dist/modules/Cart/types.d.ts +2 -0
- package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
- package/dist/modules/Cart/utils/cartProduct.js +59 -32
- package/dist/modules/Date/index.d.ts +1 -1
- package/dist/modules/Date/index.js +60 -14
- package/dist/modules/Date/types.d.ts +5 -0
- package/dist/modules/OpenData/salesSettings.js +1 -1
- package/dist/modules/OpenData/types.d.ts +9 -0
- package/dist/modules/OpenData/utils.d.ts +1 -1
- package/dist/modules/OpenData/utils.js +3 -2
- package/dist/modules/Order/index.d.ts +22 -7
- package/dist/modules/Order/index.js +1565 -1161
- package/dist/modules/Order/localEftposState.d.ts +13 -0
- package/dist/modules/Order/localEftposState.js +39 -0
- package/dist/modules/Order/types.d.ts +33 -11
- package/dist/modules/Order/types.js +2 -2
- package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
- package/dist/modules/Order/unpaidAmountGap.js +72 -0
- package/dist/modules/Order/utils.d.ts +4 -1
- package/dist/modules/Order/utils.js +185 -129
- package/dist/modules/Payment/walletpass.js +32 -6
- package/dist/modules/Product/types.d.ts +16 -0
- package/dist/modules/ProductList/index.js +1 -1
- package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
- package/dist/modules/ResourcePlanner/planner.js +383 -24
- package/dist/modules/ResourcePlanner/types.d.ts +42 -0
- package/dist/modules/Rules/index.js +86 -54
- package/dist/modules/Schedule/index.d.ts +7 -1
- package/dist/modules/Schedule/index.js +155 -39
- package/dist/modules/Schedule/types.d.ts +2 -0
- package/dist/modules/bookingReadValidation.d.ts +6 -0
- package/dist/modules/bookingReadValidation.js +72 -0
- package/dist/plugins/request.d.ts +2 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.js +1928 -1462
- package/dist/server/modules/form/index.d.ts +19 -0
- package/dist/server/modules/form/index.js +205 -0
- package/dist/server/modules/form/types.d.ts +13 -0
- package/dist/server/modules/form/types.js +3 -0
- package/dist/server/modules/index.d.ts +3 -0
- package/dist/server/modules/index.js +4 -0
- package/dist/server/modules/order/index.d.ts +21 -0
- package/dist/server/modules/order/index.js +1399 -831
- package/dist/server/modules/order/types.d.ts +3 -0
- package/dist/server/modules/order/utils/filterOrders.js +20 -0
- package/dist/server/modules/products/index.d.ts +28 -7
- package/dist/server/modules/products/index.js +1295 -769
- package/dist/server/modules/products/replication.d.ts +8 -0
- package/dist/server/modules/products/replication.js +69 -0
- package/dist/server/modules/products/types.d.ts +12 -1
- package/dist/server/modules/products/types.js +4 -0
- package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
- package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
- package/dist/shared/receipt/small-ticket.d.ts +1 -0
- package/dist/shared/receipt/small-ticket.js +58 -26
- package/dist/shared/receipt/templateVisibility.d.ts +3 -0
- package/dist/shared/receipt/templateVisibility.js +6 -2
- package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
- package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
- package/dist/solution/BaseSales/index.d.ts +22 -6
- package/dist/solution/BaseSales/index.js +1881 -1347
- package/dist/solution/BaseSales/pickupTiming.d.ts +4 -0
- package/dist/solution/BaseSales/pickupTiming.js +35 -8
- package/dist/solution/BaseSales/types.d.ts +4 -0
- package/dist/solution/BaseSales/types.js +1 -0
- package/dist/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
- package/dist/solution/BaseSales/utils/posDurationPricing.js +174 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -8
- package/dist/solution/BookingByStep/index.d.ts +19 -3
- package/dist/solution/BookingByStep/index.js +681 -361
- package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/dist/solution/BookingByStep/utils/resources.js +117 -76
- package/dist/solution/BookingTicket/index.d.ts +6 -0
- package/dist/solution/BookingTicket/index.js +666 -593
- package/dist/solution/BookingTicket/types.d.ts +1 -1
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
- package/dist/solution/BookingTicket/utils/addProductDecision.js +35 -8
- package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +7 -7
- package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
- package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +58 -94
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +33 -62
- package/dist/solution/OrderInvoicePreview/index.js +4 -3
- package/dist/solution/Sales/index.js +1 -1
- package/dist/solution/ScanOrder/index.d.ts +2 -0
- package/dist/solution/ScanOrder/index.js +230 -97
- package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
- package/dist/solution/ScanOrder/menuAvailability.js +363 -0
- package/dist/solution/ScanOrder/types.d.ts +3 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +42 -10
- package/dist/solution/UnifiedBookingSales/index.js +2493 -1496
- package/dist/solution/UnifiedBookingSales/salesSettings.js +1 -1
- package/dist/solution/UnifiedBookingSales/types.d.ts +20 -5
- package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
- package/dist/utils/pos-receipt-auto-print.js +14 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
- package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
- package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
- package/lib/model/strategy/adapter/itemRule/type.js +10 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
- package/lib/model/strategy/adapter/promotion/evaluator.js +22 -21
- package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
- package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
- package/lib/modules/BookingContext/utils/index.d.ts +1 -0
- package/lib/modules/BookingContext/utils/index.js +11 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +21 -0
- package/lib/modules/BookingContext/utils/productExtend.js +104 -5
- package/lib/modules/BookingContext/utils/resources.js +1 -1
- package/lib/modules/Cart/index.js +4 -2
- package/lib/modules/Cart/types.d.ts +2 -0
- package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
- package/lib/modules/Cart/utils/cartProduct.js +39 -20
- package/lib/modules/Date/index.d.ts +1 -1
- package/lib/modules/Date/index.js +28 -5
- package/lib/modules/Date/types.d.ts +5 -0
- package/lib/modules/OpenData/salesSettings.js +1 -1
- package/lib/modules/OpenData/types.d.ts +9 -0
- package/lib/modules/OpenData/utils.d.ts +1 -1
- package/lib/modules/OpenData/utils.js +3 -2
- package/lib/modules/Order/index.d.ts +22 -7
- package/lib/modules/Order/index.js +457 -174
- package/lib/modules/Order/localEftposState.d.ts +13 -0
- package/lib/modules/Order/localEftposState.js +44 -0
- package/lib/modules/Order/types.d.ts +33 -11
- package/lib/modules/Order/types.js +2 -2
- package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
- package/lib/modules/Order/unpaidAmountGap.js +60 -0
- package/lib/modules/Order/utils.d.ts +4 -1
- package/lib/modules/Order/utils.js +51 -3
- package/lib/modules/Payment/walletpass.js +23 -1
- package/lib/modules/Product/types.d.ts +16 -0
- package/lib/modules/ProductList/index.js +1 -1
- package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
- package/lib/modules/ResourcePlanner/planner.js +299 -9
- package/lib/modules/ResourcePlanner/types.d.ts +42 -0
- package/lib/modules/Rules/index.js +32 -3
- package/lib/modules/Schedule/index.d.ts +7 -1
- package/lib/modules/Schedule/index.js +68 -4
- package/lib/modules/Schedule/types.d.ts +2 -0
- package/lib/modules/bookingReadValidation.d.ts +6 -0
- package/lib/modules/bookingReadValidation.js +56 -0
- package/lib/plugins/request.d.ts +2 -0
- package/lib/server/index.d.ts +9 -0
- package/lib/server/index.js +279 -30
- package/lib/server/modules/form/index.d.ts +19 -0
- package/lib/server/modules/form/index.js +73 -0
- package/lib/server/modules/form/types.d.ts +13 -0
- package/lib/server/modules/form/types.js +9 -0
- package/lib/server/modules/index.d.ts +3 -0
- package/lib/server/modules/index.js +15 -1
- package/lib/server/modules/order/index.d.ts +21 -0
- package/lib/server/modules/order/index.js +344 -35
- package/lib/server/modules/order/types.d.ts +3 -0
- package/lib/server/modules/order/utils/filterOrders.js +18 -0
- package/lib/server/modules/products/index.d.ts +28 -7
- package/lib/server/modules/products/index.js +224 -62
- package/lib/server/modules/products/replication.d.ts +8 -0
- package/lib/server/modules/products/replication.js +30 -0
- package/lib/server/modules/products/types.d.ts +12 -1
- package/lib/server/modules/products/types.js +3 -0
- package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
- package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
- package/lib/shared/receipt/small-ticket.d.ts +1 -0
- package/lib/shared/receipt/small-ticket.js +53 -25
- package/lib/shared/receipt/templateVisibility.d.ts +3 -0
- package/lib/shared/receipt/templateVisibility.js +6 -2
- package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
- package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
- package/lib/solution/BaseSales/index.d.ts +22 -6
- package/lib/solution/BaseSales/index.js +347 -59
- package/lib/solution/BaseSales/pickupTiming.d.ts +4 -0
- package/lib/solution/BaseSales/pickupTiming.js +24 -3
- package/lib/solution/BaseSales/types.d.ts +4 -0
- package/lib/solution/BaseSales/types.js +1 -0
- package/lib/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
- package/lib/solution/BaseSales/utils/posDurationPricing.js +133 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
- package/lib/solution/BookingByStep/index.d.ts +19 -3
- package/lib/solution/BookingByStep/index.js +229 -17
- package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/lib/solution/BookingByStep/utils/resources.js +25 -15
- package/lib/solution/BookingTicket/index.d.ts +6 -0
- package/lib/solution/BookingTicket/index.js +40 -5
- package/lib/solution/BookingTicket/types.d.ts +1 -1
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
- package/lib/solution/BookingTicket/utils/addProductDecision.js +34 -4
- package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +7 -7
- package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
- package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -14
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +17 -34
- package/lib/solution/OrderInvoicePreview/index.js +1 -0
- package/lib/solution/Sales/index.js +1 -1
- package/lib/solution/ScanOrder/index.d.ts +2 -0
- package/lib/solution/ScanOrder/index.js +131 -22
- package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
- package/lib/solution/ScanOrder/menuAvailability.js +203 -0
- package/lib/solution/ScanOrder/types.d.ts +3 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +42 -10
- package/lib/solution/UnifiedBookingSales/index.js +717 -144
- package/lib/solution/UnifiedBookingSales/salesSettings.js +1 -1
- package/lib/solution/UnifiedBookingSales/types.d.ts +20 -5
- package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
- package/lib/utils/pos-receipt-auto-print.js +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calendarBookingEntryKey = calendarBookingEntryKey;
|
|
7
|
+
exports.calendarBookingNeedsInput = calendarBookingNeedsInput;
|
|
8
|
+
exports.calendarBookingPreparationKey = calendarBookingPreparationKey;
|
|
9
|
+
exports.getCalendarBookingRange = getCalendarBookingRange;
|
|
10
|
+
exports.isManualBookingProduct = isManualBookingProduct;
|
|
11
|
+
exports.prepareCalendarBookingCacheItem = prepareCalendarBookingCacheItem;
|
|
12
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
13
|
+
var _localClock = require("../../ResourcePlanner/localClock");
|
|
14
|
+
var _serviceTimes = require("./serviceTimes");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function isManualBookingProduct(product) {
|
|
17
|
+
return !(0, _serviceTimes.isBookingProduct)(product) && Boolean(product?.extension_type === 'product_appointment' || product?.product_resource?.resources?.some(group => Number(group.status) === 1) || ['custom', 'package'].includes(product?.capacity?.type));
|
|
18
|
+
}
|
|
19
|
+
function getCalendarBookingRange(product, ctx) {
|
|
20
|
+
const range = ctx?.bookingTimeRangeFromCalendar;
|
|
21
|
+
if (!range || ctx?.platform !== 'pos' || (0, _serviceTimes.isMultiDayProduct)(product) || product?.duration_type === 'days' || product?.flexible?.duration?.type === 'days' || product?._extend?.sub_type === 'days' || !(0, _serviceTimes.isBookingProduct)(product) && !isManualBookingProduct(product)) return undefined;
|
|
22
|
+
try {
|
|
23
|
+
const offset = (0, _localClock.captureRuntimeOffsetMinutes)();
|
|
24
|
+
const normalize = text => {
|
|
25
|
+
const scalar = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(text));
|
|
26
|
+
const inputOffset = (0, _localClock.extractFixedOffsetMinutes)(text) ?? offset;
|
|
27
|
+
return (0, _localClock.formatLocalDateTime)(scalar + (offset - inputOffset) * 60000, offset);
|
|
28
|
+
};
|
|
29
|
+
const startAt = normalize(range.startAt);
|
|
30
|
+
const endAt = normalize(range.endAt);
|
|
31
|
+
const start = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(startAt));
|
|
32
|
+
const end = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(endAt));
|
|
33
|
+
const duration = (end - start) / 60000;
|
|
34
|
+
if (!Number.isInteger(duration) || duration <= 0 || start % 60000 || end % 60000) throw new Error();
|
|
35
|
+
return {
|
|
36
|
+
startAt,
|
|
37
|
+
endAt,
|
|
38
|
+
duration,
|
|
39
|
+
startDate: (0, _dayjs.default)(startAt.slice(0, 19)),
|
|
40
|
+
endDate: (0, _dayjs.default)(endAt.slice(0, 19))
|
|
41
|
+
};
|
|
42
|
+
} catch {
|
|
43
|
+
throw Object.assign(new Error('Calendar booking requires valid complete start/end times.'), {
|
|
44
|
+
code: 'INVALID_TARGET_FILTER'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A prepared calendar cache is reused after SKU input; no availability-driven replacement is allowed. */
|
|
50
|
+
function prepareCalendarBookingCacheItem(cacheItem, ctx) {
|
|
51
|
+
let range = getCalendarBookingRange(cacheItem, ctx);
|
|
52
|
+
if (!range) return cacheItem;
|
|
53
|
+
const resource = {};
|
|
54
|
+
const forms = (cacheItem.product_resource?.resources || []).filter(group => Number(group.status) === 1);
|
|
55
|
+
const entry = Number(ctx.resourceIdFromCalendar);
|
|
56
|
+
const preserveInput = cacheItem._data?.calendarBookingEntryKey === calendarBookingEntryKey(ctx);
|
|
57
|
+
let inputInvalid = false;
|
|
58
|
+
if (preserveInput) {
|
|
59
|
+
const ext = cacheItem._extend || {};
|
|
60
|
+
try {
|
|
61
|
+
if (!(ext.start_date ?? ext.startDate) || !(ext.end_date ?? ext.endDate) || !ext.start_time || !ext.end_time) throw new Error('Incomplete calendar input.');
|
|
62
|
+
range = getCalendarBookingRange(cacheItem, {
|
|
63
|
+
...ctx,
|
|
64
|
+
bookingTimeRangeFromCalendar: {
|
|
65
|
+
startAt: `${(0, _dayjs.default)(ext.start_date ?? ext.startDate).format('YYYY-MM-DD')}T${ext.start_time}:00`,
|
|
66
|
+
endAt: `${(0, _dayjs.default)(ext.end_date ?? ext.endDate).format('YYYY-MM-DD')}T${ext.end_time}:00`
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
} catch {
|
|
70
|
+
range = undefined;
|
|
71
|
+
inputInvalid = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const form of forms) {
|
|
75
|
+
const ids = [...(form.optional_resource || []), ...(form.default_resource || [])];
|
|
76
|
+
const linked = ids.some(id => String(id) === String(entry));
|
|
77
|
+
const origin = ctx.resourcesOriginMap?.[entry];
|
|
78
|
+
const chosen = cacheItem._extend?.resource?.[String(form.id)];
|
|
79
|
+
const hasChosen = preserveInput && chosen !== undefined;
|
|
80
|
+
const validChosen = hasChosen && Array.isArray(chosen) && new Set(chosen.map(row => String(row.relation_id))).size === chosen.length && chosen.every(row => (row.form_id == null || String(row.form_id) === String(form.id)) && (Number(row.relation_id) === 0 || ids.some(id => String(id) === String(row.relation_id)) && ctx.resourcesOriginMap?.[row.relation_id] && (ctx.resourcesOriginMap[row.relation_id].form_id == null || String(ctx.resourcesOriginMap[row.relation_id].form_id) === String(form.id))));
|
|
81
|
+
if (hasChosen && !validChosen) inputInvalid = true;
|
|
82
|
+
if (hasChosen) {
|
|
83
|
+
resource[String(form.id)] = validChosen ? chosen : [];
|
|
84
|
+
} else if (linked && origin && (origin.form_id == null || String(origin.form_id) === String(form.id))) {
|
|
85
|
+
resource[String(form.id)] = [{
|
|
86
|
+
relation_type: origin.relation_type || 'form',
|
|
87
|
+
form_id: form.id,
|
|
88
|
+
relation_id: entry,
|
|
89
|
+
like_status: 'common',
|
|
90
|
+
metadata: {
|
|
91
|
+
form_name: form.title,
|
|
92
|
+
resource_name: origin.main_field
|
|
93
|
+
}
|
|
94
|
+
}];
|
|
95
|
+
} else {
|
|
96
|
+
resource[String(form.id)] = [];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
...cacheItem,
|
|
101
|
+
...(isManualBookingProduct(cacheItem) && range ? {
|
|
102
|
+
duration: {
|
|
103
|
+
type: 'minutes',
|
|
104
|
+
value: range.duration
|
|
105
|
+
}
|
|
106
|
+
} : {}),
|
|
107
|
+
_data: {
|
|
108
|
+
...cacheItem._data,
|
|
109
|
+
calendarBookingInputInvalid: inputInvalid
|
|
110
|
+
},
|
|
111
|
+
_extend: {
|
|
112
|
+
...cacheItem._extend,
|
|
113
|
+
...(range ? {
|
|
114
|
+
startDate: range.startDate,
|
|
115
|
+
start_date: range.startDate,
|
|
116
|
+
start_time: range.startAt.slice(11, 16),
|
|
117
|
+
endDate: range.endDate,
|
|
118
|
+
end_date: range.endDate,
|
|
119
|
+
end_time: range.endAt.slice(11, 16),
|
|
120
|
+
duration: range.duration
|
|
121
|
+
} : {}),
|
|
122
|
+
resource
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function calendarBookingEntryKey(ctx) {
|
|
127
|
+
return JSON.stringify([ctx.bookingTimeRangeFromCalendar, ctx.resourceIdFromCalendar]);
|
|
128
|
+
}
|
|
129
|
+
function calendarBookingNeedsInput(cacheItem) {
|
|
130
|
+
if (cacheItem._data?.calendarBookingInputInvalid) return true;
|
|
131
|
+
const capacity = cacheItem.capacity;
|
|
132
|
+
if (capacity?.type === 'custom' && (!Array.isArray(capacity.custom) || !capacity.custom.length || capacity.custom.some(item => !Number.isFinite(Number(item.min)) || item.max == null || Number(item.min) !== Number(item.max)))) return true;
|
|
133
|
+
const groups = cacheItem.product_resource?.resources;
|
|
134
|
+
if (groups != null && !Array.isArray(groups)) return true;
|
|
135
|
+
const seen = new Set();
|
|
136
|
+
return (groups || []).some(group => {
|
|
137
|
+
if (Number(group.status) === 0) return false;
|
|
138
|
+
if (group.id == null || seen.has(String(group.id))) return true;
|
|
139
|
+
seen.add(String(group.id));
|
|
140
|
+
const rule = group.select_type;
|
|
141
|
+
if (Number(group.status) !== 1 || !rule || !['single', 'multiple'].includes(rule.type)) return true;
|
|
142
|
+
const min = Number(rule.min ?? (rule.type === 'single' ? 1 : NaN));
|
|
143
|
+
const max = Number(rule.max ?? (rule.type === 'single' ? 1 : NaN));
|
|
144
|
+
const rows = cacheItem._extend?.resource?.[String(group.id)];
|
|
145
|
+
const required = group.required ?? true;
|
|
146
|
+
const minimum = Math.max(required ? 1 : 0, min);
|
|
147
|
+
return !Number.isInteger(min) || !Number.isInteger(max) || min < 0 || max < minimum || !Array.isArray(rows) || rows.length < minimum || rows.length > max;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function calendarBookingPreparationKey(cacheItem, ctx) {
|
|
151
|
+
const identities = rows => (rows || []).map(row => [row.group_id ?? row.option_group_id ?? row.bundle_group_id, row.product_option_item_id ?? row.option_group_item_id ?? row.id, row._bundle_product_id ?? row.bundle_product_id, row.product_variant_id ?? row.bundle_variant_id, row.quantity ?? row.num ?? 1, identities(row.option)]).sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
|
|
152
|
+
const sku = cacheItem._extend?.other || {};
|
|
153
|
+
const ext = cacheItem._extend || {};
|
|
154
|
+
const dateKey = value => value == null || value === '' ? null : (0, _dayjs.default)(value).format('YYYY-MM-DD');
|
|
155
|
+
return JSON.stringify([ctx.bookingTimeRangeFromCalendar, ctx.resourceIdFromCalendar, cacheItem.capacity, cacheItem.product_resource, sku.product_variant_id ?? sku.variant_id, identities(sku.option), identities(sku.bundle), dateKey(ext.start_date ?? ext.startDate), ext.start_time, dateKey(ext.end_date ?? ext.endDate), ext.end_time, Object.entries(ext.resource || {}).map(([formId, rows]) => [formId, Array.isArray(rows) ? rows.map(row => [row.form_id, row.relation_id]) : null])]);
|
|
156
|
+
}
|
|
@@ -6,6 +6,7 @@ export * from './resources';
|
|
|
6
6
|
export * from './resourceSelection';
|
|
7
7
|
export * from './resourceErrors';
|
|
8
8
|
export * from './productExtend';
|
|
9
|
+
export * from './calendarBooking';
|
|
9
10
|
export * from './cacheItemToBookingInput';
|
|
10
11
|
export * from './buildCacheItemFromOrderLine';
|
|
11
12
|
export * from './buildNormalProductCacheItemFromOrderLine';
|
|
@@ -91,6 +91,17 @@ Object.keys(_productExtend).forEach(function (key) {
|
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
|
+
var _calendarBooking = require("./calendarBooking");
|
|
95
|
+
Object.keys(_calendarBooking).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _calendarBooking[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return _calendarBooking[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
94
105
|
var _cacheItemToBookingInput = require("./cacheItemToBookingInput");
|
|
95
106
|
Object.keys(_cacheItemToBookingInput).forEach(function (key) {
|
|
96
107
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -7,6 +7,27 @@ import { TimeSlicesResult, TimeSlice, DurationSlice } from './timeSlices';
|
|
|
7
7
|
* 让 OS 这层完全可在 Node 单测下运行(dayjs 在 Node 也是纯函数)。
|
|
8
8
|
*/
|
|
9
9
|
export interface BookingCalcContext {
|
|
10
|
+
/** Real runtime platform, injected by BookingTicket rather than inferred from sales channel. */
|
|
11
|
+
platform?: string;
|
|
12
|
+
bookingTimeRangeFromCalendar?: {
|
|
13
|
+
startAt: string;
|
|
14
|
+
endAt: string;
|
|
15
|
+
};
|
|
16
|
+
/** Sales channel; remembered duration starts are accepted only by POS. */
|
|
17
|
+
channel?: string;
|
|
18
|
+
/** Current in-memory order session, supplied by the owning Order module. */
|
|
19
|
+
orderSessionId?: string;
|
|
20
|
+
/** Rejects a session while an order replacement or hydration is pending. */
|
|
21
|
+
isOrderSessionCurrent?: (sessionId: string) => boolean;
|
|
22
|
+
/** Legacy start-only preference, or an exact interval owned by the current order session. */
|
|
23
|
+
rememberedTime?: {
|
|
24
|
+
businessDate: string;
|
|
25
|
+
startAt: string;
|
|
26
|
+
endAt?: string;
|
|
27
|
+
orderSessionId?: string;
|
|
28
|
+
};
|
|
29
|
+
/** An expired memory restarts from the current entry time, without following cart bookings. */
|
|
30
|
+
useCurrentTimeAfterRememberedExpiry?: boolean;
|
|
10
31
|
/** 来自 `/core/board/management/config` 的整套配置;常用路径见 sliceTimeSlices / appointmentTimingPreference。 */
|
|
11
32
|
bookingConfig?: any;
|
|
12
33
|
/** 资源 origin map(id → resource origin)。 */
|
|
@@ -20,6 +20,7 @@ var _resourceSelection = require("./resourceSelection");
|
|
|
20
20
|
var _serviceTimes = require("./serviceTimes");
|
|
21
21
|
var _timeSlices = require("./timeSlices");
|
|
22
22
|
var _flexible = require("./flexible");
|
|
23
|
+
var _calendarBooking = require("./calendarBooking");
|
|
23
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
25
|
/**
|
|
25
26
|
* 上下文(与 info2 state.bookingConfig / state.service / state.date 一一对应)。
|
|
@@ -28,6 +29,67 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
28
29
|
* 让 OS 这层完全可在 Node 单测下运行(dayjs 在 Node 也是纯函数)。
|
|
29
30
|
*/
|
|
30
31
|
|
|
32
|
+
/** Rebuild only the derived booking fields; SKU, quantity, notes and Holder stay intact. */
|
|
33
|
+
function seedRememberedBookingStart(cacheItem, ctx) {
|
|
34
|
+
const remembered = ctx.rememberedTime;
|
|
35
|
+
const invalid = () => Object.assign(new Error('Remembered time requires a valid POS duration interval in the current order.'), {
|
|
36
|
+
code: 'INVALID_REMEMBERED_TIME'
|
|
37
|
+
});
|
|
38
|
+
const duration = cacheItem?.duration;
|
|
39
|
+
const durationType = typeof duration === 'object' && duration ? String(duration.type || '').toLowerCase() : '';
|
|
40
|
+
const durationValue = typeof duration === 'object' && duration ? duration.value : duration;
|
|
41
|
+
const isDuration = (0, _flexible.isProductFlexibleDuration)(duration) || ['', 'fixed', 'minute', 'minutes', 'hour', 'hours'].includes(durationType) && Number.isFinite(Number(durationValue)) && Number(durationValue) > 0;
|
|
42
|
+
const isCalendarDate = value => {
|
|
43
|
+
if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
|
|
44
|
+
const date = new Date(`${value}T00:00:00.000Z`);
|
|
45
|
+
return Number.isFinite(date.getTime()) && date.toISOString().slice(0, 10) === value;
|
|
46
|
+
};
|
|
47
|
+
const isDateTime = value => {
|
|
48
|
+
const parts = typeof value === 'string' ? /^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,3})?)?(?:Z|[+-](\d{2}):(\d{2}))?$/.exec(value) : null;
|
|
49
|
+
return Boolean(parts && isCalendarDate(parts[1]) && Number(parts[2]) <= 23 && Number(parts[3]) <= 59 && Number(parts[4] || 0) <= 59 && Number(parts[5] || 0) <= 23 && Number(parts[6] || 0) <= 59);
|
|
50
|
+
};
|
|
51
|
+
if (String(ctx.channel || '').trim().toLowerCase() !== 'pos' || !isDuration || (0, _serviceTimes.isMultiDayProduct)(cacheItem) || (0, _serviceTimes.isSessionProduct)(cacheItem) || cacheItem?.cartDetailValue?.session || cacheItem?._extend?.other?.session || !isCalendarDate(remembered?.businessDate) || !isDateTime(remembered?.startAt)) throw invalid();
|
|
52
|
+
// Parse the actual instant with the same runtime clock used by the legacy booking helpers.
|
|
53
|
+
// The business-day label must not replace the calendar date of an overnight start.
|
|
54
|
+
const start = (0, _dayjs.default)(remembered.startAt);
|
|
55
|
+
if (!start.isValid()) throw invalid();
|
|
56
|
+
const hasRememberedInterval = remembered.endAt !== undefined || remembered.orderSessionId !== undefined;
|
|
57
|
+
let end;
|
|
58
|
+
let rememberedDuration;
|
|
59
|
+
if (hasRememberedInterval) {
|
|
60
|
+
if (!isDateTime(remembered.endAt) || typeof remembered.orderSessionId !== 'string' || !remembered.orderSessionId.trim() || remembered.orderSessionId !== ctx.orderSessionId || ctx.isOrderSessionCurrent && !ctx.isOrderSessionCurrent(remembered.orderSessionId)) throw invalid();
|
|
61
|
+
end = (0, _dayjs.default)(remembered.endAt);
|
|
62
|
+
const durationMinutes = (end.valueOf() - start.valueOf()) / 60000;
|
|
63
|
+
if (!end.isValid() || !Number.isFinite(durationMinutes) || durationMinutes <= 0) throw invalid();
|
|
64
|
+
const flexible = (0, _flexible.isProductFlexibleDuration)(duration);
|
|
65
|
+
const configuredDurationMinutes = Number(durationValue) * (['hour', 'hours'].includes(durationType) ? 60 : 1);
|
|
66
|
+
if (!flexible && durationMinutes !== configuredDurationMinutes) throw invalid();
|
|
67
|
+
rememberedDuration = flexible ? _flexible.flexibleObj.create(durationMinutes) : durationMinutes;
|
|
68
|
+
}
|
|
69
|
+
const clockFormat = value => value.format(value.millisecond() ? 'HH:mm:ss.SSS' : value.second() ? 'HH:mm:ss' : 'HH:mm');
|
|
70
|
+
const extend = {
|
|
71
|
+
...(cacheItem?._extend || {})
|
|
72
|
+
};
|
|
73
|
+
for (const key of ['start_date', 'startDate', 'start_time', 'end_date', 'endDate', 'end_time', 'duration', 'resource', 'resources', 'capacity', 'booking', 'availabilitySelection']) delete extend[key];
|
|
74
|
+
return {
|
|
75
|
+
...cacheItem,
|
|
76
|
+
new: 1,
|
|
77
|
+
autoClose: false,
|
|
78
|
+
_data: {},
|
|
79
|
+
_extend: {
|
|
80
|
+
...extend,
|
|
81
|
+
start_date: start.format('YYYY-MM-DD'),
|
|
82
|
+
start_time: clockFormat(start),
|
|
83
|
+
...(end ? {
|
|
84
|
+
end_date: end.format('YYYY-MM-DD'),
|
|
85
|
+
end_time: clockFormat(end),
|
|
86
|
+
endDate: end,
|
|
87
|
+
duration: rememberedDuration
|
|
88
|
+
} : {})
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
31
93
|
/** 从 BookingContext.date 提取 HH:mm(仅当日期带有效时分时)。 */
|
|
32
94
|
function derivePresetStartTimeFromDate(date) {
|
|
33
95
|
if (date == null) return undefined;
|
|
@@ -56,6 +118,15 @@ function getFlexibleOption(params) {
|
|
|
56
118
|
const duration = (0, _flexible.getDurationValue)(cacheItem?.duration);
|
|
57
119
|
if (duration !== 'flexible') return null;
|
|
58
120
|
const startDate = (0, _dayjs.default)(`${(0, _dayjs.default)(cacheItem?._extend?.start_date).format('YYYY-MM-DD')} ${useStartTime || cacheItem?._extend?.start_time || '00:00'}`);
|
|
121
|
+
// The current-order interval was validated before rebuilding the cache item.
|
|
122
|
+
// Resource defaults may change, but must never extend its saved end.
|
|
123
|
+
if (params.ctx.rememberedTime?.endAt !== undefined) {
|
|
124
|
+
const timeValue = ((0, _dayjs.default)(params.ctx.rememberedTime.endAt).valueOf() - startDate.valueOf()) / 60000;
|
|
125
|
+
return {
|
|
126
|
+
label: String(timeValue),
|
|
127
|
+
value: _flexible.flexibleObj.create(timeValue)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
59
130
|
const usable = (0, _resources.getUsableTime)(cacheItem);
|
|
60
131
|
const usableEndAt = usable?._extend?.usableTime?.end_at ? (0, _dayjs.default)(usable._extend.usableTime.end_at) : null;
|
|
61
132
|
const endDate = (0, _timeSlices.getEndDate)(startDate, 'flexible', usableEndAt, params.ctx?.shopOpeningHours);
|
|
@@ -101,6 +172,7 @@ function getTimeObj(params) {
|
|
|
101
172
|
};
|
|
102
173
|
}
|
|
103
174
|
function getDefaultBookingStartFallback(cacheItem, ctx) {
|
|
175
|
+
if (ctx.useCurrentTimeAfterRememberedExpiry) return (0, _dayjs.default)(ctx.date ?? (0, _dayjs.default)()).format('YYYY-MM-DDTHH:mm');
|
|
104
176
|
const date = (0, _dayjs.default)(cacheItem?._extend?.start_date ?? ctx.date ?? (0, _dayjs.default)()).format('YYYY-MM-DD');
|
|
105
177
|
const time = ctx.presetStartTime || cacheItem.currentDefaultTime || (0, _dayjs.default)().format('HH:mm');
|
|
106
178
|
return `${date}T${time}`;
|
|
@@ -133,7 +205,7 @@ function getServiceStartTimeAndEndTime(params) {
|
|
|
133
205
|
let _extend = {
|
|
134
206
|
duration: resolveDuration()
|
|
135
207
|
};
|
|
136
|
-
if (ctx.resolveDefaultBookingStart && !cacheItem._extend?.start_time && !(0, _serviceTimes.isSessionProduct)(cacheItem)) {
|
|
208
|
+
if (ctx.resolveDefaultBookingStart && !ctx.rememberedTime && !cacheItem._extend?.start_time && !(0, _serviceTimes.isSessionProduct)(cacheItem)) {
|
|
137
209
|
const fallback = params.defaultBookingStartFallback ?? getDefaultBookingStartFallback(cacheItem, ctx);
|
|
138
210
|
const start = ctx.resolveDefaultBookingStart(cacheItem, fallback);
|
|
139
211
|
if (start) {
|
|
@@ -218,10 +290,37 @@ function getServiceStartTimeAndEndTime(params) {
|
|
|
218
290
|
*/
|
|
219
291
|
function getProductExtend(params) {
|
|
220
292
|
const {
|
|
221
|
-
cacheItem,
|
|
222
|
-
ctx,
|
|
223
293
|
isDisabledTime
|
|
224
294
|
} = params;
|
|
295
|
+
if ((0, _calendarBooking.getCalendarBookingRange)(params.cacheItem, params.ctx)) {
|
|
296
|
+
const prepared = (0, _calendarBooking.prepareCalendarBookingCacheItem)(params.cacheItem, params.ctx);
|
|
297
|
+
const capacity = (0, _resources.setDefaultCapacitys)({
|
|
298
|
+
capacitys: prepared.capacity,
|
|
299
|
+
cacheItem: prepared
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
...prepared,
|
|
303
|
+
_extend: {
|
|
304
|
+
...prepared._extend,
|
|
305
|
+
capacity
|
|
306
|
+
},
|
|
307
|
+
_data: {
|
|
308
|
+
...prepared._data,
|
|
309
|
+
capacitys: prepared.capacity,
|
|
310
|
+
calendarManualBooking: params.cacheItem._data?.calendarManualBooking === true || (0, _calendarBooking.isManualBookingProduct)(params.cacheItem),
|
|
311
|
+
calendarBookingEntryKey: (0, _calendarBooking.calendarBookingEntryKey)(params.ctx),
|
|
312
|
+
calendarBookingPreparationKey: (0, _calendarBooking.calendarBookingPreparationKey)(prepared, params.ctx)
|
|
313
|
+
},
|
|
314
|
+
autoClose: !(0, _calendarBooking.calendarBookingNeedsInput)(prepared)
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
const hasRememberedTime = params.ctx.rememberedTime !== undefined;
|
|
318
|
+
const cacheItem = hasRememberedTime ? seedRememberedBookingStart(params.cacheItem, params.ctx) : params.cacheItem;
|
|
319
|
+
const ctx = hasRememberedTime ? {
|
|
320
|
+
...params.ctx,
|
|
321
|
+
previousService: undefined,
|
|
322
|
+
presetStartTime: undefined
|
|
323
|
+
} : params.ctx;
|
|
225
324
|
const isNew = cacheItem.new || !cacheItem._extend?.endDate;
|
|
226
325
|
const _cacheItem = {
|
|
227
326
|
...cacheItem
|
|
@@ -238,14 +337,14 @@ function getProductExtend(params) {
|
|
|
238
337
|
cacheItem,
|
|
239
338
|
ctx
|
|
240
339
|
});
|
|
241
|
-
const defaultBookingStartFallback = cacheItem._data?.salesDefaultBookingFallback ?? getDefaultBookingStartFallback(cacheItem, ctx);
|
|
340
|
+
const defaultBookingStartFallback = (!ctx.useCurrentTimeAfterRememberedExpiry ? cacheItem._data?.salesDefaultBookingFallback : undefined) ?? getDefaultBookingStartFallback(cacheItem, ctx);
|
|
242
341
|
_cacheItem._extend = getServiceStartTimeAndEndTime({
|
|
243
342
|
cacheItem,
|
|
244
343
|
timeObj: _cacheItem._data.timeObj,
|
|
245
344
|
ctx,
|
|
246
345
|
defaultBookingStartFallback
|
|
247
346
|
});
|
|
248
|
-
if (ctx.resolveDefaultBookingStart && !(0, _serviceTimes.isSessionProduct)(cacheItem)) {
|
|
347
|
+
if (ctx.resolveDefaultBookingStart && !hasRememberedTime && !(0, _serviceTimes.isSessionProduct)(cacheItem)) {
|
|
249
348
|
const start = `${(0, _dayjs.default)(_cacheItem._extend.start_date).format('YYYY-MM-DD')}T${_cacheItem._extend.start_time}`;
|
|
250
349
|
const previousDefault = cacheItem._data?.salesDefaultBookingStart;
|
|
251
350
|
if (!cacheItem._extend?.start_time || previousDefault && (0, _dayjs.default)(start).valueOf() === (0, _dayjs.default)(previousDefault).valueOf()) {
|
|
@@ -241,7 +241,7 @@ function getResourceMaxFreeTime(resource, isAutoAllocationOn) {
|
|
|
241
241
|
if (!isAutoAllocationOn(form_id)) return [];
|
|
242
242
|
const usableList = (renderList || []).filter(d => d.usable && d.id !== 0);
|
|
243
243
|
let defaultResource = [];
|
|
244
|
-
let maxFreeTime =
|
|
244
|
+
let maxFreeTime = -1;
|
|
245
245
|
usableList.forEach(d => {
|
|
246
246
|
const {
|
|
247
247
|
times = []
|
|
@@ -89,7 +89,8 @@ class CartModule extends _BaseModule.BaseModule {
|
|
|
89
89
|
bundle,
|
|
90
90
|
options,
|
|
91
91
|
date,
|
|
92
|
-
quantity = 1
|
|
92
|
+
quantity = 1,
|
|
93
|
+
isLegacyOrder
|
|
93
94
|
} = params;
|
|
94
95
|
// 生成一个唯一的 ID
|
|
95
96
|
let cartItem = {
|
|
@@ -108,7 +109,8 @@ class CartModule extends _BaseModule.BaseModule {
|
|
|
108
109
|
bundle,
|
|
109
110
|
options,
|
|
110
111
|
product_variant_id: newProduct.product_variant_id,
|
|
111
|
-
quantity
|
|
112
|
+
quantity,
|
|
113
|
+
isLegacyOrder
|
|
112
114
|
});
|
|
113
115
|
}
|
|
114
116
|
if (account) {
|
|
@@ -21,6 +21,7 @@ export declare const formatProductToCartItem: (params: {
|
|
|
21
21
|
product_variant_id?: number;
|
|
22
22
|
quantity?: number;
|
|
23
23
|
discounts?: any[];
|
|
24
|
+
isLegacyOrder?: boolean;
|
|
24
25
|
}) => CartItem;
|
|
25
26
|
export declare const formatProductToCartItemOrigin: (params: {
|
|
26
27
|
cartItem: CartItem;
|
|
@@ -29,6 +30,7 @@ export declare const formatProductToCartItemOrigin: (params: {
|
|
|
29
30
|
options?: any;
|
|
30
31
|
product_variant_id?: number;
|
|
31
32
|
quantity?: number;
|
|
33
|
+
isLegacyOrder?: boolean;
|
|
32
34
|
}) => any;
|
|
33
35
|
/**
|
|
34
36
|
* 获取商品总价
|
|
@@ -61,7 +63,7 @@ export declare const getProductOriginTotalPrice: (params: {
|
|
|
61
63
|
* @param options 套餐规格信息
|
|
62
64
|
* @returns 格式化后的套餐规格信息
|
|
63
65
|
*/
|
|
64
|
-
export declare const formatOptions: (options: any) => any;
|
|
66
|
+
export declare const formatOptions: (options: any, product?: ProductData) => any;
|
|
65
67
|
export declare const formatOptionsToOrigin: (options: any) => any;
|
|
66
68
|
/**
|
|
67
69
|
* 格式化商品套餐信息
|
|
@@ -106,7 +106,7 @@ const formatProductToCartItem = params => {
|
|
|
106
106
|
cartItem.bundle = formatBundle(bundle);
|
|
107
107
|
}
|
|
108
108
|
if (options?.length) {
|
|
109
|
-
cartItem.options = formatOptions(options);
|
|
109
|
+
cartItem.options = formatOptions(options, product);
|
|
110
110
|
}
|
|
111
111
|
// 拼装出 product_option_string
|
|
112
112
|
if (product_variant_id) {
|
|
@@ -148,22 +148,32 @@ const formatProductToCartItemOrigin = params => {
|
|
|
148
148
|
bundle,
|
|
149
149
|
options,
|
|
150
150
|
product_variant_id,
|
|
151
|
-
quantity = 1
|
|
151
|
+
quantity = 1,
|
|
152
|
+
isLegacyOrder = false
|
|
152
153
|
} = params;
|
|
153
154
|
let origin = cartItem._origin;
|
|
154
155
|
const product_discount_difference = (origin.product?.discount_list || []).filter(item => !item?.metadata?.custom_product_bundle_map_id).reduce((pre, cur) => {
|
|
155
156
|
return pre + (cur?.metadata?.product_discount_difference || 0);
|
|
156
157
|
}, 0);
|
|
157
158
|
if (product) {
|
|
159
|
+
const {
|
|
160
|
+
option: _option,
|
|
161
|
+
...legacyProductSku
|
|
162
|
+
} = origin.product?.product_sku || {};
|
|
158
163
|
origin.product = {
|
|
159
164
|
...(origin.product || {}),
|
|
160
165
|
num: quantity,
|
|
161
166
|
product_id: product.id,
|
|
162
167
|
product_variant_id: product_variant_id || 0,
|
|
163
168
|
product_bundle: origin.product?.product_bundle || [],
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
...(isLegacyOrder ? {
|
|
170
|
+
product_sku: legacyProductSku,
|
|
171
|
+
product_option_item: origin.product?.product_option_item || []
|
|
172
|
+
} : {
|
|
173
|
+
product_sku: origin.product?.product_sku || {
|
|
174
|
+
option: []
|
|
175
|
+
}
|
|
176
|
+
}),
|
|
167
177
|
metadata: {
|
|
168
178
|
product_discount_difference
|
|
169
179
|
}
|
|
@@ -176,17 +186,22 @@ const formatProductToCartItemOrigin = params => {
|
|
|
176
186
|
origin.product.product_bundle = formatBundleToOrigin(bundle);
|
|
177
187
|
}
|
|
178
188
|
if (options?.length) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
const formattedOptions = formatOptionsToOrigin(options);
|
|
190
|
+
if (isLegacyOrder) {
|
|
191
|
+
origin.product.product_option_item = formattedOptions;
|
|
192
|
+
} else {
|
|
193
|
+
origin.product.product_sku = {
|
|
194
|
+
...(origin.product.product_sku || {}),
|
|
195
|
+
option: formattedOptions.map(option => {
|
|
196
|
+
const next = {
|
|
197
|
+
...option,
|
|
198
|
+
add_price: option.add_price ?? option.price
|
|
199
|
+
};
|
|
200
|
+
delete next.price;
|
|
201
|
+
return next;
|
|
202
|
+
})
|
|
203
|
+
};
|
|
204
|
+
}
|
|
190
205
|
}
|
|
191
206
|
}
|
|
192
207
|
return origin;
|
|
@@ -299,12 +314,16 @@ const getProductOriginTotalPrice = params => {
|
|
|
299
314
|
* @returns 格式化后的套餐规格信息
|
|
300
315
|
*/
|
|
301
316
|
exports.getProductOriginTotalPrice = getProductOriginTotalPrice;
|
|
302
|
-
const formatOptions = options => {
|
|
317
|
+
const formatOptions = (options, product) => {
|
|
303
318
|
if (!options?.length) return [];
|
|
304
319
|
return options.map(item => {
|
|
320
|
+
const optionGroupId = item?.option_group_id;
|
|
321
|
+
const optionItemId = item?.id ?? item?.option_group_item_id ?? item?.product_option_item_id;
|
|
322
|
+
const optionGroup = product?.option_group?.find(group => String(group?.id) === String(optionGroupId));
|
|
323
|
+
const optionItem = optionGroup?.option_item?.find(candidate => String(candidate?.id) === String(optionItemId));
|
|
305
324
|
return {
|
|
306
|
-
id:
|
|
307
|
-
name: item?.name,
|
|
325
|
+
id: optionItemId,
|
|
326
|
+
name: item?.name ?? item?.title ?? optionItem?.name ?? optionItem?.title,
|
|
308
327
|
num: item?.num,
|
|
309
328
|
price: item?.price,
|
|
310
329
|
total: item?.price,
|
|
@@ -320,7 +339,7 @@ const formatOptionsToOrigin = options => {
|
|
|
320
339
|
return options.map(d => {
|
|
321
340
|
return {
|
|
322
341
|
num: d.num,
|
|
323
|
-
option_group_item_id: d
|
|
342
|
+
option_group_item_id: d?.option_group_item_id || d?.product_option_item_id,
|
|
324
343
|
option_group_id: d.option_group_id
|
|
325
344
|
};
|
|
326
345
|
});
|
|
@@ -15,7 +15,7 @@ export declare class DateModule extends BaseModule implements Module, DateModule
|
|
|
15
15
|
getDateRange(): ITime[];
|
|
16
16
|
getResourceDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
|
|
17
17
|
getDateList(): ITime[];
|
|
18
|
-
setDateList(dateList: ITime[]): void;
|
|
18
|
+
setDateList(dateList: ITime[], replaceDates?: boolean): void;
|
|
19
19
|
fetchResourceDates(params: IGetAvailableTimeListParams): Promise<any>;
|
|
20
20
|
/**
|
|
21
21
|
* 将时间向上取整到下一个10分钟整数
|
|
@@ -8,6 +8,7 @@ var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
|
8
8
|
var _BaseModule = require("../BaseModule");
|
|
9
9
|
var _utils = require("./utils");
|
|
10
10
|
var _cloneDeep = _interopRequireDefault(require("lodash-es/cloneDeep"));
|
|
11
|
+
var _bookingReadValidation = require("../bookingReadValidation");
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
class DateModule extends _BaseModule.BaseModule {
|
|
13
14
|
defaultName = 'date';
|
|
@@ -52,7 +53,7 @@ class DateModule extends _BaseModule.BaseModule {
|
|
|
52
53
|
return this.store.dateRange;
|
|
53
54
|
}
|
|
54
55
|
async getResourceDates(params) {
|
|
55
|
-
if (params.useCache) {
|
|
56
|
+
if (params.useCache && params.errorMode !== 'throw') {
|
|
56
57
|
// 发请求之前,做一道检测,看 dateList 里是否有对应日期,且对应日期里是否都有对应 resource_ids 的资源
|
|
57
58
|
const currentDateList = this.getDateList() || [];
|
|
58
59
|
const currentDateListMap = new Map(currentDateList.map(item => [item.date, item]));
|
|
@@ -65,14 +66,26 @@ class DateModule extends _BaseModule.BaseModule {
|
|
|
65
66
|
return currentDateList;
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
let dates;
|
|
70
|
+
try {
|
|
71
|
+
dates = await this.getResourceAvailableTimeList(params);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
params.assertCurrent?.();
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
params.assertCurrent?.();
|
|
77
|
+
this.setDateList(dates, params.errorMode === 'throw');
|
|
70
78
|
return dates;
|
|
71
79
|
}
|
|
72
80
|
getDateList() {
|
|
73
81
|
return this.store.dateList;
|
|
74
82
|
}
|
|
75
|
-
setDateList(dateList) {
|
|
83
|
+
setDateList(dateList, replaceDates = false) {
|
|
84
|
+
if (replaceDates) {
|
|
85
|
+
const incoming = new Map(dateList.map(date => [date.date, date]));
|
|
86
|
+
this.store.dateList = [...(this.store.dateList || []).filter(date => !incoming.has(date.date)), ...(0, _cloneDeep.default)(dateList)];
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
76
89
|
// this.store.dateList = dateList;
|
|
77
90
|
// 并不能直接简单的进行复制
|
|
78
91
|
// 我们需要把每一天的资源都进行一个合并
|
|
@@ -117,8 +130,16 @@ class DateModule extends _BaseModule.BaseModule {
|
|
|
117
130
|
resource_ids,
|
|
118
131
|
front_end_cache_id: useCache && this.cacheId
|
|
119
132
|
}, {
|
|
120
|
-
useCache
|
|
133
|
+
useCache,
|
|
134
|
+
...(params.bookingRead ? {
|
|
135
|
+
bookingRead: true
|
|
136
|
+
} : {})
|
|
121
137
|
});
|
|
138
|
+
if (params.errorMode === 'throw') {
|
|
139
|
+
if (!res || res.code !== undefined && Number(res.code) !== 200 || res.status === false || res.success === false || typeof res.status === 'number' && res.status >= 400 || !(0, _bookingReadValidation.isBookingResourceList)(res.data)) {
|
|
140
|
+
throw new Error(res?.message || 'Invalid booking resource response');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
122
143
|
|
|
123
144
|
// 校正资源时间段数据
|
|
124
145
|
if (res?.data && Array.isArray(res.data)) {
|
|
@@ -126,6 +147,7 @@ class DateModule extends _BaseModule.BaseModule {
|
|
|
126
147
|
}
|
|
127
148
|
return res;
|
|
128
149
|
} catch (error) {
|
|
150
|
+
if (params.errorMode === 'throw') throw error;
|
|
129
151
|
console.error(error);
|
|
130
152
|
}
|
|
131
153
|
}
|
|
@@ -244,6 +266,7 @@ class DateModule extends _BaseModule.BaseModule {
|
|
|
244
266
|
}
|
|
245
267
|
return dates;
|
|
246
268
|
} catch (error) {
|
|
269
|
+
if (params.errorMode === 'throw') throw error;
|
|
247
270
|
return (0, _utils.disableAllDates)(dates);
|
|
248
271
|
}
|
|
249
272
|
}
|
|
@@ -44,6 +44,11 @@ export interface DateModuleAPI {
|
|
|
44
44
|
getResourceDates: (params: IGetAvailableTimeListParams) => Promise<ITime[]>;
|
|
45
45
|
}
|
|
46
46
|
export interface IGetAvailableTimeListParams {
|
|
47
|
+
/** BookingByStep opts in; existing solutions retain unavailable-on-error behavior. */
|
|
48
|
+
errorMode?: 'unavailable' | 'throw';
|
|
49
|
+
bookingRead?: boolean;
|
|
50
|
+
/** Check the selection is still current before committing a response. */
|
|
51
|
+
assertCurrent?: () => void;
|
|
47
52
|
url?: string;
|
|
48
53
|
/** 是否使用缓存 */
|
|
49
54
|
useCache?: boolean;
|
|
@@ -63,7 +63,7 @@ function normalizeSalesSettings(raw, platform) {
|
|
|
63
63
|
showDontRemindAgainToday: isPos && booleanOr(raw?.['sale.show_option'], false)
|
|
64
64
|
},
|
|
65
65
|
reservation: {
|
|
66
|
-
multipleBookingScheduling: raw?.['reservation.multiple_booking_scheduling'] === '
|
|
66
|
+
multipleBookingScheduling: raw?.['reservation.multiple_booking_scheduling'] === 'one_after_another' ? 'one_after_another' : 'same_start_time',
|
|
67
67
|
resourceSettings: normalizeSalesResourceSettings(raw?.['reservation.resource_setting'])
|
|
68
68
|
}
|
|
69
69
|
};
|