@pisell/pisellos 3.0.42 → 3.0.44

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/AccountList/index.js +17 -12
  2. package/dist/modules/Cart/index.d.ts +14 -0
  3. package/dist/modules/Cart/index.js +38 -1
  4. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -0
  5. package/dist/modules/Cart/utils/cartProduct.js +28 -8
  6. package/dist/modules/Date/index.js +70 -6
  7. package/dist/modules/Discount/index.d.ts +1 -0
  8. package/dist/modules/Discount/index.js +13 -6
  9. package/dist/modules/Discount/types.d.ts +10 -0
  10. package/dist/modules/ProductList/index.d.ts +7 -0
  11. package/dist/modules/ProductList/index.js +102 -39
  12. package/dist/modules/Rules/index.js +218 -80
  13. package/dist/modules/Rules/types.d.ts +7 -1
  14. package/dist/modules/Schedule/index.d.ts +9 -1
  15. package/dist/modules/Schedule/index.js +122 -2
  16. package/dist/modules/Schedule/types.d.ts +13 -0
  17. package/dist/solution/BookingByStep/index.d.ts +120 -30
  18. package/dist/solution/BookingByStep/index.js +755 -1078
  19. package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
  20. package/dist/solution/BookingByStep/utils/capacity.js +132 -0
  21. package/dist/solution/BookingByStep/utils/resources.d.ts +21 -29
  22. package/dist/solution/BookingByStep/utils/resources.js +39 -95
  23. package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  24. package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
  25. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  26. package/dist/solution/ShopDiscount/index.js +119 -44
  27. package/lib/modules/AccountList/index.js +4 -0
  28. package/lib/modules/Cart/index.d.ts +14 -0
  29. package/lib/modules/Cart/index.js +34 -1
  30. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -0
  31. package/lib/modules/Cart/utils/cartProduct.js +20 -8
  32. package/lib/modules/Date/index.js +59 -2
  33. package/lib/modules/Discount/index.d.ts +1 -0
  34. package/lib/modules/Discount/index.js +17 -6
  35. package/lib/modules/Discount/types.d.ts +10 -0
  36. package/lib/modules/ProductList/index.d.ts +7 -0
  37. package/lib/modules/ProductList/index.js +45 -0
  38. package/lib/modules/Rules/index.js +154 -63
  39. package/lib/modules/Rules/types.d.ts +7 -1
  40. package/lib/modules/Schedule/index.d.ts +9 -1
  41. package/lib/modules/Schedule/index.js +79 -1
  42. package/lib/modules/Schedule/types.d.ts +13 -0
  43. package/lib/solution/BookingByStep/index.d.ts +120 -30
  44. package/lib/solution/BookingByStep/index.js +391 -589
  45. package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
  46. package/lib/solution/BookingByStep/utils/capacity.js +106 -0
  47. package/lib/solution/BookingByStep/utils/resources.d.ts +21 -29
  48. package/lib/solution/BookingByStep/utils/resources.js +21 -58
  49. package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  50. package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
  51. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  52. package/lib/solution/ShopDiscount/index.js +91 -19
  53. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
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
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/modules/Discount/index.ts
@@ -25,6 +35,7 @@ module.exports = __toCommonJS(Discount_exports);
25
35
  var import_utils = require("../../solution/ShopDiscount/utils");
26
36
  var import_BaseModule = require("../BaseModule");
27
37
  var import_types = require("./types");
38
+ var import_decimal = __toESM(require("decimal.js"));
28
39
  var DiscountModule = class extends import_BaseModule.BaseModule {
29
40
  constructor(name, version) {
30
41
  super(name, version);
@@ -68,13 +79,13 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
68
79
  return this.store.discountList;
69
80
  }
70
81
  async loadPrepareConfig(params) {
71
- var _a;
82
+ var _a, _b;
72
83
  const prepareConfig = await this.request.post(
73
84
  `/order/prepare/config`,
74
85
  params
75
86
  );
76
87
  const goodPassList = this.filterEnabledDiscountList(
77
- ((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || []
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) || []]
78
89
  ) || [];
79
90
  return goodPassList;
80
91
  }
@@ -82,7 +93,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
82
93
  const result = await this.request.get(`/machinecode/batch-search`, {
83
94
  code,
84
95
  translate_flag: 1,
85
- tag: "good_pass",
96
+ tags: ["good_pass", "product_discount_card"],
86
97
  available: 1,
87
98
  relation_product: 1
88
99
  });
@@ -91,7 +102,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
91
102
  }
92
103
  filterEnabledDiscountList(discountList) {
93
104
  return discountList.filter(
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
105
+ (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)
95
106
  );
96
107
  }
97
108
  // 根据productIds去重
@@ -110,8 +121,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
110
121
  }
111
122
  if (discount.appliedProductDetails) {
112
123
  return discount.appliedProductDetails.reduce((total, product) => {
113
- const price = Number(product == null ? void 0 : product.amount) || 0;
114
- return total + price;
124
+ const price = new import_decimal.default((product == null ? void 0 : product.amount) || 0).mul((product == null ? void 0 : product.num) || 1);
125
+ return new import_decimal.default(total).plus(price).toNumber();
115
126
  }, 0);
116
127
  }
117
128
  }
@@ -27,6 +27,14 @@ 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
+ };
30
38
  }
31
39
  export interface Discount {
32
40
  id: number;
@@ -60,6 +68,8 @@ export interface Discount {
60
68
  applicableProductIds?: number[];
61
69
  applicableProductDetails: ApplicableProductDetails[];
62
70
  appliedProductDetails: ApplicableProductDetails[];
71
+ isDisabledForProductUsed?: boolean;
72
+ amount?: number;
63
73
  }
64
74
  export interface DiscountState {
65
75
  discountList: Discount[];
@@ -11,6 +11,13 @@ 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>;
14
21
  loadProductsPrice({ ids, customer_id, schedule_date, channel, }: {
15
22
  ids?: number[];
16
23
  customer_id?: number;
@@ -64,6 +64,51 @@ 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
+ }
67
112
  async loadProductsPrice({
68
113
  ids = [],
69
114
  customer_id,
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
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
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/modules/Rules/index.ts
@@ -26,6 +36,7 @@ var import_BaseModule = require("../BaseModule");
26
36
  var import_types = require("./types");
27
37
  var import_utils = require("../../solution/ShopDiscount/utils");
28
38
  var import_utils2 = require("../Cart/utils");
39
+ var import_decimal = __toESM(require("decimal.js"));
29
40
  var RulesModule = class extends import_BaseModule.BaseModule {
30
41
  constructor(name, version) {
31
42
  super(name, version);
@@ -58,8 +69,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
58
69
  productList
59
70
  };
60
71
  }
72
+ if (productList.every((item) => {
73
+ var _a;
74
+ const product = this.hooks.getProduct(item);
75
+ return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) || (newDiscountList[0].tag === "good_pass" ? product.price == 0 : product.total == 0));
76
+ })) {
77
+ return {
78
+ isAvailable: false,
79
+ discountList: oldDiscountList,
80
+ productList
81
+ };
82
+ }
83
+ const filteredOldDiscountList = oldDiscountList.filter((discount) => !discount.isEditMode && discount.tag !== "good_pass");
61
84
  const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
62
- ...oldDiscountList,
85
+ ...filteredOldDiscountList,
63
86
  ...newDiscountList
64
87
  ]), "product_id");
65
88
  const result = this.calcDiscount({
@@ -94,6 +117,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
94
117
  discountList,
95
118
  productList
96
119
  }, options) {
120
+ const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
97
121
  const editModeDiscount = [];
98
122
  const addModeDiscount = [];
99
123
  discountList.forEach((discount) => {
@@ -107,19 +131,43 @@ var RulesModule = class extends import_BaseModule.BaseModule {
107
131
  return !discount.isManualSelect;
108
132
  });
109
133
  const sortedDiscountList = [...filteredDiscountList].sort((a, b) => {
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;
134
+ if (a.tag === "good_pass" && b.tag !== "good_pass")
135
+ return -1;
136
+ if (b.tag === "good_pass" && a.tag !== "good_pass")
137
+ return 1;
138
+ if (a.tag === "good_pass" && b.tag === "good_pass") {
139
+ return compareByExpireTime(a, b);
140
+ } else if (a.tag === "product_discount_card" && b.tag === "product_discount_card") {
141
+ if (a.par_value !== b.par_value) {
142
+ const valueA = new import_decimal.default(100).minus(a.par_value || 0);
143
+ const valueB = new import_decimal.default(100).minus(b.par_value || 0);
144
+ return valueA.minus(valueB).toNumber();
145
+ }
146
+ return compareByExpireTime(a, b);
147
+ }
148
+ return compareByExpireTime(a, b);
149
+ function compareByExpireTime(itemA, itemB) {
150
+ if (itemA.expire_time && itemB.expire_time) {
151
+ const timeA = new Date(itemA.expire_time).getTime();
152
+ const timeB = new Date(itemB.expire_time).getTime();
153
+ return timeA - timeB;
154
+ }
155
+ return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
114
156
  }
115
- return a.expire_time ? -1 : b.expire_time ? 1 : 0;
116
157
  });
117
158
  const sortedProductList = [...productList].sort((a, b) => {
159
+ var _a, _b;
118
160
  const aProduct = this.hooks.getProduct(a);
119
161
  const bProduct = this.hooks.getProduct(b);
120
- const priceA = parseFloat(aProduct.price || "0");
121
- const priceB = parseFloat(bProduct.price || "0");
122
- return priceB - priceA;
162
+ const priceA = new import_decimal.default(aProduct.price || "0");
163
+ const priceB = new import_decimal.default(bProduct.price || "0");
164
+ if (priceA.toNumber() === priceB.toNumber()) {
165
+ if (aProduct.quantity === bProduct.quantity) {
166
+ return ((_a = bProduct.discount_list) == null ? void 0 : _a.length) - ((_b = aProduct.discount_list) == null ? void 0 : _b.length);
167
+ }
168
+ return aProduct.quantity - bProduct.quantity;
169
+ }
170
+ return priceB.toNumber() - priceA.toNumber();
123
171
  });
124
172
  const usedDiscounts = /* @__PURE__ */ new Map();
125
173
  const discountApplicability = /* @__PURE__ */ new Map();
@@ -136,32 +184,42 @@ var RulesModule = class extends import_BaseModule.BaseModule {
136
184
  var _a, _b, _c;
137
185
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
138
186
  const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
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")));
187
+ 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))));
140
188
  if (isAvailableProduct && isLimitedProduct) {
141
189
  (_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
142
190
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
143
191
  applicableProducts.push({
144
192
  amount: product.price,
145
- type: discount.tag,
193
+ type: discount.tag || discount.type,
194
+ tag: discount.tag || discount.type,
146
195
  discount: {
147
196
  resource_id: discount.id,
148
197
  title: discount.format_title,
149
- original_amount: product.origin_total
150
- }
198
+ original_amount: product.origin_total,
199
+ pre_value: discount.par_value,
200
+ product_id: originProduct.id
201
+ },
202
+ num: product.num || 1
151
203
  });
152
204
  discountApplicableProducts.set(discount.id, applicableProducts);
153
205
  }
154
206
  });
155
207
  });
156
- sortedProductList.forEach((originProduct) => {
157
- var _a, _b, _c, _d, _e;
208
+ console.log(sortedProductList, "sortedProductListsortedProductList");
209
+ sortedProductList.forEach((originProduct, i) => {
210
+ var _a, _b, _c, _d, _e, _f, _g, _h;
158
211
  const product = this.hooks.getProduct(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
+ 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)))) {
213
+ processedProductsMap.set(product._id, [originProduct]);
161
214
  return;
162
215
  }
163
216
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
164
- if (usedDiscounts.get(discount.id))
217
+ if ((Number(product.price) === 0 || !product.price) && (discount.tag || discount.type) === "good_pass")
218
+ return false;
219
+ if ((Number(product.total) === 0 || !product.total) && (discount.tag || discount.type) !== "good_pass")
220
+ return false;
221
+ const targetUsedDiscounts = usedDiscounts.get(discount.id);
222
+ if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
165
223
  return false;
166
224
  const limitedData = discount.limited_relation_product_data;
167
225
  if (limitedData.type === "product_all") {
@@ -171,16 +229,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
171
229
  }
172
230
  return false;
173
231
  });
174
- const selectedDiscount = applicableDiscounts[0];
232
+ const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass");
233
+ const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
175
234
  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")));
176
- if ((options == null ? void 0 : options.discountId) && (options == null ? void 0 : options.discountId) === (selectedDiscount == null ? void 0 : selectedDiscount.id)) {
235
+ if ((options == null ? void 0 : options.discountId) && ((_f = product.discount_list) == null ? void 0 : _f.some((item) => {
236
+ var _a2;
237
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
238
+ }))) {
177
239
  isManualDiscount = false;
178
240
  }
179
241
  if (applicableDiscounts.length === 0 || isManualDiscount) {
180
242
  if (product.isClient) {
181
243
  processedProductsMap.set(
182
244
  product._id,
183
- this.hooks.setProduct(originProduct, {
245
+ [this.hooks.setProduct(originProduct, {
184
246
  ...isManualDiscount ? {} : {
185
247
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
186
248
  product: {
@@ -189,6 +251,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
189
251
  bundle: product.bundle,
190
252
  options: product.options
191
253
  }),
254
+ variant: originProduct._productInit.variant,
255
+ original_price: originProduct._productInit.original_price,
192
256
  total: (0, import_utils2.getProductTotalPrice)({
193
257
  product: {
194
258
  price: product.price
@@ -199,45 +263,67 @@ var RulesModule = class extends import_BaseModule.BaseModule {
199
263
  price: product.price
200
264
  },
201
265
  discount_list: []
202
- })
266
+ })]
203
267
  );
204
268
  } else {
205
269
  processedProductsMap.set(
206
270
  product._id,
207
- this.hooks.setProduct(originProduct, {
271
+ [this.hooks.setProduct(originProduct, {
208
272
  ...isManualDiscount ? {} : {
273
+ _id: product._id.split("___")[0] + "___" + i,
209
274
  total: product.origin_total || product.total,
210
275
  price: product.price
211
276
  },
212
277
  discount_list: []
213
- })
278
+ })]
214
279
  );
215
280
  }
216
281
  return;
217
282
  }
218
- if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan)) {
283
+ if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
219
284
  return;
220
285
  }
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
286
+ const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
287
+ const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
288
+ const arr = [];
289
+ if (splitCount < product.quantity && isNeedSplit) {
290
+ arr.push(this.hooks.setProduct(originProduct, {
291
+ discount_list: [],
292
+ quantity: product.quantity - splitCount,
293
+ _id: product._id.split("___")[0]
294
+ }));
295
+ }
296
+ for (let i2 = 0; i2 < splitCount; i2++) {
297
+ const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i2];
298
+ usedDiscounts.set(selectedDiscount2.id, true);
299
+ const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
300
+ let productOriginTotal = product.origin_total || product.total || 0;
301
+ if (Number(((_g = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _g.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
302
+ productOriginTotal = product.total;
231
303
  }
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, {
304
+ if (((_h = product.discount_list) == null ? void 0 : _h.length) && product.origin_total) {
305
+ productOriginTotal = product.origin_total;
306
+ }
307
+ const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(productOriginTotal).minus(new import_decimal.default(product.price || 0)).toNumber() : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(productOriginTotal)).toNumber();
308
+ const discountDetail = {
309
+ amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
310
+ type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
311
+ discount: {
312
+ resource_id: selectedDiscount2.id,
313
+ title: selectedDiscount2.format_title,
314
+ original_amount: productOriginTotal,
315
+ product_id: originProduct.id,
316
+ percent: selectedDiscount2.par_value
317
+ },
318
+ num: product.num || 1
319
+ };
320
+ appliedProducts.push(discountDetail);
321
+ appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
322
+ if (product.isClient) {
323
+ arr.push(this.hooks.setProduct(originProduct, {
239
324
  discount_list: [discountDetail],
240
- price: 0,
325
+ price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
326
+ quantity: isNeedSplit ? 1 : product.quantity,
241
327
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
242
328
  product: {
243
329
  original_price: product.original_price
@@ -245,28 +331,26 @@ var RulesModule = class extends import_BaseModule.BaseModule {
245
331
  bundle: product.bundle,
246
332
  options: product.options
247
333
  }),
248
- total: (0, import_utils2.getProductTotalPrice)({
249
- product: {
250
- price: "0"
251
- },
252
- bundle: product.bundle,
253
- options: product.options
254
- })
255
- })
256
- );
257
- } else {
258
- processedProductsMap.set(
259
- product._id,
260
- this.hooks.setProduct(originProduct, {
334
+ variant: originProduct._productInit.variant,
335
+ original_price: new import_decimal.default(product.price || 0).toNumber(),
336
+ total: targetProductTotal
337
+ }));
338
+ } else {
339
+ arr.push(this.hooks.setProduct(originProduct, {
261
340
  discount_list: [discountDetail],
262
- price: 0,
263
- total: (product.origin_total || product.total) - product.price,
264
- origin_total: product.origin_total || product.total
265
- })
266
- );
341
+ _id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
342
+ price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
343
+ quantity: isNeedSplit ? 1 : product.quantity,
344
+ total: targetProductTotal,
345
+ origin_total: productOriginTotal
346
+ }));
347
+ }
267
348
  }
349
+ console.log(arr, "arrarrarr");
350
+ processedProductsMap.set(product._id, arr);
268
351
  });
269
- const processedProductList = productList.map((originProduct) => {
352
+ const processedProductList = [];
353
+ productList.forEach((originProduct) => {
270
354
  const product = this.hooks.getProduct(originProduct);
271
355
  const getDefaultProduct = () => {
272
356
  if (product.isClient) {
@@ -280,6 +364,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
280
364
  bundle: product.bundle,
281
365
  options: product.options
282
366
  }),
367
+ variant: originProduct._productInit.variant,
368
+ original_price: originProduct._productInit.original_price,
283
369
  total: (0, import_utils2.getProductTotalPrice)({
284
370
  product: {
285
371
  price: product.price
@@ -297,7 +383,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
297
383
  });
298
384
  }
299
385
  };
300
- return processedProductsMap.get(product._id) || getDefaultProduct();
386
+ const arr = processedProductsMap.get(product._id);
387
+ (arr == null ? void 0 : arr.length) ? processedProductList.push(...arr) : processedProductList.push(getDefaultProduct());
301
388
  });
302
389
  const updatedDiscountList = addModeDiscount.map((discount) => {
303
390
  const applicableProducts = discountApplicability.get(discount.id) || [];
@@ -321,6 +408,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
321
408
  return {
322
409
  ...discount,
323
410
  isSelected: true,
411
+ isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
324
412
  // 标记为可用,因为它已被应用
325
413
  isAvailable: true,
326
414
  // 记录适用的商品IDs
@@ -342,6 +430,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
342
430
  // 如果有适用的商品,标记为可用
343
431
  isAvailable,
344
432
  isSelected,
433
+ // 如果是扫码进来的,要手动设置为手动选择:false
434
+ isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
345
435
  // 记录适用的商品IDs
346
436
  applicableProductIds: applicableProducts,
347
437
  // 添加可抵扣的商品详情
@@ -350,6 +440,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
350
440
  appliedProductDetails: []
351
441
  };
352
442
  });
443
+ console.log(processedProductList, "processedProductList");
353
444
  return {
354
445
  productList: processedProductList,
355
446
  discountList: [...editModeDiscount, ...updatedDiscountList]
@@ -37,14 +37,20 @@ type ProductDetail = {
37
37
  options?: any[];
38
38
  bundle?: any[];
39
39
  original_price?: number | string;
40
+ num?: number;
41
+ quantity: number;
40
42
  };
41
43
  export interface RulesParamsHooks {
42
44
  getProduct: (product: Record<string, any>) => ProductDetail;
43
45
  setProduct: (product: Record<string, any>, values: {
46
+ _id?: string;
44
47
  total?: number;
45
48
  discount_list: any[];
46
49
  origin_total?: number;
47
- price?: number;
50
+ price?: string | number;
51
+ variant?: any[];
52
+ original_price?: number;
53
+ quantity?: number;
48
54
  }) => Record<string, any>;
49
55
  }
50
56
  export {};
@@ -1,16 +1,24 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { ScheduleModuleAPI, ScheduleAvailabilityDateItem, ScheduleItem } from './types';
3
+ import { ScheduleModuleAPI, ScheduleAvailabilityDateItem, ScheduleItem, LoadScheduleAvailableDateParams } from './types';
4
4
  export declare class ScheduleModule extends BaseModule implements Module, ScheduleModuleAPI {
5
5
  protected defaultName: string;
6
6
  protected defaultVersion: string;
7
+ private request;
7
8
  private store;
8
9
  private cacheId;
9
10
  private openCache;
10
11
  private fatherModule;
11
12
  constructor(name?: string, version?: string);
12
13
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
14
+ /**
15
+ * 加载当前店铺下所有 schedule
16
+ *
17
+ * @memberof ScheduleModule
18
+ */
19
+ loadAllSchedule(): Promise<void>;
13
20
  setScheduleList(list: ScheduleItem[]): void;
21
+ loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: LoadScheduleAvailableDateParams): Promise<import("../Date/types").ITime[]>;
14
22
  getScheduleListByIds(ids: number[]): ScheduleItem[];
15
23
  setAvailabilityScheduleDateList(list: ScheduleAvailabilityDateItem[]): void;
16
24
  getAvailabilityScheduleDateList(): ScheduleAvailabilityDateItem[];