@pisell/pisellos 2.2.256 → 2.2.258

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 (52) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +17 -13
  3. package/dist/modules/Order/index.d.ts +29 -1
  4. package/dist/modules/Order/index.js +508 -241
  5. package/dist/modules/Order/types.d.ts +20 -2
  6. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  7. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  8. package/dist/modules/Order/utils.d.ts +4 -0
  9. package/dist/modules/Order/utils.js +114 -28
  10. package/dist/modules/Product/index.d.ts +1 -1
  11. package/dist/modules/Product/types.d.ts +6 -0
  12. package/dist/modules/Rules/index.d.ts +3 -3
  13. package/dist/modules/Rules/index.js +8 -3
  14. package/dist/modules/Rules/types.d.ts +2 -1
  15. package/dist/server/index.d.ts +12 -2
  16. package/dist/server/index.js +1227 -923
  17. package/dist/server/modules/order/index.d.ts +22 -3
  18. package/dist/server/modules/order/index.js +397 -314
  19. package/dist/solution/BaseSales/index.d.ts +16 -2
  20. package/dist/solution/BaseSales/index.js +484 -314
  21. package/dist/solution/BaseSales/types.d.ts +1 -0
  22. package/dist/solution/BaseSales/types.js +2 -1
  23. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -2
  24. package/dist/solution/BookingByStep/index.d.ts +1 -1
  25. package/dist/solution/BookingTicket/index.d.ts +9 -1
  26. package/dist/solution/BookingTicket/index.js +162 -6
  27. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -1
  28. package/lib/modules/Order/index.d.ts +29 -1
  29. package/lib/modules/Order/index.js +340 -57
  30. package/lib/modules/Order/types.d.ts +20 -2
  31. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  32. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  33. package/lib/modules/Order/utils.d.ts +4 -0
  34. package/lib/modules/Order/utils.js +84 -2
  35. package/lib/modules/Product/index.d.ts +1 -1
  36. package/lib/modules/Product/types.d.ts +6 -0
  37. package/lib/modules/Rules/index.d.ts +3 -3
  38. package/lib/modules/Rules/index.js +4 -3
  39. package/lib/modules/Rules/types.d.ts +2 -1
  40. package/lib/server/index.d.ts +12 -2
  41. package/lib/server/index.js +218 -12
  42. package/lib/server/modules/order/index.d.ts +22 -3
  43. package/lib/server/modules/order/index.js +102 -51
  44. package/lib/solution/BaseSales/index.d.ts +16 -2
  45. package/lib/solution/BaseSales/index.js +143 -31
  46. package/lib/solution/BaseSales/types.d.ts +1 -0
  47. package/lib/solution/BaseSales/types.js +2 -1
  48. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -5
  49. package/lib/solution/BookingByStep/index.d.ts +1 -1
  50. package/lib/solution/BookingTicket/index.d.ts +9 -1
  51. package/lib/solution/BookingTicket/index.js +112 -0
  52. package/package.json +1 -1
@@ -156,6 +156,9 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
156
156
  this.hasManualDiscountSelection = false;
157
157
  this.reusedSharedSubModuleNames = /* @__PURE__ */ new Set();
158
158
  this.paymentMethodsCache = [];
159
+ this.queuedAutoPaymentSync = false;
160
+ this.autoPaymentSyncFlushing = false;
161
+ this.autoPaymentSyncTimer = null;
159
162
  }
160
163
  /**
161
164
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
@@ -165,10 +168,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
165
168
  return ["products", "order", "salesSummary", "schedule", "payment", "quotation"];
166
169
  }
167
170
  getReusableSharedSubModule(moduleName) {
168
- var _a;
171
+ var _a, _b;
169
172
  if (moduleName !== "schedule" && moduleName !== "quotation")
170
173
  return null;
171
- return ((_a = this.core) == null ? void 0 : _a.getModule(moduleName)) || null;
174
+ return ((_b = (_a = this.core) == null ? void 0 : _a.getModule) == null ? void 0 : _b.call(_a, moduleName)) || null;
172
175
  }
173
176
  isScheduleListLoaded(scheduleModule) {
174
177
  if (!scheduleModule)
@@ -1019,7 +1022,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1019
1022
  });
1020
1023
  }
1021
1024
  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;
1025
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
1023
1026
  if (!this.store.order)
1024
1027
  throw new Error("order 模块未初始化");
1025
1028
  const tempOrder = this.store.order.ensureTempOrder();
@@ -1090,13 +1093,15 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1090
1093
  };
1091
1094
  }
1092
1095
  if (rulesModule) {
1093
- const holders = ((_l = tempOrder.holder) == null ? void 0 : _l.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
1096
+ const holders = ((_l = tempOrder.holder) == null ? void 0 : _l.form_record) || [];
1097
+ const orderTotalAmount = Number(((_m = orderStore.summary) == null ? void 0 : _m.total_amount) || 0);
1098
+ console.log("[BaseSales.applyDiscountConfig.calcDiscount]");
1094
1099
  const result = rulesModule.calcDiscount({
1095
1100
  productList: tempOrder.products,
1096
1101
  discountList: nextDiscountList,
1097
1102
  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)
1103
+ isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
1104
+ orderTotalAmount
1100
1105
  }) || { productList: tempOrder.products, discountList: nextDiscountList };
1101
1106
  if (result.productList) {
1102
1107
  tempOrder.products = preserveManualProductDiscountProducts(
@@ -1105,8 +1110,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1105
1110
  );
1106
1111
  }
1107
1112
  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;
1113
+ const productUid = (_n = product.metadata) == null ? void 0 : _n.unique_identification_number;
1114
+ 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
1115
  if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
1111
1116
  continue;
1112
1117
  const totalPerUnitDiscount = (product.discount_list || []).reduce(
@@ -1114,7 +1119,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1114
1119
  0
1115
1120
  );
1116
1121
  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");
1122
+ 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
1123
  const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1119
1124
  const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
1120
1125
  if (product.metadata) {
@@ -1150,7 +1155,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1150
1155
  };
1151
1156
  }
1152
1157
  async bestDiscount(cb) {
1153
- var _a, _b, _c, _d, _e;
1158
+ var _a, _b, _c, _d;
1154
1159
  if (!this.store.order)
1155
1160
  throw new Error("order 模块未初始化");
1156
1161
  const tempOrder = this.store.order.ensureTempOrder();
@@ -1169,13 +1174,15 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1169
1174
  };
1170
1175
  await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
1171
1176
  if (rulesModule) {
1172
- const holders = ((_c = tempOrder.holder) == null ? void 0 : _c.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
1177
+ const holders = ((_c = tempOrder.holder) == null ? void 0 : _c.form_record) || [];
1178
+ const orderTotalAmount = Number(((_d = orderStore.summary) == null ? void 0 : _d.total_amount) || 0);
1179
+ console.log("[BaseSales.bestDiscount.calcDiscount]");
1173
1180
  result = rulesModule.calcDiscount({
1174
1181
  productList: tempOrder.products,
1175
1182
  discountList: nextDiscountList,
1176
1183
  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)
1184
+ isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
1185
+ orderTotalAmount
1179
1186
  }) || result;
1180
1187
  if (result.productList) {
1181
1188
  tempOrder.products = preserveManualProductDiscountProducts(
@@ -1244,16 +1251,19 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1244
1251
  const orderStore = this.store.order.store || {};
1245
1252
  const discountModule = orderStore.discount;
1246
1253
  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 }] : [];
1254
+ const holders = ((_a = tempOrder.holder) == null ? void 0 : _a.form_record) || [];
1248
1255
  let nextDiscountList = updated;
1249
1256
  await (discountModule == null ? void 0 : discountModule.setDiscountList(updated));
1250
1257
  if (rulesModule) {
1258
+ const orderTotalAmount = Number(((_b = orderStore.summary) == null ? void 0 : _b.total_amount) || 0);
1259
+ console.log("[BaseSales.setDiscountSelected.calcDiscount]");
1251
1260
  const result = rulesModule.calcDiscount(
1252
1261
  {
1253
1262
  productList: tempOrder.products,
1254
1263
  discountList: updated,
1255
1264
  holders,
1256
- isFormSubject: !!((_b = tempOrder.holder) == null ? void 0 : _b.type) && tempOrder.holder.type === "form"
1265
+ isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
1266
+ orderTotalAmount
1257
1267
  },
1258
1268
  {
1259
1269
  discountId: params.discountId,
@@ -1276,6 +1286,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1276
1286
  if (d.isSelected && !beforeSelectedIds.has(d.id)) {
1277
1287
  d.isSelected = false;
1278
1288
  d.isManualSelect = true;
1289
+ d.appliedProductDetails = [];
1279
1290
  }
1280
1291
  }
1281
1292
  }
@@ -1284,16 +1295,32 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1284
1295
  const selectedResourceIds = new Set(
1285
1296
  nextDiscountList.filter((d) => d.isSelected).map((d) => d.id)
1286
1297
  );
1298
+ const filterSelectedDiscountDetails = (discountList) => (discountList || []).filter((pd) => {
1299
+ var _a2;
1300
+ const rid = ((_a2 = pd.discount) == null ? void 0 : _a2.resource_id) ?? pd.id;
1301
+ return rid != null && selectedResourceIds.has(rid);
1302
+ });
1287
1303
  for (const product of tempOrder.products) {
1288
1304
  const productUid = (_c = product.metadata) == null ? void 0 : _c.unique_identification_number;
1289
1305
  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
1306
  if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
1291
1307
  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
- });
1308
+ product.discount_list = filterSelectedDiscountDetails(product.discount_list);
1309
+ if (Array.isArray(product.product_bundle)) {
1310
+ product.product_bundle = product.product_bundle.map((bundle) => {
1311
+ const nextBundleDiscountList = filterSelectedDiscountDetails(bundle == null ? void 0 : bundle.discount_list);
1312
+ const shouldRestoreBundlePrice = nextBundleDiscountList.length === 0;
1313
+ const restoredBundlePrice = (bundle == null ? void 0 : bundle.original_price) ?? (bundle == null ? void 0 : bundle.product_price) ?? (bundle == null ? void 0 : bundle.price);
1314
+ return {
1315
+ ...bundle,
1316
+ ...shouldRestoreBundlePrice ? {
1317
+ price: restoredBundlePrice,
1318
+ bundle_selling_price: restoredBundlePrice
1319
+ } : {},
1320
+ discount_list: nextBundleDiscountList
1321
+ };
1322
+ });
1323
+ }
1297
1324
  const totalPerUnitDiscount = (product.discount_list || []).reduce(
1298
1325
  (sum, pd) => sum + (pd.amount || 0),
1299
1326
  0
@@ -1382,6 +1409,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1382
1409
  ...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
1383
1410
  ...inferredPaymentStatus !== void 0 ? { paymentStatus: inferredPaymentStatus } : {},
1384
1411
  ...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
1412
+ ...(params == null ? void 0 : params.confirmPendingVoucherPayments) !== void 0 ? { confirmPendingVoucherPayments: params.confirmPendingVoucherPayments } : {},
1385
1413
  ...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
1386
1414
  };
1387
1415
  return this.store.order.submitTempOrder(submitParams);
@@ -1401,6 +1429,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1401
1429
  ...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
1402
1430
  ...inferredPaymentStatus !== void 0 ? { paymentStatus: inferredPaymentStatus } : {},
1403
1431
  ...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
1432
+ ...(params == null ? void 0 : params.confirmPendingVoucherPayments) !== void 0 ? { confirmPendingVoucherPayments: params.confirmPendingVoucherPayments } : {},
1404
1433
  ...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
1405
1434
  };
1406
1435
  return this.store.order.submitTempOrderAsync(submitParams);
@@ -1469,6 +1498,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1469
1498
  };
1470
1499
  const syncState = this.store.order.getOrderSyncState();
1471
1500
  if (params.submitWhenPaid && syncState === "submitting") {
1501
+ this.queueLatestAutoPaymentSync();
1472
1502
  return this.store.order.syncPaymentsToOrder(syncParams);
1473
1503
  }
1474
1504
  const payments = params.payments || [];
@@ -1480,14 +1510,28 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1480
1510
  });
1481
1511
  try {
1482
1512
  const syncResult = await this.store.order.syncPaymentsToOrder(syncParams);
1483
- await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
1513
+ const latestPayments = this.store.order.getOrderPayments();
1514
+ const amountSnapshot = this.store.order.getOrderAmountSnapshot();
1515
+ const orderSnapshot = this.store.order.getOrderSnapshot();
1516
+ const syncPayload = {
1484
1517
  ok: true,
1485
1518
  syncResult,
1486
- payments: this.store.order.getOrderPayments(),
1519
+ payments: latestPayments,
1487
1520
  params: syncParams,
1488
- amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1489
- orderSnapshot: this.store.order.getOrderSnapshot()
1490
- });
1521
+ amountSnapshot,
1522
+ orderSnapshot,
1523
+ isFullyPaid: syncResult.isFullyPaid,
1524
+ isOrderFullyPaid: syncResult.isOrderFullyPaid,
1525
+ isDepositFullyPaid: syncResult.isDepositFullyPaid,
1526
+ paymentStage: syncResult.paymentStage,
1527
+ depositAmount: syncResult.depositAmount,
1528
+ orderExpectedAmount: syncResult.orderExpectedAmount
1529
+ };
1530
+ await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, syncPayload);
1531
+ if (syncResult.isDepositFullyPaid && !syncResult.isOrderFullyPaid) {
1532
+ await this.effectsEmit(import_types.BaseSalesHookNames.onDepositPaymentSyncEnd, syncPayload);
1533
+ }
1534
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
1491
1535
  return syncResult;
1492
1536
  } catch (error) {
1493
1537
  await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
@@ -1498,6 +1542,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1498
1542
  amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1499
1543
  orderSnapshot: this.store.order.getOrderSnapshot()
1500
1544
  });
1545
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
1501
1546
  throw error;
1502
1547
  }
1503
1548
  }
@@ -1514,6 +1559,61 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1514
1559
  throw new Error("order 模块未初始化");
1515
1560
  return this.store.order.setOrderPayments(payments);
1516
1561
  }
1562
+ getPaymentStatusForSync(payments) {
1563
+ const order = this.store.order;
1564
+ if (!order)
1565
+ throw new Error("order 模块未初始化");
1566
+ const completion = order.getPaymentCompletion(payments);
1567
+ return completion.isOrderFullyPaid ? "paid" : "partially_paid";
1568
+ }
1569
+ queueLatestAutoPaymentSync() {
1570
+ this.queuedAutoPaymentSync = true;
1571
+ this.scheduleQueuedAutoPaymentSyncFlush();
1572
+ }
1573
+ scheduleQueuedAutoPaymentSyncFlush(delay = 100) {
1574
+ if (!this.queuedAutoPaymentSync)
1575
+ return;
1576
+ if (this.autoPaymentSyncTimer)
1577
+ return;
1578
+ this.autoPaymentSyncTimer = setTimeout(() => {
1579
+ this.autoPaymentSyncTimer = null;
1580
+ void this.flushQueuedAutoPaymentSync();
1581
+ }, delay);
1582
+ }
1583
+ async flushQueuedAutoPaymentSync() {
1584
+ if (!this.store.order)
1585
+ return;
1586
+ if (!this.queuedAutoPaymentSync || this.autoPaymentSyncFlushing)
1587
+ return;
1588
+ if (this.store.order.getOrderSyncState() === "submitting") {
1589
+ this.scheduleQueuedAutoPaymentSyncFlush();
1590
+ return;
1591
+ }
1592
+ this.autoPaymentSyncFlushing = true;
1593
+ try {
1594
+ while (this.queuedAutoPaymentSync) {
1595
+ this.queuedAutoPaymentSync = false;
1596
+ const payments = this.store.order.getOrderPayments();
1597
+ if (!payments.length)
1598
+ continue;
1599
+ await this.syncPaymentsToOrder({
1600
+ payments,
1601
+ paymentStatus: this.getPaymentStatusForSync(payments),
1602
+ submitWhenPaid: true,
1603
+ smallTicketDataFlag: 1
1604
+ });
1605
+ }
1606
+ } catch (error) {
1607
+ this.logError("queued auto sync payments failed", {
1608
+ error: error instanceof Error ? error.message : String(error)
1609
+ });
1610
+ } finally {
1611
+ this.autoPaymentSyncFlushing = false;
1612
+ if (this.queuedAutoPaymentSync) {
1613
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
1614
+ }
1615
+ }
1616
+ }
1517
1617
  /** 追加单个支付项到当前订单。 */
1518
1618
  addOrderPayment(payment) {
1519
1619
  var _a;
@@ -1549,11 +1649,14 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1549
1649
  });
1550
1650
  const amountSnapshot = this.store.order.getOrderAmountSnapshot();
1551
1651
  const syncState = this.store.order.getOrderSyncState();
1552
- if (amountSnapshot && syncState !== "submitting") {
1553
- const paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? "paid" : "partially_paid";
1652
+ if (amountSnapshot) {
1653
+ if (syncState === "submitting") {
1654
+ this.queueLatestAutoPaymentSync();
1655
+ return payments;
1656
+ }
1554
1657
  void this.syncPaymentsToOrder({
1555
1658
  payments,
1556
- paymentStatus,
1659
+ paymentStatus: this.getPaymentStatusForSync(payments),
1557
1660
  submitWhenPaid: true,
1558
1661
  smallTicketDataFlag: 1
1559
1662
  }).catch((error) => {
@@ -1561,7 +1664,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1561
1664
  error: error instanceof Error ? error.message : String(error)
1562
1665
  });
1563
1666
  });
1564
- } else {
1565
1667
  }
1566
1668
  return payments;
1567
1669
  }
@@ -1578,10 +1680,20 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1578
1680
  return this.store.order.deleteOrderPayment(paymentIdentity);
1579
1681
  }
1580
1682
  /** 覆盖 wallet pass 支付项,同时保留普通支付项。 */
1581
- updateVoucherOrderPayments(payments) {
1683
+ updateVoucherOrderPayments(payments, options) {
1684
+ if (!this.store.order)
1685
+ throw new Error("order 模块未初始化");
1686
+ return this.store.order.updateVoucherOrderPayments(payments, options);
1687
+ }
1688
+ confirmPendingVoucherPayments() {
1689
+ if (!this.store.order)
1690
+ throw new Error("order 模块未初始化");
1691
+ return this.store.order.confirmPendingVoucherPayments();
1692
+ }
1693
+ discardPendingVoucherPayments() {
1582
1694
  if (!this.store.order)
1583
1695
  throw new Error("order 模块未初始化");
1584
- return this.store.order.updateVoucherOrderPayments(payments);
1696
+ return this.store.order.discardPendingVoucherPayments();
1585
1697
  }
1586
1698
  getWalletProductList() {
1587
1699
  var _a, _b, _c;
@@ -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 | 5 | 1 | 2 | 3 | 6 | 4;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -322,7 +322,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
322
322
  * 获取当前的客户搜索条件
323
323
  * @returns 当前搜索条件
324
324
  */
325
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
325
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
326
326
  /**
327
327
  * 获取客户列表状态(包含滚动加载相关状态)
328
328
  * @returns 客户状态
@@ -551,6 +551,14 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
551
551
  setOtherParams(params: Record<string, any>, { cover }?: {
552
552
  cover?: boolean;
553
553
  }): Promise<void>;
554
+ private getDeviceTaskPlugin;
555
+ handlePrintWristband(params: {
556
+ voucher_ids: number[];
557
+ }): Promise<void>;
558
+ handleCheckIn(params: {
559
+ voucher_ids: number[];
560
+ is_checkin: boolean;
561
+ }): Promise<any>;
554
562
  /**
555
563
  * 销毁模块:先调用父类(销毁所有 store 内子模块 + emit destroy + super.destroy()),
556
564
  * 再清理 BookingTicket 自有资源(scan 监听 + scan 内存缓存)。
@@ -52,6 +52,7 @@ var import_buildNormalProductCacheItemFromOrderLine = require("../../modules/Boo
52
52
  var import_orderLineDisplay = require("../../modules/BookingContext/utils/orderLineDisplay");
53
53
  var import_bookingStatus = require("./utils/bookingStatus");
54
54
  var import_resolveBestAddTimePlan = require("./utils/resolveBestAddTimePlan");
55
+ var import_utils = require("../../modules/Order/utils");
55
56
  __reExport(BookingTicket_exports, require("./types"), module.exports);
56
57
  var OPEN_DATA_SECTION_CODES = ["sale", "reservation", "fulfillment", "menu", "workflow"];
57
58
  var OPEN_DATA_CACHE_TTL = 5 * 60 * 1e3;
@@ -1505,6 +1506,117 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
1505
1506
  await this.configureIdGeneratorFromOpenData();
1506
1507
  }
1507
1508
  }
1509
+ getDeviceTaskPlugin() {
1510
+ var _a;
1511
+ const app = this.core.getPlugin("app");
1512
+ return ((_a = app == null ? void 0 : app.getApp()) == null ? void 0 : _a.getPlugin("deviceTask")) || null;
1513
+ }
1514
+ // 打印手环,单个或批量都可以
1515
+ async handlePrintWristband(params) {
1516
+ var _a;
1517
+ const deviceTask = this.getDeviceTaskPlugin();
1518
+ if (!(deviceTask == null ? void 0 : deviceTask.dispatch)) {
1519
+ this.logger.addLog({
1520
+ type: "info",
1521
+ title: "[BookingTicket] handlePrintWristband: deviceTask.dispatch 不可用",
1522
+ metadata: {
1523
+ voucher_ids: Array.isArray(params.voucher_ids) ? params.voucher_ids : [params.voucher_ids]
1524
+ }
1525
+ });
1526
+ return;
1527
+ }
1528
+ this.logger.addLog({
1529
+ type: "info",
1530
+ title: "[BookingTicket] handlePrintWristband",
1531
+ metadata: {
1532
+ voucher_ids: Array.isArray(params.voucher_ids) ? params.voucher_ids : [params.voucher_ids]
1533
+ }
1534
+ });
1535
+ const deviceId = await this.getShortNumberOrDeviceId();
1536
+ const idempotencyKey = (0, import_utils.createUuidV4)();
1537
+ deviceTask.dispatch({
1538
+ action: "print_all",
1539
+ device_id: deviceId,
1540
+ payload: {
1541
+ type: "WRISTBAND",
1542
+ data: {
1543
+ order_id: (_a = this.getOrderIdentity()) == null ? void 0 : _a.orderId,
1544
+ voucher_ids: Array.isArray(params.voucher_ids) ? params.voucher_ids : [params.voucher_ids]
1545
+ }
1546
+ },
1547
+ idempotency_key: idempotencyKey,
1548
+ name: "PRINT_WRISTBAND",
1549
+ source: "bookingTicket",
1550
+ source_type: "handlePrintWristband",
1551
+ source_id: idempotencyKey
1552
+ });
1553
+ }
1554
+ // 触发 checkIn
1555
+ async handleCheckIn(params) {
1556
+ var _a, _b, _c;
1557
+ this.logger.addLog({
1558
+ type: "info",
1559
+ title: "[BookingTicket] handleCheckIn",
1560
+ metadata: {
1561
+ voucher_ids: Array.isArray(params.voucher_ids) ? params.voucher_ids : [params.voucher_ids],
1562
+ is_checkin: params.is_checkin
1563
+ }
1564
+ });
1565
+ const voucherIds = Array.isArray(params.voucher_ids) ? params.voucher_ids : [];
1566
+ const voucherIdSet = new Set(voucherIds);
1567
+ const tempOrder = (_b = (_a = this.store.order) == null ? void 0 : _a.getTempOrder) == null ? void 0 : _b.call(_a);
1568
+ const vouchers = (tempOrder == null ? void 0 : tempOrder.vouchers) || ((_c = this.store.order) == null ? void 0 : _c.getVouchers()) || [];
1569
+ const batchMetadata = [];
1570
+ let hasUpdatedVoucher = false;
1571
+ const nextVouchers = vouchers.map((voucher) => {
1572
+ var _a2;
1573
+ if (!voucherIdSet.has(voucher.voucher_id))
1574
+ return voucher;
1575
+ hasUpdatedVoucher = true;
1576
+ const metadata = {
1577
+ ...voucher.metadata || {},
1578
+ ticket: {
1579
+ ...((_a2 = voucher.metadata) == null ? void 0 : _a2.ticket) || {},
1580
+ is_checkin: params.is_checkin
1581
+ }
1582
+ };
1583
+ batchMetadata.push({
1584
+ voucher_id: voucher.voucher_id,
1585
+ metadata
1586
+ });
1587
+ return {
1588
+ ...voucher,
1589
+ metadata
1590
+ };
1591
+ });
1592
+ if (tempOrder && hasUpdatedVoucher) {
1593
+ await this.replaceTempOrder({
1594
+ ...tempOrder,
1595
+ vouchers: nextVouchers
1596
+ });
1597
+ }
1598
+ this.core.effects.emit(`${this.name}:onVouchersChange`, {});
1599
+ if (batchMetadata.length === 0) {
1600
+ return {
1601
+ code: 200,
1602
+ status: true,
1603
+ message: "",
1604
+ data: []
1605
+ };
1606
+ }
1607
+ const identity = this.getOrderIdentity();
1608
+ const externalSaleNumber = (tempOrder == null ? void 0 : tempOrder.external_sale_number) || (identity == null ? void 0 : identity.externalSaleNumber) || void 0;
1609
+ const orderId = (tempOrder == null ? void 0 : tempOrder.order_id) ?? (identity == null ? void 0 : identity.orderId) ?? void 0;
1610
+ const orderLookup = externalSaleNumber || orderId || (identity == null ? void 0 : identity.orderNumber) || (identity == null ? void 0 : identity.shopOrderNumber) || (identity == null ? void 0 : identity.shopFullOrderNumber) || void 0;
1611
+ return this.request.post("/machinecode/batch-metadata", {
1612
+ data: batchMetadata,
1613
+ order_lookup: orderLookup,
1614
+ order_id: orderId,
1615
+ external_sale_number: externalSaleNumber
1616
+ }, {
1617
+ osServer: true
1618
+ });
1619
+ }
1508
1620
  /**
1509
1621
  * 销毁模块:先调用父类(销毁所有 store 内子模块 + emit destroy + super.destroy()),
1510
1622
  * 再清理 BookingTicket 自有资源(scan 监听 + scan 内存缓存)。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.256",
4
+ "version": "2.2.258",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",