@pisell/pisellos 2.3.112 → 2.3.114
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/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/BookingContext/index.js +4 -4
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Payment/index.d.ts +0 -5
- package/dist/modules/Payment/index.js +35 -85
- package/dist/modules/ResourcePlanner/planner.js +9 -5
- package/dist/modules/ResourcePlanner/types.d.ts +2 -1
- package/dist/server/index.js +4 -0
- package/dist/server/modules/payment/index.d.ts +25 -6
- package/dist/server/modules/payment/index.js +660 -133
- package/dist/solution/BaseSales/index.d.ts +2 -0
- package/dist/solution/BaseSales/index.js +1081 -1042
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/UnifiedBookingSales/index.d.ts +2 -2
- package/dist/solution/UnifiedBookingSales/index.js +3 -3
- package/lib/modules/BookingContext/index.js +3 -3
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Payment/index.d.ts +0 -5
- package/lib/modules/Payment/index.js +3 -28
- package/lib/modules/ResourcePlanner/planner.js +9 -5
- package/lib/modules/ResourcePlanner/types.d.ts +2 -1
- package/lib/server/index.js +4 -0
- package/lib/server/modules/payment/index.d.ts +25 -6
- package/lib/server/modules/payment/index.js +350 -78
- package/lib/solution/BaseSales/index.d.ts +2 -0
- package/lib/solution/BaseSales/index.js +14 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/UnifiedBookingSales/index.d.ts +2 -2
- package/lib/solution/UnifiedBookingSales/index.js +3 -3
- package/package.json +1 -1
|
@@ -5,18 +5,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.PaymentServerModule = void 0;
|
|
7
7
|
var _BaseModule = require("../../../modules/BaseModule");
|
|
8
|
+
var _lodashEs = require("lodash-es");
|
|
8
9
|
const WALLET_PASS_CODE = 'WALLET_PASS';
|
|
9
10
|
const WALLET_DEPENDENT_CODES = new Set(['PRODUCTVOUCHER', 'GIFTCARD', 'POINTCARD']);
|
|
10
11
|
const PAYMENT_METHODS_LOADED_EVENT = 'payment:onPaymentMethodsLoaded';
|
|
12
|
+
const PAYMENT_METHODS_CHANGED_EVENT = 'payment:onPaymentMethodsChanged';
|
|
13
|
+
const PAYMENT_METHOD_STORE_NAME = 'pay_method';
|
|
14
|
+
const CUSTOM_PAYMENT_MODULE = 'custom_payment';
|
|
15
|
+
const PAYMENT_METHOD_SYNC_DEBOUNCE_MS = 500;
|
|
16
|
+
const SNAPSHOT_ORDER_FIELD = '__payment_snapshot_order';
|
|
17
|
+
const SNAPSHOT_SHOP_ID_FIELD = '__payment_snapshot_shop_id';
|
|
11
18
|
class PaymentServerModule extends _BaseModule.BaseModule {
|
|
12
19
|
defaultName = 'payment';
|
|
13
20
|
defaultVersion = '1.0.0';
|
|
14
21
|
request;
|
|
15
22
|
app;
|
|
16
23
|
logger;
|
|
24
|
+
dbManager;
|
|
17
25
|
store;
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
paymentDataSource;
|
|
27
|
+
initialLoadInFlight = null;
|
|
28
|
+
refreshInFlight = null;
|
|
29
|
+
hasLoadedPayMethods = false;
|
|
30
|
+
hasEmittedLoaded = false;
|
|
31
|
+
syncTimer;
|
|
32
|
+
pendingMessageUuids = new Set();
|
|
33
|
+
queuedTrailingRefresh = false;
|
|
34
|
+
trailingMessageUuids = new Set();
|
|
20
35
|
constructor(name, version) {
|
|
21
36
|
super(name || 'payment', version);
|
|
22
37
|
}
|
|
@@ -31,78 +46,327 @@ class PaymentServerModule extends _BaseModule.BaseModule {
|
|
|
31
46
|
const appPlugin = core.getPlugin('app');
|
|
32
47
|
this.app = appPlugin?.getApp();
|
|
33
48
|
this.logger = this.app?.logger;
|
|
49
|
+
this.dbManager = this.app?.sqlite;
|
|
34
50
|
if (!this.request && !this.app?.request) {
|
|
35
51
|
throw new Error('PaymentServerModule 需要 request 插件或 app.request 支持');
|
|
36
52
|
}
|
|
53
|
+
this.initPaymentDataSource();
|
|
54
|
+
this.setupPaymentMethodSync();
|
|
37
55
|
this.logInfo('PaymentServerModule initialized successfully', {
|
|
38
|
-
hasAppRequest: !!this.app?.request
|
|
56
|
+
hasAppRequest: !!this.app?.request,
|
|
57
|
+
hasSQLite: !!this.dbManager,
|
|
58
|
+
hasPaymentDataSource: !!this.paymentDataSource
|
|
39
59
|
});
|
|
40
60
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// });
|
|
51
|
-
// return {
|
|
52
|
-
// code: 200,
|
|
53
|
-
// status: true,
|
|
54
|
-
// data: payMethods,
|
|
55
|
-
// };
|
|
56
|
-
// },
|
|
57
|
-
// },
|
|
58
|
-
// ];
|
|
59
|
-
// }
|
|
60
|
-
|
|
61
|
+
async preload() {
|
|
62
|
+
try {
|
|
63
|
+
await this.ensureInitialPayMethods('preload');
|
|
64
|
+
} catch (error) {
|
|
65
|
+
this.logError('preload 支付方式失败,保持空列表并允许后续读取重试', {
|
|
66
|
+
error: this.getErrorMessage(error)
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
61
70
|
async getPayMethodListAsync(options = {}) {
|
|
62
|
-
this.logInfo('Starting getPayMethodListAsync'
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
this.logInfo('Starting getPayMethodListAsync', {
|
|
72
|
+
hasLoadedPayMethods: this.hasLoadedPayMethods,
|
|
73
|
+
cachedCount: this.store.payMethods.length
|
|
74
|
+
});
|
|
75
|
+
if (!this.hasLoadedPayMethods) {
|
|
76
|
+
try {
|
|
77
|
+
await this.ensureInitialPayMethods('route');
|
|
78
|
+
} catch (error) {
|
|
79
|
+
this.logError('getPayMethodListAsync 初始化失败', {
|
|
80
|
+
error: this.getErrorMessage(error)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
} else if (!this.paymentDataSource) {
|
|
84
|
+
try {
|
|
85
|
+
await this.refreshPayMethodsSingleFlight({
|
|
86
|
+
trigger: 'compat.route',
|
|
87
|
+
emitChanged: false
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
this.logWarning('兼容模式远端刷新失败,保留当前运行态快照', {
|
|
91
|
+
error: this.getErrorMessage(error)
|
|
92
|
+
});
|
|
93
|
+
}
|
|
65
94
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
95
|
+
return this.resolvePayMethods(this.store.payMethods, options);
|
|
96
|
+
}
|
|
97
|
+
async ensureInitialPayMethods(trigger) {
|
|
98
|
+
if (this.hasLoadedPayMethods) return this.store.payMethods;
|
|
99
|
+
if (this.initialLoadInFlight) return this.initialLoadInFlight;
|
|
100
|
+
this.initialLoadInFlight = (async () => {
|
|
101
|
+
const localSnapshot = await this.loadPayMethodsFromSQLite();
|
|
102
|
+
if (localSnapshot.available) {
|
|
103
|
+
this.setPayMethodMirror(localSnapshot.methods);
|
|
104
|
+
this.logInfo('从 SQLite 加载支付方式兜底快照', {
|
|
105
|
+
trigger,
|
|
106
|
+
count: localSnapshot.methods.length,
|
|
107
|
+
shopScope: this.resolveCurrentShopScope(localSnapshot.methods)
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
await this.refreshPayMethodsSingleFlight({
|
|
112
|
+
trigger,
|
|
113
|
+
emitChanged: false
|
|
114
|
+
});
|
|
115
|
+
this.hasLoadedPayMethods = true;
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (!localSnapshot.available) throw error;
|
|
118
|
+
this.hasLoadedPayMethods = true;
|
|
119
|
+
this.logWarning('远端刷新失败,继续使用 SQLite 支付方式快照', {
|
|
120
|
+
trigger,
|
|
121
|
+
count: localSnapshot.methods.length,
|
|
122
|
+
error: this.getErrorMessage(error)
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (!this.hasEmittedLoaded) {
|
|
126
|
+
this.hasEmittedLoaded = true;
|
|
127
|
+
await this.core.effects.emit(PAYMENT_METHODS_LOADED_EVENT, this.store.payMethods);
|
|
128
|
+
}
|
|
129
|
+
return this.store.payMethods;
|
|
130
|
+
})().finally(() => {
|
|
131
|
+
this.initialLoadInFlight = null;
|
|
132
|
+
});
|
|
133
|
+
return this.initialLoadInFlight;
|
|
134
|
+
}
|
|
135
|
+
initPaymentDataSource() {
|
|
136
|
+
const PaymentDataSourceClass = this.core.serverOptions?.All_DATA_SOURCES?.PaymentDataSource;
|
|
137
|
+
if (!PaymentDataSourceClass) {
|
|
138
|
+
this.logWarning('PaymentDataSource 不可用,使用无本地持久化的兼容模式');
|
|
139
|
+
return;
|
|
69
140
|
}
|
|
70
|
-
this.
|
|
71
|
-
|
|
141
|
+
this.paymentDataSource = new PaymentDataSourceClass();
|
|
142
|
+
}
|
|
143
|
+
setupPaymentMethodSync() {
|
|
144
|
+
if (!this.paymentDataSource) return;
|
|
145
|
+
this.paymentDataSource.run({
|
|
146
|
+
pubsub: {
|
|
147
|
+
callback: res => {
|
|
148
|
+
const message = res?.data || res;
|
|
149
|
+
if (!message || message.module !== CUSTOM_PAYMENT_MODULE) return;
|
|
150
|
+
const messageUuid = String(message.message_uuid || '').trim();
|
|
151
|
+
if (messageUuid) this.pendingMessageUuids.add(messageUuid);
|
|
152
|
+
this.logInfo('收到 custom_payment Ably 消息,等待全量刷新', {
|
|
153
|
+
message_uuid: messageUuid || undefined,
|
|
154
|
+
action: message.action,
|
|
155
|
+
operation: message.operation
|
|
156
|
+
});
|
|
157
|
+
this.schedulePaymentMethodRefresh();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}).catch(error => {
|
|
161
|
+
this.logError('建立 custom_payment pubsub 订阅失败', {
|
|
162
|
+
error: this.getErrorMessage(error)
|
|
163
|
+
});
|
|
72
164
|
});
|
|
73
|
-
const payMethods = await this.payMethodListInFlight;
|
|
74
|
-
return this.resolvePayMethods(payMethods, options);
|
|
75
165
|
}
|
|
76
|
-
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
166
|
+
schedulePaymentMethodRefresh() {
|
|
167
|
+
if (this.syncTimer) clearTimeout(this.syncTimer);
|
|
168
|
+
this.syncTimer = setTimeout(() => {
|
|
169
|
+
this.syncTimer = undefined;
|
|
170
|
+
const messageUuids = [...this.pendingMessageUuids];
|
|
171
|
+
this.pendingMessageUuids.clear();
|
|
172
|
+
void this.refreshPayMethodsSingleFlight({
|
|
173
|
+
trigger: 'ably',
|
|
174
|
+
emitChanged: true,
|
|
175
|
+
messageUuids
|
|
176
|
+
}).catch(error => {
|
|
177
|
+
this.logError('custom_payment Ably 全量刷新失败,保留旧快照', {
|
|
178
|
+
message_uuids: messageUuids,
|
|
179
|
+
error: this.getErrorMessage(error)
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}, PAYMENT_METHOD_SYNC_DEBOUNCE_MS);
|
|
79
183
|
}
|
|
80
|
-
async
|
|
184
|
+
async refreshPayMethodsSingleFlight(context) {
|
|
185
|
+
if (this.refreshInFlight) {
|
|
186
|
+
if (context.trigger.startsWith('ably')) {
|
|
187
|
+
this.queuedTrailingRefresh = true;
|
|
188
|
+
context.messageUuids?.forEach(uuid => this.trailingMessageUuids.add(uuid));
|
|
189
|
+
this.logInfo('支付方式刷新进行中,已排队一次尾随刷新', {
|
|
190
|
+
trigger: context.trigger,
|
|
191
|
+
message_uuids: context.messageUuids || []
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return this.refreshInFlight;
|
|
195
|
+
}
|
|
196
|
+
const refreshTask = this.performRemoteRefresh(context);
|
|
197
|
+
this.refreshInFlight = refreshTask;
|
|
81
198
|
try {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
|
|
199
|
+
return await refreshTask;
|
|
200
|
+
} finally {
|
|
201
|
+
if (this.refreshInFlight === refreshTask) this.refreshInFlight = null;
|
|
202
|
+
if (this.queuedTrailingRefresh) {
|
|
203
|
+
this.queuedTrailingRefresh = false;
|
|
204
|
+
const messageUuids = [...this.trailingMessageUuids];
|
|
205
|
+
this.trailingMessageUuids.clear();
|
|
206
|
+
void this.refreshPayMethodsSingleFlight({
|
|
207
|
+
trigger: 'ably.trailing',
|
|
208
|
+
emitChanged: true,
|
|
209
|
+
messageUuids
|
|
210
|
+
}).catch(error => {
|
|
211
|
+
this.logError('custom_payment 尾随刷新失败,保留当前快照', {
|
|
212
|
+
message_uuids: messageUuids,
|
|
213
|
+
error: this.getErrorMessage(error)
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async performRemoteRefresh(context) {
|
|
220
|
+
const oldMethods = this.store.payMethods;
|
|
221
|
+
const payMethods = await this.fetchRemotePayMethods();
|
|
222
|
+
const persisted = await this.replacePayMethodsInSQLite(payMethods);
|
|
223
|
+
if (!persisted) {
|
|
224
|
+
this.logWarning('SQLite 不可用,支付方式仅用于当前运行时', {
|
|
225
|
+
trigger: context.trigger,
|
|
226
|
+
count: payMethods.length
|
|
87
227
|
});
|
|
88
|
-
return payMethods;
|
|
89
|
-
} catch (error) {
|
|
90
|
-
console.error('[PaymentServerModule] 获取支付方式列表失败', error);
|
|
91
|
-
this.logError('getPayMethodListAsync failed', error);
|
|
92
|
-
return [];
|
|
93
228
|
}
|
|
229
|
+
this.setPayMethodMirror(payMethods);
|
|
230
|
+
this.hasLoadedPayMethods = true;
|
|
231
|
+
const changed = !this.arePayMethodsEqual(oldMethods, payMethods);
|
|
232
|
+
if (context.emitChanged && changed) {
|
|
233
|
+
await this.core.effects.emit(PAYMENT_METHODS_CHANGED_EVENT, {
|
|
234
|
+
oldMethods,
|
|
235
|
+
newMethods: this.store.payMethods
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
this.logInfo('远端支付方式全量刷新成功', {
|
|
239
|
+
trigger: context.trigger,
|
|
240
|
+
message_uuids: context.messageUuids || [],
|
|
241
|
+
count: payMethods.length,
|
|
242
|
+
persisted,
|
|
243
|
+
changed
|
|
244
|
+
});
|
|
245
|
+
return this.store.payMethods;
|
|
94
246
|
}
|
|
95
247
|
async fetchRemotePayMethods() {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
248
|
+
const response = this.paymentDataSource ? await this.paymentDataSource.run({
|
|
249
|
+
http: {
|
|
250
|
+
url: '/shop/pay/custom-payment/all'
|
|
251
|
+
}
|
|
252
|
+
}) : await (this.app?.request || this.request).get('/shop/pay/custom-payment/all', undefined);
|
|
253
|
+
const payMethods = response?.data !== undefined ? response.data : response;
|
|
254
|
+
if (!Array.isArray(payMethods)) {
|
|
255
|
+
throw new Error('支付方式全量接口返回值不是数组');
|
|
256
|
+
}
|
|
257
|
+
if (payMethods.some(method => !method || method.id === undefined || method.id === null)) {
|
|
258
|
+
throw new Error('支付方式全量接口存在缺少 id 的记录');
|
|
259
|
+
}
|
|
260
|
+
return payMethods;
|
|
261
|
+
}
|
|
262
|
+
async loadPayMethodsFromSQLite() {
|
|
263
|
+
if (!this.dbManager) return {
|
|
264
|
+
available: false,
|
|
265
|
+
methods: []
|
|
266
|
+
};
|
|
267
|
+
try {
|
|
268
|
+
const rows = await this.dbManager.getAll(PAYMENT_METHOD_STORE_NAME);
|
|
269
|
+
if (!Array.isArray(rows) || rows.length === 0) {
|
|
270
|
+
return {
|
|
271
|
+
available: false,
|
|
272
|
+
methods: []
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
const currentShopScope = this.resolveCurrentShopScope();
|
|
276
|
+
if (!currentShopScope) {
|
|
277
|
+
this.logWarning('无法确认当前店铺,忽略 SQLite 支付方式快照');
|
|
278
|
+
return {
|
|
279
|
+
available: false,
|
|
280
|
+
methods: []
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
const scopedRows = rows.filter(row => String(row?.[SNAPSHOT_SHOP_ID_FIELD] || '') === currentShopScope);
|
|
284
|
+
if (scopedRows.length === 0) {
|
|
285
|
+
this.logWarning('忽略其他店铺的 SQLite 支付方式快照', {
|
|
286
|
+
currentShopScope,
|
|
287
|
+
storedShopScopes: [...new Set(rows.map(row => String(row?.[SNAPSHOT_SHOP_ID_FIELD] || '')).filter(Boolean))]
|
|
288
|
+
});
|
|
289
|
+
return {
|
|
290
|
+
available: false,
|
|
291
|
+
methods: []
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
const methods = scopedRows.slice().sort((left, right) => Number(left?.[SNAPSHOT_ORDER_FIELD] || 0) - Number(right?.[SNAPSHOT_ORDER_FIELD] || 0)).map(row => this.stripSnapshotFields(row));
|
|
295
|
+
return {
|
|
296
|
+
available: true,
|
|
297
|
+
methods
|
|
298
|
+
};
|
|
299
|
+
} catch (error) {
|
|
300
|
+
this.logWarning('从 SQLite 读取支付方式失败', {
|
|
301
|
+
error: this.getErrorMessage(error)
|
|
302
|
+
});
|
|
303
|
+
return {
|
|
304
|
+
available: false,
|
|
305
|
+
methods: []
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async replacePayMethodsInSQLite(payMethods) {
|
|
310
|
+
if (!this.dbManager) return false;
|
|
311
|
+
const previousRows = await this.dbManager.getAll(PAYMENT_METHOD_STORE_NAME);
|
|
312
|
+
const shopScope = this.resolveCurrentShopScope(payMethods);
|
|
313
|
+
const snapshotRows = payMethods.map((method, index) => ({
|
|
314
|
+
...method,
|
|
315
|
+
[SNAPSHOT_ORDER_FIELD]: index,
|
|
316
|
+
[SNAPSHOT_SHOP_ID_FIELD]: shopScope
|
|
317
|
+
}));
|
|
318
|
+
try {
|
|
319
|
+
await this.dbManager.clear(PAYMENT_METHOD_STORE_NAME);
|
|
320
|
+
if (snapshotRows.length > 0) {
|
|
321
|
+
await this.dbManager.bulkAdd(PAYMENT_METHOD_STORE_NAME, snapshotRows);
|
|
322
|
+
}
|
|
323
|
+
return true;
|
|
324
|
+
} catch (error) {
|
|
325
|
+
const writeError = this.getErrorMessage(error);
|
|
326
|
+
try {
|
|
327
|
+
await this.dbManager.clear(PAYMENT_METHOD_STORE_NAME);
|
|
328
|
+
if (Array.isArray(previousRows) && previousRows.length > 0) {
|
|
329
|
+
await this.dbManager.bulkAdd(PAYMENT_METHOD_STORE_NAME, previousRows);
|
|
330
|
+
}
|
|
331
|
+
} catch (rollbackError) {
|
|
332
|
+
this.logError('支付方式 SQLite 快照回滚失败', {
|
|
333
|
+
writeError,
|
|
334
|
+
rollbackError: this.getErrorMessage(rollbackError)
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
throw new Error(`支付方式 SQLite 全量替换失败: ${writeError}`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
resolveCurrentShopScope(payMethods = []) {
|
|
341
|
+
const readStorageObject = key => {
|
|
342
|
+
try {
|
|
343
|
+
const raw = this.app?.storage?.getStorage?.(key);
|
|
344
|
+
if (!raw) return {};
|
|
345
|
+
if (typeof raw === 'object') return raw;
|
|
346
|
+
const parsed = JSON.parse(raw);
|
|
347
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
348
|
+
} catch {
|
|
349
|
+
return {};
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
const selectedStore = readStorageObject('selectedStore');
|
|
353
|
+
const core = readStorageObject('core');
|
|
354
|
+
const scope = selectedStore.id ?? selectedStore.shop_id ?? core.id ?? core.shop_id ?? payMethods.find(method => method?.shop_id != null)?.shop_id;
|
|
355
|
+
return scope === undefined || scope === null ? '' : String(scope);
|
|
356
|
+
}
|
|
357
|
+
stripSnapshotFields(row) {
|
|
358
|
+
const {
|
|
359
|
+
[SNAPSHOT_ORDER_FIELD]: _snapshotOrder,
|
|
360
|
+
[SNAPSHOT_SHOP_ID_FIELD]: _snapshotShopId,
|
|
361
|
+
...method
|
|
362
|
+
} = row;
|
|
363
|
+
return method;
|
|
100
364
|
}
|
|
101
|
-
|
|
102
|
-
return
|
|
365
|
+
arePayMethodsEqual(left, right) {
|
|
366
|
+
return (0, _lodashEs.isEqual)(left, right);
|
|
103
367
|
}
|
|
104
368
|
resolvePayMethods(payMethods, options) {
|
|
105
|
-
if (!options.shouldFilter) return payMethods;
|
|
369
|
+
if (!options.shouldFilter) return [...payMethods];
|
|
106
370
|
return this.filterPayMethods(payMethods);
|
|
107
371
|
}
|
|
108
372
|
filterPayMethods(payMethods) {
|
|
@@ -121,48 +385,56 @@ class PaymentServerModule extends _BaseModule.BaseModule {
|
|
|
121
385
|
});
|
|
122
386
|
return availableMethods;
|
|
123
387
|
}
|
|
124
|
-
|
|
125
|
-
this.
|
|
126
|
-
|
|
388
|
+
setPayMethodMirror(payMethods) {
|
|
389
|
+
this.store.payMethods = payMethods.map(method => ({
|
|
390
|
+
...method
|
|
391
|
+
}));
|
|
392
|
+
}
|
|
393
|
+
getErrorMessage(error) {
|
|
394
|
+
return error instanceof Error ? error.message : String(error);
|
|
127
395
|
}
|
|
128
396
|
logInfo(title, metadata) {
|
|
129
397
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
});
|
|
136
|
-
}
|
|
398
|
+
this.logger?.addLog({
|
|
399
|
+
type: 'info',
|
|
400
|
+
title: `[PaymentServerModule] ${title}`,
|
|
401
|
+
metadata: metadata || {}
|
|
402
|
+
});
|
|
137
403
|
} catch {
|
|
138
404
|
// 日志记录失败不影响主流程
|
|
139
405
|
}
|
|
140
406
|
}
|
|
141
407
|
logWarning(title, metadata) {
|
|
142
408
|
try {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
}
|
|
409
|
+
this.logger?.addLog({
|
|
410
|
+
type: 'warning',
|
|
411
|
+
title: `[PaymentServerModule] ${title}`,
|
|
412
|
+
metadata: metadata || {}
|
|
413
|
+
});
|
|
150
414
|
} catch {
|
|
151
415
|
// 日志记录失败不影响主流程
|
|
152
416
|
}
|
|
153
417
|
}
|
|
154
418
|
logError(title, metadata) {
|
|
155
419
|
try {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
});
|
|
162
|
-
}
|
|
420
|
+
this.logger?.addLog({
|
|
421
|
+
type: 'error',
|
|
422
|
+
title: `[PaymentServerModule] ${title}`,
|
|
423
|
+
metadata: metadata || {}
|
|
424
|
+
});
|
|
163
425
|
} catch {
|
|
164
426
|
// 日志记录失败不影响主流程
|
|
165
427
|
}
|
|
166
428
|
}
|
|
429
|
+
destroy() {
|
|
430
|
+
if (this.syncTimer) clearTimeout(this.syncTimer);
|
|
431
|
+
this.syncTimer = undefined;
|
|
432
|
+
this.pendingMessageUuids.clear();
|
|
433
|
+
this.trailingMessageUuids.clear();
|
|
434
|
+
this.queuedTrailingRefresh = false;
|
|
435
|
+
this.paymentDataSource?.destroy?.();
|
|
436
|
+
this.paymentDataSource = undefined;
|
|
437
|
+
super.destroy();
|
|
438
|
+
}
|
|
167
439
|
}
|
|
168
440
|
exports.PaymentServerModule = PaymentServerModule;
|
|
@@ -72,6 +72,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
72
72
|
private walletAssetsRefreshSequence;
|
|
73
73
|
private salesDetailHydrateQueue;
|
|
74
74
|
private serverOrderChangeUnsubscribe;
|
|
75
|
+
private paymentMethodsChangedUnsubscribe;
|
|
75
76
|
private serverOrderChangeHydrateInFlight;
|
|
76
77
|
private queuedServerOrderChanges;
|
|
77
78
|
private serverOrderChangeSyncEnabled;
|
|
@@ -101,6 +102,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
101
102
|
private drainQueuedServerOrderChanges;
|
|
102
103
|
private syncCurrentSalesDetailFromServerOrderChange;
|
|
103
104
|
private registerServerOrderChangeSync;
|
|
105
|
+
private registerPaymentMethodsChangeSync;
|
|
104
106
|
private hydrateLatestLoadedSalesDetail;
|
|
105
107
|
private hydrateOrderPaymentNames;
|
|
106
108
|
get payment(): PaymentModule | undefined;
|
|
@@ -37,6 +37,7 @@ var _transformBaseProductToOrderProduct = require("./utils/transformBaseProductT
|
|
|
37
37
|
var _quotationPrice = require("./utils/quotationPrice");
|
|
38
38
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
39
|
const SERVER_ORDER_CHANGED_EVENT = 'order:onOrdersChanged';
|
|
40
|
+
const PAYMENT_METHODS_CHANGED_EVENT = 'payment:onPaymentMethodsChanged';
|
|
40
41
|
const OS_FULFILLMENT_REF_MODE_FIELD = '_os_fulfillment_ref_mode';
|
|
41
42
|
const OS_INVOICE_LAYOUT_CONFIG_FIELD = '_os_invoice_layout_config';
|
|
42
43
|
const OS_INVOICE_TEMPLATE_SETTINGS_FIELD = '_os_invoice_template_settings';
|
|
@@ -487,6 +488,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
487
488
|
walletAssetsRefreshSequence = 0;
|
|
488
489
|
salesDetailHydrateQueue = Promise.resolve();
|
|
489
490
|
serverOrderChangeUnsubscribe = null;
|
|
491
|
+
paymentMethodsChangedUnsubscribe = null;
|
|
490
492
|
serverOrderChangeHydrateInFlight = null;
|
|
491
493
|
queuedServerOrderChanges = [];
|
|
492
494
|
serverOrderChangeSyncEnabled = false;
|
|
@@ -630,6 +632,15 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
630
632
|
});
|
|
631
633
|
});
|
|
632
634
|
}
|
|
635
|
+
registerPaymentMethodsChangeSync() {
|
|
636
|
+
this.paymentMethodsChangedUnsubscribe?.();
|
|
637
|
+
const effects = this.core?.effects;
|
|
638
|
+
if (!effects || typeof effects.on !== 'function') return;
|
|
639
|
+
this.paymentMethodsChangedUnsubscribe = effects.on(PAYMENT_METHODS_CHANGED_EVENT, async payload => {
|
|
640
|
+
if (!Array.isArray(payload?.newMethods)) return;
|
|
641
|
+
await this.getPaymentMethodsAsync();
|
|
642
|
+
});
|
|
643
|
+
}
|
|
633
644
|
async hydrateLatestLoadedSalesDetail(record, loadSequence, options) {
|
|
634
645
|
let hydratedSales = null;
|
|
635
646
|
let skippedBeforeHydrate = false;
|
|
@@ -1429,12 +1440,15 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1429
1440
|
this.store.order.setEnableTempOrderPersist(this.otherParams.enableTempOrderPersist);
|
|
1430
1441
|
}
|
|
1431
1442
|
await this.getPaymentMethodsAsync();
|
|
1443
|
+
this.registerPaymentMethodsChangeSync();
|
|
1432
1444
|
this.registerServerOrderChangeSync();
|
|
1433
1445
|
this.core.effects.emit(`${this.name}:onInited`, {});
|
|
1434
1446
|
}
|
|
1435
1447
|
async destroy() {
|
|
1436
1448
|
this.serverOrderChangeUnsubscribe?.();
|
|
1437
1449
|
this.serverOrderChangeUnsubscribe = null;
|
|
1450
|
+
this.paymentMethodsChangedUnsubscribe?.();
|
|
1451
|
+
this.paymentMethodsChangedUnsubscribe = null;
|
|
1438
1452
|
Object.keys(this.store).forEach(key => {
|
|
1439
1453
|
if (this.reusedSharedSubModuleNames.has(key)) return;
|
|
1440
1454
|
const sub = this.store[key];
|
|
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
326
326
|
date: string;
|
|
327
327
|
status: string;
|
|
328
328
|
week: string;
|
|
329
|
-
weekNum: 0 | 2 |
|
|
329
|
+
weekNum: 0 | 2 | 3 | 1 | 5 | 6 | 4;
|
|
330
330
|
}[]>;
|
|
331
331
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
332
332
|
private getScheduleDataByIds;
|
|
@@ -127,8 +127,8 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
|
|
|
127
127
|
*/
|
|
128
128
|
clearSessionStorageOrderSnapshot(): void;
|
|
129
129
|
/**
|
|
130
|
-
* H5/Kiosk
|
|
131
|
-
*
|
|
130
|
+
* PC/H5/Kiosk 结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
|
|
131
|
+
* 显式传 checkoutSyncTaskEnabled: true 时仍可回退到本地同步模式。
|
|
132
132
|
*/
|
|
133
133
|
protected shouldUseCheckoutSyncTask(): boolean;
|
|
134
134
|
/** UnifiedBookingSales 的真实结账默认请求收据数据,供云端确认后再本地打印。 */
|
|
@@ -1581,14 +1581,14 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1581
1581
|
}
|
|
1582
1582
|
|
|
1583
1583
|
/**
|
|
1584
|
-
* H5/Kiosk
|
|
1585
|
-
*
|
|
1584
|
+
* PC/H5/Kiosk 结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
|
|
1585
|
+
* 显式传 checkoutSyncTaskEnabled: true 时仍可回退到本地同步模式。
|
|
1586
1586
|
*/
|
|
1587
1587
|
shouldUseCheckoutSyncTask() {
|
|
1588
1588
|
const configured = this.otherParams?.checkoutSyncTaskEnabled;
|
|
1589
1589
|
if (configured === true) return true;
|
|
1590
1590
|
const platform = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform);
|
|
1591
|
-
return platform
|
|
1591
|
+
return !(0, _platform.isCustomerUserPlatform)(platform) && platform !== 'kiosk';
|
|
1592
1592
|
}
|
|
1593
1593
|
|
|
1594
1594
|
/** UnifiedBookingSales 的真实结账默认请求收据数据,供云端确认后再本地打印。 */
|