@pisell/pisellos 1.0.0 → 1.0.1

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 (53) hide show
  1. package/dist/modules/Cart/index.d.ts +0 -14
  2. package/dist/modules/Cart/index.js +0 -36
  3. package/dist/modules/Cart/utils/cartProduct.js +1 -10
  4. package/dist/modules/Date/index.js +6 -57
  5. package/dist/modules/Discount/index.d.ts +0 -1
  6. package/dist/modules/Discount/index.js +7 -15
  7. package/dist/modules/Discount/types.d.ts +0 -10
  8. package/dist/modules/ProductList/index.d.ts +0 -7
  9. package/dist/modules/ProductList/index.js +39 -102
  10. package/dist/modules/Rules/index.js +71 -196
  11. package/dist/modules/Rules/types.d.ts +0 -6
  12. package/dist/modules/Schedule/index.d.ts +1 -9
  13. package/dist/modules/Schedule/index.js +2 -122
  14. package/dist/modules/Schedule/types.d.ts +0 -13
  15. package/dist/solution/BookingByStep/index.d.ts +30 -120
  16. package/dist/solution/BookingByStep/index.js +1065 -750
  17. package/dist/solution/BookingByStep/utils/resources.d.ts +31 -29
  18. package/dist/solution/BookingByStep/utils/resources.js +94 -39
  19. package/dist/solution/BookingByStep/utils/timeslots.d.ts +0 -11
  20. package/dist/solution/BookingByStep/utils/timeslots.js +0 -15
  21. package/dist/solution/ShopDiscount/index.d.ts +0 -2
  22. package/dist/solution/ShopDiscount/index.js +32 -93
  23. package/lib/modules/Cart/index.d.ts +0 -14
  24. package/lib/modules/Cart/index.js +0 -32
  25. package/lib/modules/Cart/utils/cartProduct.js +1 -1
  26. package/lib/modules/Date/index.js +10 -62
  27. package/lib/modules/Discount/index.d.ts +0 -1
  28. package/lib/modules/Discount/index.js +6 -18
  29. package/lib/modules/Discount/types.d.ts +0 -10
  30. package/lib/modules/ProductList/index.d.ts +0 -7
  31. package/lib/modules/ProductList/index.js +0 -45
  32. package/lib/modules/Rules/index.js +56 -147
  33. package/lib/modules/Rules/types.d.ts +0 -6
  34. package/lib/modules/Schedule/index.d.ts +1 -9
  35. package/lib/modules/Schedule/index.js +1 -79
  36. package/lib/modules/Schedule/types.d.ts +0 -13
  37. package/lib/solution/BookingByStep/index.d.ts +30 -120
  38. package/lib/solution/BookingByStep/index.js +581 -392
  39. package/lib/solution/BookingByStep/utils/resources.d.ts +31 -29
  40. package/lib/solution/BookingByStep/utils/resources.js +59 -23
  41. package/lib/solution/BookingByStep/utils/timeslots.d.ts +0 -11
  42. package/lib/solution/BookingByStep/utils/timeslots.js +0 -7
  43. package/lib/solution/ShopDiscount/index.d.ts +0 -2
  44. package/lib/solution/ShopDiscount/index.js +18 -85
  45. package/package.json +1 -1
  46. package/dist/modules/Cart/utils/changePrice.d.ts +0 -3
  47. package/dist/modules/Cart/utils/changePrice.js +0 -104
  48. package/dist/solution/BookingByStep/utils/capacity.d.ts +0 -47
  49. package/dist/solution/BookingByStep/utils/capacity.js +0 -132
  50. package/lib/modules/Cart/utils/changePrice.d.ts +0 -3
  51. package/lib/modules/Cart/utils/changePrice.js +0 -78
  52. package/lib/solution/BookingByStep/utils/capacity.d.ts +0 -47
  53. package/lib/solution/BookingByStep/utils/capacity.js +0 -106
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/modules/Date/index.ts
@@ -34,7 +24,6 @@ __export(Date_exports, {
34
24
  module.exports = __toCommonJS(Date_exports);
35
25
  var import_BaseModule = require("../BaseModule");
36
26
  var import_utils = require("./utils");
37
- var import_cloneDeep = __toESM(require("lodash-es/cloneDeep"));
38
27
  var DateModule = class extends import_BaseModule.BaseModule {
39
28
  constructor(name, version) {
40
29
  super(name, version);
@@ -69,70 +58,29 @@ var DateModule = class extends import_BaseModule.BaseModule {
69
58
  return this.store.dateRange;
70
59
  }
71
60
  async getResourceDates(params) {
72
- var _a;
73
- const currentDateList = this.getDateList() || [];
74
- const currentDateListMap = new Map(
75
- currentDateList.map((item) => [item.date, item])
76
- );
77
- const resourceIds = ((_a = params.query) == null ? void 0 : _a.resource_ids) || [];
78
- const hasResource = resourceIds.every((id) => {
79
- var _a2;
80
- const currentItem = currentDateListMap.get(id.toString());
81
- return (_a2 = currentItem == null ? void 0 : currentItem.resource) == null ? void 0 : _a2.some((n) => n.id === id);
82
- });
83
- if (hasResource) {
84
- return currentDateList;
85
- }
86
61
  const dates = await this.getResourceAvailableTimeList(params);
87
- this.setDateList(dates);
62
+ this.store.dateList = dates;
88
63
  return dates;
89
64
  }
90
65
  getDateList() {
91
66
  return this.store.dateList;
92
67
  }
93
68
  setDateList(dateList) {
94
- const currentDateList = (0, import_cloneDeep.default)(this.store.dateList) || [];
95
- dateList.forEach((item) => {
96
- var _a;
97
- const currentItemIndex = currentDateList.findIndex(
98
- (n) => n.date === item.date
99
- );
100
- if (currentItemIndex !== -1) {
101
- const currentItem = currentDateList[currentItemIndex];
102
- const newResource = (_a = item.resource) == null ? void 0 : _a.filter(
103
- (n) => {
104
- var _a2;
105
- return !((_a2 = currentItem.resource) == null ? void 0 : _a2.some((m) => m.id === n.id));
106
- }
107
- );
108
- currentItem.resource = [
109
- ...currentItem.resource || [],
110
- ...newResource || []
111
- ];
112
- currentDateList[currentItemIndex] = currentItem;
113
- } else {
114
- currentDateList.push(item);
115
- }
116
- });
117
- this.store.dateList = currentDateList;
69
+ this.store.dateList = dateList;
118
70
  }
119
71
  async fetchResourceDates(params) {
120
72
  const { url, query } = params;
121
73
  const fetchUrl = url || "/schedule/resource/list";
122
74
  const { start_date, end_date, resource_ids } = query || {};
123
75
  try {
124
- const res = await this.request.get(
125
- fetchUrl,
126
- {
127
- start_date,
128
- end_date,
129
- resource_ids,
130
- front_end_cache_id: this.cacheId
131
- },
132
- {
133
- useCache: true
134
- }
135
- );
76
+ const res = await this.request.get(fetchUrl, {
77
+ start_date,
78
+ end_date,
79
+ resource_ids,
80
+ front_end_cache_id: this.cacheId
81
+ }, {
82
+ useCache: true
83
+ });
136
84
  return res;
137
85
  } catch (error) {
138
86
  console.error(error);
@@ -17,7 +17,6 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
17
17
  loadPrepareConfig(params: {
18
18
  action?: 'create';
19
19
  with_good_pass: 0 | 1;
20
- with_discount_card: 0 | 1;
21
20
  customer_id: number;
22
21
  }): Promise<Discount[]>;
23
22
  batchSearch(code: string): Promise<Discount[]>;
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/modules/Discount/index.ts
@@ -35,7 +25,6 @@ module.exports = __toCommonJS(Discount_exports);
35
25
  var import_utils = require("../../solution/ShopDiscount/utils");
36
26
  var import_BaseModule = require("../BaseModule");
37
27
  var import_types = require("./types");
38
- var import_decimal = __toESM(require("decimal.js"));
39
28
  var DiscountModule = class extends import_BaseModule.BaseModule {
40
29
  constructor(name, version) {
41
30
  super(name, version);
@@ -79,22 +68,21 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
79
68
  return this.store.discountList;
80
69
  }
81
70
  async loadPrepareConfig(params) {
82
- var _a, _b;
71
+ var _a;
83
72
  const prepareConfig = await this.request.post(
84
73
  `/order/prepare/config`,
85
74
  params
86
75
  );
87
76
  const goodPassList = this.filterEnabledDiscountList(
88
- [...((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || [], ...((_b = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _b.discount_card_list) || []]
77
+ ((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || []
89
78
  ) || [];
90
- this.setDiscountList(goodPassList);
91
79
  return goodPassList;
92
80
  }
93
81
  async batchSearch(code) {
94
82
  const result = await this.request.get(`/machinecode/batch-search`, {
95
83
  code,
96
84
  translate_flag: 1,
97
- tags: ["good_pass", "product_discount_card"],
85
+ tag: "good_pass",
98
86
  available: 1,
99
87
  relation_product: 1
100
88
  });
@@ -103,7 +91,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
103
91
  }
104
92
  filterEnabledDiscountList(discountList) {
105
93
  return discountList.filter(
106
- (discount) => discount.limit_status === "enable" && new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0)
94
+ (discount) => discount.limit_status === "enable" && Number((discount == null ? void 0 : discount.par_value) || 0) - Number((discount == null ? void 0 : discount.used_par_value) || 0) > 0
107
95
  );
108
96
  }
109
97
  // 根据productIds去重
@@ -122,8 +110,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
122
110
  }
123
111
  if (discount.appliedProductDetails) {
124
112
  return discount.appliedProductDetails.reduce((total, product) => {
125
- const price = new import_decimal.default((product == null ? void 0 : product.amount) || 0).mul((product == null ? void 0 : product.num) || 1);
126
- return new import_decimal.default(total).plus(price).toNumber();
113
+ const price = Number(product == null ? void 0 : product.amount) || 0;
114
+ return total + price;
127
115
  }, 0);
128
116
  }
129
117
  }
@@ -27,14 +27,6 @@ interface ApplicableProductDetails {
27
27
  resource_id: number;
28
28
  title: string;
29
29
  original_amount: string;
30
- num: number;
31
- discount?: {
32
- product_id?: number;
33
- original_amount?: string;
34
- percent?: string;
35
- resource_id?: number;
36
- title?: string;
37
- };
38
30
  }
39
31
  export interface Discount {
40
32
  id: number;
@@ -68,8 +60,6 @@ export interface Discount {
68
60
  applicableProductIds?: number[];
69
61
  applicableProductDetails: ApplicableProductDetails[];
70
62
  appliedProductDetails: ApplicableProductDetails[];
71
- isDisabledForProductUsed?: boolean;
72
- amount?: number;
73
63
  }
74
64
  export interface DiscountState {
75
65
  discountList: Discount[];
@@ -11,13 +11,6 @@ export declare class ProductList extends BaseModule implements Module {
11
11
  constructor(name?: string, version?: string);
12
12
  initialize(core: PisellCore, options: any): Promise<void>;
13
13
  storeChange(path?: string, value?: any): Promise<void>;
14
- loadProducts({ category_ids, product_ids, collection, schedule_date, cacheId }: {
15
- category_ids?: number[];
16
- product_ids?: number[];
17
- collection?: number | string[];
18
- schedule_date?: string;
19
- cacheId?: string;
20
- }): Promise<any>;
21
14
  loadProductsPrice({ ids, customer_id, schedule_date, channel, }: {
22
15
  ids?: number[];
23
16
  customer_id?: number;
@@ -64,51 +64,6 @@ var ProductList = class extends import_BaseModule.BaseModule {
64
64
  }
65
65
  });
66
66
  }
67
- async loadProducts({
68
- category_ids = [],
69
- product_ids = [],
70
- collection = [],
71
- schedule_date,
72
- cacheId
73
- }) {
74
- var _a;
75
- let userPlugin = this.core.getPlugin("user");
76
- let customer_id = void 0;
77
- try {
78
- customer_id = (_a = userPlugin == null ? void 0 : userPlugin.get()) == null ? void 0 : _a.id;
79
- } catch (error) {
80
- console.error(error);
81
- }
82
- const productsData = await this.request.post(
83
- `/product/query`,
84
- {
85
- open_quotation: 1,
86
- open_bundle: 0,
87
- exclude_extension_type: [
88
- "product_party",
89
- "product_event",
90
- "product_series_event",
91
- "product_package_ticket",
92
- "ticket",
93
- "event_item"
94
- ],
95
- with: ["category", "collection", "resourceRelation"],
96
- status: "published",
97
- num: 500,
98
- skip: 1,
99
- customer_id,
100
- category_ids,
101
- ids: product_ids,
102
- collection,
103
- front_end_cache_id: cacheId,
104
- // client_schedule_ids: schedule_ids,
105
- schedule_date
106
- },
107
- { useCache: true }
108
- );
109
- this.addProduct(productsData.data.list);
110
- return productsData.data.list;
111
- }
112
67
  async loadProductsPrice({
113
68
  ids = [],
114
69
  customer_id,
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/modules/Rules/index.ts
@@ -36,7 +26,6 @@ var import_BaseModule = require("../BaseModule");
36
26
  var import_types = require("./types");
37
27
  var import_utils = require("../../solution/ShopDiscount/utils");
38
28
  var import_utils2 = require("../Cart/utils");
39
- var import_decimal = __toESM(require("decimal.js"));
40
29
  var RulesModule = class extends import_BaseModule.BaseModule {
41
30
  constructor(name, version) {
42
31
  super(name, version);
@@ -69,16 +58,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
69
58
  productList
70
59
  };
71
60
  }
72
- if (productList.every((item) => {
73
- var _a;
74
- return item.booking_id && (((_a = item.discount_list) == null ? void 0 : _a.length) || item.price == 0);
75
- })) {
76
- return {
77
- isAvailable: false,
78
- discountList: oldDiscountList,
79
- productList
80
- };
81
- }
82
61
  const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
83
62
  ...oldDiscountList,
84
63
  ...newDiscountList
@@ -115,7 +94,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
115
94
  discountList,
116
95
  productList
117
96
  }, options) {
118
- const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
119
97
  const editModeDiscount = [];
120
98
  const addModeDiscount = [];
121
99
  discountList.forEach((discount) => {
@@ -129,43 +107,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
129
107
  return !discount.isManualSelect;
130
108
  });
131
109
  const sortedDiscountList = [...filteredDiscountList].sort((a, b) => {
132
- if (a.tag === "good_pass" && b.tag !== "good_pass")
133
- return -1;
134
- if (b.tag === "good_pass" && a.tag !== "good_pass")
135
- return 1;
136
- if (a.tag === "good_pass" && b.tag === "good_pass") {
137
- return compareByExpireTime(a, b);
138
- } else if (a.tag === "product_discount_card" && b.tag === "product_discount_card") {
139
- if (a.par_value !== b.par_value) {
140
- const valueA = new import_decimal.default(100).minus(a.par_value || 0);
141
- const valueB = new import_decimal.default(100).minus(b.par_value || 0);
142
- return valueA.minus(valueB).toNumber();
143
- }
144
- return compareByExpireTime(a, b);
145
- }
146
- return compareByExpireTime(a, b);
147
- function compareByExpireTime(itemA, itemB) {
148
- if (itemA.expire_time && itemB.expire_time) {
149
- const timeA = new Date(itemA.expire_time).getTime();
150
- const timeB = new Date(itemB.expire_time).getTime();
151
- return timeA - timeB;
152
- }
153
- return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
110
+ if (a.expire_time && b.expire_time) {
111
+ const timeA = new Date(a.expire_time).getTime();
112
+ const timeB = new Date(b.expire_time).getTime();
113
+ return timeA - timeB;
154
114
  }
115
+ return a.expire_time ? -1 : b.expire_time ? 1 : 0;
155
116
  });
156
117
  const sortedProductList = [...productList].sort((a, b) => {
157
- var _a, _b;
158
118
  const aProduct = this.hooks.getProduct(a);
159
119
  const bProduct = this.hooks.getProduct(b);
160
- const priceA = new import_decimal.default(aProduct.price || "0");
161
- const priceB = new import_decimal.default(bProduct.price || "0");
162
- if (priceA.toNumber() === priceB.toNumber()) {
163
- if (aProduct.quantity === bProduct.quantity) {
164
- return ((_a = bProduct.discount_list) == null ? void 0 : _a.length) - ((_b = aProduct.discount_list) == null ? void 0 : _b.length);
165
- }
166
- return aProduct.quantity - bProduct.quantity;
167
- }
168
- return priceB.toNumber() - priceA.toNumber();
120
+ const priceA = parseFloat(aProduct.price || "0");
121
+ const priceB = parseFloat(bProduct.price || "0");
122
+ return priceB - priceA;
169
123
  });
170
124
  const usedDiscounts = /* @__PURE__ */ new Map();
171
125
  const discountApplicability = /* @__PURE__ */ new Map();
@@ -182,40 +136,32 @@ var RulesModule = class extends import_BaseModule.BaseModule {
182
136
  var _a, _b, _c;
183
137
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
184
138
  const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
185
- const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type))));
139
+ const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && discount2.type === "good_pass")));
186
140
  if (isAvailableProduct && isLimitedProduct) {
187
141
  (_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
188
142
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
189
143
  applicableProducts.push({
190
144
  amount: product.price,
191
- type: discount.tag || discount.type,
192
- tag: discount.tag || discount.type,
145
+ type: discount.tag,
193
146
  discount: {
194
147
  resource_id: discount.id,
195
148
  title: discount.format_title,
196
- original_amount: product.origin_total,
197
- pre_value: discount.par_value,
198
- product_id: originProduct.id
199
- },
200
- num: product.num || 1
149
+ original_amount: product.origin_total
150
+ }
201
151
  });
202
152
  discountApplicableProducts.set(discount.id, applicableProducts);
203
153
  }
204
154
  });
205
155
  });
206
- console.log(sortedProductList, "sortedProductListsortedProductList");
207
- sortedProductList.forEach((originProduct, i) => {
208
- var _a, _b, _c, _d, _e, _f;
156
+ sortedProductList.forEach((originProduct) => {
157
+ var _a, _b, _c, _d, _e;
209
158
  const product = this.hooks.getProduct(originProduct);
210
- if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
211
- processedProductsMap.set(product._id, [originProduct]);
159
+ if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && discount.type === "good_pass"))) {
160
+ processedProductsMap.set(product._id, originProduct);
212
161
  return;
213
162
  }
214
163
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
215
- if (Number(product.price) === 0 || !product.price)
216
- return false;
217
- const targetUsedDiscounts = usedDiscounts.get(discount.id);
218
- if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
164
+ if (usedDiscounts.get(discount.id))
219
165
  return false;
220
166
  const limitedData = discount.limited_relation_product_data;
221
167
  if (limitedData.type === "product_all") {
@@ -227,17 +173,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
227
173
  });
228
174
  const selectedDiscount = applicableDiscounts[0];
229
175
  let isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (!((_c = product.discount_list) == null ? void 0 : _c.length) || ((_e = (_d = product == null ? void 0 : product.discount_list) == null ? void 0 : _d.every) == null ? void 0 : _e.call(_d, (item) => item.type === "product")));
230
- if ((options == null ? void 0 : options.discountId) && product.discount_list.some((item) => {
231
- var _a2;
232
- return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
233
- })) {
176
+ if ((options == null ? void 0 : options.discountId) && (options == null ? void 0 : options.discountId) === (selectedDiscount == null ? void 0 : selectedDiscount.id)) {
234
177
  isManualDiscount = false;
235
178
  }
236
179
  if (applicableDiscounts.length === 0 || isManualDiscount) {
237
180
  if (product.isClient) {
238
181
  processedProductsMap.set(
239
182
  product._id,
240
- [this.hooks.setProduct(originProduct, {
183
+ this.hooks.setProduct(originProduct, {
241
184
  ...isManualDiscount ? {} : {
242
185
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
243
186
  product: {
@@ -246,8 +189,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
246
189
  bundle: product.bundle,
247
190
  options: product.options
248
191
  }),
249
- variant: originProduct._productInit.variant,
250
- original_price: originProduct._productInit.original_price,
251
192
  total: (0, import_utils2.getProductTotalPrice)({
252
193
  product: {
253
194
  price: product.price
@@ -258,102 +199,74 @@ var RulesModule = class extends import_BaseModule.BaseModule {
258
199
  price: product.price
259
200
  },
260
201
  discount_list: []
261
- })]
202
+ })
262
203
  );
263
204
  } else {
264
205
  processedProductsMap.set(
265
206
  product._id,
266
- [this.hooks.setProduct(originProduct, {
207
+ this.hooks.setProduct(originProduct, {
267
208
  ...isManualDiscount ? {} : {
268
- _id: product._id.split("___")[0] + "___" + i,
269
209
  total: product.origin_total || product.total,
270
210
  price: product.price
271
211
  },
272
212
  discount_list: []
273
- })]
213
+ })
274
214
  );
275
215
  }
276
216
  return;
277
217
  }
278
- if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
218
+ if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan)) {
279
219
  return;
280
220
  }
281
- const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
282
- const splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
283
- const arr = [];
284
- if (splitCount < product.quantity && isNeedSplit) {
285
- arr.push(this.hooks.setProduct(originProduct, {
286
- discount_list: [],
287
- quantity: product.quantity - splitCount,
288
- _id: product._id.split("___")[0]
289
- }));
290
- }
291
- for (let i2 = 0; i2 < splitCount; i2++) {
292
- const selectedDiscount2 = applicableDiscounts[i2];
293
- usedDiscounts.set(selectedDiscount2.id, true);
294
- const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
295
- const targetProductPrice = selectedDiscount2.tag === "good_pass" ? "0" : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(product.price || 0)).toFixed(2);
296
- const discountDetail = {
297
- amount: selectedDiscount2.tag === "good_pass" ? product.price : new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice)).toNumber(),
298
- type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
299
- discount: {
300
- resource_id: selectedDiscount2.id,
301
- title: selectedDiscount2.format_title,
302
- original_amount: product.origin_total || product.price,
303
- product_id: originProduct.id,
304
- percent: selectedDiscount2.par_value
305
- },
306
- num: product.num || 1
307
- };
308
- appliedProducts.push(discountDetail);
309
- appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
310
- if (product.isClient) {
311
- const variant = (_f = originProduct._productOrigin.variant) == null ? void 0 : _f.map((n) => {
312
- var _a2;
313
- if (n.id === ((_a2 = originProduct._productOrigin) == null ? void 0 : _a2.product_variant_id)) {
314
- n.original_price = n.price;
315
- const targetProductPrice2 = selectedDiscount2.tag === "good_pass" ? "0" : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(n.price || 0)).toFixed(2);
316
- n.price = targetProductPrice2;
317
- }
318
- return n;
319
- });
320
- arr.push(this.hooks.setProduct(originProduct, {
221
+ usedDiscounts.set(selectedDiscount.id, true);
222
+ const appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
223
+ const discountDetail = {
224
+ amount: product.price,
225
+ type: selectedDiscount.tag,
226
+ discount: {
227
+ resource_id: selectedDiscount.id,
228
+ title: selectedDiscount.format_title,
229
+ original_amount: product.origin_total,
230
+ product_id: selectedDiscount.product_id
231
+ }
232
+ };
233
+ appliedProducts.push(discountDetail);
234
+ appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
235
+ if (product.isClient) {
236
+ processedProductsMap.set(
237
+ product._id,
238
+ this.hooks.setProduct(originProduct, {
321
239
  discount_list: [discountDetail],
322
- price: new import_decimal.default(targetProductPrice).toNumber(),
323
- quantity: isNeedSplit ? 1 : product.quantity,
240
+ price: 0,
324
241
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
325
242
  product: {
326
- original_price: targetProductPrice
243
+ original_price: product.original_price
327
244
  },
328
245
  bundle: product.bundle,
329
246
  options: product.options
330
247
  }),
331
- variant,
332
- original_price: new import_decimal.default(product.price).toNumber(),
333
248
  total: (0, import_utils2.getProductTotalPrice)({
334
249
  product: {
335
- price: targetProductPrice
250
+ price: "0"
336
251
  },
337
252
  bundle: product.bundle,
338
253
  options: product.options
339
254
  })
340
- }));
341
- } else {
342
- arr.push(this.hooks.setProduct(originProduct, {
255
+ })
256
+ );
257
+ } else {
258
+ processedProductsMap.set(
259
+ product._id,
260
+ this.hooks.setProduct(originProduct, {
343
261
  discount_list: [discountDetail],
344
- _id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
345
- price: new import_decimal.default(targetProductPrice).toNumber(),
346
- quantity: isNeedSplit ? 1 : product.quantity,
347
- total: new import_decimal.default(product.origin_total || product.total || 0).minus(new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice))).toNumber(),
262
+ price: 0,
263
+ total: (product.origin_total || product.total) - product.price,
348
264
  origin_total: product.origin_total || product.total
349
- }));
350
- }
265
+ })
266
+ );
351
267
  }
352
- console.log(arr, "arrarrarr");
353
- processedProductsMap.set(product._id, arr);
354
268
  });
355
- const processedProductList = [];
356
- productList.forEach((originProduct) => {
269
+ const processedProductList = productList.map((originProduct) => {
357
270
  const product = this.hooks.getProduct(originProduct);
358
271
  const getDefaultProduct = () => {
359
272
  if (product.isClient) {
@@ -367,8 +280,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
367
280
  bundle: product.bundle,
368
281
  options: product.options
369
282
  }),
370
- variant: originProduct._productInit.variant,
371
- original_price: originProduct._productInit.original_price,
372
283
  total: (0, import_utils2.getProductTotalPrice)({
373
284
  product: {
374
285
  price: product.price
@@ -386,8 +297,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
386
297
  });
387
298
  }
388
299
  };
389
- const arr = processedProductsMap.get(product._id);
390
- (arr == null ? void 0 : arr.length) ? processedProductList.push(...arr) : processedProductList.push(getDefaultProduct());
300
+ return processedProductsMap.get(product._id) || getDefaultProduct();
391
301
  });
392
302
  const updatedDiscountList = addModeDiscount.map((discount) => {
393
303
  const applicableProducts = discountApplicability.get(discount.id) || [];
@@ -440,7 +350,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
440
350
  appliedProductDetails: []
441
351
  };
442
352
  });
443
- console.log(processedProductList, "processedProductList");
444
353
  return {
445
354
  productList: processedProductList,
446
355
  discountList: [...editModeDiscount, ...updatedDiscountList]
@@ -37,20 +37,14 @@ type ProductDetail = {
37
37
  options?: any[];
38
38
  bundle?: any[];
39
39
  original_price?: number | string;
40
- num?: number;
41
- quantity: number;
42
40
  };
43
41
  export interface RulesParamsHooks {
44
42
  getProduct: (product: Record<string, any>) => ProductDetail;
45
43
  setProduct: (product: Record<string, any>, values: {
46
- _id?: string;
47
44
  total?: number;
48
45
  discount_list: any[];
49
46
  origin_total?: number;
50
47
  price?: number;
51
- quantity?: number;
52
- variant?: any[];
53
- original_price?: number;
54
48
  }) => Record<string, any>;
55
49
  }
56
50
  export {};