@pisell/pisellos 2.2.185 → 2.2.186

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.
@@ -0,0 +1,9 @@
1
+ // 导出评估器
2
+ export { PromotionEvaluator } from "./evaluator";
3
+
4
+ // 导出适配器
5
+ export { PromotionAdapter } from "./adapter";
6
+ export { default } from "./adapter";
7
+
8
+ // 导出策略配置示例常量
9
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
@@ -264,7 +264,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
264
264
  private logSubmitBackendRejected;
265
265
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
266
266
  createOrder(params: CommitOrderParams['query']): {
267
- type: "appointment_booking" | "virtual";
267
+ type: "virtual" | "appointment_booking";
268
268
  platform: string;
269
269
  sales_channel: string;
270
270
  order_sales_channel: string;
@@ -1,3 +1,7 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
4
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1
5
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
6
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
7
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -2101,6 +2105,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2101
2105
  return _regeneratorRuntime().wrap(function _callee16$(_context18) {
2102
2106
  while (1) switch (_context18.prev = _context18.next) {
2103
2107
  case 0:
2108
+ debugger;
2104
2109
  tempOrder = this.ensureTempOrder();
2105
2110
  linked = booking ? this.createLinkedProductAndBooking({
2106
2111
  product: product,
@@ -2122,10 +2127,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2122
2127
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
2123
2128
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(matchedProduct.product_option_item, matchedProduct.product_bundle) : '';
2124
2129
  if (!matchedProduct) {
2125
- _context18.next = 17;
2130
+ _context18.next = 18;
2126
2131
  break;
2127
2132
  }
2128
- _context18.next = 14;
2133
+ _context18.next = 15;
2129
2134
  return this.shouldMergeProductToOrder({
2130
2135
  incomingProduct: productToAdd,
2131
2136
  normalizedIncoming: normalizedIncoming,
@@ -2136,13 +2141,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2136
2141
  tempOrder: tempOrder,
2137
2142
  booking: booking
2138
2143
  });
2139
- case 14:
2144
+ case 15:
2140
2145
  _context18.t0 = _context18.sent;
2141
- _context18.next = 18;
2146
+ _context18.next = 19;
2142
2147
  break;
2143
- case 17:
2144
- _context18.t0 = false;
2145
2148
  case 18:
2149
+ _context18.t0 = false;
2150
+ case 19:
2146
2151
  shouldMerge = _context18.t0;
2147
2152
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
2148
2153
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
@@ -2175,18 +2180,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2175
2180
  if (linked) {
2176
2181
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
2177
2182
  }
2178
- _context18.next = 23;
2183
+ _context18.next = 24;
2179
2184
  return this.applyPromotion();
2180
- case 23:
2185
+ case 24:
2181
2186
  this.applyDiscount();
2182
- _context18.next = 26;
2187
+ _context18.next = 27;
2183
2188
  return this.recalculateSummary({
2184
2189
  createIfMissing: true
2185
2190
  });
2186
- case 26:
2191
+ case 27:
2187
2192
  this.persistTempOrder();
2188
2193
  return _context18.abrupt("return", tempOrder.products);
2189
- case 28:
2194
+ case 29:
2190
2195
  case "end":
2191
2196
  return _context18.stop();
2192
2197
  }
@@ -2559,11 +2564,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2559
2564
  channel: params === null || params === void 0 ? void 0 : params.channel,
2560
2565
  type: params === null || params === void 0 ? void 0 : params.type,
2561
2566
  enhance: enhancePayload
2562
- });
2563
- _context23.next = 10;
2567
+ }); // TODO: 前端生成的时间现在是有问题的,后面要统一优化
2568
+ payload.created_at = undefined;
2569
+ _context23.next = 11;
2564
2570
  return this.saveDraft();
2565
- case 10:
2566
- _context23.prev = 10;
2571
+ case 11:
2572
+ _context23.prev = 11;
2567
2573
  this.logInfo('submitTempOrder calling sales checkout', {
2568
2574
  orderId: payload.order_id,
2569
2575
  externalSaleNumber: payload.external_sale_number,
@@ -2572,26 +2578,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2572
2578
  paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
2573
2579
  smallTicketDataFlag: payload.small_ticket_data_flag
2574
2580
  });
2575
- _context23.next = 14;
2581
+ _context23.next = 15;
2576
2582
  return this.submitSalesOrder({
2577
2583
  query: payload
2578
2584
  });
2579
- case 14:
2585
+ case 15:
2580
2586
  result = _context23.sent;
2581
- _context23.next = 27;
2587
+ _context23.next = 28;
2582
2588
  break;
2583
- case 17:
2584
- _context23.prev = 17;
2585
- _context23.t0 = _context23["catch"](10);
2589
+ case 18:
2590
+ _context23.prev = 18;
2591
+ _context23.t0 = _context23["catch"](11);
2586
2592
  backendErrorResponse = this.extractSubmitErrorResponse(_context23.t0);
2587
2593
  if (!backendErrorResponse) {
2588
- _context23.next = 24;
2594
+ _context23.next = 25;
2589
2595
  break;
2590
2596
  }
2591
2597
  this.store.syncState = 'failed';
2592
2598
  this.logSubmitBackendRejected(backendErrorResponse, payload);
2593
2599
  return _context23.abrupt("return", backendErrorResponse);
2594
- case 24:
2600
+ case 25:
2595
2601
  this.store.syncState = 'failed';
2596
2602
  this.logError('submitTempOrder failed', {
2597
2603
  error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
@@ -2601,31 +2607,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2601
2607
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
2602
2608
  });
2603
2609
  throw _context23.t0;
2604
- case 27:
2610
+ case 28:
2605
2611
  if (!this.isSubmitResponseRejected(result)) {
2606
- _context23.next = 31;
2612
+ _context23.next = 32;
2607
2613
  break;
2608
2614
  }
2609
2615
  this.store.syncState = 'failed';
2610
2616
  this.logSubmitBackendRejected(result, payload);
2611
2617
  return _context23.abrupt("return", result);
2612
- case 31:
2618
+ case 32:
2613
2619
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
2614
2620
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
2615
- _context23.next = 37;
2621
+ _context23.next = 38;
2616
2622
  break;
2617
2623
  }
2618
2624
  tempOrder.order_id = submittedOrderId;
2619
2625
  resultRecord = result;
2620
- _context23.next = 37;
2626
+ _context23.next = 38;
2621
2627
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
2622
- case 37:
2623
- return _context23.abrupt("return", result);
2624
2628
  case 38:
2629
+ return _context23.abrupt("return", result);
2630
+ case 39:
2625
2631
  case "end":
2626
2632
  return _context23.stop();
2627
2633
  }
2628
- }, _callee21, this, [[10, 17]]);
2634
+ }, _callee21, this, [[11, 18]]);
2629
2635
  }));
2630
2636
  function submitTempOrder(_x21) {
2631
2637
  return _submitTempOrder.apply(this, arguments);
@@ -3275,7 +3281,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3275
3281
  delete nextTempOrder.holder_id;
3276
3282
  nextTempOrder.metadata = raw.metadata && _typeof(raw.metadata) === 'object' ? _objectSpread({}, raw.metadata) : {};
3277
3283
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
3278
- nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map(function (p) {
3284
+ var rawProducts = Array.isArray(raw.products) ? raw.products : [];
3285
+ nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
3279
3286
  return _this10.normalizeHydratedOrderProduct(p);
3280
3287
  }) : [];
3281
3288
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
@@ -3302,6 +3309,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3302
3309
  }) : {
3303
3310
  productsByUid: {}
3304
3311
  };
3312
+ var tempOrderExtend = nextTempOrder._extend;
3313
+ var productsByUid = tempOrderExtend.productsByUid || {};
3314
+ var _iterator8 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
3315
+ _step8;
3316
+ try {
3317
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
3318
+ var _product$metadata6, _ref23, _ref24, _existed$origin, _rawProduct$metadata;
3319
+ var _step8$value = _slicedToArray(_step8.value, 2),
3320
+ index = _step8$value[0],
3321
+ product = _step8$value[1];
3322
+ var uid = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.unique_identification_number;
3323
+ if (!uid) continue;
3324
+ var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
3325
+ var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
3326
+ var origin = (_ref23 = (_ref24 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref24 !== void 0 ? _ref24 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref23 !== void 0 ? _ref23 : rawProduct;
3327
+ productsByUid[uid] = _objectSpread(_objectSpread({}, existed), {}, {
3328
+ origin: cloneDeep(origin)
3329
+ });
3330
+ }
3331
+ } catch (err) {
3332
+ _iterator8.e(err);
3333
+ } finally {
3334
+ _iterator8.f();
3335
+ }
3336
+ tempOrderExtend.productsByUid = productsByUid;
3305
3337
  if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
3306
3338
  this.ensureExternalSaleNumber(nextTempOrder);
3307
3339
  }
@@ -3311,10 +3343,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3311
3343
  }, {
3312
3344
  key: "normalizeHydratedProductOptionItem",
3313
3345
  value: function normalizeHydratedProductOptionItem(optionItem) {
3314
- var _ref23, _optionItem$num, _ref24, _optionItem$price;
3315
- var rawNum = (_ref23 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref23 !== void 0 ? _ref23 : 1;
3346
+ var _ref25, _optionItem$num, _ref26, _optionItem$price;
3347
+ var rawNum = (_ref25 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref25 !== void 0 ? _ref25 : 1;
3316
3348
  var parsedNum = Number(rawNum);
3317
- var rawPrice = (_ref24 = (_optionItem$price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _optionItem$price !== void 0 ? _optionItem$price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _ref24 !== void 0 ? _ref24 : 0;
3349
+ var rawPrice = (_ref26 = (_optionItem$price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _optionItem$price !== void 0 ? _optionItem$price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _ref26 !== void 0 ? _ref26 : 0;
3318
3350
  var parsedPrice = Number(rawPrice);
3319
3351
  return {
3320
3352
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -3412,67 +3444,67 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3412
3444
  var amount = new Decimal(discount.amount || 0).times(qty).plus(((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0);
3413
3445
  savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
3414
3446
  };
3415
- var _iterator8 = _createForOfIteratorHelper(productList),
3416
- _step8;
3447
+ var _iterator9 = _createForOfIteratorHelper(productList),
3448
+ _step9;
3417
3449
  try {
3418
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
3419
- var product = _step8.value;
3450
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3451
+ var product = _step9.value;
3420
3452
  var qty = product.num || 1;
3421
- var _iterator10 = _createForOfIteratorHelper(product.discount_list || []),
3422
- _step10;
3453
+ var _iterator11 = _createForOfIteratorHelper(product.discount_list || []),
3454
+ _step11;
3423
3455
  try {
3424
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
3425
- var pd = _step10.value;
3456
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3457
+ var pd = _step11.value;
3426
3458
  addDiscountAmount(pd, qty);
3427
3459
  }
3428
3460
  } catch (err) {
3429
- _iterator10.e(err);
3461
+ _iterator11.e(err);
3430
3462
  } finally {
3431
- _iterator10.f();
3463
+ _iterator11.f();
3432
3464
  }
3433
- var _iterator11 = _createForOfIteratorHelper(product.product_bundle || []),
3434
- _step11;
3465
+ var _iterator12 = _createForOfIteratorHelper(product.product_bundle || []),
3466
+ _step12;
3435
3467
  try {
3436
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3437
- var _ref25, _bundle$num;
3438
- var bundle = _step11.value;
3439
- var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref25 = (_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref25 !== void 0 ? _ref25 : 1) || 1).toNumber();
3440
- var _iterator12 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
3441
- _step12;
3468
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
3469
+ var _ref27, _bundle$num;
3470
+ var bundle = _step12.value;
3471
+ var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref27 = (_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref27 !== void 0 ? _ref27 : 1) || 1).toNumber();
3472
+ var _iterator13 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
3473
+ _step13;
3442
3474
  try {
3443
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
3444
- var _pd = _step12.value;
3475
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
3476
+ var _pd = _step13.value;
3445
3477
  addDiscountAmount(_pd, bundleQty);
3446
3478
  }
3447
3479
  } catch (err) {
3448
- _iterator12.e(err);
3480
+ _iterator13.e(err);
3449
3481
  } finally {
3450
- _iterator12.f();
3482
+ _iterator13.f();
3451
3483
  }
3452
3484
  }
3453
3485
  } catch (err) {
3454
- _iterator11.e(err);
3486
+ _iterator12.e(err);
3455
3487
  } finally {
3456
- _iterator11.f();
3488
+ _iterator12.f();
3457
3489
  }
3458
3490
  }
3459
3491
  } catch (err) {
3460
- _iterator8.e(err);
3492
+ _iterator9.e(err);
3461
3493
  } finally {
3462
- _iterator8.f();
3494
+ _iterator9.f();
3463
3495
  }
3464
- var _iterator9 = _createForOfIteratorHelper(discountList),
3465
- _step9;
3496
+ var _iterator10 = _createForOfIteratorHelper(discountList),
3497
+ _step10;
3466
3498
  try {
3467
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3468
- var d = _step9.value;
3499
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
3500
+ var d = _step10.value;
3469
3501
  var key = d.id;
3470
3502
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
3471
3503
  }
3472
3504
  } catch (err) {
3473
- _iterator9.e(err);
3505
+ _iterator10.e(err);
3474
3506
  } finally {
3475
- _iterator9.f();
3507
+ _iterator10.f();
3476
3508
  }
3477
3509
  }
3478
3510
  }]);
@@ -267,8 +267,9 @@ export interface OrderSubmitProduct extends Omit<OrderProduct, 'unique_identific
267
267
  payment_price: string;
268
268
  product_sku: Record<string, any>;
269
269
  }
270
- export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | '_extend' | 'customer' | 'discount_list'> {
270
+ export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | '_extend' | 'customer' | 'discount_list' | 'created_at'> {
271
271
  platform: string;
272
+ created_at?: string | undefined;
272
273
  request_unique_idempotency_token?: string;
273
274
  form_record_ids?: Array<{
274
275
  form_id: number | string;
@@ -393,7 +394,7 @@ export interface SubmitSalesOrderParams {
393
394
  delivery_type?: string;
394
395
  table_number?: Record<string, any>;
395
396
  schedule_date: string;
396
- created_at: string;
397
+ created_at?: string | undefined;
397
398
  products: OrderSubmitProduct[];
398
399
  bookings: OrderSubmitBooking[];
399
400
  payments: any[];
@@ -825,7 +825,7 @@ export function mapPaymentItemToOrderPayment(paymentItem) {
825
825
  metadata[key] = item[key];
826
826
  }
827
827
  }
828
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
828
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
829
829
  amount: String((_item$amount = item.amount) !== null && _item$amount !== void 0 ? _item$amount : '0.00'),
830
830
  code: String(item.code || ''),
831
831
  custom_payment_id: Number(customPaymentId !== null && customPaymentId !== void 0 ? customPaymentId : 0),
@@ -853,8 +853,6 @@ export function mapPaymentItemToOrderPayment(paymentItem) {
853
853
  service_charge: item.service_charge
854
854
  } : {}), item.order_payment_type !== undefined ? {
855
855
  order_payment_type: item.order_payment_type
856
- } : {}), item.created_at !== undefined ? {
857
- created_at: item.created_at
858
856
  } : {}), item.updated_at !== undefined ? {
859
857
  updated_at: item.updated_at
860
858
  } : {});
@@ -992,7 +992,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
992
992
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
993
993
  // 🔥 使用扁平化后的列表进行处理
994
994
  sortedFlattenedList.forEach(function (flatItem, index) {
995
- var _product10, _product$discount_lis2, _product11;
995
+ var _product10, _originProduct, _originProduct2, _originProduct3, _product$discount_lis2, _product11;
996
996
  // 获取商品数据
997
997
  var product, originProduct;
998
998
  if (flatItem.type === 'main') {
@@ -1016,11 +1016,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1016
1016
  };
1017
1017
  originProduct = flatItem.originProduct;
1018
1018
  }
1019
+ var isPersistedProduct = ((_product10 = product) === null || _product10 === void 0 ? void 0 : _product10.booking_id) || ((_originProduct = originProduct) === null || _originProduct === void 0 ? void 0 : _originProduct.order_detail_id) || ((_originProduct2 = originProduct) === null || _originProduct2 === void 0 ? void 0 : _originProduct2.orderDetailId) || ((_originProduct3 = originProduct) === null || _originProduct3 === void 0 ? void 0 : _originProduct3.booking_id);
1020
+ var hasExistingWalletDiscount = ((_product$discount_lis2 = product.discount_list) === null || _product$discount_lis2 === void 0 ? void 0 : _product$discount_lis2.length) && ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 ? void 0 : _product11.every(function (discount) {
1021
+ var _discount$id, _discount$discount4;
1022
+ var discountIdentity = (_discount$id = discount.id) !== null && _discount$id !== void 0 ? _discount$id : (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.resource_id;
1023
+ var discountType = discount.tag || discount.type;
1024
+ return Boolean(discountIdentity && ['good_pass', 'discount_card', 'product_discount_card'].includes(discountType));
1025
+ }));
1019
1026
 
1020
- // 已有优惠的商品跳过
1021
- if ((_product10 = product) !== null && _product10 !== void 0 && _product10.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product11 = product) !== null && _product11 !== void 0 && (_product11 = _product11.discount_list) !== null && _product11 !== void 0 && _product11.every(function (discount) {
1022
- return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
1023
- })) {
1027
+ // 已持久化且已有钱包券/折扣卡的商品行跳过,保留后端历史折扣结果。
1028
+ if (isPersistedProduct && hasExistingWalletDiscount) {
1024
1029
  if (flatItem.type === 'main') {
1025
1030
  processedProductsMap.set(product._id, [originProduct]);
1026
1031
  } else {
@@ -1115,12 +1120,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1115
1120
  // 如果是手动折扣,则不适用优惠券
1116
1121
  var isManualDiscount = false;
1117
1122
  if (flatItem.type === 'main') {
1118
- var _product$discount_lis5, _product12, _product12$every;
1123
+ var _product$discount_lis5, _product$discount_lis6, _product12, _product12$every;
1119
1124
  // 主商品:判断自身是否手动折扣
1120
- isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
1125
+ isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : ((_product$discount_lis5 = product.discount_list) === null || _product$discount_lis5 === void 0 ? void 0 : _product$discount_lis5.some(function (item) {
1126
+ return item.type === 'product';
1127
+ })) || product.total != product.origin_total && (product.bundle || []).every(function (item) {
1121
1128
  var _ref11;
1122
1129
  return !((_ref11 = item.discount_list || []) !== null && _ref11 !== void 0 && _ref11.length);
1123
- }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
1130
+ }) && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
1124
1131
  return item.type === 'product';
1125
1132
  })));
1126
1133
  if (product.inPromotion) {
@@ -1130,11 +1137,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1130
1137
  // bundle子商品:判断父主商品是否手动折扣
1131
1138
  var parentProduct = flatItem.parentProduct;
1132
1139
  if (parentProduct) {
1133
- var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
1134
- isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
1140
+ var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3, _parentProduct$discou4;
1141
+ isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : ((_parentProduct$discou = parentProduct.discount_list) === null || _parentProduct$discou === void 0 ? void 0 : _parentProduct$discou.some(function (item) {
1142
+ return item.type === 'product';
1143
+ })) || parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
1135
1144
  var _ref12;
1136
1145
  return !((_ref12 = item.discount_list || []) !== null && _ref12 !== void 0 && _ref12.length);
1137
- }) && (!((_parentProduct$discou = parentProduct.discount_list) !== null && _parentProduct$discou !== void 0 && _parentProduct$discou.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou2 = parentProduct.discount_list) === null || _parentProduct$discou2 === void 0 || (_parentProduct$discou3 = _parentProduct$discou2.every) === null || _parentProduct$discou3 === void 0 ? void 0 : _parentProduct$discou3.call(_parentProduct$discou2, function (item) {
1146
+ }) && (!((_parentProduct$discou2 = parentProduct.discount_list) !== null && _parentProduct$discou2 !== void 0 && _parentProduct$discou2.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou3 = parentProduct.discount_list) === null || _parentProduct$discou3 === void 0 || (_parentProduct$discou4 = _parentProduct$discou3.every) === null || _parentProduct$discou4 === void 0 ? void 0 : _parentProduct$discou4.call(_parentProduct$discou3, function (item) {
1138
1147
  return item.type === 'product';
1139
1148
  })));
1140
1149
  }
@@ -1142,9 +1151,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1142
1151
 
1143
1152
  // 勾选时覆盖手动折扣
1144
1153
  if (options !== null && options !== void 0 && options.discountId) {
1145
- var _product$discount_lis6;
1154
+ var _product$discount_lis7;
1146
1155
  // 主商品:检查自己的 discount_list
1147
- if (flatItem.type === 'main' && (_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.some(function (item) {
1156
+ if (flatItem.type === 'main' && (_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.some(function (item) {
1148
1157
  var _item$discount;
1149
1158
  return ((_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) === options.discountId;
1150
1159
  })) {
@@ -1152,8 +1161,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1152
1161
  }
1153
1162
  // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
1154
1163
  if (flatItem.type === 'bundle') {
1155
- var _product$discount_lis7, _flatItem$parentProdu7;
1156
- if ((_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.some(function (item) {
1164
+ var _product$discount_lis8, _flatItem$parentProdu7;
1165
+ if ((_product$discount_lis8 = product.discount_list) !== null && _product$discount_lis8 !== void 0 && _product$discount_lis8.some(function (item) {
1157
1166
  var _item$discount2;
1158
1167
  return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === options.discountId;
1159
1168
  }) || (_flatItem$parentProdu7 = flatItem.parentProduct) !== null && _flatItem$parentProdu7 !== void 0 && (_flatItem$parentProdu7 = _flatItem$parentProdu7.discount_list) !== null && _flatItem$parentProdu7 !== void 0 && _flatItem$parentProdu7.some(function (item) {
@@ -1165,9 +1174,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1165
1174
  }
1166
1175
  }
1167
1176
  if (options !== null && options !== void 0 && options.selectedList) {
1168
- var _product$discount_lis8;
1177
+ var _product$discount_lis9;
1169
1178
  // 主商品:检查自己的 discount_list
1170
- if (flatItem.type === 'main' && (_product$discount_lis8 = product.discount_list) !== null && _product$discount_lis8 !== void 0 && _product$discount_lis8.some(function (item) {
1179
+ if (flatItem.type === 'main' && (_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.some(function (item) {
1171
1180
  var _options$selectedList;
1172
1181
  return options === null || options === void 0 || (_options$selectedList = options.selectedList) === null || _options$selectedList === void 0 ? void 0 : _options$selectedList.some(function (n) {
1173
1182
  var _item$discount4;
@@ -1178,8 +1187,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1178
1187
  }
1179
1188
  // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
1180
1189
  if (flatItem.type === 'bundle') {
1181
- var _product$discount_lis9, _flatItem$parentProdu8;
1182
- if ((_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.some(function (item) {
1190
+ var _product$discount_lis10, _flatItem$parentProdu8;
1191
+ if ((_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.some(function (item) {
1183
1192
  var _options$selectedList2;
1184
1193
  return options === null || options === void 0 || (_options$selectedList2 = options.selectedList) === null || _options$selectedList2 === void 0 ? void 0 : _options$selectedList2.some(function (n) {
1185
1194
  var _item$discount5;
@@ -1301,7 +1310,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1301
1310
  }));
1302
1311
  }
1303
1312
  for (var i = 0; i < splitCount; i++) {
1304
- var _originProduct, _selectedDiscount$con, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2;
1313
+ var _originProduct4, _selectedDiscount$con, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2;
1305
1314
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
1306
1315
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
1307
1316
  // 标记优惠券为已使用
@@ -1322,7 +1331,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1322
1331
  productOriginTotal = product.origin_total;
1323
1332
  }
1324
1333
  // 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
1325
- if (Number(((_originProduct = originProduct) === null || _originProduct === void 0 || (_originProduct = _originProduct._productInit) === null || _originProduct === void 0 ? void 0 : _originProduct.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
1334
+ if (Number(((_originProduct4 = originProduct) === null || _originProduct4 === void 0 || (_originProduct4 = _originProduct4._productInit) === null || _originProduct4 === void 0 ? void 0 : _originProduct4.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
1326
1335
  productOriginTotal = product.total;
1327
1336
  }
1328
1337
 
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
314
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -609,10 +609,14 @@ export function normalizeOrderProduct(product) {
609
609
  metadata: metadata,
610
610
  lineOriginalPrice: product.original_price
611
611
  }, composedOriginalPrice);
612
+ var hasManualProductDiscount = (product.discount_list || []).some(function (item) {
613
+ return (item === null || item === void 0 ? void 0 : item.type) === 'product';
614
+ });
615
+ var manualOriginalPrice = hasManualProductDiscount && product.original_price != null ? String(product.original_price) : finalOriginalPrice;
612
616
  var discountList = ensureManualProductDiscountList({
613
617
  discountList: product.discount_list,
614
618
  metadata: metadata,
615
- originalPrice: finalOriginalPrice,
619
+ originalPrice: manualOriginalPrice,
616
620
  sellingPrice: composedSellingPrice,
617
621
  quantity: getSafeProductNum(product.num)
618
622
  });
@@ -623,7 +627,7 @@ export function normalizeOrderProduct(product) {
623
627
  product_variant_id: product.product_variant_id,
624
628
  product_option_item: normalizedOptions,
625
629
  selling_price: composedSellingPrice,
626
- original_price: finalOriginalPrice,
630
+ original_price: manualOriginalPrice,
627
631
  tax_fee: product.tax_fee || '0.00',
628
632
  is_charge_tax: (_product$is_charge_ta = product.is_charge_tax) !== null && _product$is_charge_ta !== void 0 ? _product$is_charge_ta : 0,
629
633
  discount_list: discountList,
@@ -0,0 +1,49 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/model/strategy/adapter/promotion/index.ts
30
+ var promotion_exports = {};
31
+ __export(promotion_exports, {
32
+ BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
+ PromotionAdapter: () => import_adapter.PromotionAdapter,
34
+ PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
+ X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
+ default: () => import_adapter2.default
37
+ });
38
+ module.exports = __toCommonJS(promotion_exports);
39
+ var import_evaluator = require("./evaluator");
40
+ var import_adapter = require("./adapter");
41
+ var import_adapter2 = __toESM(require("./adapter"));
42
+ var import_examples = require("./examples");
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ BUY_X_GET_Y_FREE_STRATEGY,
46
+ PromotionAdapter,
47
+ PromotionEvaluator,
48
+ X_ITEMS_FOR_Y_PRICE_STRATEGY
49
+ });
@@ -264,7 +264,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
264
264
  private logSubmitBackendRejected;
265
265
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
266
266
  createOrder(params: CommitOrderParams['query']): {
267
- type: "appointment_booking" | "virtual";
267
+ type: "virtual" | "appointment_booking";
268
268
  platform: string;
269
269
  sales_channel: string;
270
270
  order_sales_channel: string;
@@ -1436,6 +1436,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1436
1436
  // ─── TempOrder: 商品 CRUD ───
1437
1437
  async addProductToOrder(product, booking) {
1438
1438
  var _a;
1439
+ debugger;
1439
1440
  const tempOrder = this.ensureTempOrder();
1440
1441
  const linked = booking ? this.createLinkedProductAndBooking({ product, booking }) : null;
1441
1442
  const productToAdd = (linked == null ? void 0 : linked.product) || product;
@@ -1848,6 +1849,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1848
1849
  type: params == null ? void 0 : params.type,
1849
1850
  enhance: enhancePayload
1850
1851
  });
1852
+ payload.created_at = void 0;
1851
1853
  await this.saveDraft();
1852
1854
  let result;
1853
1855
  try {
@@ -2282,6 +2284,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2282
2284
  return nextTempOrder;
2283
2285
  }
2284
2286
  normalizeTempOrderForRuntime(raw, options) {
2287
+ var _a, _b;
2285
2288
  const nextTempOrder = {
2286
2289
  ...this.createDefaultTempOrderInstance(),
2287
2290
  ...raw || {}
@@ -2301,7 +2304,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2301
2304
  delete nextTempOrder.holder_id;
2302
2305
  nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
2303
2306
  nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
2304
- nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
2307
+ const rawProducts = Array.isArray(raw.products) ? raw.products : [];
2308
+ nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
2305
2309
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map((b) => ({
2306
2310
  ...b || {},
2307
2311
  is_all: (0, import_utils.normalizeBookingIsAll)(b || {}),
@@ -2316,6 +2320,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2316
2320
  ...raw._extend,
2317
2321
  productsByUid: raw._extend.productsByUid || {}
2318
2322
  } : { productsByUid: {} };
2323
+ const tempOrderExtend = nextTempOrder._extend;
2324
+ const productsByUid = tempOrderExtend.productsByUid || {};
2325
+ for (const [index, product] of nextTempOrder.products.entries()) {
2326
+ const uid = (_a = product.metadata) == null ? void 0 : _a.unique_identification_number;
2327
+ if (!uid)
2328
+ continue;
2329
+ const existed = productsByUid[uid] && typeof productsByUid[uid] === "object" ? productsByUid[uid] : {};
2330
+ const rawProduct = rawProducts[index] && typeof rawProducts[index] === "object" ? rawProducts[index] : product;
2331
+ const origin = existed.origin ?? rawProduct._origin ?? ((_b = rawProduct.metadata) == null ? void 0 : _b.origin) ?? rawProduct;
2332
+ productsByUid[uid] = {
2333
+ ...existed,
2334
+ origin: (0, import_lodash_es.cloneDeep)(origin)
2335
+ };
2336
+ }
2337
+ tempOrderExtend.productsByUid = productsByUid;
2319
2338
  if ((options == null ? void 0 : options.ensureIdentity) !== false) {
2320
2339
  this.ensureExternalSaleNumber(nextTempOrder);
2321
2340
  }
@@ -267,8 +267,9 @@ export interface OrderSubmitProduct extends Omit<OrderProduct, 'unique_identific
267
267
  payment_price: string;
268
268
  product_sku: Record<string, any>;
269
269
  }
270
- export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | '_extend' | 'customer' | 'discount_list'> {
270
+ export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | '_extend' | 'customer' | 'discount_list' | 'created_at'> {
271
271
  platform: string;
272
+ created_at?: string | undefined;
272
273
  request_unique_idempotency_token?: string;
273
274
  form_record_ids?: Array<{
274
275
  form_id: number | string;
@@ -393,7 +394,7 @@ export interface SubmitSalesOrderParams {
393
394
  delivery_type?: string;
394
395
  table_number?: Record<string, any>;
395
396
  schedule_date: string;
396
- created_at: string;
397
+ created_at?: string | undefined;
397
398
  products: OrderSubmitProduct[];
398
399
  bookings: OrderSubmitBooking[];
399
400
  payments: any[];
@@ -769,7 +769,6 @@ function mapPaymentItemToOrderPayment(paymentItem) {
769
769
  ...item.rounding_amount !== void 0 ? { rounding_amount: String(item.rounding_amount) } : {},
770
770
  ...item.service_charge !== void 0 ? { service_charge: item.service_charge } : {},
771
771
  ...item.order_payment_type !== void 0 ? { order_payment_type: item.order_payment_type } : {},
772
- ...item.created_at !== void 0 ? { created_at: item.created_at } : {},
773
772
  ...item.updated_at !== void 0 ? { updated_at: item.updated_at } : {}
774
773
  };
775
774
  }
@@ -680,7 +680,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
680
680
  }, 0);
681
681
  };
682
682
  sortedFlattenedList.forEach((flatItem, index) => {
683
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G;
683
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I;
684
684
  let product, originProduct;
685
685
  if (flatItem.type === "main") {
686
686
  product = flatItem.product;
@@ -701,11 +701,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
701
701
  };
702
702
  originProduct = flatItem.originProduct;
703
703
  }
704
- if ((product == null ? void 0 : product.booking_id) && ((_e = product.discount_list) == null ? void 0 : _e.length) && ((_f = product == null ? void 0 : product.discount_list) == null ? void 0 : _f.every(
705
- (discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(
706
- discount.tag || discount.type
707
- )
708
- ))) {
704
+ const isPersistedProduct = (product == null ? void 0 : product.booking_id) || (originProduct == null ? void 0 : originProduct.order_detail_id) || (originProduct == null ? void 0 : originProduct.orderDetailId) || (originProduct == null ? void 0 : originProduct.booking_id);
705
+ const hasExistingWalletDiscount = ((_e = product.discount_list) == null ? void 0 : _e.length) && ((_f = product == null ? void 0 : product.discount_list) == null ? void 0 : _f.every((discount) => {
706
+ var _a2;
707
+ const discountIdentity = discount.id ?? ((_a2 = discount.discount) == null ? void 0 : _a2.resource_id);
708
+ const discountType = discount.tag || discount.type;
709
+ return Boolean(
710
+ discountIdentity && ["good_pass", "discount_card", "product_discount_card"].includes(
711
+ discountType
712
+ )
713
+ );
714
+ }));
715
+ if (isPersistedProduct && hasExistingWalletDiscount) {
709
716
  if (flatItem.type === "main") {
710
717
  processedProductsMap.set(product._id, [originProduct]);
711
718
  } else {
@@ -786,13 +793,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
786
793
  const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
787
794
  let isManualDiscount = false;
788
795
  if (flatItem.type === "main") {
789
- isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
796
+ isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : ((_g = product.discount_list) == null ? void 0 : _g.some((item) => item.type === "product")) || product.total != product.origin_total && (product.bundle || []).every(
790
797
  (item) => {
791
798
  var _a2;
792
799
  return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
793
800
  }
794
- ) && (!((_g = product.discount_list) == null ? void 0 : _g.length) || ((_i = (_h = product == null ? void 0 : product.discount_list) == null ? void 0 : _h.every) == null ? void 0 : _i.call(
795
- _h,
801
+ ) && (!((_h = product.discount_list) == null ? void 0 : _h.length) || ((_j = (_i = product == null ? void 0 : product.discount_list) == null ? void 0 : _i.every) == null ? void 0 : _j.call(
802
+ _i,
796
803
  (item) => item.type === "product"
797
804
  )));
798
805
  if (product.inPromotion) {
@@ -801,19 +808,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
801
808
  } else {
802
809
  const parentProduct = flatItem.parentProduct;
803
810
  if (parentProduct) {
804
- isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
811
+ isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : ((_k = parentProduct.discount_list) == null ? void 0 : _k.some((item) => item.type === "product")) || parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
805
812
  (item) => {
806
813
  var _a2;
807
814
  return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
808
815
  }
809
- ) && (!((_j = parentProduct.discount_list) == null ? void 0 : _j.length) || ((_l = (_k = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _k.every) == null ? void 0 : _l.call(
810
- _k,
816
+ ) && (!((_l = parentProduct.discount_list) == null ? void 0 : _l.length) || ((_n = (_m = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _m.every) == null ? void 0 : _n.call(
817
+ _m,
811
818
  (item) => item.type === "product"
812
819
  )));
813
820
  }
814
821
  }
815
822
  if (options == null ? void 0 : options.discountId) {
816
- if (flatItem.type === "main" && ((_m = product.discount_list) == null ? void 0 : _m.some(
823
+ if (flatItem.type === "main" && ((_o = product.discount_list) == null ? void 0 : _o.some(
817
824
  (item) => {
818
825
  var _a2;
819
826
  return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
@@ -822,12 +829,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
822
829
  isManualDiscount = false;
823
830
  }
824
831
  if (flatItem.type === "bundle") {
825
- if (((_n = product.discount_list) == null ? void 0 : _n.some(
832
+ if (((_p = product.discount_list) == null ? void 0 : _p.some(
826
833
  (item) => {
827
834
  var _a2;
828
835
  return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
829
836
  }
830
- )) || ((_p = (_o = flatItem.parentProduct) == null ? void 0 : _o.discount_list) == null ? void 0 : _p.some(
837
+ )) || ((_r = (_q = flatItem.parentProduct) == null ? void 0 : _q.discount_list) == null ? void 0 : _r.some(
831
838
  (item) => {
832
839
  var _a2;
833
840
  return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
@@ -838,7 +845,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
838
845
  }
839
846
  }
840
847
  if (options == null ? void 0 : options.selectedList) {
841
- if (flatItem.type === "main" && ((_q = product.discount_list) == null ? void 0 : _q.some(
848
+ if (flatItem.type === "main" && ((_s = product.discount_list) == null ? void 0 : _s.some(
842
849
  (item) => {
843
850
  var _a2;
844
851
  return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
@@ -852,7 +859,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
852
859
  isManualDiscount = false;
853
860
  }
854
861
  if (flatItem.type === "bundle") {
855
- if (((_r = product.discount_list) == null ? void 0 : _r.some(
862
+ if (((_t = product.discount_list) == null ? void 0 : _t.some(
856
863
  (item) => {
857
864
  var _a2;
858
865
  return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
@@ -862,7 +869,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
862
869
  }
863
870
  );
864
871
  }
865
- )) || ((_t = (_s = flatItem.parentProduct) == null ? void 0 : _s.discount_list) == null ? void 0 : _t.some(
872
+ )) || ((_v = (_u = flatItem.parentProduct) == null ? void 0 : _u.discount_list) == null ? void 0 : _v.some(
866
873
  (item) => {
867
874
  var _a2;
868
875
  return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
@@ -907,7 +914,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
907
914
  })
908
915
  ]);
909
916
  } else {
910
- let total = product.inPromotion ? ((_u = product == null ? void 0 : product._promotion) == null ? void 0 : _u.finalPrice) ?? product.origin_total ?? product.total : product.origin_total ?? product.total;
917
+ let total = product.inPromotion ? ((_w = product == null ? void 0 : product._promotion) == null ? void 0 : _w.finalPrice) ?? product.origin_total ?? product.total : product.origin_total ?? product.total;
911
918
  let main_product_selling_price = product.price;
912
919
  if ((product.discount_list || []).some((item) => item.type === "promotion") || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
913
920
  total = product.total ?? product.origin_total;
@@ -932,7 +939,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
932
939
  } else {
933
940
  processedFlatItemsMap.set(flatItem._id, [{
934
941
  ...flatItem,
935
- discount_list: isManualDiscount ? this.resolveDiscountListForManualOverride(((_v = flatItem.bundleItem) == null ? void 0 : _v.discount_list) || []) : this.filterDiscountListByType(((_w = flatItem.bundleItem) == null ? void 0 : _w.discount_list) || [], "promotion"),
942
+ discount_list: isManualDiscount ? this.resolveDiscountListForManualOverride(((_x = flatItem.bundleItem) == null ? void 0 : _x.discount_list) || []) : this.filterDiscountListByType(((_y = flatItem.bundleItem) == null ? void 0 : _y.discount_list) || [], "promotion"),
936
943
  price: isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price,
937
944
  processed: true
938
945
  }]);
@@ -983,13 +990,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
983
990
  if (this.filterDiscountListByType(product.discount_list, "promotion").length && product.origin_total) {
984
991
  productOriginTotal = product.origin_total;
985
992
  }
986
- if (Number(((_x = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _x.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
993
+ if (Number(((_z = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _z.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
987
994
  productOriginTotal = product.total;
988
995
  }
989
996
  const isOrderLevel = (0, import_utils3.isOrderLevelFixedAmountDiscount)(selectedDiscount2);
990
997
  const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount2.id) : null;
991
998
  const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
992
- const isDeductOptionPrice = !!((_y = selectedDiscount2.config) == null ? void 0 : _y.deductOptionPrice);
999
+ const isDeductOptionPrice = !!((_A = selectedDiscount2.config) == null ? void 0 : _A.deductOptionPrice);
993
1000
  let mainProductSellingPrice;
994
1001
  let amount;
995
1002
  let productDiscountDifference;
@@ -1007,7 +1014,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1007
1014
  );
1008
1015
  amount = new import_decimal.default(product.price).minus(new import_decimal.default(mainProductSellingPrice)).toNumber();
1009
1016
  }
1010
- if (isDeductOptionPrice && ((_z = product.options) == null ? void 0 : _z.length)) {
1017
+ if (isDeductOptionPrice && ((_B = product.options) == null ? void 0 : _B.length)) {
1011
1018
  const optionResult = applyDiscountToOptions(
1012
1019
  product.options,
1013
1020
  selectedDiscount2
@@ -1015,7 +1022,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1015
1022
  discountedOptions = optionResult.discountedOptions;
1016
1023
  optionDiscountAmount = optionResult.optionDiscountAmount;
1017
1024
  }
1018
- const optionsForLineTotal = isDeductOptionPrice && ((_A = product.options) == null ? void 0 : _A.length) ? discountedOptions : product.options;
1025
+ const optionsForLineTotal = isDeductOptionPrice && ((_C = product.options) == null ? void 0 : _C.length) ? discountedOptions : product.options;
1019
1026
  const optionsLineTotal = getOptionTotal(optionsForLineTotal || []);
1020
1027
  const total = new import_decimal.default(mainProductSellingPrice).plus(optionsLineTotal).toNumber();
1021
1028
  const mainProductDiscountAmount = amount;
@@ -1026,9 +1033,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1026
1033
  amount: lineDiscountAmount,
1027
1034
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : discountType,
1028
1035
  discount: {
1029
- discount_card_type: (_B = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _B.discount_card_type,
1036
+ discount_card_type: (_D = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _D.discount_card_type,
1030
1037
  fixed_amount: lineDiscountAmount,
1031
- discount_calculation_mode: (_C = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _C.discount_calculation_mode,
1038
+ discount_calculation_mode: (_E = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _E.discount_calculation_mode,
1032
1039
  resource_id: selectedDiscount2.id,
1033
1040
  title: selectedDiscount2.format_title,
1034
1041
  original_amount: product.price,
@@ -1110,7 +1117,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1110
1117
  type: "good_pass",
1111
1118
  discount: {
1112
1119
  fixed_amount: product.origin_total,
1113
- discount_calculation_mode: (_D = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _D.discount_calculation_mode,
1120
+ discount_calculation_mode: (_F = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _F.discount_calculation_mode,
1114
1121
  resource_id: selectedDiscount2.id,
1115
1122
  title: selectedDiscount2.format_title,
1116
1123
  original_amount: product.origin_total,
@@ -1184,9 +1191,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1184
1191
  amount: fixedAmountPerItem * (product.num || 1),
1185
1192
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
1186
1193
  discount: {
1187
- discount_card_type: (_E = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _E.discount_card_type,
1194
+ discount_card_type: (_G = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _G.discount_card_type,
1188
1195
  fixed_amount: fixedAmountPerItem,
1189
- discount_calculation_mode: (_F = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _F.discount_calculation_mode,
1196
+ discount_calculation_mode: (_H = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _H.discount_calculation_mode,
1190
1197
  resource_id: selectedDiscount2.id,
1191
1198
  title: selectedDiscount2.format_title,
1192
1199
  original_amount: product.original_price,
@@ -1202,7 +1209,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1202
1209
  ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
1203
1210
  },
1204
1211
  config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
1205
- _num: (product.num || 1) * (((_G = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _G.num) || 1)
1212
+ _num: (product.num || 1) * (((_I = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _I.num) || 1)
1206
1213
  };
1207
1214
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
1208
1215
  appliedProducts.push(discountDetail);
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
314
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -511,10 +511,14 @@ function normalizeOrderProduct(product) {
511
511
  { num: product.num, metadata, lineOriginalPrice: product.original_price },
512
512
  composedOriginalPrice
513
513
  );
514
+ const hasManualProductDiscount = (product.discount_list || []).some(
515
+ (item) => (item == null ? void 0 : item.type) === "product"
516
+ );
517
+ const manualOriginalPrice = hasManualProductDiscount && product.original_price != null ? String(product.original_price) : finalOriginalPrice;
514
518
  const discountList = (0, import_manualProductDiscount.ensureManualProductDiscountList)({
515
519
  discountList: product.discount_list,
516
520
  metadata,
517
- originalPrice: finalOriginalPrice,
521
+ originalPrice: manualOriginalPrice,
518
522
  sellingPrice: composedSellingPrice,
519
523
  quantity: getSafeProductNum(product.num)
520
524
  });
@@ -525,7 +529,7 @@ function normalizeOrderProduct(product) {
525
529
  product_variant_id: product.product_variant_id,
526
530
  product_option_item: normalizedOptions,
527
531
  selling_price: composedSellingPrice,
528
- original_price: finalOriginalPrice,
532
+ original_price: manualOriginalPrice,
529
533
  tax_fee: product.tax_fee || "0.00",
530
534
  is_charge_tax: product.is_charge_tax ?? 0,
531
535
  discount_list: discountList,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.185",
4
+ "version": "2.2.186",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",