@pisell/pisellos 2.3.18 → 2.3.19

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.
@@ -84,7 +84,9 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
84
84
  unavailableReasonKey?: string | null;
85
85
  scannedDiscountList?: Discount[];
86
86
  }>;
87
- applyDiscount(): void;
87
+ applyDiscount(options?: {
88
+ reapplyBookingDiscountProductUids?: string[];
89
+ }): void;
88
90
  /**
89
91
  * 注入促销评估器。
90
92
  *
@@ -6,12 +6,12 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
6
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
7
7
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8
8
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
9
- 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; }
10
- 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; }
11
9
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
10
  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."); }
13
11
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
12
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
+ 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; }
14
+ 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; }
15
15
  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; } } }; }
16
16
  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); }
17
17
  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; }
@@ -158,9 +158,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
158
158
  };
159
159
  var existed = discountMap.get(key);
160
160
  if (existed) {
161
+ var _existed$limited_rela;
161
162
  existed.amount = Number(existed.amount || 0) + amount;
162
163
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
163
164
  existed.balance = String(Number(existed.balance || 0) + amount);
165
+ var productIds = Array.isArray((_existed$limited_rela = existed.limited_relation_product_data) === null || _existed$limited_rela === void 0 ? void 0 : _existed$limited_rela.product_ids) ? existed.limited_relation_product_data.product_ids : [];
166
+ if ((product === null || product === void 0 ? void 0 : product.product_id) !== undefined && (product === null || product === void 0 ? void 0 : product.product_id) !== null && !productIds.includes(product.product_id)) {
167
+ existed.limited_relation_product_data = _objectSpread(_objectSpread({}, existed.limited_relation_product_data || {}), {}, {
168
+ product_ids: [].concat(_toConsumableArray(productIds), [product.product_id])
169
+ });
170
+ }
164
171
  existed.applicableProductDetails = [].concat(_toConsumableArray(existed.applicableProductDetails || []), [detail]);
165
172
  existed.appliedProductDetails = [].concat(_toConsumableArray(existed.appliedProductDetails || []), [detail]);
166
173
  continue;
@@ -702,7 +709,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
702
709
  }()
703
710
  }, {
704
711
  key: "applyDiscount",
705
- value: function applyDiscount() {
712
+ value: function applyDiscount(options) {
706
713
  var _this$store$discount9,
707
714
  _tempOrder$holder2,
708
715
  _this$store$summary2,
@@ -728,6 +735,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
728
735
  return resolveIsFormSubject(tempOrder, product);
729
736
  },
730
737
  orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
738
+ }, {
739
+ reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
731
740
  });
732
741
  if (result !== null && result !== void 0 && result.productList) {
733
742
  var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
@@ -3908,7 +3917,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3908
3917
  }, {
3909
3918
  key: "applyOrderProductUpdateToTempOrder",
3910
3919
  value: function applyOrderProductUpdateToTempOrder(tempOrder, params) {
3911
- var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _nextProduct$metadata, _targetProduct$metada8, _tempOrder$products$p;
3920
+ var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _nextProduct$metadata, _targetProduct$metada8, _tempOrder$products$p, _tempOrder$products$p2;
3912
3921
  var product_id = params.product_id,
3913
3922
  product_variant_id = params.product_variant_id,
3914
3923
  updates = params.updates,
@@ -4039,21 +4048,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4039
4048
  tempOrder.products[productIndex] = normalizedProduct;
4040
4049
  this.syncTempOrderHolderFromBookings(tempOrder);
4041
4050
  this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], (_tempOrder$products$p = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p === void 0 ? void 0 : _tempOrder$products$p.unique_identification_number);
4051
+ return (_tempOrder$products$p2 = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p2 === void 0 ? void 0 : _tempOrder$products$p2.unique_identification_number;
4042
4052
  }
4043
4053
  }, {
4044
4054
  key: "updateOrderProduct",
4045
4055
  value: function () {
4046
4056
  var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
4047
- var tempOrder;
4057
+ var tempOrder, updatedProductUid;
4048
4058
  return _regeneratorRuntime().wrap(function _callee19$(_context21) {
4049
4059
  while (1) switch (_context21.prev = _context21.next) {
4050
4060
  case 0:
4051
4061
  tempOrder = this.ensureTempOrder();
4052
- this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4062
+ updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4053
4063
  _context21.next = 4;
4054
4064
  return this.applyPromotion();
4055
4065
  case 4:
4056
- this.applyDiscount();
4066
+ this.applyDiscount({
4067
+ reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4068
+ });
4057
4069
  this.sanitizeTempOrderProducts(tempOrder);
4058
4070
  _context21.next = 8;
4059
4071
  return this.recalculateSummary({
@@ -340,6 +340,19 @@ export interface UpdateOrderProductParams {
340
340
  * });
341
341
  */
342
342
  allow_booking_reprice?: boolean;
343
+ /**
344
+ * Change time 重报价后,允许当前预约商品行重新应用已选编辑态折扣卡。
345
+ *
346
+ * @example
347
+ * await order.updateOrderProduct({
348
+ * product_id: 1,
349
+ * product_variant_id: 0,
350
+ * updates: { discount_list: [] },
351
+ * booking: { duration: 2 },
352
+ * allow_booking_discount_reapply: true,
353
+ * });
354
+ */
355
+ allow_booking_discount_reapply?: boolean;
343
356
  }
344
357
  /** 仅更新购物车行数量;行定位语义与 updateOrderProduct / removeProductFromOrder 保持一致 */
345
358
  export interface UpdateOrderProductQuantityParams extends OrderProductIdentity {
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -1,8 +1,7 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, UnavailableReason } from './types';
3
+ import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, RulesCalcDiscountOptions, UnavailableReason } from './types';
4
4
  import { Discount } from '../Discount/types';
5
- import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
6
5
  import { WindowPlugin } from '../../plugins';
7
6
  export declare class RulesModule extends BaseModule implements Module, RulesModuleAPI {
8
7
  protected defaultName: string;
@@ -45,12 +44,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
45
44
  }[];
46
45
  isFormSubject: RulesFormSubject;
47
46
  orderTotalAmount: number;
48
- }, options?: {
49
- isSelected?: boolean;
50
- discountId?: number;
51
- selectedList?: SetDiscountSelectedParams[];
52
- scan?: boolean;
53
- }): DiscountResult;
47
+ }, options?: RulesCalcDiscountOptions): DiscountResult;
54
48
  /**
55
49
  * 检查优惠是否符合 PackageSubItemUsageRules 配置
56
50
  * @param discount 优惠券
@@ -335,6 +335,32 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
335
335
  }) && productList.find(function (n) {
336
336
  return !n.booking_id;
337
337
  });
338
+ var reapplyBookingDiscountProductUids = new Set(((options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids) || []).filter(function (uid) {
339
+ return uid !== undefined && uid !== null && uid !== '';
340
+ }).map(String));
341
+ var getOriginProductUid = function getOriginProductUid(originProduct) {
342
+ var _originProduct$metada, _originProduct$metada2;
343
+ var uid = (_originProduct$metada = originProduct === null || originProduct === void 0 || (_originProduct$metada2 = originProduct.metadata) === null || _originProduct$metada2 === void 0 ? void 0 : _originProduct$metada2.unique_identification_number) !== null && _originProduct$metada !== void 0 ? _originProduct$metada : originProduct === null || originProduct === void 0 ? void 0 : originProduct.unique_identification_number;
344
+ if (uid === undefined || uid === null || uid === '') return undefined;
345
+ return String(uid);
346
+ };
347
+ var shouldReapplyBookingDiscount = function shouldReapplyBookingDiscount(originProduct, selectedDiscount) {
348
+ if (!selectedDiscount) return false;
349
+ var uid = getOriginProductUid(originProduct);
350
+ if (!uid || !reapplyBookingDiscountProductUids.has(uid)) return false;
351
+ var discountType = selectedDiscount.tag || selectedDiscount.type;
352
+ return selectedDiscount.isEditMode === true && selectedDiscount.isSelected === true && ['good_pass', 'discount_card', 'product_discount_card'].includes(discountType);
353
+ };
354
+ var resolveReapplyEditModeDiscountPercent = function resolveReapplyEditModeDiscountPercent(originProduct, selectedDiscount) {
355
+ var _discount2;
356
+ if (!shouldReapplyBookingDiscount(originProduct, selectedDiscount)) return undefined;
357
+ var discountType = (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.tag) || (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.type);
358
+ if (discountType !== 'discount_card' && discountType !== 'product_discount_card') {
359
+ return undefined;
360
+ }
361
+ var percent = Number((_discount2 = selectedDiscount.discount) === null || _discount2 === void 0 ? void 0 : _discount2.percent);
362
+ return Number.isFinite(percent) ? percent : undefined;
363
+ };
338
364
  var editModeDiscount = [];
339
365
  var addModeDiscount = [];
340
366
  discountList.forEach(function (discount) {
@@ -363,11 +389,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
363
389
  }
364
390
  });
365
391
  }
366
-
367
- // 过滤掉手动取消false的优惠券,但仅用于应用优惠逻辑
368
- var filteredDiscountList = addModeDiscount.filter(function (discount) {
369
- return !discount.isManualSelect;
370
- });
371
392
  var hasDiscountInput = editModeDiscount.length > 0 || addModeDiscount.length > 0 || Boolean(options === null || options === void 0 ? void 0 : options.discountId) || Boolean(options === null || options === void 0 || (_options$selectedList = options.selectedList) === null || _options$selectedList === void 0 ? void 0 : _options$selectedList.length) || Boolean(options === null || options === void 0 ? void 0 : options.scan);
372
393
  if (!hasDiscountInput) {
373
394
  return {
@@ -375,6 +396,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
375
396
  productList: productList
376
397
  };
377
398
  }
399
+ var canUseEditModeDiscountForReapply = function canUseEditModeDiscountForReapply(discount) {
400
+ var discountType = discount.tag || discount.type;
401
+ return reapplyBookingDiscountProductUids.size > 0 && discount.isEditMode === true && discount.isSelected === true && ['good_pass', 'discount_card', 'product_discount_card'].includes(discountType);
402
+ };
403
+
404
+ // 过滤掉手动取消false的优惠券,但仅用于应用优惠逻辑。
405
+ // Change time 重报价需要把已选编辑态折扣卡重新放入候选,再由目标 uid 限定作用范围。
406
+ var filteredDiscountList = [].concat(_toConsumableArray(addModeDiscount.filter(function (discount) {
407
+ return !discount.isManualSelect;
408
+ })), _toConsumableArray(editModeDiscount.filter(canUseEditModeDiscountForReapply)));
378
409
 
379
410
  // 🔥 扁平化商品列表:将 bundle 子商品展开为虚拟商品
380
411
  var flattenProductsWithBundle = function flattenProductsWithBundle(productList) {
@@ -1056,7 +1087,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1056
1087
  var _product$discount_lis3, _product$discount_lis4;
1057
1088
  // 🔥 检查策略可用性(针对 good_pass 和折扣卡)
1058
1089
  var discountType = discount.tag || discount.type;
1059
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
1090
+ var currentOriginUid = getOriginProductUid(originProduct);
1091
+ var isReapplyEditModeDiscountForProduct = discount.isEditMode && reapplyBookingDiscountProductUids.size > 0 && currentOriginUid && reapplyBookingDiscountProductUids.has(String(currentOriginUid)) && discount.isSelected === true;
1092
+ if (discount.isEditMode && reapplyBookingDiscountProductUids.size > 0) {
1093
+ var uid = currentOriginUid;
1094
+ if (!uid || !reapplyBookingDiscountProductUids.has(uid)) return false;
1095
+ if (!discount.isSelected) return false;
1096
+ }
1097
+ if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType) && !isReapplyEditModeDiscountForProduct) {
1060
1098
  var _discount$config2;
1061
1099
  // 如果策略检查后没有config,说明不可用
1062
1100
  if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config2 = discount.config) !== null && _discount$config2 !== void 0 && _discount$config2.isAvailable)) {
@@ -1284,7 +1322,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1284
1322
  }
1285
1323
  return;
1286
1324
  }
1287
- if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan) && !isEditModeAddNewProduct) {
1325
+ var shouldReapplyBookingDiscountForProduct = shouldReapplyBookingDiscount(originProduct, selectedDiscount);
1326
+ if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan) && !isEditModeAddNewProduct && !shouldReapplyBookingDiscountForProduct) {
1288
1327
  return;
1289
1328
  }
1290
1329
 
@@ -1325,7 +1364,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1325
1364
  }));
1326
1365
  }
1327
1366
  for (var i = 0; i < splitCount; i++) {
1328
- var _originProduct4, _selectedDiscount$con, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2;
1367
+ var _originProduct4, _selectedDiscount$con, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2, _reapplyDiscountPerce;
1329
1368
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
1330
1369
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
1331
1370
  // 标记优惠券为已使用
@@ -1363,11 +1402,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1363
1402
  var productDiscountDifference = void 0;
1364
1403
  var discountedOptions = product.options;
1365
1404
  var optionDiscountAmount = 0;
1405
+ var reapplyDiscountPercent = void 0;
1366
1406
  if (isOrderLevel && productAllocation) {
1367
1407
  // order_level:使用预计算的分摊金额
1368
1408
  amount = productAllocation.discountAmount;
1369
1409
  productDiscountDifference = productAllocation.difference;
1370
1410
  mainProductSellingPrice = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
1411
+ } else if (resolveReapplyEditModeDiscountPercent(originProduct, _selectedDiscount) !== undefined) {
1412
+ // Change time 重套编辑态折扣卡时,历史 par_value 不是运行时折扣口径,优先使用后端快照里的 percent。
1413
+ var percent = resolveReapplyEditModeDiscountPercent(originProduct, _selectedDiscount);
1414
+ reapplyDiscountPercent = new Decimal(percent).toFixed(2);
1415
+ mainProductSellingPrice = new Decimal(product.price || 0).mul(new Decimal(100).minus(percent)).div(100).toDecimalPlaces(2).toNumber();
1416
+ amount = new Decimal(product.price).minus(mainProductSellingPrice).toNumber();
1371
1417
  } else {
1372
1418
  // item_level 或其他类型:使用原有逻辑
1373
1419
  mainProductSellingPrice = getDiscountAmount(_selectedDiscount, product.price, product.price);
@@ -1400,7 +1446,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1400
1446
  title: _selectedDiscount.format_title,
1401
1447
  original_amount: product.price,
1402
1448
  product_id: originProduct.id || originProduct.product_id,
1403
- percent: _selectedDiscount.par_value,
1449
+ percent: (_reapplyDiscountPerce = reapplyDiscountPercent) !== null && _reapplyDiscountPerce !== void 0 ? _reapplyDiscountPerce : _selectedDiscount.par_value,
1404
1450
  discount_product_id: _selectedDiscount.product_id
1405
1451
  },
1406
1452
  // 前端使用的num数量,为了计算优惠金额
@@ -1,4 +1,5 @@
1
1
  import { Discount } from '../Discount/types';
2
+ import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
2
3
  export declare enum UnavailableReason {
3
4
  TimeLimit = "time_limit",
4
5
  ProductNotApplicable = "product_not_applicable",
@@ -23,6 +24,14 @@ export interface DiscountResult {
23
24
  discountList: any[];
24
25
  }
25
26
  export type RulesFormSubject = boolean | ((product: any) => boolean);
27
+ export interface RulesCalcDiscountOptions {
28
+ isSelected?: boolean;
29
+ discountId?: number;
30
+ selectedList?: SetDiscountSelectedParams[];
31
+ scan?: boolean;
32
+ /** Change time 重报价目标行:允许已选编辑态折扣卡重新应用到这些 booking 商品。 */
33
+ reapplyBookingDiscountProductUids?: string[];
34
+ }
26
35
  export interface RulesModuleAPI {
27
36
  setRulesList: (rulesList: Rules[]) => Promise<void>;
28
37
  clear: () => Promise<void>;
@@ -34,7 +43,7 @@ export interface RulesModuleAPI {
34
43
  }[];
35
44
  isFormSubject: RulesFormSubject;
36
45
  orderTotalAmount: number;
37
- }) => DiscountResult;
46
+ }, options?: RulesCalcDiscountOptions) => DiscountResult;
38
47
  }
39
48
  type ProductDetail = {
40
49
  isClient?: boolean;
@@ -448,9 +448,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
448
448
  var appPlugin = this.core.getPlugin('app');
449
449
  var app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
450
450
  if (app) {
451
- var _this$store$createdAt;
452
451
  var coreData = app.data.store.getStore().getDataByModel('core');
453
- if (!((_this$store$createdAt = this.store.createdAtQuery) !== null && _this$store$createdAt !== void 0 && _this$store$createdAt.sales_time_between) && coreData !== null && coreData !== void 0 && coreData.core) {
452
+ if (coreData !== null && coreData !== void 0 && coreData.core) {
454
453
  var today = dayjs();
455
454
  if (coreData !== null && coreData !== void 0 && coreData.core.operating_day_boundary) {
456
455
  var operatingDayBoundary = coreData.core.operating_day_boundary;
@@ -49,6 +49,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
49
49
  private queuedAutoPaymentSync;
50
50
  private autoPaymentSyncFlushing;
51
51
  private autoPaymentSyncTimer;
52
+ private salesDetailLoadInFlight;
53
+ private serverOrderChangeUnsubscribe;
54
+ private serverOrderChangeHydrateInFlight;
52
55
  constructor(name?: string, version?: string);
53
56
  /**
54
57
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
@@ -69,6 +72,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
69
72
  * 记录错误日志
70
73
  */
71
74
  private logError;
75
+ private isCurrentSalesOrderRecord;
76
+ private syncCurrentSalesDetailFromServerOrderChange;
77
+ private registerServerOrderChangeSync;
72
78
  private hydrateOrderPaymentNames;
73
79
  get payment(): PaymentModule | undefined;
74
80
  private getCurrentOrderCustomerId;