@pisell/pisellos 2.2.171 → 2.2.172

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 (156) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +193 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.d.ts +6 -0
  32. package/dist/modules/Customer/index.js +129 -83
  33. package/dist/modules/Customer/types.d.ts +2 -0
  34. package/dist/modules/Discount/index.d.ts +2 -4
  35. package/dist/modules/Discount/index.js +8 -93
  36. package/dist/modules/Discount/types.d.ts +1 -7
  37. package/dist/modules/Order/index.d.ts +47 -16
  38. package/dist/modules/Order/index.js +743 -334
  39. package/dist/modules/Order/types.d.ts +57 -17
  40. package/dist/modules/Order/types.js +2 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  42. package/dist/modules/Order/utils/manualProductDiscount.js +212 -0
  43. package/dist/modules/Order/utils.d.ts +23 -1
  44. package/dist/modules/Order/utils.js +139 -30
  45. package/dist/modules/Quotation/index.js +16 -5
  46. package/dist/modules/Rules/index.d.ts +4 -0
  47. package/dist/modules/Rules/index.js +26 -10
  48. package/dist/modules/SalesSummary/index.js +4 -2
  49. package/dist/modules/Schedule/index.js +6 -2
  50. package/dist/modules/index.d.ts +1 -0
  51. package/dist/modules/index.js +2 -1
  52. package/dist/server/index.js +10 -6
  53. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  54. package/dist/server/modules/products/index.js +9 -8
  55. package/dist/server/modules/schedule/index.js +13 -6
  56. package/dist/solution/BaseSales/index.d.ts +65 -7
  57. package/dist/solution/BaseSales/index.js +1066 -315
  58. package/dist/solution/BaseSales/types.d.ts +53 -1
  59. package/dist/solution/BaseSales/types.js +3 -1
  60. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  61. package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
  62. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +65 -15
  63. package/dist/solution/BaseSales/utils.js +46 -8
  64. package/dist/solution/BookingTicket/index.d.ts +134 -2
  65. package/dist/solution/BookingTicket/index.js +768 -175
  66. package/dist/solution/BookingTicket/types.d.ts +2 -0
  67. package/dist/solution/BookingTicket/types.js +3 -0
  68. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  69. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  70. package/dist/solution/ScanOrder/index.d.ts +9 -3
  71. package/dist/solution/ScanOrder/index.js +231 -128
  72. package/dist/solution/ScanOrder/utils.js +46 -8
  73. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  74. package/dist/solution/ShopDiscount/index.js +18 -23
  75. package/dist/solution/VenueBooking/index.d.ts +5 -9
  76. package/dist/solution/VenueBooking/index.js +103 -55
  77. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  78. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  79. package/lib/modules/BookingContext/index.d.ts +37 -0
  80. package/lib/modules/BookingContext/index.js +297 -0
  81. package/lib/modules/BookingContext/types.d.ts +102 -0
  82. package/lib/modules/BookingContext/types.js +34 -0
  83. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  84. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +207 -0
  85. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  86. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  87. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  88. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  89. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  90. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  91. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  92. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  93. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  94. package/lib/modules/BookingContext/utils/index.js +43 -0
  95. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  96. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  97. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  98. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  99. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  100. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  101. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  102. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  103. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  104. package/lib/modules/BookingContext/utils/resources.js +377 -0
  105. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  106. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  107. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  108. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  109. package/lib/modules/Customer/index.d.ts +6 -0
  110. package/lib/modules/Customer/index.js +26 -11
  111. package/lib/modules/Customer/types.d.ts +2 -0
  112. package/lib/modules/Discount/index.d.ts +2 -4
  113. package/lib/modules/Discount/index.js +8 -63
  114. package/lib/modules/Discount/types.d.ts +1 -7
  115. package/lib/modules/Order/index.d.ts +47 -16
  116. package/lib/modules/Order/index.js +389 -90
  117. package/lib/modules/Order/types.d.ts +57 -17
  118. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  119. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  120. package/lib/modules/Order/utils.d.ts +23 -1
  121. package/lib/modules/Order/utils.js +145 -21
  122. package/lib/modules/Quotation/index.js +17 -6
  123. package/lib/modules/Rules/index.d.ts +4 -0
  124. package/lib/modules/Rules/index.js +22 -14
  125. package/lib/modules/SalesSummary/index.js +4 -2
  126. package/lib/modules/Schedule/index.js +3 -1
  127. package/lib/modules/index.d.ts +1 -0
  128. package/lib/modules/index.js +3 -1
  129. package/lib/server/index.js +2 -0
  130. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  131. package/lib/server/modules/products/index.js +8 -9
  132. package/lib/server/modules/schedule/index.js +2 -1
  133. package/lib/solution/BaseSales/index.d.ts +65 -7
  134. package/lib/solution/BaseSales/index.js +492 -20
  135. package/lib/solution/BaseSales/types.d.ts +53 -1
  136. package/lib/solution/BaseSales/types.js +3 -1
  137. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  138. package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
  139. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +70 -11
  140. package/lib/solution/BaseSales/utils.js +46 -6
  141. package/lib/solution/BookingTicket/index.d.ts +134 -2
  142. package/lib/solution/BookingTicket/index.js +341 -8
  143. package/lib/solution/BookingTicket/types.d.ts +2 -0
  144. package/lib/solution/BookingTicket/types.js +6 -0
  145. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  146. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  147. package/lib/solution/ScanOrder/index.d.ts +9 -3
  148. package/lib/solution/ScanOrder/index.js +147 -66
  149. package/lib/solution/ScanOrder/utils.js +46 -6
  150. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  151. package/lib/solution/ShopDiscount/index.js +2 -4
  152. package/lib/solution/VenueBooking/index.d.ts +5 -9
  153. package/lib/solution/VenueBooking/index.js +50 -14
  154. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  155. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  156. package/package.json +2 -2
@@ -89,13 +89,45 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
89
89
  moduleName: "scanOrder"
90
90
  };
91
91
  }
92
+ safeStringify(value) {
93
+ try {
94
+ return JSON.stringify(value);
95
+ } catch {
96
+ return void 0;
97
+ }
98
+ }
99
+ pickErrorMessage(error) {
100
+ var _a, _b, _c, _d;
101
+ const candidates = [
102
+ error.message,
103
+ (_a = error.data) == null ? void 0 : _a.message,
104
+ (_c = (_b = error.response) == null ? void 0 : _b.data) == null ? void 0 : _c.message,
105
+ (_d = error.error) == null ? void 0 : _d.message
106
+ ];
107
+ for (const candidate of candidates) {
108
+ if (typeof candidate === "string" && candidate.trim())
109
+ return candidate;
110
+ }
111
+ return void 0;
112
+ }
92
113
  serializeError(error) {
93
114
  if (error instanceof Error) {
94
- return JSON.stringify({
115
+ return {
95
116
  name: error.name,
96
117
  message: error.message,
97
118
  stack: error.stack
98
- });
119
+ };
120
+ }
121
+ if (error && typeof error === "object") {
122
+ const raw = error;
123
+ const message = this.pickErrorMessage(raw) || this.safeStringify(raw) || String(error);
124
+ return {
125
+ ...typeof raw.name === "string" ? { name: raw.name } : {},
126
+ message,
127
+ ..."code" in raw ? { code: raw.code } : {},
128
+ ..."status" in raw ? { status: raw.status } : {},
129
+ ...this.safeStringify(raw) ? { raw: this.safeStringify(raw) } : {}
130
+ };
99
131
  }
100
132
  return {
101
133
  message: String(error)
@@ -155,6 +187,14 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
155
187
  }
156
188
  });
157
189
  }
190
+ assertProductListLoaded(method, result, payload = {}) {
191
+ if (Array.isArray(result))
192
+ return result;
193
+ const error = result instanceof Error ? result : new Error("商品列表接口返回异常");
194
+ this.logMethodError(method, error, payload);
195
+ error.__scanOrderLogged = true;
196
+ throw error;
197
+ }
158
198
  async addLog(params) {
159
199
  await this.addScanOrderLog({
160
200
  ...params,
@@ -319,13 +359,13 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
319
359
  if (targetModule) {
320
360
  this.store[step] = targetModule;
321
361
  const initialState = step === "salesSummary" ? {
322
- // TODO(Order types): ScanOrder runtime should read OrderState.summary instead of tempOrder.summary.
323
362
  summary: ((_b2 = (_a2 = this.store.order) == null ? void 0 : _a2.getTempOrder()) == null ? void 0 : _b2.summary) || (0, import_utils.createEmptySummary)()
324
363
  } : {};
325
364
  const loggerProvider = ((_c2 = this.otherParams) == null ? void 0 : _c2.scanOrderLoggerProvider) || "feishu";
326
365
  const loggerConfig = ((_d2 = this.otherParams) == null ? void 0 : _d2.scanOrderLoggerConfig) || {
327
366
  feishu: {
328
- webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/216b3fe6-af98-424e-8706-f0471241a7ed"
367
+ webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/216b3fe6-af98-424e-8706-f0471241a7ed",
368
+ errorHook: "https://open.feishu.cn/open-apis/bot/v2/hook/015b7c2a-dd3c-4c30-9898-ef0f5253111f"
329
369
  }
330
370
  };
331
371
  this.core.registerModule(targetModule, {
@@ -747,6 +787,34 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
747
787
  throw error;
748
788
  }
749
789
  }
790
+ findReservationRuleResource(formId) {
791
+ var _a;
792
+ if (formId == null)
793
+ return void 0;
794
+ const numericFormId = Number(formId);
795
+ if (!Number.isFinite(numericFormId) || numericFormId <= 0)
796
+ return void 0;
797
+ for (const product of this.enabledReservationRuleProducts) {
798
+ const resources = (_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources;
799
+ if (!Array.isArray(resources))
800
+ continue;
801
+ const matched = resources.find((resource) => Number(resource == null ? void 0 : resource.id) === numericFormId);
802
+ if (matched)
803
+ return matched;
804
+ }
805
+ return void 0;
806
+ }
807
+ buildScanOrderResourceMetadata(params) {
808
+ const { resourceState, resourceName } = params;
809
+ const ruleResource = this.findReservationRuleResource(resourceState.tableFormId);
810
+ const combined = ruleResource == null ? void 0 : ruleResource.combined_resource;
811
+ const isCombined = !!(combined && combined.status === 1 && Array.isArray(combined.resource_ids));
812
+ return {
813
+ form_name: (ruleResource == null ? void 0 : ruleResource.title) ?? "",
814
+ resource_name: resourceName,
815
+ combined_resource: isCombined ? combined : null
816
+ };
817
+ }
750
818
  // ScanOrder 提交 payload enhancer:
751
819
  // - 给所有 booking 注入 appointment_status: 'started'(扫码点餐语义)
752
820
  // - 给所有 booking 的 metadata 注入 resource_select_type(来自预约规则商品的 resource.type)
@@ -770,6 +838,9 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
770
838
  return (payload, { bookingUuid, tempOrder }) => {
771
839
  var _a, _b;
772
840
  const resourceId = tempOrder.resource_id ?? (resourceState == null ? void 0 : resourceState.relationId);
841
+ const rawCollectPax = (_a = tempOrder.metadata) == null ? void 0 : _a.collect_pax;
842
+ const hasCollectPaxForCapacity = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
843
+ const resourceCapacityValue = hasCollectPaxForCapacity ? (0, import_utils2.normalizeSubmitCollectPaxValue)(rawCollectPax) : resolveResourceCapacity();
773
844
  const pickOriginal = (value) => {
774
845
  if (value && typeof value === "object" && !Array.isArray(value)) {
775
846
  const original = value.original;
@@ -777,7 +848,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
777
848
  }
778
849
  return void 0;
779
850
  };
780
- const mainField = pickOriginal(tempOrder.table_number) ?? pickOriginal((_a = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _a.name) ?? "";
851
+ const mainField = pickOriginal(tempOrder.table_number) ?? pickOriginal((_b = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _b.name) ?? "";
781
852
  const resourceEntry = resourceState && resourceId ? {
782
853
  relation_type: "form",
783
854
  like_status: "common",
@@ -785,37 +856,35 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
785
856
  main_field: mainField,
786
857
  form_id: resourceState.tableFormId,
787
858
  relation_id: resourceState.relationId ?? resourceId,
788
- capacity: resolveResourceCapacity(),
789
- metadata: {}
859
+ capacity: resourceCapacityValue,
860
+ metadata: this.buildScanOrderResourceMetadata({
861
+ resourceState,
862
+ resourceName: mainField
863
+ })
790
864
  } : void 0;
791
865
  const ruleProductUid = ruleProduct ? (0, import_utils2.createUuidV4)() : void 0;
792
- const rawCollectPax = (_b = tempOrder.metadata) == null ? void 0 : _b.collect_pax;
793
- const hasCollectPaxForCapacity = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
794
- const bookingCapacityValue = hasCollectPaxForCapacity ? (0, import_utils2.normalizeSubmitCollectPaxValue)(rawCollectPax) : resolveResourceCapacity();
866
+ const bookingCapacityValue = resourceCapacityValue;
795
867
  const bookingCapacityDimensionId = (0, import_utils.pickFirstCustomCapacityDimensionId)(this.enabledReservationRuleProducts) ?? 0;
796
- const nextBookings = (payload.bookings || []).map((booking, idx) => {
797
- var _a2;
798
- return {
799
- ...booking,
800
- appointment_status: "started",
801
- metadata: {
802
- ...booking.metadata || {},
803
- holder_id: ((_a2 = booking.metadata) == null ? void 0 : _a2.holder_id) ?? null,
804
- ...resourceSelectType ? { resource_select_type: resourceSelectType } : {},
805
- ...resourceSelectType ? {
806
- capacity: [
807
- {
808
- id: bookingCapacityDimensionId,
809
- value: bookingCapacityValue,
810
- name: ""
811
- }
812
- ]
813
- } : {}
814
- },
815
- ...idx === 0 && resourceEntry ? { resources: [resourceEntry] } : {},
816
- ...idx === 0 && ruleProductUid ? { product_uid: ruleProductUid } : {}
817
- };
818
- });
868
+ const nextBookings = (payload.bookings || []).map((booking, idx) => ({
869
+ ...booking,
870
+ number: bookingCapacityValue,
871
+ appointment_status: "started",
872
+ metadata: {
873
+ ...booking.metadata || {},
874
+ ...resourceSelectType ? { resource_select_type: resourceSelectType } : {},
875
+ ...resourceSelectType ? {
876
+ capacity: [
877
+ {
878
+ id: bookingCapacityDimensionId,
879
+ value: bookingCapacityValue,
880
+ name: ""
881
+ }
882
+ ]
883
+ } : {}
884
+ },
885
+ ...idx === 0 && resourceEntry ? { resources: [resourceEntry] } : {},
886
+ ...idx === 0 && ruleProductUid ? { product_uid: ruleProductUid } : {}
887
+ }));
819
888
  const nextProducts = [...payload.products || []];
820
889
  if (ruleProduct && ruleProductUid && !tempOrder.order_id) {
821
890
  const sellingPrice = String(ruleProduct.price ?? "0.00");
@@ -903,23 +972,23 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
903
972
  throw error;
904
973
  }
905
974
  }
906
- async updateProductInOrder(params) {
907
- this.logMethodStart("updateProductInOrder", {
975
+ async updateOrderProduct(params) {
976
+ this.logMethodStart("updateOrderProduct", {
908
977
  product_id: params.product_id,
909
978
  product_variant_id: params.product_variant_id
910
979
  });
911
980
  try {
912
981
  if (!this.store.order)
913
982
  throw new Error("order 模块未初始化");
914
- const products = await this.store.order.updateProductInOrder(params);
983
+ const products = await this.store.order.updateOrderProduct(params);
915
984
  await this.refreshItemRuleQuantityLimits();
916
985
  await this.refreshCartValidationPassed();
917
- this.logMethodSuccess("updateProductInOrder", {
986
+ this.logMethodSuccess("updateOrderProduct", {
918
987
  productCount: products.length
919
988
  });
920
989
  return products;
921
990
  } catch (error) {
922
- this.logMethodError("updateProductInOrder", error);
991
+ this.logMethodError("updateOrderProduct", error);
923
992
  throw error;
924
993
  }
925
994
  }
@@ -938,15 +1007,14 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
938
1007
  product_variant_id: identity.product_variant_id,
939
1008
  updates: { note: String(note || "") }
940
1009
  };
941
- if (identity.identity_key !== void 0) {
1010
+ if (identity.identity_key !== void 0)
942
1011
  params.identity_key = identity.identity_key;
943
- }
944
1012
  if (identity.product_option_item !== void 0) {
945
1013
  params.product_option_item = identity.product_option_item;
946
1014
  }
947
1015
  if (identity.product_bundle !== void 0)
948
1016
  params.product_bundle = identity.product_bundle;
949
- const products = await this.updateProductInOrder(params);
1017
+ const products = await this.updateOrderProduct(params);
950
1018
  this.logMethodSuccess("setOrderProductLineNote", { productCount: products.length });
951
1019
  return products;
952
1020
  } catch (error) {
@@ -1208,7 +1276,6 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1208
1276
  item_rule_prefill: true,
1209
1277
  item_rule_id: prefillItem.ruleId
1210
1278
  },
1211
- // TODO(Order types): migrate ScanOrder prefill origin runtime into tempOrder._extend.
1212
1279
  _origin: sourceItem ? {
1213
1280
  ...targetProduct._origin || {},
1214
1281
  ...sourceItem
@@ -1433,14 +1500,17 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1433
1500
  // 通过 resource_id + 店铺配置
1434
1501
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
1435
1502
  async checkResourceAvailable(resourceId, hasOrderId) {
1436
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1503
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1437
1504
  this.logMethodStart("checkResourceAvailable", {
1438
1505
  resourceId
1439
1506
  });
1440
1507
  try {
1441
- const openData = await ((_b = (_a = this.otherParams) == null ? void 0 : _a.getOpenData) == null ? void 0 : _b.call(_a, {
1508
+ const businessCode = String(((_a = this.otherParams) == null ? void 0 : _a.businessCode) ?? "").trim();
1509
+ const channel = String(((_b = this.otherParams) == null ? void 0 : _b.channel) ?? "").trim();
1510
+ const openDataTarget = businessCode && channel ? `${businessCode}+${channel}` : "dine_in+scan_to_order";
1511
+ const openData = await ((_d = (_c = this.otherParams) == null ? void 0 : _c.getOpenData) == null ? void 0 : _d.call(_c, {
1442
1512
  scope: "board",
1443
- target: "dine_in+scan_to_order",
1513
+ target: openDataTarget,
1444
1514
  section_code: ["basic", "fulfillment", "reservation", "sale", "menu", "availability", "workflow"]
1445
1515
  }));
1446
1516
  if ((openData == null ? void 0 : openData.status) === false) {
@@ -1531,13 +1601,13 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1531
1601
  }
1532
1602
  } else {
1533
1603
  this.enabledReservationRuleProducts = [];
1534
- void this.addScanOrderLog({
1535
- level: "error",
1536
- title: "[ScanOrder] enabled_reservation_rules product query failed",
1537
- payload: {
1538
- linkIds: reservationLinkIds,
1539
- error: this.serializeError(loaded)
1540
- }
1604
+ const error = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1605
+ this.logMethodError("loadReservationRuleProducts", error, {
1606
+ resourceId,
1607
+ reservationLinkIds,
1608
+ scheduleDate,
1609
+ scheduleDatetime,
1610
+ cacheId: this.cacheId
1541
1611
  });
1542
1612
  }
1543
1613
  }
@@ -1567,16 +1637,16 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1567
1637
  table_form_id: resourceState.tableFormId,
1568
1638
  deskmate_valid: resourceState.deskmate_valid,
1569
1639
  table_form_record: resourceState.table_form_record,
1570
- policy: (_c = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _c.policy,
1571
- partyroom_booking: (_d = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _d.partyroom_booking,
1640
+ policy: (_e = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _e.policy,
1641
+ partyroom_booking: (_f = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _f.partyroom_booking,
1572
1642
  ...this.store.resource.requestEntryPax !== void 0 ? { requestEntryPax: this.store.resource.requestEntryPax } : {},
1573
1643
  ...this.store.resource.requestPaxMin !== void 0 ? { requestPaxMin: this.store.resource.requestPaxMin } : {},
1574
1644
  ...this.store.resource.requestPaxMax !== void 0 ? { requestPaxMax: this.store.resource.requestPaxMax } : {}
1575
1645
  };
1576
- tempOrder.relation_id = resourceId || ((_e = this.otherParams) == null ? void 0 : _e.relation_id);
1646
+ tempOrder.relation_id = resourceId || ((_g = this.otherParams) == null ? void 0 : _g.relation_id);
1577
1647
  tempOrder.table_form_id = resourceState.tableFormId;
1578
1648
  tempOrder.resource_id = resourceId;
1579
- (_f = this.store.order) == null ? void 0 : _f.persistTempOrder();
1649
+ (_h = this.store.order) == null ? void 0 : _h.persistTempOrder();
1580
1650
  if (availabilityInfo.mode === "idle") {
1581
1651
  await this.addNewOrder();
1582
1652
  }
@@ -1584,16 +1654,16 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1584
1654
  tempOrder.order_id = resourceState.lastOrderId;
1585
1655
  }
1586
1656
  if (tempOrder.order_id) {
1587
- const res = await ((_g = this.store.order) == null ? void 0 : _g.getOrderInfoByRemote(tempOrder.order_id));
1588
- const entryPaxNumber = (_k = (_j = (_i = (_h = res == null ? void 0 : res.data) == null ? void 0 : _h.bookings) == null ? void 0 : _i.find((p) => {
1657
+ const res = await ((_i = this.store.order) == null ? void 0 : _i.getOrderInfoByRemote(tempOrder.order_id));
1658
+ const entryPaxNumber = (_m = (_l = (_k = (_j = res == null ? void 0 : res.data) == null ? void 0 : _j.bookings) == null ? void 0 : _k.find((p) => {
1589
1659
  var _a2;
1590
1660
  return (_a2 = p.metadata) == null ? void 0 : _a2.collect_pax;
1591
- })) == null ? void 0 : _j.metadata) == null ? void 0 : _k.collect_pax;
1661
+ })) == null ? void 0 : _l.metadata) == null ? void 0 : _m.collect_pax;
1592
1662
  if (entryPaxNumber) {
1593
1663
  await this.setEntryPaxNumber(entryPaxNumber);
1594
1664
  }
1595
1665
  }
1596
- const lastOrderInfo = (_m = (_l = this.store.order) == null ? void 0 : _l.getLastOrderInfo) == null ? void 0 : _m.call(_l);
1666
+ const lastOrderInfo = (_o = (_n = this.store.order) == null ? void 0 : _n.getLastOrderInfo) == null ? void 0 : _o.call(_n);
1597
1667
  const historicalItems = hasOrderId && Array.isArray(lastOrderInfo == null ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce((acc, p) => {
1598
1668
  if (typeof (p == null ? void 0 : p.product_id) !== "number")
1599
1669
  return acc;
@@ -1605,7 +1675,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1605
1675
  return acc;
1606
1676
  }, []) : [];
1607
1677
  await this.setItemRuleRuntimeConfig({
1608
- serviceType: (_n = this.otherParams) == null ? void 0 : _n.businessCode,
1678
+ serviceType: (_p = this.otherParams) == null ? void 0 : _p.businessCode,
1609
1679
  submissionIndex: hasOrderId ? 1 : 0,
1610
1680
  historicalItems
1611
1681
  });
@@ -1653,18 +1723,24 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1653
1723
  }
1654
1724
  // 获取商品列表
1655
1725
  async getProductList() {
1656
- var _a, _b, _c;
1726
+ var _a, _b;
1657
1727
  this.logMethodStart("getProductList");
1658
1728
  const menu_list_ids = ((_b = (_a = this.otherParams) == null ? void 0 : _a.dineInConfig) == null ? void 0 : _b["menu.associated_menus"].map((n) => Number(n.value))) || [];
1659
1729
  try {
1660
- const res = await ((_c = this.store.products) == null ? void 0 : _c.loadProducts({
1730
+ if (!this.store.products)
1731
+ throw new Error("products 模块未初始化");
1732
+ const res = await this.store.products.loadProducts({
1661
1733
  menu_list_ids,
1662
1734
  cacheId: this.cacheId,
1663
1735
  schedule_date: (0, import_dayjs.default)().format("YYYY-MM-DD"),
1664
1736
  schedule_datetime: (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
1665
- }));
1737
+ });
1738
+ const productList = this.assertProductListLoaded("getProductList", res, {
1739
+ menu_list_ids,
1740
+ cacheId: this.cacheId
1741
+ });
1666
1742
  const formattedRes = (0, import_utils.attachItemRuleLimitsToTopLevelProducts)(
1667
- res,
1743
+ productList,
1668
1744
  this.store.itemRuleQuantityLimits || []
1669
1745
  );
1670
1746
  this.logMethodSuccess("getProductList", {
@@ -1672,7 +1748,12 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1672
1748
  });
1673
1749
  return formattedRes;
1674
1750
  } catch (error) {
1675
- this.logMethodError("getProductList", error.message);
1751
+ if (!(error == null ? void 0 : error.__scanOrderLogged)) {
1752
+ this.logMethodError("getProductList", error, {
1753
+ menu_list_ids,
1754
+ cacheId: this.cacheId
1755
+ });
1756
+ }
1676
1757
  throw error;
1677
1758
  }
1678
1759
  }
@@ -63,6 +63,7 @@ module.exports = __toCommonJS(utils_exports);
63
63
  var import_dayjs = __toESM(require("dayjs"));
64
64
  var import_decimal = __toESM(require("decimal.js"));
65
65
  var import_utils = require("../../modules/Order/utils");
66
+ var import_manualProductDiscount = require("../../modules/Order/utils/manualProductDiscount");
66
67
  function createEmptySummary() {
67
68
  return {
68
69
  product_quantity: 0,
@@ -406,12 +407,40 @@ function getProductIdentityIndex(products, identity) {
406
407
  return products.findIndex((item) => isIdentityMatch(item, identity));
407
408
  }
408
409
  function normalizeOrderProduct(product) {
409
- var _a, _b, _c;
410
+ var _a, _b, _c, _d, _e, _f;
410
411
  const metadata = { ...product.metadata || {} };
411
412
  const resolvedIdentityKey = ((_a = product.metadata) == null ? void 0 : _a.unique_identification_number) ? String(product.metadata.unique_identification_number) : product.unique_identification_number && String(product.unique_identification_number).length > 0 ? String(product.unique_identification_number) : product.identity_key && String(product.identity_key).length > 0 ? String(product.identity_key) : (0, import_utils.createUuidV4)();
412
413
  metadata.unique_identification_number = resolvedIdentityKey;
413
- const normalizedBundle = (product.product_bundle || []).map((item) => ({
414
+ const priceOverride = metadata.price_override;
415
+ const originOtherBundle = (_d = (_c = (_b = metadata.origin) == null ? void 0 : _b._extend) == null ? void 0 : _c.other) == null ? void 0 : _d.bundle;
416
+ let bundleInput = product.product_bundle || [];
417
+ if (priceOverride !== void 0 && priceOverride !== null && priceOverride !== "" && Array.isArray(originOtherBundle) && originOtherBundle.length > 0) {
418
+ const priceById = /* @__PURE__ */ new Map();
419
+ originOtherBundle.forEach((item) => {
420
+ if ((item == null ? void 0 : item.id) == null)
421
+ return;
422
+ const unit = item.price ?? item.bundle_selling_price;
423
+ if (unit === void 0 || unit === null)
424
+ return;
425
+ priceById.set(String(item.id), String(unit));
426
+ });
427
+ const base = Array.isArray(bundleInput) && bundleInput.length > 0 ? bundleInput : originOtherBundle;
428
+ bundleInput = base.map((item) => {
429
+ const unit = priceById.get(String(item == null ? void 0 : item.id));
430
+ if (unit === void 0)
431
+ return item;
432
+ return {
433
+ ...item,
434
+ price: unit,
435
+ bundle_selling_price: unit
436
+ };
437
+ });
438
+ }
439
+ const normalizedBundle = bundleInput.map((item) => ({
414
440
  ...item,
441
+ bundle_id: item.bundle_id ?? item.id,
442
+ bundle_product_id: item.bundle_product_id ?? item._bundle_product_id,
443
+ bundle_group_id: item.bundle_group_id ?? item.group_id,
415
444
  bundle_selling_price: item.bundle_selling_price ?? item.price ?? "0.00",
416
445
  price: item.price ?? item.custom_price ?? item.bundle_selling_price ?? "0.00",
417
446
  price_type: item.price_type ?? item.custom_price_type ?? "",
@@ -421,8 +450,8 @@ function normalizeOrderProduct(product) {
421
450
  const optionSum = (0, import_utils.sumOptionUnitPrice)(normalizedOptions);
422
451
  const isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === "2";
423
452
  const variantId = Number(product.product_variant_id || 0);
424
- const variantList = variantId ? (_b = metadata == null ? void 0 : metadata.origin) == null ? void 0 : _b.variant : null;
425
- const variantPrice = Array.isArray(variantList) ? (_c = variantList.find((v) => Number(v == null ? void 0 : v.id) === variantId)) == null ? void 0 : _c.price : void 0;
453
+ const variantList = variantId ? (_e = metadata == null ? void 0 : metadata.origin) == null ? void 0 : _e.variant : null;
454
+ const variantPrice = Array.isArray(variantList) ? (_f = variantList.find((v) => Number(v == null ? void 0 : v.id) === variantId)) == null ? void 0 : _f.price : void 0;
426
455
  const resolvedSource = (() => {
427
456
  var _a2, _b2;
428
457
  if (metadata.source_product_price !== void 0) {
@@ -478,6 +507,17 @@ function normalizeOrderProduct(product) {
478
507
  bundle: normalizedBundle,
479
508
  useOriginalBundle: true
480
509
  });
510
+ const finalOriginalPrice = (0, import_utils.resolveManualOverrideLineOriginalPrice)(
511
+ { num: product.num, metadata, lineOriginalPrice: product.original_price },
512
+ composedOriginalPrice
513
+ );
514
+ const discountList = (0, import_manualProductDiscount.ensureManualProductDiscountList)({
515
+ discountList: product.discount_list,
516
+ metadata,
517
+ originalPrice: finalOriginalPrice,
518
+ sellingPrice: composedSellingPrice,
519
+ quantity: getSafeProductNum(product.num)
520
+ });
481
521
  return {
482
522
  order_detail_id: product.order_detail_id || null,
483
523
  product_id: product.product_id,
@@ -485,10 +525,10 @@ function normalizeOrderProduct(product) {
485
525
  product_variant_id: product.product_variant_id,
486
526
  product_option_item: normalizedOptions,
487
527
  selling_price: composedSellingPrice,
488
- original_price: composedOriginalPrice,
528
+ original_price: finalOriginalPrice,
489
529
  tax_fee: product.tax_fee || "0.00",
490
530
  is_charge_tax: product.is_charge_tax ?? 0,
491
- discount_list: product.discount_list || [],
531
+ discount_list: discountList,
492
532
  product_bundle: normalizedBundle,
493
533
  metadata,
494
534
  note: product.note != null ? String(product.note) : ""
@@ -46,7 +46,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
46
46
  discountList: Discount[];
47
47
  type: "server" | "clientCalc";
48
48
  unavailableReason?: UnavailableReason;
49
- unavailableReasonKey?: string | null;
50
49
  }>;
51
50
  calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
52
51
  private getCustomer;
@@ -274,8 +274,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
274
274
  async scanCode(code, customerId) {
275
275
  var _a, _b, _c;
276
276
  try {
277
- const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId, orderId: this.store.orderId })) || { discountList: [], unavailableReasonKey: null };
278
- const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
277
+ const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId, orderId: this.store.orderId })) || [];
279
278
  const rulesModule = this.store.rules;
280
279
  if (!rulesModule) {
281
280
  return {
@@ -291,8 +290,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
291
290
  type: "server",
292
291
  isAvailable: false,
293
292
  productList: this.store.productList || [],
294
- discountList: this.getDiscountList(),
295
- unavailableReasonKey
293
+ discountList: this.getDiscountList()
296
294
  };
297
295
  }
298
296
  const withScanList = resultDiscountList.map((item) => {
@@ -2,7 +2,7 @@ import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
3
  import { VenueBookingAddLogParams, VenueBookingSlotConfig, VenueDateSummaryItem, VenueSlotSelection, VenueTimeSlotGrid } from './types';
4
4
  import type { ScanOrderOrderProduct, ScanOrderOrderProductIdentity } from '../ScanOrder/types';
5
- import type { UpdateProductInOrderParams } from '../../modules/Order/types';
5
+ import type { UpdateOrderProductParams } from '../../modules/Order/types';
6
6
  import type { OpenDataAvailabilityResult } from '../../modules/OpenData';
7
7
  import type { ProductData } from '../../modules/Product/types';
8
8
  import { type CartItemSummary, type PaxInfo, type QuantityCheckResult, type QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
@@ -41,6 +41,8 @@ export declare class VenueBookingImpl extends BaseModule implements Module {
41
41
  private loadOpenDataConfigInFlight;
42
42
  private static readonly OPEN_DATA_CACHE_TTL;
43
43
  private getLoggerContext;
44
+ private safeStringify;
45
+ private pickErrorMessage;
44
46
  private serializeError;
45
47
  private addVenueBookingLog;
46
48
  private logMethodStart;
@@ -148,13 +150,7 @@ export declare class VenueBookingImpl extends BaseModule implements Module {
148
150
  customerId: number;
149
151
  }): Promise<void>;
150
152
  private recalculateOrderPricesFromQuotation;
151
- scanCode(code: string, customerId?: number): Promise<{
152
- isAvailable: boolean;
153
- discountList: import("../../modules/Discount").Discount[];
154
- type: "server" | "clientCalc";
155
- unavailableReason?: import("../../modules/Rules/types").UnavailableReason | undefined;
156
- unavailableReasonKey?: string | null | undefined;
157
- }>;
153
+ scanCode(code: string, customerId?: number): Promise<import("../../modules/Order/types").OrderScanCodeResult>;
158
154
  /** 获取当前折扣列表(包装 order.getDiscountList) */
159
155
  getDiscountList(): import("../../modules/Discount").Discount[];
160
156
  /** 勾选/取消勾选某张折扣券,重新计算折扣并持久化 */
@@ -167,7 +163,7 @@ export declare class VenueBookingImpl extends BaseModule implements Module {
167
163
  getSummary(): Promise<import("../../modules/Order/types").OrderSummary>;
168
164
  submitOrder<T = any>(): Promise<T>;
169
165
  addProductToOrder(product: Partial<ScanOrderOrderProduct> & ScanOrderOrderProductIdentity): Promise<import("../../modules/Order/types").OrderProduct[]>;
170
- updateProductInOrder(params: UpdateProductInOrderParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
166
+ updateOrderProduct(params: UpdateOrderProductParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
171
167
  removeProductFromOrder(identity: ScanOrderOrderProductIdentity): Promise<import("../../modules/Order/types").OrderProduct[]>;
172
168
  getProductList(): Promise<ProductData[]>;
173
169
  private loadOpenDataConfig;