@pisell/pisellos 1.0.5 → 1.0.7
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/Cart/index.d.ts +14 -0
- package/dist/modules/Cart/index.js +36 -0
- package/dist/modules/Cart/utils/cartProduct.js +1 -1
- package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
- package/dist/modules/Cart/utils/changePrice.js +100 -0
- package/dist/modules/Date/index.js +57 -6
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +15 -7
- 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 +59 -24
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/Schedule/index.d.ts +9 -1
- package/dist/modules/Schedule/index.js +121 -1
- package/dist/modules/Schedule/types.d.ts +13 -0
- package/dist/solution/BookingByStep/index.d.ts +120 -30
- package/dist/solution/BookingByStep/index.js +749 -1083
- 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 +1 -0
- package/dist/solution/ShopDiscount/index.js +63 -24
- package/lib/modules/Cart/index.d.ts +14 -0
- package/lib/modules/Cart/index.js +32 -0
- package/lib/modules/Cart/utils/cartProduct.js +1 -1
- package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
- package/lib/modules/Cart/utils/changePrice.js +64 -0
- package/lib/modules/Date/index.js +62 -10
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +18 -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 +59 -22
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/Schedule/index.d.ts +9 -1
- package/lib/modules/Schedule/index.js +78 -0
- package/lib/modules/Schedule/types.d.ts +13 -0
- package/lib/solution/BookingByStep/index.d.ts +120 -30
- package/lib/solution/BookingByStep/index.js +379 -581
- 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 +1 -0
- package/lib/solution/ShopDiscount/index.js +68 -18
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
3
|
import { CartItem, CartModuleAPI, ECartItemCheckType, ECartItemInfoType, IAddItemParams, IUpdateItemParams } from './types';
|
|
4
|
+
import { Account } from '../Account';
|
|
4
5
|
export * from './types';
|
|
5
6
|
/**
|
|
6
7
|
* 购物车模块实现
|
|
@@ -67,4 +68,17 @@ export declare class CartModule extends BaseModule implements Module, CartModule
|
|
|
67
68
|
clear(): void;
|
|
68
69
|
storeChange(): void;
|
|
69
70
|
checkCartItemByType(cartItem: CartItem, type: ECartItemCheckType): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* 基于rowkey 合并商品,目前只有普通商品需要合并
|
|
73
|
+
*
|
|
74
|
+
* @param {string} rowKey
|
|
75
|
+
* @param {number} quantity
|
|
76
|
+
* @return {*}
|
|
77
|
+
* @memberof CartModule
|
|
78
|
+
*/
|
|
79
|
+
mergeCartItemByRowKey(params: {
|
|
80
|
+
rowKey?: string;
|
|
81
|
+
quantity?: number;
|
|
82
|
+
account?: Account;
|
|
83
|
+
}): boolean;
|
|
70
84
|
}
|
|
@@ -27,6 +27,7 @@ var import_BaseModule = require("../BaseModule");
|
|
|
27
27
|
var import_types = require("./types");
|
|
28
28
|
var import_utils = require("./utils");
|
|
29
29
|
var import_lodash_es = require("lodash-es");
|
|
30
|
+
var import_utils2 = require("../Product/utils");
|
|
30
31
|
__reExport(Cart_exports, require("./types"), module.exports);
|
|
31
32
|
var CartModule = class extends import_BaseModule.BaseModule {
|
|
32
33
|
constructor(name, version) {
|
|
@@ -310,6 +311,37 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
310
311
|
}
|
|
311
312
|
return result;
|
|
312
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* 基于rowkey 合并商品,目前只有普通商品需要合并
|
|
316
|
+
*
|
|
317
|
+
* @param {string} rowKey
|
|
318
|
+
* @param {number} quantity
|
|
319
|
+
* @return {*}
|
|
320
|
+
* @memberof CartModule
|
|
321
|
+
*/
|
|
322
|
+
mergeCartItemByRowKey(params) {
|
|
323
|
+
const { rowKey, quantity, account } = params;
|
|
324
|
+
let flag = false;
|
|
325
|
+
const cartItems = this.getItems();
|
|
326
|
+
const targetCartItem = cartItems.find(
|
|
327
|
+
(n) => {
|
|
328
|
+
var _a;
|
|
329
|
+
return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
const isSameAccount = (account == null ? void 0 : account.id) === (targetCartItem == null ? void 0 : targetCartItem.holder_id);
|
|
333
|
+
if (rowKey && targetCartItem && (0, import_utils2.isNormalProduct)(targetCartItem._productOrigin) && isSameAccount) {
|
|
334
|
+
this.updateItem({
|
|
335
|
+
_id: targetCartItem._id,
|
|
336
|
+
product: {
|
|
337
|
+
...targetCartItem._productOrigin,
|
|
338
|
+
quantity: (targetCartItem.num || 1) + (quantity || 1)
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
flag = true;
|
|
342
|
+
}
|
|
343
|
+
return flag;
|
|
344
|
+
}
|
|
313
345
|
};
|
|
314
346
|
// Annotate the CommonJS export names for ESM import in node:
|
|
315
347
|
0 && (module.exports = {
|
|
@@ -194,7 +194,7 @@ var getProductOriginTotalPrice = (params) => {
|
|
|
194
194
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
195
195
|
}, price);
|
|
196
196
|
}
|
|
197
|
-
return price
|
|
197
|
+
return price;
|
|
198
198
|
};
|
|
199
199
|
var formatOptions = (options) => {
|
|
200
200
|
if (!(options == null ? void 0 : options.length))
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Product } from "../../Product";
|
|
2
|
+
import { CartItem, IUpdateItemParams } from "../types";
|
|
3
|
+
export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void): Promise<void>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/modules/Cart/utils/changePrice.ts
|
|
20
|
+
var changePrice_exports = {};
|
|
21
|
+
__export(changePrice_exports, {
|
|
22
|
+
updateAllCartItemPrice: () => updateAllCartItemPrice
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(changePrice_exports);
|
|
25
|
+
async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart) {
|
|
26
|
+
for (const item of cartItems) {
|
|
27
|
+
const targetProduct = priceData.find((n) => n.id === item.id);
|
|
28
|
+
const cartProduct = await getProduct(
|
|
29
|
+
item.id
|
|
30
|
+
);
|
|
31
|
+
const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
|
|
32
|
+
let bundle = item._bundleOrigin;
|
|
33
|
+
productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
|
|
34
|
+
productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
|
|
35
|
+
bundle = bundle == null ? void 0 : bundle.map((n) => {
|
|
36
|
+
var _a;
|
|
37
|
+
const targetBundle = (_a = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a.find(
|
|
38
|
+
(m) => m.id === n.group_id
|
|
39
|
+
);
|
|
40
|
+
if (targetBundle) {
|
|
41
|
+
const targetBundleItem = targetBundle.bundle_item.find(
|
|
42
|
+
(m) => m.id === n.id
|
|
43
|
+
);
|
|
44
|
+
if (targetBundleItem) {
|
|
45
|
+
return {
|
|
46
|
+
...n,
|
|
47
|
+
price: targetBundleItem.price,
|
|
48
|
+
base_price: targetBundleItem.base_price
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return n;
|
|
53
|
+
});
|
|
54
|
+
updateCart({
|
|
55
|
+
_id: item._id,
|
|
56
|
+
product: productInfo,
|
|
57
|
+
bundle
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
updateAllCartItemPrice
|
|
64
|
+
});
|
|
@@ -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,21 +79,22 @@ 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
|
) || [];
|
|
90
|
+
this.setDiscountList(goodPassList);
|
|
79
91
|
return goodPassList;
|
|
80
92
|
}
|
|
81
93
|
async batchSearch(code) {
|
|
82
94
|
const result = await this.request.get(`/machinecode/batch-search`, {
|
|
83
95
|
code,
|
|
84
96
|
translate_flag: 1,
|
|
85
|
-
|
|
97
|
+
tags: ["good_pass", "product_discount_card"],
|
|
86
98
|
available: 1,
|
|
87
99
|
relation_product: 1
|
|
88
100
|
});
|
|
@@ -91,7 +103,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
91
103
|
}
|
|
92
104
|
filterEnabledDiscountList(discountList) {
|
|
93
105
|
return discountList.filter(
|
|
94
|
-
(discount) => discount.limit_status === "enable" &&
|
|
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)
|
|
95
107
|
);
|
|
96
108
|
}
|
|
97
109
|
// 根据productIds去重
|
|
@@ -110,8 +122,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
110
122
|
}
|
|
111
123
|
if (discount.appliedProductDetails) {
|
|
112
124
|
return discount.appliedProductDetails.reduce((total, product) => {
|
|
113
|
-
const price =
|
|
114
|
-
return total
|
|
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();
|
|
115
127
|
}, 0);
|
|
116
128
|
}
|
|
117
129
|
}
|
|
@@ -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);
|
|
@@ -107,19 +118,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
107
118
|
return !discount.isManualSelect;
|
|
108
119
|
});
|
|
109
120
|
const sortedDiscountList = [...filteredDiscountList].sort((a, b) => {
|
|
110
|
-
if (a.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return
|
|
121
|
+
if (a.tag === "good_pass" && b.tag !== "good_pass")
|
|
122
|
+
return -1;
|
|
123
|
+
if (b.tag === "good_pass" && a.tag !== "good_pass")
|
|
124
|
+
return 1;
|
|
125
|
+
if (a.tag === "good_pass" && b.tag === "good_pass") {
|
|
126
|
+
return compareByExpireTime(a, b);
|
|
127
|
+
} else if (a.tag === "product_discount_card" && b.tag === "product_discount_card") {
|
|
128
|
+
if (a.par_value !== b.par_value) {
|
|
129
|
+
const valueA = new import_decimal.default(100).minus(a.par_value || 0);
|
|
130
|
+
const valueB = new import_decimal.default(100).minus(b.par_value || 0);
|
|
131
|
+
return valueA.minus(valueB).toNumber();
|
|
132
|
+
}
|
|
133
|
+
return compareByExpireTime(a, b);
|
|
134
|
+
}
|
|
135
|
+
return compareByExpireTime(a, b);
|
|
136
|
+
function compareByExpireTime(itemA, itemB) {
|
|
137
|
+
if (itemA.expire_time && itemB.expire_time) {
|
|
138
|
+
const timeA = new Date(itemA.expire_time).getTime();
|
|
139
|
+
const timeB = new Date(itemB.expire_time).getTime();
|
|
140
|
+
return timeA - timeB;
|
|
141
|
+
}
|
|
142
|
+
return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
|
|
114
143
|
}
|
|
115
|
-
return a.expire_time ? -1 : b.expire_time ? 1 : 0;
|
|
116
144
|
});
|
|
117
145
|
const sortedProductList = [...productList].sort((a, b) => {
|
|
118
146
|
const aProduct = this.hooks.getProduct(a);
|
|
119
147
|
const bProduct = this.hooks.getProduct(b);
|
|
120
|
-
const priceA =
|
|
121
|
-
const priceB =
|
|
122
|
-
return priceB
|
|
148
|
+
const priceA = new import_decimal.default(aProduct.price || "0");
|
|
149
|
+
const priceB = new import_decimal.default(bProduct.price || "0");
|
|
150
|
+
return priceB.minus(priceA).toNumber();
|
|
123
151
|
});
|
|
124
152
|
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
125
153
|
const discountApplicability = /* @__PURE__ */ new Map();
|
|
@@ -136,7 +164,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
136
164
|
var _a, _b, _c;
|
|
137
165
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
138
166
|
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 &&
|
|
167
|
+
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))));
|
|
140
168
|
if (isAvailableProduct && isLimitedProduct) {
|
|
141
169
|
(_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
|
|
142
170
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
@@ -146,8 +174,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
146
174
|
discount: {
|
|
147
175
|
resource_id: discount.id,
|
|
148
176
|
title: discount.format_title,
|
|
149
|
-
original_amount: product.origin_total
|
|
150
|
-
|
|
177
|
+
original_amount: product.origin_total,
|
|
178
|
+
pre_value: discount.par_value,
|
|
179
|
+
product_id: originProduct.id
|
|
180
|
+
},
|
|
181
|
+
num: product.num || 1
|
|
151
182
|
});
|
|
152
183
|
discountApplicableProducts.set(discount.id, applicableProducts);
|
|
153
184
|
}
|
|
@@ -156,12 +187,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
156
187
|
sortedProductList.forEach((originProduct) => {
|
|
157
188
|
var _a, _b, _c, _d, _e;
|
|
158
189
|
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 &&
|
|
190
|
+
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)))) {
|
|
160
191
|
processedProductsMap.set(product._id, originProduct);
|
|
161
192
|
return;
|
|
162
193
|
}
|
|
163
194
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
164
|
-
if (
|
|
195
|
+
if (Number(product.price) === 0 || !product.price)
|
|
196
|
+
return false;
|
|
197
|
+
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
198
|
+
if (targetUsedDiscounts && discount.tag === "good_pass")
|
|
165
199
|
return false;
|
|
166
200
|
const limitedData = discount.limited_relation_product_data;
|
|
167
201
|
if (limitedData.type === "product_all") {
|
|
@@ -220,15 +254,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
220
254
|
}
|
|
221
255
|
usedDiscounts.set(selectedDiscount.id, true);
|
|
222
256
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
|
|
257
|
+
const targetProductPrice = selectedDiscount.tag === "good_pass" ? "0" : new import_decimal.default(100).minus(selectedDiscount.par_value || 0).div(100).mul(new import_decimal.default(product.price || 0)).toFixed(2);
|
|
223
258
|
const discountDetail = {
|
|
224
|
-
amount: product.price,
|
|
225
|
-
type: selectedDiscount.tag,
|
|
259
|
+
amount: selectedDiscount.tag === "product_discount_card" ? new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice)).toNumber() : product.price,
|
|
260
|
+
type: selectedDiscount.tag === "product_discount_card" ? "discount_card" : selectedDiscount.tag,
|
|
226
261
|
discount: {
|
|
227
262
|
resource_id: selectedDiscount.id,
|
|
228
263
|
title: selectedDiscount.format_title,
|
|
229
|
-
original_amount: product.
|
|
230
|
-
product_id:
|
|
231
|
-
|
|
264
|
+
original_amount: product.price,
|
|
265
|
+
product_id: originProduct.id,
|
|
266
|
+
percent: selectedDiscount.par_value
|
|
267
|
+
},
|
|
268
|
+
num: product.num || 1
|
|
232
269
|
};
|
|
233
270
|
appliedProducts.push(discountDetail);
|
|
234
271
|
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
@@ -237,7 +274,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
237
274
|
product._id,
|
|
238
275
|
this.hooks.setProduct(originProduct, {
|
|
239
276
|
discount_list: [discountDetail],
|
|
240
|
-
price:
|
|
277
|
+
price: new import_decimal.default(targetProductPrice).toNumber(),
|
|
241
278
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
242
279
|
product: {
|
|
243
280
|
original_price: product.original_price
|
|
@@ -247,7 +284,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
247
284
|
}),
|
|
248
285
|
total: (0, import_utils2.getProductTotalPrice)({
|
|
249
286
|
product: {
|
|
250
|
-
price:
|
|
287
|
+
price: targetProductPrice
|
|
251
288
|
},
|
|
252
289
|
bundle: product.bundle,
|
|
253
290
|
options: product.options
|
|
@@ -259,8 +296,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
259
296
|
product._id,
|
|
260
297
|
this.hooks.setProduct(originProduct, {
|
|
261
298
|
discount_list: [discountDetail],
|
|
262
|
-
price:
|
|
263
|
-
total: (product.origin_total || product.total)
|
|
299
|
+
price: new import_decimal.default(targetProductPrice).toNumber(),
|
|
300
|
+
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(),
|
|
264
301
|
origin_total: product.origin_total || product.total
|
|
265
302
|
})
|
|
266
303
|
);
|
|
@@ -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[];
|