@pisell/pisellos 0.0.490 → 0.0.492
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/apis/picoding.d.ts +0 -0
- package/dist/apis/picoding.js +1 -0
- package/dist/model/strategy/adapter/index.d.ts +2 -0
- package/dist/model/strategy/adapter/index.js +3 -1
- package/dist/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
- package/dist/model/strategy/adapter/itemRule/adapter.js +439 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
- package/dist/model/strategy/adapter/itemRule/examples.d.ts +64 -0
- package/dist/model/strategy/adapter/itemRule/examples.js +315 -0
- package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/dist/model/strategy/adapter/itemRule/index.js +5 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +206 -0
- package/dist/model/strategy/adapter/itemRule/type.js +101 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +2 -2
- package/dist/modules/OpenData/index.d.ts +23 -0
- package/dist/modules/OpenData/index.js +167 -0
- package/dist/modules/OpenData/types.d.ts +73 -0
- package/dist/modules/OpenData/types.js +1 -0
- package/dist/modules/OpenData/utils.d.ts +2 -0
- package/dist/modules/OpenData/utils.js +75 -0
- package/dist/modules/Order/index.d.ts +53 -1
- package/dist/modules/Order/index.js +717 -27
- package/dist/modules/Order/types.d.ts +144 -12
- package/dist/modules/Order/utils.d.ts +25 -0
- package/dist/modules/Order/utils.js +214 -1
- package/dist/modules/Product/utils.js +2 -2
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +3 -1
- package/dist/modules/Quotation/index.d.ts +40 -0
- package/dist/modules/Quotation/index.js +212 -0
- package/dist/modules/Quotation/types.d.ts +42 -0
- package/dist/modules/Quotation/types.js +1 -0
- package/dist/modules/Rules/index.js +2 -2
- package/dist/modules/SalesSummary/index.d.ts +63 -0
- package/dist/modules/SalesSummary/index.js +174 -0
- package/dist/modules/SalesSummary/types.d.ts +59 -0
- package/dist/modules/SalesSummary/types.js +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +30 -0
- package/dist/modules/SalesSummary/utils.js +506 -0
- package/dist/modules/ScanOrderLogger/index.d.ts +21 -0
- package/dist/modules/ScanOrderLogger/index.js +161 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.js +95 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
- package/dist/modules/ScanOrderLogger/types.d.ts +46 -0
- package/dist/modules/ScanOrderLogger/types.js +1 -0
- package/dist/modules/Summary/utils.d.ts +3 -3
- package/dist/modules/Summary/utils.js +4 -4
- package/dist/modules/index.d.ts +4 -0
- package/dist/modules/index.js +5 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/types.d.ts +3 -1
- package/dist/solution/BookingByStep/types.js +5 -1
- package/dist/solution/ScanOrder/index.d.ts +90 -0
- package/dist/solution/ScanOrder/index.js +1853 -0
- package/dist/solution/ScanOrder/types.d.ts +210 -0
- package/dist/solution/ScanOrder/types.js +16 -0
- package/dist/solution/ScanOrder/utils.d.ts +93 -0
- package/dist/solution/ScanOrder/utils.js +378 -0
- package/dist/solution/VenueBooking/index.d.ts +159 -0
- package/dist/solution/VenueBooking/index.js +2773 -0
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/dist/solution/VenueBooking/types.d.ts +123 -0
- package/dist/solution/VenueBooking/types.js +21 -0
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
- package/dist/solution/VenueBooking/utils/dateSummary.js +102 -0
- package/dist/solution/VenueBooking/utils/resource.d.ts +4 -0
- package/dist/solution/VenueBooking/utils/resource.js +94 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +18 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +128 -0
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/dist/solution/VenueBooking/utils/timeSlot.js +256 -0
- package/dist/solution/VenueBooking/utils.d.ts +1 -0
- package/dist/solution/VenueBooking/utils.js +1 -0
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/lib/apis/picoding.d.ts +0 -0
- package/lib/apis/picoding.js +0 -0
- package/lib/model/strategy/adapter/index.d.ts +2 -0
- package/lib/model/strategy/adapter/index.js +6 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
- package/lib/model/strategy/adapter/itemRule/adapter.js +338 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
- package/lib/model/strategy/adapter/itemRule/examples.d.ts +64 -0
- package/lib/model/strategy/adapter/itemRule/examples.js +269 -0
- package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/lib/model/strategy/adapter/itemRule/index.js +58 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +206 -0
- package/lib/model/strategy/adapter/itemRule/type.js +46 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +2 -2
- package/lib/modules/OpenData/index.d.ts +23 -0
- package/lib/modules/OpenData/index.js +116 -0
- package/lib/modules/OpenData/types.d.ts +73 -0
- package/lib/modules/OpenData/types.js +17 -0
- package/lib/modules/OpenData/utils.d.ts +2 -0
- package/lib/modules/OpenData/utils.js +111 -0
- package/lib/modules/Order/index.d.ts +53 -1
- package/lib/modules/Order/index.js +389 -1
- package/lib/modules/Order/types.d.ts +144 -12
- package/lib/modules/Order/utils.d.ts +25 -0
- package/lib/modules/Order/utils.js +217 -0
- package/lib/modules/Product/utils.js +2 -2
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +2 -1
- package/lib/modules/Quotation/index.d.ts +40 -0
- package/lib/modules/Quotation/index.js +128 -0
- package/lib/modules/Quotation/types.d.ts +42 -0
- package/lib/modules/Quotation/types.js +17 -0
- package/lib/modules/Rules/index.js +1 -1
- package/lib/modules/SalesSummary/index.d.ts +63 -0
- package/lib/modules/SalesSummary/index.js +105 -0
- package/lib/modules/SalesSummary/types.d.ts +59 -0
- package/lib/modules/SalesSummary/types.js +17 -0
- package/lib/modules/SalesSummary/utils.d.ts +30 -0
- package/lib/modules/SalesSummary/utils.js +445 -0
- package/lib/modules/ScanOrderLogger/index.d.ts +21 -0
- package/lib/modules/ScanOrderLogger/index.js +135 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.js +82 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
- package/lib/modules/ScanOrderLogger/types.d.ts +46 -0
- package/lib/modules/ScanOrderLogger/types.js +17 -0
- package/lib/modules/Summary/utils.d.ts +3 -3
- package/lib/modules/Summary/utils.js +4 -4
- package/lib/modules/index.d.ts +4 -0
- package/lib/modules/index.js +9 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/types.d.ts +3 -1
- package/lib/solution/BookingByStep/types.js +10 -0
- package/lib/solution/ScanOrder/index.d.ts +90 -0
- package/lib/solution/ScanOrder/index.js +1071 -0
- package/lib/solution/ScanOrder/types.d.ts +210 -0
- package/lib/solution/ScanOrder/types.js +36 -0
- package/lib/solution/ScanOrder/utils.d.ts +93 -0
- package/lib/solution/ScanOrder/utils.js +342 -0
- package/lib/solution/VenueBooking/index.d.ts +159 -0
- package/lib/solution/VenueBooking/index.js +1508 -0
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/lib/solution/VenueBooking/types.d.ts +123 -0
- package/lib/solution/VenueBooking/types.js +44 -0
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
- package/lib/solution/VenueBooking/utils/dateSummary.js +101 -0
- package/lib/solution/VenueBooking/utils/resource.d.ts +4 -0
- package/lib/solution/VenueBooking/utils/resource.js +80 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +18 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +156 -0
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/lib/solution/VenueBooking/utils/timeSlot.js +200 -0
- package/lib/solution/VenueBooking/utils.d.ts +1 -0
- package/lib/solution/VenueBooking/utils.js +69 -0
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1,1071 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/solution/ScanOrder/index.ts
|
|
31
|
+
var ScanOrder_exports = {};
|
|
32
|
+
__export(ScanOrder_exports, {
|
|
33
|
+
ScanOrderImpl: () => ScanOrderImpl
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(ScanOrder_exports);
|
|
36
|
+
var import_BaseModule = require("../../modules/BaseModule");
|
|
37
|
+
var import_types = require("./types");
|
|
38
|
+
var import_utils = require("./utils");
|
|
39
|
+
var import_types2 = require("../BookingByStep/types");
|
|
40
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
41
|
+
var import_itemRule = require("../../model/strategy/adapter/itemRule");
|
|
42
|
+
__reExport(ScanOrder_exports, require("./types"), module.exports);
|
|
43
|
+
var ScanOrderImpl = class extends import_BaseModule.BaseModule {
|
|
44
|
+
constructor(name, version) {
|
|
45
|
+
super(name, version);
|
|
46
|
+
this.defaultName = "scanOrder";
|
|
47
|
+
this.defaultVersion = "1.0.0";
|
|
48
|
+
this.isSolution = true;
|
|
49
|
+
this.initializeOptions = {};
|
|
50
|
+
this.store = {
|
|
51
|
+
entryContext: null,
|
|
52
|
+
status: "idle",
|
|
53
|
+
config: null,
|
|
54
|
+
resource: null,
|
|
55
|
+
flow: {},
|
|
56
|
+
error: null,
|
|
57
|
+
products: void 0,
|
|
58
|
+
itemRuleQuantityLimits: [],
|
|
59
|
+
cartValidation: {
|
|
60
|
+
passed: null,
|
|
61
|
+
failures: []
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
this.otherParams = {};
|
|
65
|
+
this.itemRuleEvaluator = new import_itemRule.ItemRuleEvaluator();
|
|
66
|
+
this.itemRuleConfigs = [];
|
|
67
|
+
this.itemRuleConfigsPromise = null;
|
|
68
|
+
this.itemRulePrefillApplied = false;
|
|
69
|
+
this.itemRuleRuntimeConfig = {};
|
|
70
|
+
}
|
|
71
|
+
getScanOrderLoggerContext() {
|
|
72
|
+
return {
|
|
73
|
+
cacheId: this.cacheId,
|
|
74
|
+
solutionName: this.name,
|
|
75
|
+
moduleName: "scanOrder"
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
serializeError(error) {
|
|
79
|
+
if (error instanceof Error) {
|
|
80
|
+
return {
|
|
81
|
+
name: error.name,
|
|
82
|
+
message: error.message,
|
|
83
|
+
stack: error.stack
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
message: String(error)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async addScanOrderLog(params) {
|
|
91
|
+
const payload = {
|
|
92
|
+
cacheId: this.cacheId,
|
|
93
|
+
...params.payload || {}
|
|
94
|
+
};
|
|
95
|
+
const extra = {
|
|
96
|
+
...params.extra || {}
|
|
97
|
+
};
|
|
98
|
+
const logger = this.store.scanOrderLogger;
|
|
99
|
+
if (!logger) {
|
|
100
|
+
if ((params.level || "info") === "error") {
|
|
101
|
+
console.error("[ScanOrder][log-fallback]", params.title, { payload, extra });
|
|
102
|
+
} else {
|
|
103
|
+
console.log("[ScanOrder][log-fallback]", params.title, { payload, extra });
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
await logger.addLog({
|
|
108
|
+
...params,
|
|
109
|
+
payload,
|
|
110
|
+
extra
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
logMethodStart(method, payload = {}) {
|
|
114
|
+
void this.addScanOrderLog({
|
|
115
|
+
level: "info",
|
|
116
|
+
title: `[ScanOrder] ${method} start`,
|
|
117
|
+
payload: {
|
|
118
|
+
method,
|
|
119
|
+
...payload
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
logMethodSuccess(method, payload = {}) {
|
|
124
|
+
void this.addScanOrderLog({
|
|
125
|
+
level: "info",
|
|
126
|
+
title: `[ScanOrder] ${method} success`,
|
|
127
|
+
payload: {
|
|
128
|
+
method,
|
|
129
|
+
...payload
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
logMethodError(method, error, payload = {}) {
|
|
134
|
+
void this.addScanOrderLog({
|
|
135
|
+
level: "error",
|
|
136
|
+
title: `[ScanOrder] ${method} failed`,
|
|
137
|
+
payload: {
|
|
138
|
+
method,
|
|
139
|
+
...payload,
|
|
140
|
+
error: this.serializeError(error)
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async addLog(params) {
|
|
145
|
+
await this.addScanOrderLog({
|
|
146
|
+
...params,
|
|
147
|
+
payload: {
|
|
148
|
+
source: "ui-bridge",
|
|
149
|
+
...params.payload || {}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async initialize(core, options = {}) {
|
|
154
|
+
var _a, _b, _c, _d, _e, _f;
|
|
155
|
+
this.logMethodStart("initialize");
|
|
156
|
+
this.core = core;
|
|
157
|
+
this.initializeOptions = options || {};
|
|
158
|
+
this.store = { ...this.store, ...options.store };
|
|
159
|
+
this.store.entryContext = ((_a = options.otherParams) == null ? void 0 : _a.entryContext) || this.store.entryContext;
|
|
160
|
+
this.store.status = "initializing";
|
|
161
|
+
this.store.error = null;
|
|
162
|
+
this.otherParams = options.otherParams || {};
|
|
163
|
+
this.cacheId = (_b = this.otherParams) == null ? void 0 : _b.cacheId;
|
|
164
|
+
this.itemRuleRuntimeConfig = ((_c = this.otherParams) == null ? void 0 : _c.scanOrderItemRule) || ((_d = this.otherParams) == null ? void 0 : _d.itemRule) || {};
|
|
165
|
+
this.itemRuleConfigs = [];
|
|
166
|
+
this.itemRuleConfigsPromise = null;
|
|
167
|
+
this.itemRulePrefillApplied = false;
|
|
168
|
+
this.store.itemRuleQuantityLimits = [];
|
|
169
|
+
this.store.cartValidation = {
|
|
170
|
+
passed: null,
|
|
171
|
+
failures: []
|
|
172
|
+
};
|
|
173
|
+
this.window = core.getPlugin("window");
|
|
174
|
+
this.request = core.getPlugin("request");
|
|
175
|
+
if (!this.window) {
|
|
176
|
+
this.logMethodError("initialize", "window plugin missing");
|
|
177
|
+
throw new Error("scanOrder解决方案需要 window 插件支持");
|
|
178
|
+
}
|
|
179
|
+
if (!this.request) {
|
|
180
|
+
this.logMethodError("initialize", "request plugin missing");
|
|
181
|
+
throw new Error("scanOrder解决方案需要 request 插件支持");
|
|
182
|
+
}
|
|
183
|
+
const moduleArr = [
|
|
184
|
+
"scanOrderLogger",
|
|
185
|
+
"products",
|
|
186
|
+
"order",
|
|
187
|
+
"salesSummary"
|
|
188
|
+
];
|
|
189
|
+
moduleArr.forEach((step) => {
|
|
190
|
+
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
191
|
+
const targetModule = (0, import_types2.createModule)(step, this.name);
|
|
192
|
+
if (targetModule) {
|
|
193
|
+
this.store[step] = targetModule;
|
|
194
|
+
const initialState = step === "salesSummary" ? {
|
|
195
|
+
summary: ((_b2 = (_a2 = this.store.order) == null ? void 0 : _a2.getTempOrder()) == null ? void 0 : _b2.summary) || (0, import_utils.createEmptySummary)()
|
|
196
|
+
} : {};
|
|
197
|
+
const loggerProvider = ((_c2 = this.otherParams) == null ? void 0 : _c2.scanOrderLoggerProvider) || "feishu";
|
|
198
|
+
const loggerConfig = ((_d2 = this.otherParams) == null ? void 0 : _d2.scanOrderLoggerConfig) || {
|
|
199
|
+
feishu: {
|
|
200
|
+
// webhook: 'https://open.feishu.cn/open-apis/bot/v2/hook/216b3fe6-af98-424e-8706-f0471241a7ed',
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
this.core.registerModule(targetModule, {
|
|
204
|
+
initialState,
|
|
205
|
+
otherParams: {
|
|
206
|
+
...this.otherParams,
|
|
207
|
+
fatherModule: this.name,
|
|
208
|
+
openCache: ((_e2 = this.otherParams) == null ? void 0 : _e2.cacheId) ? true : false,
|
|
209
|
+
cacheId: (_f2 = this.otherParams) == null ? void 0 : _f2.cacheId,
|
|
210
|
+
salesSummaryModuleName: `${this.name}_salesSummary`,
|
|
211
|
+
provider: loggerProvider,
|
|
212
|
+
providerConfig: loggerConfig,
|
|
213
|
+
context: this.getScanOrderLoggerContext()
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
} else {
|
|
217
|
+
this.logMethodError("initialize", `module ${step} missing`);
|
|
218
|
+
throw new Error(`模块 ${step} 不存在`);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
if (this.store.scanOrderLogger) {
|
|
222
|
+
this.store.scanOrderLogger.setContext(this.getScanOrderLoggerContext());
|
|
223
|
+
}
|
|
224
|
+
console.log("[ScanOrder] 初始化开始");
|
|
225
|
+
try {
|
|
226
|
+
await ((_e = this.store.order) == null ? void 0 : _e.recalculateSummary({ createIfMissing: false }));
|
|
227
|
+
(_f = this.store.order) == null ? void 0 : _f.persistTempOrder();
|
|
228
|
+
await this.loadRuntimeConfigs();
|
|
229
|
+
await this.refreshItemRuleQuantityLimits();
|
|
230
|
+
this.store.status = "ready";
|
|
231
|
+
console.log("[ScanOrder] 初始化完成");
|
|
232
|
+
await this.core.effects.emit(import_types.ScanOrderHooks.onInited, {
|
|
233
|
+
status: this.store.status
|
|
234
|
+
});
|
|
235
|
+
this.logMethodSuccess("initialize", {
|
|
236
|
+
status: this.store.status
|
|
237
|
+
});
|
|
238
|
+
} catch (error) {
|
|
239
|
+
this.store.status = "error";
|
|
240
|
+
this.store.error = error instanceof Error ? error.message : "初始化失败";
|
|
241
|
+
console.error("[ScanOrder] 初始化失败", error);
|
|
242
|
+
this.logMethodError("initialize", error, {
|
|
243
|
+
status: this.store.status
|
|
244
|
+
});
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async destroy() {
|
|
249
|
+
this.logMethodStart("destroy");
|
|
250
|
+
await this.core.effects.emit(import_types.ScanOrderHooks.onDestroy, {});
|
|
251
|
+
console.log("[ScanOrder] 已销毁");
|
|
252
|
+
this.logMethodSuccess("destroy");
|
|
253
|
+
}
|
|
254
|
+
async retryInit() {
|
|
255
|
+
this.logMethodStart("retryInit");
|
|
256
|
+
console.log("[ScanOrder] retryInit 调用");
|
|
257
|
+
await this.core.effects.emit(import_types.ScanOrderHooks.onRetryInit, {});
|
|
258
|
+
try {
|
|
259
|
+
await this.initialize(this.core, this.initializeOptions);
|
|
260
|
+
this.logMethodSuccess("retryInit");
|
|
261
|
+
} catch (error) {
|
|
262
|
+
this.logMethodError("retryInit", error);
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async refresh() {
|
|
267
|
+
this.logMethodStart("refresh");
|
|
268
|
+
console.log("[ScanOrder] refresh 调用");
|
|
269
|
+
try {
|
|
270
|
+
this.store.status = "initializing";
|
|
271
|
+
await this.loadRuntimeConfigs();
|
|
272
|
+
await this.refreshItemRuleQuantityLimits();
|
|
273
|
+
this.store.status = "ready";
|
|
274
|
+
await this.core.effects.emit(import_types.ScanOrderHooks.onRefresh, {
|
|
275
|
+
status: this.store.status
|
|
276
|
+
});
|
|
277
|
+
this.logMethodSuccess("refresh", {
|
|
278
|
+
status: this.store.status
|
|
279
|
+
});
|
|
280
|
+
} catch (error) {
|
|
281
|
+
this.logMethodError("refresh", error);
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
getStatus() {
|
|
286
|
+
this.logMethodStart("getStatus");
|
|
287
|
+
const result = this.store.status;
|
|
288
|
+
this.logMethodSuccess("getStatus", {
|
|
289
|
+
status: result
|
|
290
|
+
});
|
|
291
|
+
return result;
|
|
292
|
+
}
|
|
293
|
+
getEntryContext() {
|
|
294
|
+
this.logMethodStart("getEntryContext");
|
|
295
|
+
const result = this.store.entryContext;
|
|
296
|
+
this.logMethodSuccess("getEntryContext", {
|
|
297
|
+
hasEntryContext: Boolean(result)
|
|
298
|
+
});
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
getConfig() {
|
|
302
|
+
this.logMethodStart("getConfig");
|
|
303
|
+
const result = this.store.config || {};
|
|
304
|
+
this.logMethodSuccess("getConfig", {
|
|
305
|
+
configKeys: Object.keys(result || {})
|
|
306
|
+
});
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
309
|
+
getItemRuleQuantityLimits() {
|
|
310
|
+
this.logMethodStart("getItemRuleQuantityLimits");
|
|
311
|
+
const result = this.store.itemRuleQuantityLimits || [];
|
|
312
|
+
this.logMethodSuccess("getItemRuleQuantityLimits", {
|
|
313
|
+
limitCount: result.length
|
|
314
|
+
});
|
|
315
|
+
return result;
|
|
316
|
+
}
|
|
317
|
+
getCartValidationPassed() {
|
|
318
|
+
var _a;
|
|
319
|
+
this.logMethodStart("getCartValidationPassed");
|
|
320
|
+
const result = ((_a = this.store.cartValidation) == null ? void 0 : _a.passed) ?? null;
|
|
321
|
+
this.logMethodSuccess("getCartValidationPassed", {
|
|
322
|
+
cartValidationPassed: result
|
|
323
|
+
});
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
getCartValidation() {
|
|
327
|
+
this.logMethodStart("getCartValidation");
|
|
328
|
+
const result = this.store.cartValidation || {
|
|
329
|
+
passed: null,
|
|
330
|
+
failures: []
|
|
331
|
+
};
|
|
332
|
+
this.logMethodSuccess("getCartValidation", {
|
|
333
|
+
cartValidationPassed: result.passed,
|
|
334
|
+
failureCount: Array.isArray(result.failures) ? result.failures.length : 0
|
|
335
|
+
});
|
|
336
|
+
return result;
|
|
337
|
+
}
|
|
338
|
+
getTempOrder() {
|
|
339
|
+
var _a, _b, _c;
|
|
340
|
+
this.logMethodStart("getTempOrder");
|
|
341
|
+
const result = ((_a = this.store.order) == null ? void 0 : _a.getTempOrder()) || null;
|
|
342
|
+
this.logMethodSuccess("getTempOrder", {
|
|
343
|
+
hasTempOrder: Boolean(result),
|
|
344
|
+
productCount: ((_b = result == null ? void 0 : result.products) == null ? void 0 : _b.length) || 0,
|
|
345
|
+
noteLength: ((_c = result == null ? void 0 : result.note) == null ? void 0 : _c.length) || 0
|
|
346
|
+
});
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
updateTempOrderNote(note) {
|
|
350
|
+
this.logMethodStart("updateTempOrderNote", {
|
|
351
|
+
noteLength: String(note || "").length
|
|
352
|
+
});
|
|
353
|
+
try {
|
|
354
|
+
if (!this.store.order)
|
|
355
|
+
throw new Error("order 模块未初始化");
|
|
356
|
+
const result = this.store.order.updateTempOrderNote(note);
|
|
357
|
+
this.logMethodSuccess("updateTempOrderNote", {
|
|
358
|
+
noteLength: result.length
|
|
359
|
+
});
|
|
360
|
+
return result;
|
|
361
|
+
} catch (error) {
|
|
362
|
+
this.logMethodError("updateTempOrderNote", error);
|
|
363
|
+
throw error;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
ensureTempOrder() {
|
|
367
|
+
if (!this.store.order)
|
|
368
|
+
throw new Error("order 模块未初始化");
|
|
369
|
+
return this.store.order.ensureTempOrder();
|
|
370
|
+
}
|
|
371
|
+
// 主动创建临时订单;若已存在则直接返回已有订单
|
|
372
|
+
async addNewOrder() {
|
|
373
|
+
this.logMethodStart("addNewOrder");
|
|
374
|
+
try {
|
|
375
|
+
if (!this.store.order)
|
|
376
|
+
throw new Error("order 模块未初始化");
|
|
377
|
+
const tempOrder = await this.store.order.addNewOrder();
|
|
378
|
+
this.logMethodSuccess("addNewOrder", {
|
|
379
|
+
productCount: tempOrder.products.length
|
|
380
|
+
});
|
|
381
|
+
return tempOrder;
|
|
382
|
+
} catch (error) {
|
|
383
|
+
this.logMethodError("addNewOrder", error);
|
|
384
|
+
throw error;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
getOrderProducts() {
|
|
388
|
+
this.logMethodStart("getOrderProducts");
|
|
389
|
+
if (!this.store.order)
|
|
390
|
+
throw new Error("order 模块未初始化");
|
|
391
|
+
const products = this.store.order.getOrderProducts();
|
|
392
|
+
this.logMethodSuccess("getOrderProducts", {
|
|
393
|
+
productCount: products.length
|
|
394
|
+
});
|
|
395
|
+
return products;
|
|
396
|
+
}
|
|
397
|
+
async getSummary() {
|
|
398
|
+
this.logMethodStart("getSummary");
|
|
399
|
+
try {
|
|
400
|
+
if (!this.store.order)
|
|
401
|
+
throw new Error("order 模块未初始化");
|
|
402
|
+
const summary = await this.store.order.getScanOrderSummary();
|
|
403
|
+
this.logMethodSuccess("getSummary", {
|
|
404
|
+
totalAmount: summary.total_amount
|
|
405
|
+
});
|
|
406
|
+
return summary;
|
|
407
|
+
} catch (error) {
|
|
408
|
+
this.logMethodError("getSummary", error);
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
async submitScanOrder() {
|
|
413
|
+
var _a;
|
|
414
|
+
this.logMethodStart("submitScanOrder");
|
|
415
|
+
try {
|
|
416
|
+
await this.validateBeforeSubmitByItemRule();
|
|
417
|
+
if (!this.store.order) {
|
|
418
|
+
throw new Error("scanOrder解决方案需要 order 模块支持");
|
|
419
|
+
}
|
|
420
|
+
const result = await this.store.order.submitTempOrder({
|
|
421
|
+
cacheId: this.cacheId
|
|
422
|
+
});
|
|
423
|
+
const tempOrder = this.store.order.getTempOrder();
|
|
424
|
+
this.logMethodSuccess("submitScanOrder", {
|
|
425
|
+
productCount: ((_a = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _a.length) || 0
|
|
426
|
+
});
|
|
427
|
+
return result;
|
|
428
|
+
} catch (error) {
|
|
429
|
+
this.logMethodError("submitScanOrder", error);
|
|
430
|
+
throw error;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
async addProductToOrder(product) {
|
|
434
|
+
this.logMethodStart("addProductToOrder", {
|
|
435
|
+
product_id: product.product_id,
|
|
436
|
+
product_variant_id: product.product_variant_id
|
|
437
|
+
});
|
|
438
|
+
try {
|
|
439
|
+
if (!this.store.order)
|
|
440
|
+
throw new Error("order 模块未初始化");
|
|
441
|
+
const products = await this.store.order.addProductToOrder(product);
|
|
442
|
+
await this.refreshItemRuleQuantityLimits();
|
|
443
|
+
await this.refreshCartValidationPassed();
|
|
444
|
+
this.logMethodSuccess("addProductToOrder", {
|
|
445
|
+
productCount: products.length
|
|
446
|
+
});
|
|
447
|
+
return products;
|
|
448
|
+
} catch (error) {
|
|
449
|
+
this.logMethodError("addProductToOrder", error);
|
|
450
|
+
throw error;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
async updateProductInOrder(params) {
|
|
454
|
+
this.logMethodStart("updateProductInOrder", {
|
|
455
|
+
product_id: params.product_id,
|
|
456
|
+
product_variant_id: params.product_variant_id
|
|
457
|
+
});
|
|
458
|
+
try {
|
|
459
|
+
if (!this.store.order)
|
|
460
|
+
throw new Error("order 模块未初始化");
|
|
461
|
+
const products = await this.store.order.updateProductInOrder(params);
|
|
462
|
+
await this.refreshItemRuleQuantityLimits();
|
|
463
|
+
await this.refreshCartValidationPassed();
|
|
464
|
+
this.logMethodSuccess("updateProductInOrder", {
|
|
465
|
+
productCount: products.length
|
|
466
|
+
});
|
|
467
|
+
return products;
|
|
468
|
+
} catch (error) {
|
|
469
|
+
this.logMethodError("updateProductInOrder", error);
|
|
470
|
+
throw error;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
async removeProductFromOrder(identity) {
|
|
474
|
+
this.logMethodStart("removeProductFromOrder", {
|
|
475
|
+
product_id: identity.product_id,
|
|
476
|
+
product_variant_id: identity.product_variant_id
|
|
477
|
+
});
|
|
478
|
+
try {
|
|
479
|
+
if (!this.store.order)
|
|
480
|
+
throw new Error("order 模块未初始化");
|
|
481
|
+
const products = await this.store.order.removeProductFromOrder(identity);
|
|
482
|
+
await this.refreshItemRuleQuantityLimits();
|
|
483
|
+
await this.refreshCartValidationPassed();
|
|
484
|
+
this.logMethodSuccess("removeProductFromOrder", {
|
|
485
|
+
productCount: products.length
|
|
486
|
+
});
|
|
487
|
+
return products;
|
|
488
|
+
} catch (error) {
|
|
489
|
+
this.logMethodError("removeProductFromOrder", error);
|
|
490
|
+
throw error;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
async loadRuntimeConfigs() {
|
|
494
|
+
const itemRuleConfigs = await this.ensureItemRuleConfigsLoaded();
|
|
495
|
+
this.logMethodSuccess("loadRuntimeConfigs", {
|
|
496
|
+
itemRuleCount: itemRuleConfigs.length
|
|
497
|
+
});
|
|
498
|
+
return {
|
|
499
|
+
itemRuleConfigs
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
async syncItemRuleConfigsFromDineInConfig(dineInConfig) {
|
|
503
|
+
const enableItemRules = (0, import_utils.toBoolean)(dineInConfig == null ? void 0 : dineInConfig["sale.enable_item_rules"]);
|
|
504
|
+
const strategyModelIds = (0, import_utils.normalizeEnabledItemRuleIds)(
|
|
505
|
+
dineInConfig == null ? void 0 : dineInConfig["sale.enabled_item_rules"]
|
|
506
|
+
);
|
|
507
|
+
if (!enableItemRules || !strategyModelIds.length) {
|
|
508
|
+
this.itemRuleConfigs = [];
|
|
509
|
+
this.itemRuleConfigsPromise = Promise.resolve([]);
|
|
510
|
+
this.itemRuleEvaluator.setStrategyConfigs([]);
|
|
511
|
+
this.logMethodSuccess("syncItemRuleConfigsFromDineInConfig", {
|
|
512
|
+
enabled: enableItemRules,
|
|
513
|
+
strategyModelIds: [],
|
|
514
|
+
itemRuleCount: 0
|
|
515
|
+
});
|
|
516
|
+
return [];
|
|
517
|
+
}
|
|
518
|
+
const itemRuleConfigs = await this.fetchItemRuleConfigsByModelIds(
|
|
519
|
+
strategyModelIds
|
|
520
|
+
);
|
|
521
|
+
this.itemRuleConfigs = itemRuleConfigs;
|
|
522
|
+
this.itemRuleConfigsPromise = Promise.resolve(itemRuleConfigs);
|
|
523
|
+
this.itemRuleEvaluator.setStrategyConfigs(itemRuleConfigs);
|
|
524
|
+
this.logMethodSuccess("syncItemRuleConfigsFromDineInConfig", {
|
|
525
|
+
enabled: enableItemRules,
|
|
526
|
+
strategyModelIds,
|
|
527
|
+
itemRuleCount: itemRuleConfigs.length
|
|
528
|
+
});
|
|
529
|
+
return itemRuleConfigs;
|
|
530
|
+
}
|
|
531
|
+
async fetchItemRuleConfigsByModelIds(strategyModelIds) {
|
|
532
|
+
this.logMethodStart("fetchItemRuleConfigsByModelIds", {
|
|
533
|
+
strategyModelIds
|
|
534
|
+
});
|
|
535
|
+
if (!strategyModelIds.length)
|
|
536
|
+
return [];
|
|
537
|
+
try {
|
|
538
|
+
const result = await this.request.get("/promotion", {
|
|
539
|
+
skip: 1,
|
|
540
|
+
num: 99,
|
|
541
|
+
status: "active",
|
|
542
|
+
ids: strategyModelIds
|
|
543
|
+
});
|
|
544
|
+
let configs = [];
|
|
545
|
+
if (result.code === 200) {
|
|
546
|
+
configs = result.data.list.map((item) => {
|
|
547
|
+
return item.metadata;
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
this.logMethodSuccess("fetchItemRuleConfigsByModelIds", {
|
|
551
|
+
strategyModelIds,
|
|
552
|
+
strategyCount: configs.length
|
|
553
|
+
});
|
|
554
|
+
return configs;
|
|
555
|
+
} catch (error) {
|
|
556
|
+
this.logMethodError("fetchItemRuleConfigsByModelIds", error, {
|
|
557
|
+
strategyModelIds
|
|
558
|
+
});
|
|
559
|
+
return [];
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
async buildPrefillProductSourceMap() {
|
|
563
|
+
const sourceMap = /* @__PURE__ */ new Map();
|
|
564
|
+
try {
|
|
565
|
+
const productList = await this.getProductList();
|
|
566
|
+
if (!Array.isArray(productList))
|
|
567
|
+
return sourceMap;
|
|
568
|
+
const visited = /* @__PURE__ */ new Set();
|
|
569
|
+
const collectFromValue = (value) => {
|
|
570
|
+
if (!value || typeof value !== "object")
|
|
571
|
+
return;
|
|
572
|
+
if (visited.has(value))
|
|
573
|
+
return;
|
|
574
|
+
visited.add(value);
|
|
575
|
+
if (Array.isArray(value)) {
|
|
576
|
+
for (const item of value)
|
|
577
|
+
collectFromValue(item);
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
const node = value;
|
|
581
|
+
const rawProductId = node.product_id ?? node.id;
|
|
582
|
+
const productId = Number(rawProductId);
|
|
583
|
+
if (Number.isFinite(productId) && productId > 0) {
|
|
584
|
+
const productVariantId = Number(
|
|
585
|
+
node.product_variant_id ?? node.variant_id ?? 0
|
|
586
|
+
);
|
|
587
|
+
const normalizedVariantId = Number.isNaN(productVariantId) ? 0 : productVariantId;
|
|
588
|
+
const key = (0, import_utils.buildProductKey)(productId, normalizedVariantId);
|
|
589
|
+
if (!sourceMap.has(key)) {
|
|
590
|
+
sourceMap.set(key, node);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
for (const childValue of Object.values(node)) {
|
|
594
|
+
if (childValue && typeof childValue === "object") {
|
|
595
|
+
collectFromValue(childValue);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
collectFromValue(productList);
|
|
600
|
+
} catch (error) {
|
|
601
|
+
this.logMethodError("buildPrefillProductSourceMap", error);
|
|
602
|
+
}
|
|
603
|
+
return sourceMap;
|
|
604
|
+
}
|
|
605
|
+
getItemRuleRuntimeConfig() {
|
|
606
|
+
return this.itemRuleRuntimeConfig || {};
|
|
607
|
+
}
|
|
608
|
+
async ensureItemRuleConfigsLoaded() {
|
|
609
|
+
if (this.itemRuleConfigs.length > 0)
|
|
610
|
+
return this.itemRuleConfigs;
|
|
611
|
+
if (this.itemRuleConfigsPromise)
|
|
612
|
+
return this.itemRuleConfigsPromise;
|
|
613
|
+
this.itemRuleConfigsPromise = (async () => {
|
|
614
|
+
const runtimeConfig = this.getItemRuleRuntimeConfig();
|
|
615
|
+
const staticConfigs = (0, import_utils.normalizeItemRuleStrategies)(runtimeConfig.strategyConfigs);
|
|
616
|
+
if (staticConfigs.length > 0) {
|
|
617
|
+
this.itemRuleConfigs = staticConfigs;
|
|
618
|
+
this.itemRuleEvaluator.setStrategyConfigs(staticConfigs);
|
|
619
|
+
return this.itemRuleConfigs;
|
|
620
|
+
}
|
|
621
|
+
this.itemRuleConfigs = [];
|
|
622
|
+
this.itemRuleEvaluator.setStrategyConfigs([]);
|
|
623
|
+
return this.itemRuleConfigs;
|
|
624
|
+
})();
|
|
625
|
+
const loadedConfigs = await this.itemRuleConfigsPromise;
|
|
626
|
+
return loadedConfigs;
|
|
627
|
+
}
|
|
628
|
+
async refreshItemRuleQuantityLimits() {
|
|
629
|
+
try {
|
|
630
|
+
const strategyConfigs = await this.ensureItemRuleConfigsLoaded();
|
|
631
|
+
if (!strategyConfigs.length) {
|
|
632
|
+
this.store.itemRuleQuantityLimits = [];
|
|
633
|
+
return [];
|
|
634
|
+
}
|
|
635
|
+
const businessData = (0, import_utils.buildItemRuleBusinessData)({
|
|
636
|
+
tempOrder: this.ensureTempOrder(),
|
|
637
|
+
runtimeConfig: this.getItemRuleRuntimeConfig(),
|
|
638
|
+
itemRuleConfigs: this.itemRuleConfigs
|
|
639
|
+
});
|
|
640
|
+
const limits = this.itemRuleEvaluator.getQuantityLimits(businessData);
|
|
641
|
+
this.store.itemRuleQuantityLimits = limits;
|
|
642
|
+
this.logMethodSuccess("refreshItemRuleQuantityLimits", {
|
|
643
|
+
limitCount: limits.length
|
|
644
|
+
});
|
|
645
|
+
return limits;
|
|
646
|
+
} catch (error) {
|
|
647
|
+
this.store.itemRuleQuantityLimits = [];
|
|
648
|
+
this.logMethodError("refreshItemRuleQuantityLimits", error);
|
|
649
|
+
return [];
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
async applyPrefillByItemRule() {
|
|
653
|
+
var _a, _b, _c;
|
|
654
|
+
if (this.itemRulePrefillApplied)
|
|
655
|
+
return;
|
|
656
|
+
if (!this.store.order)
|
|
657
|
+
return;
|
|
658
|
+
const strategyConfigs = await this.ensureItemRuleConfigsLoaded();
|
|
659
|
+
if (!strategyConfigs.length)
|
|
660
|
+
return;
|
|
661
|
+
const businessData = (0, import_utils.buildItemRuleBusinessData)({
|
|
662
|
+
tempOrder: this.ensureTempOrder(),
|
|
663
|
+
runtimeConfig: this.getItemRuleRuntimeConfig(),
|
|
664
|
+
itemRuleConfigs: this.itemRuleConfigs
|
|
665
|
+
});
|
|
666
|
+
const prefillItems = this.itemRuleEvaluator.getPrefillItems(businessData);
|
|
667
|
+
if (!prefillItems.length) {
|
|
668
|
+
this.itemRulePrefillApplied = true;
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
const productSourceMap = await this.buildPrefillProductSourceMap();
|
|
672
|
+
const tempOrder = this.ensureTempOrder();
|
|
673
|
+
let hasChanges = false;
|
|
674
|
+
for (const prefillItem of prefillItems) {
|
|
675
|
+
const productId = Number(prefillItem.product_id);
|
|
676
|
+
const productVariantId = Number(prefillItem.product_variant_id ?? 0);
|
|
677
|
+
const targetQuantity = (0, import_utils.toNonNegativeInt)(prefillItem.quantity);
|
|
678
|
+
if (!Number.isFinite(productId) || targetQuantity <= 0)
|
|
679
|
+
continue;
|
|
680
|
+
if (Number.isNaN(productVariantId))
|
|
681
|
+
continue;
|
|
682
|
+
const sourceItem = productSourceMap.get(
|
|
683
|
+
(0, import_utils.buildProductKey)(productId, productVariantId)
|
|
684
|
+
) || productSourceMap.get((0, import_utils.buildProductKey)(productId, 0)) || null;
|
|
685
|
+
const productIndex = (0, import_utils.getProductIdentityIndex)(tempOrder.products, {
|
|
686
|
+
product_id: productId,
|
|
687
|
+
product_variant_id: productVariantId
|
|
688
|
+
});
|
|
689
|
+
if (productIndex === -1) {
|
|
690
|
+
const sellingPrice = (0, import_utils.toPriceString)(
|
|
691
|
+
(sourceItem == null ? void 0 : sourceItem.price) ?? (sourceItem == null ? void 0 : sourceItem.selling_price),
|
|
692
|
+
"0.00"
|
|
693
|
+
);
|
|
694
|
+
const originalPrice = (0, import_utils.toPriceString)(
|
|
695
|
+
(sourceItem == null ? void 0 : sourceItem.original_price) ?? (sourceItem == null ? void 0 : sourceItem.price) ?? sellingPrice,
|
|
696
|
+
sellingPrice
|
|
697
|
+
);
|
|
698
|
+
const paymentPrice = (0, import_utils.toPriceString)(
|
|
699
|
+
(sourceItem == null ? void 0 : sourceItem.payment_price) ?? (sourceItem == null ? void 0 : sourceItem.price) ?? sellingPrice,
|
|
700
|
+
sellingPrice
|
|
701
|
+
);
|
|
702
|
+
tempOrder.products.push(
|
|
703
|
+
(0, import_utils.normalizeOrderProduct)({
|
|
704
|
+
product_id: productId,
|
|
705
|
+
product_variant_id: productVariantId,
|
|
706
|
+
num: targetQuantity,
|
|
707
|
+
selling_price: sellingPrice,
|
|
708
|
+
original_price: originalPrice,
|
|
709
|
+
payment_price: paymentPrice,
|
|
710
|
+
metadata: {
|
|
711
|
+
item_rule_prefill: true,
|
|
712
|
+
item_rule_id: prefillItem.ruleId
|
|
713
|
+
},
|
|
714
|
+
_origin: {
|
|
715
|
+
...sourceItem || {},
|
|
716
|
+
item_rule_prefill: true,
|
|
717
|
+
item_rule_id: prefillItem.ruleId
|
|
718
|
+
}
|
|
719
|
+
})
|
|
720
|
+
);
|
|
721
|
+
hasChanges = true;
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
const targetProduct = tempOrder.products[productIndex];
|
|
725
|
+
const existedQuantity = (0, import_utils.toNonNegativeInt)(targetProduct.num);
|
|
726
|
+
const delta = targetQuantity - existedQuantity;
|
|
727
|
+
const nextProduct = {
|
|
728
|
+
...targetProduct,
|
|
729
|
+
...delta > 0 ? { num: (0, import_utils.getSafeProductNum)(existedQuantity + delta) } : {},
|
|
730
|
+
metadata: {
|
|
731
|
+
...targetProduct.metadata || {},
|
|
732
|
+
item_rule_prefill: true,
|
|
733
|
+
item_rule_id: prefillItem.ruleId
|
|
734
|
+
},
|
|
735
|
+
_origin: sourceItem ? {
|
|
736
|
+
...targetProduct._origin || {},
|
|
737
|
+
...sourceItem
|
|
738
|
+
} : targetProduct._origin
|
|
739
|
+
};
|
|
740
|
+
const hasQuantityChanged = delta > 0;
|
|
741
|
+
const hasOriginChanged = Boolean(
|
|
742
|
+
sourceItem && (!targetProduct._origin || ((_a = targetProduct._origin) == null ? void 0 : _a.name) !== (sourceItem == null ? void 0 : sourceItem.name) || ((_b = targetProduct._origin) == null ? void 0 : _b.title) !== (sourceItem == null ? void 0 : sourceItem.title) || ((_c = targetProduct._origin) == null ? void 0 : _c.price) !== (sourceItem == null ? void 0 : sourceItem.price))
|
|
743
|
+
);
|
|
744
|
+
if (hasQuantityChanged || hasOriginChanged) {
|
|
745
|
+
tempOrder.products[productIndex] = nextProduct;
|
|
746
|
+
hasChanges = true;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
if (hasChanges) {
|
|
750
|
+
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
751
|
+
this.store.order.persistTempOrder();
|
|
752
|
+
}
|
|
753
|
+
await this.refreshItemRuleQuantityLimits();
|
|
754
|
+
this.itemRulePrefillApplied = true;
|
|
755
|
+
this.logMethodSuccess("applyPrefillByItemRule", {
|
|
756
|
+
prefillCount: prefillItems.length,
|
|
757
|
+
hasChanges
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
async applyItemRulePrefill() {
|
|
761
|
+
this.logMethodStart("applyItemRulePrefill");
|
|
762
|
+
await this.applyPrefillByItemRule();
|
|
763
|
+
await this.refreshItemRuleQuantityLimits();
|
|
764
|
+
await this.refreshCartValidationPassed();
|
|
765
|
+
}
|
|
766
|
+
async evaluateCartValidationByItemRule() {
|
|
767
|
+
const strategyConfigs = await this.ensureItemRuleConfigsLoaded();
|
|
768
|
+
if (!strategyConfigs.length) {
|
|
769
|
+
return {
|
|
770
|
+
passed: true,
|
|
771
|
+
failures: []
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
const businessData = (0, import_utils.buildItemRuleBusinessData)({
|
|
775
|
+
tempOrder: this.ensureTempOrder(),
|
|
776
|
+
runtimeConfig: this.getItemRuleRuntimeConfig(),
|
|
777
|
+
itemRuleConfigs: this.itemRuleConfigs
|
|
778
|
+
});
|
|
779
|
+
return this.itemRuleEvaluator.validateCart(businessData);
|
|
780
|
+
}
|
|
781
|
+
async validateBeforeSubmitByItemRule() {
|
|
782
|
+
const validationResult = await this.evaluateCartValidationByItemRule();
|
|
783
|
+
if (validationResult.passed)
|
|
784
|
+
return;
|
|
785
|
+
const firstFailure = validationResult.failures[0];
|
|
786
|
+
const errorMessage = (firstFailure == null ? void 0 : firstFailure.validationMessage) || "当前购物车未满足商品规则,请调整后再提交";
|
|
787
|
+
const error = new Error(String(errorMessage));
|
|
788
|
+
error.failures = validationResult.failures;
|
|
789
|
+
throw error;
|
|
790
|
+
}
|
|
791
|
+
async refreshCartValidationPassed() {
|
|
792
|
+
const previous = this.store.cartValidation || {
|
|
793
|
+
passed: null,
|
|
794
|
+
failures: []
|
|
795
|
+
};
|
|
796
|
+
let nextState = {
|
|
797
|
+
passed: null,
|
|
798
|
+
failures: []
|
|
799
|
+
};
|
|
800
|
+
try {
|
|
801
|
+
const validationResult = await this.evaluateCartValidationByItemRule();
|
|
802
|
+
nextState = {
|
|
803
|
+
passed: validationResult.passed,
|
|
804
|
+
failures: validationResult.failures || []
|
|
805
|
+
};
|
|
806
|
+
} catch (error) {
|
|
807
|
+
nextState = {
|
|
808
|
+
passed: false,
|
|
809
|
+
failures: []
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
this.store.cartValidation = nextState;
|
|
813
|
+
const changed = previous.passed !== nextState.passed || previous.failures !== nextState.failures;
|
|
814
|
+
if (changed) {
|
|
815
|
+
await this.core.effects.emit(import_types.ScanOrderHooks.onCartValidationChanged, {
|
|
816
|
+
cartValidation: nextState,
|
|
817
|
+
cartValidationPassed: nextState.passed
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
return nextState.passed;
|
|
821
|
+
}
|
|
822
|
+
async setItemRuleRuntimeConfig(config = {}) {
|
|
823
|
+
var _a, _b;
|
|
824
|
+
this.logMethodStart("setItemRuleRuntimeConfig");
|
|
825
|
+
this.itemRuleRuntimeConfig = {
|
|
826
|
+
...this.itemRuleRuntimeConfig,
|
|
827
|
+
...config,
|
|
828
|
+
pax: {
|
|
829
|
+
...((_a = this.itemRuleRuntimeConfig) == null ? void 0 : _a.pax) || {},
|
|
830
|
+
...(config == null ? void 0 : config.pax) || {}
|
|
831
|
+
},
|
|
832
|
+
custom: {
|
|
833
|
+
...((_b = this.itemRuleRuntimeConfig) == null ? void 0 : _b.custom) || {},
|
|
834
|
+
...(config == null ? void 0 : config.custom) || {}
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
if ("strategyConfigs" in config) {
|
|
838
|
+
this.itemRuleConfigs = [];
|
|
839
|
+
this.itemRuleConfigsPromise = null;
|
|
840
|
+
this.itemRuleEvaluator.setStrategyConfigs([]);
|
|
841
|
+
}
|
|
842
|
+
this.itemRulePrefillApplied = false;
|
|
843
|
+
await this.refreshItemRuleQuantityLimits();
|
|
844
|
+
await this.refreshCartValidationPassed();
|
|
845
|
+
this.logMethodSuccess("setItemRuleRuntimeConfig", {
|
|
846
|
+
strategyCount: Array.isArray(this.itemRuleRuntimeConfig.strategyConfigs) ? this.itemRuleRuntimeConfig.strategyConfigs.length : 0
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
normalizeResourceState(config, hasOrderId) {
|
|
850
|
+
var _a, _b;
|
|
851
|
+
const orderNumberPrefix = Array.isArray(config == null ? void 0 : config.order_number_prefix) ? (config == null ? void 0 : config.order_number_prefix) || [] : [];
|
|
852
|
+
const tableMaxNumber = Number((config == null ? void 0 : config.table_max_number) || 1);
|
|
853
|
+
const orderCount = (0, import_utils.toNonNegativeNumber)(config == null ? void 0 : config.order_count);
|
|
854
|
+
const currentOrderId = (0, import_utils.toPositiveString)(config == null ? void 0 : config.order_id);
|
|
855
|
+
const lastOrderId = (0, import_utils.toPositiveString)(config == null ? void 0 : config.last_order_id);
|
|
856
|
+
const relationId = (0, import_utils.toPositiveString)(config == null ? void 0 : config.relation_id);
|
|
857
|
+
const tableFormId = (0, import_utils.toPositiveString)(config == null ? void 0 : config.table_form_id);
|
|
858
|
+
const allowSnack = ((_b = (_a = this.otherParams) == null ? void 0 : _a.dineInConfig) == null ? void 0 : _b["workflow.allow_add_items"]) || false;
|
|
859
|
+
const deskmateValid = false;
|
|
860
|
+
const isExclusive = tableMaxNumber > 0 ? tableMaxNumber <= 1 : false;
|
|
861
|
+
const isFull = tableMaxNumber > 0 ? orderCount >= tableMaxNumber : false;
|
|
862
|
+
const isBlock = tableMaxNumber === -1;
|
|
863
|
+
let availabilityInfo = {
|
|
864
|
+
mode: "idle",
|
|
865
|
+
deskmate_valid: deskmateValid
|
|
866
|
+
};
|
|
867
|
+
if (currentOrderId) {
|
|
868
|
+
if (!hasOrderId) {
|
|
869
|
+
availabilityInfo = {
|
|
870
|
+
mode: "resource_busy",
|
|
871
|
+
order_id: currentOrderId,
|
|
872
|
+
relation_id: relationId,
|
|
873
|
+
table_form_id: tableFormId,
|
|
874
|
+
deskmate_valid: deskmateValid
|
|
875
|
+
};
|
|
876
|
+
} else {
|
|
877
|
+
availabilityInfo = {
|
|
878
|
+
mode: allowSnack ? "additional_order" : "resource_busy",
|
|
879
|
+
order_id: currentOrderId,
|
|
880
|
+
relation_id: relationId,
|
|
881
|
+
table_form_id: tableFormId,
|
|
882
|
+
deskmate_valid: deskmateValid
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
} else if (lastOrderId) {
|
|
886
|
+
availabilityInfo = allowSnack ? {
|
|
887
|
+
mode: deskmateValid ? "additional_order_with_code" : "additional_order",
|
|
888
|
+
order_id: lastOrderId,
|
|
889
|
+
relation_id: relationId,
|
|
890
|
+
table_form_id: tableFormId,
|
|
891
|
+
deskmate_valid: deskmateValid
|
|
892
|
+
} : {
|
|
893
|
+
mode: "resource_busy",
|
|
894
|
+
order_id: lastOrderId,
|
|
895
|
+
relation_id: relationId,
|
|
896
|
+
table_form_id: tableFormId,
|
|
897
|
+
deskmate_valid: deskmateValid
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
if (isBlock) {
|
|
901
|
+
availabilityInfo = {
|
|
902
|
+
mode: "resource_block",
|
|
903
|
+
order_id: lastOrderId,
|
|
904
|
+
relation_id: relationId,
|
|
905
|
+
table_form_id: tableFormId,
|
|
906
|
+
deskmate_valid: deskmateValid
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
return {
|
|
910
|
+
...availabilityInfo,
|
|
911
|
+
tableMaxNumber,
|
|
912
|
+
orderCount,
|
|
913
|
+
currentOrderId,
|
|
914
|
+
lastOrderId,
|
|
915
|
+
relationId,
|
|
916
|
+
tableFormId,
|
|
917
|
+
allowSnack,
|
|
918
|
+
deskmateValid,
|
|
919
|
+
isExclusive,
|
|
920
|
+
isFull,
|
|
921
|
+
orderNumberPrefix,
|
|
922
|
+
raw: config
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
async fetchTableConfigByResourceId(resourceId) {
|
|
926
|
+
const tableResourceId = Number(resourceId);
|
|
927
|
+
if (!Number.isFinite(tableResourceId) || tableResourceId <= 0) {
|
|
928
|
+
throw new Error(`[ScanOrder] 非法桌台 resourceId: ${resourceId}`);
|
|
929
|
+
}
|
|
930
|
+
const response = await this.request.get(
|
|
931
|
+
"/order/dining/table/config",
|
|
932
|
+
{
|
|
933
|
+
table_resource_id: tableResourceId,
|
|
934
|
+
with_table_form_info: 1
|
|
935
|
+
}
|
|
936
|
+
);
|
|
937
|
+
if (!(response == null ? void 0 : response.status)) {
|
|
938
|
+
throw new Error((response == null ? void 0 : response.message) || "获取桌台配置失败");
|
|
939
|
+
}
|
|
940
|
+
return (response == null ? void 0 : response.data) || null;
|
|
941
|
+
}
|
|
942
|
+
// 检测当前链接是否可用
|
|
943
|
+
// 通过 resource_id + 店铺配置
|
|
944
|
+
// hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
|
|
945
|
+
async checkResourceAvailable(resourceId, hasOrderId) {
|
|
946
|
+
var _a, _b, _c, _d, _e, _f;
|
|
947
|
+
this.logMethodStart("checkResourceAvailable", {
|
|
948
|
+
resourceId
|
|
949
|
+
});
|
|
950
|
+
try {
|
|
951
|
+
const openData = await ((_b = (_a = this.otherParams) == null ? void 0 : _a.getOpenData) == null ? void 0 : _b.call(_a, {
|
|
952
|
+
scope: "board",
|
|
953
|
+
target: "dine_in+scan_to_order",
|
|
954
|
+
section_code: ["basic", "fulfillment", "reservation", "sale", "menu", "availability", "workflow"]
|
|
955
|
+
}));
|
|
956
|
+
if ((openData == null ? void 0 : openData.status) === false) {
|
|
957
|
+
throw new Error((openData == null ? void 0 : openData.message) || "获取店铺配置失败");
|
|
958
|
+
}
|
|
959
|
+
const dineInConfig = (openData == null ? void 0 : openData.data) || {};
|
|
960
|
+
this.otherParams.dineInConfig = dineInConfig;
|
|
961
|
+
await this.syncItemRuleConfigsFromDineInConfig(dineInConfig);
|
|
962
|
+
const shopClosedInfo = () => ({
|
|
963
|
+
mode: "shop_closed",
|
|
964
|
+
order_id: void 0,
|
|
965
|
+
relation_id: void 0,
|
|
966
|
+
table_form_id: void 0,
|
|
967
|
+
deskmate_valid: false,
|
|
968
|
+
errorTips: (dineInConfig == null ? void 0 : dineInConfig["availability.pause_message"]) || (dineInConfig == null ? void 0 : dineInConfig["availability.closed_message"]) || (dineInConfig == null ? void 0 : dineInConfig["availability.message"]) || (dineInConfig == null ? void 0 : dineInConfig["basic.closed_message"])
|
|
969
|
+
});
|
|
970
|
+
if ((0, import_utils.toBoolean)(dineInConfig == null ? void 0 : dineInConfig["availability.paused"])) {
|
|
971
|
+
if ((dineInConfig == null ? void 0 : dineInConfig["availability.pause_behavior"]) === "hide_all") {
|
|
972
|
+
return shopClosedInfo();
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
const config = await this.fetchTableConfigByResourceId(resourceId);
|
|
976
|
+
const resourceState = this.normalizeResourceState(config, hasOrderId);
|
|
977
|
+
this.store.resource = resourceState;
|
|
978
|
+
const availabilityInfo = {
|
|
979
|
+
mode: resourceState.mode,
|
|
980
|
+
order_id: resourceState.order_id,
|
|
981
|
+
relation_id: resourceState.relationId,
|
|
982
|
+
table_form_id: resourceState.tableFormId,
|
|
983
|
+
deskmate_valid: resourceState.deskmate_valid,
|
|
984
|
+
policy: (_c = config == null ? void 0 : config.table_form_record) == null ? void 0 : _c.policy,
|
|
985
|
+
partyroom_booking: (_d = config == null ? void 0 : config.table_form_record) == null ? void 0 : _d.partyroom_booking
|
|
986
|
+
};
|
|
987
|
+
const tempOrder = this.ensureTempOrder();
|
|
988
|
+
tempOrder.relation_id = resourceId || ((_e = this.otherParams) == null ? void 0 : _e.relation_id);
|
|
989
|
+
tempOrder.table_form_id = resourceState.tableFormId;
|
|
990
|
+
tempOrder.resource_id = resourceId;
|
|
991
|
+
(_f = this.store.order) == null ? void 0 : _f.persistTempOrder();
|
|
992
|
+
if (availabilityInfo.mode === "idle") {
|
|
993
|
+
await this.addNewOrder();
|
|
994
|
+
}
|
|
995
|
+
if (availabilityInfo.mode === "additional_order" || availabilityInfo.mode === "additional_order_with_code") {
|
|
996
|
+
tempOrder.order_id = resourceState.lastOrderId;
|
|
997
|
+
}
|
|
998
|
+
await this.refreshItemRuleQuantityLimits();
|
|
999
|
+
await this.refreshCartValidationPassed();
|
|
1000
|
+
this.logMethodSuccess("checkResourceAvailable", {
|
|
1001
|
+
resourceId,
|
|
1002
|
+
mode: availabilityInfo.mode,
|
|
1003
|
+
orderId: availabilityInfo.order_id,
|
|
1004
|
+
relationId: availabilityInfo.relation_id,
|
|
1005
|
+
tableFormId: availabilityInfo.table_form_id,
|
|
1006
|
+
persistedRelationId: tempOrder.relation_id,
|
|
1007
|
+
persistedResourceId: tempOrder.resource_id,
|
|
1008
|
+
deskmateValid: availabilityInfo.deskmate_valid,
|
|
1009
|
+
orderCount: resourceState.orderCount,
|
|
1010
|
+
tableMaxNumber: resourceState.tableMaxNumber,
|
|
1011
|
+
isExclusive: resourceState.isExclusive,
|
|
1012
|
+
isFull: resourceState.isFull
|
|
1013
|
+
});
|
|
1014
|
+
return availabilityInfo;
|
|
1015
|
+
} catch (error) {
|
|
1016
|
+
this.logMethodError("checkResourceAvailable", error, {
|
|
1017
|
+
resourceId
|
|
1018
|
+
});
|
|
1019
|
+
throw error;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
// 如果是加单的情况,提供返回当前订单相关信息的能力
|
|
1023
|
+
async getAdditionalOrderInfo() {
|
|
1024
|
+
this.logMethodStart("getAdditionalOrderInfo");
|
|
1025
|
+
const result = {
|
|
1026
|
+
orderId: "123567890",
|
|
1027
|
+
orderStatus: "pending",
|
|
1028
|
+
orderTime: "2026-03-31 10:00:00",
|
|
1029
|
+
orderAmount: 100,
|
|
1030
|
+
orderItems: []
|
|
1031
|
+
};
|
|
1032
|
+
this.logMethodSuccess("getAdditionalOrderInfo", {
|
|
1033
|
+
orderId: result.orderId,
|
|
1034
|
+
orderStatus: result.orderStatus
|
|
1035
|
+
});
|
|
1036
|
+
return result;
|
|
1037
|
+
}
|
|
1038
|
+
// 获取商品列表
|
|
1039
|
+
async getProductList() {
|
|
1040
|
+
var _a, _b, _c;
|
|
1041
|
+
this.logMethodStart("getProductList");
|
|
1042
|
+
const menu_list_ids = ((_b = (_a = this.otherParams) == null ? void 0 : _a.dineInConfig) == null ? void 0 : _b["menu.associated_menus"].map((n) => Number(n.value))) || [];
|
|
1043
|
+
try {
|
|
1044
|
+
const res = await ((_c = this.store.products) == null ? void 0 : _c.loadProducts({
|
|
1045
|
+
menu_list_ids,
|
|
1046
|
+
cacheId: this.cacheId,
|
|
1047
|
+
schedule_date: (0, import_dayjs.default)().format("YYYY-MM-DD"),
|
|
1048
|
+
schedule_datetime: (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
|
|
1049
|
+
}));
|
|
1050
|
+
const formattedRes = (0, import_utils.attachItemRuleLimitsToTopLevelProducts)(
|
|
1051
|
+
res,
|
|
1052
|
+
this.store.itemRuleQuantityLimits || []
|
|
1053
|
+
);
|
|
1054
|
+
this.logMethodSuccess("getProductList", {
|
|
1055
|
+
menuCount: menu_list_ids.length
|
|
1056
|
+
});
|
|
1057
|
+
return formattedRes;
|
|
1058
|
+
} catch (error) {
|
|
1059
|
+
this.logMethodError("getProductList", error);
|
|
1060
|
+
throw error;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
getOtherParams() {
|
|
1064
|
+
return this.otherParams;
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1068
|
+
0 && (module.exports = {
|
|
1069
|
+
ScanOrderImpl,
|
|
1070
|
+
...require("./types")
|
|
1071
|
+
});
|