@pisell/pisellos 2.2.163 → 2.2.165

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 (124) 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 +157 -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 +65 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +191 -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.js +23 -22
  32. package/dist/modules/Discount/index.js +4 -3
  33. package/dist/modules/Order/index.d.ts +25 -7
  34. package/dist/modules/Order/index.js +608 -291
  35. package/dist/modules/Order/types.d.ts +46 -14
  36. package/dist/modules/Order/types.js +2 -0
  37. package/dist/modules/Order/utils.d.ts +10 -0
  38. package/dist/modules/Order/utils.js +76 -23
  39. package/dist/modules/SalesSummary/index.js +4 -2
  40. package/dist/modules/index.d.ts +1 -0
  41. package/dist/modules/index.js +2 -1
  42. package/dist/solution/BaseSales/index.d.ts +46 -7
  43. package/dist/solution/BaseSales/index.js +928 -312
  44. package/dist/solution/BaseSales/types.d.ts +51 -1
  45. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  46. package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
  47. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +33 -14
  48. package/dist/solution/BaseSales/utils.js +36 -7
  49. package/dist/solution/BookingByStep/index.d.ts +1 -1
  50. package/dist/solution/BookingTicket/index.d.ts +124 -1
  51. package/dist/solution/BookingTicket/index.js +488 -90
  52. package/dist/solution/BookingTicket/types.d.ts +2 -0
  53. package/dist/solution/BookingTicket/types.js +3 -0
  54. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +111 -0
  55. package/dist/solution/BookingTicket/utils/addProductDecision.js +334 -0
  56. package/dist/solution/ScanOrder/index.d.ts +9 -3
  57. package/dist/solution/ScanOrder/index.js +231 -128
  58. package/dist/solution/ScanOrder/utils.js +36 -7
  59. package/dist/solution/VenueBooking/index.d.ts +4 -2
  60. package/dist/solution/VenueBooking/index.js +103 -55
  61. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  62. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  63. package/lib/modules/BookingContext/index.d.ts +37 -0
  64. package/lib/modules/BookingContext/index.js +297 -0
  65. package/lib/modules/BookingContext/types.d.ts +102 -0
  66. package/lib/modules/BookingContext/types.js +34 -0
  67. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  68. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +174 -0
  69. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  70. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  71. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +65 -0
  72. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +177 -0
  73. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  74. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  75. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  76. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  77. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  78. package/lib/modules/BookingContext/utils/index.js +43 -0
  79. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  80. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  81. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  82. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  83. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  84. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  85. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  86. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  87. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  88. package/lib/modules/BookingContext/utils/resources.js +377 -0
  89. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  90. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  91. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  92. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  93. package/lib/modules/Customer/index.js +8 -8
  94. package/lib/modules/Discount/index.js +5 -1
  95. package/lib/modules/Order/index.d.ts +25 -7
  96. package/lib/modules/Order/index.js +268 -72
  97. package/lib/modules/Order/types.d.ts +46 -14
  98. package/lib/modules/Order/utils.d.ts +10 -0
  99. package/lib/modules/Order/utils.js +66 -15
  100. package/lib/modules/SalesSummary/index.js +4 -2
  101. package/lib/modules/index.d.ts +1 -0
  102. package/lib/modules/index.js +3 -1
  103. package/lib/solution/BaseSales/index.d.ts +46 -7
  104. package/lib/solution/BaseSales/index.js +369 -17
  105. package/lib/solution/BaseSales/types.d.ts +51 -1
  106. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  107. package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
  108. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +31 -10
  109. package/lib/solution/BaseSales/utils.js +37 -5
  110. package/lib/solution/BookingByStep/index.d.ts +1 -1
  111. package/lib/solution/BookingTicket/index.d.ts +124 -1
  112. package/lib/solution/BookingTicket/index.js +255 -8
  113. package/lib/solution/BookingTicket/types.d.ts +2 -0
  114. package/lib/solution/BookingTicket/types.js +6 -0
  115. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +111 -0
  116. package/lib/solution/BookingTicket/utils/addProductDecision.js +308 -0
  117. package/lib/solution/ScanOrder/index.d.ts +9 -3
  118. package/lib/solution/ScanOrder/index.js +147 -66
  119. package/lib/solution/ScanOrder/utils.js +37 -5
  120. package/lib/solution/VenueBooking/index.d.ts +4 -2
  121. package/lib/solution/VenueBooking/index.js +50 -14
  122. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  123. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  124. package/package.json +1 -1
@@ -174,21 +174,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
174
174
  }
175
175
  // ─── Discount: 公共 API ───
176
176
  async loadDiscountConfig(params) {
177
- var _a, _b, _c, _d;
178
- const discountList = await ((_a = this.store.discount) == null ? void 0 : _a.loadPrepareConfig({
177
+ var _a, _b, _c, _d, _e, _f;
178
+ const orderId = params.orderId || ((_a = this.store.tempOrder) == null ? void 0 : _a.order_id) || void 0;
179
+ const discountList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
179
180
  customer_id: params.customerId,
180
- action: params.action || "create",
181
+ action: params.action || (orderId ? "edit" : "create"),
181
182
  with_good_pass: 1,
182
183
  with_discount_card: 1,
183
184
  with_wallet_pass_holder: 1,
184
- request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
185
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
186
+ ...orderId ? { order_id: orderId } : {}
185
187
  }));
186
188
  if (discountList) {
187
- (_b = this.store.discount) == null ? void 0 : _b.setDiscountList(discountList);
189
+ await ((_c = this.store.discount) == null ? void 0 : _c.setOriginalDiscountList(discountList));
190
+ await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(discountList));
188
191
  }
189
- if ((_d = (_c = this.store.tempOrder) == null ? void 0 : _c.products) == null ? void 0 : _d.length) {
192
+ if (params.apply !== false && ((_f = (_e = this.store.tempOrder) == null ? void 0 : _e.products) == null ? void 0 : _f.length)) {
190
193
  this.applyDiscount();
191
194
  }
195
+ return this.getDiscountList();
192
196
  }
193
197
  getDiscountList() {
194
198
  var _a;
@@ -491,6 +495,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
491
495
  });
492
496
  }
493
497
  }
498
+ saveDraftInBackground() {
499
+ void this.saveDraft();
500
+ }
494
501
  async hydrateTempOrderFromLocalRecord(record) {
495
502
  return this.hydrateTempOrderFromRecord(record);
496
503
  }
@@ -568,6 +575,28 @@ var OrderModule = class extends import_BaseModule.BaseModule {
568
575
  getTempOrder() {
569
576
  return this.store.tempOrder;
570
577
  }
578
+ async replaceTempOrder(tempOrder, options) {
579
+ if (!(0, import_utils.isTempOrder)(tempOrder)) {
580
+ throw new Error("无效的 tempOrder 数据");
581
+ }
582
+ const nextTempOrder = this.normalizeTempOrderForRuntime(
583
+ (0, import_lodash_es.cloneDeep)(tempOrder),
584
+ { ensureIdentity: false }
585
+ );
586
+ this.store.tempOrder = nextTempOrder;
587
+ if ((options == null ? void 0 : options.recalculateSummary) !== false) {
588
+ await this.recalculateSummary({ createIfMissing: false });
589
+ } else {
590
+ this.store.summary = (0, import_utils.createEmptySummary)();
591
+ }
592
+ if ((options == null ? void 0 : options.persist) !== false) {
593
+ this.persistTempOrder();
594
+ }
595
+ if (options == null ? void 0 : options.saveDraft) {
596
+ await this.saveDraft();
597
+ }
598
+ return nextTempOrder;
599
+ }
571
600
  getOrderIdentity() {
572
601
  var _a;
573
602
  const tempOrder = this.store.tempOrder;
@@ -716,6 +745,33 @@ var OrderModule = class extends import_BaseModule.BaseModule {
716
745
  }
717
746
  };
718
747
  }
748
+ getBookingUniqueIdentificationNumber(booking) {
749
+ var _a;
750
+ const uid = (_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.unique_identification_number;
751
+ if (uid === void 0 || uid === null || uid === "")
752
+ return null;
753
+ return String(uid);
754
+ }
755
+ findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
756
+ return (tempOrder.bookings || []).findIndex((booking) => {
757
+ return this.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
758
+ });
759
+ }
760
+ removeLinkedBookingsForProduct(tempOrder, product) {
761
+ var _a, _b;
762
+ const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
763
+ const bookingUid = (product == null ? void 0 : product.booking_uid) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.booking_uid);
764
+ if (!productUid && !bookingUid)
765
+ return;
766
+ tempOrder.bookings = (tempOrder.bookings || []).filter((booking) => {
767
+ const currentBookingUid = this.getBookingUniqueIdentificationNumber(booking);
768
+ if (bookingUid && currentBookingUid === String(bookingUid))
769
+ return false;
770
+ if (productUid && String((booking == null ? void 0 : booking.product_uid) || "") === String(productUid))
771
+ return false;
772
+ return true;
773
+ });
774
+ }
719
775
  // ─── TempOrder: 金额汇总 ───
720
776
  getSalesSummary() {
721
777
  if (!this.salesSummaryModuleName)
@@ -775,13 +831,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
775
831
  this.persistTempOrder();
776
832
  return summary;
777
833
  }
778
- // ─── TempOrder: 备注 ───
779
- updateTempOrderNote(note) {
834
+ updateTempOrderNote(note, sync = false) {
780
835
  const tempOrder = this.ensureTempOrder();
781
836
  tempOrder.note = String(note || "");
782
837
  this.persistTempOrder();
838
+ if (sync) {
839
+ const orderId = tempOrder.order_id;
840
+ if (!orderId)
841
+ return tempOrder.note;
842
+ return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
843
+ }
783
844
  return tempOrder.note;
784
845
  }
846
+ async syncTempOrderNoteToRemote(orderId, note) {
847
+ await this.request.put(`/order/order/${orderId}/note`, { note });
848
+ return note;
849
+ }
785
850
  getTempOrderNote() {
786
851
  var _a;
787
852
  return ((_a = this.store.tempOrder) == null ? void 0 : _a.note) || "";
@@ -849,11 +914,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
849
914
  extend.customerSnapshot = (0, import_lodash_es.cloneDeep)(snapshot);
850
915
  }
851
916
  this.persistTempOrder();
917
+ this.saveDraftInBackground();
852
918
  this.emitOrderCustomerChange();
853
919
  }
854
920
  getOrderCustomer() {
855
921
  const tempOrder = this.store.tempOrder;
856
- if (!tempOrder || tempOrder.customer_id === null || tempOrder.customer_id === void 0) {
922
+ if (!tempOrder || !tempOrder.customer_id) {
857
923
  return null;
858
924
  }
859
925
  return {
@@ -871,7 +937,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
871
937
  }
872
938
  clearOrderCustomer() {
873
939
  const tempOrder = this.ensureTempOrder();
874
- tempOrder.customer_id = null;
940
+ tempOrder.customer_id = 0;
875
941
  tempOrder.customer_name = "";
876
942
  tempOrder.country_calling_code = "";
877
943
  tempOrder.phone = "";
@@ -879,6 +945,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
879
945
  if (tempOrder._extend)
880
946
  delete tempOrder._extend.customerSnapshot;
881
947
  this.persistTempOrder();
948
+ this.saveDraftInBackground();
882
949
  this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, null);
883
950
  }
884
951
  emitOrderCustomerChange() {
@@ -1125,15 +1192,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1125
1192
  (item) => (item == null ? void 0 : item.type) === "good_pass" || (item == null ? void 0 : item.tag) === "good_pass"
1126
1193
  );
1127
1194
  }
1128
- async updateProductInOrder(params) {
1129
- var _a, _b, _c, _d, _e;
1195
+ async updateOrderProduct(params) {
1196
+ var _a, _b, _c, _d, _e, _f, _g;
1130
1197
  const {
1131
1198
  product_id,
1132
1199
  product_variant_id,
1133
1200
  updates,
1134
1201
  unique_identification_number,
1202
+ identity_key,
1135
1203
  product_option_item,
1136
- product_bundle
1204
+ product_bundle,
1205
+ booking
1137
1206
  } = params;
1138
1207
  const tempOrder = this.ensureTempOrder();
1139
1208
  const identityLookup = {
@@ -1142,12 +1211,30 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1142
1211
  };
1143
1212
  if (unique_identification_number !== void 0) {
1144
1213
  identityLookup.unique_identification_number = unique_identification_number;
1214
+ if (identity_key === void 0) {
1215
+ identityLookup.identity_key = unique_identification_number;
1216
+ }
1217
+ }
1218
+ if (identity_key !== void 0) {
1219
+ identityLookup.identity_key = identity_key;
1145
1220
  }
1146
1221
  if (product_option_item !== void 0)
1147
1222
  identityLookup.product_option_item = product_option_item;
1148
1223
  if (product_bundle !== void 0)
1149
1224
  identityLookup.product_bundle = product_bundle;
1150
- const productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
1225
+ let productIndex = -1;
1226
+ if (unique_identification_number !== void 0) {
1227
+ const targetUid = String(unique_identification_number);
1228
+ productIndex = tempOrder.products.findIndex((item) => {
1229
+ var _a2;
1230
+ return String(
1231
+ ((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
1232
+ ) === targetUid;
1233
+ });
1234
+ }
1235
+ if (productIndex === -1) {
1236
+ productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
1237
+ }
1151
1238
  if (productIndex === -1) {
1152
1239
  throw new Error("[Order] 目标商品不存在,无法更新");
1153
1240
  }
@@ -1174,28 +1261,169 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1174
1261
  delete nextProduct.metadata.main_product_original_price;
1175
1262
  delete nextProduct.metadata.price_schema_version;
1176
1263
  }
1177
- tempOrder.products[productIndex] = (0, import_utils3.normalizeOrderProduct)(nextProduct);
1264
+ let normalizedProduct = (0, import_utils3.normalizeOrderProduct)(nextProduct);
1265
+ if (booking) {
1266
+ const productUid = String(
1267
+ ((_e = normalizedProduct.metadata) == null ? void 0 : _e.unique_identification_number) || ((_f = targetProduct.metadata) == null ? void 0 : _f.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
1268
+ );
1269
+ normalizedProduct.metadata = {
1270
+ ...normalizedProduct.metadata || {},
1271
+ unique_identification_number: productUid
1272
+ };
1273
+ const linked = this.createLinkedProductAndBooking({
1274
+ product: {
1275
+ ...normalizedProduct,
1276
+ unique_identification_number: productUid
1277
+ },
1278
+ booking
1279
+ });
1280
+ this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
1281
+ normalizedProduct = {
1282
+ ...normalizedProduct,
1283
+ booking_uid: linked.bookingUid,
1284
+ metadata: {
1285
+ ...normalizedProduct.metadata || {},
1286
+ booking_uid: linked.bookingUid,
1287
+ unique_identification_number: productUid
1288
+ }
1289
+ };
1290
+ tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
1291
+ }
1292
+ tempOrder.products[productIndex] = normalizedProduct;
1178
1293
  this.captureProductRuntime(
1179
1294
  tempOrder,
1180
1295
  updates,
1181
1296
  tempOrder.products[productIndex],
1182
- (_e = tempOrder.products[productIndex].metadata) == null ? void 0 : _e.unique_identification_number
1297
+ (_g = tempOrder.products[productIndex].metadata) == null ? void 0 : _g.unique_identification_number
1183
1298
  );
1184
1299
  this.applyDiscount();
1185
1300
  await this.recalculateSummary({ createIfMissing: true });
1186
1301
  this.persistTempOrder();
1187
1302
  return tempOrder.products;
1188
1303
  }
1189
- async removeProductFromOrder(identity) {
1304
+ async updateOrderProductQuantity(params) {
1305
+ var _a;
1306
+ const {
1307
+ product_id,
1308
+ product_variant_id,
1309
+ num,
1310
+ unique_identification_number,
1311
+ identity_key,
1312
+ product_option_item,
1313
+ product_bundle
1314
+ } = params;
1190
1315
  const tempOrder = this.ensureTempOrder();
1191
- tempOrder.products = tempOrder.products.filter(
1192
- (item) => !(0, import_utils3.isIdentityMatch)(item, identity)
1316
+ const identityLookup = {
1317
+ product_id,
1318
+ product_variant_id
1319
+ };
1320
+ if (unique_identification_number !== void 0) {
1321
+ identityLookup.unique_identification_number = unique_identification_number;
1322
+ if (identity_key === void 0) {
1323
+ identityLookup.identity_key = unique_identification_number;
1324
+ }
1325
+ }
1326
+ if (identity_key !== void 0)
1327
+ identityLookup.identity_key = identity_key;
1328
+ if (product_option_item !== void 0)
1329
+ identityLookup.product_option_item = product_option_item;
1330
+ if (product_bundle !== void 0)
1331
+ identityLookup.product_bundle = product_bundle;
1332
+ let productIndex = -1;
1333
+ if (unique_identification_number !== void 0) {
1334
+ const targetUid = String(unique_identification_number);
1335
+ productIndex = tempOrder.products.findIndex((item) => {
1336
+ var _a2;
1337
+ return String(
1338
+ ((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
1339
+ ) === targetUid;
1340
+ });
1341
+ }
1342
+ if (productIndex === -1) {
1343
+ productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
1344
+ }
1345
+ if (productIndex === -1) {
1346
+ throw new Error("[Order] 目标商品不存在,无法更新数量");
1347
+ }
1348
+ const targetProduct = tempOrder.products[productIndex];
1349
+ const normalizedProduct = (0, import_utils3.normalizeOrderProduct)({
1350
+ ...targetProduct,
1351
+ num: (0, import_utils3.getSafeProductNum)(num),
1352
+ metadata: {
1353
+ ...targetProduct.metadata || {},
1354
+ unique_identification_number: ((_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number) || unique_identification_number
1355
+ }
1356
+ });
1357
+ tempOrder.products[productIndex] = normalizedProduct;
1358
+ this.applyDiscount();
1359
+ await this.recalculateSummary({ createIfMissing: true });
1360
+ this.persistTempOrder();
1361
+ return tempOrder.products;
1362
+ }
1363
+ updateOrderBooking(params) {
1364
+ const { unique_identification_number, updates } = params;
1365
+ const tempOrder = this.ensureTempOrder();
1366
+ const bookingUid = String(unique_identification_number || "");
1367
+ const bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(
1368
+ tempOrder,
1369
+ bookingUid
1193
1370
  );
1371
+ if (!bookingUid || bookingIndex === -1) {
1372
+ throw new Error("[Order] 目标 booking 不存在,无法更新");
1373
+ }
1374
+ const targetBooking = tempOrder.bookings[bookingIndex] || {};
1375
+ const nextBooking = {
1376
+ ...targetBooking,
1377
+ ...updates,
1378
+ metadata: {
1379
+ ...targetBooking.metadata || {},
1380
+ ...updates.metadata || {},
1381
+ unique_identification_number: bookingUid
1382
+ }
1383
+ };
1384
+ nextBooking.is_all = (0, import_utils.normalizeBookingIsAll)(nextBooking);
1385
+ nextBooking.sub_type = (0, import_utils.normalizeBookingSubType)(nextBooking);
1386
+ tempOrder.bookings[bookingIndex] = nextBooking;
1387
+ this.persistTempOrder();
1388
+ return tempOrder.bookings;
1389
+ }
1390
+ async removeProductFromOrder(identity) {
1391
+ const tempOrder = this.ensureTempOrder();
1392
+ const removedProducts = [];
1393
+ tempOrder.products = tempOrder.products.filter((item) => {
1394
+ const shouldRemove = (0, import_utils3.isIdentityMatch)(item, identity);
1395
+ if (shouldRemove)
1396
+ removedProducts.push(item);
1397
+ return !shouldRemove;
1398
+ });
1399
+ for (const product of removedProducts) {
1400
+ this.removeLinkedBookingsForProduct(tempOrder, product);
1401
+ }
1194
1402
  this.applyDiscount();
1195
1403
  await this.recalculateSummary({ createIfMissing: true });
1196
1404
  this.persistTempOrder();
1197
1405
  return tempOrder.products;
1198
1406
  }
1407
+ /**
1408
+ * 仅清空购物车行(products / bookings / discount_list),不重置整单。
1409
+ * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
1410
+ */
1411
+ async clearOrderCartLines() {
1412
+ const tempOrder = this.ensureTempOrder();
1413
+ tempOrder.products = [];
1414
+ tempOrder.bookings = [];
1415
+ tempOrder.discount_list = [];
1416
+ if (tempOrder._extend && typeof tempOrder._extend === "object") {
1417
+ tempOrder._extend = {
1418
+ ...tempOrder._extend,
1419
+ productsByUid: {}
1420
+ };
1421
+ }
1422
+ this.applyDiscount();
1423
+ await this.recalculateSummary({ createIfMissing: true });
1424
+ this.persistTempOrder();
1425
+ return tempOrder;
1426
+ }
1199
1427
  // ─── TempOrder: 提交 ───
1200
1428
  /**
1201
1429
  * 提交当前 Sales tempOrder。
@@ -1339,7 +1567,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1339
1567
  const submitResult = await this.submitTempOrder({
1340
1568
  payments: mappedPayments,
1341
1569
  paymentStatus: params.paymentStatus || "paid",
1342
- smallTicketDataFlag: params.smallTicketDataFlag
1570
+ smallTicketDataFlag: params.smallTicketDataFlag,
1571
+ channel: params.channel
1343
1572
  });
1344
1573
  return { isFullyPaid, submitResult };
1345
1574
  }
@@ -1639,53 +1868,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1639
1868
  */
1640
1869
  async hydrateTempOrderFromRecord(record, options) {
1641
1870
  const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
1642
- const defaults = this.createDefaultTempOrderInstance();
1871
+ const nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
1872
+ ensureIdentity: true
1873
+ });
1874
+ this.store.tempOrder = nextTempOrder;
1875
+ this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
1876
+ this.store.lastOrderInfo = raw.lastOrderInfo || raw;
1877
+ if (options == null ? void 0 : options.recalcOnHydrate) {
1878
+ await this.recalculateSummary({ createIfMissing: false });
1879
+ }
1880
+ this.persistTempOrder();
1881
+ return nextTempOrder;
1882
+ }
1883
+ normalizeTempOrderForRuntime(raw, options) {
1643
1884
  const nextTempOrder = {
1644
- ...defaults
1885
+ ...this.createDefaultTempOrderInstance(),
1886
+ ...raw || {}
1645
1887
  };
1646
- const TEMP_ORDER_KEYS = [
1647
- "order_id",
1648
- "external_sale_number",
1649
- "order_number",
1650
- "shop_order_number",
1651
- "shop_full_order_number",
1652
- "type",
1653
- "business_code",
1654
- "platform",
1655
- "sales_channel",
1656
- "order_sales_channel",
1657
- "status",
1658
- "payment_status",
1659
- "shipping_status",
1660
- "customer_id",
1661
- "customer_name",
1662
- "country_calling_code",
1663
- "phone",
1664
- "email",
1665
- "customer",
1666
- "is_price_include_tax",
1667
- "tax_title",
1668
- "tax_country_code",
1669
- "currency_code",
1670
- "currency_symbol",
1671
- "currency_format",
1672
- "is_deposit",
1673
- "deposit_amount",
1674
- "shop_discount",
1675
- "surcharge_fee",
1676
- "note",
1677
- "buzzer",
1678
- "delivery_type",
1679
- "table_number",
1680
- "schedule_date",
1681
- "created_at",
1682
- "request_unique_idempotency_token"
1683
- ];
1684
- TEMP_ORDER_KEYS.forEach((key) => {
1685
- if (raw[key] !== void 0) {
1686
- nextTempOrder[key] = raw[key];
1687
- }
1688
- });
1888
+ delete nextTempOrder.summary;
1889
+ delete nextTempOrder.lastOrderInfo;
1689
1890
  nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
1690
1891
  nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
1691
1892
  nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
@@ -1704,14 +1905,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1704
1905
  ...raw._extend,
1705
1906
  productsByUid: raw._extend.productsByUid || {}
1706
1907
  } : { productsByUid: {} };
1707
- this.ensureExternalSaleNumber(nextTempOrder);
1708
- this.store.tempOrder = nextTempOrder;
1709
- this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
1710
- this.store.lastOrderInfo = raw.lastOrderInfo || raw;
1711
- if (options == null ? void 0 : options.recalcOnHydrate) {
1712
- await this.recalculateSummary({ createIfMissing: false });
1908
+ if ((options == null ? void 0 : options.ensureIdentity) !== false) {
1909
+ this.ensureExternalSaleNumber(nextTempOrder);
1713
1910
  }
1714
- this.persistTempOrder();
1715
1911
  return nextTempOrder;
1716
1912
  }
1717
1913
  normalizeHydratedOrderProduct(product) {
@@ -103,11 +103,11 @@ export interface OrderSummary {
103
103
  export interface OrderTempOrder {
104
104
  order_id: number | null;
105
105
  external_sale_number: string;
106
- order_number: string;
107
- shop_order_number: string;
108
- shop_full_order_number: string;
106
+ order_number: string | null;
107
+ shop_order_number: string | null;
108
+ shop_full_order_number: string | null;
109
109
  type: string;
110
- business_code: string;
110
+ business_code?: string;
111
111
  platform: string;
112
112
  sales_channel: string;
113
113
  order_sales_channel: string;
@@ -157,7 +157,7 @@ export interface OrderSubmitProduct extends Omit<OrderProduct, 'unique_identific
157
157
  payment_price: string;
158
158
  product_sku: Record<string, any>;
159
159
  }
160
- export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | '_extend' | 'customer' | 'shop_full_order_number'> {
160
+ export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | '_extend' | 'customer'> {
161
161
  platform: string;
162
162
  request_unique_idempotency_token?: string;
163
163
  form_record_ids?: Array<{
@@ -176,16 +176,32 @@ export interface OrderState {
176
176
  discount: DiscountModule | null;
177
177
  rules: RulesModule | null;
178
178
  }
179
+ export interface ReplaceTempOrderOptions {
180
+ recalculateSummary?: boolean;
181
+ persist?: boolean;
182
+ saveDraft?: boolean;
183
+ }
184
+ export type AddProductBookingInput = Record<string, any>;
179
185
  /** 更新购物车行:仅传 SKU 时命中同 SKU 第一行;多行同 SKU 须传 unique_identification_number / 选项指纹等 */
180
- export interface UpdateProductInOrderParams {
186
+ export interface UpdateOrderProductParams {
181
187
  product_id: number | null;
182
188
  product_variant_id: number;
183
189
  updates: Partial<OrderProduct>;
184
190
  unique_identification_number?: string;
191
+ identity_key?: string;
185
192
  product_option_item?: any[];
186
193
  product_bundle?: any[];
194
+ booking?: AddProductBookingInput;
195
+ }
196
+ /** 仅更新购物车行数量;行定位语义与 updateOrderProduct / removeProductFromOrder 保持一致 */
197
+ export interface UpdateOrderProductQuantityParams extends OrderProductIdentity {
198
+ num: number;
199
+ identity_key?: string;
200
+ }
201
+ export interface UpdateOrderBookingParams {
202
+ unique_identification_number: string;
203
+ updates: AddProductBookingInput;
187
204
  }
188
- export type AddProductBookingInput = Record<string, any>;
189
205
  export interface OrderProductMergeDecisionContext {
190
206
  incomingProduct: Partial<OrderProduct> & OrderProductIdentity;
191
207
  normalizedIncoming: OrderProduct;
@@ -236,10 +252,11 @@ export interface SubmitSalesOrderParams {
236
252
  query: {
237
253
  order_id: number | null;
238
254
  external_sale_number: string;
239
- order_number: string;
240
- shop_order_number: string;
255
+ order_number: string | null;
256
+ shop_order_number: string | null;
257
+ shop_full_order_number: string | null;
241
258
  type: string;
242
- business_code: string;
259
+ business_code?: string;
243
260
  platform: string;
244
261
  request_unique_idempotency_token?: string;
245
262
  sales_channel: string;
@@ -350,6 +367,7 @@ export interface SyncPaymentsToOrderParams {
350
367
  paymentStatus?: SubmitSalesOrderParams['query']['payment_status'];
351
368
  submitWhenPaid?: boolean;
352
369
  smallTicketDataFlag?: number;
370
+ channel?: string;
353
371
  }
354
372
  export interface SyncPaymentsToOrderResult<T = any> {
355
373
  isFullyPaid: boolean;
@@ -446,6 +464,7 @@ export interface OrderModuleAPI {
446
464
  }) => void;
447
465
  getTempOrder: () => OrderTempOrder | null;
448
466
  ensureTempOrder: () => OrderTempOrder;
467
+ replaceTempOrder: (tempOrder: OrderTempOrder, options?: ReplaceTempOrderOptions) => Promise<OrderTempOrder>;
449
468
  addNewOrder: () => Promise<OrderTempOrder>;
450
469
  restoreOrder: () => OrderTempOrder;
451
470
  getOrderProducts: () => OrderProduct[];
@@ -458,14 +477,25 @@ export interface OrderModuleAPI {
458
477
  getOrderSyncState: () => OrderSyncState;
459
478
  getOrderAmountSnapshot: () => OrderAmountSnapshot | null;
460
479
  getTempOrderNote: () => string;
461
- updateTempOrderNote: (note: string) => string;
480
+ updateTempOrderNote: {
481
+ (note: string): string;
482
+ (note: string, sync: true): Promise<string>;
483
+ (note: string, sync: boolean): string | Promise<string>;
484
+ };
462
485
  updateTempOrderShopDiscount: (amount: string | number) => string;
463
486
  updateTempOrderCustomer: (customer: UpdateTempOrderCustomerInput) => OrderSnapshot['customer'];
464
487
  updateTempOrderBuzzer: (buzzer: string) => string;
465
488
  updateTempOrderContactsInfo: (contactsInfo: Record<string, any> | null) => Record<string, any> | null;
466
489
  addProductToOrder: (product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput) => Promise<OrderProduct[]>;
467
- updateProductInOrder: (params: UpdateProductInOrderParams) => Promise<OrderProduct[]>;
490
+ updateOrderProduct: (params: UpdateOrderProductParams) => Promise<OrderProduct[]>;
491
+ updateOrderProductQuantity: (params: UpdateOrderProductQuantityParams) => Promise<OrderProduct[]>;
492
+ updateOrderBooking: (params: UpdateOrderBookingParams) => any[];
468
493
  removeProductFromOrder: (identity: OrderProductIdentity) => Promise<OrderProduct[]>;
494
+ /**
495
+ * 仅清空购物车行:products / bookings / discount_list(保留客户、备注、支付等其它 tempOrder 字段)。
496
+ * 内部会 applyDiscount + recalculateSummary + persist。
497
+ */
498
+ clearOrderCartLines: () => Promise<OrderTempOrder>;
469
499
  persistTempOrder: () => void;
470
500
  submitTempOrder: <T = any>(params?: {
471
501
  cacheId?: string;
@@ -516,8 +546,10 @@ export interface OrderModuleAPI {
516
546
  clearOrderCustomer: () => void;
517
547
  loadDiscountConfig: (params: {
518
548
  customerId: number;
519
- action?: 'create';
520
- }) => Promise<void>;
549
+ action?: 'create' | 'edit';
550
+ orderId?: number;
551
+ apply?: boolean;
552
+ }) => Promise<Discount[]>;
521
553
  getDiscountList: () => Discount[];
522
554
  applyDiscount: () => void;
523
555
  /**
@@ -65,6 +65,16 @@ export declare function sumOptionUnitPrice(options?: Array<{
65
65
  *
66
66
  * 导出为纯函数方便单测直接驱动钩子,不依赖 OrderModule 实例。
67
67
  */
68
+ /** Rules calcDiscount 用手动价标记;undefined 表示交给 Rules 用 total/origin_total 推断 */
69
+ export declare function resolveRulesManualDiscountFlag(metadata: Record<string, any> | null | undefined): boolean | undefined;
70
+ /**
71
+ * 手动改价(price_override)时行级 original_price:
72
+ * 购物车划线价应对齐改价前的 origin_total(如 40),而非 bundle 子项 catalog 原价合成的 30。
73
+ */
74
+ export declare function resolveManualOverrideLineOriginalPrice(params: {
75
+ num?: number;
76
+ metadata?: Record<string, any> | null;
77
+ }, fallbackCompositeOriginal: string): string;
68
78
  export declare function createDefaultOrderRulesHooks(): RulesParamsHooks;
69
79
  /**
70
80
  * 通过 session 类商品的开始时间结束时间生成商品的时长