@pisell/pisellos 2.3.140 → 2.3.142

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 (39) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/Cart/index.js +4 -3
  3. package/dist/modules/Cart/types.d.ts +2 -0
  4. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
  5. package/dist/modules/Cart/utils/cartProduct.js +59 -32
  6. package/dist/modules/Order/index.d.ts +1 -1
  7. package/dist/modules/Order/types.d.ts +1 -0
  8. package/dist/modules/Order/utils.js +8 -0
  9. package/dist/modules/Product/types.d.ts +11 -0
  10. package/dist/server/index.js +118 -69
  11. package/dist/server/modules/order/types.d.ts +1 -0
  12. package/dist/shared/receipt/small-ticket.d.ts +2 -0
  13. package/dist/shared/receipt/small-ticket.js +188 -73
  14. package/dist/shared/receipt/templateVisibility.d.ts +23 -0
  15. package/dist/shared/receipt/templateVisibility.js +64 -0
  16. package/dist/solution/BookingByStep/index.d.ts +4 -2
  17. package/dist/solution/BookingByStep/index.js +8 -3
  18. package/dist/solution/OrderInvoicePreview/index.js +2 -1
  19. package/dist/solution/UnifiedBookingSales/index.js +6 -2
  20. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  21. package/lib/modules/Cart/index.js +4 -2
  22. package/lib/modules/Cart/types.d.ts +2 -0
  23. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
  24. package/lib/modules/Cart/utils/cartProduct.js +39 -20
  25. package/lib/modules/Order/index.d.ts +1 -1
  26. package/lib/modules/Order/types.d.ts +1 -0
  27. package/lib/modules/Order/utils.js +8 -0
  28. package/lib/modules/Product/types.d.ts +11 -0
  29. package/lib/server/index.js +68 -28
  30. package/lib/server/modules/order/types.d.ts +1 -0
  31. package/lib/shared/receipt/small-ticket.d.ts +2 -0
  32. package/lib/shared/receipt/small-ticket.js +113 -22
  33. package/lib/shared/receipt/templateVisibility.d.ts +23 -0
  34. package/lib/shared/receipt/templateVisibility.js +63 -0
  35. package/lib/solution/BookingByStep/index.d.ts +4 -2
  36. package/lib/solution/BookingByStep/index.js +7 -3
  37. package/lib/solution/OrderInvoicePreview/index.js +2 -1
  38. package/lib/solution/UnifiedBookingSales/index.js +2 -1
  39. package/package.json +1 -1
@@ -0,0 +1,9 @@
1
+ // 导出评估器
2
+ export { PromotionEvaluator } from "./evaluator";
3
+
4
+ // 导出适配器
5
+ export { PromotionAdapter } from "./adapter";
6
+ export { default } from "./adapter";
7
+
8
+ // 导出策略配置示例常量
9
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
@@ -113,11 +113,11 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
113
113
  key: "addItem",
114
114
  value: (function () {
115
115
  var _addItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
116
- var account, product, bundle, options, date, _params$quantity, quantity, cartItem, newProduct, items;
116
+ var account, product, bundle, options, date, _params$quantity, quantity, isLegacyOrder, cartItem, newProduct, items;
117
117
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
118
118
  while (1) switch (_context2.prev = _context2.next) {
119
119
  case 0:
120
- account = params.account, product = params.product, bundle = params.bundle, options = params.options, date = params.date, _params$quantity = params.quantity, quantity = _params$quantity === void 0 ? 1 : _params$quantity; // 生成一个唯一的 ID
120
+ account = params.account, product = params.product, bundle = params.bundle, options = params.options, date = params.date, _params$quantity = params.quantity, quantity = _params$quantity === void 0 ? 1 : _params$quantity, isLegacyOrder = params.isLegacyOrder; // 生成一个唯一的 ID
121
121
  cartItem = {
122
122
  _id: getUniqueId(),
123
123
  _origin: createCartItemOrigin()
@@ -134,7 +134,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
134
134
  bundle: bundle,
135
135
  options: options,
136
136
  product_variant_id: newProduct.product_variant_id,
137
- quantity: quantity
137
+ quantity: quantity,
138
+ isLegacyOrder: isLegacyOrder
138
139
  });
139
140
  }
140
141
  if (account) {
@@ -180,6 +180,8 @@ export interface IAddItemParams {
180
180
  };
181
181
  /** 商品组合规格ID */
182
182
  product_variant_id?: number;
183
+ /** 是否由旧版下单流程加入购物车 */
184
+ isLegacyOrder?: boolean;
183
185
  }
184
186
  /**
185
187
  * 更新购物车信息参数
@@ -21,6 +21,7 @@ export declare const formatProductToCartItem: (params: {
21
21
  product_variant_id?: number;
22
22
  quantity?: number;
23
23
  discounts?: any[];
24
+ isLegacyOrder?: boolean;
24
25
  }) => CartItem;
25
26
  export declare const formatProductToCartItemOrigin: (params: {
26
27
  cartItem: CartItem;
@@ -29,6 +30,7 @@ export declare const formatProductToCartItemOrigin: (params: {
29
30
  options?: any;
30
31
  product_variant_id?: number;
31
32
  quantity?: number;
33
+ isLegacyOrder?: boolean;
32
34
  }) => any;
33
35
  /**
34
36
  * 获取商品总价
@@ -61,7 +63,7 @@ export declare const getProductOriginTotalPrice: (params: {
61
63
  * @param options 套餐规格信息
62
64
  * @returns 格式化后的套餐规格信息
63
65
  */
64
- export declare const formatOptions: (options: any) => any;
66
+ export declare const formatOptions: (options: any, product?: ProductData) => any;
65
67
  export declare const formatOptionsToOrigin: (options: any) => any;
66
68
  /**
67
69
  * 格式化商品套餐信息
@@ -1,4 +1,5 @@
1
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
+ var _excluded = ["option"];
2
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
4
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
5
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -10,6 +11,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
10
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; }
11
12
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
13
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
13
16
  import Decimal from 'decimal.js';
14
17
  import { isNormalProduct } from "../../Product/utils";
15
18
  import { getDiscountAmount } from "../../../solution/ShopDiscount/utils";
@@ -117,7 +120,7 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
117
120
  cartItem.bundle = formatBundle(bundle);
118
121
  }
119
122
  if (options !== null && options !== void 0 && options.length) {
120
- cartItem.options = formatOptions(options);
123
+ cartItem.options = formatOptions(options, product);
121
124
  }
122
125
  // 拼装出 product_option_string
123
126
  if (product_variant_id) {
@@ -167,7 +170,9 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
167
170
  options = params.options,
168
171
  product_variant_id = params.product_variant_id,
169
172
  _params$quantity2 = params.quantity,
170
- quantity = _params$quantity2 === void 0 ? 1 : _params$quantity2;
173
+ quantity = _params$quantity2 === void 0 ? 1 : _params$quantity2,
174
+ _params$isLegacyOrder = params.isLegacyOrder,
175
+ isLegacyOrder = _params$isLegacyOrder === void 0 ? false : _params$isLegacyOrder;
171
176
  var origin = cartItem._origin;
172
177
  var product_discount_difference = (((_origin$product = origin.product) === null || _origin$product === void 0 ? void 0 : _origin$product.discount_list) || []).filter(function (item) {
173
178
  var _item$metadata;
@@ -177,15 +182,23 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
177
182
  return pre + ((cur === null || cur === void 0 || (_cur$metadata = cur.metadata) === null || _cur$metadata === void 0 ? void 0 : _cur$metadata.product_discount_difference) || 0);
178
183
  }, 0);
179
184
  if (product) {
180
- var _origin$product2, _origin$product3, _product$duration, _product$duration2;
181
- origin.product = _objectSpread(_objectSpread({}, origin.product || {}), {}, {
185
+ var _origin$product2, _origin$product3, _origin$product4, _origin$product5, _product$duration, _product$duration2;
186
+ var _ref = ((_origin$product2 = origin.product) === null || _origin$product2 === void 0 ? void 0 : _origin$product2.product_sku) || {},
187
+ _option = _ref.option,
188
+ legacyProductSku = _objectWithoutProperties(_ref, _excluded);
189
+ origin.product = _objectSpread(_objectSpread(_objectSpread({}, origin.product || {}), {}, {
182
190
  num: quantity,
183
191
  product_id: product.id,
184
192
  product_variant_id: product_variant_id || 0,
185
- product_bundle: ((_origin$product2 = origin.product) === null || _origin$product2 === void 0 ? void 0 : _origin$product2.product_bundle) || [],
186
- product_sku: ((_origin$product3 = origin.product) === null || _origin$product3 === void 0 ? void 0 : _origin$product3.product_sku) || {
193
+ product_bundle: ((_origin$product3 = origin.product) === null || _origin$product3 === void 0 ? void 0 : _origin$product3.product_bundle) || []
194
+ }, isLegacyOrder ? {
195
+ product_sku: legacyProductSku,
196
+ product_option_item: ((_origin$product4 = origin.product) === null || _origin$product4 === void 0 ? void 0 : _origin$product4.product_option_item) || []
197
+ } : {
198
+ product_sku: ((_origin$product5 = origin.product) === null || _origin$product5 === void 0 ? void 0 : _origin$product5.product_sku) || {
187
199
  option: []
188
- },
200
+ }
201
+ }), {}, {
189
202
  metadata: {
190
203
  product_discount_difference: product_discount_difference
191
204
  }
@@ -198,16 +211,21 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
198
211
  origin.product.product_bundle = formatBundleToOrigin(bundle);
199
212
  }
200
213
  if (options !== null && options !== void 0 && options.length) {
201
- origin.product.product_sku = _objectSpread(_objectSpread({}, origin.product.product_sku || {}), {}, {
202
- option: formatOptionsToOrigin(options).map(function (option) {
203
- var _option$add_price;
204
- var next = _objectSpread(_objectSpread({}, option), {}, {
205
- add_price: (_option$add_price = option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option.price
206
- });
207
- delete next.price;
208
- return next;
209
- })
210
- });
214
+ var formattedOptions = formatOptionsToOrigin(options);
215
+ if (isLegacyOrder) {
216
+ origin.product.product_option_item = formattedOptions;
217
+ } else {
218
+ origin.product.product_sku = _objectSpread(_objectSpread({}, origin.product.product_sku || {}), {}, {
219
+ option: formattedOptions.map(function (option) {
220
+ var _option$add_price;
221
+ var next = _objectSpread(_objectSpread({}, option), {}, {
222
+ add_price: (_option$add_price = option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option.price
223
+ });
224
+ delete next.price;
225
+ return next;
226
+ })
227
+ });
228
+ }
211
229
  }
212
230
  }
213
231
  return origin;
@@ -230,10 +248,10 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
230
248
 
231
249
  // option 行:unit 折后价在循环中与主商品使用同一套 getDiscountAmount(含 deductOptionPrice)
232
250
  var optionRows = (_options$map = options === null || options === void 0 ? void 0 : options.map(function (currentValue) {
233
- var _ref, _currentValue$price, _ref2, _currentValue$num;
251
+ var _ref2, _currentValue$price, _ref3, _currentValue$num;
234
252
  return {
235
- unit: Number((_ref = (_currentValue$price = currentValue.price) !== null && _currentValue$price !== void 0 ? _currentValue$price : currentValue.add_price) !== null && _ref !== void 0 ? _ref : 0),
236
- num: Number((_ref2 = (_currentValue$num = currentValue.num) !== null && _currentValue$num !== void 0 ? _currentValue$num : currentValue.quantity) !== null && _ref2 !== void 0 ? _ref2 : 1)
253
+ unit: Number((_ref2 = (_currentValue$price = currentValue.price) !== null && _currentValue$price !== void 0 ? _currentValue$price : currentValue.add_price) !== null && _ref2 !== void 0 ? _ref2 : 0),
254
+ num: Number((_ref3 = (_currentValue$num = currentValue.num) !== null && _currentValue$num !== void 0 ? _currentValue$num : currentValue.quantity) !== null && _ref3 !== void 0 ? _ref3 : 1)
237
255
  };
238
256
  })) !== null && _options$map !== void 0 ? _options$map : [];
239
257
 
@@ -317,12 +335,21 @@ export var getProductOriginTotalPrice = function getProductOriginTotalPrice(para
317
335
  * @param options 套餐规格信息
318
336
  * @returns 格式化后的套餐规格信息
319
337
  */
320
- export var formatOptions = function formatOptions(options) {
338
+ export var formatOptions = function formatOptions(options, product) {
321
339
  if (!(options !== null && options !== void 0 && options.length)) return [];
322
340
  return options.map(function (item) {
341
+ var _ref4, _item$id, _product$option_group, _optionGroup$option_i, _ref5, _ref6, _item$name;
342
+ var optionGroupId = item === null || item === void 0 ? void 0 : item.option_group_id;
343
+ var optionItemId = (_ref4 = (_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : item === null || item === void 0 ? void 0 : item.option_group_item_id) !== null && _ref4 !== void 0 ? _ref4 : item === null || item === void 0 ? void 0 : item.product_option_item_id;
344
+ var optionGroup = product === null || product === void 0 || (_product$option_group = product.option_group) === null || _product$option_group === void 0 ? void 0 : _product$option_group.find(function (group) {
345
+ return String(group === null || group === void 0 ? void 0 : group.id) === String(optionGroupId);
346
+ });
347
+ var optionItem = optionGroup === null || optionGroup === void 0 || (_optionGroup$option_i = optionGroup.option_item) === null || _optionGroup$option_i === void 0 ? void 0 : _optionGroup$option_i.find(function (candidate) {
348
+ return String(candidate === null || candidate === void 0 ? void 0 : candidate.id) === String(optionItemId);
349
+ });
323
350
  return {
324
- id: item === null || item === void 0 ? void 0 : item.id,
325
- name: item === null || item === void 0 ? void 0 : item.name,
351
+ id: optionItemId,
352
+ name: (_ref5 = (_ref6 = (_item$name = item === null || item === void 0 ? void 0 : item.name) !== null && _item$name !== void 0 ? _item$name : item === null || item === void 0 ? void 0 : item.title) !== null && _ref6 !== void 0 ? _ref6 : optionItem === null || optionItem === void 0 ? void 0 : optionItem.name) !== null && _ref5 !== void 0 ? _ref5 : optionItem === null || optionItem === void 0 ? void 0 : optionItem.title,
326
353
  num: item === null || item === void 0 ? void 0 : item.num,
327
354
  price: item === null || item === void 0 ? void 0 : item.price,
328
355
  total: item === null || item === void 0 ? void 0 : item.price,
@@ -337,7 +364,7 @@ export var formatOptionsToOrigin = function formatOptionsToOrigin(options) {
337
364
  return options.map(function (d) {
338
365
  return {
339
366
  num: d.num,
340
- option_group_item_id: d.option_group_item_id,
367
+ option_group_item_id: (d === null || d === void 0 ? void 0 : d.option_group_item_id) || (d === null || d === void 0 ? void 0 : d.product_option_item_id),
341
368
  option_group_id: d.option_group_id
342
369
  };
343
370
  });
@@ -431,11 +458,11 @@ export var getProductDeposit = function getProductDeposit(params) {
431
458
  // 判定商品是否有定金规则
432
459
  if ((product === null || product === void 0 || (_product$custom_depos2 = product.custom_deposit_data) === null || _product$custom_depos2 === void 0 ? void 0 : _product$custom_depos2.has_deposit) == 1) {
433
460
  var total = new Decimal(0);
434
- var _ref3 = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
435
- deposit_fixed = _ref3.deposit_fixed,
436
- deposit_percentage = _ref3.deposit_percentage,
437
- deposit_policy_data = _ref3.deposit_policy_data,
438
- self_deposit_policy_ids = _ref3.self_deposit_policy_ids;
461
+ var _ref7 = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
462
+ deposit_fixed = _ref7.deposit_fixed,
463
+ deposit_percentage = _ref7.deposit_percentage,
464
+ deposit_policy_data = _ref7.deposit_policy_data,
465
+ self_deposit_policy_ids = _ref7.self_deposit_policy_ids;
439
466
  // 所有协议数据
440
467
  var allProtocols = deposit_policy_data || [];
441
468
  // 是否存在定金,主商品has_deposit为1,但是自身没有定金设置,需要判定子商品是否存在定金,如果不存在最终判定也是不存在定金
@@ -529,9 +556,9 @@ export var handleProductDeposit = function handleProductDeposit(params) {
529
556
  depositTotal: new Decimal(0)
530
557
  };
531
558
  }
532
- var _ref4 = depositData || {},
533
- deposit_fixed = _ref4.deposit_fixed,
534
- deposit_percentage = _ref4.deposit_percentage;
559
+ var _ref8 = depositData || {},
560
+ deposit_fixed = _ref8.deposit_fixed,
561
+ deposit_percentage = _ref8.deposit_percentage;
535
562
  if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
536
563
  var depositFixed = Decimal(deposit_fixed || 0);
537
564
  var depositPercent = Decimal(deposit_percentage || 0);
@@ -592,7 +592,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
592
592
  generateIdempotencyToken(): string;
593
593
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
594
594
  createOrder(params: CommitOrderParams['query']): {
595
- type: "appointment_booking" | "virtual";
595
+ type: "virtual" | "appointment_booking";
596
596
  platform: string;
597
597
  sales_channel: string;
598
598
  order_sales_channel: string;
@@ -213,6 +213,7 @@ export interface VirtualCurrencySnapshotItem {
213
213
  id: number | string;
214
214
  tag: 'virtual_currency';
215
215
  product_id?: number | string;
216
+ code?: string;
216
217
  product_name: string;
217
218
  par_value: string;
218
219
  used_par_value: string;
@@ -188,6 +188,10 @@ export function normalizeVirtualCurrencySnapshotItem(value) {
188
188
  if (productId !== undefined) {
189
189
  snapshot.product_id = productId;
190
190
  }
191
+ var code = normalizeSnapshotScalar(value.code);
192
+ if (code !== undefined) {
193
+ snapshot.code = String(code).trim();
194
+ }
191
195
  return snapshot;
192
196
  }
193
197
  function normalizeVirtualCurrencySnapshotList(value) {
@@ -219,6 +223,10 @@ export function buildVirtualCurrencySnapshotFromList(value) {
219
223
  if (productId !== undefined) {
220
224
  snapshot.product_id = productId;
221
225
  }
226
+ var code = normalizeSnapshotScalar(item.code);
227
+ if (code !== undefined) {
228
+ snapshot.code = String(code).trim();
229
+ }
222
230
  result.push(snapshot);
223
231
  return result;
224
232
  }, []);
@@ -218,6 +218,17 @@ export interface ProductData {
218
218
  bundle?: any[];
219
219
  /** 商品选项组成 */
220
220
  options?: any[];
221
+ /** 单规格组;用于由已选 option 反查规格项名称、价格等商品快照字段。 */
222
+ option_group?: Array<{
223
+ id: number | string;
224
+ option_item?: Array<{
225
+ id: number | string;
226
+ name?: string | Record<string, any>;
227
+ title?: string | Record<string, any>;
228
+ [key: string]: any;
229
+ }>;
230
+ [key: string]: any;
231
+ }>;
221
232
  /** 商品原信息 */
222
233
  origin?: any;
223
234
  /** 容量 */