@pisell/pisellos 2.3.95 → 2.3.97

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 (29) hide show
  1. package/dist/model/strategy/adapter/dataVariant/evaluator.js +13 -2
  2. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  3. package/dist/modules/Order/index.d.ts +2 -0
  4. package/dist/modules/Order/index.js +51 -28
  5. package/dist/modules/SalesSummary/index.js +6 -4
  6. package/dist/server/index.js +14 -8
  7. package/dist/server/modules/products/index.d.ts +2 -2
  8. package/dist/server/modules/products/index.js +10 -9
  9. package/dist/server/utils/product.d.ts +1 -1
  10. package/dist/server/utils/product.js +186 -22
  11. package/dist/server/utils/small-ticket.d.ts +9 -1
  12. package/dist/server/utils/small-ticket.js +136 -41
  13. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  14. package/dist/solution/BookingByStep/index.d.ts +2 -2
  15. package/lib/model/strategy/adapter/dataVariant/evaluator.js +12 -2
  16. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  17. package/lib/modules/Order/index.d.ts +2 -0
  18. package/lib/modules/Order/index.js +33 -14
  19. package/lib/modules/SalesSummary/index.js +3 -1
  20. package/lib/server/index.js +10 -6
  21. package/lib/server/modules/products/index.d.ts +2 -2
  22. package/lib/server/modules/products/index.js +5 -4
  23. package/lib/server/utils/product.d.ts +1 -1
  24. package/lib/server/utils/product.js +163 -3
  25. package/lib/server/utils/small-ticket.d.ts +9 -1
  26. package/lib/server/utils/small-ticket.js +126 -33
  27. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  28. package/lib/solution/BookingByStep/index.d.ts +2 -2
  29. package/package.json +1 -1
@@ -1,4 +1,3 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
1
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
2
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -6,6 +5,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
6
5
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
6
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9
9
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
11
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -195,9 +195,120 @@ var I18N_FIELD_MAP = {
195
195
  description_i18n: 'description',
196
196
  cover_i18n: 'cover'
197
197
  };
198
+ /**
199
+ * 按当前语言读取 i18n 文案;当前语言为空时回退到商家原始文案。
200
+ */
201
+ function resolveI18nValue(i18nDict, locale) {
202
+ if (!i18nDict) return undefined;
203
+ return i18nDict[locale] || i18nDict.original || undefined;
204
+ }
205
+
206
+ /**
207
+ * 递归格式化商品分类名称,同时保留未变化节点的引用。
208
+ */
209
+ function applyI18nToCategory(category, locale) {
210
+ if (!category || _typeof(category) !== 'object') return category;
211
+ var localizedName = resolveI18nValue(category.name_i18n, locale);
212
+ var localizedParent = applyI18nToCategory(category.parent_category, locale);
213
+ var nameChanged = localizedName !== undefined && localizedName !== category.name;
214
+ var parentChanged = localizedParent !== category.parent_category;
215
+ if (!nameChanged && !parentChanged) return category;
216
+ return _objectSpread(_objectSpread(_objectSpread({}, category), nameChanged ? {
217
+ name: localizedName
218
+ } : {}), parentChanged ? {
219
+ parent_category: localizedParent
220
+ } : {});
221
+ }
222
+ function applyI18nToCategories(categories, locale) {
223
+ if (!Array.isArray(categories)) return categories;
224
+ var changed = false;
225
+ var localizedCategories = categories.map(function (category) {
226
+ var localizedCategory = applyI18nToCategory(category, locale);
227
+ if (localizedCategory !== category) changed = true;
228
+ return localizedCategory;
229
+ });
230
+ return changed ? localizedCategories : categories;
231
+ }
232
+ function applyI18nToNamedItems(items, locale) {
233
+ if (!Array.isArray(items)) return items;
234
+ var changed = false;
235
+ var localizedItems = items.map(function (item) {
236
+ if (!item || _typeof(item) !== 'object') return item;
237
+ var localizedName = resolveI18nValue(item.name_i18n, locale);
238
+ if (localizedName === undefined || localizedName === item.name) return item;
239
+ changed = true;
240
+ return _objectSpread(_objectSpread({}, item), {}, {
241
+ name: localizedName
242
+ });
243
+ });
244
+ return changed ? localizedItems : items;
245
+ }
246
+
247
+ /**
248
+ * 格式化选项组、规格组及其子项名称,同时保留未变化节点的引用。
249
+ */
250
+ function applyI18nToNamedGroups(groups, itemKey, locale) {
251
+ if (!Array.isArray(groups)) return groups;
252
+ var changed = false;
253
+ var localizedGroups = groups.map(function (group) {
254
+ if (!group || _typeof(group) !== 'object') return group;
255
+ var localizedName = resolveI18nValue(group.name_i18n, locale);
256
+ var localizedItems = applyI18nToNamedItems(group[itemKey], locale);
257
+ var nameChanged = localizedName !== undefined && localizedName !== group.name;
258
+ var itemsChanged = localizedItems !== group[itemKey];
259
+ if (!nameChanged && !itemsChanged) return group;
260
+ changed = true;
261
+ return _objectSpread(_objectSpread(_objectSpread({}, group), nameChanged ? {
262
+ name: localizedName
263
+ } : {}), itemsChanged ? _defineProperty({}, itemKey, localizedItems) : {});
264
+ });
265
+ return changed ? localizedGroups : groups;
266
+ }
267
+ function applyI18nToBundleItems(items, locale) {
268
+ if (!Array.isArray(items)) return items;
269
+ var changed = false;
270
+ var localizedItems = items.map(function (item) {
271
+ if (!item || _typeof(item) !== 'object') return item;
272
+ var localizedTitle = resolveI18nValue(item.trans_title, locale);
273
+ var localizedOptionGroups = applyI18nToNamedGroups(item.option_group, 'option_item', locale);
274
+ var titleChanged = localizedTitle !== undefined && localizedTitle !== item.title;
275
+ var optionGroupsChanged = localizedOptionGroups !== item.option_group;
276
+ if (!titleChanged && !optionGroupsChanged) return item;
277
+ changed = true;
278
+ return _objectSpread(_objectSpread(_objectSpread({}, item), titleChanged ? {
279
+ title: localizedTitle
280
+ } : {}), optionGroupsChanged ? {
281
+ option_group: localizedOptionGroups
282
+ } : {});
283
+ });
284
+ return changed ? localizedItems : items;
285
+ }
198
286
 
199
287
  /**
200
- * 根据 locale 将商品的 i18n 字段覆盖到对应原始字段
288
+ * 格式化套餐组名称、套餐子商品标题及子商品选项,同时保留未变化节点的引用。
289
+ */
290
+ function applyI18nToBundleGroups(groups, locale) {
291
+ if (!Array.isArray(groups)) return groups;
292
+ var changed = false;
293
+ var localizedGroups = groups.map(function (group) {
294
+ if (!group || _typeof(group) !== 'object') return group;
295
+ var localizedName = resolveI18nValue(group.name_i18n, locale);
296
+ var localizedItems = applyI18nToBundleItems(group.bundle_item, locale);
297
+ var nameChanged = localizedName !== undefined && localizedName !== group.name;
298
+ var itemsChanged = localizedItems !== group.bundle_item;
299
+ if (!nameChanged && !itemsChanged) return group;
300
+ changed = true;
301
+ return _objectSpread(_objectSpread(_objectSpread({}, group), nameChanged ? {
302
+ name: localizedName
303
+ } : {}), itemsChanged ? {
304
+ bundle_item: localizedItems
305
+ } : {});
306
+ });
307
+ return changed ? localizedGroups : groups;
308
+ }
309
+
310
+ /**
311
+ * 根据 locale 格式化商品、分类、规格及套餐文案,缺少对应语言时回退 original。
201
312
  */
202
313
  export function applyI18nToProducts(products, locale) {
203
314
  if (!locale) return products;
@@ -210,12 +321,65 @@ export function applyI18nToProducts(products, locale) {
210
321
  originalKey = _Object$entries$_i[1];
211
322
  var i18nDict = product[i18nKey];
212
323
  if (!i18nDict) continue;
213
- var localizedValue = i18nDict[locale];
214
- if (localizedValue) {
324
+ var localizedValue = resolveI18nValue(i18nDict, locale);
325
+ if (localizedValue !== undefined && localizedValue !== product[originalKey]) {
215
326
  if (!patched) patched = _objectSpread({}, product);
216
327
  patched[originalKey] = localizedValue;
217
328
  }
218
329
  }
330
+ var _iterator = _createForOfIteratorHelper(['category', 'categories']),
331
+ _step;
332
+ try {
333
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
334
+ var categoryKey = _step.value;
335
+ var categories = product[categoryKey];
336
+ var localizedCategories = applyI18nToCategories(categories, locale);
337
+ if (localizedCategories !== categories) {
338
+ if (!patched) patched = _objectSpread({}, product);
339
+ patched[categoryKey] = localizedCategories;
340
+ }
341
+ }
342
+ } catch (err) {
343
+ _iterator.e(err);
344
+ } finally {
345
+ _iterator.f();
346
+ }
347
+ var _iterator2 = _createForOfIteratorHelper([['option_group', 'option_item'], ['variant_group', 'variant_item']]),
348
+ _step2;
349
+ try {
350
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
351
+ var _step2$value = _slicedToArray(_step2.value, 2),
352
+ groupKey = _step2$value[0],
353
+ itemKey = _step2$value[1];
354
+ var groups = product[groupKey];
355
+ var localizedGroups = applyI18nToNamedGroups(groups, itemKey, locale);
356
+ if (localizedGroups !== groups) {
357
+ if (!patched) patched = _objectSpread({}, product);
358
+ patched[groupKey] = localizedGroups;
359
+ }
360
+ }
361
+ } catch (err) {
362
+ _iterator2.e(err);
363
+ } finally {
364
+ _iterator2.f();
365
+ }
366
+ var _iterator3 = _createForOfIteratorHelper(['bundle_group', 'bundle_groups']),
367
+ _step3;
368
+ try {
369
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
370
+ var bundleGroupKey = _step3.value;
371
+ var _groups = product[bundleGroupKey];
372
+ var _localizedGroups = applyI18nToBundleGroups(_groups, locale);
373
+ if (_localizedGroups !== _groups) {
374
+ if (!patched) patched = _objectSpread({}, product);
375
+ patched[bundleGroupKey] = _localizedGroups;
376
+ }
377
+ }
378
+ } catch (err) {
379
+ _iterator3.e(err);
380
+ } finally {
381
+ _iterator3.f();
382
+ }
219
383
  return (_patched = patched) !== null && _patched !== void 0 ? _patched : product;
220
384
  });
221
385
  }
@@ -234,54 +398,54 @@ var formatDataKey = function formatDataKey(data) {
234
398
 
235
399
  // 单规格
236
400
  if (_data !== null && _data !== void 0 && (_data$option = _data.option) !== null && _data$option !== void 0 && _data$option.length) {
237
- var _iterator = _createForOfIteratorHelper(_data.option),
238
- _step;
401
+ var _iterator4 = _createForOfIteratorHelper(_data.option),
402
+ _step4;
239
403
  try {
240
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
241
- var item = _step.value;
404
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
405
+ var item = _step4.value;
242
406
  var _str = "_".concat(item.option_group_id, "_").concat(item.option_group_item_id);
243
407
  key += _str;
244
408
  rowKey += "".concat(_str, "_").concat(item.quantity || item.num);
245
409
  }
246
410
  } catch (err) {
247
- _iterator.e(err);
411
+ _iterator4.e(err);
248
412
  } finally {
249
- _iterator.f();
413
+ _iterator4.f();
250
414
  }
251
415
  }
252
416
 
253
417
  // 套餐
254
418
  if (_data !== null && _data !== void 0 && (_data$bundle = _data.bundle) !== null && _data$bundle !== void 0 && _data$bundle.length) {
255
- var _iterator2 = _createForOfIteratorHelper(_data.bundle),
256
- _step2;
419
+ var _iterator5 = _createForOfIteratorHelper(_data.bundle),
420
+ _step5;
257
421
  try {
258
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
259
- var _item = _step2.value;
422
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
423
+ var _item = _step5.value;
260
424
  var _str2 = "_".concat(_item.group_id, "_").concat(_item.bundle_product_id);
261
425
  key += _str2;
262
426
  rowKey += "".concat(_str2, "_").concat(_item.quantity || _item.num);
263
427
  // 如果有单规格
264
428
  if (_item !== null && _item !== void 0 && _item.option) {
265
- var _iterator3 = _createForOfIteratorHelper(_item.option),
266
- _step3;
429
+ var _iterator6 = _createForOfIteratorHelper(_item.option),
430
+ _step6;
267
431
  try {
268
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
269
- var opt = _step3.value;
432
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
433
+ var opt = _step6.value;
270
434
  var _str3 = "_".concat(opt.option_group_id, "_").concat(opt.option_group_item_id);
271
435
  key += _str3;
272
436
  rowKey += "".concat(_str3, "_").concat(opt.quantity || opt.num);
273
437
  }
274
438
  } catch (err) {
275
- _iterator3.e(err);
439
+ _iterator6.e(err);
276
440
  } finally {
277
- _iterator3.f();
441
+ _iterator6.f();
278
442
  }
279
443
  }
280
444
  }
281
445
  } catch (err) {
282
- _iterator2.e(err);
446
+ _iterator5.e(err);
283
447
  } finally {
284
- _iterator2.f();
448
+ _iterator5.f();
285
449
  }
286
450
  }
287
451
 
@@ -35,6 +35,8 @@ export interface SmallTicketProduct {
35
35
  original_price: string;
36
36
  total_original_price: string;
37
37
  extension_list: any[];
38
+ product_uid?: string | number;
39
+ booking_uid?: string | number;
38
40
  options?: Array<{
39
41
  name: string;
40
42
  num?: number;
@@ -44,6 +46,11 @@ export interface SmallTicketProduct {
44
46
  variant?: string;
45
47
  combinations?: any[];
46
48
  }
49
+ export interface SmallTicketBookingSnapshot extends Record<string, any> {
50
+ product_uid?: string | number;
51
+ booking_uid?: string | number;
52
+ }
53
+ export type SmallTicketAppointment = SmallTicketItem[] | SmallTicketBookingSnapshot[];
47
54
  export interface SmallTicketLocaleData {
48
55
  base_data: Record<string, any>;
49
56
  products: SmallTicketProduct[];
@@ -52,7 +59,7 @@ export interface SmallTicketLocaleData {
52
59
  countFee: Record<string, any>;
53
60
  };
54
61
  customer: SmallTicketItem[];
55
- appointment: SmallTicketItem[];
62
+ appointment: SmallTicketAppointment;
56
63
  delivery?: SmallTicketItem[];
57
64
  resources: Array<{
58
65
  id: string | number;
@@ -61,6 +68,7 @@ export interface SmallTicketLocaleData {
61
68
  form_title: string;
62
69
  }>;
63
70
  payment_data: SmallTicketItem[][];
71
+ wallets: SmallTicketItem[][];
64
72
  tickets: any[];
65
73
  source_shop: any[];
66
74
  refund_data: any[];
@@ -40,6 +40,7 @@ var LABELS = {
40
40
  orderDiscount: 'Order discount',
41
41
  manualDiscount: 'Manual discount',
42
42
  payProcessingFee: 'Pay processing fee',
43
+ surchargeIncluded: 'Surcharge(Included)',
43
44
  rounding: 'Rounding',
44
45
  gross: 'Gross',
45
46
  tare: 'Tare'
@@ -66,6 +67,7 @@ var LABELS = {
66
67
  orderDiscount: '整单折扣',
67
68
  manualDiscount: '手动折扣',
68
69
  payProcessingFee: '支付手续费',
70
+ surchargeIncluded: '手续费(已含)',
69
71
  rounding: '抹零',
70
72
  gross: '重量',
71
73
  tare: '去皮'
@@ -92,6 +94,7 @@ var LABELS = {
92
94
  orderDiscount: '整單折扣',
93
95
  manualDiscount: '手動折扣',
94
96
  payProcessingFee: '支付手續費',
97
+ surchargeIncluded: '手續費(已含)',
95
98
  rounding: '抹零',
96
99
  gross: '重量',
97
100
  tare: '去皮'
@@ -147,6 +150,11 @@ function buildLocaleData(params) {
147
150
  locale: locale,
148
151
  currencySymbol: currencySymbol
149
152
  }),
153
+ wallets: buildWallets({
154
+ order: order,
155
+ locale: locale,
156
+ currencySymbol: currencySymbol
157
+ }),
150
158
  tickets: Array.isArray(order.tickets) ? order.tickets : [],
151
159
  source_shop: [],
152
160
  refund_data: [],
@@ -159,7 +167,7 @@ function buildBaseData(params) {
159
167
  shopInfo = params.shopInfo,
160
168
  locale = params.locale;
161
169
  var orderNumber = stringify(order.buzzer || order.shop_full_order_number);
162
- return {
170
+ return _objectSpread({
163
171
  shop_name: stringify(shopInfo.name || order.shop_name),
164
172
  note: stringify(order.note),
165
173
  shop_order_number: stringify(order.shop_order_number),
@@ -172,12 +180,14 @@ function buildBaseData(params) {
172
180
  buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
173
181
  order_no: orderNumber,
174
182
  order_time: formatDateTime(order.created_at || order.sales_time || new Date(), locale)
175
- };
183
+ }, isPresentId(order.updated_at) ? {
184
+ updated_at: formatDateTime(order.updated_at, locale)
185
+ } : {});
176
186
  }
177
187
  function buildProducts(order, locale, productMap) {
178
188
  var products = Array.isArray(order.products) ? order.products : [];
179
189
  return products.map(function (product) {
180
- var _ref, _ref2, _product$product_quan, _ref3, _ref4, _ref5, _product$original_pri, _ref6, _ref7, _product$selling_pric, _product$product_id;
190
+ var _ref, _ref2, _product$product_quan, _ref3, _ref4, _ref5, _product$original_pri, _ref6, _ref7, _product$selling_pric, _product$product_id, _product$metadata, _product$metadata2;
181
191
  var quantity = toNumber((_ref = (_ref2 = (_product$product_quan = product.product_quantity) !== null && _product$product_quan !== void 0 ? _product$product_quan : product.quantity) !== null && _ref2 !== void 0 ? _ref2 : product.num) !== null && _ref !== void 0 ? _ref : 1, 1);
182
192
  var originalPrice = (_ref3 = (_ref4 = (_ref5 = (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product.selling_price) !== null && _ref5 !== void 0 ? _ref5 : product.payment_price) !== null && _ref4 !== void 0 ? _ref4 : product.price) !== null && _ref3 !== void 0 ? _ref3 : 0;
183
193
  var sellingPrice = (_ref6 = (_ref7 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.payment_price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : originalPrice;
@@ -206,6 +216,8 @@ function buildProducts(order, locale, productMap) {
206
216
  parentProduct: parentProduct,
207
217
  locale: locale
208
218
  });
219
+ var productUid = firstPresentValue((_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number, product.unique_identification_number);
220
+ var bookingUid = firstPresentValue(product.booking_uid, (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.booking_uid);
209
221
  var extensionList = buildProductExtensionList({
210
222
  product: product,
211
223
  locale: locale,
@@ -213,14 +225,18 @@ function buildProducts(order, locale, productMap) {
213
225
  quantity: quantity,
214
226
  originalPrice: originalPrice
215
227
  });
216
- return _objectSpread(_objectSpread(_objectSpread({
228
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
217
229
  product_title: productTitle,
218
230
  product_quantity: quantity,
219
231
  selling_price: formatMoney(sellingPrice, currencySymbol),
220
232
  original_price: formatMoney(originalPrice, currencySymbol),
221
233
  total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
222
234
  extension_list: extensionList
223
- }, options.length ? {
235
+ }, isPresentId(productUid) ? {
236
+ product_uid: productUid
237
+ } : {}), isPresentId(bookingUid) ? {
238
+ booking_uid: bookingUid
239
+ } : {}), options.length ? {
224
240
  options: options
225
241
  } : {}), resolvedVariant ? {
226
242
  variant: resolvedVariant
@@ -601,6 +617,14 @@ function isNonZeroId(value) {
601
617
  function isPresentId(value) {
602
618
  return value !== undefined && value !== null && value !== '';
603
619
  }
620
+ function firstPresentValue() {
621
+ for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
622
+ values[_key] = arguments[_key];
623
+ }
624
+ return values.find(function (value) {
625
+ return isPresentId(value);
626
+ });
627
+ }
604
628
  function isSameId(left, right) {
605
629
  if (!isPresentId(left) || !isPresentId(right)) return false;
606
630
  return String(left) === String(right);
@@ -625,7 +649,7 @@ function formatBundlePrice(bundle, currencySymbol) {
625
649
  return formatMoney(amount, currencySymbol);
626
650
  }
627
651
  function buildFees(params) {
628
- var _ref36, _order$shop_discount, _ref37, _summary$product_orig;
652
+ var _ref36, _order$shop_discount, _firstPresentValue;
629
653
  var order = params.order,
630
654
  shopInfo = params.shopInfo,
631
655
  locale = params.locale,
@@ -672,12 +696,13 @@ function buildFees(params) {
672
696
  });
673
697
  }
674
698
  var productExpectAmount = summary.product_expect_amount || summary.product_amount || order.product_expect_amount;
675
- var productOriginalAmount = (_ref37 = (_summary$product_orig = summary.product_original_amount) !== null && _summary$product_orig !== void 0 ? _summary$product_orig : order.product_original_amount) !== null && _ref37 !== void 0 ? _ref37 : productExpectAmount;
699
+ var productOriginalAmount = (_firstPresentValue = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : calculateProductOriginalAmount(order);
676
700
  var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
677
701
  return {
678
702
  fees: fees,
679
703
  countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread({
680
704
  total_amount: formatMoney(summary.total_amount || order.total_amount, currencySymbol),
705
+ original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
681
706
  product_expect_amount: formatMoney(productExpectAmount, currencySymbol),
682
707
  expect_amount: formatMoney(summary.expect_amount || order.expect_amount || summary.total_amount || order.total_amount, currencySymbol),
683
708
  product_quantity: toNumber(summary.product_quantity || products.reduce(function (sum, product) {
@@ -698,6 +723,14 @@ function buildFees(params) {
698
723
  } : {})
699
724
  };
700
725
  }
726
+ function calculateProductOriginalAmount(order) {
727
+ return normalizeArray(order.products).reduce(function (total, product) {
728
+ var _ref37, _ref38, _product$product_quan2, _ref39, _ref40, _ref41, _product$original_pri2;
729
+ var quantity = toNumber((_ref37 = (_ref38 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref38 !== void 0 ? _ref38 : product.num) !== null && _ref37 !== void 0 ? _ref37 : 1, 1);
730
+ var originalPrice = (_ref39 = (_ref40 = (_ref41 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref41 !== void 0 ? _ref41 : product.payment_price) !== null && _ref40 !== void 0 ? _ref40 : product.price) !== null && _ref39 !== void 0 ? _ref39 : 0;
731
+ return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
732
+ }, new Decimal(0));
733
+ }
701
734
  function buildCustomer(order, locale) {
702
735
  var _order$customer, _order$customer2, _order$customer3, _order$customer4;
703
736
  return [{
@@ -738,6 +771,22 @@ function buildDelivery(order, locale) {
738
771
  }
739
772
  function buildAppointment(order, locale) {
740
773
  var _order$metadata3, _order$metadata4, _order$form_data;
774
+ var bookings = normalizeArray(order.bookings);
775
+ if (bookings.length) {
776
+ return bookings.map(function (booking) {
777
+ var _booking$metadata, _booking$metadata2;
778
+ var snapshot = _objectSpread({}, booking);
779
+ delete snapshot.product_uid;
780
+ delete snapshot.booking_uid;
781
+ var productUid = firstPresentValue(booking.product_uid, (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.product_uid);
782
+ var bookingUid = firstPresentValue((_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.unique_identification_number, booking.booking_uid);
783
+ return _objectSpread(_objectSpread(_objectSpread({}, snapshot), isPresentId(productUid) ? {
784
+ product_uid: productUid
785
+ } : {}), isPresentId(bookingUid) ? {
786
+ booking_uid: bookingUid
787
+ } : {});
788
+ });
789
+ }
741
790
  var tableName = order.table_name || ((_order$metadata3 = order.metadata) === null || _order$metadata3 === void 0 ? void 0 : _order$metadata3.table_name) || ((_order$metadata4 = order.metadata) === null || _order$metadata4 === void 0 || (_order$metadata4 = _order$metadata4.table) === null || _order$metadata4 === void 0 ? void 0 : _order$metadata4.name) || ((_order$form_data = order.form_data) === null || _order$form_data === void 0 ? void 0 : _order$form_data.table_name);
742
791
  if (!tableName) return [];
743
792
  return [{
@@ -760,41 +809,85 @@ function buildPaymentData(params) {
760
809
  return payments.filter(function (payment) {
761
810
  return isPrintablePayment(payment);
762
811
  }).map(function (payment) {
763
- var _payment$amount;
764
- var items = [{
765
- item: paymentMethodName(payment, params.locale),
766
- value: formatMoney((_payment$amount = payment.amount) !== null && _payment$amount !== void 0 ? _payment$amount : payment.origin_amount, params.currencySymbol)
767
- }];
768
- var fundRecord = getFundRecord(payment);
769
- if (fundRecord) {
770
- items.push.apply(items, _toConsumableArray(buildFundRecordPaymentItems({
771
- payment: payment,
772
- fundRecord: fundRecord,
773
- locale: params.locale,
774
- currencySymbol: params.currencySymbol
775
- })));
776
- } else {
777
- var _ref38, _payment$remaining_am, _payment$metadata;
778
- var remainingAmount = (_ref38 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref38 !== void 0 ? _ref38 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
779
- if (remainingAmount !== undefined && remainingAmount !== null) {
780
- items.push({
781
- item: label(params.locale, 'remainingAmount'),
782
- value: formatMoney(remainingAmount, params.currencySymbol)
783
- });
784
- }
785
- }
812
+ return buildPaymentItems({
813
+ payment: payment,
814
+ locale: params.locale,
815
+ currencySymbol: params.currencySymbol,
816
+ includeFundRecordBalance: false
817
+ });
818
+ });
819
+ }
820
+ function buildWallets(params) {
821
+ return normalizeArray(params.order.payments).filter(function (payment) {
822
+ return isPrintablePayment(payment) && !!getFundRecord(payment);
823
+ }).map(function (payment) {
824
+ return buildPaymentItems({
825
+ payment: payment,
826
+ locale: params.locale,
827
+ currencySymbol: params.currencySymbol,
828
+ includeFundRecordBalance: true
829
+ });
830
+ });
831
+ }
832
+ function buildPaymentItems(params) {
833
+ var payment = params.payment,
834
+ locale = params.locale,
835
+ currencySymbol = params.currencySymbol,
836
+ includeFundRecordBalance = params.includeFundRecordBalance;
837
+ var serviceFee = getPaymentServiceFee(payment);
838
+ var items = [{
839
+ item: paymentMethodName(payment, locale),
840
+ value: formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol)
841
+ }];
842
+ if (serviceFee.gt(0)) {
786
843
  items.push({
787
- item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), params.locale),
788
- value: ''
844
+ item: label(locale, 'surchargeIncluded'),
845
+ value: formatMoney(serviceFee, currencySymbol)
789
846
  });
790
- return items;
847
+ }
848
+ var fundRecord = getFundRecord(payment);
849
+ if (fundRecord) {
850
+ items.push.apply(items, _toConsumableArray(buildFundRecordPaymentItems({
851
+ payment: payment,
852
+ fundRecord: fundRecord,
853
+ locale: locale,
854
+ currencySymbol: currencySymbol,
855
+ includeBalance: includeFundRecordBalance
856
+ })));
857
+ } else {
858
+ var _ref42, _payment$remaining_am, _payment$metadata;
859
+ var remainingAmount = (_ref42 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref42 !== void 0 ? _ref42 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
860
+ if (remainingAmount !== undefined && remainingAmount !== null) {
861
+ items.push({
862
+ item: label(locale, 'remainingAmount'),
863
+ value: formatMoney(remainingAmount, currencySymbol)
864
+ });
865
+ }
866
+ }
867
+ items.push({
868
+ item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), locale),
869
+ value: ''
791
870
  });
871
+ return items;
872
+ }
873
+ function getPaymentServiceFee(payment) {
874
+ return new Decimal(toMoneyNumber(payment.service_fee));
875
+ }
876
+ function resolveReceiptPaymentAmount(payment, serviceFee) {
877
+ var _payment$amount;
878
+ var amount = new Decimal(toMoneyNumber((_payment$amount = payment.amount) !== null && _payment$amount !== void 0 ? _payment$amount : payment.origin_amount));
879
+ var hasAmount = payment.amount !== undefined && payment.amount !== null && payment.amount !== '';
880
+ var hasOriginAmount = payment.origin_amount !== undefined && payment.origin_amount !== null && payment.origin_amount !== '';
881
+ if (!hasAmount || !hasOriginAmount || serviceFee.lte(0)) return amount;
882
+ var originAmount = new Decimal(toMoneyNumber(payment.origin_amount));
883
+ return amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
792
884
  }
793
885
  function buildFundRecordPaymentItems(params) {
794
886
  var payment = params.payment,
795
887
  fundRecord = params.fundRecord,
796
888
  locale = params.locale,
797
- currencySymbol = params.currencySymbol;
889
+ currencySymbol = params.currencySymbol,
890
+ includeBalance = params.includeBalance;
798
891
  var items = [];
799
892
  var usingBeforeValue = fundRecord.using_before_value;
800
893
  var usingAfterValue = fundRecord.using_after_value;
@@ -804,13 +897,15 @@ function buildFundRecordPaymentItems(params) {
804
897
  item: label(locale, 'redeemPoints'),
805
898
  value: trimDecimal(usedPoints)
806
899
  });
807
- items.push({
808
- item: label(locale, 'remainingPoints'),
809
- value: trimDecimal(new Decimal(toMoneyNumber(usingAfterValue)))
810
- });
900
+ if (includeBalance) {
901
+ items.push({
902
+ item: label(locale, 'remainingPoints'),
903
+ value: trimDecimal(new Decimal(toMoneyNumber(usingAfterValue)))
904
+ });
905
+ }
811
906
  return items;
812
907
  }
813
- if (usingAfterValue !== undefined && usingAfterValue !== null) {
908
+ if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
814
909
  items.push({
815
910
  item: label(locale, 'remainingAmount'),
816
911
  value: formatMoney(usingAfterValue, currencySymbol)
@@ -883,12 +978,12 @@ function label(locale, key) {
883
978
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
884
979
  }
885
980
  function getLocalizedValue(value, locale) {
886
- var _ref39, _ref40, _ref41, _ref42, _ref43, _ref44, _value$locale2;
981
+ var _ref43, _ref44, _ref45, _ref46, _ref47, _ref48, _value$locale2;
887
982
  if (value === undefined || value === null) return '';
888
983
  if (_typeof(value) !== 'object') return stringify(value);
889
984
  var dashedLocale = locale.replace('_', '-');
890
985
  var underscoredLocale = locale.replace('-', '_');
891
- return stringify((_ref39 = (_ref40 = (_ref41 = (_ref42 = (_ref43 = (_ref44 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref44 !== void 0 ? _ref44 : value[underscoredLocale]) !== null && _ref43 !== void 0 ? _ref43 : value.original) !== null && _ref42 !== void 0 ? _ref42 : value.auto) !== null && _ref41 !== void 0 ? _ref41 : value.default) !== null && _ref40 !== void 0 ? _ref40 : value.en) !== null && _ref39 !== void 0 ? _ref39 : '');
986
+ return stringify((_ref43 = (_ref44 = (_ref45 = (_ref46 = (_ref47 = (_ref48 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref48 !== void 0 ? _ref48 : value[underscoredLocale]) !== null && _ref47 !== void 0 ? _ref47 : value.original) !== null && _ref46 !== void 0 ? _ref46 : value.auto) !== null && _ref45 !== void 0 ? _ref45 : value.default) !== null && _ref44 !== void 0 ? _ref44 : value.en) !== null && _ref43 !== void 0 ? _ref43 : '');
892
987
  }
893
988
  function serviceTypeToLabelKey(serviceType) {
894
989
  var normalized = serviceType.toLowerCase();
@@ -197,8 +197,9 @@ export function transformBaseProductToOrderProduct(params) {
197
197
  metadata.unique_identification_number = String(uniqueIdentificationNumber);
198
198
  }
199
199
  // 从源头补充商品多语言标题
200
- var productTitle = _objectSpread(_objectSpread({}, (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title_i18n) || {}), {}, {
201
- original: (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.original_title) || (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) || ''
200
+ var productTitleI18n = (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title_i18n) || {};
201
+ var productTitle = _objectSpread(_objectSpread({}, productTitleI18n), {}, {
202
+ original: productTitleI18n.original || (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.original_title) || (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) || ''
202
203
  });
203
204
  return _objectSpread(_objectSpread({
204
205
  product_id: productId,
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  date: string;
327
327
  status: string;
328
328
  week: string;
329
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
329
+ weekNum: 0 | 5 | 3 | 1 | 2 | 4 | 6;
330
330
  }[]>;
331
331
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
332
  private getScheduleDataByIds;
@@ -345,7 +345,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
345
345
  count: number;
346
346
  left: number;
347
347
  summaryCount: number;
348
- status: "lots_of_space" | "filling_up_fast" | "sold_out";
348
+ status: "sold_out" | "lots_of_space" | "filling_up_fast";
349
349
  }[];
350
350
  /**
351
351
  * 找到多个资源的公共可用时间段