@pisell/pisellos 2.3.230 → 2.3.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 (54) hide show
  1. package/dist/model/strategy/adapter/promotion/adapter.js +14 -2
  2. package/dist/model/strategy/adapter/promotion/evaluator.js +23 -8
  3. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  4. package/dist/model/strategy/adapter/promotion/type.d.ts +10 -2
  5. package/dist/modules/Customer/types.d.ts +0 -4
  6. package/dist/modules/Order/index.js +1411 -1318
  7. package/dist/modules/Order/types.d.ts +13 -36
  8. package/dist/modules/Order/types.js +2 -0
  9. package/dist/modules/Order/utils.js +0 -2
  10. package/dist/modules/Product/index.d.ts +1 -1
  11. package/dist/solution/BaseSales/index.js +0 -3
  12. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -18
  13. package/dist/solution/BaseSales/utils/cartPromotion.js +252 -168
  14. package/dist/solution/BookingByStep/index.d.ts +3 -3
  15. package/dist/solution/BookingTicket/index.d.ts +1 -1
  16. package/dist/solution/BookingTicket/index.js +45 -21
  17. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +9 -9
  18. package/dist/solution/Checkout/index.js +69 -104
  19. package/dist/solution/Checkout/types.d.ts +0 -1
  20. package/dist/solution/ScanOrder/index.d.ts +1 -0
  21. package/dist/solution/ScanOrder/index.js +54 -48
  22. package/dist/solution/ScanOrder/menuAvailability.js +3 -25
  23. package/dist/solution/ScanOrder/shopTime.d.ts +6 -0
  24. package/dist/solution/ScanOrder/shopTime.js +36 -0
  25. package/dist/solution/VenueBooking/index.js +490 -522
  26. package/lib/model/strategy/adapter/promotion/adapter.js +10 -1
  27. package/lib/model/strategy/adapter/promotion/evaluator.js +18 -6
  28. package/lib/model/strategy/adapter/promotion/type.d.ts +10 -2
  29. package/lib/modules/Customer/types.d.ts +0 -4
  30. package/lib/modules/Order/index.js +109 -76
  31. package/lib/modules/Order/types.d.ts +13 -36
  32. package/lib/modules/Order/types.js +1 -0
  33. package/lib/modules/Order/utils.js +1 -5
  34. package/lib/modules/Product/index.d.ts +1 -1
  35. package/lib/solution/BaseSales/index.js +0 -3
  36. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -18
  37. package/lib/solution/BaseSales/utils/cartPromotion.js +87 -40
  38. package/lib/solution/BookingByStep/index.d.ts +3 -3
  39. package/lib/solution/BookingTicket/index.d.ts +1 -1
  40. package/lib/solution/BookingTicket/index.js +28 -11
  41. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +9 -9
  42. package/lib/solution/Checkout/index.js +0 -21
  43. package/lib/solution/Checkout/types.d.ts +0 -1
  44. package/lib/solution/ScanOrder/index.d.ts +1 -0
  45. package/lib/solution/ScanOrder/index.js +26 -19
  46. package/lib/solution/ScanOrder/menuAvailability.js +3 -20
  47. package/lib/solution/ScanOrder/shopTime.d.ts +6 -0
  48. package/lib/solution/ScanOrder/shopTime.js +37 -0
  49. package/lib/solution/VenueBooking/index.js +1 -6
  50. package/package.json +1 -1
  51. package/dist/modules/Order/utils/bookingUuid.d.ts +0 -4
  52. package/dist/modules/Order/utils/bookingUuid.js +0 -24
  53. package/lib/modules/Order/utils/bookingUuid.d.ts +0 -4
  54. package/lib/modules/Order/utils/bookingUuid.js +0 -25
@@ -1,4 +1,5 @@
1
- import type { OrderProduct } from '../../../modules/Order/types';
1
+ import type { OrderFixedGiftQuotas, OrderProduct } from '../../../modules/Order/types';
2
+ import type { GiftInfo } from '../../../model/strategy/adapter/promotion/type';
2
3
  /**
3
4
  * 运行态商品行标记:该行由“不合并商品”加车策略创建,促销重算时必须保持独立。
4
5
  * `normalizeSubmitProduct` 会按白名单裁剪 metadata,不会把此字段提交到后端。
@@ -49,15 +50,7 @@ export interface CartPromotionEvaluator {
49
50
  _originalId?: string;
50
51
  _originalIndex?: number;
51
52
  }>;
52
- gifts: Array<{
53
- strategyId: string;
54
- strategyName: string | Record<string, string>;
55
- giftCount: number;
56
- giftOptions: Array<{
57
- product_id: number;
58
- product_variant_id: number;
59
- }>;
60
- }>;
53
+ gifts: GiftInfo[];
61
54
  totalDiscount: number;
62
55
  };
63
56
  getProductsApplicableStrategies(input: {
@@ -94,14 +87,7 @@ export interface GiftReduceItem {
94
87
  newQuantity: number;
95
88
  }
96
89
  /** 赠品新增项 */
97
- export interface GiftToAddAction {
98
- strategyId: string;
99
- strategyName: string | Record<string, string>;
100
- giftCount: number;
101
- giftOptions: Array<{
102
- product_id: number;
103
- product_variant_id: number;
104
- }>;
90
+ export interface GiftToAddAction extends GiftInfo {
105
91
  /** 触发此赠品的主商品 uid 列表 */
106
92
  sourceProductIds: string[];
107
93
  }
@@ -291,4 +277,5 @@ export declare function appendPromotionTags<T extends Record<string, any>>(produ
291
277
  */
292
278
  export declare function processCartPromotion(list: OrderProduct[] | null | undefined, evaluator: CartPromotionEvaluator | null | undefined, options?: {
293
279
  channel?: string;
280
+ previousFixedGiftQuotas?: OrderFixedGiftQuotas[];
294
281
  }): ProcessCartPromotionResult;
@@ -595,15 +595,83 @@ function convertToPromotionProduct(product, index) {
595
595
  // 主流程:processCartPromotion
596
596
  // ============================================
597
597
 
598
+ function reduceGiftQuantity(actions, strategyId, items, quantity) {
599
+ const reductions = [];
600
+ let remaining = quantity;
601
+ for (const item of [...items].reverse()) {
602
+ if (remaining <= 0) break;
603
+ const uid = getOrderProductUid(item);
604
+ const currentQuantity = Number(item.num ?? 1) || 1;
605
+ if (currentQuantity <= remaining) {
606
+ actions.toRemove.push(uid);
607
+ remaining -= currentQuantity;
608
+ } else {
609
+ reductions.push({
610
+ uid,
611
+ currentQuantity,
612
+ newQuantity: currentQuantity - remaining
613
+ });
614
+ remaining = 0;
615
+ }
616
+ }
617
+ if (reductions.length) actions.toReduce.push({
618
+ strategyId,
619
+ items: reductions
620
+ });
621
+ }
622
+ function calculateFixedGiftActions(gift, existing, previousQuotas, actions) {
623
+ const unmatched = new Set(existing);
624
+ const addedQuotas = [];
625
+ for (const quota of gift.giftQuotas || []) {
626
+ const {
627
+ product_id,
628
+ product_variant_id,
629
+ quantity
630
+ } = quota;
631
+ const matching = existing.filter(item => Number(item.product_id) === product_id && (product_variant_id === 0 || Number(item.product_variant_id) === product_variant_id));
632
+ matching.forEach(item => unmatched.delete(item));
633
+ const existingCount = matching.reduce((count, item) => count + (Number(item.num ?? 1) || 1), 0);
634
+ const previous = previousQuotas.find(item => item.product_id === product_id && item.product_variant_id === product_variant_id);
635
+ // 已放弃的额度可以手动领取。自动选择只请求本次新增的部分。
636
+ const added = quantity - Math.max(existingCount, previous?.quantity ?? 0);
637
+ if (added > 0) {
638
+ addedQuotas.push({
639
+ product_id,
640
+ product_variant_id,
641
+ quantity: added
642
+ });
643
+ } else if (existingCount > quantity) {
644
+ reduceGiftQuantity(actions, gift.strategyId, matching, existingCount - quantity);
645
+ }
646
+ }
647
+ if (addedQuotas.length) {
648
+ actions.toAdd.push({
649
+ ...gift,
650
+ giftCount: addedQuotas.reduce((count, quota) => count + quota.quantity, 0),
651
+ giftOptions: addedQuotas.map(({
652
+ product_id,
653
+ product_variant_id
654
+ }) => ({
655
+ product_id,
656
+ product_variant_id
657
+ })),
658
+ giftQuotas: addedQuotas
659
+ });
660
+ }
661
+ for (const item of unmatched) actions.toRemove.push(getOrderProductUid(item));
662
+ }
663
+
598
664
  /**
599
665
  * 计算赠品差异化操作(toAdd / toReduce / toRemove)。
600
666
  *
601
- * 与 legacy `calculateGiftActions` 等价;唯一差别是行键从 `_id` 改成 `metadata.unique_identification_number`。
667
+ * 任选赠品按活动总量对账,固定赠品按活动内的各款额度对账。
602
668
  */
603
- function calculateGiftActions(gifts, existingGifts) {
604
- const toAdd = [];
605
- const toReduce = [];
606
- const toRemove = [];
669
+ function calculateGiftActions(gifts, existingGifts, previousFixedGiftQuotas) {
670
+ const actions = {
671
+ toAdd: [],
672
+ toReduce: [],
673
+ toRemove: []
674
+ };
607
675
 
608
676
  // 按 strategyId 分组现有赠品
609
677
  const existingByStrategy = new Map();
@@ -633,6 +701,11 @@ function calculateGiftActions(gifts, existingGifts) {
633
701
  } = giftInfo;
634
702
  processedStrategyIds.add(strategyId);
635
703
  const existing = existingByStrategy.get(strategyId);
704
+ if (giftInfo.giftQuotas) {
705
+ const previous = previousFixedGiftQuotas.find(item => item.strategyId === strategyId);
706
+ calculateFixedGiftActions(giftInfo, existing?.items || [], previous?.giftQuotas || [], actions);
707
+ continue;
708
+ }
636
709
  const existingCount = existing?.totalQuantity ?? 0;
637
710
  const diff = giftCount - existingCount;
638
711
  if (diff > 0) {
@@ -640,7 +713,7 @@ function calculateGiftActions(gifts, existingGifts) {
640
713
  const lastEvaluated = getGiftInfo(existing?.items?.[0])?.lastEvaluatedGiftCount;
641
714
  const strategyChanged = lastEvaluated === undefined || giftCount !== lastEvaluated;
642
715
  if (strategyChanged) {
643
- toAdd.push({
716
+ actions.toAdd.push({
644
717
  strategyId,
645
718
  strategyName,
646
719
  giftCount: diff,
@@ -649,32 +722,7 @@ function calculateGiftActions(gifts, existingGifts) {
649
722
  });
650
723
  }
651
724
  } else if (diff < 0) {
652
- // 减赠品:后进先出
653
- let remaining = Math.abs(diff);
654
- const reduceItems = [];
655
- const removeIds = [];
656
- const reversed = [...(existing?.items || [])].reverse();
657
- for (const giftItem of reversed) {
658
- if (remaining <= 0) break;
659
- const uid = getOrderProductUid(giftItem);
660
- const qty = Number(giftItem?.num ?? 1) || 1;
661
- if (qty <= remaining) {
662
- removeIds.push(uid);
663
- remaining -= qty;
664
- } else {
665
- reduceItems.push({
666
- uid,
667
- currentQuantity: qty,
668
- newQuantity: qty - remaining
669
- });
670
- remaining = 0;
671
- }
672
- }
673
- if (reduceItems.length > 0) toReduce.push({
674
- strategyId,
675
- items: reduceItems
676
- });
677
- toRemove.push(...removeIds);
725
+ reduceGiftQuantity(actions, strategyId, existing?.items || [], -diff);
678
726
  }
679
727
  }
680
728
 
@@ -682,14 +730,10 @@ function calculateGiftActions(gifts, existingGifts) {
682
730
  for (const [strategyId, existing] of existingByStrategy) {
683
731
  if (processedStrategyIds.has(strategyId)) continue;
684
732
  for (const giftItem of existing.items) {
685
- toRemove.push(getOrderProductUid(giftItem));
733
+ actions.toRemove.push(getOrderProductUid(giftItem));
686
734
  }
687
735
  }
688
- return {
689
- toAdd,
690
- toReduce,
691
- toRemove
692
- };
736
+ return actions;
693
737
  }
694
738
 
695
739
  /**
@@ -1123,7 +1167,10 @@ function processCartPromotion(list, evaluator, options) {
1123
1167
  const giftInfoData = {
1124
1168
  strategyName: gift.strategyName,
1125
1169
  giftCount: gift.giftCount,
1126
- giftOptions: gift.giftOptions
1170
+ giftOptions: gift.giftOptions,
1171
+ ...(gift.giftQuotas && {
1172
+ giftQuotas: gift.giftQuotas
1173
+ })
1127
1174
  };
1128
1175
  const bundleIdx = priced.matchedBundleIndex;
1129
1176
  if (bundleIdx !== undefined && Array.isArray(newItem.product_bundle) && newItem.product_bundle[bundleIdx]?._promotion) {
@@ -1211,7 +1258,7 @@ function processCartPromotion(list, evaluator, options) {
1211
1258
  }
1212
1259
 
1213
1260
  // 10. 赠品操作(在更新 lastEvaluatedGiftCount 前做对比)
1214
- const giftActions = calculateGiftActions(extendedGifts, existingGifts);
1261
+ const giftActions = calculateGiftActions(extendedGifts, existingGifts, options?.previousFixedGiftQuotas || []);
1215
1262
 
1216
1263
  // 10.1 更新 lastEvaluatedGiftCount,便于下次评估时判别「策略已变」
1217
1264
  for (const gift of existingGifts) {
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
342
342
  date: string;
343
343
  status: string;
344
344
  week: string;
345
- weekNum: 0 | 1 | 2 | 5 | 4 | 3 | 6;
345
+ weekNum: 0 | 1 | 2 | 6 | 4 | 5 | 3;
346
346
  }[]>;
347
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
348
348
  private getScheduleDataByIds;
@@ -361,7 +361,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
361
361
  count: number;
362
362
  left: number;
363
363
  summaryCount: number;
364
- status: "sold_out" | "lots_of_space" | "filling_up_fast";
364
+ status: "lots_of_space" | "filling_up_fast" | "sold_out";
365
365
  }[];
366
366
  /**
367
367
  * 找到多个资源的公共可用时间段
@@ -389,7 +389,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
389
389
  };
390
390
  setOtherData(key: string, value: any): void;
391
391
  getOtherData(key: string): any;
392
- getProductTypeById(id: number): Promise<"normal" | "session" | "duration">;
392
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
393
393
  /**
394
394
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
395
395
  *
@@ -295,7 +295,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
295
295
  private getCustomerContactOrderKey;
296
296
  replaceTempOrder(...args: Parameters<BaseSalesImpl['replaceTempOrder']>): Promise<import("../../modules/Order/types").OrderTempOrder>;
297
297
  private applyDefaultOrderCustomerContactInfo;
298
- private withAccountNameFallback;
298
+ private withAccountContactFallback;
299
299
  private prefillOrderCustomerContactInfo;
300
300
  protected waitForOrderCustomerContactInfo(): Promise<void>;
301
301
  validateContactInfo(): Promise<void>;
@@ -1168,18 +1168,35 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1168
1168
  tempOrder: this.getTempOrder()
1169
1169
  });
1170
1170
  }
1171
- withAccountNameFallback(contact, customer) {
1171
+ withAccountContactFallback(contact, customer) {
1172
1172
  let next = contact;
1173
- // Saved booking contacts take precedence. Only missing name fields fall back
1174
- // to the account profile; phone/email keep their existing contact-info source.
1175
- for (const field of ['first_name', 'last_name']) {
1173
+ // Saved booking contacts take precedence. Fill only missing fields from the
1174
+ // account, without mutating its profile or replacing an existing contact number.
1175
+ for (const field of ['first_name', 'last_name', 'email']) {
1176
1176
  if (typeof contact?.[field] === 'string' && contact[field].trim()) continue;
1177
- const name = customer[field];
1178
- if (typeof name !== 'string' || !name.trim()) continue;
1177
+ const value = customer[field];
1178
+ if (typeof value !== 'string' || !value.trim()) continue;
1179
1179
  if (next === contact) next = {
1180
1180
  ...contact
1181
1181
  };
1182
- next[field] = name.trim();
1182
+ next[field] = value.trim();
1183
+ }
1184
+ const phone = (0, _contactInfo.isContactRecord)(contact?.phone) ? contact.phone : null;
1185
+ if (!(typeof phone?.phone === 'string' && phone.phone.trim()) && typeof customer.phone === 'string' && customer.phone.trim()) {
1186
+ // The account number must travel with its own dialing code, not an empty
1187
+ // contact form's default country (for example AU for a +86 login number).
1188
+ const accountPhone = {
1189
+ ...phone,
1190
+ phone: customer.phone.trim()
1191
+ };
1192
+ for (const field of ['country_calling_code', 'country_code']) {
1193
+ const value = customer[field];
1194
+ accountPhone[field] = typeof value === 'string' || typeof value === 'number' ? String(value).trim() : '';
1195
+ }
1196
+ next = {
1197
+ ...next,
1198
+ phone: accountPhone
1199
+ };
1183
1200
  }
1184
1201
  return next;
1185
1202
  }
@@ -1193,13 +1210,13 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1193
1210
  const contact = order.contacts_info ?? (0, _contactInfo.extractCustomerContactInfo)(customer);
1194
1211
  if (contact) {
1195
1212
  this.orderCustomerContactRequest = null;
1196
- const next = this.withAccountNameFallback(contact, customer);
1213
+ const next = this.withAccountContactFallback(contact, customer);
1197
1214
  if (next !== order.contacts_info) void this.applyDefaultOrderCustomerContactInfo(next);
1198
1215
  return;
1199
1216
  }
1200
1217
  // A relation explicitly returned as null is authoritative. Only a missing relation needs fetching.
1201
1218
  if (customer.contacts_info !== undefined) {
1202
- const next = this.withAccountNameFallback(null, customer);
1219
+ const next = this.withAccountContactFallback(null, customer);
1203
1220
  if (next) void this.applyDefaultOrderCustomerContactInfo(next);
1204
1221
  return;
1205
1222
  }
@@ -1228,12 +1245,12 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1228
1245
  }
1229
1246
  // POS and physical Kiosk share the /shop request plugin and current-shop customer resolver.
1230
1247
  const resolved = await this.resolveCustomerById(customerId);
1231
- return resolved && Number(resolved.id) === customerId ? this.withAccountNameFallback((0, _contactInfo.extractCustomerContactInfo)(resolved), resolved) : null;
1248
+ return resolved && Number(resolved.id) === customerId ? this.withAccountContactFallback((0, _contactInfo.extractCustomerContactInfo)(resolved), resolved) : null;
1232
1249
  };
1233
1250
  pending.promise = loadContact().then(async value => {
1234
1251
  const current = this.getTempOrder();
1235
1252
  if (this.orderCustomerContactRequest !== pending || this.getCustomerContactOrderKey() !== orderKey || Number(current?.customer_id) !== customerId || scope !== this.getCustomerContactScope() || current?._extend?.contactInfoEdited || current?.contacts_info != null || userPlatform && getAuthenticatedCustomerId() !== customerId) return;
1236
- const next = this.withAccountNameFallback(value, customer);
1253
+ const next = this.withAccountContactFallback(value, customer);
1237
1254
  if (next) await this.applyDefaultOrderCustomerContactInfo(next);
1238
1255
  }).catch(() => {
1239
1256
  // A failed default does not prevent manual entry; a subsequent sync can retry.
@@ -25,11 +25,16 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
25
25
  notes?: import("../../../modules/Order/types").SalesNote[] | undefined;
26
26
  summary?: import("../../../modules/Order/types").OrderSummary | undefined;
27
27
  small_ticket_data_flag?: number | undefined;
28
- metadata: Record<string, any>;
29
28
  type: string;
30
- note: string;
29
+ metadata: Record<string, any>;
31
30
  holder: Record<string, any> | null;
32
- relation_forms: any[];
31
+ note: string;
32
+ status: string;
33
+ bookings: any[];
34
+ payments: any[];
35
+ contacts_info: Record<string, any> | null;
36
+ order_meta_list?: import("../../../modules/Order/types").OrderMetaList | undefined;
37
+ refunds?: any[] | undefined;
33
38
  holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
34
39
  order_id: number | null;
35
40
  external_sale_number: string;
@@ -39,7 +44,6 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
39
44
  business_code?: string | undefined;
40
45
  sales_channel: string;
41
46
  order_sales_channel: string;
42
- status: string;
43
47
  shipping_status: string;
44
48
  customer_id: number | null;
45
49
  customer_name: string;
@@ -60,13 +64,9 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
60
64
  delivery_type?: string | undefined;
61
65
  table_number?: Record<string, any> | undefined;
62
66
  schedule_date: string;
63
- bookings: any[];
64
- payments: any[];
65
- refunds?: any[] | undefined;
66
67
  surcharges: any[];
68
+ relation_forms: any[];
67
69
  contacts: any[];
68
- contacts_info: Record<string, any> | null;
69
- order_meta_list?: import("../../../modules/Order/types").OrderMetaList | undefined;
70
70
  };
71
71
  export declare function describeChangedBookings(before: OrderTempOrder['bookings'], after: OrderTempOrder['bookings']): {
72
72
  schedule_event_id: any;
@@ -10,8 +10,6 @@ exports.CheckoutImpl = void 0;
10
10
  var _BaseModule = require("../../modules/BaseModule");
11
11
  var _decimal = _interopRequireDefault(require("decimal.js"));
12
12
  var _Order = require("../../modules/Order");
13
- var _bookingUuid = require("../../modules/Order/utils/bookingUuid");
14
- var _orderCollectionIdentity = require("../../modules/Order/utils/orderCollectionIdentity");
15
13
  var _Payment = require("../../modules/Payment");
16
14
  var _types = require("./types");
17
15
  Object.keys(_types).forEach(function (key) {
@@ -460,7 +458,6 @@ class CheckoutImpl extends _BaseModule.BaseModule {
460
458
  params.orderData.tax_fee = params.totalInfo?.total?.tax;
461
459
 
462
460
  // 保存原始订单数据和小计数据到状态中
463
- params.orderData.bookings?.forEach(_bookingUuid.assignBookingUuid);
464
461
  this.store.localOrderData = params.orderData;
465
462
  this.store.cartSummary = params.cartSummary;
466
463
 
@@ -593,24 +590,6 @@ class CheckoutImpl extends _BaseModule.BaseModule {
593
590
  // 保留原有支付项:通过 orderId 找到现有订单(按 id 或 order_id 匹配)
594
591
  const allOrders = await this.payment.getOrderListAsync();
595
592
  const existingOrder = allOrders.find(o => String(o.id) === String(params.orderId) || String(o.order_id) === String(params.orderId));
596
-
597
- // POS 再次保存会重建预约行;按已有行标识复用上次保存的 UUID。
598
- const previousBookings = existingOrder?.order_info?.original_order_data?.bookings;
599
- const previousUuids = new Map();
600
- if (Array.isArray(previousBookings)) {
601
- for (const booking of previousBookings) {
602
- const uid = (0, _orderCollectionIdentity.getOrderCollectionUid)('booking', booking);
603
- if (uid && booking.uuid !== undefined) previousUuids.set(uid, booking.uuid);
604
- }
605
- }
606
- for (const booking of params.orderData.bookings || []) {
607
- const uid = (0, _orderCollectionIdentity.getOrderCollectionUid)('booking', booking);
608
- if (uid && previousUuids.has(uid)) {
609
- booking.uuid ?? (booking.uuid = previousUuids.get(uid));
610
- previousUuids.delete(uid);
611
- }
612
- (0, _bookingUuid.assignBookingUuid)(booking);
613
- }
614
593
  if (existingOrder) {
615
594
  // 🔧 新增: 如果传入了 existPayment,需要更新支付项列表
616
595
  if (params.existPayment && params.existPayment.length > 0) {
@@ -149,7 +149,6 @@ export interface LocalOrderData {
149
149
  * 本地预订项
150
150
  */
151
151
  export interface LocalBookingItem {
152
- uuid?: string | null;
153
152
  /** ID */
154
153
  id: number;
155
154
  /** 数量 */
@@ -98,6 +98,7 @@ export declare class ScanOrderImpl extends BaseSalesImpl implements Module {
98
98
  private findReservationRuleResource;
99
99
  private buildScanOrderResourceMetadata;
100
100
  private prepareRetailAvailability;
101
+ private getShopTime;
101
102
  private buildSubmitPayloadEnhancer;
102
103
  private isScanOrderMoreMode;
103
104
  private submitScanOrderMore;
@@ -29,7 +29,7 @@ var _types4 = require("../BookingByStep/types");
29
29
  var _ProductList = require("../../modules/ProductList");
30
30
  var _getDateIsInSchedule = require("../../modules/Schedule/getDateIsInSchedule");
31
31
  var _utils2 = require("../../modules/Order/utils");
32
- var _dayjs = _interopRequireDefault(require("dayjs"));
32
+ var _shopTime = require("./shopTime");
33
33
  var _itemRule = require("../../model/strategy/adapter/itemRule");
34
34
  var _menuAvailability = require("./menuAvailability");
35
35
  var _additionalOrderPayload = require("./additionalOrderPayload");
@@ -797,6 +797,9 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
797
797
  });
798
798
  return availabilityInfo;
799
799
  }
800
+ getShopTime(instant = new Date()) {
801
+ return (0, _shopTime.createScanOrderShopClock)(String(this.getPickupTimingContextData('timezone') ?? ''))(instant);
802
+ }
800
803
 
801
804
  // ScanOrder 提交 payload enhancer:
802
805
  // - 新单有桌台上下文但无 booking 时,补建基础预约(通用 Order 已不再自动生成)
@@ -876,28 +879,25 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
876
879
  const ruleProductUid = ruleProduct ? (0, _utils2.createUuidV4)() : undefined;
877
880
  const bookingCapacityDimensionId = (0, _utils.pickFirstCustomCapacityDimensionId)(this.enabledReservationRuleProducts) ?? 0;
878
881
  let bookings = payload.bookings || [];
882
+ let scheduleDate = payload.schedule_date;
879
883
  if (!tempOrder.order_id && bookings.length === 0) {
880
- const extend = tempOrder._extend ?? (tempOrder._extend = {});
881
- if (!extend.scanOrderBookingUuid) {
882
- extend.scanOrderBookingUuid = (0, _utils2.createUuidV4)();
883
- this.store.order?.persistTempOrder?.();
884
- }
885
- const bookingStart = (0, _dayjs.default)(now);
884
+ const bookingStart = this.getShopTime(now);
886
885
  const bookingDuration = (0, _utils2.resolveTableOccupancyDuration)(tempOrder);
887
- const bookingEnd = bookingStart.add(bookingDuration, 'minute');
886
+ // Add elapsed minutes before formatting both ends so DST changes are respected.
887
+ const bookingEnd = this.getShopTime(new Date(now.getTime() + bookingDuration * 60_000));
888
+ scheduleDate = bookingStart.dateTime;
888
889
  bookings = [(0, _utils2.normalizeSubmitBooking)({
889
- uuid: extend.scanOrderBookingUuid,
890
890
  relation_id: 0,
891
891
  form_id: 0,
892
- start_time: bookingStart.format('HH:mm'),
893
- start_date: bookingStart.format('YYYY-MM-DD'),
894
- end_time: bookingEnd.format('HH:mm'),
895
- end_date: bookingEnd.format('YYYY-MM-DD'),
892
+ start_time: bookingStart.time,
893
+ start_date: bookingStart.date,
894
+ end_time: bookingEnd.time,
895
+ end_date: bookingEnd.date,
896
896
  duration: bookingDuration,
897
897
  metadata: {
898
898
  unique_identification_number: bookingUuid
899
899
  },
900
- select_date: bookingStart.format('YYYY-MM-DD'),
900
+ select_date: bookingStart.date,
901
901
  is_all: false,
902
902
  like_status: 'common',
903
903
  schedule_id: 0,
@@ -967,6 +967,7 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
967
967
  }
968
968
  return {
969
969
  ...payload,
970
+ schedule_date: scheduleDate,
970
971
  bookings: nextBookings,
971
972
  products: nextProducts
972
973
  };
@@ -1760,7 +1761,7 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
1760
1761
  if (operatingHourIds.length && this.store.schedule) {
1761
1762
  const scheduleList = this.store.schedule.getScheduleListByIds(operatingHourIds);
1762
1763
  if (scheduleList.length) {
1763
- const now = (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss');
1764
+ const now = this.getShopTime().dateTime;
1764
1765
  outsideOperatingHours = !(0, _getDateIsInSchedule.getDateIsInSchedule)(now, scheduleList);
1765
1766
  }
1766
1767
  }
@@ -1800,8 +1801,10 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
1800
1801
  cacheId: this.cacheId
1801
1802
  }
1802
1803
  });
1803
- const scheduleDate = (0, _dayjs.default)().format('YYYY-MM-DD');
1804
- const scheduleDatetime = (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss');
1804
+ const {
1805
+ date: scheduleDate,
1806
+ dateTime: scheduleDatetime
1807
+ } = this.getShopTime();
1805
1808
  const loaded = await reservationProductList.loadProducts({
1806
1809
  product_ids: reservationLinkIds,
1807
1810
  schedule_date: scheduleDate,
@@ -2032,11 +2035,15 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
2032
2035
  const menu_list_ids = associatedMenus.map(n => Number(n.value)) || [];
2033
2036
  try {
2034
2037
  if (!this.store.products) throw new Error('products 模块未初始化');
2038
+ const {
2039
+ date,
2040
+ dateTime
2041
+ } = this.getShopTime();
2035
2042
  const res = await this.store.products.loadProducts({
2036
2043
  menu_list_ids,
2037
2044
  cacheId: this.cacheId,
2038
- schedule_date: (0, _dayjs.default)().format('YYYY-MM-DD'),
2039
- schedule_datetime: (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss')
2045
+ schedule_date: date,
2046
+ schedule_datetime: dateTime
2040
2047
  });
2041
2048
  const productList = this.assertProductListLoaded('getProductList', res, {
2042
2049
  menu_list_ids,
@@ -7,6 +7,7 @@ exports.ScanOrderMenuAvailabilityError = void 0;
7
7
  exports.prepareScanOrderMenuAvailability = prepareScanOrderMenuAvailability;
8
8
  var _utils = require("../ShopDiscount/utils");
9
9
  var _dayjs = _interopRequireDefault(require("dayjs"));
10
+ var _shopTime = require("./shopTime");
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12
  class ScanOrderMenuAvailabilityError extends Error {
12
13
  code;
@@ -78,24 +79,6 @@ function validateSchedule(schedule) {
78
79
  }
79
80
  if (schedule.repeat_type === 'weekly' && (!Array.isArray(rule.frequency_date) || rule.frequency_date.some(day => typeof day !== 'number' || !Number.isInteger(day) || day < 0 || day > 6))) return fail();
80
81
  }
81
- function createShopClock(timezone) {
82
- if (typeof timezone !== 'string' || !timezone.trim()) return fail();
83
- const formatter = new Intl.DateTimeFormat('en-GB', {
84
- timeZone: timezone.trim(),
85
- year: 'numeric',
86
- month: '2-digit',
87
- day: '2-digit',
88
- hour: '2-digit',
89
- minute: '2-digit',
90
- second: '2-digit',
91
- hourCycle: 'h23'
92
- });
93
- return () => {
94
- const parts = formatter.formatToParts(new Date());
95
- const value = type => parts.find(part => part.type === type)?.value;
96
- return `${value('year')}-${value('month')}-${value('day')} ${value('hour')}:${value('minute')}:${value('second')}`;
97
- };
98
- }
99
82
  function collectSources(target, sources) {
100
83
  for (const source of sources) {
101
84
  const id = productId(source);
@@ -120,7 +103,7 @@ async function prepareScanOrderMenuAvailability({
120
103
  }) {
121
104
  const initialIds = products.filter(product => !isReservationRuleProduct(product)).map(productId).filter(id => id !== undefined);
122
105
  try {
123
- const now = createShopClock(timezone);
106
+ const now = (0, _shopTime.createScanOrderShopClock)(timezone);
124
107
  const configuredIds = readIds(menuIds);
125
108
  const [menuResponse, scheduleResponse] = await Promise.all([request.get('/form/data/v1', {
126
109
  skip: 1,
@@ -170,7 +153,7 @@ async function prepareScanOrderMenuAvailability({
170
153
  }
171
154
  return (currentProducts, currentSources = []) => {
172
155
  try {
173
- const currentTime = now();
156
+ const currentTime = now().dateTime;
174
157
  const collections = new Map(collectionsByProduct);
175
158
  collectSources(collections, [...currentProducts, ...currentSources]);
176
159
  const unavailable = [];
@@ -0,0 +1,6 @@
1
+ /** Format absolute instants as the shop's calendar fields, independent of the device timezone. */
2
+ export declare function createScanOrderShopClock(timezone: string): (instant?: Date) => {
3
+ date: string;
4
+ time: string;
5
+ dateTime: string;
6
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createScanOrderShopClock = createScanOrderShopClock;
7
+ /** Format absolute instants as the shop's calendar fields, independent of the device timezone. */
8
+ function createScanOrderShopClock(timezone) {
9
+ const message = 'Unable to determine store time. Please refresh and try again.';
10
+ let formatter;
11
+ try {
12
+ if (typeof timezone !== 'string' || !timezone.trim()) throw new Error(message);
13
+ formatter = new Intl.DateTimeFormat('en-GB', {
14
+ timeZone: timezone.trim(),
15
+ year: 'numeric',
16
+ month: '2-digit',
17
+ day: '2-digit',
18
+ hour: '2-digit',
19
+ minute: '2-digit',
20
+ second: '2-digit',
21
+ hourCycle: 'h23'
22
+ });
23
+ } catch {
24
+ throw new Error(message);
25
+ }
26
+ return (instant = new Date()) => {
27
+ const parts = formatter.formatToParts(instant);
28
+ const value = type => parts.find(part => part.type === type).value;
29
+ const date = `${value('year')}-${value('month')}-${value('day')}`;
30
+ const time = `${value('hour')}:${value('minute')}`;
31
+ return {
32
+ date,
33
+ time,
34
+ dateTime: `${date} ${time}:${value('second')}`
35
+ };
36
+ };
37
+ }