@pisell/pisellos 2.1.148 → 2.1.150
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/Discount/index.d.ts +6 -2
- package/dist/modules/Discount/index.js +14 -8
- package/dist/modules/Order/index.js +3 -1
- package/dist/modules/Summary/utils.js +38 -13
- package/dist/solution/ShopDiscount/index.d.ts +2 -1
- package/dist/solution/ShopDiscount/index.js +32 -20
- package/dist/solution/ShopDiscount/types.d.ts +1 -0
- package/lib/modules/Discount/index.d.ts +6 -2
- package/lib/modules/Discount/index.js +3 -1
- package/lib/modules/Order/index.js +1 -1
- package/lib/modules/Summary/utils.js +21 -1
- package/lib/solution/ShopDiscount/index.d.ts +2 -1
- package/lib/solution/ShopDiscount/index.js +10 -4
- package/lib/solution/ShopDiscount/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -17,14 +17,18 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
17
17
|
setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
|
|
18
18
|
getOriginalDiscountList(): Discount[];
|
|
19
19
|
loadPrepareConfig(params: {
|
|
20
|
-
action?: 'create';
|
|
20
|
+
action?: 'create' | 'edit';
|
|
21
21
|
with_good_pass: 0 | 1;
|
|
22
22
|
with_discount_card: 0 | 1;
|
|
23
23
|
customer_id: number;
|
|
24
24
|
with_wallet_pass_holder: 0 | 1;
|
|
25
25
|
request_timezone: string;
|
|
26
|
+
order_id?: number;
|
|
27
|
+
}): Promise<Discount[]>;
|
|
28
|
+
batchSearch(code: string, options?: {
|
|
29
|
+
customerId?: number;
|
|
30
|
+
orderId?: number;
|
|
26
31
|
}): Promise<Discount[]>;
|
|
27
|
-
batchSearch(code: string, customerId?: number): Promise<Discount[]>;
|
|
28
32
|
batchSearchByProductIds(productIds: number[]): Promise<any>;
|
|
29
33
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
30
34
|
private checkUsageCreditsLimit;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
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 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; }
|
|
3
|
+
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; }
|
|
2
4
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
5
|
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."); }
|
|
4
6
|
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); }
|
|
@@ -176,13 +178,14 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
176
178
|
}, {
|
|
177
179
|
key: "batchSearch",
|
|
178
180
|
value: function () {
|
|
179
|
-
var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code,
|
|
180
|
-
var result, resultDiscountList;
|
|
181
|
+
var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, options) {
|
|
182
|
+
var _ref, customerId, orderId, result, resultDiscountList;
|
|
181
183
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
182
184
|
while (1) switch (_context5.prev = _context5.next) {
|
|
183
185
|
case 0:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
+
_ref = options || {}, customerId = _ref.customerId, orderId = _ref.orderId;
|
|
187
|
+
_context5.next = 3;
|
|
188
|
+
return this.request.get("/machinecode/batch-search", _objectSpread(_objectSpread({
|
|
186
189
|
code: code,
|
|
187
190
|
translate_flag: 1,
|
|
188
191
|
tags: ['good_pass', 'product_discount_card'],
|
|
@@ -190,14 +193,17 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
190
193
|
relation_product: 1,
|
|
191
194
|
with: ['extensionData', 'customScheduleSnapshot', 'holder.detail'],
|
|
192
195
|
order_behavior_count: 1,
|
|
193
|
-
order_behavior_count_customer_id: customerId || 1
|
|
196
|
+
order_behavior_count_customer_id: customerId || 1
|
|
197
|
+
}, orderId ? {
|
|
198
|
+
order_behavior_count_order_id: orderId
|
|
199
|
+
} : {}), {}, {
|
|
194
200
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
195
|
-
});
|
|
196
|
-
case
|
|
201
|
+
}));
|
|
202
|
+
case 3:
|
|
197
203
|
result = _context5.sent;
|
|
198
204
|
resultDiscountList = this.filterEnabledDiscountList((result === null || result === void 0 ? void 0 : result.data) || []) || [];
|
|
199
205
|
return _context5.abrupt("return", resultDiscountList);
|
|
200
|
-
case
|
|
206
|
+
case 6:
|
|
201
207
|
case "end":
|
|
202
208
|
return _context5.stop();
|
|
203
209
|
}
|
|
@@ -233,7 +233,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
233
233
|
while (1) switch (_context3.prev = _context3.next) {
|
|
234
234
|
case 0:
|
|
235
235
|
_context3.next = 2;
|
|
236
|
-
return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.batchSearch(code,
|
|
236
|
+
return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.batchSearch(code, {
|
|
237
|
+
customerId: customerId
|
|
238
|
+
});
|
|
237
239
|
case 2:
|
|
238
240
|
_context3.t0 = _context3.sent;
|
|
239
241
|
if (_context3.t0) {
|
|
@@ -685,25 +685,50 @@ var getBundleItemIsDiscountPrice = function getBundleItemIsDiscountPrice(item) {
|
|
|
685
685
|
var getBundleItemIsMarkupOrDiscountPrice = function getBundleItemIsMarkupOrDiscountPrice(item) {
|
|
686
686
|
return getBundleItemIsMarkupPrice(item) || getBundleItemIsDiscountPrice(item);
|
|
687
687
|
};
|
|
688
|
+
var getDiscountAmount = function getDiscountAmount(discounts) {
|
|
689
|
+
return (discounts || []).reduce(function (total, discount) {
|
|
690
|
+
return total.add(new Decimal(discount.amount || 0));
|
|
691
|
+
}, new Decimal(0)).toNumber();
|
|
692
|
+
};
|
|
688
693
|
|
|
689
694
|
/**
|
|
690
695
|
* 获取主商品加价减价后的总价 (主商品价格 + 子商品加价减价)
|
|
691
696
|
*/
|
|
692
697
|
var getMainProductTotal = function getMainProductTotal(item) {
|
|
693
|
-
var _ref8, _ref9, _item$main_product_se, _item$metadata, _item$metadata2;
|
|
698
|
+
var _ref8, _ref9, _item$main_product_se, _item$metadata, _item$metadata2, _item$metadata3, _item$metadata4;
|
|
694
699
|
// 新语义 v2 下 `main_product_selling_price` / `metadata.main_product_selling_price`
|
|
695
700
|
// 已经是"含 option、含主商品折扣"的主价,直接作为主商品基准,无需再减折扣或加 option。
|
|
696
701
|
// 仅需叠加 markup / markdown 类 bundle(原价 bundle 的税费单独处理)。
|
|
697
702
|
var total = new Decimal((_ref8 = (_ref9 = (_item$main_product_se = item === null || item === void 0 ? void 0 : item.main_product_selling_price) !== null && _item$main_product_se !== void 0 ? _item$main_product_se : item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.main_product_selling_price) !== null && _ref9 !== void 0 ? _ref9 : item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.main_product_original_price) !== null && _ref8 !== void 0 ? _ref8 : 0);
|
|
703
|
+
|
|
704
|
+
// 做个兜底 如果新语义价格字段都没有,则切换回老逻辑
|
|
705
|
+
var hasMainProductPrice = (item === null || item === void 0 ? void 0 : item.main_product_selling_price) != null || (item === null || item === void 0 || (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.main_product_selling_price) != null || (item === null || item === void 0 || (_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.main_product_original_price) != null;
|
|
706
|
+
if (!hasMainProductPrice) {
|
|
707
|
+
var _ref10, _ref11, _item$main_product_se2, _item$metadata5, _item$_origin3, _item$_originData;
|
|
708
|
+
total = new Decimal((_ref10 = (_ref11 = (_item$main_product_se2 = item === null || item === void 0 ? void 0 : item.main_product_selling_price) !== null && _item$main_product_se2 !== void 0 ? _item$main_product_se2 : item === null || item === void 0 || (_item$metadata5 = item.metadata) === null || _item$metadata5 === void 0 ? void 0 : _item$metadata5.main_product_selling_price) !== null && _ref11 !== void 0 ? _ref11 : item.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
|
|
709
|
+
var discount = (item === null || item === void 0 || (_item$_origin3 = item._origin) === null || _item$_origin3 === void 0 || (_item$_origin3 = _item$_origin3.product) === null || _item$_origin3 === void 0 ? void 0 : _item$_origin3.discount_list) || (item === null || item === void 0 || (_item$_originData = item._originData) === null || _item$_originData === void 0 || (_item$_originData = _item$_originData.product) === null || _item$_originData === void 0 || (_item$_originData = _item$_originData.discount_list) === null || _item$_originData === void 0 ? void 0 : _item$_originData.filter(function (item) {
|
|
710
|
+
var _item$metadata6;
|
|
711
|
+
return !(item !== null && item !== void 0 && (_item$metadata6 = item.metadata) !== null && _item$metadata6 !== void 0 && _item$metadata6.custom_product_bundle_map_id);
|
|
712
|
+
})) || [];
|
|
713
|
+
var mainProductDiscountAmount = getDiscountAmount(discount);
|
|
714
|
+
total = total.minus(mainProductDiscountAmount);
|
|
715
|
+
|
|
716
|
+
// 单规格
|
|
717
|
+
if (item !== null && item !== void 0 && item.option && Array.isArray(item === null || item === void 0 ? void 0 : item.option)) {
|
|
718
|
+
total = total.add(item === null || item === void 0 ? void 0 : item.option.reduce(function (t, option) {
|
|
719
|
+
return t.add(new Decimal(option.price || 0).mul(option.num || 1));
|
|
720
|
+
}, new Decimal(0)));
|
|
721
|
+
}
|
|
722
|
+
}
|
|
698
723
|
var _iterator4 = _createForOfIteratorHelper((item === null || item === void 0 ? void 0 : item.bundle) || []),
|
|
699
724
|
_step4;
|
|
700
725
|
try {
|
|
701
726
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
702
727
|
var bundleItem = _step4.value;
|
|
703
728
|
if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
|
|
704
|
-
var
|
|
729
|
+
var _ref12, _bundleItem$bundle_se2;
|
|
705
730
|
// IMPORTANT: 套餐子商品如果应用了 discount,bundle_selling_price 和 price 其实都已经是折后价格了,不需要单独再减一次
|
|
706
|
-
var bundleItemTotal = new Decimal((
|
|
731
|
+
var bundleItemTotal = new Decimal((_ref12 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref12 !== void 0 ? _ref12 : 0);
|
|
707
732
|
total = total.add(bundleItemTotal);
|
|
708
733
|
}
|
|
709
734
|
}
|
|
@@ -823,12 +848,12 @@ var isProductMatchSurchargeCondition = function isProductMatchSurchargeCondition
|
|
|
823
848
|
* @param options.scheduleById schedule 映射表:`{ [scheduleId]: schedule }`(用于根据配置的 `available_schedule_ids` 做日程匹配)
|
|
824
849
|
* @returns 附加费列表(仅返回金额 > 0 的项)
|
|
825
850
|
*/
|
|
826
|
-
export var getSurcharge = function getSurcharge(
|
|
851
|
+
export var getSurcharge = function getSurcharge(_ref13, options) {
|
|
827
852
|
var _service$filter;
|
|
828
|
-
var service =
|
|
829
|
-
addons =
|
|
830
|
-
bookingDetail =
|
|
831
|
-
bookingId =
|
|
853
|
+
var service = _ref13.service,
|
|
854
|
+
addons = _ref13.addons,
|
|
855
|
+
bookingDetail = _ref13.bookingDetail,
|
|
856
|
+
bookingId = _ref13.bookingId;
|
|
832
857
|
var isEdit = options.isEdit,
|
|
833
858
|
isInScheduleByDate = options.isInScheduleByDate,
|
|
834
859
|
surcharge_list = options.surcharge_list,
|
|
@@ -950,11 +975,11 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
950
975
|
scheduleById: scheduleById || {},
|
|
951
976
|
isInScheduleByDate: isInScheduleByDate
|
|
952
977
|
})) {
|
|
953
|
-
var
|
|
978
|
+
var _ref14, _bundleItem$bundle_se3;
|
|
954
979
|
var _mainQuantity = item.num || 1;
|
|
955
980
|
matchedItems.push({
|
|
956
981
|
isMain: false,
|
|
957
|
-
total: Number((
|
|
982
|
+
total: Number((_ref14 = (_bundleItem$bundle_se3 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se3 !== void 0 ? _bundleItem$bundle_se3 : bundleItem.price) !== null && _ref14 !== void 0 ? _ref14 : 0),
|
|
958
983
|
quantity: bundleItem.num || bundleItem.quantity || 1,
|
|
959
984
|
item: bundleItem,
|
|
960
985
|
mainQuantity: _mainQuantity // 子商品的mainQuantity是所属主商品的quantity
|
|
@@ -1170,9 +1195,9 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
|
1170
1195
|
}
|
|
1171
1196
|
return surchargeWithAmount;
|
|
1172
1197
|
};
|
|
1173
|
-
function resetItemsSurchargeSideEffects(
|
|
1174
|
-
var service =
|
|
1175
|
-
addons =
|
|
1198
|
+
function resetItemsSurchargeSideEffects(_ref15) {
|
|
1199
|
+
var service = _ref15.service,
|
|
1200
|
+
addons = _ref15.addons;
|
|
1176
1201
|
var resetItem = function resetItem(item) {
|
|
1177
1202
|
if (!item) return;
|
|
1178
1203
|
item.surcharge_fee = 0;
|
|
@@ -29,6 +29,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
29
29
|
type?: 'form' | 'customer';
|
|
30
30
|
[key: string]: any;
|
|
31
31
|
}): void;
|
|
32
|
+
setOrderId(id?: number): void;
|
|
32
33
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
33
34
|
productList: Record<string, any>[];
|
|
34
35
|
discountList: Discount[];
|
|
@@ -56,7 +57,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
56
57
|
private bestDiscount;
|
|
57
58
|
loadPrepareConfig(params: {
|
|
58
59
|
customerId: number;
|
|
59
|
-
action?: 'create' | '
|
|
60
|
+
action?: 'create' | 'edit';
|
|
60
61
|
with_good_pass?: 0 | 1;
|
|
61
62
|
with_discount_card?: 0 | 1;
|
|
62
63
|
}): Promise<void>;
|
|
@@ -56,7 +56,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
56
56
|
originalDiscountList: [],
|
|
57
57
|
currentBookingTime: "",
|
|
58
58
|
filteredDiscountList: [],
|
|
59
|
-
bookingSubject: undefined
|
|
59
|
+
bookingSubject: undefined,
|
|
60
|
+
orderId: undefined
|
|
60
61
|
};
|
|
61
62
|
return _this;
|
|
62
63
|
}
|
|
@@ -299,6 +300,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
299
300
|
value: function setBookingSubject(bookingSubject) {
|
|
300
301
|
this.store.bookingSubject = bookingSubject;
|
|
301
302
|
}
|
|
303
|
+
}, {
|
|
304
|
+
key: "setOrderId",
|
|
305
|
+
value: function setOrderId(id) {
|
|
306
|
+
this.store.orderId = id;
|
|
307
|
+
}
|
|
302
308
|
|
|
303
309
|
// 计算优惠券
|
|
304
310
|
}, {
|
|
@@ -434,7 +440,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
434
440
|
case 0:
|
|
435
441
|
_context6.prev = 0;
|
|
436
442
|
_context6.next = 3;
|
|
437
|
-
return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.batchSearch(code,
|
|
443
|
+
return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.batchSearch(code, {
|
|
444
|
+
customerId: customerId,
|
|
445
|
+
orderId: this.store.orderId
|
|
446
|
+
});
|
|
438
447
|
case 3:
|
|
439
448
|
_context6.t0 = _context6.sent;
|
|
440
449
|
if (_context6.t0) {
|
|
@@ -769,24 +778,27 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
769
778
|
key: "loadPrepareConfig",
|
|
770
779
|
value: function () {
|
|
771
780
|
var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
772
|
-
var _this$getCustomer2, _this$store$discount8, _this$getDiscountList, _this$store$discount9, _this$store$productLi2, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, filteredDiscountList, _result3;
|
|
781
|
+
var _this$getCustomer2, _this$store$discount8, _this$getDiscountList, _this$store$discount9, _this$store$productLi2, orderId, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, filteredDiscountList, _result3;
|
|
773
782
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
774
783
|
while (1) switch (_context10.prev = _context10.next) {
|
|
775
784
|
case 0:
|
|
776
785
|
_context10.prev = 0;
|
|
786
|
+
orderId = this.store.orderId;
|
|
777
787
|
customerId = params.customerId || ((_this$getCustomer2 = this.getCustomer()) === null || _this$getCustomer2 === void 0 ? void 0 : _this$getCustomer2.id); // if (customerId === 1 || !customerId) {
|
|
778
788
|
// return
|
|
779
789
|
// }
|
|
780
|
-
_context10.next =
|
|
781
|
-
return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 ? void 0 : _this$store$discount8.loadPrepareConfig({
|
|
790
|
+
_context10.next = 5;
|
|
791
|
+
return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 ? void 0 : _this$store$discount8.loadPrepareConfig(_objectSpread({
|
|
782
792
|
customer_id: customerId,
|
|
783
|
-
action: 'create',
|
|
793
|
+
action: orderId ? 'edit' : 'create',
|
|
784
794
|
with_good_pass: 1,
|
|
785
795
|
with_discount_card: 1,
|
|
786
796
|
with_wallet_pass_holder: 1,
|
|
787
797
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
788
|
-
}
|
|
789
|
-
|
|
798
|
+
}, orderId ? {
|
|
799
|
+
order_id: orderId
|
|
800
|
+
} : {}));
|
|
801
|
+
case 5:
|
|
790
802
|
goodPassList = _context10.sent;
|
|
791
803
|
scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
|
|
792
804
|
return item.isScan;
|
|
@@ -799,35 +811,35 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
799
811
|
});
|
|
800
812
|
newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || [])); // 存储原始优惠券列表
|
|
801
813
|
this.store.originalDiscountList = newDiscountList;
|
|
802
|
-
_context10.next =
|
|
814
|
+
_context10.next = 13;
|
|
803
815
|
return (_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.setOriginalDiscountList(newDiscountList);
|
|
804
|
-
case
|
|
816
|
+
case 13:
|
|
805
817
|
// 根据当前预约时间过滤优惠券列表
|
|
806
818
|
filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
807
819
|
this.store.filteredDiscountList = filteredDiscountList;
|
|
808
820
|
this.setDiscountList(filteredDiscountList || []);
|
|
809
821
|
if (!((_this$store$productLi2 = this.store.productList) !== null && _this$store$productLi2 !== void 0 && _this$store$productLi2.length)) {
|
|
810
|
-
_context10.next =
|
|
822
|
+
_context10.next = 20;
|
|
811
823
|
break;
|
|
812
824
|
}
|
|
813
825
|
_result3 = this.calcDiscount(this.store.productList);
|
|
814
|
-
_context10.next =
|
|
826
|
+
_context10.next = 20;
|
|
815
827
|
return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"), _result3);
|
|
816
|
-
case
|
|
817
|
-
_context10.next =
|
|
828
|
+
case 20:
|
|
829
|
+
_context10.next = 22;
|
|
818
830
|
return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), filteredDiscountList);
|
|
819
|
-
case
|
|
820
|
-
_context10.next =
|
|
831
|
+
case 22:
|
|
832
|
+
_context10.next = 27;
|
|
821
833
|
break;
|
|
822
|
-
case
|
|
823
|
-
_context10.prev =
|
|
834
|
+
case 24:
|
|
835
|
+
_context10.prev = 24;
|
|
824
836
|
_context10.t0 = _context10["catch"](0);
|
|
825
837
|
console.error('[ShopDiscount] 加载准备配置出错:', _context10.t0);
|
|
826
|
-
case
|
|
838
|
+
case 27:
|
|
827
839
|
case "end":
|
|
828
840
|
return _context10.stop();
|
|
829
841
|
}
|
|
830
|
-
}, _callee10, this, [[0,
|
|
842
|
+
}, _callee10, this, [[0, 24]]);
|
|
831
843
|
}));
|
|
832
844
|
function loadPrepareConfig(_x10) {
|
|
833
845
|
return _loadPrepareConfig.apply(this, arguments);
|
|
@@ -17,14 +17,18 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
17
17
|
setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
|
|
18
18
|
getOriginalDiscountList(): Discount[];
|
|
19
19
|
loadPrepareConfig(params: {
|
|
20
|
-
action?: 'create';
|
|
20
|
+
action?: 'create' | 'edit';
|
|
21
21
|
with_good_pass: 0 | 1;
|
|
22
22
|
with_discount_card: 0 | 1;
|
|
23
23
|
customer_id: number;
|
|
24
24
|
with_wallet_pass_holder: 0 | 1;
|
|
25
25
|
request_timezone: string;
|
|
26
|
+
order_id?: number;
|
|
27
|
+
}): Promise<Discount[]>;
|
|
28
|
+
batchSearch(code: string, options?: {
|
|
29
|
+
customerId?: number;
|
|
30
|
+
orderId?: number;
|
|
26
31
|
}): Promise<Discount[]>;
|
|
27
|
-
batchSearch(code: string, customerId?: number): Promise<Discount[]>;
|
|
28
32
|
batchSearchByProductIds(productIds: number[]): Promise<any>;
|
|
29
33
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
30
34
|
private checkUsageCreditsLimit;
|
|
@@ -102,7 +102,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
102
102
|
) || [];
|
|
103
103
|
return goodPassList;
|
|
104
104
|
}
|
|
105
|
-
async batchSearch(code,
|
|
105
|
+
async batchSearch(code, options) {
|
|
106
|
+
const { customerId, orderId } = options || {};
|
|
106
107
|
const result = await this.request.get(`/machinecode/batch-search`, {
|
|
107
108
|
code,
|
|
108
109
|
translate_flag: 1,
|
|
@@ -112,6 +113,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
112
113
|
with: ["extensionData", "customScheduleSnapshot", "holder.detail"],
|
|
113
114
|
order_behavior_count: 1,
|
|
114
115
|
order_behavior_count_customer_id: customerId || 1,
|
|
116
|
+
...orderId ? { order_behavior_count_order_id: orderId } : {},
|
|
115
117
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
116
118
|
});
|
|
117
119
|
const resultDiscountList = this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || [];
|
|
@@ -184,7 +184,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
184
184
|
}
|
|
185
185
|
async scanCode(code, customerId) {
|
|
186
186
|
var _a, _b, _c, _d;
|
|
187
|
-
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || [];
|
|
187
|
+
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || [];
|
|
188
188
|
const rulesModule = this.store.rules;
|
|
189
189
|
if (!rulesModule) {
|
|
190
190
|
return {
|
|
@@ -423,11 +423,31 @@ var getBundleItemIsDiscountPrice = (item) => {
|
|
|
423
423
|
var getBundleItemIsMarkupOrDiscountPrice = (item) => {
|
|
424
424
|
return getBundleItemIsMarkupPrice(item) || getBundleItemIsDiscountPrice(item);
|
|
425
425
|
};
|
|
426
|
+
var getDiscountAmount = (discounts) => {
|
|
427
|
+
return (discounts || []).reduce((total, discount) => {
|
|
428
|
+
return total.add(new import_decimal.default(discount.amount || 0));
|
|
429
|
+
}, new import_decimal.default(0)).toNumber();
|
|
430
|
+
};
|
|
426
431
|
var getMainProductTotal = (item) => {
|
|
427
|
-
var _a, _b;
|
|
432
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
428
433
|
let total = new import_decimal.default(
|
|
429
434
|
(item == null ? void 0 : item.main_product_selling_price) ?? ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.main_product_selling_price) ?? ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.main_product_original_price) ?? 0
|
|
430
435
|
);
|
|
436
|
+
const hasMainProductPrice = (item == null ? void 0 : item.main_product_selling_price) != null || ((_c = item == null ? void 0 : item.metadata) == null ? void 0 : _c.main_product_selling_price) != null || ((_d = item == null ? void 0 : item.metadata) == null ? void 0 : _d.main_product_original_price) != null;
|
|
437
|
+
if (!hasMainProductPrice) {
|
|
438
|
+
total = new import_decimal.default((item == null ? void 0 : item.main_product_selling_price) ?? ((_e = item == null ? void 0 : item.metadata) == null ? void 0 : _e.main_product_selling_price) ?? item.price ?? 0);
|
|
439
|
+
const discount = ((_g = (_f = item == null ? void 0 : item._origin) == null ? void 0 : _f.product) == null ? void 0 : _g.discount_list) || ((_j = (_i = (_h = item == null ? void 0 : item._originData) == null ? void 0 : _h.product) == null ? void 0 : _i.discount_list) == null ? void 0 : _j.filter((item2) => {
|
|
440
|
+
var _a2;
|
|
441
|
+
return !((_a2 = item2 == null ? void 0 : item2.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
|
|
442
|
+
})) || [];
|
|
443
|
+
const mainProductDiscountAmount = getDiscountAmount(discount);
|
|
444
|
+
total = total.minus(mainProductDiscountAmount);
|
|
445
|
+
if ((item == null ? void 0 : item.option) && Array.isArray(item == null ? void 0 : item.option)) {
|
|
446
|
+
total = total.add(item == null ? void 0 : item.option.reduce((t, option) => {
|
|
447
|
+
return t.add(new import_decimal.default(option.price || 0).mul(option.num || 1));
|
|
448
|
+
}, new import_decimal.default(0)));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
431
451
|
for (let bundleItem of (item == null ? void 0 : item.bundle) || []) {
|
|
432
452
|
if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
|
|
433
453
|
const bundleItemTotal = new import_decimal.default(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
|
|
@@ -29,6 +29,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
29
29
|
type?: 'form' | 'customer';
|
|
30
30
|
[key: string]: any;
|
|
31
31
|
}): void;
|
|
32
|
+
setOrderId(id?: number): void;
|
|
32
33
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
33
34
|
productList: Record<string, any>[];
|
|
34
35
|
discountList: Discount[];
|
|
@@ -56,7 +57,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
56
57
|
private bestDiscount;
|
|
57
58
|
loadPrepareConfig(params: {
|
|
58
59
|
customerId: number;
|
|
59
|
-
action?: 'create' | '
|
|
60
|
+
action?: 'create' | 'edit';
|
|
60
61
|
with_good_pass?: 0 | 1;
|
|
61
62
|
with_discount_card?: 0 | 1;
|
|
62
63
|
}): Promise<void>;
|
|
@@ -56,7 +56,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
56
56
|
originalDiscountList: [],
|
|
57
57
|
currentBookingTime: "",
|
|
58
58
|
filteredDiscountList: [],
|
|
59
|
-
bookingSubject: void 0
|
|
59
|
+
bookingSubject: void 0,
|
|
60
|
+
orderId: void 0
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
// =========== 生命周期方法 ===========
|
|
@@ -201,6 +202,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
201
202
|
setBookingSubject(bookingSubject) {
|
|
202
203
|
this.store.bookingSubject = bookingSubject;
|
|
203
204
|
}
|
|
205
|
+
setOrderId(id) {
|
|
206
|
+
this.store.orderId = id;
|
|
207
|
+
}
|
|
204
208
|
// 计算优惠券
|
|
205
209
|
calcDiscount(productList, options) {
|
|
206
210
|
var _a;
|
|
@@ -277,7 +281,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
277
281
|
async scanCode(code, customerId) {
|
|
278
282
|
var _a, _b, _c;
|
|
279
283
|
try {
|
|
280
|
-
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || [];
|
|
284
|
+
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId, orderId: this.store.orderId })) || [];
|
|
281
285
|
const rulesModule = this.store.rules;
|
|
282
286
|
if (!rulesModule) {
|
|
283
287
|
return {
|
|
@@ -503,14 +507,16 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
503
507
|
async loadPrepareConfig(params) {
|
|
504
508
|
var _a, _b, _c, _d, _e;
|
|
505
509
|
try {
|
|
510
|
+
const orderId = this.store.orderId;
|
|
506
511
|
const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
|
|
507
512
|
const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
508
513
|
customer_id: customerId,
|
|
509
|
-
action: "create",
|
|
514
|
+
action: orderId ? "edit" : "create",
|
|
510
515
|
with_good_pass: 1,
|
|
511
516
|
with_discount_card: 1,
|
|
512
517
|
with_wallet_pass_holder: 1,
|
|
513
|
-
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
518
|
+
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
519
|
+
...orderId ? { order_id: orderId } : {}
|
|
514
520
|
}));
|
|
515
521
|
const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
|
|
516
522
|
(item) => item.isScan
|