@pisell/pisellos 2.3.5 → 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.
Files changed (40) hide show
  1. package/dist/core/index.js +1 -1
  2. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  3. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +17 -13
  4. package/dist/modules/Order/index.d.ts +12 -1
  5. package/dist/modules/Order/index.js +260 -160
  6. package/dist/modules/Order/types.d.ts +5 -0
  7. package/dist/modules/Order/utils.d.ts +4 -0
  8. package/dist/modules/Order/utils.js +31 -0
  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 +4 -3
  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.js +93 -68
  17. package/dist/solution/BaseSales/types.d.ts +1 -0
  18. package/dist/solution/BaseSales/types.js +2 -1
  19. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -2
  20. package/dist/solution/BookingByStep/index.d.ts +1 -1
  21. package/lib/core/index.js +1 -1
  22. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -1
  23. package/lib/modules/Order/index.d.ts +12 -1
  24. package/lib/modules/Order/index.js +135 -26
  25. package/lib/modules/Order/types.d.ts +5 -0
  26. package/lib/modules/Order/utils.d.ts +4 -0
  27. package/lib/modules/Order/utils.js +39 -0
  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/index.js +1 -4
  33. package/lib/server/modules/order/index.d.ts +4 -4
  34. package/lib/server/modules/order/index.js +4 -4
  35. package/lib/solution/BaseSales/index.js +40 -19
  36. package/lib/solution/BaseSales/types.d.ts +1 -0
  37. package/lib/solution/BaseSales/types.js +2 -1
  38. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -5
  39. package/lib/solution/BookingByStep/index.d.ts +1 -1
  40. package/package.json +1 -1
@@ -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,
@@ -1480,14 +1487,27 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1480
1487
  });
1481
1488
  try {
1482
1489
  const syncResult = await this.store.order.syncPaymentsToOrder(syncParams);
1483
- await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
1490
+ const latestPayments = this.store.order.getOrderPayments();
1491
+ const amountSnapshot = this.store.order.getOrderAmountSnapshot();
1492
+ const orderSnapshot = this.store.order.getOrderSnapshot();
1493
+ const syncPayload = {
1484
1494
  ok: true,
1485
1495
  syncResult,
1486
- payments: this.store.order.getOrderPayments(),
1496
+ payments: latestPayments,
1487
1497
  params: syncParams,
1488
- amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1489
- orderSnapshot: this.store.order.getOrderSnapshot()
1490
- });
1498
+ amountSnapshot,
1499
+ orderSnapshot,
1500
+ isFullyPaid: syncResult.isFullyPaid,
1501
+ isOrderFullyPaid: syncResult.isOrderFullyPaid,
1502
+ isDepositFullyPaid: syncResult.isDepositFullyPaid,
1503
+ paymentStage: syncResult.paymentStage,
1504
+ depositAmount: syncResult.depositAmount,
1505
+ orderExpectedAmount: syncResult.orderExpectedAmount
1506
+ };
1507
+ await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, syncPayload);
1508
+ if (syncResult.isDepositFullyPaid && !syncResult.isOrderFullyPaid) {
1509
+ await this.effectsEmit(import_types.BaseSalesHookNames.onDepositPaymentSyncEnd, syncPayload);
1510
+ }
1491
1511
  return syncResult;
1492
1512
  } catch (error) {
1493
1513
  await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
@@ -1550,7 +1570,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1550
1570
  const amountSnapshot = this.store.order.getOrderAmountSnapshot();
1551
1571
  const syncState = this.store.order.getOrderSyncState();
1552
1572
  if (amountSnapshot && syncState !== "submitting") {
1553
- const paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? "paid" : "partially_paid";
1573
+ const completion = this.store.order.getPaymentCompletion(payments);
1574
+ const paymentStatus = completion.isOrderFullyPaid ? "paid" : "partially_paid";
1554
1575
  void this.syncPaymentsToOrder({
1555
1576
  payments,
1556
1577
  paymentStatus,
@@ -14,6 +14,7 @@ export declare const BaseSalesHookNames: {
14
14
  readonly onCartValidationChanged: "onCartValidationChanged";
15
15
  readonly onPaymentSyncStart: "onPaymentSyncStart";
16
16
  readonly onPaymentSyncEnd: "onPaymentSyncEnd";
17
+ readonly onDepositPaymentSyncEnd: "onDepositPaymentSyncEnd";
17
18
  };
18
19
  export type BaseSalesHookName = typeof BaseSalesHookNames[keyof typeof BaseSalesHookNames];
19
20
  export declare function createBaseSalesHook(moduleName: string, hookName: BaseSalesHookName): string;
@@ -30,7 +30,8 @@ var BaseSalesHookNames = {
30
30
  onRefresh: "onRefresh",
31
31
  onCartValidationChanged: "onCartValidationChanged",
32
32
  onPaymentSyncStart: "onPaymentSyncStart",
33
- onPaymentSyncEnd: "onPaymentSyncEnd"
33
+ onPaymentSyncEnd: "onPaymentSyncEnd",
34
+ onDepositPaymentSyncEnd: "onDepositPaymentSyncEnd"
34
35
  };
35
36
  function createBaseSalesHook(moduleName, hookName) {
36
37
  return `${moduleName}:${hookName}`;
@@ -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 | 2 | 1 | 5 | 3 | 4 | 6;
314
+ weekNum: 0 | 1 | 2 | 6 | 3 | 4 | 5;
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.5",
4
+ "version": "2.3.7",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",