@pisell/pisellos 0.0.115 → 0.0.117

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 (55) hide show
  1. package/dist/modules/Cart/index.js +16 -35
  2. package/dist/modules/Cart/utils/cartAccount.d.ts +21 -0
  3. package/dist/modules/Cart/utils/cartAccount.js +52 -0
  4. package/dist/modules/Cart/utils/cartDate.d.ts +31 -0
  5. package/dist/modules/Cart/utils/cartDate.js +55 -0
  6. package/dist/modules/Cart/utils/cartDiscount.d.ts +19 -0
  7. package/dist/modules/Cart/utils/cartDiscount.js +35 -0
  8. package/dist/modules/Cart/utils/cartNote.d.ts +19 -0
  9. package/dist/modules/Cart/utils/cartNote.js +29 -0
  10. package/dist/modules/Cart/utils/cartProduct.d.ts +107 -0
  11. package/dist/modules/Cart/{utils.js → utils/cartProduct.js} +77 -416
  12. package/dist/modules/Cart/utils/cartRelationForms.d.ts +26 -0
  13. package/dist/modules/Cart/utils/cartRelationForms.js +29 -0
  14. package/dist/modules/Cart/utils/cartResource.d.ts +21 -0
  15. package/dist/modules/Cart/utils/cartResource.js +102 -0
  16. package/dist/modules/Cart/utils/index.d.ts +34 -0
  17. package/dist/modules/Cart/utils/index.js +63 -0
  18. package/dist/modules/Order/index.js +3 -2
  19. package/dist/modules/Product/index.d.ts +1 -1
  20. package/dist/modules/Product/types.d.ts +4 -0
  21. package/dist/modules/Product/utils.d.ts +17 -0
  22. package/dist/modules/Product/utils.js +41 -0
  23. package/dist/solution/BookingByStep/index.d.ts +25 -0
  24. package/dist/solution/BookingByStep/index.js +320 -58
  25. package/dist/solution/BookingByStep/utils/timeslots.d.ts +25 -0
  26. package/dist/solution/BookingByStep/utils/timeslots.js +209 -0
  27. package/lib/modules/Cart/index.js +14 -25
  28. package/lib/modules/Cart/utils/cartAccount.d.ts +21 -0
  29. package/lib/modules/Cart/utils/cartAccount.js +65 -0
  30. package/lib/modules/Cart/utils/cartDate.d.ts +31 -0
  31. package/lib/modules/Cart/utils/cartDate.js +75 -0
  32. package/lib/modules/Cart/utils/cartDiscount.d.ts +19 -0
  33. package/lib/modules/Cart/utils/cartDiscount.js +52 -0
  34. package/lib/modules/Cart/utils/cartNote.d.ts +19 -0
  35. package/lib/modules/Cart/utils/cartNote.js +46 -0
  36. package/lib/modules/Cart/utils/cartProduct.d.ts +107 -0
  37. package/lib/modules/Cart/{utils.js → utils/cartProduct.js} +78 -328
  38. package/lib/modules/Cart/utils/cartRelationForms.d.ts +26 -0
  39. package/lib/modules/Cart/utils/cartRelationForms.js +48 -0
  40. package/lib/modules/Cart/utils/cartResource.d.ts +21 -0
  41. package/lib/modules/Cart/utils/cartResource.js +124 -0
  42. package/lib/modules/Cart/utils/index.d.ts +34 -0
  43. package/lib/modules/Cart/utils/index.js +91 -0
  44. package/lib/modules/Order/index.js +2 -1
  45. package/lib/modules/Product/index.d.ts +1 -1
  46. package/lib/modules/Product/types.d.ts +4 -0
  47. package/lib/modules/Product/utils.d.ts +17 -0
  48. package/lib/modules/Product/utils.js +46 -0
  49. package/lib/solution/BookingByStep/index.d.ts +25 -0
  50. package/lib/solution/BookingByStep/index.js +181 -23
  51. package/lib/solution/BookingByStep/utils/timeslots.d.ts +25 -0
  52. package/lib/solution/BookingByStep/utils/timeslots.js +159 -0
  53. package/package.json +1 -1
  54. package/dist/modules/Cart/utils.d.ts +0 -257
  55. package/lib/modules/Cart/utils.d.ts +0 -257
@@ -0,0 +1,107 @@
1
+ import Decimal from 'decimal.js';
2
+ import { ProductData } from '../../Product/types';
3
+ import { CartItem } from '../types';
4
+ /**
5
+ * @title 处理组合商品
6
+ * @description 组合商品需要直接修改 product 里的价格和 is_charge_tax
7
+ * @param product 商品
8
+ * @returns 处理后的商品
9
+ */
10
+ export declare const handleVariantProduct: (product: ProductData) => ProductData;
11
+ /**
12
+ * 格式化商品到购物车
13
+ * @param product 商品
14
+ * @returns 格式化后的商品
15
+ */
16
+ export declare const formatProductToCartItem: (params: {
17
+ cartItem: CartItem;
18
+ product: ProductData;
19
+ bundle?: any;
20
+ options?: any;
21
+ product_variant_id?: number;
22
+ quantity?: number;
23
+ }) => CartItem;
24
+ export declare const formatProductToCartItemOrigin: (params: {
25
+ cartItem: CartItem;
26
+ product: ProductData;
27
+ bundle?: any;
28
+ options?: any;
29
+ product_variant_id?: number;
30
+ quantity?: number;
31
+ }) => any;
32
+ /**
33
+ * 获取商品总价
34
+ * @description 当前总价计算基于商品数量为1
35
+ * @param item 商品
36
+ * @returns 商品总价
37
+ */
38
+ export declare const getProductTotalPrice: (params: {
39
+ product: ProductData;
40
+ bundle?: any;
41
+ options?: any;
42
+ num?: number;
43
+ }) => number;
44
+ /**
45
+ * 获取商品原始总价
46
+ * @description 当前总价计算基于商品数量为1
47
+ * @param item 商品
48
+ * @returns 商品原始总价
49
+ */
50
+ export declare const getProductOriginTotalPrice: (params: {
51
+ product: ProductData;
52
+ bundle?: any;
53
+ options?: any;
54
+ num?: number;
55
+ }) => number | undefined;
56
+ /**
57
+ * 格式化套餐规格信息
58
+ * @param options 套餐规格信息
59
+ * @returns 格式化后的套餐规格信息
60
+ */
61
+ export declare const formatOptions: (options: any) => any;
62
+ export declare const formatOptionsToOrigin: (options: any) => any;
63
+ /**
64
+ * 格式化商品套餐信息
65
+ * @param bundle 商品套餐信息
66
+ * @returns 格式化后的商品套餐信息
67
+ */
68
+ export declare const formatBundle: (bundle: any) => any;
69
+ export declare const formatBundleToOrigin: (bundle: any) => any;
70
+ /**
71
+ * 获取商品定金
72
+ * @description 定金基于商品售价来算,最终乘商品数量
73
+ * 1、如果套餐主商品有定金规则,则定金为:(套餐商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
74
+ * 2、如果套餐主商品没有定金规则,子商品有定金规则,则定金为:(套餐子商品售价 * 套餐子商品定金百分比 + 套餐子商品定金固定金额)* 商品数量,最终将所有子商品定金相加
75
+ * 3、普通商品/单规格商品/组合规则商品,定金规则:(商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
76
+ * @param params 参数
77
+ * @returns 商品定金
78
+ */
79
+ export declare const getProductDeposit: (params: {
80
+ cartItem: CartItem;
81
+ product: ProductData;
82
+ bundle?: any;
83
+ options?: any;
84
+ num?: number;
85
+ }) => {
86
+ total: number;
87
+ protocols: {
88
+ id: number;
89
+ title: string;
90
+ }[];
91
+ } | null;
92
+ /**
93
+ * 计算商品定金
94
+ * @param params 参数
95
+ * @returns 商品定金
96
+ */
97
+ export declare const handleProductDeposit: (params: {
98
+ depositData: {
99
+ deposit_fixed?: string;
100
+ deposit_percentage?: string;
101
+ };
102
+ total: string | number;
103
+ num: number;
104
+ }) => {
105
+ result: boolean;
106
+ depositTotal: Decimal;
107
+ };
@@ -26,92 +26,48 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  ));
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
 
29
- // src/modules/Cart/utils.ts
30
- var utils_exports = {};
31
- __export(utils_exports, {
32
- createCartItemOrigin: () => createCartItemOrigin,
33
- deleteHolderFromCartItem: () => deleteHolderFromCartItem,
34
- deleteRelationFormsFromCartItem: () => deleteRelationFormsFromCartItem,
35
- deleteResourceFromCartItem: () => deleteResourceFromCartItem,
36
- deleteTimeFromCartItem: () => deleteTimeFromCartItem,
37
- formatAccountToCartItem: () => formatAccountToCartItem,
38
- formatAccountToCartItemOrigin: () => formatAccountToCartItemOrigin,
29
+ // src/modules/Cart/utils/cartProduct.ts
30
+ var cartProduct_exports = {};
31
+ __export(cartProduct_exports, {
39
32
  formatBundle: () => formatBundle,
40
33
  formatBundleToOrigin: () => formatBundleToOrigin,
41
- formatDateToCartItem: () => formatDateToCartItem,
42
- formatDateToCartItemOrigin: () => formatDateToCartItemOrigin,
43
- formatDiscountToCartItem: () => formatDiscountToCartItem,
44
- formatDiscountToCartItemOrigin: () => formatDiscountToCartItemOrigin,
45
- formatNoteToCartItem: () => formatNoteToCartItem,
46
- formatNoteToCartItemOrigin: () => formatNoteToCartItemOrigin,
47
34
  formatOptions: () => formatOptions,
48
35
  formatOptionsToOrigin: () => formatOptionsToOrigin,
49
36
  formatProductToCartItem: () => formatProductToCartItem,
50
37
  formatProductToCartItemOrigin: () => formatProductToCartItemOrigin,
51
- formatRelationFormsToCartItem: () => formatRelationFormsToCartItem,
52
- formatRelationFormsToCartItemOrigin: () => formatRelationFormsToCartItemOrigin,
53
- formatResourceToCartItem: () => formatResourceToCartItem,
54
- formatResourceToCartItemOrigin: () => formatResourceToCartItemOrigin,
55
38
  getProductDeposit: () => getProductDeposit,
56
39
  getProductOriginTotalPrice: () => getProductOriginTotalPrice,
57
40
  getProductTotalPrice: () => getProductTotalPrice,
58
- getUniqueId: () => getUniqueId,
59
41
  handleProductDeposit: () => handleProductDeposit,
60
- isNormalProduct: () => isNormalProduct
42
+ handleVariantProduct: () => handleVariantProduct
61
43
  });
62
- module.exports = __toCommonJS(utils_exports);
63
- var import_dayjs = __toESM(require("dayjs"));
44
+ module.exports = __toCommonJS(cartProduct_exports);
64
45
  var import_decimal = __toESM(require("decimal.js"));
65
- var getUniqueId = (prefix = "", maxLength = 11) => {
66
- return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
67
- };
68
- var createCartItemOrigin = () => {
69
- return {
70
- // 新增为0
71
- id: 0,
72
- // 数量 固定为1
73
- number: 1,
74
- // 客户端报名所有活动;
75
- registration_type: "all",
76
- // 暂时不用
77
- relation_products: [],
78
- // 固定
79
- is_all: false,
80
- // 商品相关
81
- product: null,
82
- // 时长类型
83
- sub_type: null,
84
- // 时长
85
- duration: null,
86
- // 资源相关
87
- // 资源状态 -固定
88
- like_status: "common",
89
- // 资源类型 - 固定--谭景琳备注:马天宇说现在平行资源是不传这个的
90
- // relation_type: "form",
91
- // 所选资源
92
- resources: null,
93
- // 日程id - 固定
94
- schedule_id: 0,
95
- // 所选开始时间
96
- start_date: null,
97
- // 所选开始时间
98
- start_time: null,
99
- // 所选开始时间
100
- select_date: null,
101
- // 所选结束时间
102
- end_time: null,
103
- // 所选结束时间
104
- end_date: null,
105
- // 额外信息
106
- metadata: {},
107
- // holder相关
108
- holder: null
109
- };
46
+ var import_utils = require("../../Product/utils");
47
+ var handleVariantProduct = (product) => {
48
+ if (product == null ? void 0 : product.product_variant_id) {
49
+ const targetVariant = product.variant.find(
50
+ (n) => n.id === product.product_variant_id
51
+ );
52
+ if (targetVariant) {
53
+ product.price = targetVariant.price;
54
+ product.original_price = targetVariant.original_price;
55
+ product.is_charge_tax = targetVariant.is_charge_tax;
56
+ }
57
+ }
58
+ return product;
110
59
  };
111
60
  var formatProductToCartItem = (params) => {
112
61
  var _a, _b;
113
- const { cartItem, product, bundle, options, product_variant_id } = params;
114
- const num = 1;
62
+ const {
63
+ cartItem,
64
+ product,
65
+ bundle,
66
+ options,
67
+ product_variant_id,
68
+ quantity = 1
69
+ } = params;
70
+ const num = quantity;
115
71
  if (product) {
116
72
  cartItem.id = product == null ? void 0 : product.id;
117
73
  cartItem.name = product == null ? void 0 : product.title;
@@ -127,7 +83,7 @@ var formatProductToCartItem = (params) => {
127
83
  cartItem.image = product == null ? void 0 : product.cover;
128
84
  cartItem.like_status = "common";
129
85
  cartItem.duration = product == null ? void 0 : product.duration;
130
- cartItem.isNormalProduct = isNormalProduct(product);
86
+ cartItem.isNormalProduct = (0, import_utils.isNormalProduct)(product);
131
87
  cartItem.is_charge_tax = product == null ? void 0 : product.is_charge_tax;
132
88
  }
133
89
  if (bundle == null ? void 0 : bundle.length) {
@@ -137,17 +93,25 @@ var formatProductToCartItem = (params) => {
137
93
  cartItem.options = formatOptions(options);
138
94
  }
139
95
  if (product_variant_id) {
140
- const sku_key = (_a = product.variant.find((n) => n.id === product_variant_id)) == null ? void 0 : _a.sku_key;
96
+ const sku_key = (_a = product.variant.find(
97
+ (n) => n.id === product_variant_id
98
+ )) == null ? void 0 : _a.sku_key;
141
99
  if (sku_key) {
142
100
  const sku_key_arr = sku_key.split("_");
143
101
  const product_option_string = [];
144
102
  sku_key_arr.forEach((item) => {
145
103
  var _a2;
146
104
  const keyMap = item.split(":");
147
- const targetVariantGroup = product.variant_group.find((n) => String(n.position_id) === keyMap[0]);
148
- const targetVariantItem = (_a2 = targetVariantGroup == null ? void 0 : targetVariantGroup.variant_item) == null ? void 0 : _a2.find((n) => String(n.position_id) === keyMap[1]);
105
+ const targetVariantGroup = product.variant_group.find(
106
+ (n) => String(n.position_id) === keyMap[0]
107
+ );
108
+ const targetVariantItem = (_a2 = targetVariantGroup == null ? void 0 : targetVariantGroup.variant_item) == null ? void 0 : _a2.find(
109
+ (n) => String(n.position_id) === keyMap[1]
110
+ );
149
111
  if (targetVariantGroup && targetVariantItem) {
150
- product_option_string.push(`${targetVariantGroup.name}:${targetVariantItem.name}`);
112
+ product_option_string.push(
113
+ `${targetVariantGroup.name}:${targetVariantItem.name}`
114
+ );
151
115
  }
152
116
  });
153
117
  cartItem.product_option_string = product_option_string.join(", ");
@@ -168,12 +132,19 @@ var formatProductToCartItem = (params) => {
168
132
  };
169
133
  var formatProductToCartItemOrigin = (params) => {
170
134
  var _a, _b, _c, _d;
171
- const { cartItem, product, bundle, options, product_variant_id } = params;
135
+ const {
136
+ cartItem,
137
+ product,
138
+ bundle,
139
+ options,
140
+ product_variant_id,
141
+ quantity = 1
142
+ } = params;
172
143
  let origin = cartItem._origin;
173
144
  if (product) {
174
145
  origin.product = {
175
146
  ...origin.product || {},
176
- num: 1,
147
+ num: quantity,
177
148
  product_id: product.id,
178
149
  product_variant_id: product_variant_id || 0,
179
150
  product_bundle: ((_a = origin.product) == null ? void 0 : _a.product_bundle) || [],
@@ -190,176 +161,40 @@ var formatProductToCartItemOrigin = (params) => {
190
161
  }
191
162
  return origin;
192
163
  };
193
- var formatDiscountToCartItem = (params) => {
194
- const { cartItem } = params;
195
- const oringin = formatDiscountToCartItemOrigin(params);
196
- cartItem._origin = oringin;
197
- return cartItem;
198
- };
199
- var formatDiscountToCartItemOrigin = (params) => {
200
- const { cartItem, discounts } = params;
201
- const origin = cartItem._origin;
202
- if (discounts && (discounts == null ? void 0 : discounts.length)) {
203
- if (!origin.product) {
204
- origin.product = {};
205
- }
206
- origin.product.discount_list = discounts;
207
- } else {
208
- if (!origin.product) {
209
- origin.product = {};
210
- }
211
- origin.product.discount_list = [];
212
- }
213
- return origin;
214
- };
215
- var formatAccountToCartItem = (params) => {
216
- const { cartItem, account } = params;
217
- if (account) {
218
- cartItem.holder_id = account.id;
219
- cartItem.holder_title = account.username;
164
+ var getProductTotalPrice = (params) => {
165
+ const { product, bundle, options } = params;
166
+ const num = params.num || 1;
167
+ let price = Number(product.price);
168
+ if (bundle == null ? void 0 : bundle.length) {
169
+ price = bundle.reduce((accumulator, currentValue) => {
170
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
171
+ }, price);
220
172
  }
221
- const oringin = formatAccountToCartItemOrigin(params);
222
- cartItem._origin = oringin;
223
- return cartItem;
224
- };
225
- var formatAccountToCartItemOrigin = (params) => {
226
- const { cartItem, account } = params;
227
- let origin = cartItem._origin;
228
- if (account) {
229
- if ((account == null ? void 0 : account.type) === "holder") {
230
- const { customer_id, form_id, form_record_id } = (account == null ? void 0 : account._origin) || {};
231
- origin.holder = {
232
- customer_id,
233
- form_id,
234
- form_record: form_record_id ? [form_record_id] : null
235
- };
236
- } else {
237
- origin.metadata.account = account;
238
- }
173
+ if (options == null ? void 0 : options.length) {
174
+ price = options.reduce((accumulator, currentValue) => {
175
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
176
+ }, price);
239
177
  }
240
- return origin;
178
+ return price * num;
241
179
  };
242
- var formatResourceToCartItem = (params) => {
243
- const { cartItem, resources } = params;
244
- if (resources && (resources == null ? void 0 : resources.length)) {
245
- const firstResource = resources[0];
246
- cartItem.resource_id = firstResource == null ? void 0 : firstResource.id;
247
- cartItem.relation_form_name = firstResource == null ? void 0 : firstResource.main_field;
248
- if (firstResource.startTime && firstResource.endTime) {
249
- cartItem.start_date = (0, import_dayjs.default)(firstResource.startTime).format("YYYY-MM-DD");
250
- cartItem.start_time = (0, import_dayjs.default)(firstResource.startTime).format("HH:mm");
251
- cartItem.end_date = (0, import_dayjs.default)(firstResource.endTime).format("YYYY-MM-DD");
252
- cartItem.end_time = (0, import_dayjs.default)(firstResource.endTime).format("HH:mm");
253
- }
254
- } else {
255
- cartItem.resource_id = void 0;
256
- cartItem.relation_form_name = void 0;
257
- cartItem.start_date = void 0;
258
- cartItem.start_time = void 0;
259
- cartItem.end_date = void 0;
260
- cartItem.end_time = void 0;
180
+ var getProductOriginTotalPrice = (params) => {
181
+ const { product, bundle, options } = params;
182
+ const num = (params == null ? void 0 : params.num) || 1;
183
+ let price = Number(product.original_price);
184
+ if (isNaN(price) || price === 0) {
185
+ return void 0;
261
186
  }
262
- const oringin = formatResourceToCartItemOrigin(params);
263
- cartItem._origin = oringin;
264
- cartItem._resourceOrigin = resources;
265
- return cartItem;
266
- };
267
- var formatResourceToCartItemOrigin = (params) => {
268
- const { cartItem, resources } = params;
269
- let origin = cartItem._origin;
270
- if (resources && (resources == null ? void 0 : resources.length)) {
271
- origin.resources = [];
272
- const checkResourcesFormat = (resources2, arr) => {
273
- resources2.forEach((resource) => {
274
- var _a;
275
- const childArr = [];
276
- if ((_a = resource == null ? void 0 : resource.children) == null ? void 0 : _a.length) {
277
- checkResourcesFormat(resource.children, childArr);
278
- }
279
- const obj = {
280
- relation_type: "form",
281
- like_status: "common",
282
- id: resource.id,
283
- main_field: resource.main_field,
284
- resourceType: resource.resourceType,
285
- form_id: resource.form_id,
286
- relation_id: resource.id,
287
- capacity: (resource == null ? void 0 : resource.capacity) || 0,
288
- metadata: (resource == null ? void 0 : resource.metadata) || {}
289
- // 后端可以在这里挂一个前端用于计算的数据
290
- };
291
- if (childArr.length) {
292
- obj.children = childArr;
293
- }
294
- arr.push(obj);
295
- });
296
- };
297
- checkResourcesFormat(resources, origin.resources);
298
- const { startTime, endTime } = resources[0];
299
- if (startTime && endTime) {
300
- origin.select_date = (0, import_dayjs.default)(startTime).format("YYYY-MM-DD");
301
- origin.start_date = (0, import_dayjs.default)(startTime).format("YYYY-MM-DD");
302
- origin.start_time = (0, import_dayjs.default)(startTime).format("HH:mm");
303
- origin.end_date = (0, import_dayjs.default)(endTime).format("YYYY-MM-DD");
304
- origin.end_time = (0, import_dayjs.default)(endTime).format("HH:mm");
305
- }
306
- } else if ((resources == null ? void 0 : resources.length) === 0) {
307
- origin.resources = [];
308
- origin.select_date = null;
309
- origin.start_date = null;
310
- origin.start_time = null;
311
- origin.end_date = null;
312
- origin.end_time = null;
187
+ if (bundle == null ? void 0 : bundle.length) {
188
+ price = bundle.reduce((accumulator, currentValue) => {
189
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
190
+ }, price);
313
191
  }
314
- return origin;
315
- };
316
- var formatRelationFormsToCartItem = (params) => {
317
- const { cartItem } = params;
318
- const oringin = formatRelationFormsToCartItemOrigin(params);
319
- cartItem._origin = oringin;
320
- return cartItem;
321
- };
322
- var formatRelationFormsToCartItemOrigin = (params) => {
323
- const { cartItem, relationForms } = params;
324
- const origin = cartItem._origin;
325
- origin.relation_forms = relationForms;
326
- return origin;
327
- };
328
- var formatDateToCartItem = (params) => {
329
- const { cartItem, date } = params;
330
- cartItem.start_date = (0, import_dayjs.default)(date.startTime).format("YYYY-MM-DD");
331
- cartItem.start_time = (0, import_dayjs.default)(date.startTime).format("HH:mm");
332
- cartItem.end_date = (0, import_dayjs.default)(date.endTime).format("YYYY-MM-DD");
333
- cartItem.end_time = (0, import_dayjs.default)(date.endTime).format("HH:mm");
334
- const oringin = formatDateToCartItemOrigin(params);
335
- cartItem._origin = oringin;
336
- return cartItem;
337
- };
338
- var formatDateToCartItemOrigin = (params) => {
339
- const { cartItem, date } = params;
340
- const origin = cartItem._origin;
341
- origin.select_date = (0, import_dayjs.default)(date.startTime).format("YYYY-MM-DD");
342
- origin.start_date = (0, import_dayjs.default)(date.startTime).format("YYYY-MM-DD");
343
- origin.start_time = (0, import_dayjs.default)(date.startTime).format("HH:mm");
344
- origin.end_date = (0, import_dayjs.default)(date.endTime).format("YYYY-MM-DD");
345
- origin.end_time = (0, import_dayjs.default)(date.endTime).format("HH:mm");
346
- return origin;
347
- };
348
- var formatNoteToCartItem = (params) => {
349
- const { cartItem, note } = params;
350
- cartItem.note = note;
351
- const oringin = formatNoteToCartItemOrigin(params);
352
- cartItem._origin = oringin;
353
- return cartItem;
354
- };
355
- var formatNoteToCartItemOrigin = (params) => {
356
- const { cartItem, note } = params;
357
- const origin = cartItem._origin;
358
- if (!origin.product) {
359
- origin.product = {};
192
+ if (options == null ? void 0 : options.length) {
193
+ price = options.reduce((accumulator, currentValue) => {
194
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
195
+ }, price);
360
196
  }
361
- origin.product.note = note;
362
- return origin;
197
+ return price * num;
363
198
  };
364
199
  var formatOptions = (options) => {
365
200
  if (!(options == null ? void 0 : options.length))
@@ -420,44 +255,6 @@ var formatBundleToOrigin = (bundle) => {
420
255
  };
421
256
  });
422
257
  };
423
- var isNormalProduct = (product) => {
424
- return (product == null ? void 0 : product.extension_type) !== "product_appointment";
425
- };
426
- var getProductTotalPrice = (params) => {
427
- const { product, bundle, options } = params;
428
- const num = params.num || 1;
429
- let price = Number(product.price);
430
- if (bundle == null ? void 0 : bundle.length) {
431
- price = bundle.reduce((accumulator, currentValue) => {
432
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
433
- }, price);
434
- }
435
- if (options == null ? void 0 : options.length) {
436
- price = options.reduce((accumulator, currentValue) => {
437
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
438
- }, price);
439
- }
440
- return price * num;
441
- };
442
- var getProductOriginTotalPrice = (params) => {
443
- const { product, bundle, options } = params;
444
- const num = (params == null ? void 0 : params.num) || 1;
445
- let price = Number(product.original_price);
446
- if (isNaN(price) || price === 0) {
447
- return void 0;
448
- }
449
- if (bundle == null ? void 0 : bundle.length) {
450
- price = bundle.reduce((accumulator, currentValue) => {
451
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
452
- }, price);
453
- }
454
- if (options == null ? void 0 : options.length) {
455
- price = options.reduce((accumulator, currentValue) => {
456
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
457
- }, price);
458
- }
459
- return price * num;
460
- };
461
258
  var getProductDeposit = (params) => {
462
259
  var _a;
463
260
  const { cartItem, product, bundle, options } = params;
@@ -526,64 +323,17 @@ var handleProductDeposit = (params) => {
526
323
  }
527
324
  return { result: false, depositTotal: new import_decimal.default(0) };
528
325
  };
529
- var deleteResourceFromCartItem = (cartItem) => {
530
- cartItem.resource_id = void 0;
531
- cartItem.relation_form_name = void 0;
532
- delete cartItem._resourceOrigin;
533
- cartItem._origin.resources = null;
534
- return cartItem;
535
- };
536
- var deleteTimeFromCartItem = (cartItem) => {
537
- cartItem.start_date = void 0;
538
- cartItem.start_time = void 0;
539
- cartItem.end_date = void 0;
540
- cartItem.end_time = void 0;
541
- cartItem._origin.select_date = null;
542
- cartItem._origin.start_date = null;
543
- cartItem._origin.start_time = null;
544
- cartItem._origin.end_date = null;
545
- cartItem._origin.end_time = null;
546
- return cartItem;
547
- };
548
- var deleteRelationFormsFromCartItem = (cartItem) => {
549
- cartItem._origin.relation_forms = null;
550
- return cartItem;
551
- };
552
- var deleteHolderFromCartItem = (cartItem) => {
553
- cartItem.holder_id = void 0;
554
- cartItem.holder_title = void 0;
555
- cartItem._origin.holder = null;
556
- return cartItem;
557
- };
558
326
  // Annotate the CommonJS export names for ESM import in node:
559
327
  0 && (module.exports = {
560
- createCartItemOrigin,
561
- deleteHolderFromCartItem,
562
- deleteRelationFormsFromCartItem,
563
- deleteResourceFromCartItem,
564
- deleteTimeFromCartItem,
565
- formatAccountToCartItem,
566
- formatAccountToCartItemOrigin,
567
328
  formatBundle,
568
329
  formatBundleToOrigin,
569
- formatDateToCartItem,
570
- formatDateToCartItemOrigin,
571
- formatDiscountToCartItem,
572
- formatDiscountToCartItemOrigin,
573
- formatNoteToCartItem,
574
- formatNoteToCartItemOrigin,
575
330
  formatOptions,
576
331
  formatOptionsToOrigin,
577
332
  formatProductToCartItem,
578
333
  formatProductToCartItemOrigin,
579
- formatRelationFormsToCartItem,
580
- formatRelationFormsToCartItemOrigin,
581
- formatResourceToCartItem,
582
- formatResourceToCartItemOrigin,
583
334
  getProductDeposit,
584
335
  getProductOriginTotalPrice,
585
336
  getProductTotalPrice,
586
- getUniqueId,
587
337
  handleProductDeposit,
588
- isNormalProduct
338
+ handleVariantProduct
589
339
  });
@@ -0,0 +1,26 @@
1
+ import { CartItem } from '../types';
2
+ /**
3
+ * 格式化关联表单到购物车
4
+ * @param params 参数
5
+ * @returns 格式化后的购物车
6
+ */
7
+ export declare const formatRelationFormsToCartItem: (params: {
8
+ cartItem: CartItem;
9
+ relationForms: {
10
+ form_id: number;
11
+ form_record_ids: number[];
12
+ }[];
13
+ }) => CartItem;
14
+ export declare const formatRelationFormsToCartItemOrigin: (params: {
15
+ cartItem: CartItem;
16
+ relationForms: {
17
+ form_id: number;
18
+ form_record_ids: number[];
19
+ }[];
20
+ }) => any;
21
+ /**
22
+ * 从购物车中删除关联表单信息
23
+ * @param cartItem 购物车
24
+ * @returns 删除后的购物车
25
+ */
26
+ export declare const deleteRelationFormsFromCartItem: (cartItem: CartItem) => CartItem;
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/Cart/utils/cartRelationForms.ts
20
+ var cartRelationForms_exports = {};
21
+ __export(cartRelationForms_exports, {
22
+ deleteRelationFormsFromCartItem: () => deleteRelationFormsFromCartItem,
23
+ formatRelationFormsToCartItem: () => formatRelationFormsToCartItem,
24
+ formatRelationFormsToCartItemOrigin: () => formatRelationFormsToCartItemOrigin
25
+ });
26
+ module.exports = __toCommonJS(cartRelationForms_exports);
27
+ var formatRelationFormsToCartItem = (params) => {
28
+ const { cartItem } = params;
29
+ const oringin = formatRelationFormsToCartItemOrigin(params);
30
+ cartItem._origin = oringin;
31
+ return cartItem;
32
+ };
33
+ var formatRelationFormsToCartItemOrigin = (params) => {
34
+ const { cartItem, relationForms } = params;
35
+ const origin = cartItem._origin;
36
+ origin.relation_forms = relationForms;
37
+ return origin;
38
+ };
39
+ var deleteRelationFormsFromCartItem = (cartItem) => {
40
+ cartItem._origin.relation_forms = null;
41
+ return cartItem;
42
+ };
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ deleteRelationFormsFromCartItem,
46
+ formatRelationFormsToCartItem,
47
+ formatRelationFormsToCartItemOrigin
48
+ });