@pisell/pisellos 2.1.130 → 2.1.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/Order/index.d.ts +3 -6
- package/dist/modules/Order/index.js +119 -41
- package/dist/modules/Order/types.d.ts +23 -5
- package/dist/modules/Order/types.js +2 -0
- package/dist/modules/Order/utils.d.ts +66 -11
- package/dist/modules/Order/utils.js +281 -45
- package/dist/modules/SalesSummary/utils.js +33 -68
- package/dist/modules/ScanOrderLogger/providers/feishu.js +168 -60
- package/dist/modules/ScanOrderLogger/types.d.ts +6 -0
- package/dist/modules/Summary/utils.js +6 -21
- package/dist/solution/ScanOrder/index.d.ts +31 -6
- package/dist/solution/ScanOrder/index.js +1062 -498
- package/dist/solution/ScanOrder/types.d.ts +52 -2
- package/dist/solution/ScanOrder/types.js +16 -1
- package/dist/solution/ScanOrder/utils.d.ts +41 -5
- package/dist/solution/ScanOrder/utils.js +214 -33
- package/dist/solution/VenueBooking/index.d.ts +2 -5
- package/dist/solution/VenueBooking/index.js +35 -27
- package/lib/modules/Order/index.d.ts +3 -6
- package/lib/modules/Order/index.js +109 -30
- package/lib/modules/Order/types.d.ts +23 -5
- package/lib/modules/Order/utils.d.ts +66 -11
- package/lib/modules/Order/utils.js +181 -16
- package/lib/modules/SalesSummary/utils.js +13 -47
- package/lib/modules/ScanOrderLogger/providers/feishu.js +100 -34
- package/lib/modules/ScanOrderLogger/types.d.ts +6 -0
- package/lib/modules/Summary/utils.js +4 -18
- package/lib/solution/ScanOrder/index.d.ts +31 -6
- package/lib/solution/ScanOrder/index.js +315 -14
- package/lib/solution/ScanOrder/types.d.ts +52 -2
- package/lib/solution/ScanOrder/utils.d.ts +41 -5
- package/lib/solution/ScanOrder/utils.js +150 -20
- package/lib/solution/VenueBooking/index.d.ts +2 -5
- package/lib/solution/VenueBooking/index.js +13 -6
- package/package.json +1 -1
|
@@ -1,39 +1,114 @@
|
|
|
1
1
|
var _excluded = ["_origin", "identity_key"],
|
|
2
2
|
_excluded2 = ["created_at", "summary", "surcharges"],
|
|
3
3
|
_excluded3 = ["collect_pax", "table_occupancy_duration"];
|
|
4
|
-
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; } } }; }
|
|
5
4
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
6
5
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
7
6
|
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); }
|
|
8
7
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
8
|
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."); }
|
|
10
|
-
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); }
|
|
11
9
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
10
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
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
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; }
|
|
15
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; }
|
|
16
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; }
|
|
17
14
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
18
15
|
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); }
|
|
16
|
+
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; } } }; }
|
|
17
|
+
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); }
|
|
18
|
+
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; }
|
|
19
19
|
import dayjs from "dayjs";
|
|
20
20
|
import Decimal from 'decimal.js';
|
|
21
|
-
import { createEmptySummary } from "../../solution/ScanOrder/utils";
|
|
21
|
+
import { buildProductLineFingerprint, createEmptySummary } from "../../solution/ScanOrder/utils";
|
|
22
|
+
/**
|
|
23
|
+
* 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。
|
|
24
|
+
*
|
|
25
|
+
* 新语义 v2 约定:
|
|
26
|
+
* - `mainPrice` 必须是**已经包含 option 的主商品单价**(即 `metadata.main_product_selling_price`
|
|
27
|
+
* 或 `metadata.main_product_original_price`),option 价格不由本函数叠加。
|
|
28
|
+
* - 套餐价:Σ((bundle.bundle_selling_price ?? bundle.price) × (bundle.num ?? bundle.quantity ?? 1))
|
|
29
|
+
* 当 `useOriginalBundle=true` 时,改用 `bundle.original_price ?? bundle.product_price ?? bundle.price`。
|
|
30
|
+
* - 返回值:保留 2 位小数的字符串,方便直接写回 `selling_price` / `original_price` 字段。
|
|
31
|
+
*
|
|
32
|
+
* 被 `normalizeOrderProduct`、Rules setProduct 钩子、各 Solution 的 setDiscountSelected 共用,
|
|
33
|
+
* 保证合成逻辑单点来源。
|
|
34
|
+
*/
|
|
35
|
+
export function composeLinePrice(params) {
|
|
36
|
+
var mainPrice = params.mainPrice,
|
|
37
|
+
bundle = params.bundle,
|
|
38
|
+
useOriginalBundle = params.useOriginalBundle;
|
|
39
|
+
var total = new Decimal(Number(mainPrice) || 0);
|
|
40
|
+
if (Array.isArray(bundle)) {
|
|
41
|
+
var _iterator = _createForOfIteratorHelper(bundle),
|
|
42
|
+
_step;
|
|
43
|
+
try {
|
|
44
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
45
|
+
var _ref, _item$original_price, _item$bundle_selling_, _ref2, _item$num;
|
|
46
|
+
var item = _step.value;
|
|
47
|
+
var rawPrice = useOriginalBundle ? (_ref = (_item$original_price = item === null || item === void 0 ? void 0 : item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item === null || item === void 0 ? void 0 : item.product_price) !== null && _ref !== void 0 ? _ref : item === null || item === void 0 ? void 0 : item.price : (_item$bundle_selling_ = item === null || item === void 0 ? void 0 : item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item === null || item === void 0 ? void 0 : item.price;
|
|
48
|
+
var price = new Decimal(Number(rawPrice) || 0);
|
|
49
|
+
var rawNum = (_ref2 = (_item$num = item === null || item === void 0 ? void 0 : item.num) !== null && _item$num !== void 0 ? _item$num : item === null || item === void 0 ? void 0 : item.quantity) !== null && _ref2 !== void 0 ? _ref2 : 1;
|
|
50
|
+
var num = new Decimal(Number(rawNum) || 0);
|
|
51
|
+
total = total.plus(price.times(num));
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
_iterator.e(err);
|
|
55
|
+
} finally {
|
|
56
|
+
_iterator.f();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return total.toDecimalPlaces(2).toFixed(2);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 计算 option 单价合计:Σ(option.price × option.num)。
|
|
64
|
+
* 在新语义 v2 下,main_product_original_price = source_product_price + 本函数结果。
|
|
65
|
+
*/
|
|
66
|
+
export function sumOptionUnitPrice(options) {
|
|
67
|
+
var total = new Decimal(0);
|
|
68
|
+
if (!Array.isArray(options)) return total;
|
|
69
|
+
var _iterator2 = _createForOfIteratorHelper(options),
|
|
70
|
+
_step2;
|
|
71
|
+
try {
|
|
72
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
73
|
+
var opt = _step2.value;
|
|
74
|
+
var price = new Decimal(Number(opt === null || opt === void 0 ? void 0 : opt.price) || 0);
|
|
75
|
+
var num = new Decimal(Number(opt === null || opt === void 0 ? void 0 : opt.num) || 0);
|
|
76
|
+
total = total.plus(price.times(num));
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
_iterator2.e(err);
|
|
80
|
+
} finally {
|
|
81
|
+
_iterator2.f();
|
|
82
|
+
}
|
|
83
|
+
return total;
|
|
84
|
+
}
|
|
85
|
+
|
|
22
86
|
/**
|
|
23
87
|
* OrderModule 默认 Rules 钩子工厂。
|
|
24
88
|
*
|
|
25
|
-
*
|
|
26
|
-
* - `selling_price
|
|
27
|
-
*
|
|
28
|
-
* - `
|
|
89
|
+
* 价格语义约定(订单域,v2 composite 口径):
|
|
90
|
+
* - `selling_price`:券后 **行 composite 单价**
|
|
91
|
+
* = `metadata.main_product_selling_price` + Σ(bundle_selling_price × num)。
|
|
92
|
+
* - `original_price`:券前 **行 composite 单价**
|
|
93
|
+
* = `metadata.main_product_original_price` + Σ(bundle 原价 × num)。
|
|
94
|
+
* - `metadata.source_product_price`:主商品/variant 基础价(已应用报价单),不含 option、
|
|
95
|
+
* 不含折扣。**权威源**。
|
|
96
|
+
* - `metadata.main_product_original_price` = source + Σ(option.price × option.num)(含 option、不含折扣)。
|
|
97
|
+
* - `metadata.main_product_selling_price` = main_original − 主商品券 per-unit amount(含 option、含折扣)。
|
|
98
|
+
* - `payment_price`:出站 payload 中由 `selling_price` 派生以兼容后端(composite)。
|
|
29
99
|
*
|
|
30
|
-
* Rules
|
|
31
|
-
* - `getProduct.
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
100
|
+
* Rules 钩子契约(hook_adapt 方案,Rules 内部保持不变):
|
|
101
|
+
* - `getProduct.price` / `getProduct.original_price` 回传 **source-level 主价**
|
|
102
|
+
* (`metadata.source_product_price`)。Rules 内部 `getProductTotalPrice` /
|
|
103
|
+
* `getProductOriginTotalPrice` 会自行叠加 option + bundle,喂 source 可避免 option 双加。
|
|
104
|
+
* - `getProduct.total` = `selling_price × num`(行 composite × num),与 Rules 内部产出的
|
|
105
|
+
* total(source + option + bundle)对齐。
|
|
106
|
+
* - `setProduct` 反向流程:把 Rules 返回的 source-level `main_product_selling_price` / `price`
|
|
107
|
+
* 加回 Σoptions,重新合成含 option 的 main_product_* 并派生 composite。
|
|
108
|
+
* 优先级:
|
|
109
|
+
* 1. `values.main_product_selling_price`(券应用分支,per-unit 券后 source-level 主价)
|
|
110
|
+
* 2. `values.price`(还原分支 `restoredPrice`、good_pass 归零)
|
|
111
|
+
* 3. `values.total / num`(仅当 Rules 只给出总价时的兜底)
|
|
37
112
|
*
|
|
38
113
|
* 导出为纯函数方便单测直接驱动钩子,不依赖 OrderModule 实例。
|
|
39
114
|
*/
|
|
@@ -45,13 +120,40 @@ export function createDefaultOrderRulesHooks() {
|
|
|
45
120
|
return {
|
|
46
121
|
getProduct: function getProduct(product) {
|
|
47
122
|
var _product$_origin, _product$_origin2, _product$_origin3, _product$_origin4;
|
|
123
|
+
// source_product_price 是权威源;兜底链:source → mainSelling − options(反推)→ 行 selling_price
|
|
124
|
+
var metadataAny = product.metadata || {};
|
|
125
|
+
var optionSum = sumOptionUnitPrice(product.product_option_item);
|
|
126
|
+
var sourcePrice;
|
|
127
|
+
if (metadataAny.source_product_price !== undefined) {
|
|
128
|
+
sourcePrice = String(metadataAny.source_product_price);
|
|
129
|
+
} else if (metadataAny.main_product_selling_price !== undefined) {
|
|
130
|
+
sourcePrice = new Decimal(Number(metadataAny.main_product_selling_price) || 0).minus(optionSum).toDecimalPlaces(2).toString();
|
|
131
|
+
} else {
|
|
132
|
+
var _product$selling_pric;
|
|
133
|
+
sourcePrice = String((_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : 0);
|
|
134
|
+
}
|
|
135
|
+
var sourceOriginalPrice;
|
|
136
|
+
if (metadataAny.source_product_price !== undefined) {
|
|
137
|
+
sourceOriginalPrice = String(metadataAny.source_product_price);
|
|
138
|
+
} else if (metadataAny.main_product_original_price !== undefined) {
|
|
139
|
+
sourceOriginalPrice = new Decimal(Number(metadataAny.main_product_original_price) || 0).minus(optionSum).toDecimalPlaces(2).toString();
|
|
140
|
+
} else {
|
|
141
|
+
sourceOriginalPrice = sourcePrice;
|
|
142
|
+
}
|
|
48
143
|
return {
|
|
49
144
|
id: product.product_id,
|
|
50
|
-
|
|
51
|
-
|
|
145
|
+
// Rules 引擎用 _id 作为 processedProductsMap 键;必须与购物车行级 identity 一致,
|
|
146
|
+
// 否则同 SKU 不同小料会在 calcDiscount 重组时互相覆盖。
|
|
147
|
+
// 不透明 identity 契约下,normalizeOrderProduct / restoreTempOrderFromStorage 已保证 identity_key 必存在;
|
|
148
|
+
// 留 fingerprint 分支仅作 Rules 单测里直接传裸 product 时的兜底。
|
|
149
|
+
_id: product.identity_key ? "".concat(product.product_id, "_").concat(product.product_variant_id, "_").concat(product.identity_key) : "".concat(product.product_id, "_").concat(product.product_variant_id, "_").concat(buildProductLineFingerprint(product.product_option_item, product.product_bundle)),
|
|
150
|
+
// Rules 内部 getProductTotalPrice / getProductOriginTotalPrice 会各自再叠加 bundle + option,
|
|
151
|
+
// 所以这里必须喂 source-level(不含 option、不含 bundle、不含折扣)单价,避免双加 option。
|
|
152
|
+
price: sourcePrice,
|
|
153
|
+
// total / origin_total 使用 composite × num,跟 Rules 内部产出的 total 对齐(含 option + bundle)。
|
|
52
154
|
total: new Decimal(product.selling_price || 0).times(product.num || 1).toNumber(),
|
|
53
155
|
origin_total: new Decimal(product.original_price || product.selling_price || 0).times(product.num || 1).toNumber(),
|
|
54
|
-
original_price:
|
|
156
|
+
original_price: sourceOriginalPrice,
|
|
55
157
|
quantity: product.num || 1,
|
|
56
158
|
num: product.num || 1,
|
|
57
159
|
discount_list: product.discount_list || [],
|
|
@@ -64,18 +166,47 @@ export function createDefaultOrderRulesHooks() {
|
|
|
64
166
|
};
|
|
65
167
|
},
|
|
66
168
|
setProduct: function setProduct(product, values) {
|
|
67
|
-
var
|
|
68
|
-
var nextNum = Number((
|
|
69
|
-
var
|
|
169
|
+
var _ref3, _values$quantity, _ref4, _metadataAny$source_p, _values$bundle, _values$discount_list, _values$quantity2;
|
|
170
|
+
var nextNum = Number((_ref3 = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref3 !== void 0 ? _ref3 : 1) || 1;
|
|
171
|
+
var metadataAny = product.metadata || {};
|
|
172
|
+
var existedSource = (_ref4 = (_metadataAny$source_p = metadataAny.source_product_price) !== null && _metadataAny$source_p !== void 0 ? _metadataAny$source_p : product.selling_price) !== null && _ref4 !== void 0 ? _ref4 : '0';
|
|
173
|
+
var nextOptions = product.product_option_item;
|
|
174
|
+
var optionSum = sumOptionUnitPrice(nextOptions);
|
|
175
|
+
|
|
176
|
+
// Rules 返回的 main_product_selling_price / price / total 均为 source-level。
|
|
177
|
+
// 优先级:main_product_selling_price(per-unit 券后 source)> price(还原/good_pass 分支)>
|
|
178
|
+
// total/num(仅当 Rules 只给 total 时的兜底)> 保留当前 source。
|
|
179
|
+
var nextSourceSellingPrice = values.main_product_selling_price !== undefined ? String(values.main_product_selling_price) : values.price !== undefined ? String(values.price) : values.total !== undefined ? toUnitPriceString(values.total, nextNum) : String(existedSource);
|
|
180
|
+
|
|
181
|
+
// 券前 source:values.original_price 是 source-level(Rules 层本就不含 option),
|
|
182
|
+
// 缺省时保留现有 source(券前 = 当前 source)。
|
|
183
|
+
var nextSourceOriginalPrice = values.original_price !== undefined ? String(values.original_price) : String(existedSource);
|
|
184
|
+
|
|
185
|
+
// 含 option 的 main_product_*
|
|
186
|
+
var nextMainSellingPrice = new Decimal(Number(nextSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
187
|
+
var nextMainOriginalPrice = new Decimal(Number(nextSourceOriginalPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
188
|
+
var nextBundle = (_values$bundle = values.bundle) !== null && _values$bundle !== void 0 ? _values$bundle : product.product_bundle;
|
|
189
|
+
var composedSellingPrice = composeLinePrice({
|
|
190
|
+
mainPrice: nextMainSellingPrice,
|
|
191
|
+
bundle: nextBundle
|
|
192
|
+
});
|
|
193
|
+
var composedOriginalPrice = composeLinePrice({
|
|
194
|
+
mainPrice: nextMainOriginalPrice,
|
|
195
|
+
bundle: nextBundle,
|
|
196
|
+
useOriginalBundle: true
|
|
197
|
+
});
|
|
70
198
|
return _objectSpread(_objectSpread({}, product), {}, {
|
|
71
|
-
selling_price:
|
|
72
|
-
original_price:
|
|
199
|
+
selling_price: composedSellingPrice,
|
|
200
|
+
original_price: composedOriginalPrice,
|
|
73
201
|
discount_list: (_values$discount_list = values.discount_list) !== null && _values$discount_list !== void 0 ? _values$discount_list : product.discount_list,
|
|
74
202
|
num: (_values$quantity2 = values.quantity) !== null && _values$quantity2 !== void 0 ? _values$quantity2 : product.num,
|
|
75
|
-
product_bundle:
|
|
76
|
-
metadata: _objectSpread(_objectSpread({},
|
|
77
|
-
|
|
78
|
-
|
|
203
|
+
product_bundle: nextBundle,
|
|
204
|
+
metadata: _objectSpread(_objectSpread({}, metadataAny), {}, {
|
|
205
|
+
source_product_price: nextSourceSellingPrice,
|
|
206
|
+
main_product_selling_price: nextMainSellingPrice,
|
|
207
|
+
main_product_original_price: nextMainOriginalPrice,
|
|
208
|
+
price_schema_version: 2
|
|
209
|
+
})
|
|
79
210
|
});
|
|
80
211
|
}
|
|
81
212
|
};
|
|
@@ -168,6 +299,92 @@ export function formatDateTime(date) {
|
|
|
168
299
|
function normalizeSubmitPlatform(platform) {
|
|
169
300
|
return (platform === null || platform === void 0 ? void 0 : platform.toLowerCase()) === 'pc' ? 'PC' : 'H5';
|
|
170
301
|
}
|
|
302
|
+
|
|
303
|
+
// 出站重命名:后端 checkout 协议字段 option_group_item_id;
|
|
304
|
+
// tempOrder / UI 运行时一律使用 product_option_item_id。仅保留后端契约字段,
|
|
305
|
+
// 与 src/modules/Cart/utils/cartProduct.ts#formatOptionsToOrigin 形状一致。
|
|
306
|
+
function formatSubmitOptionItems(options) {
|
|
307
|
+
if (!Array.isArray(options)) return [];
|
|
308
|
+
return options.map(function (d) {
|
|
309
|
+
var _d$option_group_item_;
|
|
310
|
+
return {
|
|
311
|
+
num: d === null || d === void 0 ? void 0 : d.num,
|
|
312
|
+
option_group_item_id: (_d$option_group_item_ = d === null || d === void 0 ? void 0 : d.option_group_item_id) !== null && _d$option_group_item_ !== void 0 ? _d$option_group_item_ : d === null || d === void 0 ? void 0 : d.product_option_item_id,
|
|
313
|
+
option_group_id: d === null || d === void 0 ? void 0 : d.option_group_id
|
|
314
|
+
};
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
function toBundleNumber(value) {
|
|
318
|
+
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
319
|
+
var parsed = Number(value);
|
|
320
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
321
|
+
}
|
|
322
|
+
function toBundleCustomPriceString(value) {
|
|
323
|
+
var parsed = Number(value);
|
|
324
|
+
if (Number.isFinite(parsed)) return parsed.toFixed(2);
|
|
325
|
+
if (value === null || value === undefined || value === '') return '0.00';
|
|
326
|
+
return String(value);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// 出站补齐:以 additive 方式把 bundle 项补足为后端 checkout 协议所需的形状,
|
|
330
|
+
// 同时把 Summary / Rules 运行时写到 bundle 顶层的 surcharge_fee / relation_surcharge_ids
|
|
331
|
+
// 和来自 _origin 的 product_discount_difference 汇总到 metadata。
|
|
332
|
+
// 保留原对象上已有字段(如 discount_list、metadata.custom_product_bundle_map_id)
|
|
333
|
+
// 以兼容运行时 bundle 归一化、Rules、Summary 的消费。
|
|
334
|
+
function formatSubmitBundleItems(bundle) {
|
|
335
|
+
if (!Array.isArray(bundle)) return [];
|
|
336
|
+
return bundle.map(function (b) {
|
|
337
|
+
var _rawBundle$bundle_sel, _rawBundle$price_type, _ref5, _rawBundle$custom_pri, _rawBundle$surcharge_, _rawBundle$is_charge_, _rawBundle$bundle_var, _rawBundle$extension_, _rawBundle$extension_2, _rawBundle$price_type2, _ref6, _rawBundle$custom_pri2;
|
|
338
|
+
var rawBundle = b && _typeof(b) === 'object' ? b : {};
|
|
339
|
+
var existedMetadata = rawBundle.metadata && _typeof(rawBundle.metadata) === 'object' ? rawBundle.metadata : {};
|
|
340
|
+
var sellingPriceNum = toBundleNumber((_rawBundle$bundle_sel = rawBundle.bundle_selling_price) !== null && _rawBundle$bundle_sel !== void 0 ? _rawBundle$bundle_sel : rawBundle.price, 0);
|
|
341
|
+
var priceNum = toBundleNumber(rawBundle.price, sellingPriceNum);
|
|
342
|
+
var priceType = (_rawBundle$price_type = rawBundle.price_type) !== null && _rawBundle$price_type !== void 0 ? _rawBundle$price_type : '';
|
|
343
|
+
var customPriceStr = toBundleCustomPriceString((_ref5 = (_rawBundle$custom_pri = rawBundle.custom_price) !== null && _rawBundle$custom_pri !== void 0 ? _rawBundle$custom_pri : rawBundle.bundle_selling_price) !== null && _ref5 !== void 0 ? _ref5 : rawBundle.price);
|
|
344
|
+
var relationSurchargeIds = Array.isArray(rawBundle.relation_surcharge_ids) ? rawBundle.relation_surcharge_ids : Array.isArray(existedMetadata.relation_surcharge_ids) ? existedMetadata.relation_surcharge_ids : [];
|
|
345
|
+
var surchargeFee = toBundleNumber((_rawBundle$surcharge_ = rawBundle.surcharge_fee) !== null && _rawBundle$surcharge_ !== void 0 ? _rawBundle$surcharge_ : existedMetadata.surcharge_fee, 0);
|
|
346
|
+
var productDiscountDifference = toBundleNumber(existedMetadata.product_discount_difference, 0);
|
|
347
|
+
return _objectSpread(_objectSpread({}, rawBundle), {}, {
|
|
348
|
+
is_charge_tax: (_rawBundle$is_charge_ = rawBundle.is_charge_tax) !== null && _rawBundle$is_charge_ !== void 0 ? _rawBundle$is_charge_ : 0,
|
|
349
|
+
tax_fee: toBundleNumber(rawBundle.tax_fee, 0),
|
|
350
|
+
bundle_variant_id: (_rawBundle$bundle_var = rawBundle.bundle_variant_id) !== null && _rawBundle$bundle_var !== void 0 ? _rawBundle$bundle_var : 0,
|
|
351
|
+
num: toBundleNumber(rawBundle.num, 1),
|
|
352
|
+
extension_id: (_rawBundle$extension_ = rawBundle.extension_id) !== null && _rawBundle$extension_ !== void 0 ? _rawBundle$extension_ : 0,
|
|
353
|
+
extension_type: (_rawBundle$extension_2 = rawBundle.extension_type) !== null && _rawBundle$extension_2 !== void 0 ? _rawBundle$extension_2 : 'normal',
|
|
354
|
+
price: priceNum,
|
|
355
|
+
price_type: priceType,
|
|
356
|
+
price_type_ext: (_rawBundle$price_type2 = rawBundle.price_type_ext) !== null && _rawBundle$price_type2 !== void 0 ? _rawBundle$price_type2 : '',
|
|
357
|
+
custom_price: customPriceStr,
|
|
358
|
+
custom_price_type: (_ref6 = (_rawBundle$custom_pri2 = rawBundle.custom_price_type) !== null && _rawBundle$custom_pri2 !== void 0 ? _rawBundle$custom_pri2 : priceType) !== null && _ref6 !== void 0 ? _ref6 : '',
|
|
359
|
+
bundle_selling_price: sellingPriceNum,
|
|
360
|
+
option: formatSubmitOptionItems(rawBundle.option),
|
|
361
|
+
bundle_group_id: rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.group_id,
|
|
362
|
+
bundle_id: rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.id,
|
|
363
|
+
metadata: _objectSpread(_objectSpread({}, existedMetadata), {}, {
|
|
364
|
+
surcharge_fee: surchargeFee,
|
|
365
|
+
relation_surcharge_ids: relationSurchargeIds,
|
|
366
|
+
product_discount_difference: productDiscountDifference
|
|
367
|
+
})
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* 把 tempOrder product 打包成出站 submit payload。
|
|
374
|
+
*
|
|
375
|
+
* 价格字段语义(出站口径,v2 composite):
|
|
376
|
+
* - `selling_price`:**行 composite 券后单价**
|
|
377
|
+
* = `metadata.main_product_selling_price` + Σ(bundle_selling_price × num)。
|
|
378
|
+
* - `original_price`:**行 composite 券前单价**
|
|
379
|
+
* = `metadata.main_product_original_price` + Σ(bundle 原价 × num)。
|
|
380
|
+
* - `payment_price`:兼容后端的出站字段,直接从 `selling_price` 派生(composite)。
|
|
381
|
+
* - `metadata.source_product_price`:主商品/variant 基础价(不含 option、不含折扣),权威源。
|
|
382
|
+
* - `metadata.main_product_original_price`:含 option、不含折扣。
|
|
383
|
+
* - `metadata.main_product_selling_price`:含 option、含主商品折扣。
|
|
384
|
+
* - `metadata.price_schema_version`:schema 版本号(当前 = 2),用于跨端协商价格口径。
|
|
385
|
+
*
|
|
386
|
+
* 本函数不再改造价格字段形状,仅做字段/metadata 裁剪。
|
|
387
|
+
*/
|
|
171
388
|
function normalizeSubmitProduct(product) {
|
|
172
389
|
var _origin = product._origin,
|
|
173
390
|
identity_key = product.identity_key,
|
|
@@ -178,7 +395,7 @@ function normalizeSubmitProduct(product) {
|
|
|
178
395
|
if (rawMetadata.unique_identification_number) {
|
|
179
396
|
cleanMetadata.unique_identification_number = rawMetadata.unique_identification_number;
|
|
180
397
|
}
|
|
181
|
-
var priceMetaKeys = ['main_product_original_price', 'main_product_selling_price', 'source_product_price'];
|
|
398
|
+
var priceMetaKeys = ['main_product_original_price', 'main_product_selling_price', 'source_product_price', 'price_schema_version'];
|
|
182
399
|
for (var _i = 0, _priceMetaKeys = priceMetaKeys; _i < _priceMetaKeys.length; _i++) {
|
|
183
400
|
var key = _priceMetaKeys[_i];
|
|
184
401
|
if (rawMetadata[key] !== undefined) {
|
|
@@ -194,11 +411,12 @@ function normalizeSubmitProduct(product) {
|
|
|
194
411
|
return _objectSpread(_objectSpread(_objectSpread({}, submitProduct), bookingUid ? {
|
|
195
412
|
booking_uid: bookingUid
|
|
196
413
|
} : {}), {}, {
|
|
197
|
-
product_option_item: submitProduct.product_option_item
|
|
414
|
+
product_option_item: formatSubmitOptionItems(submitProduct.product_option_item),
|
|
198
415
|
discount_list: submitProduct.discount_list || [],
|
|
199
|
-
product_bundle: submitProduct.product_bundle
|
|
416
|
+
product_bundle: formatSubmitBundleItems(submitProduct.product_bundle),
|
|
200
417
|
metadata: cleanMetadata,
|
|
201
|
-
//
|
|
418
|
+
// 出站兼容:后端消费 payment_price 字段,这里从 selling_price 直接派生。
|
|
419
|
+
// 新语义下 selling_price 是 composite(含 option/bundle),payment_price 同语义。
|
|
202
420
|
payment_price: submitProduct.selling_price
|
|
203
421
|
});
|
|
204
422
|
}
|
|
@@ -206,19 +424,19 @@ var SUBMIT_BOOKING_METADATA_WHITELIST = ['unique_identification_number', 'collec
|
|
|
206
424
|
export function normalizeSubmitBooking(booking) {
|
|
207
425
|
var rawMetadata = booking.metadata || {};
|
|
208
426
|
var cleanMetadata = {};
|
|
209
|
-
var
|
|
210
|
-
|
|
427
|
+
var _iterator3 = _createForOfIteratorHelper(SUBMIT_BOOKING_METADATA_WHITELIST),
|
|
428
|
+
_step3;
|
|
211
429
|
try {
|
|
212
|
-
for (
|
|
213
|
-
var key =
|
|
430
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
431
|
+
var key = _step3.value;
|
|
214
432
|
if (rawMetadata[key] !== undefined) {
|
|
215
433
|
cleanMetadata[key] = rawMetadata[key];
|
|
216
434
|
}
|
|
217
435
|
}
|
|
218
436
|
} catch (err) {
|
|
219
|
-
|
|
437
|
+
_iterator3.e(err);
|
|
220
438
|
} finally {
|
|
221
|
-
|
|
439
|
+
_iterator3.f();
|
|
222
440
|
}
|
|
223
441
|
return _objectSpread(_objectSpread({}, booking), {}, {
|
|
224
442
|
metadata: cleanMetadata
|
|
@@ -299,7 +517,7 @@ export function createDefaultTempOrder(params) {
|
|
|
299
517
|
};
|
|
300
518
|
}
|
|
301
519
|
export function buildSubmitPayload(params) {
|
|
302
|
-
var
|
|
520
|
+
var _ref7, _ref8, _ref9, _tempOrder$is_price_i, _tempOrder$is_deposit;
|
|
303
521
|
var tempOrder = params.tempOrder,
|
|
304
522
|
cacheId = params.cacheId,
|
|
305
523
|
_params$now = params.now,
|
|
@@ -347,10 +565,10 @@ export function buildSubmitPayload(params) {
|
|
|
347
565
|
var payload = _objectSpread(_objectSpread({}, tempOrderRest), {}, {
|
|
348
566
|
platform: normalizeSubmitPlatform(platform !== null && platform !== void 0 ? platform : tempOrder.platform),
|
|
349
567
|
request_unique_idempotency_token: cacheId,
|
|
350
|
-
type: (
|
|
351
|
-
business_code: (
|
|
568
|
+
type: (_ref7 = type !== null && type !== void 0 ? type : tempOrder.type) !== null && _ref7 !== void 0 ? _ref7 : 'table-order',
|
|
569
|
+
business_code: (_ref8 = businessCode !== null && businessCode !== void 0 ? businessCode : tempOrder.business_code) !== null && _ref8 !== void 0 ? _ref8 : 'table-order',
|
|
352
570
|
sales_channel: tempOrder.sales_channel || 'my_pisel',
|
|
353
|
-
order_sales_channel: (
|
|
571
|
+
order_sales_channel: (_ref9 = channel !== null && channel !== void 0 ? channel : tempOrder.order_sales_channel) !== null && _ref9 !== void 0 ? _ref9 : 'online_store',
|
|
354
572
|
status: tempOrder.status || 'normal',
|
|
355
573
|
payment_status: tempOrder.payment_status || 'payment_processing',
|
|
356
574
|
// shipping_status: tempOrder.shipping_status || 'unfulfilled',
|
|
@@ -374,10 +592,10 @@ export function buildSubmitPayload(params) {
|
|
|
374
592
|
// holder: tempOrder.holder || null,
|
|
375
593
|
// summary,
|
|
376
594
|
metadata: function () {
|
|
377
|
-
var
|
|
378
|
-
_collectPax =
|
|
379
|
-
_tableOccupancyDuration =
|
|
380
|
-
rest = _objectWithoutProperties(
|
|
595
|
+
var _ref10 = tempOrder.metadata || {},
|
|
596
|
+
_collectPax = _ref10.collect_pax,
|
|
597
|
+
_tableOccupancyDuration = _ref10.table_occupancy_duration,
|
|
598
|
+
rest = _objectWithoutProperties(_ref10, _excluded3);
|
|
381
599
|
return _objectSpread({}, rest);
|
|
382
600
|
}(),
|
|
383
601
|
products: (tempOrder.products || []).map(function (product) {
|
|
@@ -390,8 +608,25 @@ export function buildSubmitPayload(params) {
|
|
|
390
608
|
now: now
|
|
391
609
|
}) : payload;
|
|
392
610
|
}
|
|
611
|
+
|
|
612
|
+
/** 加单(scanOrderMore)不应提交 booking 关联的虚拟规则商品行 */
|
|
613
|
+
export function filterProductsForScanOrderMore(products) {
|
|
614
|
+
return (products || []).filter(function (p) {
|
|
615
|
+
var _p$metadata;
|
|
616
|
+
return ((_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.is_rule) !== true;
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* 历史 V1 加餐结构映射器。
|
|
622
|
+
*
|
|
623
|
+
* @deprecated 加餐(`PUT /order/order/product/:id`)已改为与正常 checkout 共用
|
|
624
|
+
* `ScanOrderSubmitProduct` 新结构(见 `OrderModule.submitTempOrder` 的加餐分支)。
|
|
625
|
+
* 本函数仅保留以兼容历史接入方,未来会移除。新代码请勿再调用。
|
|
626
|
+
*/
|
|
393
627
|
export function formatV1Product(products) {
|
|
394
628
|
return products.map(function (product) {
|
|
629
|
+
var _product$note;
|
|
395
630
|
return {
|
|
396
631
|
bundle: product.product_bundle,
|
|
397
632
|
key: product.product_id,
|
|
@@ -399,6 +634,7 @@ export function formatV1Product(products) {
|
|
|
399
634
|
product_id: product.product_id,
|
|
400
635
|
product_variant_id: product.product_variant_id,
|
|
401
636
|
num: product.num,
|
|
637
|
+
note: String((_product$note = product.note) !== null && _product$note !== void 0 ? _product$note : ''),
|
|
402
638
|
rowKey: product.product_id,
|
|
403
639
|
session: null,
|
|
404
640
|
unique: createUuidV4()
|
|
@@ -19,41 +19,6 @@ function getSafeNum(num) {
|
|
|
19
19
|
if (num < 1) return 1;
|
|
20
20
|
return Math.floor(num);
|
|
21
21
|
}
|
|
22
|
-
function getVariantPrice(product) {
|
|
23
|
-
var _product$metadata;
|
|
24
|
-
var variantId = Number(product.product_variant_id || 0);
|
|
25
|
-
if (!variantId) return null;
|
|
26
|
-
|
|
27
|
-
// TODO: callbackData 在 src/ 内无写入方,暂时注释掉观察
|
|
28
|
-
// const callbackVariantList = product._origin?.callbackData?.origin?.variant;
|
|
29
|
-
// if (Array.isArray(callbackVariantList)) {
|
|
30
|
-
// const variant = callbackVariantList.find(
|
|
31
|
-
// (item: any) => Number(item.id) === variantId,
|
|
32
|
-
// );
|
|
33
|
-
// if (variant?.price !== undefined && variant?.price !== null) {
|
|
34
|
-
// return toDecimal(variant.price);
|
|
35
|
-
// }
|
|
36
|
-
// }
|
|
37
|
-
|
|
38
|
-
var metadataVariantList = (_product$metadata = product.metadata) === null || _product$metadata === void 0 || (_product$metadata = _product$metadata.origin) === null || _product$metadata === void 0 ? void 0 : _product$metadata.variant;
|
|
39
|
-
if (Array.isArray(metadataVariantList)) {
|
|
40
|
-
var variant = metadataVariantList.find(function (item) {
|
|
41
|
-
return Number(item.id) === variantId;
|
|
42
|
-
});
|
|
43
|
-
if ((variant === null || variant === void 0 ? void 0 : variant.price) !== undefined && (variant === null || variant === void 0 ? void 0 : variant.price) !== null) {
|
|
44
|
-
return toDecimal(variant.price);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
function getOptionUnitPrice(product) {
|
|
50
|
-
var optionItems = product.product_option_item || [];
|
|
51
|
-
return optionItems.reduce(function (sum, item) {
|
|
52
|
-
var quantity = getSafeNum(item === null || item === void 0 ? void 0 : item.num);
|
|
53
|
-
var itemPrice = toDecimal(item === null || item === void 0 ? void 0 : item.price);
|
|
54
|
-
return sum.plus(itemPrice.times(quantity));
|
|
55
|
-
}, new Decimal(0));
|
|
56
|
-
}
|
|
57
22
|
function getBundleUnitPrice(product) {
|
|
58
23
|
var useOriginal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
59
24
|
var bundleItems = product.product_bundle || [];
|
|
@@ -65,19 +30,27 @@ function getBundleUnitPrice(product) {
|
|
|
65
30
|
}, new Decimal(0));
|
|
66
31
|
}
|
|
67
32
|
|
|
68
|
-
//
|
|
33
|
+
// 单商品 composite 单价(随后再乘商品数量):
|
|
34
|
+
// 新语义 v2 下 `metadata.main_product_selling_price` 已经是"含 option、含主商品折扣"的主价,
|
|
35
|
+
// composite 单价 = main_product_selling_price + Σ(bundle_selling_price × num)。
|
|
36
|
+
// 不再叠加 options(会重复计算),也不再用 variant/selling_price 兜底(选项已固化进 metadata)。
|
|
69
37
|
function getUnitPaymentTotal(product) {
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
|
|
38
|
+
var _product$metadata, _product$metadata2;
|
|
39
|
+
var mainSelling = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.main_product_selling_price;
|
|
40
|
+
var mainOriginal = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.main_product_original_price;
|
|
41
|
+
var basePrice = mainSelling !== undefined ? toDecimal(mainSelling) : mainOriginal !== undefined ? toDecimal(mainOriginal) : toDecimal(product.selling_price);
|
|
42
|
+
return basePrice.plus(getBundleUnitPrice(product));
|
|
73
43
|
}
|
|
74
44
|
function getUnitOriginalTotal(product) {
|
|
75
|
-
var
|
|
76
|
-
|
|
45
|
+
var _product$metadata3, _product$metadata4;
|
|
46
|
+
var mainOriginal = (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.main_product_original_price;
|
|
47
|
+
var mainSelling = (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.main_product_selling_price;
|
|
48
|
+
var basePrice = mainOriginal !== undefined ? toDecimal(mainOriginal) : mainSelling !== undefined ? toDecimal(mainSelling) : toDecimal(product.original_price || product.selling_price);
|
|
49
|
+
return basePrice.plus(getBundleUnitPrice(product, true));
|
|
77
50
|
}
|
|
78
51
|
function buildSurchargeServiceItems(products) {
|
|
79
52
|
return products.map(function (product) {
|
|
80
|
-
var _product$is_charge_ta, _product$
|
|
53
|
+
var _product$is_charge_ta, _product$metadata5, _product$metadata6;
|
|
81
54
|
var quantity = getSafeNum(product.num);
|
|
82
55
|
var unitTotal = getUnitPaymentTotal(product);
|
|
83
56
|
return {
|
|
@@ -99,8 +72,8 @@ function buildSurchargeServiceItems(products) {
|
|
|
99
72
|
options: product.product_option_item || [],
|
|
100
73
|
relation_details: [],
|
|
101
74
|
metadata: product.metadata || {},
|
|
102
|
-
start_date: ((_product$
|
|
103
|
-
start_time: ((_product$
|
|
75
|
+
start_date: ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.start_date) || '',
|
|
76
|
+
start_time: ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.start_time) || ''
|
|
104
77
|
};
|
|
105
78
|
});
|
|
106
79
|
}
|
|
@@ -221,11 +194,6 @@ function isBundleMarkupOrDiscount(item) {
|
|
|
221
194
|
var isDiscount = (item === null || item === void 0 ? void 0 : item.price_type) === 'markdown' && ((item === null || item === void 0 ? void 0 : item.price_type_ext) === '' || !(item !== null && item !== void 0 && item.price_type_ext));
|
|
222
195
|
return isMarkup || isDiscount;
|
|
223
196
|
}
|
|
224
|
-
function getDiscountListAmount(discountList) {
|
|
225
|
-
return (discountList || []).reduce(function (total, d) {
|
|
226
|
-
return total.plus(toDecimal(d.amount));
|
|
227
|
-
}, new Decimal(0));
|
|
228
|
-
}
|
|
229
197
|
|
|
230
198
|
/**
|
|
231
199
|
* 计算单个商品税费(返回精确值,不四舍五入)。
|
|
@@ -250,20 +218,17 @@ function calculateSingleItemTax(params) {
|
|
|
250
218
|
}
|
|
251
219
|
|
|
252
220
|
/**
|
|
253
|
-
*
|
|
254
|
-
*
|
|
221
|
+
* 获取主商品折扣后总价(含 option、含主商品折扣、含加价/减价 bundle)。
|
|
222
|
+
*
|
|
223
|
+
* 新语义 v2 下:
|
|
224
|
+
* - `metadata.main_product_selling_price` 已是"含 option、含折扣"的主价,直接读即可;
|
|
225
|
+
* - 无需再 `minus(mainDiscountAmount)` 或 `plus(getOptionUnitPrice)`;
|
|
226
|
+
* - 仅需叠加 `markup` / `markdown` 类 bundle(原价 bundle 已由 `calculateProductsTax` 独立处理)。
|
|
255
227
|
*/
|
|
256
228
|
function getMainProductPaymentTotal(product) {
|
|
257
|
-
var _product$metadata$mai, _product$
|
|
258
|
-
var
|
|
259
|
-
var total =
|
|
260
|
-
var mainDiscountList = ((_product$_origin3 = product._origin) === null || _product$_origin3 === void 0 || (_product$_origin3 = _product$_origin3.product) === null || _product$_origin3 === void 0 ? void 0 : _product$_origin3.discount_list) || ((_product$_origin4 = product._origin) === null || _product$_origin4 === void 0 ? void 0 : _product$_origin4.discount_list) || [];
|
|
261
|
-
var mainDiscountAmount = getDiscountListAmount(mainDiscountList.filter(function (d) {
|
|
262
|
-
var _d$metadata;
|
|
263
|
-
return !(d !== null && d !== void 0 && (_d$metadata = d.metadata) !== null && _d$metadata !== void 0 && _d$metadata.custom_product_bundle_map_id);
|
|
264
|
-
}));
|
|
265
|
-
total = total.minus(mainDiscountAmount);
|
|
266
|
-
total = total.plus(getOptionUnitPrice(product));
|
|
229
|
+
var _ref2, _product$metadata$mai, _product$metadata7, _product$metadata8;
|
|
230
|
+
var mainSelling = (_ref2 = (_product$metadata$mai = (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.main_product_selling_price) !== null && _product$metadata$mai !== void 0 ? _product$metadata$mai : (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.main_product_original_price) !== null && _ref2 !== void 0 ? _ref2 : 0;
|
|
231
|
+
var total = toDecimal(mainSelling);
|
|
267
232
|
var bundleItems = product.product_bundle || [];
|
|
268
233
|
var _iterator5 = _createForOfIteratorHelper(bundleItems),
|
|
269
234
|
_step5;
|
|
@@ -271,8 +236,8 @@ function getMainProductPaymentTotal(product) {
|
|
|
271
236
|
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
272
237
|
var bundleItem = _step5.value;
|
|
273
238
|
if (isBundleMarkupOrDiscount(bundleItem)) {
|
|
274
|
-
var
|
|
275
|
-
total = total.plus(toDecimal((
|
|
239
|
+
var _ref3, _bundleItem$bundle_se;
|
|
240
|
+
total = total.plus(toDecimal((_ref3 = (_bundleItem$bundle_se = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se !== void 0 ? _bundleItem$bundle_se : bundleItem.price) !== null && _ref3 !== void 0 ? _ref3 : 0));
|
|
276
241
|
}
|
|
277
242
|
}
|
|
278
243
|
} catch (err) {
|
|
@@ -340,24 +305,24 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
|
340
305
|
_step7;
|
|
341
306
|
try {
|
|
342
307
|
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
343
|
-
var _bundleItem$num,
|
|
308
|
+
var _bundleItem$num, _ref4, _bundleItem$bundle_se2, _ref5, _ref6, _bundleItem$original_, _ref7, _bundleItem$is_charge, _ref8, _bundleItem$is_charge2;
|
|
344
309
|
var bundleItem = _step7.value;
|
|
345
310
|
if (!isBundleOriginalPrice(bundleItem)) continue;
|
|
346
311
|
var bundleQuantity = new Decimal(getSafeNum((_bundleItem$num = bundleItem.num) !== null && _bundleItem$num !== void 0 ? _bundleItem$num : bundleItem.quantity));
|
|
347
|
-
var bundlePrice = toDecimal((
|
|
348
|
-
var bundleOriginalPrice = toDecimal((
|
|
312
|
+
var bundlePrice = toDecimal((_ref4 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref4 !== void 0 ? _ref4 : 0);
|
|
313
|
+
var bundleOriginalPrice = toDecimal((_ref5 = (_ref6 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref6 !== void 0 ? _ref6 : bundleItem.price) !== null && _ref5 !== void 0 ? _ref5 : 0);
|
|
349
314
|
var bundleTaxPrecise = calculateSingleItemTax({
|
|
350
315
|
price: bundlePrice,
|
|
351
316
|
taxRate: rate,
|
|
352
317
|
isPriceIncludeTax: isPriceIncludeTax,
|
|
353
|
-
isChargeTax: (
|
|
318
|
+
isChargeTax: (_ref7 = (_bundleItem$is_charge = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge !== void 0 ? _bundleItem$is_charge : product.is_charge_tax) !== null && _ref7 !== void 0 ? _ref7 : 0
|
|
354
319
|
});
|
|
355
320
|
var bundleTaxRounded = bundleTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
|
|
356
321
|
var bundleOrigTaxPrecise = calculateSingleItemTax({
|
|
357
322
|
price: bundleOriginalPrice,
|
|
358
323
|
taxRate: rate,
|
|
359
324
|
isPriceIncludeTax: isPriceIncludeTax,
|
|
360
|
-
isChargeTax: (
|
|
325
|
+
isChargeTax: (_ref8 = (_bundleItem$is_charge2 = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge2 !== void 0 ? _bundleItem$is_charge2 : product.is_charge_tax) !== null && _ref8 !== void 0 ? _ref8 : 0
|
|
361
326
|
});
|
|
362
327
|
var bundleOrigTaxRounded = bundleOrigTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
|
|
363
328
|
bundleItem.tax_fee = bundleTaxRounded.toNumber();
|