@pisell/pisellos 2.3.229 → 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 (37) 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/type.d.ts +10 -2
  4. package/dist/modules/Order/index.d.ts +1 -1
  5. package/dist/modules/Order/index.js +1371 -1234
  6. package/dist/modules/Order/types.d.ts +13 -34
  7. package/dist/modules/Order/types.js +2 -0
  8. package/dist/modules/Summary/utils.d.ts +1 -1
  9. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -18
  10. package/dist/solution/BaseSales/utils/cartPromotion.js +252 -168
  11. package/dist/solution/BookingTicket/index.d.ts +2 -2
  12. package/dist/solution/BookingTicket/index.js +45 -21
  13. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +10 -10
  14. package/dist/solution/ScanOrder/index.d.ts +1 -0
  15. package/dist/solution/ScanOrder/index.js +52 -38
  16. package/dist/solution/ScanOrder/menuAvailability.js +3 -25
  17. package/dist/solution/ScanOrder/shopTime.d.ts +6 -0
  18. package/dist/solution/ScanOrder/shopTime.js +36 -0
  19. package/lib/model/strategy/adapter/promotion/adapter.js +10 -1
  20. package/lib/model/strategy/adapter/promotion/evaluator.js +18 -6
  21. package/lib/model/strategy/adapter/promotion/type.d.ts +10 -2
  22. package/lib/modules/Order/index.d.ts +1 -1
  23. package/lib/modules/Order/index.js +103 -32
  24. package/lib/modules/Order/types.d.ts +13 -34
  25. package/lib/modules/Order/types.js +1 -0
  26. package/lib/modules/Summary/utils.d.ts +1 -1
  27. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -18
  28. package/lib/solution/BaseSales/utils/cartPromotion.js +87 -40
  29. package/lib/solution/BookingTicket/index.d.ts +2 -2
  30. package/lib/solution/BookingTicket/index.js +28 -11
  31. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +10 -10
  32. package/lib/solution/ScanOrder/index.d.ts +1 -0
  33. package/lib/solution/ScanOrder/index.js +26 -13
  34. package/lib/solution/ScanOrder/menuAvailability.js +3 -20
  35. package/lib/solution/ScanOrder/shopTime.d.ts +6 -0
  36. package/lib/solution/ScanOrder/shopTime.js +37 -0
  37. package/package.json +1 -1
@@ -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,17 +25,25 @@ 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
+ type: string;
28
29
  metadata: Record<string, any>;
30
+ holder: Record<string, any> | null;
29
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;
38
+ holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
30
39
  order_id: number | null;
40
+ external_sale_number: string;
31
41
  order_number: string | null;
32
42
  shop_order_number: string | null;
33
43
  shop_full_order_number: string | null;
34
- type: string;
35
44
  business_code?: string | undefined;
36
45
  sales_channel: string;
37
46
  order_sales_channel: string;
38
- status: string;
39
47
  shipping_status: string;
40
48
  customer_id: number | null;
41
49
  customer_name: string;
@@ -56,17 +64,9 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
56
64
  delivery_type?: string | undefined;
57
65
  table_number?: Record<string, any> | undefined;
58
66
  schedule_date: string;
59
- bookings: any[];
60
- payments: any[];
61
67
  surcharges: any[];
62
68
  relation_forms: any[];
63
69
  contacts: any[];
64
- contacts_info: Record<string, any> | null;
65
- holder: Record<string, any> | null;
66
- external_sale_number: string;
67
- holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
68
- refunds?: any[] | undefined;
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;
@@ -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,22 +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 bookingStart = (0, _dayjs.default)(now);
884
+ const bookingStart = this.getShopTime(now);
881
885
  const bookingDuration = (0, _utils2.resolveTableOccupancyDuration)(tempOrder);
882
- 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;
883
889
  bookings = [(0, _utils2.normalizeSubmitBooking)({
884
890
  relation_id: 0,
885
891
  form_id: 0,
886
- start_time: bookingStart.format('HH:mm'),
887
- start_date: bookingStart.format('YYYY-MM-DD'),
888
- end_time: bookingEnd.format('HH:mm'),
889
- 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,
890
896
  duration: bookingDuration,
891
897
  metadata: {
892
898
  unique_identification_number: bookingUuid
893
899
  },
894
- select_date: bookingStart.format('YYYY-MM-DD'),
900
+ select_date: bookingStart.date,
895
901
  is_all: false,
896
902
  like_status: 'common',
897
903
  schedule_id: 0,
@@ -961,6 +967,7 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
961
967
  }
962
968
  return {
963
969
  ...payload,
970
+ schedule_date: scheduleDate,
964
971
  bookings: nextBookings,
965
972
  products: nextProducts
966
973
  };
@@ -1754,7 +1761,7 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
1754
1761
  if (operatingHourIds.length && this.store.schedule) {
1755
1762
  const scheduleList = this.store.schedule.getScheduleListByIds(operatingHourIds);
1756
1763
  if (scheduleList.length) {
1757
- const now = (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss');
1764
+ const now = this.getShopTime().dateTime;
1758
1765
  outsideOperatingHours = !(0, _getDateIsInSchedule.getDateIsInSchedule)(now, scheduleList);
1759
1766
  }
1760
1767
  }
@@ -1794,8 +1801,10 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
1794
1801
  cacheId: this.cacheId
1795
1802
  }
1796
1803
  });
1797
- const scheduleDate = (0, _dayjs.default)().format('YYYY-MM-DD');
1798
- const scheduleDatetime = (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss');
1804
+ const {
1805
+ date: scheduleDate,
1806
+ dateTime: scheduleDatetime
1807
+ } = this.getShopTime();
1799
1808
  const loaded = await reservationProductList.loadProducts({
1800
1809
  product_ids: reservationLinkIds,
1801
1810
  schedule_date: scheduleDate,
@@ -2026,11 +2035,15 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
2026
2035
  const menu_list_ids = associatedMenus.map(n => Number(n.value)) || [];
2027
2036
  try {
2028
2037
  if (!this.store.products) throw new Error('products 模块未初始化');
2038
+ const {
2039
+ date,
2040
+ dateTime
2041
+ } = this.getShopTime();
2029
2042
  const res = await this.store.products.loadProducts({
2030
2043
  menu_list_ids,
2031
2044
  cacheId: this.cacheId,
2032
- schedule_date: (0, _dayjs.default)().format('YYYY-MM-DD'),
2033
- schedule_datetime: (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss')
2045
+ schedule_date: date,
2046
+ schedule_datetime: dateTime
2034
2047
  });
2035
2048
  const productList = this.assertProductListLoaded('getProductList', res, {
2036
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
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.229",
4
+ "version": "2.3.231",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",