@pisell/pisellos 2.3.18 → 2.3.20

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
  *
@@ -461,7 +463,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
461
463
  generateIdempotencyToken(): string;
462
464
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
463
465
  createOrder(params: CommitOrderParams['query']): {
464
- type: "virtual" | "appointment_booking";
466
+ type: "appointment_booking" | "virtual";
465
467
  platform: string;
466
468
  sales_channel: string;
467
469
  order_sales_channel: string;
@@ -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({
@@ -4081,7 +4093,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4081
4093
  value: function () {
4082
4094
  var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(paramsList) {
4083
4095
  var _this24 = this;
4084
- var tempOrder;
4096
+ var tempOrder, reapplyBookingDiscountProductUids;
4085
4097
  return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4086
4098
  while (1) switch (_context22.prev = _context22.next) {
4087
4099
  case 0:
@@ -4092,11 +4104,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4092
4104
  }
4093
4105
  return _context22.abrupt("return", tempOrder.products);
4094
4106
  case 3:
4095
- paramsList.forEach(function (params) {
4096
- _this24.applyOrderProductUpdateToTempOrder(tempOrder, params);
4097
- });
4107
+ reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4108
+ var updatedProductUid = _this24.applyOrderProductUpdateToTempOrder(tempOrder, params);
4109
+ // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4110
+ if (params.allow_booking_discount_reapply && updatedProductUid) {
4111
+ acc.push(String(updatedProductUid));
4112
+ }
4113
+ return acc;
4114
+ }, []);
4098
4115
  _context22.next = 6;
4099
- return this.finalizeAfterProductsMutation(tempOrder);
4116
+ return this.finalizeAfterProductsMutation(tempOrder, {
4117
+ reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4118
+ });
4100
4119
  case 6:
4101
4120
  this.logInfo('updateOrderProduct success', {
4102
4121
  paramsList: paramsList
@@ -4225,7 +4244,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4225
4244
  }, {
4226
4245
  key: "finalizeAfterProductsMutation",
4227
4246
  value: (function () {
4228
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(tempOrder) {
4247
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(tempOrder, options) {
4229
4248
  return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4230
4249
  while (1) switch (_context24.prev = _context24.next) {
4231
4250
  case 0:
@@ -4233,7 +4252,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4233
4252
  _context24.next = 3;
4234
4253
  return this.applyPromotion();
4235
4254
  case 3:
4236
- this.applyDiscount();
4255
+ this.applyDiscount({
4256
+ reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4257
+ });
4237
4258
  this.sanitizeTempOrderProducts(tempOrder);
4238
4259
  _context24.next = 7;
4239
4260
  return this.recalculateSummary({
@@ -4247,7 +4268,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4247
4268
  }
4248
4269
  }, _callee22, this);
4249
4270
  }));
4250
- function finalizeAfterProductsMutation(_x26) {
4271
+ function finalizeAfterProductsMutation(_x26, _x27) {
4251
4272
  return _finalizeAfterProductsMutation.apply(this, arguments);
4252
4273
  }
4253
4274
  return finalizeAfterProductsMutation;
@@ -4380,7 +4401,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4380
4401
  }
4381
4402
  }, _callee23, this, [[11, 22, 25, 28]]);
4382
4403
  }));
4383
- function removeProductsFromOrder(_x27) {
4404
+ function removeProductsFromOrder(_x28) {
4384
4405
  return _removeProductsFromOrder.apply(this, arguments);
4385
4406
  }
4386
4407
  return removeProductsFromOrder;
@@ -4399,7 +4420,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4399
4420
  }
4400
4421
  }, _callee24, this);
4401
4422
  }));
4402
- function removeProductFromOrder(_x28) {
4423
+ function removeProductFromOrder(_x29) {
4403
4424
  return _removeProductFromOrder.apply(this, arguments);
4404
4425
  }
4405
4426
  return removeProductFromOrder;
@@ -4511,7 +4532,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4511
4532
  }
4512
4533
  }, _callee26, this);
4513
4534
  }));
4514
- function applyLocalPrintOrderNumbers(_x29) {
4535
+ function applyLocalPrintOrderNumbers(_x30) {
4515
4536
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4516
4537
  }
4517
4538
  return applyLocalPrintOrderNumbers;
@@ -4536,7 +4557,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4536
4557
  }
4537
4558
  }, _callee27, this);
4538
4559
  }));
4539
- function submitTempOrder(_x30) {
4560
+ function submitTempOrder(_x31) {
4540
4561
  return _submitTempOrder.apply(this, arguments);
4541
4562
  }
4542
4563
  return submitTempOrder;
@@ -4557,7 +4578,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4557
4578
  }
4558
4579
  }, _callee28, this);
4559
4580
  }));
4560
- function submitTempOrderAsync(_x31) {
4581
+ function submitTempOrderAsync(_x32) {
4561
4582
  return _submitTempOrderAsync.apply(this, arguments);
4562
4583
  }
4563
4584
  return submitTempOrderAsync;
@@ -4727,7 +4748,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4727
4748
  }
4728
4749
  }, _callee29, this, [[26, 33]]);
4729
4750
  }));
4730
- function runSubmitTempOrder(_x32) {
4751
+ function runSubmitTempOrder(_x33) {
4731
4752
  return _runSubmitTempOrder.apply(this, arguments);
4732
4753
  }
4733
4754
  return runSubmitTempOrder;
@@ -4754,7 +4775,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4754
4775
  }
4755
4776
  }, _callee30, this);
4756
4777
  }));
4757
- function markLocalOrderSynced(_x33, _x34) {
4778
+ function markLocalOrderSynced(_x34, _x35) {
4758
4779
  return _markLocalOrderSynced.apply(this, arguments);
4759
4780
  }
4760
4781
  return markLocalOrderSynced;
@@ -4886,7 +4907,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4886
4907
  }
4887
4908
  }, _callee31, this);
4888
4909
  }));
4889
- function syncPaymentsToOrder(_x35) {
4910
+ function syncPaymentsToOrder(_x36) {
4890
4911
  return _syncPaymentsToOrder.apply(this, arguments);
4891
4912
  }
4892
4913
  return syncPaymentsToOrder;
@@ -5006,7 +5027,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5006
5027
  }
5007
5028
  }, _callee32, this);
5008
5029
  }));
5009
- function submitOrder(_x36) {
5030
+ function submitOrder(_x37) {
5010
5031
  return _submitOrder.apply(this, arguments);
5011
5032
  }
5012
5033
  return submitOrder;
@@ -5045,7 +5066,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5045
5066
  }
5046
5067
  }, _callee33, this);
5047
5068
  }));
5048
- function cancelOrder(_x37) {
5069
+ function cancelOrder(_x38) {
5049
5070
  return _cancelOrder.apply(this, arguments);
5050
5071
  }
5051
5072
  return cancelOrder;
@@ -5089,7 +5110,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5089
5110
  }
5090
5111
  }, _callee34, this);
5091
5112
  }));
5092
- function changeBookingStatus(_x38) {
5113
+ function changeBookingStatus(_x39) {
5093
5114
  return _changeBookingStatus.apply(this, arguments);
5094
5115
  }
5095
5116
  return changeBookingStatus;
@@ -5236,7 +5257,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5236
5257
  }
5237
5258
  }, _callee35, this, [[4, 18]]);
5238
5259
  }));
5239
- function createOrderByCheckout(_x39) {
5260
+ function createOrderByCheckout(_x40) {
5240
5261
  return _createOrderByCheckout.apply(this, arguments);
5241
5262
  }
5242
5263
  return createOrderByCheckout;
@@ -5261,7 +5282,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5261
5282
  }
5262
5283
  }, _callee36, this);
5263
5284
  }));
5264
- function submitSalesOrder(_x40) {
5285
+ function submitSalesOrder(_x41) {
5265
5286
  return _submitSalesOrder.apply(this, arguments);
5266
5287
  }
5267
5288
  return submitSalesOrder;
@@ -5305,7 +5326,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5305
5326
  }
5306
5327
  }, _callee37, this);
5307
5328
  }));
5308
- function sendCustomerPayLink(_x41) {
5329
+ function sendCustomerPayLink(_x42) {
5309
5330
  return _sendCustomerPayLink.apply(this, arguments);
5310
5331
  }
5311
5332
  return sendCustomerPayLink;
@@ -5349,7 +5370,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5349
5370
  }
5350
5371
  }, _callee38, this);
5351
5372
  }));
5352
- function getSalesOrderByLookup(_x42) {
5373
+ function getSalesOrderByLookup(_x43) {
5353
5374
  return _getSalesOrderByLookup.apply(this, arguments);
5354
5375
  }
5355
5376
  return getSalesOrderByLookup;
@@ -5421,7 +5442,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5421
5442
  }
5422
5443
  }, _callee39, this);
5423
5444
  }));
5424
- function hydrateTempOrderFromRecord(_x43, _x44) {
5445
+ function hydrateTempOrderFromRecord(_x44, _x45) {
5425
5446
  return _hydrateTempOrderFromRecord.apply(this, arguments);
5426
5447
  }
5427
5448
  return hydrateTempOrderFromRecord;
@@ -5718,7 +5739,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5718
5739
  }
5719
5740
  }, _callee40, this);
5720
5741
  }));
5721
- function getOrderInfo(_x45) {
5742
+ function getOrderInfo(_x46) {
5722
5743
  return _getOrderInfo.apply(this, arguments);
5723
5744
  }
5724
5745
  return getOrderInfo;
@@ -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;