@pisell/pisellos 2.3.8 → 2.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ // 导出评估器
2
+ export { PromotionEvaluator } from "./evaluator";
3
+
4
+ // 导出适配器
5
+ export { PromotionAdapter } from "./adapter";
6
+ export { default } from "./adapter";
7
+
8
+ // 导出策略配置示例常量
9
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
@@ -458,7 +458,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
458
458
  generateIdempotencyToken(): string;
459
459
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
460
460
  createOrder(params: CommitOrderParams['query']): {
461
- type: "appointment_booking" | "virtual";
461
+ type: "virtual" | "appointment_booking";
462
462
  platform: string;
463
463
  sales_channel: string;
464
464
  order_sales_channel: string;
@@ -79,6 +79,9 @@ function isPendingVoucherPaymentRecord(payment) {
79
79
  function isPaidPaymentRecord(payment) {
80
80
  return (payment === null || payment === void 0 ? void 0 : payment.status) === ORDER_PAYMENT_STATUS_PAID;
81
81
  }
82
+ function isCommittedVoucherPaymentRecord(payment) {
83
+ return isVoucherPaymentRecord(payment) && (payment === null || payment === void 0 ? void 0 : payment.status) !== 'voided' && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
84
+ }
82
85
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
83
86
  _inherits(OrderModule, _BaseModule);
84
87
  var _super = _createSuper(OrderModule);
@@ -3253,6 +3256,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3253
3256
  this.applyPaymentLifecycleChange(tempOrder, _objectSpread(_objectSpread({}, options), {}, {
3254
3257
  logContext: 'confirmPendingVoucherPayments'
3255
3258
  }));
3259
+ // this.recalculateSummary();
3256
3260
  return tempOrder.payments;
3257
3261
  }
3258
3262
  }, {
@@ -3322,21 +3326,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3322
3326
  var nonVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3323
3327
  return !isVoucherPaymentRecord(payment);
3324
3328
  });
3325
- var syncedVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3326
- return isVoucherPaymentRecord(payment) && hasSyncedOrderPaymentRecord(payment);
3329
+ var normalizeCommittedVoucherPayment = function normalizeCommittedVoucherPayment(payment) {
3330
+ if (hasSyncedOrderPaymentRecord(payment) && (payment.status === undefined || payment.status === 'active')) {
3331
+ return _objectSpread(_objectSpread({}, payment), {}, {
3332
+ status: ORDER_PAYMENT_STATUS_PAID
3333
+ });
3334
+ }
3335
+ return payment;
3336
+ };
3337
+ var committedVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3338
+ return isCommittedVoucherPaymentRecord(payment);
3339
+ }).map(function (payment) {
3340
+ return normalizeCommittedVoucherPayment(payment);
3327
3341
  });
3328
- var syncedVoucherPaymentIds = new Set(syncedVoucherPayments.map(function (payment) {
3342
+ var committedVoucherPaymentIds = new Set(committedVoucherPayments.filter(function (payment) {
3343
+ return hasSyncedOrderPaymentRecord(payment);
3344
+ }).map(function (payment) {
3329
3345
  return String(payment.order_payment_id);
3330
3346
  }));
3347
+ var committedVoucherIds = new Set(committedVoucherPayments.map(function (payment) {
3348
+ return String(payment.voucher_id);
3349
+ }));
3331
3350
  var replaceableVouchers = mappedVouchers.filter(function (payment) {
3332
- if (!hasSyncedOrderPaymentRecord(payment)) return true;
3333
- return !syncedVoucherPaymentIds.has(String(payment.order_payment_id));
3351
+ if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
3352
+ return false;
3353
+ }
3354
+ if (payment.voucher_id !== undefined && committedVoucherIds.has(String(payment.voucher_id))) {
3355
+ return false;
3356
+ }
3357
+ return true;
3334
3358
  });
3335
3359
  var cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
3336
3360
  vouchers: replaceableVouchers,
3337
- nonVoucherPayments: [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(syncedVoucherPayments))
3361
+ nonVoucherPayments: [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(committedVoucherPayments))
3338
3362
  });
3339
- tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(syncedVoucherPayments), _toConsumableArray(cappedVouchers));
3363
+ tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(committedVoucherPayments), _toConsumableArray(cappedVouchers));
3340
3364
  this.updateTempOrderPaymentStatus(tempOrder);
3341
3365
  this.persistTempOrder();
3342
3366
  void this.recalculateSummary({
@@ -4533,7 +4557,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4533
4557
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
4534
4558
  var nextPayload = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, payload), hasPaymentOverride ? {
4535
4559
  payments: preparedPaymentOverride || []
4536
- } : {}), hasPaymentStatusOverride ? {
4560
+ } : {}), hasPaymentStatusOverride && !shouldConfirmPendingVoucherPayments ? {
4537
4561
  payment_status: params === null || params === void 0 ? void 0 : params.paymentStatus
4538
4562
  } : {}), hasSmallTicketDataFlagOverride ? {
4539
4563
  small_ticket_data_flag: params === null || params === void 0 ? void 0 : params.smallTicketDataFlag
@@ -180,6 +180,7 @@ export declare class OrderModule extends BaseModule implements Module {
180
180
  * const idx = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys)
181
181
  */
182
182
  private lookupOrderIndexByIdentityKeys;
183
+ private isRemoteEchoMergeSource;
183
184
  /**
184
185
  * 将订单的全部身份键登记到索引并指向其在列表中的下标。
185
186
  * 合并后订单新增的身份字段(如挂单同步后拿到 order_id)也会被登记。
@@ -1607,7 +1607,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1607
1607
  key: "mergeOrdersToStore",
1608
1608
  value: (function () {
1609
1609
  var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(freshOrders, source) {
1610
- var storeOrderCountBefore, normalizedFreshOrders, _iterator9, _step9, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator10, _step10, key, _iterator11, _step11, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, mergedOrder, insertIndex, insertCount, updateCount;
1610
+ var storeOrderCountBefore, normalizedFreshOrders, _iterator9, _step9, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator10, _step10, key, _iterator11, _step11, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _ref2, _existingOrder$order_, _ref3, _external_sale_number, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, mergedOrder, insertIndex, insertCount, updateCount;
1611
1611
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1612
1612
  while (1) switch (_context16.prev = _context16.next) {
1613
1613
  case 0:
@@ -1680,7 +1680,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1680
1680
  _iterator11.s();
1681
1681
  case 33:
1682
1682
  if ((_step11 = _iterator11.n()).done) {
1683
- _context16.next = 53;
1683
+ _context16.next = 57;
1684
1684
  break;
1685
1685
  }
1686
1686
  fresh = _step11.value;
@@ -1689,38 +1689,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1689
1689
  storageKey = this.getOrderStorageKey(fresh);
1690
1690
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
1691
1691
  if (!(matchIndex >= 0)) {
1692
- _context16.next = 46;
1692
+ _context16.next = 50;
1693
1693
  break;
1694
1694
  }
1695
- mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], fresh);
1695
+ existingOrder = updatedList[matchIndex];
1696
+ if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
1697
+ _context16.next = 44;
1698
+ break;
1699
+ }
1700
+ this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
1701
+ source: source,
1702
+ order_id: (_ref2 = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref2 !== void 0 ? _ref2 : null,
1703
+ external_sale_number: (_ref3 = (_external_sale_number = existingOrder.external_sale_number) !== null && _external_sale_number !== void 0 ? _external_sale_number : fresh.external_sale_number) !== null && _ref3 !== void 0 ? _ref3 : null,
1704
+ local_payment_status: (_existingOrder$paymen = existingOrder.payment_status) !== null && _existingOrder$paymen !== void 0 ? _existingOrder$paymen : null,
1705
+ remote_payment_status: (_fresh$payment_status = fresh.payment_status) !== null && _fresh$payment_status !== void 0 ? _fresh$payment_status : null,
1706
+ local_need_sync: (_existingOrder$need_s = existingOrder.need_sync) !== null && _existingOrder$need_s !== void 0 ? _existingOrder$need_s : null,
1707
+ remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
1708
+ reason: 'protect_pending_sync_order_from_remote_echo'
1709
+ });
1710
+ return _context16.abrupt("continue", 55);
1711
+ case 44:
1712
+ mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
1696
1713
  updatedList[matchIndex] = mergedOrder;
1697
1714
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
1698
1715
  // 供同批后续 fresh 命中同一槽位,避免重复插入
1699
1716
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
1700
1717
  patchedOrders.push(mergedOrder);
1701
1718
  if (mergeKey) mergeActions[mergeKey] = 'update';
1702
- return _context16.abrupt("continue", 51);
1703
- case 46:
1719
+ return _context16.abrupt("continue", 55);
1720
+ case 50:
1704
1721
  insertIndex = updatedList.length;
1705
1722
  updatedList.push(fresh);
1706
1723
  this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
1707
1724
  patchedOrders.push(fresh);
1708
1725
  if (mergeKey) mergeActions[mergeKey] = 'insert';
1709
- case 51:
1726
+ case 55:
1710
1727
  _context16.next = 33;
1711
1728
  break;
1712
- case 53:
1713
- _context16.next = 58;
1729
+ case 57:
1730
+ _context16.next = 62;
1714
1731
  break;
1715
- case 55:
1716
- _context16.prev = 55;
1732
+ case 59:
1733
+ _context16.prev = 59;
1717
1734
  _context16.t1 = _context16["catch"](31);
1718
1735
  _iterator11.e(_context16.t1);
1719
- case 58:
1720
- _context16.prev = 58;
1736
+ case 62:
1737
+ _context16.prev = 62;
1721
1738
  _iterator11.f();
1722
- return _context16.finish(58);
1723
- case 61:
1739
+ return _context16.finish(62);
1740
+ case 65:
1724
1741
  insertCount = Object.values(mergeActions).filter(function (v) {
1725
1742
  return v === 'insert';
1726
1743
  }).length;
@@ -1736,22 +1753,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1736
1753
  // 仅在自检开关开启时做一次兜底校验。
1737
1754
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
1738
1755
  this.syncOrdersMap();
1739
- _context16.next = 68;
1756
+ _context16.next = 72;
1740
1757
  return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
1741
- case 68:
1758
+ case 72:
1742
1759
  this.logInfo('mergeOrdersToStore-结束', {
1743
1760
  uniqueFreshCount: uniqueFreshCount,
1744
1761
  storeOrderCountAfter: this.store.list.length,
1745
1762
  insertCount: insertCount,
1746
1763
  updateCount: updateCount
1747
1764
  });
1748
- _context16.next = 71;
1765
+ _context16.next = 75;
1749
1766
  return this.emitOrdersChanged(patchedOrders, source);
1750
- case 71:
1767
+ case 75:
1751
1768
  case "end":
1752
1769
  return _context16.stop();
1753
1770
  }
1754
- }, _callee16, this, [[5, 17, 20, 23], [31, 55, 58, 61]]);
1771
+ }, _callee16, this, [[5, 17, 20, 23], [31, 59, 62, 65]]);
1755
1772
  }));
1756
1773
  function mergeOrdersToStore(_x9, _x10) {
1757
1774
  return _mergeOrdersToStore.apply(this, arguments);
@@ -1786,6 +1803,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1786
1803
  }
1787
1804
  return matchIndex;
1788
1805
  }
1806
+ }, {
1807
+ key: "isRemoteEchoMergeSource",
1808
+ value: function isRemoteEchoMergeSource(source) {
1809
+ return source === 'pubsub.bodyUpsert' || source === 'pubsub.httpRefresh';
1810
+ }
1789
1811
 
1790
1812
  /**
1791
1813
  * 将订单的全部身份键登记到索引并指向其在列表中的下标。
@@ -2166,22 +2188,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2166
2188
  } finally {
2167
2189
  _iterator20.f();
2168
2190
  }
2169
- return _toConsumableArray(groups.entries()).filter(function (_ref2) {
2170
- var _ref3 = _slicedToArray(_ref2, 2),
2171
- group = _ref3[1];
2172
- return group.length > 1;
2173
- }).slice(0, 20).map(function (_ref4) {
2191
+ return _toConsumableArray(groups.entries()).filter(function (_ref4) {
2174
2192
  var _ref5 = _slicedToArray(_ref4, 2),
2175
- key = _ref5[0],
2176
2193
  group = _ref5[1];
2194
+ return group.length > 1;
2195
+ }).slice(0, 20).map(function (_ref6) {
2196
+ var _ref7 = _slicedToArray(_ref6, 2),
2197
+ key = _ref7[0],
2198
+ group = _ref7[1];
2177
2199
  return {
2178
2200
  key: key,
2179
2201
  count: group.length,
2180
2202
  orders: group.map(function (order) {
2181
- var _order$order_id2, _external_sale_number, _shop_order_number, _shop_full_order_numb, _order$need_sync;
2203
+ var _order$order_id2, _external_sale_number2, _shop_order_number, _shop_full_order_numb, _order$need_sync;
2182
2204
  return {
2183
2205
  order_id: (_order$order_id2 = order.order_id) !== null && _order$order_id2 !== void 0 ? _order$order_id2 : null,
2184
- external_sale_number: (_external_sale_number = order.external_sale_number) !== null && _external_sale_number !== void 0 ? _external_sale_number : null,
2206
+ external_sale_number: (_external_sale_number2 = order.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : null,
2185
2207
  shop_order_number: (_shop_order_number = order.shop_order_number) !== null && _shop_order_number !== void 0 ? _shop_order_number : null,
2186
2208
  shop_full_order_number: (_shop_full_order_numb = order.shop_full_order_number) !== null && _shop_full_order_numb !== void 0 ? _shop_full_order_numb : null,
2187
2209
  need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null
@@ -46,6 +46,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
46
46
  protected hasManualDiscountSelection: boolean;
47
47
  private readonly reusedSharedSubModuleNames;
48
48
  private paymentMethodsCache;
49
+ private queuedAutoPaymentSync;
50
+ private autoPaymentSyncFlushing;
51
+ private autoPaymentSyncTimer;
49
52
  constructor(name?: string, version?: string);
50
53
  /**
51
54
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
@@ -225,6 +228,10 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
225
228
  getOrderPayments(): OrderPaymentData[];
226
229
  /** 覆盖当前订单支付项,内部由 OrderModule 清洗为 Sales 协议字段。 */
227
230
  setOrderPayments(payments: OrderPaymentSource[]): OrderPaymentData[];
231
+ private getPaymentStatusForSync;
232
+ private queueLatestAutoPaymentSync;
233
+ private scheduleQueuedAutoPaymentSyncFlush;
234
+ private flushQueuedAutoPaymentSync;
228
235
  /** 追加单个支付项到当前订单。 */
229
236
  addOrderPayment(payment: OrderPaymentSource): OrderPaymentData[];
230
237
  /** 更新当前订单中的指定支付项。 */