@pisell/pisellos 2.3.6 → 2.3.7

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.
@@ -236,6 +236,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
236
236
  product.metadata.main_product_selling_price = newMainSellingPrice;
237
237
  product.metadata.price_schema_version = 2;
238
238
  }
239
+ if (Array.isArray(product.product_bundle)) {
240
+ product.product_bundle = product.product_bundle.map((bundle) => {
241
+ const hasBundleDiscount = Array.isArray(bundle == null ? void 0 : bundle.discount_list) && bundle.discount_list.length > 0;
242
+ if (hasBundleDiscount)
243
+ return bundle;
244
+ const restoredPrice = (bundle == null ? void 0 : bundle.original_price) ?? (bundle == null ? void 0 : bundle.product_price) ?? (bundle == null ? void 0 : bundle.price);
245
+ if (restoredPrice === void 0 || restoredPrice === null || restoredPrice === "")
246
+ return bundle;
247
+ return {
248
+ ...bundle,
249
+ price: restoredPrice,
250
+ bundle_selling_price: restoredPrice
251
+ };
252
+ });
253
+ }
239
254
  product.selling_price = (0, import_utils.composeLinePrice)({
240
255
  mainPrice: newMainSellingPrice,
241
256
  bundle: product.product_bundle
@@ -434,7 +449,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
434
449
  });
435
450
  }
436
451
  async scanCode(code, customerId) {
437
- var _a, _b, _c, _d, _e;
452
+ var _a, _b, _c, _d;
438
453
  const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
439
454
  const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
440
455
  const rulesModule = this.store.rules;
@@ -470,17 +485,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
470
485
  };
471
486
  }
472
487
  const tempOrder = this.store.tempOrder;
473
- const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
488
+ const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record) || [];
474
489
  const { isAvailable, discountList: newDiscountList, unavailableReason } = rulesModule.isDiscountListAvailable({
475
490
  productList: (tempOrder == null ? void 0 : tempOrder.products) || [],
476
491
  oldDiscountList: this.getDiscountList(),
477
492
  newDiscountList: withScanList,
478
493
  orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0),
479
494
  holders,
480
- isFormSubject: !!((_d = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _d.type) && tempOrder.holder.type === "form"
495
+ isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product)
481
496
  }) || { isAvailable: false, discountList: this.getDiscountList() };
482
497
  if (isAvailable && newDiscountList) {
483
- (_e = this.store.discount) == null ? void 0 : _e.setDiscountList(newDiscountList);
498
+ (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(newDiscountList);
484
499
  this.applyDiscount();
485
500
  }
486
501
  return {
@@ -492,24 +507,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
492
507
  };
493
508
  }
494
509
  applyDiscount() {
495
- var _a, _b, _c, _d, _e;
510
+ var _a, _b, _c, _d;
496
511
  const tempOrder = this.store.tempOrder;
497
512
  if (!tempOrder)
498
513
  return;
499
514
  delete tempOrder.discount_list;
500
- if (this.shouldSkipDiscountCalculation(tempOrder))
515
+ const discountList = ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
516
+ const shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
517
+ if (shouldSkipDiscountCalculation)
501
518
  return;
502
519
  const rulesModule = this.store.rules;
503
520
  if (!rulesModule)
504
521
  return;
505
- const discountList = ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
506
- const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
522
+ const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record) || [];
507
523
  const result = rulesModule.calcDiscount({
508
524
  productList: tempOrder.products,
509
525
  discountList,
510
526
  holders,
511
- isFormSubject: !!((_c = tempOrder.holder) == null ? void 0 : _c.type) && tempOrder.holder.type === "form",
512
- orderTotalAmount: Number(((_d = this.store.summary) == null ? void 0 : _d.total_amount) || 0)
527
+ isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
528
+ orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0)
513
529
  });
514
530
  if (result == null ? void 0 : result.productList) {
515
531
  const previousProductsByUid = (0, import_utils.indexOrderProductsByUid)(tempOrder.products);
@@ -538,7 +554,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
538
554
  result.productList || tempOrder.products,
539
555
  result.discountList
540
556
  );
541
- (_e = this.store.discount) == null ? void 0 : _e.setDiscountList(result.discountList);
557
+ (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(result.discountList);
542
558
  }
543
559
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(
544
560
  (product) => this.productHasCustomerBoundDiscount(product)
@@ -886,11 +902,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
886
902
  }
887
903
  };
888
904
  tempOrder.deposit_amount = snapshot.depositAmount;
889
- tempOrder.is_deposit = snapshot.isDeposit;
905
+ tempOrder.is_deposit = tempOrder.is_deposit === 0 && new import_decimal.default(tempOrder.deposit_amount || 0).gt(0) ? 0 : snapshot.isDeposit;
890
906
  return nextSummary;
891
907
  }
892
908
  isDepositOrder(tempOrder, depositAmount) {
893
- return tempOrder.is_deposit === 1 || depositAmount.gt(0);
909
+ return tempOrder.is_deposit === 1 && depositAmount.gt(0);
894
910
  }
895
911
  getOrderExpectedAmount(summary) {
896
912
  return new import_decimal.default(summary.expect_amount || summary.total_amount || 0);
@@ -1588,7 +1604,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1588
1604
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1589
1605
  });
1590
1606
  return {
1591
- isDeposit: tempOrder.is_deposit === 1 || depositAmount !== "0.00",
1607
+ isDeposit: tempOrder.is_deposit === 1,
1592
1608
  depositAmount,
1593
1609
  expectAmount: summary.expect_amount || "0.00",
1594
1610
  totalAmount: summary.total_amount || "0.00",
@@ -1873,8 +1889,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1873
1889
  hasDeposit: true
1874
1890
  } : void 0
1875
1891
  };
1892
+ const isExistingDepositDisabled = tempOrder.is_deposit === 0 && new import_decimal.default(tempOrder.deposit_amount || 0).gt(0);
1876
1893
  tempOrder.deposit_amount = depositAmount;
1877
- tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
1894
+ tempOrder.is_deposit = hasDepositAmount && !isExistingDepositDisabled ? 1 : 0;
1878
1895
  return this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
1879
1896
  }
1880
1897
  async recalculateSummary(options) {
@@ -2219,6 +2236,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2219
2236
  if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
2220
2237
  (0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
2221
2238
  this.clearCustomerBoundDiscounts(tempOrder);
2239
+ this.applyDiscount();
2222
2240
  }
2223
2241
  this.persistTempOrder();
2224
2242
  this.saveDraftInBackground();
@@ -2390,9 +2408,27 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2390
2408
  const hasSyncedOrderPayment = (payment) => {
2391
2409
  return payment.order_payment_id !== void 0 && payment.order_payment_id !== null;
2392
2410
  };
2411
+ const isOrderPaymentType = (value) => {
2412
+ return value === "normal" || value === "deposit";
2413
+ };
2414
+ const voucherOrderPaymentType = this.resolveNextOrderPaymentType(tempOrder);
2415
+ const withVoucherPaymentType = (payment) => {
2416
+ const paymentRecord = payment;
2417
+ if (!isVoucherPayment(paymentRecord))
2418
+ return payment;
2419
+ const explicitPaymentType = isOrderPaymentType(paymentRecord.order_payment_type) ? paymentRecord.order_payment_type : isOrderPaymentType(paymentRecord.type) ? paymentRecord.type : void 0;
2420
+ const nextPaymentType = explicitPaymentType || voucherOrderPaymentType;
2421
+ const shouldPreserveCustomPaymentType = paymentRecord.custom_payment_type === void 0 && paymentRecord.type !== void 0 && !isOrderPaymentType(paymentRecord.type);
2422
+ return {
2423
+ ...paymentRecord,
2424
+ ...shouldPreserveCustomPaymentType ? { custom_payment_type: paymentRecord.type } : {},
2425
+ type: nextPaymentType,
2426
+ order_payment_type: nextPaymentType
2427
+ };
2428
+ };
2393
2429
  const mappedVouchers = (0, import_utils.mapPaymentItemsToOrderPayments)(
2394
2430
  payments.map(
2395
- (payment) => this.normalizePaymentSource(payment, { defaultPaid: true })
2431
+ (payment) => this.normalizePaymentSource(withVoucherPaymentType(payment), { defaultPaid: true })
2396
2432
  )
2397
2433
  ).filter((payment) => {
2398
2434
  return isVoucherPayment(payment);
@@ -2634,7 +2670,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2634
2670
  */
2635
2671
  async addProductToOrder(product, booking) {
2636
2672
  const tempOrder = this.ensureTempOrder();
2637
- debugger;
2638
2673
  if (booking) {
2639
2674
  const productRecord = product;
2640
2675
  const splitCount = (0, import_utils3.getSafeProductNum)(
@@ -3964,6 +3999,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3964
3999
  async getOrderInfo(order_id) {
3965
4000
  const res = await this.request.get(`/order/sales/${order_id}`, {
3966
4001
  with: ["products", "bookings"]
4002
+ }, {
4003
+ osServer: true
3967
4004
  });
3968
4005
  return res;
3969
4006
  }
@@ -254,6 +254,10 @@ export declare function clearTempOrderHolderAssignments(tempOrder: OrderTempOrde
254
254
  * getOrderProductLineUid({ metadata: { unique_identification_number: 'line-1' } }); // 'line-1'
255
255
  */
256
256
  export declare function getOrderProductLineUid(product: Record<string, any> | null | undefined): string | null;
257
+ export declare function getRuntimeProductOrigin(tempOrder: OrderTempOrder | null | undefined, product: any): Record<string, any> | null;
258
+ export declare function isHolderConfigRequired(holderConfig: any): boolean;
259
+ export declare function productRequiresFormSubject(tempOrder: OrderTempOrder | null | undefined, product: any): boolean;
260
+ export declare function resolveIsFormSubject(tempOrder: OrderTempOrder | null | undefined, product?: any): boolean;
257
261
  /**
258
262
  * 判断展示字段是否为空(含 i18n 对象全空)。
259
263
  *
@@ -49,9 +49,11 @@ __export(utils_exports, {
49
49
  getBundleSignedUnit: () => getBundleSignedUnit,
50
50
  getOrderProductLineUid: () => getOrderProductLineUid,
51
51
  getProductSkuOptions: () => getProductSkuOptions,
52
+ getRuntimeProductOrigin: () => getRuntimeProductOrigin,
52
53
  hasAssignedHolderId: () => hasAssignedHolderId,
53
54
  indexOrderProductsByUid: () => indexOrderProductsByUid,
54
55
  isEmptyOrderProductDisplayValue: () => isEmptyOrderProductDisplayValue,
56
+ isHolderConfigRequired: () => isHolderConfigRequired,
55
57
  isMarkdownBundle: () => isMarkdownBundle,
56
58
  isTempOrder: () => isTempOrder,
57
59
  mapPaymentItemToOrderPayment: () => mapPaymentItemToOrderPayment,
@@ -65,7 +67,9 @@ __export(utils_exports, {
65
67
  normalizeProductSkuOptions: () => normalizeProductSkuOptions,
66
68
  normalizeSubmitBooking: () => normalizeSubmitBooking,
67
69
  normalizeSubmitCollectPaxValue: () => normalizeSubmitCollectPaxValue,
70
+ productRequiresFormSubject: () => productRequiresFormSubject,
68
71
  resolveEffectivePerUnitDiscount: () => resolveEffectivePerUnitDiscount,
72
+ resolveIsFormSubject: () => resolveIsFormSubject,
69
73
  resolveManualDiscountMessage: () => import_manualProductDiscount.resolveManualDiscountMessage,
70
74
  resolveManualDiscountOriginTotal: () => import_manualProductDiscount.resolveManualDiscountOriginTotal,
71
75
  resolveManualDiscountReasonFromSources: () => import_manualProductDiscount.resolveManualDiscountReasonFromSources,
@@ -1094,6 +1098,37 @@ function getOrderProductLineUid(product) {
1094
1098
  return null;
1095
1099
  return String(uid);
1096
1100
  }
1101
+ function getRuntimeProductOrigin(tempOrder, product) {
1102
+ var _a, _b, _c, _d, _e, _f;
1103
+ const uid = getOrderProductLineUid(product);
1104
+ if (uid && ((_c = (_b = (_a = tempOrder == null ? void 0 : tempOrder._extend) == null ? void 0 : _a.productsByUid) == null ? void 0 : _b[uid]) == null ? void 0 : _c.origin)) {
1105
+ return tempOrder._extend.productsByUid[uid].origin;
1106
+ }
1107
+ const matchedProduct = ((tempOrder == null ? void 0 : tempOrder.products) || []).find((item) => item === product || getOrderProductLineUid(item) === uid || String((item == null ? void 0 : item.product_id) ?? (item == null ? void 0 : item.id) ?? "") === String((product == null ? void 0 : product.product_id) ?? (product == null ? void 0 : product.id) ?? ""));
1108
+ const matchedUid = matchedProduct ? getOrderProductLineUid(matchedProduct) : "";
1109
+ return matchedUid ? ((_f = (_e = (_d = tempOrder == null ? void 0 : tempOrder._extend) == null ? void 0 : _d.productsByUid) == null ? void 0 : _e[matchedUid]) == null ? void 0 : _f.origin) || null : null;
1110
+ }
1111
+ function isHolderConfigRequired(holderConfig) {
1112
+ if (!holderConfig || typeof holderConfig !== "object")
1113
+ return false;
1114
+ if (holderConfig.status === "disable")
1115
+ return false;
1116
+ return Number(holderConfig.required) === 1;
1117
+ }
1118
+ function productRequiresFormSubject(tempOrder, product) {
1119
+ const runtimeOrigin = getRuntimeProductOrigin(tempOrder, product);
1120
+ return isHolderConfigRequired(product == null ? void 0 : product.holder_config) || isHolderConfigRequired(runtimeOrigin == null ? void 0 : runtimeOrigin.holder_config);
1121
+ }
1122
+ function resolveIsFormSubject(tempOrder, product) {
1123
+ var _a;
1124
+ if (((_a = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _a.type) === "form")
1125
+ return true;
1126
+ if (product)
1127
+ return productRequiresFormSubject(tempOrder, product);
1128
+ return ((tempOrder == null ? void 0 : tempOrder.products) || []).some(
1129
+ (item) => productRequiresFormSubject(tempOrder, item)
1130
+ );
1131
+ }
1097
1132
  function isEmptyOrderProductDisplayValue(value) {
1098
1133
  if (value === void 0 || value === null)
1099
1134
  return true;
@@ -1174,9 +1209,11 @@ function indexOrderProductsByUid(products) {
1174
1209
  getBundleSignedUnit,
1175
1210
  getOrderProductLineUid,
1176
1211
  getProductSkuOptions,
1212
+ getRuntimeProductOrigin,
1177
1213
  hasAssignedHolderId,
1178
1214
  indexOrderProductsByUid,
1179
1215
  isEmptyOrderProductDisplayValue,
1216
+ isHolderConfigRequired,
1180
1217
  isMarkdownBundle,
1181
1218
  isTempOrder,
1182
1219
  mapPaymentItemToOrderPayment,
@@ -1190,7 +1227,9 @@ function indexOrderProductsByUid(products) {
1190
1227
  normalizeProductSkuOptions,
1191
1228
  normalizeSubmitBooking,
1192
1229
  normalizeSubmitCollectPaxValue,
1230
+ productRequiresFormSubject,
1193
1231
  resolveEffectivePerUnitDiscount,
1232
+ resolveIsFormSubject,
1194
1233
  resolveManualDiscountMessage,
1195
1234
  resolveManualDiscountOriginTotal,
1196
1235
  resolveManualDiscountReasonFromSources,
@@ -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(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -1,6 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Rules, RulesModuleAPI, DiscountResult, UnavailableReason } from './types';
3
+ import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, UnavailableReason } from './types';
4
4
  import { Discount } from '../Discount/types';
5
5
  import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
6
6
  import { WindowPlugin } from '../../plugins';
@@ -24,7 +24,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
24
24
  holders: {
25
25
  form_record_id: number;
26
26
  }[];
27
- isFormSubject: boolean;
27
+ isFormSubject: RulesFormSubject;
28
28
  }): {
29
29
  isAvailable: boolean;
30
30
  discountList: Discount[];
@@ -43,7 +43,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
43
43
  holders: {
44
44
  form_record_id: number;
45
45
  }[];
46
- isFormSubject: boolean;
46
+ isFormSubject: RulesFormSubject;
47
47
  orderTotalAmount: number;
48
48
  }, options?: {
49
49
  isSelected?: boolean;
@@ -70,7 +70,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
70
70
  var _a;
71
71
  if (((_a = discount.holder) == null ? void 0 : _a.holder_type) !== "form")
72
72
  return true;
73
- const orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id : void 0;
73
+ const orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id || holders[0] : void 0;
74
74
  const productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
75
75
  if (!product.isNeedHolder)
76
76
  return true;
@@ -207,6 +207,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
207
207
  orderTotalAmount
208
208
  }, options) {
209
209
  var _a;
210
+ const resolveIsFormSubject = (product) => typeof isFormSubject === "function" ? Boolean(isFormSubject(product)) : Boolean(isFormSubject);
210
211
  const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
211
212
  const editModeDiscount = [];
212
213
  const addModeDiscount = [];
@@ -596,7 +597,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
596
597
  const isHolderMatch = this.checkHolderMatch(
597
598
  discount,
598
599
  {
599
- isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
600
+ isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
600
601
  holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
601
602
  },
602
603
  holders
@@ -767,7 +768,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
767
768
  const isHolderMatch = this.checkHolderMatch(
768
769
  discount,
769
770
  {
770
- isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
771
+ isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
771
772
  holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
772
773
  },
773
774
  holders
@@ -22,6 +22,7 @@ export interface DiscountResult {
22
22
  productList: any[];
23
23
  discountList: any[];
24
24
  }
25
+ export type RulesFormSubject = boolean | ((product: any) => boolean);
25
26
  export interface RulesModuleAPI {
26
27
  setRulesList: (rulesList: Rules[]) => Promise<void>;
27
28
  clear: () => Promise<void>;
@@ -31,7 +32,7 @@ export interface RulesModuleAPI {
31
32
  holders: {
32
33
  form_record_id: number;
33
34
  }[];
34
- isFormSubject: boolean;
35
+ isFormSubject: RulesFormSubject;
35
36
  orderTotalAmount: number;
36
37
  }) => DiscountResult;
37
38
  }
@@ -31,10 +31,10 @@ export declare class OrderModule extends BaseModule implements Module {
31
31
  private emitOrdersChanged;
32
32
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
33
33
  /**
34
- * 记录信息日志
35
- * @param title 日志标题
36
- * @param metadata 日志元数据
37
- */
34
+ * 记录信息日志
35
+ * @param title 日志标题
36
+ * @param metadata 日志元数据
37
+ */
38
38
  private logInfo;
39
39
  /**
40
40
  * 记录错误日志
@@ -109,10 +109,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
109
109
  });
110
110
  }
111
111
  /**
112
- * 记录信息日志
113
- * @param title 日志标题
114
- * @param metadata 日志元数据
115
- */
112
+ * 记录信息日志
113
+ * @param title 日志标题
114
+ * @param metadata 日志元数据
115
+ */
116
116
  logInfo(title, metadata) {
117
117
  try {
118
118
  if (this.logger) {
@@ -1019,7 +1019,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1019
1019
  });
1020
1020
  }
1021
1021
  async loadDiscountConfig(params) {
1022
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
1022
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
1023
1023
  if (!this.store.order)
1024
1024
  throw new Error("order 模块未初始化");
1025
1025
  const tempOrder = this.store.order.ensureTempOrder();
@@ -1090,13 +1090,15 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1090
1090
  };
1091
1091
  }
1092
1092
  if (rulesModule) {
1093
- const holders = ((_l = tempOrder.holder) == null ? void 0 : _l.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
1093
+ const holders = ((_l = tempOrder.holder) == null ? void 0 : _l.form_record) || [];
1094
+ const orderTotalAmount = Number(((_m = orderStore.summary) == null ? void 0 : _m.total_amount) || 0);
1095
+ console.log("[BaseSales.applyDiscountConfig.calcDiscount]");
1094
1096
  const result = rulesModule.calcDiscount({
1095
1097
  productList: tempOrder.products,
1096
1098
  discountList: nextDiscountList,
1097
1099
  holders,
1098
- isFormSubject: !!((_m = tempOrder.holder) == null ? void 0 : _m.type) && tempOrder.holder.type === "form",
1099
- orderTotalAmount: Number(((_n = orderStore.summary) == null ? void 0 : _n.total_amount) || 0)
1100
+ isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
1101
+ orderTotalAmount
1100
1102
  }) || { productList: tempOrder.products, discountList: nextDiscountList };
1101
1103
  if (result.productList) {
1102
1104
  tempOrder.products = preserveManualProductDiscountProducts(
@@ -1105,8 +1107,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1105
1107
  );
1106
1108
  }
1107
1109
  for (const product of tempOrder.products || []) {
1108
- const productUid = (_o = product.metadata) == null ? void 0 : _o.unique_identification_number;
1109
- const runtimeOrigin = productUid ? (_r = (_q = (_p = tempOrder._extend) == null ? void 0 : _p.productsByUid) == null ? void 0 : _q[productUid]) == null ? void 0 : _r.origin : void 0;
1110
+ const productUid = (_n = product.metadata) == null ? void 0 : _n.unique_identification_number;
1111
+ const runtimeOrigin = productUid ? (_q = (_p = (_o = tempOrder._extend) == null ? void 0 : _o.productsByUid) == null ? void 0 : _p[productUid]) == null ? void 0 : _q.origin : void 0;
1110
1112
  if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
1111
1113
  continue;
1112
1114
  const totalPerUnitDiscount = (product.discount_list || []).reduce(
@@ -1114,7 +1116,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1114
1116
  0
1115
1117
  );
1116
1118
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
1117
- const sourcePrice = ((_s = product.metadata) == null ? void 0 : _s.source_product_price) ?? (((_t = product.metadata) == null ? void 0 : _t.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
1119
+ const sourcePrice = ((_r = product.metadata) == null ? void 0 : _r.source_product_price) ?? (((_s = product.metadata) == null ? void 0 : _s.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
1118
1120
  const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1119
1121
  const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
1120
1122
  if (product.metadata) {
@@ -1150,7 +1152,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1150
1152
  };
1151
1153
  }
1152
1154
  async bestDiscount(cb) {
1153
- var _a, _b, _c, _d, _e;
1155
+ var _a, _b, _c, _d;
1154
1156
  if (!this.store.order)
1155
1157
  throw new Error("order 模块未初始化");
1156
1158
  const tempOrder = this.store.order.ensureTempOrder();
@@ -1169,13 +1171,15 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1169
1171
  };
1170
1172
  await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
1171
1173
  if (rulesModule) {
1172
- const holders = ((_c = tempOrder.holder) == null ? void 0 : _c.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
1174
+ const holders = ((_c = tempOrder.holder) == null ? void 0 : _c.form_record) || [];
1175
+ const orderTotalAmount = Number(((_d = orderStore.summary) == null ? void 0 : _d.total_amount) || 0);
1176
+ console.log("[BaseSales.bestDiscount.calcDiscount]");
1173
1177
  result = rulesModule.calcDiscount({
1174
1178
  productList: tempOrder.products,
1175
1179
  discountList: nextDiscountList,
1176
1180
  holders,
1177
- isFormSubject: !!((_d = tempOrder.holder) == null ? void 0 : _d.type) && tempOrder.holder.type === "form",
1178
- orderTotalAmount: Number(((_e = orderStore.summary) == null ? void 0 : _e.total_amount) || 0)
1181
+ isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
1182
+ orderTotalAmount
1179
1183
  }) || result;
1180
1184
  if (result.productList) {
1181
1185
  tempOrder.products = preserveManualProductDiscountProducts(
@@ -1244,16 +1248,19 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1244
1248
  const orderStore = this.store.order.store || {};
1245
1249
  const discountModule = orderStore.discount;
1246
1250
  const rulesModule = orderStore.rules;
1247
- const holders = ((_a = tempOrder.holder) == null ? void 0 : _a.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
1251
+ const holders = ((_a = tempOrder.holder) == null ? void 0 : _a.form_record) || [];
1248
1252
  let nextDiscountList = updated;
1249
1253
  await (discountModule == null ? void 0 : discountModule.setDiscountList(updated));
1250
1254
  if (rulesModule) {
1255
+ const orderTotalAmount = Number(((_b = orderStore.summary) == null ? void 0 : _b.total_amount) || 0);
1256
+ console.log("[BaseSales.setDiscountSelected.calcDiscount]");
1251
1257
  const result = rulesModule.calcDiscount(
1252
1258
  {
1253
1259
  productList: tempOrder.products,
1254
1260
  discountList: updated,
1255
1261
  holders,
1256
- isFormSubject: !!((_b = tempOrder.holder) == null ? void 0 : _b.type) && tempOrder.holder.type === "form"
1262
+ isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
1263
+ orderTotalAmount
1257
1264
  },
1258
1265
  {
1259
1266
  discountId: params.discountId,
@@ -129,10 +129,9 @@ function transformBaseProductToOrderProduct(params) {
129
129
  payload.price ?? payload.selling_price ?? (matchedVariant == null ? void 0 : matchedVariant.price) ?? (matchedVariant == null ? void 0 : matchedVariant.base_price) ?? (origin == null ? void 0 : origin.price) ?? (origin == null ? void 0 : origin.base_price) ?? (sourceProduct == null ? void 0 : sourceProduct.price) ?? (sourceProduct == null ? void 0 : sourceProduct.selling_price) ?? (sourceProduct == null ? void 0 : sourceProduct.base_price),
130
130
  "0.00"
131
131
  );
132
- const lineCompositeTotal = toPriceString(
133
- payload.line_total ?? payload.total ?? ((_c = payload._extend) == null ? void 0 : _c.total),
134
- sourceProductPrice
135
- );
132
+ const explicitLineTotal = payload.line_total ?? payload.total ?? ((_c = payload._extend) == null ? void 0 : _c.total);
133
+ const hasExplicitLineTotal = Number.isFinite(Number(explicitLineTotal));
134
+ const lineCompositeTotal = toPriceString(explicitLineTotal, sourceProductPrice);
136
135
  const hasPriceOverride = payload.price_override !== void 0 && payload.price_override !== null && payload.price_override !== "";
137
136
  const productOptionItem = (0, import_utils.normalizeProductSkuOptions)(
138
137
  normalizeOptionItems(
@@ -180,7 +179,7 @@ function transformBaseProductToOrderProduct(params) {
180
179
  const optionSum = (0, import_utils.sumOptionUnitPrice)(productOptionItem).toNumber();
181
180
  const mainProductOriginalPrice = toPriceString(Number(sourceProductPrice) + optionSum);
182
181
  const bundleOnlyComposite = (0, import_utils.composeLinePrice)({ mainPrice: 0, bundle: productBundle });
183
- const derivedMainSelling = Number(lineCompositeTotal) - Number(bundleOnlyComposite);
182
+ const derivedMainSelling = hasExplicitLineTotal ? Number(lineCompositeTotal) - Number(bundleOnlyComposite) : Number(mainProductOriginalPrice);
184
183
  const mainProductSellingPrice = toPriceString(
185
184
  Number.isFinite(derivedMainSelling) && derivedMainSelling >= 0 ? derivedMainSelling : Number(mainProductOriginalPrice)
186
185
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.6",
4
+ "version": "2.3.7",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",