@pisell/pisellos 2.2.247 → 2.2.249
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/Order/index.d.ts +1 -0
- package/dist/modules/Order/index.js +77 -18
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +370 -263
- package/dist/server/modules/order/index.d.ts +2 -0
- package/dist/server/modules/order/index.js +131 -71
- package/dist/server/utils/small-ticket.js +109 -23
- package/dist/solution/BaseSales/index.js +11 -6
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +5 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -13
- package/lib/modules/Order/index.d.ts +1 -0
- package/lib/modules/Order/index.js +81 -10
- package/lib/server/index.d.ts +4 -0
- package/lib/server/index.js +67 -4
- package/lib/server/modules/order/index.d.ts +2 -0
- package/lib/server/modules/order/index.js +60 -1
- package/lib/server/utils/small-ticket.js +83 -13
- package/lib/solution/BaseSales/index.js +21 -6
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +5 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -13
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
4
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
1
5
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
6
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
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); }
|
|
3
8
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
9
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
-
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); }
|
|
8
10
|
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; }
|
|
9
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
11
|
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; }
|
|
12
12
|
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; }
|
|
13
13
|
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; }
|
|
@@ -40,7 +40,9 @@ var LABELS = {
|
|
|
40
40
|
orderDiscount: 'Order discount',
|
|
41
41
|
manualDiscount: 'Manual discount',
|
|
42
42
|
payProcessingFee: 'Pay processing fee',
|
|
43
|
-
rounding: 'Rounding'
|
|
43
|
+
rounding: 'Rounding',
|
|
44
|
+
gross: 'Gross',
|
|
45
|
+
tare: 'Tare'
|
|
44
46
|
},
|
|
45
47
|
zh_CN: {
|
|
46
48
|
contactName: '联系人姓名',
|
|
@@ -64,7 +66,9 @@ var LABELS = {
|
|
|
64
66
|
orderDiscount: '整单折扣',
|
|
65
67
|
manualDiscount: '手动折扣',
|
|
66
68
|
payProcessingFee: '支付手续费',
|
|
67
|
-
rounding: '抹零'
|
|
69
|
+
rounding: '抹零',
|
|
70
|
+
gross: '重量',
|
|
71
|
+
tare: '去皮'
|
|
68
72
|
},
|
|
69
73
|
zh_HK: {
|
|
70
74
|
contactName: '聯絡人姓名',
|
|
@@ -88,7 +92,9 @@ var LABELS = {
|
|
|
88
92
|
orderDiscount: '整單折扣',
|
|
89
93
|
manualDiscount: '手動折扣',
|
|
90
94
|
payProcessingFee: '支付手續費',
|
|
91
|
-
rounding: '抹零'
|
|
95
|
+
rounding: '抹零',
|
|
96
|
+
gross: '重量',
|
|
97
|
+
tare: '去皮'
|
|
92
98
|
}
|
|
93
99
|
};
|
|
94
100
|
export function buildSmallTicketData(params) {
|
|
@@ -200,10 +206,18 @@ function buildProducts(order, locale, productMap) {
|
|
|
200
206
|
parentProduct: parentProduct,
|
|
201
207
|
locale: locale
|
|
202
208
|
});
|
|
209
|
+
var extensionList = buildProductExtensionList({
|
|
210
|
+
product: product,
|
|
211
|
+
locale: locale,
|
|
212
|
+
currencySymbol: currencySymbol,
|
|
213
|
+
quantity: quantity,
|
|
214
|
+
originalPrice: originalPrice
|
|
215
|
+
});
|
|
203
216
|
var discountList = normalizeProductDiscounts({
|
|
204
217
|
product: product,
|
|
205
218
|
locale: locale,
|
|
206
|
-
currencySymbol: currencySymbol
|
|
219
|
+
currencySymbol: currencySymbol,
|
|
220
|
+
quantity: quantity
|
|
207
221
|
});
|
|
208
222
|
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
209
223
|
product_title: productTitle,
|
|
@@ -211,7 +225,7 @@ function buildProducts(order, locale, productMap) {
|
|
|
211
225
|
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
212
226
|
original_price: formatMoney(originalPrice, currencySymbol),
|
|
213
227
|
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
|
|
214
|
-
extension_list:
|
|
228
|
+
extension_list: extensionList
|
|
215
229
|
}, discountList.length ? {
|
|
216
230
|
discount_list: discountList
|
|
217
231
|
} : {}), options.length ? {
|
|
@@ -228,12 +242,13 @@ function buildProducts(order, locale, productMap) {
|
|
|
228
242
|
function normalizeProductDiscounts(params) {
|
|
229
243
|
var product = params.product,
|
|
230
244
|
locale = params.locale,
|
|
231
|
-
currencySymbol = params.currencySymbol
|
|
245
|
+
currencySymbol = params.currencySymbol,
|
|
246
|
+
quantity = params.quantity;
|
|
232
247
|
return normalizeArray(product.discount_list).map(function (discount) {
|
|
233
248
|
var _ref8, _discount$amount;
|
|
234
|
-
var title =
|
|
249
|
+
var title = resolveDiscountTitleWithPercent(discount, locale);
|
|
235
250
|
var amount = (_ref8 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref8 !== void 0 ? _ref8 : discount.discount_amount;
|
|
236
|
-
var formattedAmount = formatNegativeMoney(amount, currencySymbol);
|
|
251
|
+
var formattedAmount = formatNegativeMoney(new Decimal(toMoneyNumber(amount)).mul(quantity), currencySymbol);
|
|
237
252
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
238
253
|
item: title,
|
|
239
254
|
name: title,
|
|
@@ -242,9 +257,77 @@ function normalizeProductDiscounts(params) {
|
|
|
242
257
|
});
|
|
243
258
|
});
|
|
244
259
|
}
|
|
260
|
+
function buildProductExtensionList(params) {
|
|
261
|
+
var product = params.product,
|
|
262
|
+
locale = params.locale,
|
|
263
|
+
currencySymbol = params.currencySymbol,
|
|
264
|
+
quantity = params.quantity,
|
|
265
|
+
originalPrice = params.originalPrice;
|
|
266
|
+
var extensionList = [].concat(_toConsumableArray(buildProductOpenWeightRows({
|
|
267
|
+
product: product,
|
|
268
|
+
locale: locale,
|
|
269
|
+
currencySymbol: currencySymbol
|
|
270
|
+
})), _toConsumableArray(quantity > 1 ? [{
|
|
271
|
+
item: buildProductQuantityPriceText({
|
|
272
|
+
quantity: quantity,
|
|
273
|
+
currencySymbol: currencySymbol,
|
|
274
|
+
price: originalPrice
|
|
275
|
+
}),
|
|
276
|
+
value: ''
|
|
277
|
+
}] : []));
|
|
278
|
+
return extensionList.length ? extensionList : normalizeArray(product.extension_list);
|
|
279
|
+
}
|
|
280
|
+
function buildProductOpenWeightRows(params) {
|
|
281
|
+
var _productSku$unit, _productSku$net_weigh, _productSku$unit_pric;
|
|
282
|
+
var product = params.product,
|
|
283
|
+
locale = params.locale,
|
|
284
|
+
currencySymbol = params.currencySymbol;
|
|
285
|
+
var productSku = product.product_sku || {};
|
|
286
|
+
if (productSku.open_sold_weight != 1) return [];
|
|
287
|
+
var unit = (_productSku$unit = productSku.unit) !== null && _productSku$unit !== void 0 ? _productSku$unit : '';
|
|
288
|
+
var manualFlag = productSku.weight_source === 'manual' ? '(M) ' : '';
|
|
289
|
+
var hasTare = toNumber(productSku.tare_weight, 0) > 0;
|
|
290
|
+
var rows = [];
|
|
291
|
+
if (hasTare) {
|
|
292
|
+
var _productSku$weight;
|
|
293
|
+
rows.push({
|
|
294
|
+
item: "".concat(manualFlag).concat(label(locale, 'gross'), ": ").concat((_productSku$weight = productSku.weight) !== null && _productSku$weight !== void 0 ? _productSku$weight : 0).concat(unit),
|
|
295
|
+
value: ''
|
|
296
|
+
});
|
|
297
|
+
rows.push({
|
|
298
|
+
item: "".concat(label(locale, 'tare'), ": ").concat(productSku.tare_weight).concat(unit),
|
|
299
|
+
value: ''
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
var netWeight = (_productSku$net_weigh = productSku.net_weight) !== null && _productSku$net_weigh !== void 0 ? _productSku$net_weigh : 0;
|
|
303
|
+
var unitPrice = (_productSku$unit_pric = productSku.unit_price) !== null && _productSku$unit_pric !== void 0 ? _productSku$unit_pric : 0;
|
|
304
|
+
var netItem = "".concat(netWeight, " ").concat(unit, " NET @ ").concat(currencySymbol).concat(unitPrice, "/").concat(unit);
|
|
305
|
+
rows.push({
|
|
306
|
+
item: hasTare ? netItem : "".concat(manualFlag).concat(netItem),
|
|
307
|
+
value: ''
|
|
308
|
+
});
|
|
309
|
+
return rows;
|
|
310
|
+
}
|
|
311
|
+
function buildProductQuantityPriceText(params) {
|
|
312
|
+
var quantity = params.quantity,
|
|
313
|
+
currencySymbol = params.currencySymbol,
|
|
314
|
+
price = params.price;
|
|
315
|
+
return "".concat(quantity, " @ ").concat(currencySymbol).concat(stringify(price), " EACH");
|
|
316
|
+
}
|
|
317
|
+
function resolveDiscountTitleWithPercent(discount, locale) {
|
|
318
|
+
var _discount$discount, _discount$discount$di, _discount$discount2;
|
|
319
|
+
var title = resolveDiscountTitle(discount, locale);
|
|
320
|
+
var percentRaw = (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.percent;
|
|
321
|
+
var cardType = (_discount$discount$di = (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.discount_card_type) !== null && _discount$discount$di !== void 0 ? _discount$discount$di : 'percent';
|
|
322
|
+
var percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
|
|
323
|
+
if (percentRaw === undefined || percentRaw === null) return title;
|
|
324
|
+
if (cardType !== 'percent') return title;
|
|
325
|
+
if (Number.isNaN(percent)) return title;
|
|
326
|
+
return "".concat(title, " (").concat(percent, "%)");
|
|
327
|
+
}
|
|
245
328
|
function resolveDiscountTitle(discount, locale) {
|
|
246
|
-
var _ref9, _ref10, _ref11, _ref12, _discount$discount$na, _discount$
|
|
247
|
-
var title = getLocalizedValue((_ref9 = (_ref10 = (_ref11 = (_ref12 = (_discount$discount$na = (_discount$
|
|
329
|
+
var _ref9, _ref10, _ref11, _ref12, _discount$discount$na, _discount$discount3, _discount$discount4, _discount$discount5;
|
|
330
|
+
var title = getLocalizedValue((_ref9 = (_ref10 = (_ref11 = (_ref12 = (_discount$discount$na = (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.name) !== null && _discount$discount$na !== void 0 ? _discount$discount$na : (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.title) !== null && _ref12 !== void 0 ? _ref12 : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.message) !== null && _ref11 !== void 0 ? _ref11 : discount.name) !== null && _ref10 !== void 0 ? _ref10 : discount.title) !== null && _ref9 !== void 0 ? _ref9 : discount.message, locale);
|
|
248
331
|
if (title) return title;
|
|
249
332
|
if (discount.type === 'product') return label(locale, 'manualDiscount');
|
|
250
333
|
return '';
|
|
@@ -544,7 +627,7 @@ function formatBundlePrice(bundle, currencySymbol) {
|
|
|
544
627
|
return formatMoney(amount, currencySymbol);
|
|
545
628
|
}
|
|
546
629
|
function buildFees(params) {
|
|
547
|
-
var _ref36, _order$shop_discount;
|
|
630
|
+
var _ref36, _order$shop_discount, _ref37, _summary$product_orig;
|
|
548
631
|
var order = params.order,
|
|
549
632
|
shopInfo = params.shopInfo,
|
|
550
633
|
locale = params.locale,
|
|
@@ -590,11 +673,14 @@ function buildFees(params) {
|
|
|
590
673
|
value: formatMoney(payProcessingFee, currencySymbol)
|
|
591
674
|
});
|
|
592
675
|
}
|
|
676
|
+
var productExpectAmount = summary.product_expect_amount || summary.product_amount || order.product_expect_amount;
|
|
677
|
+
var productOriginalAmount = (_ref37 = (_summary$product_orig = summary.product_original_amount) !== null && _summary$product_orig !== void 0 ? _summary$product_orig : order.product_original_amount) !== null && _ref37 !== void 0 ? _ref37 : productExpectAmount;
|
|
678
|
+
var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
|
|
593
679
|
return {
|
|
594
680
|
fees: fees,
|
|
595
681
|
countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
596
682
|
total_amount: formatMoney(summary.total_amount || order.total_amount, currencySymbol),
|
|
597
|
-
product_expect_amount: formatMoney(
|
|
683
|
+
product_expect_amount: formatMoney(productExpectAmount, currencySymbol),
|
|
598
684
|
expect_amount: formatMoney(summary.expect_amount || order.expect_amount || summary.total_amount || order.total_amount, currencySymbol),
|
|
599
685
|
product_quantity: toNumber(summary.product_quantity || products.reduce(function (sum, product) {
|
|
600
686
|
return sum + product.product_quantity;
|
|
@@ -605,8 +691,8 @@ function buildFees(params) {
|
|
|
605
691
|
total_refund_amount: formatMoney(summary.total_refund_amount || order.total_refund_amount, currencySymbol)
|
|
606
692
|
}, isNonZero(roundingAmount) ? {
|
|
607
693
|
rounding_amount: formatMoney(roundingAmount, currencySymbol)
|
|
608
|
-
} : {}), isNonZero(
|
|
609
|
-
order_total_discount: formatMoney(
|
|
694
|
+
} : {}), isNonZero(totalSavingsAmount) ? {
|
|
695
|
+
order_total_discount: formatMoney(totalSavingsAmount, currencySymbol)
|
|
610
696
|
} : {}), isNonZero(payProcessingFee) ? {
|
|
611
697
|
pay_processing_fee: formatMoney(payProcessingFee, currencySymbol)
|
|
612
698
|
} : {}), isNonZero(taxFee) ? {
|
|
@@ -690,8 +776,8 @@ function buildPaymentData(params) {
|
|
|
690
776
|
currencySymbol: params.currencySymbol
|
|
691
777
|
})));
|
|
692
778
|
} else {
|
|
693
|
-
var
|
|
694
|
-
var remainingAmount = (
|
|
779
|
+
var _ref38, _payment$remaining_am, _payment$metadata;
|
|
780
|
+
var remainingAmount = (_ref38 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref38 !== void 0 ? _ref38 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
|
|
695
781
|
if (remainingAmount !== undefined && remainingAmount !== null) {
|
|
696
782
|
items.push({
|
|
697
783
|
item: label(params.locale, 'remainingAmount'),
|
|
@@ -799,12 +885,12 @@ function label(locale, key) {
|
|
|
799
885
|
return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
|
|
800
886
|
}
|
|
801
887
|
function getLocalizedValue(value, locale) {
|
|
802
|
-
var
|
|
888
|
+
var _ref39, _ref40, _ref41, _ref42, _ref43, _ref44, _value$locale2;
|
|
803
889
|
if (value === undefined || value === null) return '';
|
|
804
890
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
805
891
|
var dashedLocale = locale.replace('_', '-');
|
|
806
892
|
var underscoredLocale = locale.replace('-', '_');
|
|
807
|
-
return stringify((
|
|
893
|
+
return stringify((_ref39 = (_ref40 = (_ref41 = (_ref42 = (_ref43 = (_ref44 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref44 !== void 0 ? _ref44 : value[underscoredLocale]) !== null && _ref43 !== void 0 ? _ref43 : value.original) !== null && _ref42 !== void 0 ? _ref42 : value.auto) !== null && _ref41 !== void 0 ? _ref41 : value.default) !== null && _ref40 !== void 0 ? _ref40 : value.en) !== null && _ref39 !== void 0 ? _ref39 : '');
|
|
808
894
|
}
|
|
809
895
|
function serviceTypeToLabelKey(serviceType) {
|
|
810
896
|
var normalized = serviceType.toLowerCase();
|
|
@@ -63,6 +63,9 @@ function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
|
|
|
63
63
|
return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
+
function isBaseSalesHistoricalDiscountEntry(discount) {
|
|
67
|
+
return Boolean((discount === null || discount === void 0 ? void 0 : discount.isEditMode) || (discount === null || discount === void 0 ? void 0 : discount.isDisabled) || (discount === null || discount === void 0 ? void 0 : discount.order_discount_id) != null);
|
|
68
|
+
}
|
|
66
69
|
function getBaseSalesUniqueArrayMetadataKey(key) {
|
|
67
70
|
if (key === 'products' || key === 'bookings') return 'unique_identification_number';
|
|
68
71
|
if (key === 'payments' || key === 'payment') return 'unique_payment_number';
|
|
@@ -1322,7 +1325,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1322
1325
|
return discount.id;
|
|
1323
1326
|
}));
|
|
1324
1327
|
return [].concat(_toConsumableArray(historyDiscountList), _toConsumableArray((discountList || []).filter(function (discount) {
|
|
1325
|
-
|
|
1328
|
+
if (!historyIds.has(discount.id)) return true;
|
|
1329
|
+
return !isBaseSalesHistoricalDiscountEntry(discount);
|
|
1326
1330
|
})));
|
|
1327
1331
|
}
|
|
1328
1332
|
}, {
|
|
@@ -1347,11 +1351,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1347
1351
|
key: "mergeCurrentDiscountSelectionState",
|
|
1348
1352
|
value: function mergeCurrentDiscountSelectionState(discountList, currentDiscountList) {
|
|
1349
1353
|
if (!currentDiscountList.length) return discountList;
|
|
1350
|
-
var currentDiscountMap = new Map(
|
|
1351
|
-
|
|
1352
|
-
|
|
1354
|
+
var currentDiscountMap = new Map();
|
|
1355
|
+
currentDiscountList.forEach(function (discount) {
|
|
1356
|
+
currentDiscountMap.set("".concat(discount.id, ":").concat(isBaseSalesHistoricalDiscountEntry(discount) ? 'historical' : 'runtime'), discount);
|
|
1357
|
+
});
|
|
1353
1358
|
return discountList.map(function (discount) {
|
|
1354
|
-
var currentDiscount = currentDiscountMap.get(discount.id);
|
|
1359
|
+
var currentDiscount = currentDiscountMap.get("".concat(discount.id, ":").concat(isBaseSalesHistoricalDiscountEntry(discount) ? 'historical' : 'runtime'));
|
|
1355
1360
|
if (!currentDiscount) return discount;
|
|
1356
1361
|
if (currentDiscount.isManualSelect) {
|
|
1357
1362
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
@@ -1731,7 +1736,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1731
1736
|
case 3:
|
|
1732
1737
|
list = this.store.order.getDiscountList();
|
|
1733
1738
|
updated = list.map(function (d) {
|
|
1734
|
-
return d.id === params.discountId ? _objectSpread(_objectSpread({}, d), {}, {
|
|
1739
|
+
return d.id === params.discountId && !isBaseSalesHistoricalDiscountEntry(d) ? _objectSpread(_objectSpread({}, d), {}, {
|
|
1735
1740
|
isSelected: params.isSelected,
|
|
1736
1741
|
isManualSelect: !params.isSelected
|
|
1737
1742
|
}) : d;
|
|
@@ -173,6 +173,10 @@ export function transformBaseProductToOrderProduct(params) {
|
|
|
173
173
|
if (uniqueIdentificationNumber) {
|
|
174
174
|
metadata.unique_identification_number = String(uniqueIdentificationNumber);
|
|
175
175
|
}
|
|
176
|
+
// 从源头补充商品多语言标题
|
|
177
|
+
var productTitle = _objectSpread(_objectSpread({}, (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title_i18n) || {}), {}, {
|
|
178
|
+
original: (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) || ''
|
|
179
|
+
});
|
|
176
180
|
return {
|
|
177
181
|
product_id: productId,
|
|
178
182
|
product_variant_id: productVariantId,
|
|
@@ -190,6 +194,7 @@ export function transformBaseProductToOrderProduct(params) {
|
|
|
190
194
|
is_charge_tax: toNumber((_ref32 = (_ref33 = (_payload$is_charge_ta = payload.is_charge_tax) !== null && _payload$is_charge_ta !== void 0 ? _payload$is_charge_ta : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.is_charge_tax) !== null && _ref33 !== void 0 ? _ref33 : origin === null || origin === void 0 ? void 0 : origin.is_charge_tax) !== null && _ref32 !== void 0 ? _ref32 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.is_charge_tax, 0),
|
|
191
195
|
metadata: metadata,
|
|
192
196
|
note: payload.note != null ? String(payload.note) : '',
|
|
197
|
+
product_title: productTitle,
|
|
193
198
|
_origin: _objectSpread(_objectSpread({}, sourceProduct || {}), {}, {
|
|
194
199
|
callbackData: payload
|
|
195
200
|
})
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 2 | 1 | 6 | 3 | 4 | 5;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -441,19 +441,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
441
441
|
* 加车两阶段主决策(规格弹窗 / 资源编辑 / 直接加车)。
|
|
442
442
|
* 与 ticketBooking `handleSelectProduct` + `handleBooking4Service` 等价。
|
|
443
443
|
*/
|
|
444
|
-
decideAddProduct(item: any, options?: Partial<AddProductDecideContext>):
|
|
445
|
-
action: "reloadCatalog";
|
|
446
|
-
} | {
|
|
447
|
-
action: "add";
|
|
448
|
-
cacheItem: any;
|
|
449
|
-
} | {
|
|
450
|
-
action: "requiresDetail";
|
|
451
|
-
payload: AddProductRequiresDetailPayload;
|
|
452
|
-
} | {
|
|
453
|
-
action: "requiresBookingEdit";
|
|
454
|
-
cacheItem: any;
|
|
455
|
-
payload: import("./utils/addProductDecision").AddProductRequiresBookingEditPayload;
|
|
456
|
-
};
|
|
444
|
+
decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
|
|
457
445
|
/** 规格弹窗 callback 后的第二段决策。 */
|
|
458
446
|
decideAfterDetail(cacheItem: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
|
|
459
447
|
/**
|
|
@@ -480,6 +480,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
480
480
|
recalcOnHydrate?: boolean;
|
|
481
481
|
}): Promise<OrderTempOrder>;
|
|
482
482
|
private normalizeTempOrderForRuntime;
|
|
483
|
+
private hydrateLinkedBookingIdentity;
|
|
483
484
|
private pickHydratedDisplayText;
|
|
484
485
|
private formatHydratedNamePair;
|
|
485
486
|
private buildHydratedProductOptionString;
|
|
@@ -168,33 +168,53 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
168
168
|
*/
|
|
169
169
|
static populateSavedAmounts(productList, discountList) {
|
|
170
170
|
const savedMap = /* @__PURE__ */ new Map();
|
|
171
|
-
const
|
|
171
|
+
const editModeSavedMap = /* @__PURE__ */ new Map();
|
|
172
|
+
const runtimeSavedMap = /* @__PURE__ */ new Map();
|
|
173
|
+
const editModeDiscountKeys = new Set(
|
|
174
|
+
(discountList || []).filter((discount) => discount == null ? void 0 : discount.isEditMode).map((discount) => discount == null ? void 0 : discount.id).filter((id) => id !== void 0 && id !== null)
|
|
175
|
+
);
|
|
176
|
+
const addDiscountAmount = (targetMap, discountKey, amount) => {
|
|
177
|
+
targetMap.set(
|
|
178
|
+
discountKey,
|
|
179
|
+
(targetMap.get(discountKey) || new import_decimal.default(0)).plus(amount)
|
|
180
|
+
);
|
|
181
|
+
};
|
|
182
|
+
const addProductDiscountAmount = (discount, quantity, isPersistedProduct) => {
|
|
172
183
|
var _a, _b;
|
|
173
184
|
const discountKey = ((_a = discount.discount) == null ? void 0 : _a.resource_id) || discount.id;
|
|
174
185
|
if (discountKey == null)
|
|
175
186
|
return;
|
|
176
187
|
const qty = Number(quantity) || 1;
|
|
177
188
|
const amount = new import_decimal.default(discount.amount || 0).times(qty).plus(((_b = discount.metadata) == null ? void 0 : _b.product_discount_difference) || 0);
|
|
178
|
-
savedMap
|
|
189
|
+
addDiscountAmount(savedMap, discountKey, amount);
|
|
190
|
+
addDiscountAmount(
|
|
191
|
+
isPersistedProduct || discount.order_discount_id != null ? editModeSavedMap : runtimeSavedMap,
|
|
179
192
|
discountKey,
|
|
180
|
-
|
|
193
|
+
amount
|
|
181
194
|
);
|
|
182
195
|
};
|
|
183
196
|
for (const product of productList) {
|
|
184
197
|
const qty = product.num || 1;
|
|
198
|
+
const isPersistedProduct = Boolean(
|
|
199
|
+
product.order_detail_id || product.orderDetailId || product.booking_id
|
|
200
|
+
);
|
|
185
201
|
for (const pd of product.discount_list || []) {
|
|
186
|
-
|
|
202
|
+
addProductDiscountAmount(pd, qty, isPersistedProduct);
|
|
187
203
|
}
|
|
188
204
|
for (const bundle of product.product_bundle || []) {
|
|
205
|
+
const isPersistedBundleProduct = isPersistedProduct || Boolean(
|
|
206
|
+
(bundle == null ? void 0 : bundle.order_detail_id) || (bundle == null ? void 0 : bundle.orderDetailId) || (bundle == null ? void 0 : bundle.booking_id)
|
|
207
|
+
);
|
|
189
208
|
const bundleQty = new import_decimal.default(Number(qty) || 1).times(Number((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity) ?? 1) || 1).toNumber();
|
|
190
209
|
for (const pd of (bundle == null ? void 0 : bundle.discount_list) || []) {
|
|
191
|
-
|
|
210
|
+
addProductDiscountAmount(pd, bundleQty, isPersistedBundleProduct);
|
|
192
211
|
}
|
|
193
212
|
}
|
|
194
213
|
}
|
|
195
214
|
for (const d of discountList) {
|
|
196
215
|
const key = d.id;
|
|
197
|
-
|
|
216
|
+
const sourceMap = d.isEditMode ? editModeSavedMap : editModeDiscountKeys.has(key) ? runtimeSavedMap : savedMap;
|
|
217
|
+
d.savedAmount = d.isSelected && key != null && sourceMap.has(key) ? sourceMap.get(key).toNumber() : 0;
|
|
198
218
|
}
|
|
199
219
|
}
|
|
200
220
|
applyProductDiscountPrices(products) {
|
|
@@ -371,12 +391,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
371
391
|
}));
|
|
372
392
|
if (discountList) {
|
|
373
393
|
const currentEditDiscounts = (((_c = this.store.discount) == null ? void 0 : _c.getDiscountList()) || []).filter((discount) => discount == null ? void 0 : discount.isEditMode);
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
394
|
+
const runtimeDiscountIds = /* @__PURE__ */ new Set();
|
|
395
|
+
const runtimeDiscounts = discountList.filter((discount) => {
|
|
396
|
+
if (runtimeDiscountIds.has(discount == null ? void 0 : discount.id))
|
|
397
|
+
return false;
|
|
398
|
+
runtimeDiscountIds.add(discount == null ? void 0 : discount.id);
|
|
399
|
+
return true;
|
|
400
|
+
});
|
|
377
401
|
const mergedDiscountList = [
|
|
378
402
|
...currentEditDiscounts,
|
|
379
|
-
...
|
|
403
|
+
...runtimeDiscounts
|
|
380
404
|
];
|
|
381
405
|
await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(mergedDiscountList));
|
|
382
406
|
await ((_e = this.store.discount) == null ? void 0 : _e.setDiscountList(mergedDiscountList));
|
|
@@ -3670,12 +3694,59 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3670
3694
|
};
|
|
3671
3695
|
}
|
|
3672
3696
|
tempOrderExtend.productsByUid = productsByUid;
|
|
3697
|
+
this.hydrateLinkedBookingIdentity(nextTempOrder);
|
|
3673
3698
|
if ((options == null ? void 0 : options.ensureIdentity) !== false) {
|
|
3674
3699
|
this.ensureExternalSaleNumber(nextTempOrder);
|
|
3675
3700
|
}
|
|
3676
3701
|
nextTempOrder.vouchers = raw.vouchers || [];
|
|
3677
3702
|
return nextTempOrder;
|
|
3678
3703
|
}
|
|
3704
|
+
hydrateLinkedBookingIdentity(tempOrder) {
|
|
3705
|
+
const bookingUidByProductUid = /* @__PURE__ */ new Map();
|
|
3706
|
+
const productByUid = /* @__PURE__ */ new Map();
|
|
3707
|
+
(tempOrder.products || []).forEach((product) => {
|
|
3708
|
+
var _a;
|
|
3709
|
+
const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
|
|
3710
|
+
if (productUid !== void 0 && productUid !== null && String(productUid) !== "") {
|
|
3711
|
+
productByUid.set(String(productUid), product);
|
|
3712
|
+
}
|
|
3713
|
+
});
|
|
3714
|
+
(tempOrder.bookings || []).forEach((booking) => {
|
|
3715
|
+
var _a;
|
|
3716
|
+
if (!booking || typeof booking !== "object")
|
|
3717
|
+
return;
|
|
3718
|
+
if (!booking.metadata || typeof booking.metadata !== "object") {
|
|
3719
|
+
booking.metadata = {};
|
|
3720
|
+
}
|
|
3721
|
+
const productUid = booking.product_uid || booking.metadata.product_uid;
|
|
3722
|
+
if (productUid === void 0 || productUid === null || String(productUid) === "")
|
|
3723
|
+
return;
|
|
3724
|
+
const matchedProduct = productByUid.get(String(productUid));
|
|
3725
|
+
const existedProductBookingUid = (matchedProduct == null ? void 0 : matchedProduct.booking_uid) || ((_a = matchedProduct == null ? void 0 : matchedProduct.metadata) == null ? void 0 : _a.booking_uid);
|
|
3726
|
+
const bookingUid = String(
|
|
3727
|
+
booking.metadata.unique_identification_number || existedProductBookingUid || (0, import_utils.createUuidV4)()
|
|
3728
|
+
);
|
|
3729
|
+
booking.metadata.unique_identification_number = bookingUid;
|
|
3730
|
+
bookingUidByProductUid.set(String(productUid), bookingUid);
|
|
3731
|
+
});
|
|
3732
|
+
(tempOrder.products || []).forEach((product) => {
|
|
3733
|
+
var _a;
|
|
3734
|
+
const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
|
|
3735
|
+
if (productUid === void 0 || productUid === null || String(productUid) === "")
|
|
3736
|
+
return;
|
|
3737
|
+
const bookingUid = bookingUidByProductUid.get(String(productUid));
|
|
3738
|
+
if (!bookingUid)
|
|
3739
|
+
return;
|
|
3740
|
+
if (!product.metadata || typeof product.metadata !== "object") {
|
|
3741
|
+
product.metadata = {};
|
|
3742
|
+
}
|
|
3743
|
+
const linkedBookingUid = String(
|
|
3744
|
+
product.booking_uid || product.metadata.booking_uid || bookingUid
|
|
3745
|
+
);
|
|
3746
|
+
product.booking_uid = linkedBookingUid;
|
|
3747
|
+
product.metadata.booking_uid = linkedBookingUid;
|
|
3748
|
+
});
|
|
3749
|
+
}
|
|
3679
3750
|
pickHydratedDisplayText(value) {
|
|
3680
3751
|
if (value === void 0 || value === null)
|
|
3681
3752
|
return "";
|
package/lib/server/index.d.ts
CHANGED
|
@@ -422,6 +422,10 @@ declare class Server {
|
|
|
422
422
|
private canAssignStringProductTitleToLocale;
|
|
423
423
|
private hasCjkText;
|
|
424
424
|
private resolveFirstProductTitleValue;
|
|
425
|
+
private getPaymentCodeKey;
|
|
426
|
+
private isBlankPaymentName;
|
|
427
|
+
private shouldLookupPaymentMethodNameByCode;
|
|
428
|
+
private enrichPaymentNamesByCode;
|
|
425
429
|
private withLocalSmallTicketData;
|
|
426
430
|
private handleOrderSalesDetail;
|
|
427
431
|
/**
|
package/lib/server/index.js
CHANGED
|
@@ -3091,22 +3091,85 @@ var Server = class {
|
|
|
3091
3091
|
);
|
|
3092
3092
|
return firstValue === void 0 ? null : String(firstValue);
|
|
3093
3093
|
}
|
|
3094
|
+
getPaymentCodeKey(code) {
|
|
3095
|
+
if (code === void 0 || code === null)
|
|
3096
|
+
return "";
|
|
3097
|
+
return String(code).trim().toUpperCase();
|
|
3098
|
+
}
|
|
3099
|
+
isBlankPaymentName(name) {
|
|
3100
|
+
if (name === void 0 || name === null)
|
|
3101
|
+
return true;
|
|
3102
|
+
if (typeof name === "string")
|
|
3103
|
+
return name.trim() === "";
|
|
3104
|
+
return false;
|
|
3105
|
+
}
|
|
3106
|
+
shouldLookupPaymentMethodNameByCode(code) {
|
|
3107
|
+
const codeKey = this.getPaymentCodeKey(code);
|
|
3108
|
+
if (!codeKey)
|
|
3109
|
+
return false;
|
|
3110
|
+
const builtInNameTokens = ["CASH", "EFTPOS", "CARD", "WALLET", "GIFT"];
|
|
3111
|
+
return !builtInNameTokens.some((token) => codeKey.includes(token));
|
|
3112
|
+
}
|
|
3113
|
+
async enrichPaymentNamesByCode(order) {
|
|
3114
|
+
const payments = Array.isArray(order == null ? void 0 : order.payments) ? order.payments : [];
|
|
3115
|
+
const hasMissingName = payments.some((payment) => this.isBlankPaymentName(payment == null ? void 0 : payment.name) && this.shouldLookupPaymentMethodNameByCode(payment == null ? void 0 : payment.code));
|
|
3116
|
+
if (!hasMissingName)
|
|
3117
|
+
return order;
|
|
3118
|
+
try {
|
|
3119
|
+
const paymentModule = await this.getPaymentRouteModule();
|
|
3120
|
+
const payMethods = await paymentModule.getPayMethodListAsync();
|
|
3121
|
+
const nameByCode = /* @__PURE__ */ new Map();
|
|
3122
|
+
for (const method of payMethods || []) {
|
|
3123
|
+
const codeKey = this.getPaymentCodeKey(method == null ? void 0 : method.code);
|
|
3124
|
+
const name = this.resolveFirstProductTitleValue(method == null ? void 0 : method.name);
|
|
3125
|
+
if (codeKey && name)
|
|
3126
|
+
nameByCode.set(codeKey, name);
|
|
3127
|
+
}
|
|
3128
|
+
let hasResolvedName = false;
|
|
3129
|
+
const enrichedPayments = payments.map((payment) => {
|
|
3130
|
+
if (!this.isBlankPaymentName(payment == null ? void 0 : payment.name))
|
|
3131
|
+
return payment;
|
|
3132
|
+
if (!this.shouldLookupPaymentMethodNameByCode(payment == null ? void 0 : payment.code))
|
|
3133
|
+
return payment;
|
|
3134
|
+
const name = nameByCode.get(this.getPaymentCodeKey(payment == null ? void 0 : payment.code));
|
|
3135
|
+
if (!name)
|
|
3136
|
+
return payment;
|
|
3137
|
+
hasResolvedName = true;
|
|
3138
|
+
return {
|
|
3139
|
+
...payment,
|
|
3140
|
+
name
|
|
3141
|
+
};
|
|
3142
|
+
});
|
|
3143
|
+
if (!hasResolvedName)
|
|
3144
|
+
return order;
|
|
3145
|
+
return {
|
|
3146
|
+
...order,
|
|
3147
|
+
payments: enrichedPayments
|
|
3148
|
+
};
|
|
3149
|
+
} catch (error) {
|
|
3150
|
+
this.logWarning("enrichPaymentNamesByCode: 支付方式名称回填失败", {
|
|
3151
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3152
|
+
});
|
|
3153
|
+
return order;
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3094
3156
|
async withLocalSmallTicketData(order, options) {
|
|
3095
3157
|
if (!this.shouldBuildSmallTicketData(order))
|
|
3096
3158
|
return order;
|
|
3097
3159
|
if ((options == null ? void 0 : options.requireFullyPaid) && !this.isSalesOrderFullyPaid(order))
|
|
3098
3160
|
return order;
|
|
3099
3161
|
try {
|
|
3100
|
-
const
|
|
3162
|
+
const enrichedOrder = await this.enrichPaymentNamesByCode(order);
|
|
3163
|
+
const productMap = (options == null ? void 0 : options.productMap) ?? await this.buildSmallTicketProductMap(enrichedOrder);
|
|
3101
3164
|
const smallTicketData = (0, import_small_ticket.buildSmallTicketData)({
|
|
3102
|
-
order,
|
|
3165
|
+
order: enrichedOrder,
|
|
3103
3166
|
shopInfo: this.getSmallTicketShopInfo(),
|
|
3104
3167
|
productMap
|
|
3105
3168
|
});
|
|
3106
3169
|
return {
|
|
3107
|
-
...
|
|
3170
|
+
...enrichedOrder,
|
|
3108
3171
|
payment_info: {
|
|
3109
|
-
...
|
|
3172
|
+
...enrichedOrder.payment_info || {},
|
|
3110
3173
|
small_ticket_data: smallTicketData
|
|
3111
3174
|
}
|
|
3112
3175
|
};
|
|
@@ -195,6 +195,8 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
195
195
|
private pickPreferredOrder;
|
|
196
196
|
private getProductMergeKey;
|
|
197
197
|
private mergeOrderProductLists;
|
|
198
|
+
private getPaymentMergeKey;
|
|
199
|
+
private mergeOrderPaymentLists;
|
|
198
200
|
private mergeOrderRecords;
|
|
199
201
|
private summarizeDuplicateOrders;
|
|
200
202
|
private logDuplicateOrders;
|