@pisell/pisellos 2.2.229 → 2.2.231

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 (36) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/Order/index.d.ts +1 -0
  3. package/dist/modules/Order/index.js +82 -54
  4. package/dist/modules/Order/types.d.ts +14 -2
  5. package/dist/modules/Order/types.js +8 -1
  6. package/dist/modules/ProductList/index.d.ts +9 -12
  7. package/dist/modules/ProductList/index.js +122 -59
  8. package/dist/modules/ProductList/types.d.ts +14 -0
  9. package/dist/server/index.d.ts +21 -0
  10. package/dist/server/index.js +181 -47
  11. package/dist/server/utils/small-ticket.js +113 -29
  12. package/dist/solution/BookingByStep/index.d.ts +1 -1
  13. package/dist/solution/BookingTicket/index.d.ts +8 -0
  14. package/dist/solution/BookingTicket/index.js +191 -154
  15. package/dist/solution/BookingTicket/types.d.ts +4 -0
  16. package/dist/solution/BookingTicket/utils/cartView.js +20 -6
  17. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +189 -0
  18. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +429 -0
  19. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  20. package/lib/modules/Order/index.d.ts +1 -0
  21. package/lib/modules/Order/index.js +30 -6
  22. package/lib/modules/Order/types.d.ts +14 -2
  23. package/lib/modules/ProductList/index.d.ts +9 -12
  24. package/lib/modules/ProductList/index.js +32 -4
  25. package/lib/modules/ProductList/types.d.ts +14 -0
  26. package/lib/server/index.d.ts +21 -0
  27. package/lib/server/index.js +118 -9
  28. package/lib/server/utils/small-ticket.js +78 -1
  29. package/lib/solution/BookingByStep/index.d.ts +1 -1
  30. package/lib/solution/BookingTicket/index.d.ts +8 -0
  31. package/lib/solution/BookingTicket/index.js +16 -0
  32. package/lib/solution/BookingTicket/types.d.ts +4 -0
  33. package/lib/solution/BookingTicket/utils/cartView.js +14 -7
  34. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +189 -0
  35. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +241 -0
  36. package/package.json +1 -1
@@ -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";
@@ -372,6 +372,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
372
372
  enhancePayload?: SubmitPayloadEnhancer;
373
373
  }): Promise<T>;
374
374
  private markLocalOrderSynced;
375
+ private applyRemoteOrderNumbersToTempOrder;
375
376
  private isSubmitResponseRejected;
376
377
  private isLocalPendingSubmitResult;
377
378
  private isSubmitErrorResponse;
@@ -1,8 +1,8 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
2
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
4
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
4
5
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
6
6
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
7
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
8
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -821,7 +821,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
821
821
  _iterator4 = _createForOfIteratorHelper(result.giftActions.toAdd);
822
822
  _context7.prev = 48;
823
823
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
824
- var addAction, sameStrategy, giftProducts, _iterator5, _step5, gp;
824
+ var addAction, _sameStrategy$metadat, sameStrategy, giftResult, giftProducts, giftBookings, _iterator5, _step5, _step5$value, index, gp, booking, linked;
825
825
  return _regeneratorRuntime().wrap(function _loop$(_context5) {
826
826
  while (1) switch (_context5.prev = _context5.next) {
827
827
  case 0:
@@ -834,7 +834,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
834
834
  var _p$metadata;
835
835
  return ((_p$metadata = p.metadata) === null || _p$metadata === void 0 || (_p$metadata = _p$metadata._giftInfo) === null || _p$metadata === void 0 ? void 0 : _p$metadata.strategyId) === addAction.strategyId;
836
836
  });
837
- if (!sameStrategy) {
837
+ if (!(sameStrategy && !sameStrategy.booking_uid && !((_sameStrategy$metadat = sameStrategy.metadata) !== null && _sameStrategy$metadat !== void 0 && _sameStrategy$metadat.booking_uid))) {
838
838
  _context5.next = 6;
839
839
  break;
840
840
  }
@@ -851,55 +851,70 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
851
851
  sourceProductIds: addAction.sourceProductIds
852
852
  });
853
853
  case 9:
854
- giftProducts = _context5.sent;
854
+ giftResult = _context5.sent;
855
+ giftProducts = Array.isArray(giftResult) ? giftResult : giftResult === null || giftResult === void 0 ? void 0 : giftResult.products;
856
+ giftBookings = Array.isArray(giftResult) ? [] : (giftResult === null || giftResult === void 0 ? void 0 : giftResult.bookings) || [];
855
857
  if (!(Array.isArray(giftProducts) && giftProducts.length > 0)) {
856
- _context5.next = 29;
858
+ _context5.next = 37;
857
859
  break;
858
860
  }
859
- _iterator5 = _createForOfIteratorHelper(giftProducts);
860
- _context5.prev = 12;
861
+ _iterator5 = _createForOfIteratorHelper(giftProducts.entries());
862
+ _context5.prev = 14;
861
863
  _iterator5.s();
862
- case 14:
864
+ case 16:
863
865
  if ((_step5 = _iterator5.n()).done) {
864
- _context5.next = 21;
866
+ _context5.next = 29;
865
867
  break;
866
868
  }
867
- gp = _step5.value;
869
+ _step5$value = _slicedToArray(_step5.value, 2), index = _step5$value[0], gp = _step5$value[1];
868
870
  if (gp) {
869
- _context5.next = 18;
871
+ _context5.next = 20;
870
872
  break;
871
873
  }
872
- return _context5.abrupt("continue", 19);
873
- case 18:
874
- // normalize 略过:调用方应保证返回完整 OrderProduct
874
+ return _context5.abrupt("continue", 27);
875
+ case 20:
876
+ booking = giftBookings[index];
877
+ if (!booking) {
878
+ _context5.next = 26;
879
+ break;
880
+ }
881
+ linked = _this2.createLinkedProductAndBooking({
882
+ product: gp,
883
+ booking: booking
884
+ });
885
+ result.products.push(linked.product);
886
+ tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
887
+ return _context5.abrupt("continue", 27);
888
+ case 26:
889
+ // normalize 略过:调用方应保证返回完整 OrderProduct。
875
890
  result.products.push(gp);
876
- case 19:
877
- _context5.next = 14;
878
- break;
879
- case 21:
880
- _context5.next = 26;
891
+ case 27:
892
+ _context5.next = 16;
881
893
  break;
882
- case 23:
883
- _context5.prev = 23;
884
- _context5.t0 = _context5["catch"](12);
885
- _iterator5.e(_context5.t0);
886
- case 26:
887
- _context5.prev = 26;
888
- _iterator5.f();
889
- return _context5.finish(26);
890
894
  case 29:
891
895
  _context5.next = 34;
892
896
  break;
893
897
  case 31:
894
898
  _context5.prev = 31;
899
+ _context5.t0 = _context5["catch"](14);
900
+ _iterator5.e(_context5.t0);
901
+ case 34:
902
+ _context5.prev = 34;
903
+ _iterator5.f();
904
+ return _context5.finish(34);
905
+ case 37:
906
+ _context5.next = 42;
907
+ break;
908
+ case 39:
909
+ _context5.prev = 39;
895
910
  _context5.t1 = _context5["catch"](6);
896
911
  // 用户取消 / 选择失败 → 视为放弃本次新增
897
912
  console.warn('[OrderModule] giftSelectResolver rejected, skip add gift', addAction.strategyId, _context5.t1);
898
- case 34:
913
+ case 42:
899
914
  case "end":
900
915
  return _context5.stop();
901
916
  }
902
- }, _loop, null, [[6, 31], [12, 23, 26, 29]]);
917
+ }, _loop, null, [[6, 39], [14, 31, 34, 37]]);
903
918
  });
904
919
  _iterator4.s();
905
920
  case 51:
@@ -3740,7 +3755,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3740
3755
  var enhancedPayload = params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
3741
3756
  return enhancedPayload;
3742
3757
  } : undefined;
3743
- debugger;
3744
3758
  payload = buildSubmitPayload({
3745
3759
  tempOrder: tempOrder,
3746
3760
  cacheId: effectiveCacheId,
@@ -3754,10 +3768,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3754
3768
  if (!payload.created_at) {
3755
3769
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
3756
3770
  }
3757
- _context26.next = 21;
3771
+ _context26.next = 20;
3758
3772
  return this.saveDraft();
3759
- case 21:
3760
- _context26.prev = 21;
3773
+ case 20:
3774
+ _context26.prev = 20;
3761
3775
  this.logInfo('submitTempOrder calling sales checkout', {
3762
3776
  orderId: payload.order_id,
3763
3777
  externalSaleNumber: payload.external_sale_number,
@@ -3766,26 +3780,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3766
3780
  paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
3767
3781
  smallTicketDataFlag: payload.small_ticket_data_flag
3768
3782
  });
3769
- _context26.next = 25;
3783
+ _context26.next = 24;
3770
3784
  return this.submitSalesOrder({
3771
3785
  query: payload
3772
3786
  });
3773
- case 25:
3787
+ case 24:
3774
3788
  result = _context26.sent;
3775
- _context26.next = 38;
3789
+ _context26.next = 37;
3776
3790
  break;
3777
- case 28:
3778
- _context26.prev = 28;
3779
- _context26.t2 = _context26["catch"](21);
3791
+ case 27:
3792
+ _context26.prev = 27;
3793
+ _context26.t2 = _context26["catch"](20);
3780
3794
  backendErrorResponse = this.extractSubmitErrorResponse(_context26.t2);
3781
3795
  if (!backendErrorResponse) {
3782
- _context26.next = 35;
3796
+ _context26.next = 34;
3783
3797
  break;
3784
3798
  }
3785
3799
  this.store.syncState = 'failed';
3786
3800
  this.logSubmitBackendRejected(backendErrorResponse, payload);
3787
3801
  return _context26.abrupt("return", backendErrorResponse);
3788
- case 35:
3802
+ case 34:
3789
3803
  this.store.syncState = 'failed';
3790
3804
  this.logError('submitTempOrder failed', {
3791
3805
  error: _context26.t2 instanceof Error ? _context26.t2.message : String(_context26.t2),
@@ -3795,40 +3809,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3795
3809
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
3796
3810
  });
3797
3811
  throw _context26.t2;
3798
- case 38:
3812
+ case 37:
3799
3813
  if (!this.isSubmitResponseRejected(result)) {
3800
- _context26.next = 42;
3814
+ _context26.next = 41;
3801
3815
  break;
3802
3816
  }
3803
3817
  this.store.syncState = 'failed';
3804
3818
  this.logSubmitBackendRejected(result, payload);
3805
3819
  return _context26.abrupt("return", result);
3806
- case 42:
3820
+ case 41:
3807
3821
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
3808
3822
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
3809
- _context26.next = 50;
3823
+ _context26.next = 49;
3810
3824
  break;
3811
3825
  }
3812
3826
  tempOrder.order_id = submittedOrderId;
3813
3827
  resultRecord = result;
3814
- _context26.next = 48;
3828
+ _context26.next = 47;
3815
3829
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
3816
- case 48:
3817
- _context26.next = 51;
3830
+ case 47:
3831
+ _context26.next = 50;
3818
3832
  break;
3819
- case 50:
3833
+ case 49:
3820
3834
  if (this.isLocalPendingSubmitResult(result)) {
3821
3835
  this.store.syncState = 'local';
3822
3836
  } else {
3823
3837
  this.store.syncState = 'submitted';
3824
3838
  }
3825
- case 51:
3839
+ case 50:
3826
3840
  return _context26.abrupt("return", result);
3827
- case 52:
3841
+ case 51:
3828
3842
  case "end":
3829
3843
  return _context26.stop();
3830
3844
  }
3831
- }, _callee24, this, [[21, 28]]);
3845
+ }, _callee24, this, [[20, 27]]);
3832
3846
  }));
3833
3847
  function submitTempOrder(_x26) {
3834
3848
  return _submitTempOrder.apply(this, arguments);
@@ -3845,12 +3859,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3845
3859
  case 0:
3846
3860
  tempOrder = this.ensureTempOrder();
3847
3861
  tempOrder.order_id = orderId;
3862
+ this.applyRemoteOrderNumbersToTempOrder(tempOrder, remoteOrder);
3848
3863
  this.store.lastOrderInfo = remoteOrder;
3849
3864
  this.store.syncState = 'submitted';
3850
3865
  this.persistTempOrder();
3851
- _context27.next = 7;
3866
+ _context27.next = 8;
3852
3867
  return this.saveDraft();
3853
- case 7:
3868
+ case 8:
3854
3869
  case "end":
3855
3870
  return _context27.stop();
3856
3871
  }
@@ -3861,6 +3876,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3861
3876
  }
3862
3877
  return markLocalOrderSynced;
3863
3878
  }()
3879
+ }, {
3880
+ key: "applyRemoteOrderNumbersToTempOrder",
3881
+ value: function applyRemoteOrderNumbersToTempOrder(tempOrder, remoteOrder) {
3882
+ var applyOrderNumber = function applyOrderNumber(key) {
3883
+ var value = remoteOrder === null || remoteOrder === void 0 ? void 0 : remoteOrder[key];
3884
+ if (value !== undefined && value !== null && value !== '') {
3885
+ tempOrder[key] = String(value);
3886
+ }
3887
+ };
3888
+ applyOrderNumber('order_number');
3889
+ applyOrderNumber('shop_order_number');
3890
+ applyOrderNumber('shop_full_order_number');
3891
+ }
3864
3892
  }, {
3865
3893
  key: "isSubmitResponseRejected",
3866
3894
  value: function isSubmitResponseRejected(response) {
@@ -47,6 +47,18 @@ export interface OrderGiftSelectContext {
47
47
  /** 触发此赠品的主商品 metadata.unique_identification_number 列表 */
48
48
  sourceProductIds: string[];
49
49
  }
50
+ /**
51
+ * 赠品 resolver 返回值。
52
+ *
53
+ * @example
54
+ * return { products: [giftProduct], bookings: [giftBooking] };
55
+ */
56
+ export interface OrderGiftSelectResult {
57
+ /** 完整赠品购物车行,必须带 metadata._giftInfo。 */
58
+ products: Partial<OrderProduct>[];
59
+ /** 预约赠品对应的 booking,按 products 下标一一关联。 */
60
+ bookings?: AddProductBookingInput[];
61
+ }
50
62
  /**
51
63
  * 赠品解析回调签名(SDK → OS 的返回值)。
52
64
  *
@@ -54,9 +66,9 @@ export interface OrderGiftSelectContext {
54
66
  * - 多选项:SDK 弹窗等用户确认后构造
55
67
  * - 用户取消:抛错或返回空数组(OS 视为放弃本次添加)
56
68
  *
57
- * 返回的 OrderProduct 必须是完整的购物车行(含 metadata._giftInfo 标记),OS 会直接 push 入 tempOrder.products。
69
+ * 返回数组时沿用旧协议,只写 tempOrder.products;返回对象时可同时写入预约 bookings
58
70
  */
59
- export type OrderGiftSelectResolver = (ctx: OrderGiftSelectContext) => Promise<Partial<OrderProduct>[] | null>;
71
+ export type OrderGiftSelectResolver = (ctx: OrderGiftSelectContext) => Promise<Partial<OrderProduct>[] | OrderGiftSelectResult | null>;
60
72
  /** 未满足的促销策略(购物车底部 alert 渲染源) */
61
73
  export interface OrderUnfulfilledPromotion {
62
74
  strategyId: string;
@@ -20,6 +20,13 @@ export var OrderHooks = /*#__PURE__*/function (OrderHooks) {
20
20
 
21
21
  /** 赠品解析回调 context(OS → SDK 的请求体) */
22
22
 
23
+ /**
24
+ * 赠品 resolver 返回值。
25
+ *
26
+ * @example
27
+ * return { products: [giftProduct], bookings: [giftBooking] };
28
+ */
29
+
23
30
  /**
24
31
  * 赠品解析回调签名(SDK → OS 的返回值)。
25
32
  *
@@ -27,7 +34,7 @@ export var OrderHooks = /*#__PURE__*/function (OrderHooks) {
27
34
  * - 多选项:SDK 弹窗等用户确认后构造
28
35
  * - 用户取消:抛错或返回空数组(OS 视为放弃本次添加)
29
36
  *
30
- * 返回的 OrderProduct 必须是完整的购物车行(含 metadata._giftInfo 标记),OS 会直接 push 入 tempOrder.products。
37
+ * 返回数组时沿用旧协议,只写 tempOrder.products;返回对象时可同时写入预约 bookings
31
38
  */
32
39
 
33
40
  /** 未满足的促销策略(购物车底部 alert 渲染源) */
@@ -1,5 +1,6 @@
1
1
  import { Module, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
+ import { ProductListLoadProductsParams } from './types';
3
4
  import { ProductData } from '../Product/types';
4
5
  export * from './types';
5
6
  export declare class ProductList extends BaseModule implements Module {
@@ -18,18 +19,14 @@ export declare class ProductList extends BaseModule implements Module {
18
19
  */
19
20
  updateOtherParams(params: Record<string, any>): void;
20
21
  storeChange(path?: string, value?: any): Promise<void>;
21
- loadProducts({ category_ids, product_ids, collection, menu_list_ids, customer_id: paramsCustomerId, with_count, schedule_datetime, schedule_date, cacheId, with_schedule, }: {
22
- category_ids?: number[];
23
- product_ids?: number[];
24
- collection?: number | string[];
25
- schedule_date?: string;
26
- cacheId?: string;
27
- customer_id?: number;
28
- menu_list_ids?: number[];
29
- schedule_datetime?: string;
30
- with_count?: string[];
31
- with_schedule?: number;
32
- }, options?: {
22
+ /**
23
+ * 获取加时商品列表。
24
+ *
25
+ * @example
26
+ * const products = await productList.getAddTimeProducts({ schedule_date: '2026-06-16' });
27
+ */
28
+ getAddTimeProducts(params?: ProductListLoadProductsParams): Promise<any>;
29
+ loadProducts({ category_ids, product_ids, collection, menu_list_ids, customer_id: paramsCustomerId, with_count, schedule_datetime, schedule_date, cacheId, with_schedule, extension_type, status, }?: ProductListLoadProductsParams, options?: {
33
30
  callback?: (result: any) => void;
34
31
  subscriberId?: string;
35
32
  }): Promise<any>;