@pisell/pisellos 2.0.38 → 2.0.40
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.
- package/dist/modules/AccountList/index.js +17 -12
- package/dist/modules/Cart/index.d.ts +14 -0
- package/dist/modules/Cart/index.js +38 -1
- package/dist/modules/Cart/utils/cartProduct.d.ts +2 -0
- package/dist/modules/Cart/utils/cartProduct.js +23 -5
- package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
- package/dist/modules/Cart/utils/changePrice.js +104 -0
- package/dist/modules/Date/index.js +57 -6
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +13 -6
- package/dist/modules/Discount/types.d.ts +10 -0
- package/dist/modules/ProductList/index.d.ts +7 -0
- package/dist/modules/ProductList/index.js +102 -39
- package/dist/modules/Rules/index.js +191 -75
- package/dist/modules/Rules/types.d.ts +7 -1
- package/dist/modules/Schedule/index.d.ts +9 -1
- package/dist/modules/Schedule/index.js +122 -2
- package/dist/modules/Schedule/types.d.ts +13 -0
- package/dist/solution/BookingByStep/index.d.ts +120 -30
- package/dist/solution/BookingByStep/index.js +750 -1078
- package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/dist/solution/BookingByStep/utils/capacity.js +132 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +29 -31
- package/dist/solution/BookingByStep/utils/resources.js +39 -94
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +119 -44
- package/lib/modules/AccountList/index.js +4 -0
- package/lib/modules/Cart/index.d.ts +14 -0
- package/lib/modules/Cart/index.js +34 -1
- package/lib/modules/Cart/utils/cartProduct.d.ts +2 -0
- package/lib/modules/Cart/utils/cartProduct.js +16 -5
- package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
- package/lib/modules/Cart/utils/changePrice.js +78 -0
- package/lib/modules/Date/index.js +62 -10
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +17 -6
- package/lib/modules/Discount/types.d.ts +10 -0
- package/lib/modules/ProductList/index.d.ts +7 -0
- package/lib/modules/ProductList/index.js +45 -0
- package/lib/modules/Rules/index.js +142 -62
- package/lib/modules/Rules/types.d.ts +7 -1
- package/lib/modules/Schedule/index.d.ts +9 -1
- package/lib/modules/Schedule/index.js +79 -1
- package/lib/modules/Schedule/types.d.ts +13 -0
- package/lib/solution/BookingByStep/index.d.ts +120 -30
- package/lib/solution/BookingByStep/index.js +389 -587
- package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/lib/solution/BookingByStep/utils/capacity.js +106 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +29 -31
- package/lib/solution/BookingByStep/utils/resources.js +23 -59
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +91 -19
- 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/Date/index.ts
|
|
@@ -24,6 +34,7 @@ __export(Date_exports, {
|
|
|
24
34
|
module.exports = __toCommonJS(Date_exports);
|
|
25
35
|
var import_BaseModule = require("../BaseModule");
|
|
26
36
|
var import_utils = require("./utils");
|
|
37
|
+
var import_cloneDeep = __toESM(require("lodash-es/cloneDeep"));
|
|
27
38
|
var DateModule = class extends import_BaseModule.BaseModule {
|
|
28
39
|
constructor(name, version) {
|
|
29
40
|
super(name, version);
|
|
@@ -58,29 +69,70 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
58
69
|
return this.store.dateRange;
|
|
59
70
|
}
|
|
60
71
|
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
|
+
}
|
|
61
86
|
const dates = await this.getResourceAvailableTimeList(params);
|
|
62
|
-
this.
|
|
87
|
+
this.setDateList(dates);
|
|
63
88
|
return dates;
|
|
64
89
|
}
|
|
65
90
|
getDateList() {
|
|
66
91
|
return this.store.dateList;
|
|
67
92
|
}
|
|
68
93
|
setDateList(dateList) {
|
|
69
|
-
this.store.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;
|
|
70
118
|
}
|
|
71
119
|
async fetchResourceDates(params) {
|
|
72
120
|
const { url, query } = params;
|
|
73
121
|
const fetchUrl = url || "/schedule/resource/list";
|
|
74
122
|
const { start_date, end_date, resource_ids } = query || {};
|
|
75
123
|
try {
|
|
76
|
-
const res = await this.request.get(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
+
);
|
|
84
136
|
return res;
|
|
85
137
|
} catch (error) {
|
|
86
138
|
console.error(error);
|
|
@@ -17,6 +17,7 @@ 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;
|
|
20
21
|
customer_id: number;
|
|
21
22
|
}): Promise<Discount[]>;
|
|
22
23
|
batchSearch(code: string): Promise<Discount[]>;
|
|
@@ -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
|
-
|
|
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" &&
|
|
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 =
|
|
114
|
-
return total
|
|
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,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
58
69
|
productList
|
|
59
70
|
};
|
|
60
71
|
}
|
|
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
|
+
const filteredOldDiscountList = oldDiscountList.filter((discount) => !discount.isEditMode && discount.tag !== "good_pass");
|
|
61
83
|
const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
|
|
62
|
-
...
|
|
84
|
+
...filteredOldDiscountList,
|
|
63
85
|
...newDiscountList
|
|
64
86
|
]), "product_id");
|
|
65
87
|
const result = this.calcDiscount({
|
|
@@ -94,6 +116,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
94
116
|
discountList,
|
|
95
117
|
productList
|
|
96
118
|
}, options) {
|
|
119
|
+
const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
|
|
97
120
|
const editModeDiscount = [];
|
|
98
121
|
const addModeDiscount = [];
|
|
99
122
|
discountList.forEach((discount) => {
|
|
@@ -107,19 +130,43 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
107
130
|
return !discount.isManualSelect;
|
|
108
131
|
});
|
|
109
132
|
const sortedDiscountList = [...filteredDiscountList].sort((a, b) => {
|
|
110
|
-
if (a.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return
|
|
133
|
+
if (a.tag === "good_pass" && b.tag !== "good_pass")
|
|
134
|
+
return -1;
|
|
135
|
+
if (b.tag === "good_pass" && a.tag !== "good_pass")
|
|
136
|
+
return 1;
|
|
137
|
+
if (a.tag === "good_pass" && b.tag === "good_pass") {
|
|
138
|
+
return compareByExpireTime(a, b);
|
|
139
|
+
} else if (a.tag === "product_discount_card" && b.tag === "product_discount_card") {
|
|
140
|
+
if (a.par_value !== b.par_value) {
|
|
141
|
+
const valueA = new import_decimal.default(100).minus(a.par_value || 0);
|
|
142
|
+
const valueB = new import_decimal.default(100).minus(b.par_value || 0);
|
|
143
|
+
return valueA.minus(valueB).toNumber();
|
|
144
|
+
}
|
|
145
|
+
return compareByExpireTime(a, b);
|
|
146
|
+
}
|
|
147
|
+
return compareByExpireTime(a, b);
|
|
148
|
+
function compareByExpireTime(itemA, itemB) {
|
|
149
|
+
if (itemA.expire_time && itemB.expire_time) {
|
|
150
|
+
const timeA = new Date(itemA.expire_time).getTime();
|
|
151
|
+
const timeB = new Date(itemB.expire_time).getTime();
|
|
152
|
+
return timeA - timeB;
|
|
153
|
+
}
|
|
154
|
+
return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
|
|
114
155
|
}
|
|
115
|
-
return a.expire_time ? -1 : b.expire_time ? 1 : 0;
|
|
116
156
|
});
|
|
117
157
|
const sortedProductList = [...productList].sort((a, b) => {
|
|
158
|
+
var _a, _b;
|
|
118
159
|
const aProduct = this.hooks.getProduct(a);
|
|
119
160
|
const bProduct = this.hooks.getProduct(b);
|
|
120
|
-
const priceA =
|
|
121
|
-
const priceB =
|
|
122
|
-
|
|
161
|
+
const priceA = new import_decimal.default(aProduct.price || "0");
|
|
162
|
+
const priceB = new import_decimal.default(bProduct.price || "0");
|
|
163
|
+
if (priceA.toNumber() === priceB.toNumber()) {
|
|
164
|
+
if (aProduct.quantity === bProduct.quantity) {
|
|
165
|
+
return ((_a = bProduct.discount_list) == null ? void 0 : _a.length) - ((_b = aProduct.discount_list) == null ? void 0 : _b.length);
|
|
166
|
+
}
|
|
167
|
+
return aProduct.quantity - bProduct.quantity;
|
|
168
|
+
}
|
|
169
|
+
return priceB.toNumber() - priceA.toNumber();
|
|
123
170
|
});
|
|
124
171
|
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
125
172
|
const discountApplicability = /* @__PURE__ */ new Map();
|
|
@@ -136,32 +183,40 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
136
183
|
var _a, _b, _c;
|
|
137
184
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
138
185
|
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.
|
|
186
|
+
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
187
|
if (isAvailableProduct && isLimitedProduct) {
|
|
141
188
|
(_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
|
|
142
189
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
143
190
|
applicableProducts.push({
|
|
144
191
|
amount: product.price,
|
|
145
|
-
type: discount.tag,
|
|
192
|
+
type: discount.tag || discount.type,
|
|
193
|
+
tag: discount.tag || discount.type,
|
|
146
194
|
discount: {
|
|
147
195
|
resource_id: discount.id,
|
|
148
196
|
title: discount.format_title,
|
|
149
|
-
original_amount: product.origin_total
|
|
150
|
-
|
|
197
|
+
original_amount: product.origin_total,
|
|
198
|
+
pre_value: discount.par_value,
|
|
199
|
+
product_id: originProduct.id
|
|
200
|
+
},
|
|
201
|
+
num: product.num || 1
|
|
151
202
|
});
|
|
152
203
|
discountApplicableProducts.set(discount.id, applicableProducts);
|
|
153
204
|
}
|
|
154
205
|
});
|
|
155
206
|
});
|
|
156
|
-
|
|
157
|
-
|
|
207
|
+
console.log(sortedProductList, "sortedProductListsortedProductList");
|
|
208
|
+
sortedProductList.forEach((originProduct, i) => {
|
|
209
|
+
var _a, _b, _c, _d, _e, _f;
|
|
158
210
|
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.
|
|
160
|
-
processedProductsMap.set(product._id, originProduct);
|
|
211
|
+
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)))) {
|
|
212
|
+
processedProductsMap.set(product._id, [originProduct]);
|
|
161
213
|
return;
|
|
162
214
|
}
|
|
163
215
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
164
|
-
if (
|
|
216
|
+
if (Number(product.price) === 0 || !product.price)
|
|
217
|
+
return false;
|
|
218
|
+
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
219
|
+
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
165
220
|
return false;
|
|
166
221
|
const limitedData = discount.limited_relation_product_data;
|
|
167
222
|
if (limitedData.type === "product_all") {
|
|
@@ -173,14 +228,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
173
228
|
});
|
|
174
229
|
const selectedDiscount = applicableDiscounts[0];
|
|
175
230
|
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) && (
|
|
231
|
+
if ((options == null ? void 0 : options.discountId) && ((_f = product.discount_list) == null ? void 0 : _f.some((item) => {
|
|
232
|
+
var _a2;
|
|
233
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
234
|
+
}))) {
|
|
177
235
|
isManualDiscount = false;
|
|
178
236
|
}
|
|
179
237
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
180
238
|
if (product.isClient) {
|
|
181
239
|
processedProductsMap.set(
|
|
182
240
|
product._id,
|
|
183
|
-
this.hooks.setProduct(originProduct, {
|
|
241
|
+
[this.hooks.setProduct(originProduct, {
|
|
184
242
|
...isManualDiscount ? {} : {
|
|
185
243
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
186
244
|
product: {
|
|
@@ -189,6 +247,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
189
247
|
bundle: product.bundle,
|
|
190
248
|
options: product.options
|
|
191
249
|
}),
|
|
250
|
+
variant: originProduct._productInit.variant,
|
|
251
|
+
original_price: originProduct._productInit.original_price,
|
|
192
252
|
total: (0, import_utils2.getProductTotalPrice)({
|
|
193
253
|
product: {
|
|
194
254
|
price: product.price
|
|
@@ -199,45 +259,60 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
199
259
|
price: product.price
|
|
200
260
|
},
|
|
201
261
|
discount_list: []
|
|
202
|
-
})
|
|
262
|
+
})]
|
|
203
263
|
);
|
|
204
264
|
} else {
|
|
205
265
|
processedProductsMap.set(
|
|
206
266
|
product._id,
|
|
207
|
-
this.hooks.setProduct(originProduct, {
|
|
267
|
+
[this.hooks.setProduct(originProduct, {
|
|
208
268
|
...isManualDiscount ? {} : {
|
|
269
|
+
_id: product._id.split("___")[0] + "___" + i,
|
|
209
270
|
total: product.origin_total || product.total,
|
|
210
271
|
price: product.price
|
|
211
272
|
},
|
|
212
273
|
discount_list: []
|
|
213
|
-
})
|
|
274
|
+
})]
|
|
214
275
|
);
|
|
215
276
|
}
|
|
216
277
|
return;
|
|
217
278
|
}
|
|
218
|
-
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan)) {
|
|
279
|
+
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
|
|
219
280
|
return;
|
|
220
281
|
}
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
product.
|
|
238
|
-
|
|
282
|
+
const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
|
|
283
|
+
const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
|
|
284
|
+
const arr = [];
|
|
285
|
+
if (splitCount < product.quantity && isNeedSplit) {
|
|
286
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
287
|
+
discount_list: [],
|
|
288
|
+
quantity: product.quantity - splitCount,
|
|
289
|
+
_id: product._id.split("___")[0]
|
|
290
|
+
}));
|
|
291
|
+
}
|
|
292
|
+
for (let i2 = 0; i2 < splitCount; i2++) {
|
|
293
|
+
const selectedDiscount2 = applicableDiscounts[i2];
|
|
294
|
+
usedDiscounts.set(selectedDiscount2.id, true);
|
|
295
|
+
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
296
|
+
const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(product.origin_total || 0).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(product.origin_total || 0)).toNumber();
|
|
297
|
+
const discountDetail = {
|
|
298
|
+
amount: new import_decimal.default(product.origin_total || 0).minus(new import_decimal.default(targetProductTotal)).toNumber(),
|
|
299
|
+
type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
|
|
300
|
+
discount: {
|
|
301
|
+
resource_id: selectedDiscount2.id,
|
|
302
|
+
title: selectedDiscount2.format_title,
|
|
303
|
+
original_amount: product.origin_total,
|
|
304
|
+
product_id: originProduct.id,
|
|
305
|
+
percent: selectedDiscount2.par_value
|
|
306
|
+
},
|
|
307
|
+
num: product.num || 1
|
|
308
|
+
};
|
|
309
|
+
appliedProducts.push(discountDetail);
|
|
310
|
+
appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
|
|
311
|
+
if (product.isClient) {
|
|
312
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
239
313
|
discount_list: [discountDetail],
|
|
240
|
-
price: 0,
|
|
314
|
+
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
315
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
241
316
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
242
317
|
product: {
|
|
243
318
|
original_price: product.original_price
|
|
@@ -245,28 +320,26 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
245
320
|
bundle: product.bundle,
|
|
246
321
|
options: product.options
|
|
247
322
|
}),
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
})
|
|
255
|
-
})
|
|
256
|
-
);
|
|
257
|
-
} else {
|
|
258
|
-
processedProductsMap.set(
|
|
259
|
-
product._id,
|
|
260
|
-
this.hooks.setProduct(originProduct, {
|
|
323
|
+
variant: originProduct._productInit.variant,
|
|
324
|
+
original_price: new import_decimal.default(product.price || 0).toNumber(),
|
|
325
|
+
total: targetProductTotal
|
|
326
|
+
}));
|
|
327
|
+
} else {
|
|
328
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
261
329
|
discount_list: [discountDetail],
|
|
262
|
-
|
|
263
|
-
|
|
330
|
+
_id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
|
|
331
|
+
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
332
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
333
|
+
total: targetProductTotal,
|
|
264
334
|
origin_total: product.origin_total || product.total
|
|
265
|
-
})
|
|
266
|
-
|
|
335
|
+
}));
|
|
336
|
+
}
|
|
267
337
|
}
|
|
338
|
+
console.log(arr, "arrarrarr");
|
|
339
|
+
processedProductsMap.set(product._id, arr);
|
|
268
340
|
});
|
|
269
|
-
const processedProductList =
|
|
341
|
+
const processedProductList = [];
|
|
342
|
+
productList.forEach((originProduct) => {
|
|
270
343
|
const product = this.hooks.getProduct(originProduct);
|
|
271
344
|
const getDefaultProduct = () => {
|
|
272
345
|
if (product.isClient) {
|
|
@@ -280,6 +353,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
280
353
|
bundle: product.bundle,
|
|
281
354
|
options: product.options
|
|
282
355
|
}),
|
|
356
|
+
variant: originProduct._productInit.variant,
|
|
357
|
+
original_price: originProduct._productInit.original_price,
|
|
283
358
|
total: (0, import_utils2.getProductTotalPrice)({
|
|
284
359
|
product: {
|
|
285
360
|
price: product.price
|
|
@@ -297,7 +372,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
297
372
|
});
|
|
298
373
|
}
|
|
299
374
|
};
|
|
300
|
-
|
|
375
|
+
const arr = processedProductsMap.get(product._id);
|
|
376
|
+
(arr == null ? void 0 : arr.length) ? processedProductList.push(...arr) : processedProductList.push(getDefaultProduct());
|
|
301
377
|
});
|
|
302
378
|
const updatedDiscountList = addModeDiscount.map((discount) => {
|
|
303
379
|
const applicableProducts = discountApplicability.get(discount.id) || [];
|
|
@@ -321,6 +397,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
321
397
|
return {
|
|
322
398
|
...discount,
|
|
323
399
|
isSelected: true,
|
|
400
|
+
isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
|
|
324
401
|
// 标记为可用,因为它已被应用
|
|
325
402
|
isAvailable: true,
|
|
326
403
|
// 记录适用的商品IDs
|
|
@@ -342,6 +419,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
342
419
|
// 如果有适用的商品,标记为可用
|
|
343
420
|
isAvailable,
|
|
344
421
|
isSelected,
|
|
422
|
+
// 如果是扫码进来的,要手动设置为手动选择:false
|
|
423
|
+
isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
|
|
345
424
|
// 记录适用的商品IDs
|
|
346
425
|
applicableProductIds: applicableProducts,
|
|
347
426
|
// 添加可抵扣的商品详情
|
|
@@ -350,6 +429,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
350
429
|
appliedProductDetails: []
|
|
351
430
|
};
|
|
352
431
|
});
|
|
432
|
+
console.log(processedProductList, "processedProductList");
|
|
353
433
|
return {
|
|
354
434
|
productList: processedProductList,
|
|
355
435
|
discountList: [...editModeDiscount, ...updatedDiscountList]
|