@pisell/pisellos 2.2.187 → 2.2.189
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/buildCacheItemFromOrderLine.js +11 -4
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +11 -4
- package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
- package/dist/modules/Order/index.d.ts +5 -0
- package/dist/modules/Order/index.js +174 -70
- package/dist/modules/Order/types.d.ts +1 -0
- package/dist/modules/Order/utils.js +3 -1
- package/dist/modules/Rules/index.js +32 -21
- package/dist/solution/BaseSales/utils/cartPromotion.js +31 -11
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +15 -0
- package/dist/solution/BookingTicket/index.js +135 -10
- package/dist/solution/BookingTicket/types.d.ts +48 -0
- package/dist/solution/BookingTicket/types.js +5 -1
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +394 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -1
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +4 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
- package/lib/modules/Order/index.d.ts +5 -0
- package/lib/modules/Order/index.js +99 -14
- package/lib/modules/Order/types.d.ts +1 -0
- package/lib/modules/Order/utils.js +1 -0
- package/lib/modules/Rules/index.js +88 -78
- package/lib/solution/BaseSales/utils/cartPromotion.js +22 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +15 -0
- package/lib/solution/BookingTicket/index.js +75 -2
- package/lib/solution/BookingTicket/types.d.ts +48 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +166 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
- package/package.json +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
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; }
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
/**
|
|
11
|
+
* 扫码商品条码预选规格纯函数(对齐 ticketBooking addServiceVariant/utils)。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** 套餐商品 */
|
|
15
|
+
export function isScanProductBundle(item) {
|
|
16
|
+
return ((item === null || item === void 0 ? void 0 : item.bundle_group_count) || 0) > 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** 单规格 / 选项组商品 */
|
|
20
|
+
export function isScanProductOption(item) {
|
|
21
|
+
var _item$option_group;
|
|
22
|
+
return ((item === null || item === void 0 ? void 0 : item.option_group_count) || 0) > 0 || ((item === null || item === void 0 || (_item$option_group = item.option_group) === null || _item$option_group === void 0 ? void 0 : _item$option_group.length) || 0) > 0;
|
|
23
|
+
}
|
|
24
|
+
function formatVariantGroupTitle(title) {
|
|
25
|
+
var variantGroup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
26
|
+
try {
|
|
27
|
+
return variantGroup.map(function (group) {
|
|
28
|
+
var value = title === null || title === void 0 ? void 0 : title[group === null || group === void 0 ? void 0 : group.position_id];
|
|
29
|
+
return value ? "".concat((group === null || group === void 0 ? void 0 : group.name) || '-', ": ").concat(value) : '';
|
|
30
|
+
}).filter(Boolean).join(', ');
|
|
31
|
+
} catch (_unused) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function formatDataKey(data) {
|
|
36
|
+
var _next$option, _next$bundle;
|
|
37
|
+
var next = _objectSpread({}, data);
|
|
38
|
+
var key = "".concat(next.product_id);
|
|
39
|
+
var rowKey = key;
|
|
40
|
+
if (next.product_variant_id) {
|
|
41
|
+
var str = "_".concat(next.product_variant_id);
|
|
42
|
+
key += str;
|
|
43
|
+
rowKey += str;
|
|
44
|
+
}
|
|
45
|
+
if (next !== null && next !== void 0 && (_next$option = next.option) !== null && _next$option !== void 0 && _next$option.length) {
|
|
46
|
+
var _iterator = _createForOfIteratorHelper(next.option),
|
|
47
|
+
_step;
|
|
48
|
+
try {
|
|
49
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
50
|
+
var item = _step.value;
|
|
51
|
+
var _str = "_".concat(item.option_group_id, "_").concat(item.product_option_item_id);
|
|
52
|
+
key += _str;
|
|
53
|
+
rowKey += "".concat(_str, "_").concat(item.quantity || item.num);
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
_iterator.e(err);
|
|
57
|
+
} finally {
|
|
58
|
+
_iterator.f();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (next !== null && next !== void 0 && (_next$bundle = next.bundle) !== null && _next$bundle !== void 0 && _next$bundle.length) {
|
|
62
|
+
var _iterator2 = _createForOfIteratorHelper(next.bundle),
|
|
63
|
+
_step2;
|
|
64
|
+
try {
|
|
65
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
66
|
+
var _item = _step2.value;
|
|
67
|
+
var _str2 = "_".concat(_item.group_id, "_").concat(_item.bundle_product_id);
|
|
68
|
+
key += _str2;
|
|
69
|
+
rowKey += "".concat(_str2, "_").concat(_item.quantity || _item.num);
|
|
70
|
+
if (_item !== null && _item !== void 0 && _item.option) {
|
|
71
|
+
var _iterator3 = _createForOfIteratorHelper(_item.option),
|
|
72
|
+
_step3;
|
|
73
|
+
try {
|
|
74
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
75
|
+
var opt = _step3.value;
|
|
76
|
+
var optStr = "_".concat(opt.option_group_id, "_").concat(opt.product_option_item_id);
|
|
77
|
+
key += optStr;
|
|
78
|
+
rowKey += "".concat(optStr, "_").concat(opt.quantity || opt.num);
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
_iterator3.e(err);
|
|
82
|
+
} finally {
|
|
83
|
+
_iterator3.f();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch (err) {
|
|
88
|
+
_iterator2.e(err);
|
|
89
|
+
} finally {
|
|
90
|
+
_iterator2.f();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (next !== null && next !== void 0 && next.session) {
|
|
94
|
+
var _next$session;
|
|
95
|
+
var _str3 = "_".concat((_next$session = next.session) === null || _next$session === void 0 ? void 0 : _next$session.key);
|
|
96
|
+
key += _str3;
|
|
97
|
+
rowKey += _str3;
|
|
98
|
+
}
|
|
99
|
+
if (next !== null && next !== void 0 && next.schedule) {
|
|
100
|
+
var _next$schedule;
|
|
101
|
+
var _str4 = "_".concat((_next$schedule = next.schedule) === null || _next$schedule === void 0 ? void 0 : _next$schedule.key);
|
|
102
|
+
key += _str4;
|
|
103
|
+
rowKey += _str4;
|
|
104
|
+
}
|
|
105
|
+
next.key = key;
|
|
106
|
+
next.rowKey = rowKey;
|
|
107
|
+
return next;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 根据条码匹配 variant,生成 cartDetailValue(对齐 ticketBooking `genValues`)。
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const values = genScanProductValues(catalogItem, '6901234567890');
|
|
116
|
+
* const itemWithSelection = { ...catalogItem, cartDetailValue: values };
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export function genScanProductValues(item, code) {
|
|
120
|
+
var _item$variant_group, _item$option_group2;
|
|
121
|
+
var params = {
|
|
122
|
+
bundle: [],
|
|
123
|
+
option: [],
|
|
124
|
+
product_id: item.id,
|
|
125
|
+
product_variant_id: 0,
|
|
126
|
+
quantity: 1,
|
|
127
|
+
rowKey: '',
|
|
128
|
+
session: null
|
|
129
|
+
};
|
|
130
|
+
if (item !== null && item !== void 0 && (_item$variant_group = item.variant_group) !== null && _item$variant_group !== void 0 && _item$variant_group.length || item !== null && item !== void 0 && (_item$option_group2 = item.option_group) !== null && _item$option_group2 !== void 0 && _item$option_group2.length) {
|
|
131
|
+
var variantItem = (item.variant || []).find(function (v) {
|
|
132
|
+
return (v === null || v === void 0 ? void 0 : v.code) === code || (v === null || v === void 0 ? void 0 : v.barcode) === code;
|
|
133
|
+
});
|
|
134
|
+
if (variantItem) {
|
|
135
|
+
params.price = Number((variantItem === null || variantItem === void 0 ? void 0 : variantItem.price) || 0);
|
|
136
|
+
params.product_variant_id = variantItem.id;
|
|
137
|
+
params.product_option_string = formatVariantGroupTitle(variantItem === null || variantItem === void 0 ? void 0 : variantItem.title, (item === null || item === void 0 ? void 0 : item.variant_group) || []);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return formatDataKey(params);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 统计条码命中的 variant 数量(多命中时需弹窗选择)。
|
|
145
|
+
*/
|
|
146
|
+
export function countScanVariantMatches(item, code) {
|
|
147
|
+
return ((item === null || item === void 0 ? void 0 : item.variant) || []).filter(function (v) {
|
|
148
|
+
return (v === null || v === void 0 ? void 0 : v.code) === code || (v === null || v === void 0 ? void 0 : v.barcode) === code;
|
|
149
|
+
}).length;
|
|
150
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -34,6 +34,7 @@ __export(buildCacheItemFromOrderLine_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(buildCacheItemFromOrderLine_exports);
|
|
35
35
|
var import_dayjs = __toESM(require("dayjs"));
|
|
36
36
|
var import_manualProductDiscount = require("../../Order/utils/manualProductDiscount");
|
|
37
|
+
var import_orderLineDisplay = require("./orderLineDisplay");
|
|
37
38
|
function safeFormat(value, fmt) {
|
|
38
39
|
if (value === void 0 || value === null)
|
|
39
40
|
return void 0;
|
|
@@ -178,6 +179,7 @@ function buildCacheItemFromOrderLine(input) {
|
|
|
178
179
|
const capacity = resolveCapacityFromBooking(booking);
|
|
179
180
|
const holderId = ((_a = booking.metadata) == null ? void 0 : _a.holder_id) ?? booking.holder_id;
|
|
180
181
|
const productTitle = resolveProductTitle(product, booking, sourceProduct);
|
|
182
|
+
const productOptionString = (0, import_orderLineDisplay.buildProductOptionStringFromOrderLine)(product);
|
|
181
183
|
const other = {
|
|
182
184
|
product_variant_id: product.product_variant_id ?? 0,
|
|
183
185
|
option: Array.isArray(product.product_option_item) ? [...product.product_option_item] : [],
|
|
@@ -206,7 +208,8 @@ function buildCacheItemFromOrderLine(input) {
|
|
|
206
208
|
discount_reason: (0, import_manualProductDiscount.resolveManualDiscountMessage)(
|
|
207
209
|
product.discount_list,
|
|
208
210
|
(_c = product.metadata) == null ? void 0 : _c.product_discount_reason
|
|
209
|
-
) || void 0
|
|
211
|
+
) || void 0,
|
|
212
|
+
...productOptionString ? { product_option_string: productOptionString } : {}
|
|
210
213
|
};
|
|
211
214
|
const manualDiscount = (product.discount_list || []).find((d) => (d == null ? void 0 : d.type) === "product");
|
|
212
215
|
if (manualDiscount && extend.origin_total === selling) {
|
|
@@ -233,6 +236,7 @@ function buildCacheItemFromOrderLine(input) {
|
|
|
233
236
|
price: (sourceProduct == null ? void 0 : sourceProduct.price) ?? selling,
|
|
234
237
|
selling_price: product.selling_price,
|
|
235
238
|
original_price: product.original_price,
|
|
239
|
+
...productOptionString ? { product_option_string: productOptionString } : {},
|
|
236
240
|
_extend: extend,
|
|
237
241
|
new: 0,
|
|
238
242
|
autoClose: false,
|
|
@@ -22,6 +22,7 @@ __export(buildNormalProductCacheItemFromOrderLine_exports, {
|
|
|
22
22
|
buildNormalProductCacheItemFromOrderLine: () => buildNormalProductCacheItemFromOrderLine
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(buildNormalProductCacheItemFromOrderLine_exports);
|
|
25
|
+
var import_orderLineDisplay = require("./orderLineDisplay");
|
|
25
26
|
function resolveSourceProductPrice(product, sourceProduct) {
|
|
26
27
|
var _a, _b, _c;
|
|
27
28
|
const metadata = product.metadata || {};
|
|
@@ -85,6 +86,7 @@ function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
85
86
|
Array.isArray(product.product_bundle) ? product.product_bundle : []
|
|
86
87
|
);
|
|
87
88
|
const originExtend = (_c = (_b = product.metadata) == null ? void 0 : _b.origin) == null ? void 0 : _c._extend;
|
|
89
|
+
const productOptionString = (0, import_orderLineDisplay.buildProductOptionStringFromOrderLine)(product);
|
|
88
90
|
const other = {
|
|
89
91
|
product_id: resolvedId,
|
|
90
92
|
product_variant_id: product.product_variant_id ?? 0,
|
|
@@ -110,6 +112,7 @@ function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
110
112
|
skuValue: JSON.parse(JSON.stringify(skuValue)),
|
|
111
113
|
_skuValue: JSON.parse(JSON.stringify(skuValue)),
|
|
112
114
|
isNormalProduct: true,
|
|
115
|
+
...productOptionString ? { product_option_string: productOptionString } : {},
|
|
113
116
|
...(originExtend == null ? void 0 : originExtend.priceOverride) !== void 0 ? { priceOverride: originExtend.priceOverride } : {},
|
|
114
117
|
...(originExtend == null ? void 0 : originExtend.bundle_edit) !== void 0 ? { bundle_edit: originExtend.bundle_edit } : {}
|
|
115
118
|
};
|
|
@@ -128,6 +131,7 @@ function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
128
131
|
price: (sourceProduct == null ? void 0 : sourceProduct.price) ?? sourcePrice,
|
|
129
132
|
selling_price: product.selling_price,
|
|
130
133
|
original_price: product.original_price,
|
|
134
|
+
...productOptionString ? { product_option_string: productOptionString } : {},
|
|
131
135
|
note: product.note,
|
|
132
136
|
order_detail_id: product.order_detail_id ?? null,
|
|
133
137
|
new: 0,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildProductOptionStringFromOrderLine(product: any): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/modules/BookingContext/utils/orderLineDisplay.ts
|
|
20
|
+
var orderLineDisplay_exports = {};
|
|
21
|
+
__export(orderLineDisplay_exports, {
|
|
22
|
+
buildProductOptionStringFromOrderLine: () => buildProductOptionStringFromOrderLine
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(orderLineDisplay_exports);
|
|
25
|
+
function pickDisplayText(value) {
|
|
26
|
+
if (value === void 0 || value === null)
|
|
27
|
+
return "";
|
|
28
|
+
if (typeof value === "string")
|
|
29
|
+
return value;
|
|
30
|
+
if (typeof value !== "object")
|
|
31
|
+
return String(value);
|
|
32
|
+
return value.auto || value.original || value.en || value["zh-CN"] || value["zh-HK"] || "";
|
|
33
|
+
}
|
|
34
|
+
function formatNamePair(group, item) {
|
|
35
|
+
const groupText = pickDisplayText(group);
|
|
36
|
+
const itemText = pickDisplayText(item);
|
|
37
|
+
if (groupText && itemText)
|
|
38
|
+
return `${groupText}:${itemText}`;
|
|
39
|
+
return groupText || itemText;
|
|
40
|
+
}
|
|
41
|
+
function buildProductOptionStringFromOrderLine(product) {
|
|
42
|
+
const segments = [];
|
|
43
|
+
const sku = (product == null ? void 0 : product.product_sku) || {};
|
|
44
|
+
if (Array.isArray(sku.variant)) {
|
|
45
|
+
for (const variant of sku.variant) {
|
|
46
|
+
const segment = formatNamePair(variant == null ? void 0 : variant.group, variant == null ? void 0 : variant.item);
|
|
47
|
+
if (segment)
|
|
48
|
+
segments.push(segment);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return segments.join(", ");
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
buildProductOptionStringFromOrderLine
|
|
56
|
+
});
|
|
@@ -143,6 +143,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
143
143
|
private saveDraftInBackground;
|
|
144
144
|
private hydrateTempOrderFromLocalRecord;
|
|
145
145
|
private extractOrderIdFromSubmitResult;
|
|
146
|
+
private calculatePaymentEffectiveAmount;
|
|
146
147
|
private calculatePaymentTotal;
|
|
147
148
|
private normalizePaymentSource;
|
|
148
149
|
private updateTempOrderPaymentStatus;
|
|
@@ -312,7 +313,11 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
312
313
|
recalcOnHydrate?: boolean;
|
|
313
314
|
}): Promise<OrderTempOrder>;
|
|
314
315
|
private normalizeTempOrderForRuntime;
|
|
316
|
+
private pickHydratedDisplayText;
|
|
317
|
+
private formatHydratedNamePair;
|
|
318
|
+
private buildHydratedProductOptionString;
|
|
315
319
|
private normalizeHydratedProductOptionItem;
|
|
320
|
+
private mergeHydratedProductOptionDisplayFields;
|
|
316
321
|
private resolveHydratedProductOptions;
|
|
317
322
|
private normalizeHydratedOrderProduct;
|
|
318
323
|
getLastOrderInfo(): Record<string, any> | undefined;
|
|
@@ -690,13 +690,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
690
690
|
var _a, _b;
|
|
691
691
|
return ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.order_id) ?? (result == null ? void 0 : result.order_id) ?? ((_b = result == null ? void 0 : result.data) == null ? void 0 : _b.id) ?? (result == null ? void 0 : result.id) ?? null;
|
|
692
692
|
}
|
|
693
|
+
calculatePaymentEffectiveAmount(payment) {
|
|
694
|
+
const amount = new import_decimal.default(payment.amount || 0).minus(new import_decimal.default(payment.service_fee || 0));
|
|
695
|
+
const rounding = new import_decimal.default(payment.rounding_amount || 0);
|
|
696
|
+
return amount.minus(rounding);
|
|
697
|
+
}
|
|
693
698
|
calculatePaymentTotal(payments) {
|
|
694
699
|
return (0, import_utils.mapPaymentItemsToOrderPayments)(payments, {
|
|
695
700
|
includeVoided: false
|
|
696
701
|
}).reduce((sum, payment) => {
|
|
697
|
-
|
|
698
|
-
const rounding = new import_decimal.default(payment.rounding_amount || 0);
|
|
699
|
-
return sum.plus(amount.minus(rounding));
|
|
702
|
+
return sum.plus(this.calculatePaymentEffectiveAmount(payment));
|
|
700
703
|
}, new import_decimal.default(0));
|
|
701
704
|
}
|
|
702
705
|
normalizePaymentSource(payment, options) {
|
|
@@ -739,12 +742,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
739
742
|
return {
|
|
740
743
|
customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
|
|
741
744
|
orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
|
|
745
|
+
gapPaidAmount: summary.gapPaidAmount.plus(this.calculatePaymentEffectiveAmount(paymentRecord)),
|
|
742
746
|
payServiceChargeAmount: summary.payServiceChargeAmount.plus(this.calculatePaymentServiceFee(paymentRecord))
|
|
743
747
|
};
|
|
744
748
|
},
|
|
745
749
|
{
|
|
746
750
|
customerPaidAmount: new import_decimal.default(0),
|
|
747
751
|
orderPaidAmount: new import_decimal.default(0),
|
|
752
|
+
gapPaidAmount: new import_decimal.default(0),
|
|
748
753
|
payServiceChargeAmount: new import_decimal.default(0)
|
|
749
754
|
}
|
|
750
755
|
);
|
|
@@ -1078,7 +1083,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1078
1083
|
amount_gap: this.calculateSummaryAmountGap({
|
|
1079
1084
|
tempOrder,
|
|
1080
1085
|
summary: (0, import_utils.createEmptySummary)(),
|
|
1081
|
-
orderPaidAmount: paidPaymentSummary.
|
|
1086
|
+
orderPaidAmount: paidPaymentSummary.gapPaidAmount
|
|
1082
1087
|
}),
|
|
1083
1088
|
pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
|
|
1084
1089
|
};
|
|
@@ -1100,7 +1105,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1100
1105
|
amount_gap: this.calculateSummaryAmountGap({
|
|
1101
1106
|
tempOrder,
|
|
1102
1107
|
summary: salesSummaryResult,
|
|
1103
|
-
orderPaidAmount: paidPaymentSummary.
|
|
1108
|
+
orderPaidAmount: paidPaymentSummary.gapPaidAmount
|
|
1104
1109
|
}),
|
|
1105
1110
|
pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
|
|
1106
1111
|
};
|
|
@@ -1564,7 +1569,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1564
1569
|
);
|
|
1565
1570
|
}
|
|
1566
1571
|
async updateOrderProduct(params) {
|
|
1567
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1572
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1568
1573
|
const {
|
|
1569
1574
|
product_id,
|
|
1570
1575
|
product_variant_id,
|
|
@@ -1624,7 +1629,20 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1624
1629
|
nextProduct.num = (0, import_utils3.getSafeProductNum)(nextProduct.num);
|
|
1625
1630
|
const callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, "selling_price") || Object.prototype.hasOwnProperty.call(updates || {}, "original_price");
|
|
1626
1631
|
const callerUpdatesMainMeta = ((_b = updates == null ? void 0 : updates.metadata) == null ? void 0 : _b.main_product_selling_price) !== void 0 || ((_c = updates == null ? void 0 : updates.metadata) == null ? void 0 : _c.main_product_original_price) !== void 0 || ((_d = updates == null ? void 0 : updates.metadata) == null ? void 0 : _d.source_product_price) !== void 0;
|
|
1627
|
-
|
|
1632
|
+
const isPersistedOrderLine = targetProduct.order_detail_id !== void 0 && targetProduct.order_detail_id !== null;
|
|
1633
|
+
const callerUpdatesManualPrice = ((_e = updates == null ? void 0 : updates.metadata) == null ? void 0 : _e.price_override) !== void 0 || ((_f = updates == null ? void 0 : updates.metadata) == null ? void 0 : _f.is_manual_discount) !== void 0 || ((_g = updates == null ? void 0 : updates.metadata) == null ? void 0 : _g.product_discount_reason) !== void 0 || Array.isArray(updates == null ? void 0 : updates.discount_list) && updates.discount_list.length > 0;
|
|
1634
|
+
if (isPersistedOrderLine && !callerUpdatesManualPrice) {
|
|
1635
|
+
nextProduct.selling_price = targetProduct.selling_price;
|
|
1636
|
+
nextProduct.original_price = targetProduct.original_price;
|
|
1637
|
+
nextProduct.payment_price = targetProduct.payment_price;
|
|
1638
|
+
nextProduct.metadata = {
|
|
1639
|
+
...nextProduct.metadata || {},
|
|
1640
|
+
source_product_price: (_h = targetProduct.metadata) == null ? void 0 : _h.source_product_price,
|
|
1641
|
+
main_product_selling_price: (_i = targetProduct.metadata) == null ? void 0 : _i.main_product_selling_price,
|
|
1642
|
+
main_product_original_price: (_j = targetProduct.metadata) == null ? void 0 : _j.main_product_original_price,
|
|
1643
|
+
price_schema_version: (_k = targetProduct.metadata) == null ? void 0 : _k.price_schema_version
|
|
1644
|
+
};
|
|
1645
|
+
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
1628
1646
|
const existedMeta = nextProduct.metadata || {};
|
|
1629
1647
|
nextProduct.metadata = { ...existedMeta };
|
|
1630
1648
|
delete nextProduct.metadata.source_product_price;
|
|
@@ -1639,7 +1657,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1639
1657
|
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1640
1658
|
normalizedProduct.discount_list
|
|
1641
1659
|
);
|
|
1642
|
-
const preservedBookingUid = nextProduct.booking_uid || ((
|
|
1660
|
+
const preservedBookingUid = nextProduct.booking_uid || ((_l = nextProduct.metadata) == null ? void 0 : _l.booking_uid) || targetProduct.booking_uid || ((_m = targetProduct.metadata) == null ? void 0 : _m.booking_uid);
|
|
1643
1661
|
if (!booking && preservedBookingUid) {
|
|
1644
1662
|
normalizedProduct.booking_uid = preservedBookingUid;
|
|
1645
1663
|
normalizedProduct.metadata = {
|
|
@@ -1649,7 +1667,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1649
1667
|
}
|
|
1650
1668
|
if (booking) {
|
|
1651
1669
|
const productUid = String(
|
|
1652
|
-
((
|
|
1670
|
+
((_n = normalizedProduct.metadata) == null ? void 0 : _n.unique_identification_number) || ((_o = targetProduct.metadata) == null ? void 0 : _o.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
|
|
1653
1671
|
);
|
|
1654
1672
|
normalizedProduct.metadata = {
|
|
1655
1673
|
...normalizedProduct.metadata || {},
|
|
@@ -1679,7 +1697,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1679
1697
|
tempOrder,
|
|
1680
1698
|
updates,
|
|
1681
1699
|
tempOrder.products[productIndex],
|
|
1682
|
-
(
|
|
1700
|
+
(_p = tempOrder.products[productIndex].metadata) == null ? void 0 : _p.unique_identification_number
|
|
1683
1701
|
);
|
|
1684
1702
|
await this.applyPromotion();
|
|
1685
1703
|
this.applyDiscount();
|
|
@@ -2333,9 +2351,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2333
2351
|
const existed = productsByUid[uid] && typeof productsByUid[uid] === "object" ? productsByUid[uid] : {};
|
|
2334
2352
|
const rawProduct = rawProducts[index] && typeof rawProducts[index] === "object" ? rawProducts[index] : product;
|
|
2335
2353
|
const origin = existed.origin ?? rawProduct._origin ?? ((_b = rawProduct.metadata) == null ? void 0 : _b.origin) ?? rawProduct;
|
|
2354
|
+
const originSnapshot = (0, import_lodash_es.cloneDeep)(origin);
|
|
2355
|
+
const productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
|
|
2356
|
+
if (productOptionString && originSnapshot && typeof originSnapshot === "object") {
|
|
2357
|
+
if (originSnapshot.product_option_string === void 0) {
|
|
2358
|
+
originSnapshot.product_option_string = productOptionString;
|
|
2359
|
+
}
|
|
2360
|
+
if (originSnapshot.product_options_stirng === void 0) {
|
|
2361
|
+
originSnapshot.product_options_stirng = productOptionString;
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2336
2364
|
productsByUid[uid] = {
|
|
2337
2365
|
...existed,
|
|
2338
|
-
origin:
|
|
2366
|
+
origin: originSnapshot
|
|
2339
2367
|
};
|
|
2340
2368
|
}
|
|
2341
2369
|
tempOrderExtend.productsByUid = productsByUid;
|
|
@@ -2345,24 +2373,81 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2345
2373
|
nextTempOrder.vouchers = raw.vouchers || [];
|
|
2346
2374
|
return nextTempOrder;
|
|
2347
2375
|
}
|
|
2376
|
+
pickHydratedDisplayText(value) {
|
|
2377
|
+
if (value === void 0 || value === null)
|
|
2378
|
+
return "";
|
|
2379
|
+
if (typeof value === "string")
|
|
2380
|
+
return value;
|
|
2381
|
+
if (typeof value !== "object")
|
|
2382
|
+
return String(value);
|
|
2383
|
+
return value.auto || value.original || value.en || value["zh-CN"] || value["zh-HK"] || "";
|
|
2384
|
+
}
|
|
2385
|
+
formatHydratedNamePair(group, item) {
|
|
2386
|
+
const groupText = this.pickHydratedDisplayText(group);
|
|
2387
|
+
const itemText = this.pickHydratedDisplayText(item);
|
|
2388
|
+
if (groupText && itemText)
|
|
2389
|
+
return `${groupText}:${itemText}`;
|
|
2390
|
+
return groupText || itemText;
|
|
2391
|
+
}
|
|
2392
|
+
buildHydratedProductOptionString(product) {
|
|
2393
|
+
const segments = [];
|
|
2394
|
+
const sku = (product == null ? void 0 : product.product_sku) || {};
|
|
2395
|
+
if (Array.isArray(sku.variant)) {
|
|
2396
|
+
for (const variant of sku.variant) {
|
|
2397
|
+
const segment = this.formatHydratedNamePair(variant == null ? void 0 : variant.group, variant == null ? void 0 : variant.item);
|
|
2398
|
+
if (segment)
|
|
2399
|
+
segments.push(segment);
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
return segments.join(", ");
|
|
2403
|
+
}
|
|
2348
2404
|
normalizeHydratedProductOptionItem(optionItem) {
|
|
2349
2405
|
const rawNum = (optionItem == null ? void 0 : optionItem.num) ?? (optionItem == null ? void 0 : optionItem.quantity) ?? 1;
|
|
2350
2406
|
const parsedNum = Number(rawNum);
|
|
2351
2407
|
const rawPrice = (optionItem == null ? void 0 : optionItem.price) ?? (optionItem == null ? void 0 : optionItem.add_price) ?? 0;
|
|
2352
2408
|
const parsedPrice = Number(rawPrice);
|
|
2353
|
-
|
|
2409
|
+
const normalized = {
|
|
2354
2410
|
option_group_item_id: optionItem == null ? void 0 : optionItem.option_group_item_id,
|
|
2355
2411
|
option_group_id: optionItem == null ? void 0 : optionItem.option_group_id,
|
|
2356
2412
|
num: Number.isFinite(parsedNum) && parsedNum > 0 ? parsedNum : 1,
|
|
2357
2413
|
price: Number.isFinite(parsedPrice) ? parsedPrice : 0
|
|
2358
2414
|
};
|
|
2415
|
+
if ((optionItem == null ? void 0 : optionItem.name) !== void 0)
|
|
2416
|
+
normalized.name = optionItem.name;
|
|
2417
|
+
if ((optionItem == null ? void 0 : optionItem.group_name) !== void 0)
|
|
2418
|
+
normalized.group_name = optionItem.group_name;
|
|
2419
|
+
if ((optionItem == null ? void 0 : optionItem.id) !== void 0)
|
|
2420
|
+
normalized.id = optionItem.id;
|
|
2421
|
+
return normalized;
|
|
2422
|
+
}
|
|
2423
|
+
mergeHydratedProductOptionDisplayFields(options, skuOptions) {
|
|
2424
|
+
if (!Array.isArray(skuOptions) || skuOptions.length === 0)
|
|
2425
|
+
return options;
|
|
2426
|
+
const displayByItemId = /* @__PURE__ */ new Map();
|
|
2427
|
+
for (const option of skuOptions) {
|
|
2428
|
+
const key = option == null ? void 0 : option.option_group_item_id;
|
|
2429
|
+
if (key === void 0 || key === null || key === "")
|
|
2430
|
+
continue;
|
|
2431
|
+
displayByItemId.set(String(key), option);
|
|
2432
|
+
}
|
|
2433
|
+
return options.map((option) => {
|
|
2434
|
+
const display = displayByItemId.get(String((option == null ? void 0 : option.option_group_item_id) ?? ""));
|
|
2435
|
+
if (!display)
|
|
2436
|
+
return option;
|
|
2437
|
+
return {
|
|
2438
|
+
...option,
|
|
2439
|
+
...option.name === void 0 && display.name !== void 0 ? { name: display.name } : {},
|
|
2440
|
+
...option.group_name === void 0 && display.group_name !== void 0 ? { group_name: display.group_name } : {},
|
|
2441
|
+
...option.id === void 0 && display.id !== void 0 ? { id: display.id } : {}
|
|
2442
|
+
};
|
|
2443
|
+
});
|
|
2359
2444
|
}
|
|
2360
2445
|
resolveHydratedProductOptions(row) {
|
|
2361
2446
|
var _a;
|
|
2447
|
+
const skuOptions = (_a = row.product_sku) == null ? void 0 : _a.option;
|
|
2362
2448
|
if (Array.isArray(row.product_option_item) && row.product_option_item.length > 0) {
|
|
2363
|
-
return row.product_option_item;
|
|
2449
|
+
return this.mergeHydratedProductOptionDisplayFields(row.product_option_item, skuOptions);
|
|
2364
2450
|
}
|
|
2365
|
-
const skuOptions = (_a = row.product_sku) == null ? void 0 : _a.option;
|
|
2366
2451
|
if (!Array.isArray(skuOptions))
|
|
2367
2452
|
return [];
|
|
2368
2453
|
return skuOptions.map(
|
|
@@ -753,6 +753,7 @@ function mapPaymentItemToOrderPayment(paymentItem) {
|
|
|
753
753
|
}
|
|
754
754
|
}
|
|
755
755
|
return {
|
|
756
|
+
...item.order_payment_id !== void 0 ? { order_payment_id: item.order_payment_id } : {},
|
|
756
757
|
amount: String(item.amount ?? "0.00"),
|
|
757
758
|
code: String(item.code || ""),
|
|
758
759
|
custom_payment_id: Number(customPaymentId ?? 0),
|