@pisell/pisellos 2.2.198 → 2.2.200
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/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +7 -3
- package/dist/modules/Cart/utils/cartProduct.js +11 -1
- package/dist/modules/Cart/utils/changePrice.js +11 -11
- package/dist/modules/Order/index.js +155 -104
- package/dist/modules/Order/types.d.ts +1 -0
- package/dist/modules/Order/utils.d.ts +33 -2
- package/dist/modules/Order/utils.js +112 -55
- package/dist/modules/SalesSummary/utils.js +97 -63
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +294 -190
- package/dist/server/modules/order/index.d.ts +8 -0
- package/dist/server/modules/order/index.js +536 -317
- package/dist/server/modules/order/types.d.ts +2 -0
- package/dist/solution/BaseSales/index.js +2 -1
- package/dist/solution/BaseSales/types.d.ts +1 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +19 -4
- package/dist/solution/BookingTicket/index.d.ts +23 -0
- package/dist/solution/BookingTicket/index.js +291 -196
- package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +40 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.js +70 -0
- package/dist/solution/ScanOrder/types.d.ts +1 -0
- package/dist/solution/ScanOrder/utils.js +26 -9
- package/dist/solution/VenueBooking/index.js +2 -1
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +4 -1
- package/lib/modules/Cart/utils/cartProduct.js +11 -1
- package/lib/modules/Cart/utils/changePrice.js +12 -20
- package/lib/modules/Order/index.js +58 -6
- package/lib/modules/Order/types.d.ts +1 -0
- package/lib/modules/Order/utils.d.ts +33 -2
- package/lib/modules/Order/utils.js +44 -9
- package/lib/modules/SalesSummary/utils.js +41 -44
- package/lib/server/index.d.ts +3 -0
- package/lib/server/index.js +82 -3
- package/lib/server/modules/order/index.d.ts +8 -0
- package/lib/server/modules/order/index.js +106 -4
- package/lib/server/modules/order/types.d.ts +2 -0
- package/lib/solution/BaseSales/index.js +2 -1
- package/lib/solution/BaseSales/types.d.ts +1 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +15 -1
- package/lib/solution/BookingTicket/index.d.ts +23 -0
- package/lib/solution/BookingTicket/index.js +60 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +40 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.js +44 -2
- package/lib/solution/ScanOrder/types.d.ts +1 -0
- package/lib/solution/ScanOrder/utils.js +28 -10
- package/lib/solution/VenueBooking/index.js +2 -1
- package/package.json +1 -1
|
@@ -9,6 +9,21 @@
|
|
|
9
9
|
* 字段含义严格对齐既有协议(OrderTempOrder / parseSalesResponse),
|
|
10
10
|
* 不发明等价关系。
|
|
11
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* 子预约状态机转移动作(POST /schedule/booking-transition/{schedule_event_id})。
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* await bookingTicket.transitionChildBooking({
|
|
17
|
+
* schedule_event_id: 301,
|
|
18
|
+
* action: 'confirm',
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
export type BookingTransitionAction = 'confirm' | 'reject' | 'arrive' | 'start' | 'complete' | 'cancel' | 'no_show' | 'reschedule';
|
|
22
|
+
/** 子预约状态转移入参 */
|
|
23
|
+
export interface TransitionChildBookingParams {
|
|
24
|
+
schedule_event_id: number | string;
|
|
25
|
+
action: BookingTransitionAction;
|
|
26
|
+
}
|
|
12
27
|
/**
|
|
13
28
|
* 从 tempOrder 解析用于调用 appointment-status 接口的 schedule id。
|
|
14
29
|
*
|
|
@@ -35,3 +50,28 @@ export declare function applyBookingsStatus(bookings: any[] | null | undefined,
|
|
|
35
50
|
* 长度不一致时按较短一方对齐(防御式编程,正常路径不会发生)。
|
|
36
51
|
*/
|
|
37
52
|
export declare function restoreBookingsStatus(bookings: any[] | null | undefined, previous: Array<string | undefined>): void;
|
|
53
|
+
/**
|
|
54
|
+
* 将状态机 action 解析为转移后的 `appointment_status`。
|
|
55
|
+
*
|
|
56
|
+
* `reschedule` 暂未在状态矩阵启用,返回 null 表示跳过乐观更新。
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* resolveStatusAfterTransition('confirm'); // 'confirmed'
|
|
60
|
+
*/
|
|
61
|
+
export declare function resolveStatusAfterTransition(action: BookingTransitionAction): string | null;
|
|
62
|
+
/**
|
|
63
|
+
* 在 bookings 中按 `schedule_event_id` 定位子预约并乐观写入 `appointment_status`。
|
|
64
|
+
*
|
|
65
|
+
* @returns 写入前的 status;未命中时返回 undefined(调用方跳过回滚)
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const prev = applyChildBookingStatus(tempOrder.bookings, 301, 'confirmed');
|
|
69
|
+
*/
|
|
70
|
+
export declare function applyChildBookingStatus(bookings: any[] | null | undefined, scheduleEventId: number | string, status: string): string | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* 撤销 applyChildBookingStatus 对单条子预约的乐观写入。
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* restoreChildBookingStatus(tempOrder.bookings, 301, prev);
|
|
76
|
+
*/
|
|
77
|
+
export declare function restoreChildBookingStatus(bookings: any[] | null | undefined, scheduleEventId: number | string, previous: string | undefined): void;
|
|
@@ -10,6 +10,18 @@
|
|
|
10
10
|
* 不发明等价关系。
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* 子预约状态机转移动作(POST /schedule/booking-transition/{schedule_event_id})。
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* await bookingTicket.transitionChildBooking({
|
|
18
|
+
* schedule_event_id: 301,
|
|
19
|
+
* action: 'confirm',
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** 子预约状态转移入参 */
|
|
24
|
+
|
|
13
25
|
/**
|
|
14
26
|
* 从 tempOrder 解析用于调用 appointment-status 接口的 schedule id。
|
|
15
27
|
*
|
|
@@ -63,4 +75,62 @@ export function restoreBookingsStatus(bookings, previous) {
|
|
|
63
75
|
var b = bookings[i];
|
|
64
76
|
if (b) b.appointment_status = previous[i];
|
|
65
77
|
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 将状态机 action 解析为转移后的 `appointment_status`。
|
|
82
|
+
*
|
|
83
|
+
* `reschedule` 暂未在状态矩阵启用,返回 null 表示跳过乐观更新。
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* resolveStatusAfterTransition('confirm'); // 'confirmed'
|
|
87
|
+
*/
|
|
88
|
+
export function resolveStatusAfterTransition(action) {
|
|
89
|
+
var _map$action;
|
|
90
|
+
var map = {
|
|
91
|
+
confirm: 'confirmed',
|
|
92
|
+
reject: 'rejected',
|
|
93
|
+
arrive: 'arrived',
|
|
94
|
+
start: 'started',
|
|
95
|
+
complete: 'completed',
|
|
96
|
+
cancel: 'cancelled',
|
|
97
|
+
no_show: 'no_show',
|
|
98
|
+
reschedule: null
|
|
99
|
+
};
|
|
100
|
+
return (_map$action = map[action]) !== null && _map$action !== void 0 ? _map$action : null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 在 bookings 中按 `schedule_event_id` 定位子预约并乐观写入 `appointment_status`。
|
|
105
|
+
*
|
|
106
|
+
* @returns 写入前的 status;未命中时返回 undefined(调用方跳过回滚)
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* const prev = applyChildBookingStatus(tempOrder.bookings, 301, 'confirmed');
|
|
110
|
+
*/
|
|
111
|
+
export function applyChildBookingStatus(bookings, scheduleEventId, status) {
|
|
112
|
+
var _bookings$idx;
|
|
113
|
+
if (!Array.isArray(bookings)) return undefined;
|
|
114
|
+
var idx = bookings.findIndex(function (b) {
|
|
115
|
+
return b && String(b.schedule_event_id) === String(scheduleEventId);
|
|
116
|
+
});
|
|
117
|
+
if (idx === -1) return undefined;
|
|
118
|
+
var previous = (_bookings$idx = bookings[idx]) === null || _bookings$idx === void 0 ? void 0 : _bookings$idx.appointment_status;
|
|
119
|
+
bookings[idx].appointment_status = status;
|
|
120
|
+
return previous;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 撤销 applyChildBookingStatus 对单条子预约的乐观写入。
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* restoreChildBookingStatus(tempOrder.bookings, 301, prev);
|
|
128
|
+
*/
|
|
129
|
+
export function restoreChildBookingStatus(bookings, scheduleEventId, previous) {
|
|
130
|
+
if (!Array.isArray(bookings) || previous === undefined) return;
|
|
131
|
+
var idx = bookings.findIndex(function (b) {
|
|
132
|
+
return b && String(b.schedule_event_id) === String(scheduleEventId);
|
|
133
|
+
});
|
|
134
|
+
if (idx === -1) return;
|
|
135
|
+
bookings[idx].appointment_status = previous;
|
|
66
136
|
}
|
|
@@ -13,7 +13,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
13
13
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
14
|
import dayjs from 'dayjs';
|
|
15
15
|
import Decimal from 'decimal.js';
|
|
16
|
-
import { composeLinePrice, createUuidV4, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, resolveManualOverrideLineOriginalPrice, sumOptionUnitPrice } from "../../modules/Order/utils";
|
|
16
|
+
import { composeLinePrice, createUuidV4, ensureProductSku, getBundleSellingMagnitude, getProductSkuOptions, normalizeProductSkuOptions, resolveManualOverrideLineOriginalPrice, sumOptionUnitPrice } from "../../modules/Order/utils";
|
|
17
17
|
import { ensureManualProductDiscountList } from "../../modules/Order/utils/manualProductDiscount";
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -31,6 +31,7 @@ export function createEmptySummary() {
|
|
|
31
31
|
shipping_tax_fee: '0.00',
|
|
32
32
|
tax_fee: '0.00',
|
|
33
33
|
surcharge_fee: '0.00',
|
|
34
|
+
surcharges: [],
|
|
34
35
|
discount_amount: '0.00',
|
|
35
36
|
deposit_amount: '0.00',
|
|
36
37
|
expect_amount: '0.00',
|
|
@@ -510,16 +511,32 @@ export function normalizeOrderProduct(product) {
|
|
|
510
511
|
});
|
|
511
512
|
}
|
|
512
513
|
var normalizedBundle = bundleInput.map(function (item) {
|
|
513
|
-
var _item$bundle_id2, _item$bundle_product_, _item$bundle_group_id, _ref5,
|
|
514
|
-
|
|
514
|
+
var _item$price2, _item$bundle_id2, _item$bundle_product_, _item$bundle_group_id, _ref5, _ref6, _item$price3, _ref7, _item$price_type, _ref8, _item$price_type_ext;
|
|
515
|
+
var magnitudeSource = _objectSpread(_objectSpread({}, item), {}, {
|
|
516
|
+
// 计算 markdown 净额时,只把真实毛价交给 helper;若只有 bundle_selling_price,
|
|
517
|
+
// helper 会按历史净额兜底,避免 option 二次扣减。
|
|
518
|
+
price: (_item$price2 = item.price) !== null && _item$price2 !== void 0 ? _item$price2 : item.custom_price
|
|
519
|
+
});
|
|
520
|
+
var normalizedItem = _objectSpread(_objectSpread({}, item), {}, {
|
|
515
521
|
bundle_id: (_item$bundle_id2 = item.bundle_id) !== null && _item$bundle_id2 !== void 0 ? _item$bundle_id2 : item.id,
|
|
516
522
|
bundle_product_id: (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id,
|
|
517
523
|
bundle_group_id: (_item$bundle_group_id = item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item.group_id,
|
|
518
|
-
|
|
519
|
-
price: (
|
|
520
|
-
price_type: (
|
|
521
|
-
price_type_ext: (
|
|
524
|
+
// price 保留毛价(markdown 仍为 5),由 price_type 决定符号。
|
|
525
|
+
price: (_ref5 = (_ref6 = (_item$price3 = item.price) !== null && _item$price3 !== void 0 ? _item$price3 : item.custom_price) !== null && _ref6 !== void 0 ? _ref6 : item.bundle_selling_price) !== null && _ref5 !== void 0 ? _ref5 : '0.00',
|
|
526
|
+
price_type: (_ref7 = (_item$price_type = item.price_type) !== null && _item$price_type !== void 0 ? _item$price_type : item.custom_price_type) !== null && _ref7 !== void 0 ? _ref7 : '',
|
|
527
|
+
price_type_ext: (_ref8 = (_item$price_type_ext = item.price_type_ext) !== null && _item$price_type_ext !== void 0 ? _item$price_type_ext : item.custom_price_type_ext) !== null && _ref8 !== void 0 ? _ref8 : ''
|
|
522
528
|
});
|
|
529
|
+
// bundle_selling_price 落「正净额」:markdown = |price| − Σoptions;markup/原价维持原值。
|
|
530
|
+
normalizedItem.bundle_selling_price = getBundleSellingMagnitude(magnitudeSource).toFixed(2);
|
|
531
|
+
if (normalizedItem.price_type === 'markdown' && (normalizedItem.price_type_ext === '' || normalizedItem.price_type_ext === undefined || normalizedItem.price_type_ext === null)) {
|
|
532
|
+
var _normalizedItem$custo;
|
|
533
|
+
normalizedItem.custom_price = (_normalizedItem$custo = normalizedItem.custom_price) !== null && _normalizedItem$custo !== void 0 ? _normalizedItem$custo : normalizedItem.price;
|
|
534
|
+
normalizedItem.price = normalizedItem.bundle_selling_price;
|
|
535
|
+
}
|
|
536
|
+
if ((normalizedItem.price_type === 'markdown' || normalizedItem.price_type === 'markup') && (normalizedItem.price_type_ext === '' || normalizedItem.price_type_ext === undefined || normalizedItem.price_type_ext === null)) {
|
|
537
|
+
delete normalizedItem.original_total;
|
|
538
|
+
}
|
|
539
|
+
return normalizedItem;
|
|
523
540
|
});
|
|
524
541
|
var normalizedOptions = normalizeProductSkuOptions((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option);
|
|
525
542
|
var optionSum = sumOptionUnitPrice(normalizedOptions);
|
|
@@ -541,7 +558,7 @@ export function normalizeOrderProduct(product) {
|
|
|
541
558
|
var variantPrice = Array.isArray(variantList) ? (_variantList$find = variantList.find(function (v) {
|
|
542
559
|
return Number(v === null || v === void 0 ? void 0 : v.id) === variantId;
|
|
543
560
|
})) === null || _variantList$find === void 0 ? void 0 : _variantList$find.price : undefined;
|
|
544
|
-
var resolvedSource = function (_product$_origin, _product$_origin2,
|
|
561
|
+
var resolvedSource = function (_product$_origin, _product$_origin2, _ref9, _product$original_pri) {
|
|
545
562
|
if (metadata.source_product_price !== undefined) {
|
|
546
563
|
return String(metadata.source_product_price);
|
|
547
564
|
}
|
|
@@ -559,7 +576,7 @@ export function normalizeOrderProduct(product) {
|
|
|
559
576
|
if (!isV2 && metadata.main_product_original_price !== undefined) {
|
|
560
577
|
return String(metadata.main_product_original_price);
|
|
561
578
|
}
|
|
562
|
-
return (
|
|
579
|
+
return (_ref9 = (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product.selling_price) !== null && _ref9 !== void 0 ? _ref9 : '0.00';
|
|
563
580
|
}();
|
|
564
581
|
|
|
565
582
|
// 2) 派生 main_product_original_price(含 option、不含折扣)
|
|
@@ -2295,7 +2295,8 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2295
2295
|
key: "getOrderProducts",
|
|
2296
2296
|
value: function getOrderProducts() {
|
|
2297
2297
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2298
|
-
|
|
2298
|
+
var products = this.store.order.getOrderProducts();
|
|
2299
|
+
return products;
|
|
2299
2300
|
}
|
|
2300
2301
|
}, {
|
|
2301
2302
|
key: "getSummary",
|
|
@@ -64,11 +64,14 @@ function mapOrderBundleToOtherBundle(bundle) {
|
|
|
64
64
|
const catalogOriginal = item.original_price ?? item.product_price ?? item.price ?? item.bundle_selling_price;
|
|
65
65
|
const selling = item.bundle_selling_price ?? item.price ?? catalogOriginal;
|
|
66
66
|
const { bundle_selling_price: _omitBundleSelling, ...rest } = item;
|
|
67
|
+
const isMarkupOrMarkdown = (item.price_type === "markdown" || item.price_type === "markup") && (item.price_type_ext === "" || item.price_type_ext === void 0 || item.price_type_ext === null);
|
|
68
|
+
if (isMarkupOrMarkdown)
|
|
69
|
+
delete rest.original_total;
|
|
67
70
|
return {
|
|
68
71
|
...rest,
|
|
69
72
|
price: selling,
|
|
70
73
|
original_price: catalogOriginal,
|
|
71
|
-
original_total: item.original_total ?? catalogOriginal,
|
|
74
|
+
...isMarkupOrMarkdown ? {} : { original_total: item.original_total ?? catalogOriginal },
|
|
72
75
|
num: item.num ?? item.quantity ?? 1,
|
|
73
76
|
quantity: item.quantity ?? item.num ?? 1
|
|
74
77
|
};
|
|
@@ -46,6 +46,7 @@ var import_decimal = __toESM(require("decimal.js"));
|
|
|
46
46
|
var import_utils = require("../../Product/utils");
|
|
47
47
|
var import_utils2 = require("../../../solution/ShopDiscount/utils");
|
|
48
48
|
var import_utils3 = require("../../Summary/utils");
|
|
49
|
+
var import_utils4 = require("../../Order/utils");
|
|
49
50
|
var toDiscountPayload = (discountItem) => {
|
|
50
51
|
var _a, _b;
|
|
51
52
|
return {
|
|
@@ -337,6 +338,15 @@ var formatBundleToOrigin = (bundle) => {
|
|
|
337
338
|
var _a;
|
|
338
339
|
return pre + (((_a = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a.product_discount_difference) || 0);
|
|
339
340
|
}, 0);
|
|
341
|
+
const normalizedBundle = {
|
|
342
|
+
...d,
|
|
343
|
+
// 计算 markdown 净额时只传真实毛价;若仅有 bundle_selling_price,则由 helper 当历史净额兜底。
|
|
344
|
+
price: (d == null ? void 0 : d.price) ?? (d == null ? void 0 : d.custom_price),
|
|
345
|
+
bundle_selling_price: d == null ? void 0 : d.bundle_selling_price,
|
|
346
|
+
price_type: (d == null ? void 0 : d.price_type) ?? (d == null ? void 0 : d.custom_price_type),
|
|
347
|
+
price_type_ext: (d == null ? void 0 : d.price_type_ext) ?? (d == null ? void 0 : d.custom_price_type_ext),
|
|
348
|
+
option: getBundleValueByKey("option")
|
|
349
|
+
};
|
|
340
350
|
return {
|
|
341
351
|
bundle_group_id: getBundleValueByKey("group_id"),
|
|
342
352
|
bundle_id: d.id,
|
|
@@ -347,7 +357,7 @@ var formatBundleToOrigin = (bundle) => {
|
|
|
347
357
|
extension_type: getBundleValueByKey("extension_type"),
|
|
348
358
|
option: formatOptionsToOrigin(getBundleValueByKey("option")),
|
|
349
359
|
discount_list: d.discount_list,
|
|
350
|
-
"bundle_selling_price":
|
|
360
|
+
"bundle_selling_price": (0, import_utils4.getBundleSellingMagnitude)(normalizedBundle).toFixed(2),
|
|
351
361
|
"custom_price": d == null ? void 0 : d.price,
|
|
352
362
|
metadata: {
|
|
353
363
|
custom_product_bundle_map_id: d._id,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all)
|
|
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
14
|
}
|
|
17
15
|
return to;
|
|
18
16
|
};
|
|
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
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
18
|
|
|
29
19
|
// src/modules/Cart/utils/changePrice.ts
|
|
@@ -32,7 +22,7 @@ __export(changePrice_exports, {
|
|
|
32
22
|
updateAllCartItemPrice: () => updateAllCartItemPrice
|
|
33
23
|
});
|
|
34
24
|
module.exports = __toCommonJS(changePrice_exports);
|
|
35
|
-
var
|
|
25
|
+
var import_utils = require("../../Order/utils");
|
|
36
26
|
async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart, updateItemInitInfo) {
|
|
37
27
|
var _a, _b;
|
|
38
28
|
for (const item of cartItems) {
|
|
@@ -57,18 +47,20 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
|
|
|
57
47
|
const targetBundleItem = targetBundle.bundle_item.find(
|
|
58
48
|
(m) => m.id === n.id
|
|
59
49
|
);
|
|
60
|
-
if (targetBundleItem.price_type === "markdown") {
|
|
61
|
-
targetBundleItem.price = new import_decimal.default(targetBundleItem.price || 0).mul(-1).toNumber();
|
|
62
|
-
}
|
|
63
|
-
if (n.option) {
|
|
64
|
-
targetBundleItem.price = new import_decimal.default(targetBundleItem.price || 0).add(n.option.reduce((pre, cur) => {
|
|
65
|
-
return pre + new import_decimal.default(cur.price || 0).mul(cur.num || 1).toNumber();
|
|
66
|
-
}, 0)).toNumber();
|
|
67
|
-
}
|
|
68
50
|
if (targetBundleItem) {
|
|
69
|
-
|
|
51
|
+
const normalizedBundle = {
|
|
70
52
|
...n,
|
|
71
53
|
price: targetBundleItem.price,
|
|
54
|
+
custom_price: targetBundleItem.price,
|
|
55
|
+
price_type: targetBundleItem.price_type,
|
|
56
|
+
price_type_ext: targetBundleItem.price_type_ext
|
|
57
|
+
};
|
|
58
|
+
const bundleSellingPrice = (0, import_utils.getBundleSellingMagnitude)(normalizedBundle).toFixed(2);
|
|
59
|
+
return {
|
|
60
|
+
...n,
|
|
61
|
+
custom_price: targetBundleItem.price,
|
|
62
|
+
price: targetBundleItem.price_type === "markdown" ? bundleSellingPrice : targetBundleItem.price,
|
|
63
|
+
bundle_selling_price: bundleSellingPrice,
|
|
72
64
|
base_price: targetBundleItem.base_price
|
|
73
65
|
};
|
|
74
66
|
}
|
|
@@ -891,6 +891,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
891
891
|
"surcharge_rounding_remainder",
|
|
892
892
|
"tax_fee_rounding_remainder"
|
|
893
893
|
];
|
|
894
|
+
const metadataMoneyKeys = [
|
|
895
|
+
"main_product_attached_bundle_selling_price",
|
|
896
|
+
"main_product_attached_bundle_payment_price"
|
|
897
|
+
];
|
|
894
898
|
for (const product of products || []) {
|
|
895
899
|
const productRecord = product;
|
|
896
900
|
const metadata = productRecord.metadata && typeof productRecord.metadata === "object" ? { ...productRecord.metadata } : {};
|
|
@@ -902,10 +906,26 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
902
906
|
metadata[key] = value;
|
|
903
907
|
hasMetadataPatch = true;
|
|
904
908
|
}
|
|
909
|
+
for (const key of metadataMoneyKeys) {
|
|
910
|
+
const value = this.formatSummaryMetadataMoney(metadata[key]);
|
|
911
|
+
if (value === void 0)
|
|
912
|
+
continue;
|
|
913
|
+
metadata[key] = value;
|
|
914
|
+
hasMetadataPatch = true;
|
|
915
|
+
}
|
|
916
|
+
if (metadata.average_discount_amount_rate !== void 0) {
|
|
917
|
+
hasMetadataPatch = true;
|
|
918
|
+
}
|
|
905
919
|
if (Array.isArray(productRecord.relation_surcharge_ids)) {
|
|
906
920
|
metadata.relation_surcharge_ids = productRecord.relation_surcharge_ids;
|
|
907
921
|
hasMetadataPatch = true;
|
|
908
922
|
}
|
|
923
|
+
const productPaymentPrice = this.formatSummaryMetadataMoney(
|
|
924
|
+
productRecord.payment_price
|
|
925
|
+
);
|
|
926
|
+
if (productPaymentPrice !== void 0) {
|
|
927
|
+
productRecord.payment_price = productPaymentPrice;
|
|
928
|
+
}
|
|
909
929
|
if (hasMetadataPatch)
|
|
910
930
|
productRecord.metadata = metadata;
|
|
911
931
|
if (!Array.isArray(productRecord.product_bundle))
|
|
@@ -921,6 +941,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
921
941
|
bundleMetadata.surcharge_fee = bundleSurchargeFee;
|
|
922
942
|
hasBundleMetadataPatch = true;
|
|
923
943
|
}
|
|
944
|
+
const bundlePaymentPrice = this.formatSummaryMetadataMoney(
|
|
945
|
+
bundleRecord.bundle_payment_price
|
|
946
|
+
);
|
|
947
|
+
if (bundlePaymentPrice !== void 0) {
|
|
948
|
+
bundleRecord.bundle_payment_price = bundlePaymentPrice;
|
|
949
|
+
}
|
|
924
950
|
if (Array.isArray(bundleRecord.relation_surcharge_ids)) {
|
|
925
951
|
bundleMetadata.relation_surcharge_ids = bundleRecord.relation_surcharge_ids;
|
|
926
952
|
hasBundleMetadataPatch = true;
|
|
@@ -1843,21 +1869,41 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1843
1869
|
*/
|
|
1844
1870
|
updateVoucherOrderPayments(payments) {
|
|
1845
1871
|
const tempOrder = this.ensureTempOrder();
|
|
1872
|
+
const isVoucherPayment = (payment) => {
|
|
1873
|
+
return payment.voucher_id !== void 0 && Number(payment.voucher_id) !== 0;
|
|
1874
|
+
};
|
|
1875
|
+
const hasSyncedOrderPayment = (payment) => {
|
|
1876
|
+
return payment.order_payment_id !== void 0 && payment.order_payment_id !== null;
|
|
1877
|
+
};
|
|
1846
1878
|
const mappedVouchers = (0, import_utils.mapPaymentItemsToOrderPayments)(
|
|
1847
1879
|
payments.map(
|
|
1848
1880
|
(payment) => this.normalizePaymentSource(payment, { defaultPaid: true })
|
|
1849
1881
|
)
|
|
1850
1882
|
).filter((payment) => {
|
|
1851
|
-
return
|
|
1883
|
+
return isVoucherPayment(payment);
|
|
1852
1884
|
});
|
|
1853
1885
|
const nonVoucherPayments = (tempOrder.payments || []).filter((payment) => {
|
|
1854
|
-
return
|
|
1886
|
+
return !isVoucherPayment(payment);
|
|
1887
|
+
});
|
|
1888
|
+
const syncedVoucherPayments = (tempOrder.payments || []).filter((payment) => {
|
|
1889
|
+
return isVoucherPayment(payment) && hasSyncedOrderPayment(payment);
|
|
1890
|
+
});
|
|
1891
|
+
const syncedVoucherPaymentIds = new Set(
|
|
1892
|
+
syncedVoucherPayments.map((payment) => String(payment.order_payment_id))
|
|
1893
|
+
);
|
|
1894
|
+
const replaceableVouchers = mappedVouchers.filter((payment) => {
|
|
1895
|
+
if (!hasSyncedOrderPayment(payment))
|
|
1896
|
+
return true;
|
|
1897
|
+
return !syncedVoucherPaymentIds.has(String(payment.order_payment_id));
|
|
1855
1898
|
});
|
|
1856
1899
|
const cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
|
|
1857
|
-
vouchers:
|
|
1858
|
-
nonVoucherPayments
|
|
1900
|
+
vouchers: replaceableVouchers,
|
|
1901
|
+
nonVoucherPayments: [
|
|
1902
|
+
...nonVoucherPayments,
|
|
1903
|
+
...syncedVoucherPayments
|
|
1904
|
+
]
|
|
1859
1905
|
});
|
|
1860
|
-
tempOrder.payments = [...nonVoucherPayments, ...cappedVouchers];
|
|
1906
|
+
tempOrder.payments = [...nonVoucherPayments, ...syncedVoucherPayments, ...cappedVouchers];
|
|
1861
1907
|
this.updateTempOrderPaymentStatus(tempOrder);
|
|
1862
1908
|
this.persistTempOrder();
|
|
1863
1909
|
void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
|
|
@@ -2824,8 +2870,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2824
2870
|
var _a, _b;
|
|
2825
2871
|
const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
|
|
2826
2872
|
const nextTempOrder = this.normalizeTempOrderForRuntime(raw);
|
|
2873
|
+
const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
|
|
2874
|
+
const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
|
|
2827
2875
|
this.store.tempOrder = nextTempOrder;
|
|
2828
|
-
this.store.summary =
|
|
2876
|
+
this.store.summary = {
|
|
2877
|
+
...(0, import_utils.createEmptySummary)(),
|
|
2878
|
+
...rawSummary,
|
|
2879
|
+
surcharges: summarySurcharges
|
|
2880
|
+
};
|
|
2829
2881
|
nextTempOrder._extend = {
|
|
2830
2882
|
...nextTempOrder._extend || {},
|
|
2831
2883
|
originalSalesSnapshot: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
|
-
import { CartItem } from "../Cart";
|
|
2
|
+
import type { CartItem } from "../Cart";
|
|
3
3
|
import type { OrderProductDiscountItem, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder } from './types';
|
|
4
4
|
import type { RulesParamsHooks } from '../Rules/types';
|
|
5
5
|
import type { MapOrderPaymentsOptions, OrderPaymentData, OrderPaymentSource } from './types';
|
|
@@ -21,10 +21,20 @@ export declare function composeLinePrice(params: {
|
|
|
21
21
|
bundle?: Array<{
|
|
22
22
|
bundle_selling_price?: any;
|
|
23
23
|
price?: any;
|
|
24
|
+
custom_price?: any;
|
|
24
25
|
num?: any;
|
|
25
26
|
quantity?: any;
|
|
26
27
|
original_price?: any;
|
|
27
28
|
product_price?: any;
|
|
29
|
+
price_type?: any;
|
|
30
|
+
price_type_ext?: any;
|
|
31
|
+
custom_price_type?: any;
|
|
32
|
+
custom_price_type_ext?: any;
|
|
33
|
+
option?: Array<{
|
|
34
|
+
add_price?: any;
|
|
35
|
+
price?: any;
|
|
36
|
+
num?: any;
|
|
37
|
+
}>;
|
|
28
38
|
}> | null;
|
|
29
39
|
useOriginalBundle?: boolean;
|
|
30
40
|
}): string;
|
|
@@ -43,6 +53,27 @@ export declare function sumOptionUnitPrice(options?: Array<{
|
|
|
43
53
|
price?: any;
|
|
44
54
|
num?: any;
|
|
45
55
|
}> | null): Decimal;
|
|
56
|
+
/**
|
|
57
|
+
* 判定套餐子商品是否为 markdown(减价)类型。
|
|
58
|
+
* 与后端口径一致:price_type='markdown' 且 price_type_ext 非 'product_price'(原价子商品)。
|
|
59
|
+
*/
|
|
60
|
+
export declare function isMarkdownBundle(bundle: Record<string, any> | null | undefined): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* 套餐子商品对「行价」的带符号单位贡献(与后端 markdown 口径对齐)。
|
|
63
|
+
*
|
|
64
|
+
* - markdown(减价):净额 = |catalog 毛价| − Σ(option.add_price×num),**取负**(行内减)。
|
|
65
|
+
* catalog 毛价优先 `price`/`custom_price`(避免读已落净额的 `bundle_selling_price` 造成 option 二次扣减);
|
|
66
|
+
* 仅当毛价缺失(历史/hydrate 仅剩净额)时退回 `bundle_selling_price`,且此时不再扣 option。
|
|
67
|
+
* - markup(加价)/原价子商品:维持 `+(bundle_selling_price ?? price)`,行为不变。
|
|
68
|
+
*/
|
|
69
|
+
export declare function getBundleSignedUnit(bundle: Record<string, any> | null | undefined, options?: {
|
|
70
|
+
useOriginal?: boolean;
|
|
71
|
+
}): Decimal;
|
|
72
|
+
/**
|
|
73
|
+
* 套餐子商品 `bundle_selling_price` 的存储净额(正值幅度)。
|
|
74
|
+
* markdown 取净额绝对值(3.70);markup/原价维持原值。
|
|
75
|
+
*/
|
|
76
|
+
export declare function getBundleSellingMagnitude(bundle: Record<string, any> | null | undefined): Decimal;
|
|
46
77
|
/**
|
|
47
78
|
* OrderModule 默认 Rules 钩子工厂。
|
|
48
79
|
*
|
|
@@ -55,7 +86,7 @@ export declare function sumOptionUnitPrice(options?: Array<{
|
|
|
55
86
|
* 不含折扣。**权威源**。
|
|
56
87
|
* - `metadata.main_product_original_price` = source + Σ(option.price × option.num)(含 option、不含折扣)。
|
|
57
88
|
* - `metadata.main_product_selling_price` = main_original − 主商品券 per-unit amount(含 option、含折扣)。
|
|
58
|
-
* - `payment_price`:出站 payload
|
|
89
|
+
* - `payment_price`:出站 payload 中为行 composite 已减整单折扣均摊价(无折扣时与 `selling_price` 同义)。
|
|
59
90
|
*
|
|
60
91
|
* Rules 钩子契约(hook_adapt 方案,Rules 内部保持不变):
|
|
61
92
|
* - `getProduct.price` / `getProduct.original_price` 回传 **source-level 主价**
|
|
@@ -44,11 +44,14 @@ __export(utils_exports, {
|
|
|
44
44
|
formatV1Product: () => formatV1Product,
|
|
45
45
|
generateDuration: () => generateDuration,
|
|
46
46
|
getAllDiscountList: () => getAllDiscountList,
|
|
47
|
+
getBundleSellingMagnitude: () => getBundleSellingMagnitude,
|
|
48
|
+
getBundleSignedUnit: () => getBundleSignedUnit,
|
|
47
49
|
getOrderProductLineUid: () => getOrderProductLineUid,
|
|
48
50
|
getProductSkuOptions: () => getProductSkuOptions,
|
|
49
51
|
hasAssignedHolderId: () => hasAssignedHolderId,
|
|
50
52
|
indexOrderProductsByUid: () => indexOrderProductsByUid,
|
|
51
53
|
isEmptyOrderProductDisplayValue: () => isEmptyOrderProductDisplayValue,
|
|
54
|
+
isMarkdownBundle: () => isMarkdownBundle,
|
|
52
55
|
isTempOrder: () => isTempOrder,
|
|
53
56
|
mapPaymentItemToOrderPayment: () => mapPaymentItemToOrderPayment,
|
|
54
57
|
mapPaymentItemsToOrderPayments: () => mapPaymentItemsToOrderPayments,
|
|
@@ -85,11 +88,10 @@ function composeLinePrice(params) {
|
|
|
85
88
|
let total = new import_decimal.default(Number(mainPrice) || 0);
|
|
86
89
|
if (Array.isArray(bundle)) {
|
|
87
90
|
for (const item of bundle) {
|
|
88
|
-
const
|
|
89
|
-
const price = new import_decimal.default(Number(rawPrice) || 0);
|
|
91
|
+
const signedUnit = getBundleSignedUnit(item, { useOriginal: useOriginalBundle });
|
|
90
92
|
const rawNum = (item == null ? void 0 : item.num) ?? (item == null ? void 0 : item.quantity) ?? 1;
|
|
91
93
|
const num = new import_decimal.default(Number(rawNum) || 0);
|
|
92
|
-
total = total.plus(
|
|
94
|
+
total = total.plus(signedUnit.times(num));
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
return total.toDecimalPlaces(2).toFixed(2);
|
|
@@ -129,6 +131,33 @@ function sumOptionUnitPrice(options) {
|
|
|
129
131
|
}
|
|
130
132
|
return total;
|
|
131
133
|
}
|
|
134
|
+
function isMarkdownBundle(bundle) {
|
|
135
|
+
if (!bundle || typeof bundle !== "object")
|
|
136
|
+
return false;
|
|
137
|
+
const ext = bundle.price_type_ext ?? bundle.custom_price_type_ext;
|
|
138
|
+
const type = bundle.price_type ?? bundle.custom_price_type;
|
|
139
|
+
return type === "markdown" && ext !== "product_price";
|
|
140
|
+
}
|
|
141
|
+
function getBundleSignedUnit(bundle, options) {
|
|
142
|
+
if (!bundle || typeof bundle !== "object")
|
|
143
|
+
return new import_decimal.default(0);
|
|
144
|
+
const useOriginal = (options == null ? void 0 : options.useOriginal) ?? false;
|
|
145
|
+
if (isMarkdownBundle(bundle)) {
|
|
146
|
+
const catalog = useOriginal ? bundle.original_price ?? bundle.product_price ?? bundle.custom_price ?? bundle.base_price ?? bundle.price : bundle.custom_price ?? bundle.product_price ?? bundle.original_price ?? bundle.base_price ?? bundle.price;
|
|
147
|
+
if (catalog !== void 0 && catalog !== null && catalog !== "") {
|
|
148
|
+
const raw = new import_decimal.default(Number(catalog) || 0);
|
|
149
|
+
if (raw.lt(0))
|
|
150
|
+
return raw;
|
|
151
|
+
return raw.minus(sumOptionUnitPrice(bundle.option)).negated();
|
|
152
|
+
}
|
|
153
|
+
return new import_decimal.default(Number(bundle.bundle_selling_price) || 0).abs().negated();
|
|
154
|
+
}
|
|
155
|
+
const rawPrice = useOriginal ? bundle.original_price ?? bundle.product_price ?? bundle.price : bundle.bundle_selling_price ?? bundle.price;
|
|
156
|
+
return new import_decimal.default(Number(rawPrice) || 0);
|
|
157
|
+
}
|
|
158
|
+
function getBundleSellingMagnitude(bundle) {
|
|
159
|
+
return getBundleSignedUnit(bundle).abs();
|
|
160
|
+
}
|
|
132
161
|
function resolveRulesManualDiscountFlag(metadata) {
|
|
133
162
|
if (!metadata)
|
|
134
163
|
return void 0;
|
|
@@ -472,9 +501,8 @@ function formatSubmitBundleItems(bundle) {
|
|
|
472
501
|
return bundle.map((b) => {
|
|
473
502
|
const rawBundle = b && typeof b === "object" ? b : {};
|
|
474
503
|
const existedMetadata = rawBundle.metadata && typeof rawBundle.metadata === "object" ? rawBundle.metadata : {};
|
|
475
|
-
const sellingPrice =
|
|
476
|
-
|
|
477
|
-
);
|
|
504
|
+
const sellingPrice = getBundleSellingMagnitude(rawBundle).toFixed(2);
|
|
505
|
+
const paymentPrice = rawBundle.bundle_payment_price !== void 0 && rawBundle.bundle_payment_price !== null && rawBundle.bundle_payment_price !== "" ? toMoneyString(rawBundle.bundle_payment_price) : sellingPrice;
|
|
478
506
|
const priceValue = rawBundle.price ?? rawBundle.custom_price ?? rawBundle.bundle_selling_price;
|
|
479
507
|
const relationSurchargeIds = Array.isArray(rawBundle.relation_surcharge_ids) ? rawBundle.relation_surcharge_ids : Array.isArray(existedMetadata.relation_surcharge_ids) ? existedMetadata.relation_surcharge_ids : [];
|
|
480
508
|
const surchargeFee = toMoneyString(
|
|
@@ -496,6 +524,7 @@ function formatSubmitBundleItems(bundle) {
|
|
|
496
524
|
price_type: rawBundle.price_type ?? rawBundle.custom_price_type ?? "",
|
|
497
525
|
price_type_ext: rawBundle.price_type_ext ?? rawBundle.custom_price_type_ext ?? "",
|
|
498
526
|
bundle_selling_price: sellingPrice,
|
|
527
|
+
bundle_payment_price: paymentPrice,
|
|
499
528
|
option: formatSubmitOptionItems(rawBundle.option),
|
|
500
529
|
bundle_group_id: (rawBundle == null ? void 0 : rawBundle.bundle_group_id) ?? (rawBundle == null ? void 0 : rawBundle.group_id),
|
|
501
530
|
bundle_id: (rawBundle == null ? void 0 : rawBundle.bundle_id) ?? (rawBundle == null ? void 0 : rawBundle.id),
|
|
@@ -532,6 +561,9 @@ function normalizeSubmitProduct(product) {
|
|
|
532
561
|
const priceMetaKeys = [
|
|
533
562
|
"main_product_original_price",
|
|
534
563
|
"main_product_selling_price",
|
|
564
|
+
"main_product_attached_bundle_selling_price",
|
|
565
|
+
"main_product_attached_bundle_payment_price",
|
|
566
|
+
"average_discount_amount_rate",
|
|
535
567
|
"source_product_price",
|
|
536
568
|
"main_product_attached_bundle_surcharge_fee",
|
|
537
569
|
"main_product_attached_bundle_tax_fee",
|
|
@@ -566,9 +598,9 @@ function normalizeSubmitProduct(product) {
|
|
|
566
598
|
discount_list: normalizeOrderProductDiscountList(submitProduct.discount_list),
|
|
567
599
|
product_bundle: formatSubmitBundleItems(submitProduct.product_bundle),
|
|
568
600
|
metadata: cleanMetadata,
|
|
569
|
-
// 出站兼容:后端消费 payment_price
|
|
570
|
-
//
|
|
571
|
-
payment_price: submitProduct.selling_price
|
|
601
|
+
// 出站兼容:后端消费 payment_price 字段(行 composite 已减整单折扣均摊)。
|
|
602
|
+
// 由整单折扣均摊层产出;缺省(无折扣)时与 selling_price 同义。
|
|
603
|
+
payment_price: submitProduct.payment_price ?? submitProduct.selling_price
|
|
572
604
|
};
|
|
573
605
|
}
|
|
574
606
|
var SUBMIT_BOOKING_METADATA_WHITELIST = [
|
|
@@ -953,11 +985,14 @@ function indexOrderProductsByUid(products) {
|
|
|
953
985
|
formatV1Product,
|
|
954
986
|
generateDuration,
|
|
955
987
|
getAllDiscountList,
|
|
988
|
+
getBundleSellingMagnitude,
|
|
989
|
+
getBundleSignedUnit,
|
|
956
990
|
getOrderProductLineUid,
|
|
957
991
|
getProductSkuOptions,
|
|
958
992
|
hasAssignedHolderId,
|
|
959
993
|
indexOrderProductsByUid,
|
|
960
994
|
isEmptyOrderProductDisplayValue,
|
|
995
|
+
isMarkdownBundle,
|
|
961
996
|
isTempOrder,
|
|
962
997
|
mapPaymentItemToOrderPayment,
|
|
963
998
|
mapPaymentItemsToOrderPayments,
|