@pisell/pisellos 2.3.6 → 2.3.8

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.
Files changed (38) hide show
  1. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +17 -13
  2. package/dist/modules/Order/index.d.ts +18 -2
  3. package/dist/modules/Order/index.js +392 -222
  4. package/dist/modules/Order/types.d.ts +15 -2
  5. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  6. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  7. package/dist/modules/Order/utils.d.ts +4 -0
  8. package/dist/modules/Order/utils.js +114 -28
  9. package/dist/modules/Product/index.d.ts +1 -1
  10. package/dist/modules/Rules/index.d.ts +3 -3
  11. package/dist/modules/Rules/index.js +8 -3
  12. package/dist/modules/Rules/types.d.ts +2 -1
  13. package/dist/server/index.js +1 -0
  14. package/dist/server/modules/order/index.d.ts +4 -4
  15. package/dist/server/modules/order/index.js +4 -4
  16. package/dist/solution/BaseSales/index.d.ts +8 -1
  17. package/dist/solution/BaseSales/index.js +145 -104
  18. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -2
  19. package/dist/solution/BookingByStep/index.d.ts +1 -1
  20. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -1
  21. package/lib/modules/Order/index.d.ts +18 -2
  22. package/lib/modules/Order/index.js +229 -40
  23. package/lib/modules/Order/types.d.ts +15 -2
  24. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  25. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  26. package/lib/modules/Order/utils.d.ts +4 -0
  27. package/lib/modules/Order/utils.js +84 -2
  28. package/lib/modules/Product/index.d.ts +1 -1
  29. package/lib/modules/Rules/index.d.ts +3 -3
  30. package/lib/modules/Rules/index.js +4 -3
  31. package/lib/modules/Rules/types.d.ts +2 -1
  32. package/lib/server/modules/order/index.d.ts +4 -4
  33. package/lib/server/modules/order/index.js +4 -4
  34. package/lib/solution/BaseSales/index.d.ts +8 -1
  35. package/lib/solution/BaseSales/index.js +58 -22
  36. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -5
  37. package/lib/solution/BookingByStep/index.d.ts +1 -1
  38. package/package.json +1 -1
@@ -165,10 +165,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
165
165
  return ["products", "order", "salesSummary", "schedule", "payment", "quotation"];
166
166
  }
167
167
  getReusableSharedSubModule(moduleName) {
168
- var _a;
168
+ var _a, _b;
169
169
  if (moduleName !== "schedule" && moduleName !== "quotation")
170
170
  return null;
171
- return ((_a = this.core) == null ? void 0 : _a.getModule(moduleName)) || null;
171
+ return ((_b = (_a = this.core) == null ? void 0 : _a.getModule) == null ? void 0 : _b.call(_a, moduleName)) || null;
172
172
  }
173
173
  isScheduleListLoaded(scheduleModule) {
174
174
  if (!scheduleModule)
@@ -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,
@@ -1276,6 +1283,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1276
1283
  if (d.isSelected && !beforeSelectedIds.has(d.id)) {
1277
1284
  d.isSelected = false;
1278
1285
  d.isManualSelect = true;
1286
+ d.appliedProductDetails = [];
1279
1287
  }
1280
1288
  }
1281
1289
  }
@@ -1284,16 +1292,32 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1284
1292
  const selectedResourceIds = new Set(
1285
1293
  nextDiscountList.filter((d) => d.isSelected).map((d) => d.id)
1286
1294
  );
1295
+ const filterSelectedDiscountDetails = (discountList) => (discountList || []).filter((pd) => {
1296
+ var _a2;
1297
+ const rid = ((_a2 = pd.discount) == null ? void 0 : _a2.resource_id) ?? pd.id;
1298
+ return rid != null && selectedResourceIds.has(rid);
1299
+ });
1287
1300
  for (const product of tempOrder.products) {
1288
1301
  const productUid = (_c = product.metadata) == null ? void 0 : _c.unique_identification_number;
1289
1302
  const runtimeOrigin = productUid ? (_f = (_e = (_d = tempOrder._extend) == null ? void 0 : _d.productsByUid) == null ? void 0 : _e[productUid]) == null ? void 0 : _f.origin : void 0;
1290
1303
  if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
1291
1304
  continue;
1292
- product.discount_list = (product.discount_list || []).filter((pd) => {
1293
- var _a2;
1294
- const rid = ((_a2 = pd.discount) == null ? void 0 : _a2.resource_id) ?? pd.id;
1295
- return rid != null && selectedResourceIds.has(rid);
1296
- });
1305
+ product.discount_list = filterSelectedDiscountDetails(product.discount_list);
1306
+ if (Array.isArray(product.product_bundle)) {
1307
+ product.product_bundle = product.product_bundle.map((bundle) => {
1308
+ const nextBundleDiscountList = filterSelectedDiscountDetails(bundle == null ? void 0 : bundle.discount_list);
1309
+ const shouldRestoreBundlePrice = nextBundleDiscountList.length === 0;
1310
+ const restoredBundlePrice = (bundle == null ? void 0 : bundle.original_price) ?? (bundle == null ? void 0 : bundle.product_price) ?? (bundle == null ? void 0 : bundle.price);
1311
+ return {
1312
+ ...bundle,
1313
+ ...shouldRestoreBundlePrice ? {
1314
+ price: restoredBundlePrice,
1315
+ bundle_selling_price: restoredBundlePrice
1316
+ } : {},
1317
+ discount_list: nextBundleDiscountList
1318
+ };
1319
+ });
1320
+ }
1297
1321
  const totalPerUnitDiscount = (product.discount_list || []).reduce(
1298
1322
  (sum, pd) => sum + (pd.amount || 0),
1299
1323
  0
@@ -1382,6 +1406,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1382
1406
  ...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
1383
1407
  ...inferredPaymentStatus !== void 0 ? { paymentStatus: inferredPaymentStatus } : {},
1384
1408
  ...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
1409
+ ...(params == null ? void 0 : params.confirmPendingVoucherPayments) !== void 0 ? { confirmPendingVoucherPayments: params.confirmPendingVoucherPayments } : {},
1385
1410
  ...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
1386
1411
  };
1387
1412
  return this.store.order.submitTempOrder(submitParams);
@@ -1401,6 +1426,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1401
1426
  ...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
1402
1427
  ...inferredPaymentStatus !== void 0 ? { paymentStatus: inferredPaymentStatus } : {},
1403
1428
  ...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
1429
+ ...(params == null ? void 0 : params.confirmPendingVoucherPayments) !== void 0 ? { confirmPendingVoucherPayments: params.confirmPendingVoucherPayments } : {},
1404
1430
  ...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
1405
1431
  };
1406
1432
  return this.store.order.submitTempOrderAsync(submitParams);
@@ -1592,10 +1618,20 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1592
1618
  return this.store.order.deleteOrderPayment(paymentIdentity);
1593
1619
  }
1594
1620
  /** 覆盖 wallet pass 支付项,同时保留普通支付项。 */
1595
- updateVoucherOrderPayments(payments) {
1621
+ updateVoucherOrderPayments(payments, options) {
1622
+ if (!this.store.order)
1623
+ throw new Error("order 模块未初始化");
1624
+ return this.store.order.updateVoucherOrderPayments(payments, options);
1625
+ }
1626
+ confirmPendingVoucherPayments() {
1627
+ if (!this.store.order)
1628
+ throw new Error("order 模块未初始化");
1629
+ return this.store.order.confirmPendingVoucherPayments();
1630
+ }
1631
+ discardPendingVoucherPayments() {
1596
1632
  if (!this.store.order)
1597
1633
  throw new Error("order 模块未初始化");
1598
- return this.store.order.updateVoucherOrderPayments(payments);
1634
+ return this.store.order.discardPendingVoucherPayments();
1599
1635
  }
1600
1636
  getWalletProductList() {
1601
1637
  var _a, _b, _c;
@@ -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
  );
@@ -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 | 1 | 2 | 6 | 3 | 4 | 5;
314
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
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.8",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",