@pisell/pisellos 2.1.150 → 2.1.151
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +61 -8
- package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
- package/dist/model/strategy/engine.d.ts +18 -5
- package/dist/model/strategy/engine.js +145 -45
- package/dist/model/strategy/type.d.ts +17 -0
- package/dist/model/strategy/type.js +4 -0
- package/dist/modules/Cart/types.d.ts +2 -0
- package/dist/modules/Cart/utils/cartProduct.js +56 -25
- package/dist/modules/Discount/index.d.ts +2 -6
- package/dist/modules/Discount/index.js +8 -14
- package/dist/modules/Discount/types.d.ts +19 -1
- package/dist/modules/Order/index.d.ts +1 -65
- package/dist/modules/Order/index.js +30 -901
- package/dist/modules/Order/types.d.ts +12 -174
- package/dist/modules/Order/types.js +0 -2
- package/dist/modules/Order/utils.d.ts +0 -118
- package/dist/modules/Order/utils.js +2 -586
- package/dist/modules/Payment/index.d.ts +2 -1
- package/dist/modules/Payment/index.js +10 -7
- package/dist/modules/Payment/utils.js +3 -0
- package/dist/modules/Payment/walletpass.d.ts +23 -0
- package/dist/modules/Payment/walletpass.js +191 -95
- package/dist/modules/Product/utils.js +2 -2
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +3 -4
- package/dist/modules/Rules/index.d.ts +9 -5
- package/dist/modules/Rules/index.js +677 -168
- package/dist/modules/Rules/types.d.ts +2 -0
- package/dist/modules/Schedule/getDateIsInSchedule.js +18 -11
- package/dist/modules/Schedule/utils.d.ts +1 -1
- package/dist/modules/Summary/types.d.ts +2 -0
- package/dist/modules/Summary/utils.d.ts +9 -3
- package/dist/modules/Summary/utils.js +52 -41
- package/dist/modules/index.d.ts +0 -4
- package/dist/modules/index.js +1 -5
- package/dist/plugins/window.d.ts +2 -0
- package/dist/solution/BookingByStep/index.d.ts +3 -2
- package/dist/solution/BookingByStep/index.js +43 -46
- package/dist/solution/BookingByStep/types.d.ts +1 -3
- package/dist/solution/BookingByStep/types.js +1 -5
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
- package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
- package/dist/solution/Checkout/index.js +2 -0
- package/dist/solution/ShopDiscount/index.d.ts +2 -2
- package/dist/solution/ShopDiscount/index.js +41 -37
- package/dist/solution/ShopDiscount/types.d.ts +1 -1
- package/dist/solution/ShopDiscount/types.js +2 -1
- package/dist/solution/ShopDiscount/utils.js +26 -12
- package/dist/solution/index.d.ts +0 -2
- package/dist/solution/index.js +1 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +34 -3
- package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
- package/lib/model/strategy/engine.d.ts +18 -5
- package/lib/model/strategy/engine.js +85 -21
- package/lib/model/strategy/type.d.ts +17 -0
- package/lib/modules/Cart/types.d.ts +2 -0
- package/lib/modules/Cart/utils/cartProduct.js +39 -12
- package/lib/modules/Discount/index.d.ts +2 -6
- package/lib/modules/Discount/index.js +1 -3
- package/lib/modules/Discount/types.d.ts +19 -1
- package/lib/modules/Order/index.d.ts +1 -65
- package/lib/modules/Order/index.js +1 -513
- package/lib/modules/Order/types.d.ts +12 -174
- package/lib/modules/Order/utils.d.ts +0 -118
- package/lib/modules/Order/utils.js +2 -483
- package/lib/modules/Payment/index.d.ts +2 -1
- package/lib/modules/Payment/index.js +1 -0
- package/lib/modules/Payment/utils.js +3 -0
- package/lib/modules/Payment/walletpass.d.ts +23 -0
- package/lib/modules/Payment/walletpass.js +94 -17
- package/lib/modules/Product/utils.js +2 -2
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +3 -5
- package/lib/modules/Rules/index.d.ts +9 -5
- package/lib/modules/Rules/index.js +780 -288
- package/lib/modules/Rules/types.d.ts +2 -0
- package/lib/modules/Schedule/getDateIsInSchedule.js +11 -9
- package/lib/modules/Schedule/utils.d.ts +1 -1
- package/lib/modules/Summary/types.d.ts +2 -0
- package/lib/modules/Summary/utils.d.ts +9 -3
- package/lib/modules/Summary/utils.js +31 -22
- package/lib/modules/index.d.ts +0 -4
- package/lib/modules/index.js +1 -9
- package/lib/plugins/window.d.ts +2 -0
- package/lib/solution/BookingByStep/index.d.ts +3 -2
- package/lib/solution/BookingByStep/index.js +4 -6
- package/lib/solution/BookingByStep/types.d.ts +1 -3
- package/lib/solution/BookingByStep/types.js +0 -10
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
- package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
- package/lib/solution/Checkout/index.js +2 -0
- package/lib/solution/ShopDiscount/index.d.ts +2 -2
- package/lib/solution/ShopDiscount/index.js +24 -16
- package/lib/solution/ShopDiscount/types.d.ts +1 -1
- package/lib/solution/ShopDiscount/utils.js +10 -6
- package/lib/solution/index.d.ts +0 -2
- package/lib/solution/index.js +1 -5
- package/package.json +1 -1
- package/dist/apis/picoding.d.ts +0 -0
- package/dist/apis/picoding.js +0 -1
- package/dist/modules/OpenData/index.d.ts +0 -24
- package/dist/modules/OpenData/index.js +0 -173
- package/dist/modules/OpenData/types.d.ts +0 -73
- package/dist/modules/OpenData/types.js +0 -1
- package/dist/modules/OpenData/utils.d.ts +0 -2
- package/dist/modules/OpenData/utils.js +0 -75
- package/dist/modules/Quotation/index.d.ts +0 -48
- package/dist/modules/Quotation/index.js +0 -248
- package/dist/modules/Quotation/types.d.ts +0 -42
- package/dist/modules/Quotation/types.js +0 -1
- package/dist/modules/SalesSummary/index.d.ts +0 -63
- package/dist/modules/SalesSummary/index.js +0 -174
- package/dist/modules/SalesSummary/types.d.ts +0 -60
- package/dist/modules/SalesSummary/types.js +0 -1
- package/dist/modules/SalesSummary/utils.d.ts +0 -30
- package/dist/modules/SalesSummary/utils.js +0 -480
- package/dist/modules/ScanOrderLogger/index.d.ts +0 -23
- package/dist/modules/ScanOrderLogger/index.js +0 -174
- package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
- package/dist/modules/ScanOrderLogger/providers/feishu.js +0 -221
- package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
- package/dist/modules/ScanOrderLogger/providers/grafana.js +0 -50
- package/dist/modules/ScanOrderLogger/types.d.ts +0 -53
- package/dist/modules/ScanOrderLogger/types.js +0 -1
- package/dist/solution/ScanOrder/index.d.ts +0 -152
- package/dist/solution/ScanOrder/index.js +0 -3132
- package/dist/solution/ScanOrder/types.d.ts +0 -287
- package/dist/solution/ScanOrder/types.js +0 -35
- package/dist/solution/ScanOrder/utils.d.ts +0 -167
- package/dist/solution/ScanOrder/utils.js +0 -764
- package/dist/solution/VenueBooking/index.d.ts +0 -199
- package/dist/solution/VenueBooking/index.js +0 -3459
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -343
- package/dist/solution/VenueBooking/types.d.ts +0 -154
- package/dist/solution/VenueBooking/types.js +0 -21
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
- package/dist/solution/VenueBooking/utils/dateSummary.js +0 -104
- package/dist/solution/VenueBooking/utils/resource.d.ts +0 -14
- package/dist/solution/VenueBooking/utils/resource.js +0 -131
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -38
- package/dist/solution/VenueBooking/utils/slotMerge.js +0 -239
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -32
- package/dist/solution/VenueBooking/utils/timeSlot.js +0 -453
- package/dist/solution/VenueBooking/utils.d.ts +0 -1
- package/dist/solution/VenueBooking/utils.js +0 -1
- package/lib/apis/picoding.d.ts +0 -0
- package/lib/apis/picoding.js +0 -0
- package/lib/modules/OpenData/index.d.ts +0 -24
- package/lib/modules/OpenData/index.js +0 -119
- package/lib/modules/OpenData/types.d.ts +0 -73
- package/lib/modules/OpenData/types.js +0 -17
- package/lib/modules/OpenData/utils.d.ts +0 -2
- package/lib/modules/OpenData/utils.js +0 -111
- package/lib/modules/Quotation/index.d.ts +0 -48
- package/lib/modules/Quotation/index.js +0 -152
- package/lib/modules/Quotation/types.d.ts +0 -42
- package/lib/modules/Quotation/types.js +0 -17
- package/lib/modules/SalesSummary/index.d.ts +0 -63
- package/lib/modules/SalesSummary/index.js +0 -105
- package/lib/modules/SalesSummary/types.d.ts +0 -60
- package/lib/modules/SalesSummary/types.js +0 -17
- package/lib/modules/SalesSummary/utils.d.ts +0 -30
- package/lib/modules/SalesSummary/utils.js +0 -420
- package/lib/modules/ScanOrderLogger/index.d.ts +0 -23
- package/lib/modules/ScanOrderLogger/index.js +0 -147
- package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
- package/lib/modules/ScanOrderLogger/providers/feishu.js +0 -157
- package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
- package/lib/modules/ScanOrderLogger/providers/grafana.js +0 -52
- package/lib/modules/ScanOrderLogger/types.d.ts +0 -53
- package/lib/modules/ScanOrderLogger/types.js +0 -17
- package/lib/solution/ScanOrder/index.d.ts +0 -152
- package/lib/solution/ScanOrder/index.js +0 -1901
- package/lib/solution/ScanOrder/types.d.ts +0 -287
- package/lib/solution/ScanOrder/types.js +0 -36
- package/lib/solution/ScanOrder/utils.d.ts +0 -167
- package/lib/solution/ScanOrder/utils.js +0 -635
- package/lib/solution/VenueBooking/index.d.ts +0 -199
- package/lib/solution/VenueBooking/index.js +0 -1926
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -343
- package/lib/solution/VenueBooking/types.d.ts +0 -154
- package/lib/solution/VenueBooking/types.js +0 -44
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
- package/lib/solution/VenueBooking/utils/dateSummary.js +0 -110
- package/lib/solution/VenueBooking/utils/resource.d.ts +0 -14
- package/lib/solution/VenueBooking/utils/resource.js +0 -92
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -38
- package/lib/solution/VenueBooking/utils/slotMerge.js +0 -237
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -32
- package/lib/solution/VenueBooking/utils/timeSlot.js +0 -339
- package/lib/solution/VenueBooking/utils.d.ts +0 -1
- package/lib/solution/VenueBooking/utils.js +0 -69
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProductList, CartModule, ProductData, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule,
|
|
1
|
+
import { ProductList, CartModule, ProductData, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from '../../modules';
|
|
2
2
|
export interface BookingByStepState {
|
|
3
3
|
cart: CartModule;
|
|
4
4
|
summary: SummaryModule;
|
|
@@ -14,8 +14,6 @@ export interface BookingByStepState {
|
|
|
14
14
|
currentProduct?: ProductData;
|
|
15
15
|
currentProductMeta?: Record<string, any>;
|
|
16
16
|
schedule: ScheduleModule;
|
|
17
|
-
salesSummary?: SalesSummaryModule;
|
|
18
|
-
scanOrderLogger?: ScanOrderLoggerModule;
|
|
19
17
|
}
|
|
20
18
|
export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
|
|
21
19
|
export declare enum BookingByStepHooks {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { ProductList, CartModule, AccountListModule, DateModule, OrderModule, PaymentModule, StepModule, SummaryModule,
|
|
1
|
+
import { ProductList, CartModule, AccountListModule, DateModule, OrderModule, PaymentModule, StepModule, SummaryModule, ScheduleModule } from "../../modules";
|
|
2
2
|
export function createModule(moduleName, solutionName, name, version) {
|
|
3
3
|
switch (moduleName) {
|
|
4
4
|
case 'cart':
|
|
5
5
|
return new CartModule("".concat(solutionName, "_").concat(name || moduleName), version);
|
|
6
6
|
case 'summary':
|
|
7
7
|
return new SummaryModule("".concat(solutionName, "_").concat(name || moduleName), version);
|
|
8
|
-
case 'salesSummary':
|
|
9
|
-
return new SalesSummaryModule("".concat(solutionName, "_").concat(name || moduleName), version);
|
|
10
8
|
case 'step':
|
|
11
9
|
return new StepModule("".concat(solutionName, "_").concat(name || moduleName), version);
|
|
12
10
|
case 'products':
|
|
@@ -21,8 +19,6 @@ export function createModule(moduleName, solutionName, name, version) {
|
|
|
21
19
|
return new PaymentModule("".concat(solutionName, "_").concat(name || moduleName), version);
|
|
22
20
|
case 'schedule':
|
|
23
21
|
return new ScheduleModule("".concat(solutionName, "_").concat(name || moduleName), version);
|
|
24
|
-
case 'scanOrderLogger':
|
|
25
|
-
return new ScanOrderLoggerModule("".concat(solutionName, "_").concat(name || moduleName), version);
|
|
26
22
|
default:
|
|
27
23
|
throw new Error("Unknown module type: ".concat(moduleName));
|
|
28
24
|
}
|
|
@@ -19,12 +19,10 @@ export declare function calculateResourceAvailableTime({ resource, timeSlots, cu
|
|
|
19
19
|
* @param countMap 已预约数量映射
|
|
20
20
|
* @returns 最快可用的资源
|
|
21
21
|
*/
|
|
22
|
-
export declare function findFastestAvailableResource({ resources, currentCapacity, countMap,
|
|
22
|
+
export declare function findFastestAvailableResource({ resources, currentCapacity, countMap, }: {
|
|
23
23
|
resources: ResourceItem[];
|
|
24
24
|
currentCapacity?: number;
|
|
25
25
|
countMap?: Record<number, number>;
|
|
26
|
-
targetDate?: string | Dayjs;
|
|
27
|
-
durationMinutes?: number;
|
|
28
26
|
}): ResourceItem | null;
|
|
29
27
|
/**
|
|
30
28
|
* 给定一个时间列表,通过开始和结束时间过滤出符合条件的时间段
|
|
@@ -91,14 +91,8 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
91
91
|
_ref2$currentCapacity = _ref2.currentCapacity,
|
|
92
92
|
currentCapacity = _ref2$currentCapacity === void 0 ? 1 : _ref2$currentCapacity,
|
|
93
93
|
_ref2$countMap = _ref2.countMap,
|
|
94
|
-
countMap = _ref2$countMap === void 0 ? {} : _ref2$countMap
|
|
95
|
-
targetDate = _ref2.targetDate,
|
|
96
|
-
_ref2$durationMinutes = _ref2.durationMinutes,
|
|
97
|
-
durationMinutes = _ref2$durationMinutes === void 0 ? 30 : _ref2$durationMinutes;
|
|
94
|
+
countMap = _ref2$countMap === void 0 ? {} : _ref2$countMap;
|
|
98
95
|
var currentTime = dayjs();
|
|
99
|
-
var resolvedDuration = durationMinutes > 0 ? durationMinutes : 30;
|
|
100
|
-
var targetDay = targetDate ? dayjs(targetDate) : currentTime;
|
|
101
|
-
var isTargetDayToday = targetDay.isSame(currentTime, 'day');
|
|
102
96
|
var fastestTime = null;
|
|
103
97
|
var fastestResources = [];
|
|
104
98
|
console.log('[TimeslotUtils] 查找最快可用资源:', {
|
|
@@ -114,18 +108,17 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
114
108
|
try {
|
|
115
109
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
116
110
|
var _resource = _step2.value;
|
|
117
|
-
//
|
|
118
|
-
var
|
|
119
|
-
var
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return dayjs(time.end_at).isAfter(currentTime);
|
|
111
|
+
// 获取资源当天且还在工作时间内的时间段
|
|
112
|
+
var todayTimes = _resource.times.filter(function (time) {
|
|
113
|
+
var isToday = dayjs(time.start_at).isSame(currentTime, 'day');
|
|
114
|
+
var isStillWorking = dayjs(time.end_at).isAfter(currentTime);
|
|
115
|
+
return isToday && isStillWorking;
|
|
123
116
|
});
|
|
124
|
-
if (
|
|
117
|
+
if (todayTimes.length === 0) {
|
|
125
118
|
console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(_resource.id, "(").concat(_resource.main_field, ") \u4ECA\u65E5\u65E0\u53EF\u7528\u65F6\u95F4\u6BB5"));
|
|
126
119
|
continue;
|
|
127
120
|
}
|
|
128
|
-
var _iterator4 = _createForOfIteratorHelper(
|
|
121
|
+
var _iterator4 = _createForOfIteratorHelper(todayTimes),
|
|
129
122
|
_step4;
|
|
130
123
|
try {
|
|
131
124
|
var _loop = function _loop() {
|
|
@@ -135,7 +128,7 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
135
128
|
var workEndTime = dayjs(time.end_at);
|
|
136
129
|
|
|
137
130
|
// 确定检查的起始时间(当前时间 vs 工作开始时间)
|
|
138
|
-
var nextAvailableTime =
|
|
131
|
+
var nextAvailableTime = currentTime.isBefore(workStartTime) ? workStartTime : currentTime;
|
|
139
132
|
console.log("[TimeslotUtils] \u68C0\u67E5\u8D44\u6E90 ".concat(_resource.id, "(").concat(_resource.main_field, "):"), {
|
|
140
133
|
workTime: "".concat(workStartTime.format('HH:mm'), "-").concat(workEndTime.format('HH:mm')),
|
|
141
134
|
checkStartTime: nextAvailableTime.format('HH:mm:ss'),
|
|
@@ -172,7 +165,7 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
172
165
|
// 检查资源类型和容量
|
|
173
166
|
if (_resource.resourceType === 'single' || (_resource.capacity || 1) === 1) {
|
|
174
167
|
// 单人预约资源:检查时间冲突
|
|
175
|
-
if (finalAvailableTime.isBefore(_eventEnd) && _eventStart.isBefore(finalAvailableTime.add(
|
|
168
|
+
if (finalAvailableTime.isBefore(_eventEnd) && _eventStart.isBefore(finalAvailableTime.add(30, 'minute'))) {
|
|
176
169
|
// 有冲突,使用事件结束时间
|
|
177
170
|
finalAvailableTime = _eventEnd;
|
|
178
171
|
console.log("[TimeslotUtils] \u53D1\u73B0\u65F6\u95F4\u51B2\u7A81\uFF0C\u8C03\u6574\u5230: ".concat(finalAvailableTime.format('HH:mm:ss')));
|
|
@@ -184,7 +177,7 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
184
177
|
var eventUsedCapacity = _event.pax || 1;
|
|
185
178
|
|
|
186
179
|
// 如果在事件时间范围内,检查容量是否足够
|
|
187
|
-
if (finalAvailableTime.isBefore(_eventEnd) && _eventStart.isBefore(finalAvailableTime.add(
|
|
180
|
+
if (finalAvailableTime.isBefore(_eventEnd) && _eventStart.isBefore(finalAvailableTime.add(30, 'minute'))) {
|
|
188
181
|
var totalRequiredCapacity = currentUsedCapacity + currentCapacity + eventUsedCapacity;
|
|
189
182
|
if (totalRequiredCapacity > totalCapacity) {
|
|
190
183
|
// 容量不足,使用事件结束时间
|
|
@@ -201,7 +194,7 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
201
194
|
} finally {
|
|
202
195
|
_iterator5.f();
|
|
203
196
|
}
|
|
204
|
-
if (finalAvailableTime.
|
|
197
|
+
if (finalAvailableTime.isAfter(workEndTime)) {
|
|
205
198
|
console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(_resource.id, " \u53EF\u7528\u65F6\u95F4\u8D85\u51FA\u5DE5\u4F5C\u65F6\u95F4\uFF0C\u8DF3\u8FC7"));
|
|
206
199
|
return 0; // continue
|
|
207
200
|
}
|
|
@@ -403,6 +403,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
403
403
|
product_id: item.product_id,
|
|
404
404
|
product_variant_id: item.product_variant_id,
|
|
405
405
|
quantity: item.num,
|
|
406
|
+
is_price_include_tax: item.is_price_include_tax,
|
|
406
407
|
// 商品是否含税:1;0
|
|
407
408
|
is_charge_tax: (_item$is_charge_tax = item.is_charge_tax) !== null && _item$is_charge_tax !== void 0 ? _item$is_charge_tax : 0,
|
|
408
409
|
// 若商品不含税,计算得到的税费,单位(元)
|
|
@@ -427,6 +428,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
427
428
|
},
|
|
428
429
|
product_bundle: (item.product_bundle || []).map(function (bundle) {
|
|
429
430
|
return {
|
|
431
|
+
is_price_include_tax: item.is_price_include_tax,
|
|
430
432
|
bundle_id: bundle.bundle_id,
|
|
431
433
|
bundle_product_id: bundle.bundle_product_id,
|
|
432
434
|
bundle_variant_id: bundle.bundle_variant_id,
|
|
@@ -22,6 +22,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
22
22
|
getCurrentBookingTime(): string | null;
|
|
23
23
|
private filterDiscountListByBookingTime;
|
|
24
24
|
setCustomer(customer: Customer): Promise<void>;
|
|
25
|
+
setOriginTotalAmount(amount: number): void;
|
|
25
26
|
setHolders(holders: {
|
|
26
27
|
form_record_id: number;
|
|
27
28
|
}[]): void;
|
|
@@ -29,7 +30,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
29
30
|
type?: 'form' | 'customer';
|
|
30
31
|
[key: string]: any;
|
|
31
32
|
}): void;
|
|
32
|
-
setOrderId(id?: number): void;
|
|
33
33
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
34
34
|
productList: Record<string, any>[];
|
|
35
35
|
discountList: Discount[];
|
|
@@ -57,7 +57,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
57
57
|
private bestDiscount;
|
|
58
58
|
loadPrepareConfig(params: {
|
|
59
59
|
customerId: number;
|
|
60
|
-
action?: 'create' | '
|
|
60
|
+
action?: 'create' | 'update';
|
|
61
61
|
with_good_pass?: 0 | 1;
|
|
62
62
|
with_discount_card?: 0 | 1;
|
|
63
63
|
}): Promise<void>;
|
|
@@ -57,7 +57,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
57
57
|
currentBookingTime: "",
|
|
58
58
|
filteredDiscountList: [],
|
|
59
59
|
bookingSubject: undefined,
|
|
60
|
-
|
|
60
|
+
orderTotalAmount: 0
|
|
61
61
|
};
|
|
62
62
|
return _this;
|
|
63
63
|
}
|
|
@@ -289,7 +289,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
289
289
|
return _setCustomer.apply(this, arguments);
|
|
290
290
|
}
|
|
291
291
|
return setCustomer;
|
|
292
|
-
}()
|
|
292
|
+
}()
|
|
293
|
+
}, {
|
|
294
|
+
key: "setOriginTotalAmount",
|
|
295
|
+
value: function setOriginTotalAmount(amount) {
|
|
296
|
+
this.store.orderTotalAmount = amount;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// 设置holders
|
|
293
300
|
}, {
|
|
294
301
|
key: "setHolders",
|
|
295
302
|
value: function setHolders(holders) {
|
|
@@ -300,11 +307,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
300
307
|
value: function setBookingSubject(bookingSubject) {
|
|
301
308
|
this.store.bookingSubject = bookingSubject;
|
|
302
309
|
}
|
|
303
|
-
}, {
|
|
304
|
-
key: "setOrderId",
|
|
305
|
-
value: function setOrderId(id) {
|
|
306
|
-
this.store.orderId = id;
|
|
307
|
-
}
|
|
308
310
|
|
|
309
311
|
// 计算优惠券
|
|
310
312
|
}, {
|
|
@@ -322,6 +324,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
322
324
|
var _ref = rulesModule.calcDiscount({
|
|
323
325
|
productList: productList,
|
|
324
326
|
discountList: this.getDiscountList(),
|
|
327
|
+
orderTotalAmount: this.store.orderTotalAmount || 0,
|
|
325
328
|
holders: this.store.holders || [],
|
|
326
329
|
isFormSubject: ((_this$store$bookingSu = this.store.bookingSubject) === null || _this$store$bookingSu === void 0 ? void 0 : _this$store$bookingSu.type) === 'form'
|
|
327
330
|
}, options) || {
|
|
@@ -440,10 +443,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
440
443
|
case 0:
|
|
441
444
|
_context6.prev = 0;
|
|
442
445
|
_context6.next = 3;
|
|
443
|
-
return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.batchSearch(code,
|
|
444
|
-
customerId: customerId,
|
|
445
|
-
orderId: this.store.orderId
|
|
446
|
-
});
|
|
446
|
+
return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.batchSearch(code, customerId);
|
|
447
447
|
case 3:
|
|
448
448
|
_context6.t0 = _context6.sent;
|
|
449
449
|
if (_context6.t0) {
|
|
@@ -504,6 +504,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
504
504
|
productList: this.store.productList || [],
|
|
505
505
|
oldDiscountList: this.getDiscountList(),
|
|
506
506
|
newDiscountList: withScanList,
|
|
507
|
+
orderTotalAmount: this.store.orderTotalAmount || 0,
|
|
507
508
|
holders: this.store.holders || [],
|
|
508
509
|
isFormSubject: ((_this$store$bookingSu2 = this.store.bookingSubject) === null || _this$store$bookingSu2 === void 0 ? void 0 : _this$store$bookingSu2.type) === 'form'
|
|
509
510
|
}) || {
|
|
@@ -617,21 +618,27 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
617
618
|
return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
|
|
618
619
|
});
|
|
619
620
|
if (index !== -1) {
|
|
620
|
-
var _discount$metadata;
|
|
621
|
+
var _editModeDiscountList, _discount$metadata, _discount$metadata2;
|
|
621
622
|
editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
|
|
623
|
+
metadata: _objectSpread(_objectSpread({}, discount.metadata || {}), {}, {
|
|
624
|
+
num: ((editModeDiscountList === null || editModeDiscountList === void 0 || (_editModeDiscountList = editModeDiscountList[index]) === null || _editModeDiscountList === void 0 || (_editModeDiscountList = _editModeDiscountList.metadata) === null || _editModeDiscountList === void 0 ? void 0 : _editModeDiscountList.num) || 1) + (((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.num) || 1)
|
|
625
|
+
}),
|
|
622
626
|
amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
|
|
623
|
-
savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus((discount === null || discount === void 0 || (_discount$
|
|
627
|
+
savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus((discount === null || discount === void 0 || (_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.product_discount_difference) || 0).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
624
628
|
});
|
|
625
629
|
} else {
|
|
626
|
-
var _discount$
|
|
630
|
+
var _discount$metadata3, _discount$metadata4, _discount$discount2, _discount$discount3, _discount$discount4;
|
|
627
631
|
if (discount.type && !discount.tag) {
|
|
628
632
|
discount.tag = discount.type;
|
|
629
633
|
}
|
|
630
634
|
editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
|
|
635
|
+
metadata: _objectSpread(_objectSpread({}, discount.metadata || {}), {}, {
|
|
636
|
+
num: ((_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.num) || 1
|
|
637
|
+
}),
|
|
631
638
|
name: discount.name || discount.discount.title.auto,
|
|
632
639
|
isEditMode: true,
|
|
633
640
|
limited_relation_product_data: {},
|
|
634
|
-
savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus((discount === null || discount === void 0 || (_discount$
|
|
641
|
+
savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus((discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.product_discount_difference) || 0).toNumber(),
|
|
635
642
|
isAvailable: true,
|
|
636
643
|
id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
|
|
637
644
|
format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
|
|
@@ -778,27 +785,24 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
778
785
|
key: "loadPrepareConfig",
|
|
779
786
|
value: function () {
|
|
780
787
|
var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
781
|
-
var _this$getCustomer2, _this$store$discount8, _this$getDiscountList, _this$store$discount9, _this$store$productLi2,
|
|
788
|
+
var _this$getCustomer2, _this$store$discount8, _this$getDiscountList, _this$store$discount9, _this$store$productLi2, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, filteredDiscountList, _result3;
|
|
782
789
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
783
790
|
while (1) switch (_context10.prev = _context10.next) {
|
|
784
791
|
case 0:
|
|
785
792
|
_context10.prev = 0;
|
|
786
|
-
orderId = this.store.orderId;
|
|
787
793
|
customerId = params.customerId || ((_this$getCustomer2 = this.getCustomer()) === null || _this$getCustomer2 === void 0 ? void 0 : _this$getCustomer2.id); // if (customerId === 1 || !customerId) {
|
|
788
794
|
// return
|
|
789
795
|
// }
|
|
790
|
-
_context10.next =
|
|
791
|
-
return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 ? void 0 : _this$store$discount8.loadPrepareConfig(
|
|
796
|
+
_context10.next = 4;
|
|
797
|
+
return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 ? void 0 : _this$store$discount8.loadPrepareConfig({
|
|
792
798
|
customer_id: customerId,
|
|
793
|
-
action:
|
|
799
|
+
action: 'create',
|
|
794
800
|
with_good_pass: 1,
|
|
795
801
|
with_discount_card: 1,
|
|
796
802
|
with_wallet_pass_holder: 1,
|
|
797
803
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
} : {}));
|
|
801
|
-
case 5:
|
|
804
|
+
});
|
|
805
|
+
case 4:
|
|
802
806
|
goodPassList = _context10.sent;
|
|
803
807
|
scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
|
|
804
808
|
return item.isScan;
|
|
@@ -811,35 +815,35 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
811
815
|
});
|
|
812
816
|
newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || [])); // 存储原始优惠券列表
|
|
813
817
|
this.store.originalDiscountList = newDiscountList;
|
|
814
|
-
_context10.next =
|
|
818
|
+
_context10.next = 12;
|
|
815
819
|
return (_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.setOriginalDiscountList(newDiscountList);
|
|
816
|
-
case
|
|
820
|
+
case 12:
|
|
817
821
|
// 根据当前预约时间过滤优惠券列表
|
|
818
822
|
filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
819
823
|
this.store.filteredDiscountList = filteredDiscountList;
|
|
820
824
|
this.setDiscountList(filteredDiscountList || []);
|
|
821
825
|
if (!((_this$store$productLi2 = this.store.productList) !== null && _this$store$productLi2 !== void 0 && _this$store$productLi2.length)) {
|
|
822
|
-
_context10.next =
|
|
826
|
+
_context10.next = 19;
|
|
823
827
|
break;
|
|
824
828
|
}
|
|
825
829
|
_result3 = this.calcDiscount(this.store.productList);
|
|
826
|
-
_context10.next =
|
|
830
|
+
_context10.next = 19;
|
|
827
831
|
return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"), _result3);
|
|
828
|
-
case
|
|
829
|
-
_context10.next =
|
|
830
|
-
return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"),
|
|
831
|
-
case
|
|
832
|
-
_context10.next =
|
|
832
|
+
case 19:
|
|
833
|
+
_context10.next = 21;
|
|
834
|
+
return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), newDiscountList);
|
|
835
|
+
case 21:
|
|
836
|
+
_context10.next = 26;
|
|
833
837
|
break;
|
|
834
|
-
case
|
|
835
|
-
_context10.prev =
|
|
838
|
+
case 23:
|
|
839
|
+
_context10.prev = 23;
|
|
836
840
|
_context10.t0 = _context10["catch"](0);
|
|
837
841
|
console.error('[ShopDiscount] 加载准备配置出错:', _context10.t0);
|
|
838
|
-
case
|
|
842
|
+
case 26:
|
|
839
843
|
case "end":
|
|
840
844
|
return _context10.stop();
|
|
841
845
|
}
|
|
842
|
-
}, _callee10, this, [[0,
|
|
846
|
+
}, _callee10, this, [[0, 23]]);
|
|
843
847
|
}));
|
|
844
848
|
function loadPrepareConfig(_x10) {
|
|
845
849
|
return _loadPrepareConfig.apply(this, arguments);
|
|
@@ -23,6 +23,7 @@ export interface ShopDiscountState {
|
|
|
23
23
|
discount: DiscountModule | null;
|
|
24
24
|
rules: RulesModule | null;
|
|
25
25
|
productList: Record<string, any>[];
|
|
26
|
+
orderTotalAmount?: number;
|
|
26
27
|
holders?: {
|
|
27
28
|
form_record_id: number;
|
|
28
29
|
form_id?: number;
|
|
@@ -35,7 +36,6 @@ export interface ShopDiscountState {
|
|
|
35
36
|
type?: 'form' | 'customer';
|
|
36
37
|
[key: string]: any;
|
|
37
38
|
};
|
|
38
|
-
orderId?: number;
|
|
39
39
|
}
|
|
40
40
|
export interface SetDiscountSelectedParams {
|
|
41
41
|
discountId: number;
|
|
@@ -8,4 +8,5 @@ export var ShopDiscountHooks = /*#__PURE__*/function (ShopDiscountHooks) {
|
|
|
8
8
|
ShopDiscountHooks["onRulesListChange"] = "shopDiscount:onRulesListChange";
|
|
9
9
|
ShopDiscountHooks["onLoadPrepareCalcResult"] = "shopDiscount:onLoadPrepareCalcResult";
|
|
10
10
|
return ShopDiscountHooks;
|
|
11
|
-
}({});
|
|
11
|
+
}({});
|
|
12
|
+
;
|
|
@@ -40,23 +40,37 @@ export var isAllNormalProduct = function isAllNormalProduct(items) {
|
|
|
40
40
|
* @returns
|
|
41
41
|
*/
|
|
42
42
|
export var getDiscountAmount = function getDiscountAmount(discount, total, price) {
|
|
43
|
-
var
|
|
43
|
+
var discountedPrice = 0;
|
|
44
|
+
|
|
44
45
|
// 商品券
|
|
45
46
|
if (discount.tag === 'good_pass') {
|
|
46
|
-
|
|
47
|
+
discountedPrice = new Decimal(price).minus(new Decimal(price || 0)).toNumber();
|
|
48
|
+
} else {
|
|
49
|
+
var _discount$metadata;
|
|
50
|
+
// 判断是否是固定金额
|
|
51
|
+
var isFixedAmount = (discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type) === 'fixed_amount';
|
|
52
|
+
|
|
53
|
+
// 固定金额 小于0时返回0
|
|
54
|
+
if (isFixedAmount) {
|
|
55
|
+
discountedPrice = Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
|
|
56
|
+
} else {
|
|
57
|
+
// 百分比:根据折扣卡金额计算
|
|
58
|
+
discountedPrice = new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
|
|
59
|
+
}
|
|
47
60
|
}
|
|
48
61
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
/*
|
|
63
|
+
// 🔥 如果有 maxDeductionAmount 限制,确保折扣金额不超过限制
|
|
64
|
+
if (discount.config?.maxDeductionAmount) {
|
|
65
|
+
const actualDiscountAmount = new Decimal(price).minus(discountedPrice).toNumber();
|
|
66
|
+
if (actualDiscountAmount > discount.config.maxDeductionAmount) {
|
|
67
|
+
// 折扣金额超过限制,重新计算折扣后价格
|
|
68
|
+
discountedPrice = new Decimal(price).minus(discount.config.maxDeductionAmount).toNumber();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
*/
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
|
|
73
|
+
return discountedPrice;
|
|
60
74
|
};
|
|
61
75
|
export var getDiscountListAmountTotal = function getDiscountListAmountTotal(discount) {
|
|
62
76
|
return discount.reduce(function (acc, cur) {
|
package/dist/solution/index.d.ts
CHANGED
package/dist/solution/index.js
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -38,6 +38,7 @@ __reExport(src_exports, require("./types"), module.exports);
|
|
|
38
38
|
__reExport(src_exports, require("./modules"), module.exports);
|
|
39
39
|
__reExport(src_exports, require("./plugins"), module.exports);
|
|
40
40
|
__reExport(src_exports, require("./solution"), module.exports);
|
|
41
|
+
__reExport(src_exports, require("./model"), module.exports);
|
|
41
42
|
var import_core = require("./core");
|
|
42
43
|
var import_core2 = __toESM(require("./core"));
|
|
43
44
|
var src_default = import_core2.default;
|
|
@@ -47,5 +48,6 @@ var src_default = import_core2.default;
|
|
|
47
48
|
...require("./types"),
|
|
48
49
|
...require("./modules"),
|
|
49
50
|
...require("./plugins"),
|
|
50
|
-
...require("./solution")
|
|
51
|
+
...require("./solution"),
|
|
52
|
+
...require("./model")
|
|
51
53
|
});
|
|
@@ -512,14 +512,21 @@ var PromotionEvaluator = class {
|
|
|
512
512
|
unitProducts.push({
|
|
513
513
|
product,
|
|
514
514
|
price: product.price,
|
|
515
|
-
productId: product.id
|
|
515
|
+
productId: product.id,
|
|
516
|
+
sourceAvailableQty: availableQty
|
|
516
517
|
});
|
|
517
518
|
}
|
|
518
519
|
}
|
|
519
520
|
if (unitProducts.length === 0) {
|
|
520
521
|
return { products: [], originalAmount: 0, finalAmount: 0 };
|
|
521
522
|
}
|
|
522
|
-
unitProducts.sort((a, b) =>
|
|
523
|
+
unitProducts.sort((a, b) => {
|
|
524
|
+
const aIsMultiple = a.sourceAvailableQty > 0 && a.sourceAvailableQty % x === 0 ? 1 : 0;
|
|
525
|
+
const bIsMultiple = b.sourceAvailableQty > 0 && b.sourceAvailableQty % x === 0 ? 1 : 0;
|
|
526
|
+
if (aIsMultiple !== bIsMultiple)
|
|
527
|
+
return bIsMultiple - aIsMultiple;
|
|
528
|
+
return b.price - a.price;
|
|
529
|
+
});
|
|
523
530
|
const totalUnits = unitProducts.length;
|
|
524
531
|
const groupCount = cumulative ? Math.floor(totalUnits / x) : totalUnits >= x ? 1 : 0;
|
|
525
532
|
const promotionUnits = groupCount * x;
|
|
@@ -573,7 +580,9 @@ var PromotionEvaluator = class {
|
|
|
573
580
|
(sum, p) => sum.plus(p),
|
|
574
581
|
new import_decimal.default(0)
|
|
575
582
|
);
|
|
576
|
-
const
|
|
583
|
+
const productOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
|
|
584
|
+
const actualTotal = import_decimal.default.min(totalAllocated, productOriginalAmount);
|
|
585
|
+
const finalPricePerUnit = this.formatPrice(actualTotal.div(promoQty));
|
|
577
586
|
result.push({
|
|
578
587
|
...product,
|
|
579
588
|
quantity: promoQty,
|
|
@@ -584,9 +593,8 @@ var PromotionEvaluator = class {
|
|
|
584
593
|
isSplit: false,
|
|
585
594
|
matchedBundleIndex
|
|
586
595
|
});
|
|
587
|
-
const productOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
|
|
588
596
|
originalAmount = originalAmount.plus(productOriginalAmount);
|
|
589
|
-
finalAmount = finalAmount.plus(
|
|
597
|
+
finalAmount = finalAmount.plus(actualTotal);
|
|
590
598
|
} else if (promoQty === 0 && remainingQty > 0) {
|
|
591
599
|
result.push({
|
|
592
600
|
...product,
|
|
@@ -605,7 +613,9 @@ var PromotionEvaluator = class {
|
|
|
605
613
|
(sum, p) => sum.plus(p),
|
|
606
614
|
new import_decimal.default(0)
|
|
607
615
|
);
|
|
608
|
-
const
|
|
616
|
+
const promoOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
|
|
617
|
+
const actualTotal = import_decimal.default.min(totalAllocated, promoOriginalAmount);
|
|
618
|
+
const finalPricePerUnit = this.formatPrice(actualTotal.div(promoQty));
|
|
609
619
|
result.push({
|
|
610
620
|
...product,
|
|
611
621
|
id: this.generateRandomId(),
|
|
@@ -618,9 +628,8 @@ var PromotionEvaluator = class {
|
|
|
618
628
|
matchedBundleIndex,
|
|
619
629
|
isSplit: true
|
|
620
630
|
});
|
|
621
|
-
const promoOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
|
|
622
631
|
originalAmount = originalAmount.plus(promoOriginalAmount);
|
|
623
|
-
finalAmount = finalAmount.plus(
|
|
632
|
+
finalAmount = finalAmount.plus(actualTotal);
|
|
624
633
|
result.push({
|
|
625
634
|
...product,
|
|
626
635
|
quantity: remainingQty,
|
|
@@ -636,6 +645,46 @@ var PromotionEvaluator = class {
|
|
|
636
645
|
}
|
|
637
646
|
processedQuantityMap.set(key, processedQty + availableQty);
|
|
638
647
|
}
|
|
648
|
+
if (groupCount > 0) {
|
|
649
|
+
const expectedPromoTotal = new import_decimal.default(groupPrice).mul(groupCount);
|
|
650
|
+
const promoItems = result.filter((p) => p.inPromotion);
|
|
651
|
+
let actualPromoTotal = new import_decimal.default(0);
|
|
652
|
+
for (const p of promoItems) {
|
|
653
|
+
actualPromoTotal = actualPromoTotal.plus(
|
|
654
|
+
new import_decimal.default(p.finalPrice).mul(p.quantity)
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
const roundingDiff = actualPromoTotal.minus(expectedPromoTotal);
|
|
658
|
+
if (!roundingDiff.eq(0)) {
|
|
659
|
+
const adjustTarget = promoItems.find((p) => p.quantity === 1);
|
|
660
|
+
if (adjustTarget) {
|
|
661
|
+
adjustTarget.finalPrice = this.formatPrice(
|
|
662
|
+
new import_decimal.default(adjustTarget.finalPrice).minus(roundingDiff)
|
|
663
|
+
);
|
|
664
|
+
} else if (promoItems.length > 0) {
|
|
665
|
+
const lastPromo = promoItems[promoItems.length - 1];
|
|
666
|
+
const adjustedUnitPrice = this.formatPrice(
|
|
667
|
+
new import_decimal.default(lastPromo.finalPrice).minus(roundingDiff)
|
|
668
|
+
);
|
|
669
|
+
lastPromo.quantity -= 1;
|
|
670
|
+
lastPromo.isSplit = true;
|
|
671
|
+
result.push({
|
|
672
|
+
...lastPromo,
|
|
673
|
+
id: this.generateRandomId(),
|
|
674
|
+
originalId: lastPromo.originalId || lastPromo.id,
|
|
675
|
+
quantity: 1,
|
|
676
|
+
finalPrice: adjustedUnitPrice,
|
|
677
|
+
isSplit: true
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
finalAmount = new import_decimal.default(0);
|
|
681
|
+
for (const p of result) {
|
|
682
|
+
finalAmount = finalAmount.plus(
|
|
683
|
+
new import_decimal.default(p.finalPrice).mul(p.quantity)
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
639
688
|
return {
|
|
640
689
|
products: result,
|
|
641
690
|
originalAmount: originalAmount.toNumber(),
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/model/strategy/adapter/promotion/index.ts
|
|
30
|
+
var promotion_exports = {};
|
|
31
|
+
__export(promotion_exports, {
|
|
32
|
+
BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
|
|
33
|
+
PromotionAdapter: () => import_adapter.PromotionAdapter,
|
|
34
|
+
PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
|
|
35
|
+
X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
|
|
36
|
+
default: () => import_adapter2.default
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(promotion_exports);
|
|
39
|
+
var import_evaluator = require("./evaluator");
|
|
40
|
+
var import_adapter = require("./adapter");
|
|
41
|
+
var import_adapter2 = __toESM(require("./adapter"));
|
|
42
|
+
var import_examples = require("./examples");
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
BUY_X_GET_Y_FREE_STRATEGY,
|
|
46
|
+
PromotionAdapter,
|
|
47
|
+
PromotionEvaluator,
|
|
48
|
+
X_ITEMS_FOR_Y_PRICE_STRATEGY
|
|
49
|
+
});
|