@pisell/pisellos 1.0.49 → 1.0.50
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/core/index.js +2 -1
- package/dist/effects/index.d.ts +4 -3
- package/dist/effects/index.js +15 -6
- package/dist/modules/AccountList/index.d.ts +7 -1
- package/dist/modules/AccountList/index.js +81 -14
- package/dist/modules/AccountList/types.d.ts +28 -0
- package/dist/modules/AccountList/types.js +8 -0
- package/dist/modules/Customer/constants.d.ts +7 -0
- package/dist/modules/Customer/constants.js +12 -0
- package/dist/modules/Customer/index.d.ts +122 -0
- package/dist/modules/Customer/index.js +697 -0
- package/dist/modules/Customer/types.d.ts +146 -0
- package/dist/modules/Customer/types.js +41 -0
- package/dist/modules/ProductList/index.d.ts +12 -1
- package/dist/modules/ProductList/index.js +28 -4
- package/dist/modules/Rules/index.js +7 -5
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/plugins/window.d.ts +1 -0
- package/dist/solution/BookingTicket/index.d.ts +160 -0
- package/dist/solution/BookingTicket/index.js +640 -0
- package/dist/solution/BookingTicket/types.d.ts +68 -0
- package/dist/solution/BookingTicket/types.js +43 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +159 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +19 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +182 -0
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +59 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +201 -0
- package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
- package/dist/solution/BookingTicket/utils/scan/scanCache.js +305 -0
- package/dist/solution/ShopDiscount/index.js +4 -2
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +1 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/utils/task.d.ts +31 -0
- package/dist/utils/task.js +150 -0
- package/dist/utils/watch.d.ts +102 -0
- package/dist/utils/watch.js +294 -0
- package/lib/core/index.js +1 -1
- package/lib/effects/index.d.ts +4 -3
- package/lib/effects/index.js +4 -1
- package/lib/modules/AccountList/index.d.ts +7 -1
- package/lib/modules/AccountList/index.js +27 -0
- package/lib/modules/AccountList/types.d.ts +28 -0
- package/lib/modules/Customer/constants.d.ts +7 -0
- package/lib/modules/Customer/constants.js +39 -0
- package/lib/modules/Customer/index.d.ts +122 -0
- package/lib/modules/Customer/index.js +440 -0
- package/lib/modules/Customer/types.d.ts +146 -0
- package/lib/modules/Customer/types.js +37 -0
- package/lib/modules/ProductList/index.d.ts +12 -1
- package/lib/modules/ProductList/index.js +30 -3
- package/lib/modules/Rules/index.js +4 -3
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +2 -0
- package/lib/plugins/window.d.ts +1 -0
- package/lib/solution/BookingTicket/index.d.ts +160 -0
- package/lib/solution/BookingTicket/index.js +381 -0
- package/lib/solution/BookingTicket/types.d.ts +68 -0
- package/lib/solution/BookingTicket/types.js +72 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +117 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +19 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +137 -0
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +59 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +149 -0
- package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +231 -0
- package/lib/solution/ShopDiscount/index.js +2 -1
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +2 -0
- package/lib/types/index.d.ts +3 -1
- package/lib/utils/task.d.ts +31 -0
- package/lib/utils/task.js +84 -0
- package/lib/utils/watch.d.ts +102 -0
- package/lib/utils/watch.js +217 -0
- package/package.json +1 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
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
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/solution/BookingTicket/utils/scan/handleScan.ts
|
|
30
|
+
var handleScan_exports = {};
|
|
31
|
+
__export(handleScan_exports, {
|
|
32
|
+
handleCustomerScan: () => handleCustomerScan,
|
|
33
|
+
handleGlobalScan: () => handleGlobalScan
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(handleScan_exports);
|
|
36
|
+
var import_cloudSearch = require("./cloudSearch");
|
|
37
|
+
var import_scanCache = __toESM(require("./scanCache"));
|
|
38
|
+
var promiseAny = async (promises) => {
|
|
39
|
+
if (promises.length === 0) {
|
|
40
|
+
throw new Error("No promises provided");
|
|
41
|
+
}
|
|
42
|
+
const errors = [];
|
|
43
|
+
let completedCount = 0;
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
promises.forEach((promise, index) => {
|
|
46
|
+
promise.then((result) => {
|
|
47
|
+
resolve(result);
|
|
48
|
+
}).catch((error) => {
|
|
49
|
+
errors[index] = error;
|
|
50
|
+
completedCount++;
|
|
51
|
+
if (completedCount === promises.length) {
|
|
52
|
+
const errorMessage = `All promises were rejected. Errors: ${errors.map((e) => e.message).join(", ")}`;
|
|
53
|
+
const combinedError = new Error(errorMessage);
|
|
54
|
+
combinedError.errors = errors;
|
|
55
|
+
reject(combinedError);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
var handleScanFn = (getRequestList, localSearch) => {
|
|
62
|
+
return async (scanResult) => {
|
|
63
|
+
const { value } = scanResult || {};
|
|
64
|
+
try {
|
|
65
|
+
const localResult = localSearch == null ? void 0 : localSearch(value);
|
|
66
|
+
if ((localResult == null ? void 0 : localResult.length) > 0) {
|
|
67
|
+
console.log("本地搜索到数据>>>>>>>", localResult);
|
|
68
|
+
return {
|
|
69
|
+
searchType: "local_product",
|
|
70
|
+
response: { data: { list: localResult } }
|
|
71
|
+
};
|
|
72
|
+
} else {
|
|
73
|
+
console.log("本地搜索无数据>>>>>>>");
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error("本地搜索到数据失败>>>>>>>", error);
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
if (import_scanCache.default.has(value)) {
|
|
80
|
+
const result = import_scanCache.default.get(value);
|
|
81
|
+
console.log("缓存中搜索到数据>>>>>>>", result);
|
|
82
|
+
return result;
|
|
83
|
+
} else {
|
|
84
|
+
console.log("缓存中无数据>>>>>>>");
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error("缓存中搜索数据失败>>>>>>>", error);
|
|
88
|
+
}
|
|
89
|
+
const requestList = (getRequestList == null ? void 0 : getRequestList(value)) || [];
|
|
90
|
+
if (requestList.length === 0) {
|
|
91
|
+
throw new Error("requestList is empty");
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const result = await promiseAny(requestList);
|
|
95
|
+
import_scanCache.default.set(value, result);
|
|
96
|
+
return result;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
var handleGlobalScan = (request, localSearch) => {
|
|
103
|
+
const getRequestList = (value) => {
|
|
104
|
+
let requestList = [];
|
|
105
|
+
if (value.startsWith("WL")) {
|
|
106
|
+
requestList = [(0, import_cloudSearch.searchWallet)(request, value)];
|
|
107
|
+
} else {
|
|
108
|
+
requestList = [
|
|
109
|
+
(0, import_cloudSearch.searchWalletPass)(request, value),
|
|
110
|
+
(0, import_cloudSearch.searchWallet)(request, value),
|
|
111
|
+
(0, import_cloudSearch.searchProduct)(request, value)
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
return requestList;
|
|
115
|
+
};
|
|
116
|
+
return handleScanFn(getRequestList, localSearch);
|
|
117
|
+
};
|
|
118
|
+
var handleCustomerScan = (request, localSearch) => {
|
|
119
|
+
const getRequestList = (value) => {
|
|
120
|
+
let requestList = [];
|
|
121
|
+
if (value.startsWith("WL")) {
|
|
122
|
+
requestList = [(0, import_cloudSearch.searchWallet)(request, value)];
|
|
123
|
+
} else {
|
|
124
|
+
requestList = [
|
|
125
|
+
(0, import_cloudSearch.searchWalletPass)(request, value),
|
|
126
|
+
(0, import_cloudSearch.searchWallet)(request, value)
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
return requestList;
|
|
130
|
+
};
|
|
131
|
+
return handleScanFn(getRequestList, localSearch);
|
|
132
|
+
};
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
handleCustomerScan,
|
|
136
|
+
handleGlobalScan
|
|
137
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { WatchEventItem } from '../../../../utils/watch';
|
|
2
|
+
import { BookingTicketImpl } from '../../index';
|
|
3
|
+
import Tasks from '../../../../utils/task';
|
|
4
|
+
interface ScanResult {
|
|
5
|
+
type: ScanResultType;
|
|
6
|
+
value: string;
|
|
7
|
+
data?: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
declare enum ScanResultType {
|
|
12
|
+
Scanner = "scanner",
|
|
13
|
+
NFC = "nfc",
|
|
14
|
+
NativeScanner = "nativeScanner"
|
|
15
|
+
}
|
|
16
|
+
export default class Scan {
|
|
17
|
+
private solution;
|
|
18
|
+
private watchKey;
|
|
19
|
+
private listenerConfig;
|
|
20
|
+
constructor(solution: BookingTicketImpl, watchKey: string);
|
|
21
|
+
/**
|
|
22
|
+
* 添加扫码信息监听
|
|
23
|
+
* @param watchKey 监听的key
|
|
24
|
+
* @param event 事件
|
|
25
|
+
*/
|
|
26
|
+
addListener(event: WatchEventItem, scanCallback?: (result: ScanResult) => Promise<any>): {
|
|
27
|
+
remove: () => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 移除扫码信息监听
|
|
31
|
+
* @param watchKey 监听的key
|
|
32
|
+
* @param event 事件
|
|
33
|
+
*/
|
|
34
|
+
removeListener(event: WatchEventItem): void;
|
|
35
|
+
/**
|
|
36
|
+
* 处理扫码事件
|
|
37
|
+
* @param eventKey 事件key
|
|
38
|
+
* @param value 扫码结果
|
|
39
|
+
*/
|
|
40
|
+
handleScan(value: {
|
|
41
|
+
type: string;
|
|
42
|
+
value: string;
|
|
43
|
+
}): void;
|
|
44
|
+
/**
|
|
45
|
+
* 获取监听配置
|
|
46
|
+
* @param eventKey 事件key
|
|
47
|
+
* @returns 监听配置
|
|
48
|
+
*/
|
|
49
|
+
getListenerConfig(eventKey: string): {
|
|
50
|
+
scanCallback?: ((result: ScanResult) => Promise<any>) | undefined;
|
|
51
|
+
task: Tasks;
|
|
52
|
+
} | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* 处理扫码结果
|
|
55
|
+
* @param args 参数
|
|
56
|
+
*/
|
|
57
|
+
handleScanResultFn(...args: any[]): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
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
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/solution/BookingTicket/utils/scan/index.ts
|
|
30
|
+
var scan_exports = {};
|
|
31
|
+
__export(scan_exports, {
|
|
32
|
+
default: () => Scan
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(scan_exports);
|
|
35
|
+
var import_watch = __toESM(require("../../../../utils/watch"));
|
|
36
|
+
var import_task = __toESM(require("../../../../utils/task"));
|
|
37
|
+
var Scan = class {
|
|
38
|
+
constructor(solution, watchKey) {
|
|
39
|
+
this.listenerConfig = /* @__PURE__ */ new Map();
|
|
40
|
+
var _a, _b, _c, _d, _e;
|
|
41
|
+
this.solution = solution;
|
|
42
|
+
this.watchKey = watchKey;
|
|
43
|
+
(_e = (_d = (_c = (_b = (_a = this.solution) == null ? void 0 : _a.window) == null ? void 0 : _b.interaction) == null ? void 0 : _c.utils) == null ? void 0 : _d.mountFunction) == null ? void 0 : _e.call(
|
|
44
|
+
_d,
|
|
45
|
+
"global",
|
|
46
|
+
"peripheralsResult",
|
|
47
|
+
(strVal) => {
|
|
48
|
+
try {
|
|
49
|
+
const result = JSON.parse(strVal);
|
|
50
|
+
console.log("nativeScannerResult>>>>>>>", result);
|
|
51
|
+
this.handleScan(result);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.error(err);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 添加扫码信息监听
|
|
60
|
+
* @param watchKey 监听的key
|
|
61
|
+
* @param event 事件
|
|
62
|
+
*/
|
|
63
|
+
addListener(event, scanCallback) {
|
|
64
|
+
import_watch.default.subscribe(this.watchKey, event);
|
|
65
|
+
const task = new import_task.default();
|
|
66
|
+
task.addAction(
|
|
67
|
+
event.key,
|
|
68
|
+
(...args) => this.handleScanResultFn(event.key, ...args)
|
|
69
|
+
);
|
|
70
|
+
this.listenerConfig.set(event.key, { scanCallback, task });
|
|
71
|
+
return {
|
|
72
|
+
remove: () => {
|
|
73
|
+
this.removeListener(event);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 移除扫码信息监听
|
|
79
|
+
* @param watchKey 监听的key
|
|
80
|
+
* @param event 事件
|
|
81
|
+
*/
|
|
82
|
+
removeListener(event) {
|
|
83
|
+
var _a;
|
|
84
|
+
import_watch.default.unsubscribe(this.watchKey, event);
|
|
85
|
+
(_a = this.listenerConfig.get(event.key)) == null ? void 0 : _a.task.clear();
|
|
86
|
+
this.listenerConfig.delete(event.key);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 处理扫码事件
|
|
90
|
+
* @param eventKey 事件key
|
|
91
|
+
* @param value 扫码结果
|
|
92
|
+
*/
|
|
93
|
+
handleScan(value) {
|
|
94
|
+
const lastEnableEventKey = import_watch.default.getLastEnableEventKey(this.watchKey);
|
|
95
|
+
if (lastEnableEventKey) {
|
|
96
|
+
const listenerConfig = this.listenerConfig.get(lastEnableEventKey);
|
|
97
|
+
if (listenerConfig) {
|
|
98
|
+
listenerConfig.task.addTask({
|
|
99
|
+
type: lastEnableEventKey,
|
|
100
|
+
actionParams: {
|
|
101
|
+
scanResult: value
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 获取监听配置
|
|
109
|
+
* @param eventKey 事件key
|
|
110
|
+
* @returns 监听配置
|
|
111
|
+
*/
|
|
112
|
+
getListenerConfig(eventKey) {
|
|
113
|
+
var _a;
|
|
114
|
+
return (_a = this.listenerConfig) == null ? void 0 : _a.get(eventKey);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 处理扫码结果
|
|
118
|
+
* @param args 参数
|
|
119
|
+
*/
|
|
120
|
+
async handleScanResultFn(...args) {
|
|
121
|
+
var _a;
|
|
122
|
+
const [eventKey, other] = args;
|
|
123
|
+
const { type, value, data } = (other == null ? void 0 : other.scanResult) || {};
|
|
124
|
+
const scanCallback = (_a = this.getListenerConfig(eventKey)) == null ? void 0 : _a.scanCallback;
|
|
125
|
+
if (scanCallback) {
|
|
126
|
+
try {
|
|
127
|
+
const result = await scanCallback({ type, value });
|
|
128
|
+
console.log(`${eventKey}_result>>>>>>>`, result);
|
|
129
|
+
import_watch.default.publishByEventKey(this.watchKey, eventKey, {
|
|
130
|
+
type: eventKey,
|
|
131
|
+
status: "success",
|
|
132
|
+
scanType: type,
|
|
133
|
+
scanCode: value,
|
|
134
|
+
scanData: data,
|
|
135
|
+
result
|
|
136
|
+
});
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.log(`${eventKey}_result_error>>>>>>>`, error);
|
|
139
|
+
import_watch.default.publishByEventKey(this.watchKey, eventKey, {
|
|
140
|
+
type: eventKey,
|
|
141
|
+
status: "failed",
|
|
142
|
+
scanType: type,
|
|
143
|
+
scanCode: value,
|
|
144
|
+
scanData: data
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LRU缓存类,用于缓存接口数据
|
|
3
|
+
* 限制最多存储100条数据,超过时移除最久未使用的数据
|
|
4
|
+
* 支持数据压缩以减小缓存压力
|
|
5
|
+
* 尾部优先策略:新节点插入尾部,最近使用的节点移动到尾部,删除头部节点
|
|
6
|
+
*/
|
|
7
|
+
declare class LRUCache<T> {
|
|
8
|
+
private head;
|
|
9
|
+
private tail;
|
|
10
|
+
private keyMap;
|
|
11
|
+
private readonly maxSize;
|
|
12
|
+
constructor(maxSize?: number);
|
|
13
|
+
/**
|
|
14
|
+
* 将节点移动到链表尾部(最近使用)
|
|
15
|
+
* @param node 要移动的节点
|
|
16
|
+
*/
|
|
17
|
+
private moveToTail;
|
|
18
|
+
/**
|
|
19
|
+
* 添加新节点到链表尾部
|
|
20
|
+
* @param key 缓存键
|
|
21
|
+
* @param compressedData 压缩后的数据
|
|
22
|
+
* @param timestamp 时间戳
|
|
23
|
+
*/
|
|
24
|
+
private addToTail;
|
|
25
|
+
/**
|
|
26
|
+
* 从链表中移除节点
|
|
27
|
+
* @param node 要移除的节点
|
|
28
|
+
*/
|
|
29
|
+
private removeNode;
|
|
30
|
+
/**
|
|
31
|
+
* 移除最久未使用的节点(链表头部)
|
|
32
|
+
*/
|
|
33
|
+
private removeOldest;
|
|
34
|
+
/**
|
|
35
|
+
* 设置缓存
|
|
36
|
+
* @param key 缓存键
|
|
37
|
+
* @param data 缓存数据
|
|
38
|
+
*/
|
|
39
|
+
set(key: string, data: T): void;
|
|
40
|
+
/**
|
|
41
|
+
* 获取缓存
|
|
42
|
+
* @param key 缓存键
|
|
43
|
+
* @returns 缓存数据或undefined
|
|
44
|
+
*/
|
|
45
|
+
get(key: string): T | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* 检查是否存在缓存
|
|
48
|
+
* @param key 缓存键
|
|
49
|
+
* @returns 是否存在
|
|
50
|
+
*/
|
|
51
|
+
has(key: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* 清除所有缓存
|
|
54
|
+
*/
|
|
55
|
+
clear(): void;
|
|
56
|
+
/**
|
|
57
|
+
* 获取缓存大小
|
|
58
|
+
* @returns 当前缓存数量
|
|
59
|
+
*/
|
|
60
|
+
size(): number;
|
|
61
|
+
/**
|
|
62
|
+
* 获取缓存统计信息
|
|
63
|
+
* @returns 缓存统计信息
|
|
64
|
+
*/
|
|
65
|
+
getStats(): {
|
|
66
|
+
size: number;
|
|
67
|
+
maxSize: number;
|
|
68
|
+
usage: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* 删除指定的缓存项
|
|
72
|
+
* @param key 要删除的缓存键
|
|
73
|
+
* @returns 是否删除成功
|
|
74
|
+
*/
|
|
75
|
+
delete(key: string): boolean;
|
|
76
|
+
}
|
|
77
|
+
declare const scanCache: LRUCache<any>;
|
|
78
|
+
export default scanCache;
|
|
@@ -0,0 +1,231 @@
|
|
|
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/solution/BookingTicket/utils/scan/scanCache.ts
|
|
20
|
+
var scanCache_exports = {};
|
|
21
|
+
__export(scanCache_exports, {
|
|
22
|
+
default: () => scanCache_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(scanCache_exports);
|
|
25
|
+
var compressData = (data) => {
|
|
26
|
+
try {
|
|
27
|
+
if (data === void 0) {
|
|
28
|
+
return "undefined";
|
|
29
|
+
}
|
|
30
|
+
return JSON.stringify(data);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.warn("数据压缩失败:", error);
|
|
33
|
+
return JSON.stringify(data);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var decompressData = (compressedData) => {
|
|
37
|
+
try {
|
|
38
|
+
if (compressedData === "undefined") {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
return JSON.parse(compressedData);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.warn("数据解压缩失败:", error);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var LRUCache = class {
|
|
48
|
+
constructor(maxSize = 100) {
|
|
49
|
+
this.head = null;
|
|
50
|
+
// 最久未使用的节点
|
|
51
|
+
this.tail = null;
|
|
52
|
+
// 最近使用的节点
|
|
53
|
+
this.keyMap = /* @__PURE__ */ new Map();
|
|
54
|
+
this.maxSize = maxSize;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 将节点移动到链表尾部(最近使用)
|
|
58
|
+
* @param node 要移动的节点
|
|
59
|
+
*/
|
|
60
|
+
moveToTail(node) {
|
|
61
|
+
if (this.tail === node)
|
|
62
|
+
return;
|
|
63
|
+
if (node.prev) {
|
|
64
|
+
node.prev.next = node.next;
|
|
65
|
+
}
|
|
66
|
+
if (node.next) {
|
|
67
|
+
node.next.prev = node.prev;
|
|
68
|
+
}
|
|
69
|
+
if (this.head === node) {
|
|
70
|
+
this.head = node.next;
|
|
71
|
+
}
|
|
72
|
+
if (this.tail) {
|
|
73
|
+
this.tail.next = node;
|
|
74
|
+
}
|
|
75
|
+
node.prev = this.tail;
|
|
76
|
+
node.next = null;
|
|
77
|
+
this.tail = node;
|
|
78
|
+
if (!this.head) {
|
|
79
|
+
this.head = node;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 添加新节点到链表尾部
|
|
84
|
+
* @param key 缓存键
|
|
85
|
+
* @param compressedData 压缩后的数据
|
|
86
|
+
* @param timestamp 时间戳
|
|
87
|
+
*/
|
|
88
|
+
addToTail(key, compressedData, timestamp) {
|
|
89
|
+
const oldTail = this.tail;
|
|
90
|
+
const node = {
|
|
91
|
+
key,
|
|
92
|
+
compressedData,
|
|
93
|
+
timestamp,
|
|
94
|
+
prev: oldTail,
|
|
95
|
+
// 使用保存的引用,避免循环引用
|
|
96
|
+
next: null
|
|
97
|
+
};
|
|
98
|
+
this.keyMap.set(key, node);
|
|
99
|
+
if (oldTail) {
|
|
100
|
+
oldTail.next = node;
|
|
101
|
+
}
|
|
102
|
+
this.tail = node;
|
|
103
|
+
if (!this.head) {
|
|
104
|
+
this.head = node;
|
|
105
|
+
}
|
|
106
|
+
return node;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 从链表中移除节点
|
|
110
|
+
* @param node 要移除的节点
|
|
111
|
+
*/
|
|
112
|
+
removeNode(node) {
|
|
113
|
+
if (node.prev) {
|
|
114
|
+
node.prev.next = node.next;
|
|
115
|
+
}
|
|
116
|
+
if (node.next) {
|
|
117
|
+
node.next.prev = node.prev;
|
|
118
|
+
}
|
|
119
|
+
if (this.head === node) {
|
|
120
|
+
this.head = node.next;
|
|
121
|
+
}
|
|
122
|
+
if (this.tail === node) {
|
|
123
|
+
this.tail = node.prev;
|
|
124
|
+
}
|
|
125
|
+
this.keyMap.delete(node.key);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 移除最久未使用的节点(链表头部)
|
|
129
|
+
*/
|
|
130
|
+
removeOldest() {
|
|
131
|
+
if (this.head) {
|
|
132
|
+
this.removeNode(this.head);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 设置缓存
|
|
137
|
+
* @param key 缓存键
|
|
138
|
+
* @param data 缓存数据
|
|
139
|
+
*/
|
|
140
|
+
set(key, data) {
|
|
141
|
+
const compressedData = compressData(data);
|
|
142
|
+
const timestamp = Date.now();
|
|
143
|
+
const existingNode = this.keyMap.get(key);
|
|
144
|
+
if (existingNode) {
|
|
145
|
+
existingNode.compressedData = compressedData;
|
|
146
|
+
existingNode.timestamp = timestamp;
|
|
147
|
+
this.moveToTail(existingNode);
|
|
148
|
+
} else {
|
|
149
|
+
if (this.keyMap.size >= this.maxSize) {
|
|
150
|
+
this.removeOldest();
|
|
151
|
+
}
|
|
152
|
+
this.addToTail(key, compressedData, timestamp);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 获取缓存
|
|
157
|
+
* @param key 缓存键
|
|
158
|
+
* @returns 缓存数据或undefined
|
|
159
|
+
*/
|
|
160
|
+
get(key) {
|
|
161
|
+
const node = this.keyMap.get(key);
|
|
162
|
+
if (node) {
|
|
163
|
+
const decompressedData = decompressData(node.compressedData);
|
|
164
|
+
if (decompressedData !== null) {
|
|
165
|
+
node.timestamp = Date.now();
|
|
166
|
+
this.moveToTail(node);
|
|
167
|
+
return decompressedData;
|
|
168
|
+
} else {
|
|
169
|
+
this.removeNode(node);
|
|
170
|
+
return void 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return void 0;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 检查是否存在缓存
|
|
177
|
+
* @param key 缓存键
|
|
178
|
+
* @returns 是否存在
|
|
179
|
+
*/
|
|
180
|
+
has(key) {
|
|
181
|
+
return this.keyMap.has(key);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* 清除所有缓存
|
|
185
|
+
*/
|
|
186
|
+
clear() {
|
|
187
|
+
let current = this.head;
|
|
188
|
+
while (current) {
|
|
189
|
+
const next = current.next;
|
|
190
|
+
current.prev = null;
|
|
191
|
+
current.next = null;
|
|
192
|
+
current = next;
|
|
193
|
+
}
|
|
194
|
+
this.keyMap.clear();
|
|
195
|
+
this.head = null;
|
|
196
|
+
this.tail = null;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* 获取缓存大小
|
|
200
|
+
* @returns 当前缓存数量
|
|
201
|
+
*/
|
|
202
|
+
size() {
|
|
203
|
+
return this.keyMap.size;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* 获取缓存统计信息
|
|
207
|
+
* @returns 缓存统计信息
|
|
208
|
+
*/
|
|
209
|
+
getStats() {
|
|
210
|
+
return {
|
|
211
|
+
size: this.keyMap.size,
|
|
212
|
+
maxSize: this.maxSize,
|
|
213
|
+
usage: Math.round(this.keyMap.size / this.maxSize * 100)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* 删除指定的缓存项
|
|
218
|
+
* @param key 要删除的缓存键
|
|
219
|
+
* @returns 是否删除成功
|
|
220
|
+
*/
|
|
221
|
+
delete(key) {
|
|
222
|
+
const node = this.keyMap.get(key);
|
|
223
|
+
if (node) {
|
|
224
|
+
this.removeNode(node);
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var scanCache = new LRUCache();
|
|
231
|
+
var scanCache_default = scanCache;
|
|
@@ -38,6 +38,7 @@ var import_types = require("./types");
|
|
|
38
38
|
var import_Discount = require("../../modules/Discount");
|
|
39
39
|
var import_Rules = require("../../modules/Rules");
|
|
40
40
|
var import_decimal = __toESM(require("decimal.js"));
|
|
41
|
+
var import_lodash_es = require("lodash-es");
|
|
41
42
|
var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
42
43
|
constructor(name, version) {
|
|
43
44
|
super(name, version);
|
|
@@ -337,7 +338,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
337
338
|
var _a2;
|
|
338
339
|
const targetProduct = productList.find((n) => n.id === id);
|
|
339
340
|
const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
|
|
340
|
-
return Number(product == null ? void 0 : product.total)
|
|
341
|
+
return Number(product == null ? void 0 : product.total) <= 0 && (Number(product == null ? void 0 : product.origin_total) <= 0 || !(product == null ? void 0 : product.origin_total)) || (0, import_lodash_es.isBoolean)(product == null ? void 0 : product.vouchersApplicable) && !(product == null ? void 0 : product.vouchersApplicable);
|
|
341
342
|
};
|
|
342
343
|
const allUsedProductIds = newDiscountList.map((n) => {
|
|
343
344
|
var _a2;
|
package/lib/solution/index.d.ts
CHANGED
package/lib/solution/index.js
CHANGED
|
@@ -18,10 +18,12 @@ var solution_exports = {};
|
|
|
18
18
|
module.exports = __toCommonJS(solution_exports);
|
|
19
19
|
__reExport(solution_exports, require("./BuyTickets"), module.exports);
|
|
20
20
|
__reExport(solution_exports, require("./BookingByStep"), module.exports);
|
|
21
|
+
__reExport(solution_exports, require("./BookingTicket"), module.exports);
|
|
21
22
|
__reExport(solution_exports, require("./ShopDiscount"), module.exports);
|
|
22
23
|
// Annotate the CommonJS export names for ESM import in node:
|
|
23
24
|
0 && (module.exports = {
|
|
24
25
|
...require("./BuyTickets"),
|
|
25
26
|
...require("./BookingByStep"),
|
|
27
|
+
...require("./BookingTicket"),
|
|
26
28
|
...require("./ShopDiscount")
|
|
27
29
|
});
|
package/lib/types/index.d.ts
CHANGED
|
@@ -38,7 +38,9 @@ export interface PisellCore {
|
|
|
38
38
|
getModuleExports: <T = any>(name: string) => T | null;
|
|
39
39
|
hasModule: (name: string) => boolean;
|
|
40
40
|
effects: {
|
|
41
|
-
on: (event: string, callback: (payload: any) => void) => void;
|
|
41
|
+
on: (event: string, callback: (payload: any) => void) => () => void;
|
|
42
|
+
once: (event: string, callback: (payload: any) => void) => () => void;
|
|
43
|
+
off: (event: string, callback: (payload: any) => void) => void;
|
|
42
44
|
emit: (event: string, payload: any, value?: any) => Promise<{
|
|
43
45
|
status: boolean;
|
|
44
46
|
data: any;
|