@pisell/pisellos 2.2.326 → 2.2.328
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/dataVariant/evaluator.d.ts +2 -1
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +60 -15
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/OpenData/index.d.ts +8 -1
- package/dist/modules/OpenData/index.js +276 -95
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +857 -598
- package/dist/server/modules/order/index.d.ts +1 -0
- package/dist/server/modules/order/index.js +51 -51
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/Sales/index.d.ts +2 -5
- package/dist/solution/Sales/index.js +117 -143
- package/dist/solution/Sales/types.d.ts +6 -0
- package/dist/solution/Sales/types.js +2 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +2 -1
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +40 -6
- package/lib/modules/OpenData/index.d.ts +8 -1
- package/lib/modules/OpenData/index.js +123 -21
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/server/index.d.ts +3 -0
- package/lib/server/index.js +155 -18
- package/lib/server/modules/order/index.d.ts +1 -0
- package/lib/server/modules/order/index.js +4 -3
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/Sales/index.d.ts +2 -5
- package/lib/solution/Sales/index.js +32 -66
- package/lib/solution/Sales/types.d.ts +6 -0
- package/lib/solution/Sales/types.js +1 -0
- package/package.json +1 -1
|
@@ -63,6 +63,7 @@ Object.defineProperty(exports, "resolveInvoiceReceiptLocales", {
|
|
|
63
63
|
return _utils.resolveInvoiceReceiptLocales;
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
|
+
var _lodashEs = require("lodash-es");
|
|
66
67
|
var _BaseModule = require("../BaseModule");
|
|
67
68
|
var _utils = require("./utils");
|
|
68
69
|
var _types = require("./types");
|
|
@@ -120,6 +121,7 @@ function isLegacyInvoiceTemplate(value) {
|
|
|
120
121
|
const numericLike = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
121
122
|
return !numericLike.test(normalized);
|
|
122
123
|
}
|
|
124
|
+
const INVOICE_OPEN_DATA_CACHE_TTL = 5 * 60 * 1000;
|
|
123
125
|
class OpenDataModule extends _BaseModule.BaseModule {
|
|
124
126
|
defaultName = 'openData';
|
|
125
127
|
defaultVersion = '1.0.0';
|
|
@@ -133,6 +135,8 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
133
135
|
otherParams = {};
|
|
134
136
|
fetchRevision = 0;
|
|
135
137
|
invoiceTemplateCacheRevision = 0;
|
|
138
|
+
printInvoiceTemplates = new Map();
|
|
139
|
+
lastManualPrintKey;
|
|
136
140
|
invoiceTemplateDocumentCache = new Map();
|
|
137
141
|
invoiceTemplateDocumentInFlight = new Map();
|
|
138
142
|
constructor(name, version) {
|
|
@@ -182,13 +186,26 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
182
186
|
}
|
|
183
187
|
async fetchOpenData(params) {
|
|
184
188
|
const fetchRevision = ++this.fetchRevision;
|
|
189
|
+
const response = await this.requestOpenData(params);
|
|
190
|
+
if (response?.status === false) {
|
|
191
|
+
throw new Error(response?.message || '获取 OpenData 配置失败');
|
|
192
|
+
}
|
|
193
|
+
const data = response?.data || {};
|
|
194
|
+
const resolvedInvoiceTemplate = await this.resolveInvoiceTemplateSettings(data, params.target);
|
|
195
|
+
// clearCache() 或后续请求发生后,旧响应不得复活已失效的 target 配置。
|
|
196
|
+
if (fetchRevision === this.fetchRevision) {
|
|
197
|
+
this.store.data = data;
|
|
198
|
+
this.store.lastFetchedAt = Date.now();
|
|
199
|
+
this.commitInvoiceTemplateSettings(params.target, resolvedInvoiceTemplate);
|
|
200
|
+
}
|
|
201
|
+
return data;
|
|
202
|
+
}
|
|
203
|
+
requestOpenData(params, background = false) {
|
|
185
204
|
const getData = this.appPlugin?.getData?.();
|
|
186
205
|
const shopId = getData?.('shop_id');
|
|
187
|
-
if (!shopId) throw new Error('[OpenDataModule] 无法获取 shop_id');
|
|
188
206
|
const tenantId = getData?.('tenant_id');
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const response = await this.request.post(`/open/my-pisell/${shopId}/setting`, {
|
|
207
|
+
if (!shopId) throw new Error('[OpenDataModule] 无法获取 shop_id');
|
|
208
|
+
return this.request.post(`/open/my-pisell/${encodeURIComponent(String(shopId))}/setting`, {
|
|
192
209
|
scope: params.scope,
|
|
193
210
|
target: params.target,
|
|
194
211
|
section_code: params.section_code
|
|
@@ -196,20 +213,96 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
196
213
|
pisell2: true,
|
|
197
214
|
isPisell2: true,
|
|
198
215
|
prefix: false,
|
|
199
|
-
headers
|
|
216
|
+
headers: tenantId ? {
|
|
217
|
+
'Tenant-Id': String(tenantId)
|
|
218
|
+
} : {},
|
|
219
|
+
...(background ? {
|
|
220
|
+
customToast: () => {},
|
|
221
|
+
manualErrorHandling: true,
|
|
222
|
+
skipErrorHandler: true
|
|
223
|
+
} : {})
|
|
200
224
|
});
|
|
201
|
-
|
|
202
|
-
|
|
225
|
+
}
|
|
226
|
+
loadCloudInvoiceTemplate(target) {
|
|
227
|
+
return this.loadPrintInvoiceTemplate(target, 'cloud');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** 手动和云单打印共用已成功解析的模板及进行中的请求。每个订单仍单独派单。 */
|
|
231
|
+
async loadPrintInvoiceTemplate(target, mode) {
|
|
232
|
+
const skipDocument = mode === 'manual' && this.shouldSkipInvoiceTemplateDocument();
|
|
233
|
+
const key = this.buildInvoiceCacheKey(target, skipDocument);
|
|
234
|
+
const revision = this.invoiceTemplateCacheRevision;
|
|
235
|
+
const assertCurrent = () => {
|
|
236
|
+
if (revision !== this.invoiceTemplateCacheRevision || key !== this.buildInvoiceCacheKey(target, skipDocument)) {
|
|
237
|
+
throw new Error('Invoice 配置已失效');
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
// 手动切换打印入口时沿用原有行为,重新读取该入口的 Documents 选择。
|
|
241
|
+
const manualSwitch = mode === 'manual' && this.lastManualPrintKey !== undefined && this.lastManualPrintKey !== key;
|
|
242
|
+
if (mode === 'manual') this.lastManualPrintKey = key;
|
|
243
|
+
let entry = this.printInvoiceTemplates.get(key);
|
|
244
|
+
const refresh = entry?.expiresAt !== undefined && (Date.now() >= entry.expiresAt || manualSwitch || mode === 'cloud' && entry.manualFallback);
|
|
245
|
+
if (!entry || refresh) {
|
|
246
|
+
const next = {
|
|
247
|
+
manualFallback: false,
|
|
248
|
+
request: this.fetchPrintInvoiceTemplate(target, skipDocument, assertCurrent).then(result => {
|
|
249
|
+
assertCurrent();
|
|
250
|
+
next.expiresAt = Date.now() + INVOICE_OPEN_DATA_CACHE_TTL;
|
|
251
|
+
// 只有手动打印可复用文档读取失败后的 DEFAULT 回退。
|
|
252
|
+
if ('documentError' in result) {
|
|
253
|
+
if (mode === 'cloud') throw result.documentError;
|
|
254
|
+
next.manualFallback = true;
|
|
255
|
+
next.request = Promise.resolve({
|
|
256
|
+
settings: (0, _utils.getDefaultInvoiceTemplateSettings)()
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return result;
|
|
260
|
+
}).catch(error => {
|
|
261
|
+
if (this.printInvoiceTemplates.get(key) === next) this.printInvoiceTemplates.delete(key);
|
|
262
|
+
throw error;
|
|
263
|
+
})
|
|
264
|
+
};
|
|
265
|
+
this.printInvoiceTemplates.set(key, next);
|
|
266
|
+
entry = next;
|
|
203
267
|
}
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
268
|
+
const result = await entry.request;
|
|
269
|
+
assertCurrent();
|
|
270
|
+
if ('documentError' in result) throw result.documentError;
|
|
271
|
+
return (0, _lodashEs.cloneDeep)(result.settings);
|
|
272
|
+
}
|
|
273
|
+
async fetchPrintInvoiceTemplate(target, skipDocument, assertCurrent) {
|
|
274
|
+
const response = await this.requestOpenData({
|
|
275
|
+
scope: 'board',
|
|
276
|
+
target,
|
|
277
|
+
section_code: ['documents']
|
|
278
|
+
}, true);
|
|
279
|
+
assertCurrent();
|
|
280
|
+
if (response?.status !== true || response.code !== 200 || !isRecord(response.data)) {
|
|
281
|
+
throw new Error(response?.message || 'Cloud Invoice settings unavailable');
|
|
211
282
|
}
|
|
212
|
-
return
|
|
283
|
+
if (skipDocument) return {
|
|
284
|
+
settings: (0, _utils.getDefaultInvoiceTemplateSettings)()
|
|
285
|
+
};
|
|
286
|
+
const raw = response.data['documents.invoice_template'];
|
|
287
|
+
const documentId = resolveInvoiceDocumentId(raw);
|
|
288
|
+
if (documentId) {
|
|
289
|
+
try {
|
|
290
|
+
return {
|
|
291
|
+
settings: await this.fetchInvoiceTemplateDocument(documentId, true)
|
|
292
|
+
};
|
|
293
|
+
} catch (documentError) {
|
|
294
|
+
return {
|
|
295
|
+
documentError
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (raw == null || typeof raw === 'string' && !raw.trim()) return {
|
|
300
|
+
settings: (0, _utils.getDefaultInvoiceTemplateSettings)()
|
|
301
|
+
};
|
|
302
|
+
if (isLegacyInvoiceTemplate(raw)) return {
|
|
303
|
+
settings: (0, _utils.normalizeInvoiceTemplateSettings)(response.data)
|
|
304
|
+
};
|
|
305
|
+
throw new Error('Cloud Invoice template identifier is invalid');
|
|
213
306
|
}
|
|
214
307
|
getOpenData() {
|
|
215
308
|
return this.store.data;
|
|
@@ -225,7 +318,7 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
225
318
|
const documentId = resolveInvoiceDocumentId(this.store.data?.['documents.invoice_template']);
|
|
226
319
|
if (documentId) {
|
|
227
320
|
const target = this.store.invoiceTemplateTarget;
|
|
228
|
-
if (!target || this.store.invoiceTemplateCacheKey !== this.
|
|
321
|
+
if (!target || this.store.invoiceTemplateCacheKey !== this.buildInvoiceCacheKey(target, documentId)) {
|
|
229
322
|
return (0, _utils.getDefaultInvoiceTemplateSettings)();
|
|
230
323
|
}
|
|
231
324
|
}
|
|
@@ -281,7 +374,7 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
281
374
|
cacheKey: null
|
|
282
375
|
};
|
|
283
376
|
}
|
|
284
|
-
const cacheKey = this.
|
|
377
|
+
const cacheKey = this.buildInvoiceCacheKey(target, documentId);
|
|
285
378
|
if (this.store.invoiceTemplateTarget === target && this.store.invoiceTemplateDocumentId === documentId && this.store.invoiceTemplateCacheKey === cacheKey && isRecord(this.store.invoiceTemplateSettings)) {
|
|
286
379
|
return {
|
|
287
380
|
settings: (0, _utils.normalizeRawInvoiceTemplateSettings)(this.store.invoiceTemplateSettings),
|
|
@@ -322,18 +415,22 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
322
415
|
cacheKey
|
|
323
416
|
};
|
|
324
417
|
}
|
|
325
|
-
|
|
418
|
+
buildInvoiceCacheKey(target, variant) {
|
|
326
419
|
const getData = this.appPlugin?.getData?.();
|
|
327
|
-
return JSON.stringify([getData?.('tenant_id') ?? null, getData?.('shop_id') ?? null, target,
|
|
420
|
+
return JSON.stringify([getData?.('tenant_id') ?? null, getData?.('shop_id') ?? null, target, variant]);
|
|
328
421
|
}
|
|
329
|
-
async fetchInvoiceTemplateDocument(documentId) {
|
|
422
|
+
async fetchInvoiceTemplateDocument(documentId, strict = false) {
|
|
330
423
|
const response = await this.request.get(`/document:get?filterByTk=${encodeURIComponent(documentId)}`, {}, {
|
|
331
424
|
isNocobase: true,
|
|
332
425
|
prefix: false,
|
|
333
426
|
headers: {
|
|
334
427
|
'x-data-source': 'pisell2'
|
|
335
428
|
},
|
|
336
|
-
customToast: () => {}
|
|
429
|
+
customToast: () => {},
|
|
430
|
+
...(strict ? {
|
|
431
|
+
manualErrorHandling: true,
|
|
432
|
+
skipErrorHandler: true
|
|
433
|
+
} : {})
|
|
337
434
|
});
|
|
338
435
|
const document = response?.data;
|
|
339
436
|
if (!document || resolveInvoiceDocumentId(document.id) !== documentId) {
|
|
@@ -345,6 +442,9 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
345
442
|
if (!isRecord(document.data) || !isRecord(document.data.template_settings)) {
|
|
346
443
|
throw new Error(`Invoice Document ${documentId} 缺少 template_settings`);
|
|
347
444
|
}
|
|
445
|
+
if (strict && (typeof document.data.template_settings.template !== 'string' || !document.data.template_settings.template.trim())) {
|
|
446
|
+
throw new Error(`Invoice Document ${documentId} 缺少 template`);
|
|
447
|
+
}
|
|
348
448
|
return (0, _utils.normalizeRawInvoiceTemplateSettings)(document.data.template_settings);
|
|
349
449
|
}
|
|
350
450
|
logInvoiceTemplateDocumentFallback(error, target, documentId) {
|
|
@@ -362,6 +462,8 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
362
462
|
clearCache() {
|
|
363
463
|
this.fetchRevision += 1;
|
|
364
464
|
this.invoiceTemplateCacheRevision += 1;
|
|
465
|
+
this.printInvoiceTemplates.clear();
|
|
466
|
+
this.lastManualPrintKey = undefined;
|
|
365
467
|
this.invoiceTemplateDocumentCache.clear();
|
|
366
468
|
this.invoiceTemplateDocumentInFlight.clear();
|
|
367
469
|
this.store.data = null;
|
|
@@ -640,7 +640,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
640
640
|
generateIdempotencyToken(): string;
|
|
641
641
|
syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
|
|
642
642
|
createOrder(params: CommitOrderParams['query']): {
|
|
643
|
-
type: "
|
|
643
|
+
type: "appointment_booking" | "virtual";
|
|
644
644
|
platform: string;
|
|
645
645
|
sales_channel: string;
|
|
646
646
|
order_sales_channel: string;
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "duration" | "normal" | "session";
|
|
53
53
|
}
|
package/lib/server/index.d.ts
CHANGED
|
@@ -546,8 +546,11 @@ declare class Server {
|
|
|
546
546
|
private shouldLookupLocalPrintOrder;
|
|
547
547
|
private getLocalPrintOrderLookup;
|
|
548
548
|
private mergeLocalPrintOrderInput;
|
|
549
|
+
private loadCloudInvoiceOrder;
|
|
550
|
+
private handleCloudOrderInvoice;
|
|
549
551
|
private handleLocalPrintOrder;
|
|
550
552
|
private normalizeRequestedReceiptLocales;
|
|
553
|
+
private rebuildOrderReceipt;
|
|
551
554
|
private handleLocalOrderReceiptSnapshot;
|
|
552
555
|
private handleMachinecodeBatchMeta;
|
|
553
556
|
private resolveMachinecodeBatchMetadataLookup;
|
package/lib/server/index.js
CHANGED
|
@@ -1387,6 +1387,18 @@ class Server {
|
|
|
1387
1387
|
method: 'post',
|
|
1388
1388
|
path: '/shop/local/print-order',
|
|
1389
1389
|
handler: this.handleLocalPrintOrder.bind(this)
|
|
1390
|
+
}, {
|
|
1391
|
+
method: 'post',
|
|
1392
|
+
path: '/shop/local/cloud-order-invoice/lookup',
|
|
1393
|
+
handler: ({
|
|
1394
|
+
data
|
|
1395
|
+
}) => this.handleCloudOrderInvoice(data, false)
|
|
1396
|
+
}, {
|
|
1397
|
+
method: 'post',
|
|
1398
|
+
path: '/shop/local/cloud-order-invoice/submit',
|
|
1399
|
+
handler: ({
|
|
1400
|
+
data
|
|
1401
|
+
}) => this.handleCloudOrderInvoice(data, true)
|
|
1390
1402
|
}, {
|
|
1391
1403
|
method: 'post',
|
|
1392
1404
|
path: '/shop/local/order-receipt-snapshot',
|
|
@@ -4100,6 +4112,125 @@ class Server {
|
|
|
4100
4112
|
external_sale_number: localOrder.external_sale_number ?? definedInput.external_sale_number ?? definedInput.externalSaleNumber
|
|
4101
4113
|
};
|
|
4102
4114
|
}
|
|
4115
|
+
async loadCloudInvoiceOrder(orderId, shopId, assertCurrentShop) {
|
|
4116
|
+
if (!this.order) throw new Error('Cloud invoice order service is unavailable');
|
|
4117
|
+
const hasReceiptDetail = order => {
|
|
4118
|
+
// Use the same amount fields as the receipt builder, including historical
|
|
4119
|
+
// top-level amounts. Zero is a valid total; a missing total in a list row is not.
|
|
4120
|
+
const total = [order.summary?.expect_amount, order.expect_amount, order.summary?.total_amount, order.total_amount].find(value => value != null && value !== '');
|
|
4121
|
+
return typeof order.business_code === 'string' && !!order.business_code.trim() && (typeof total === 'number' || typeof total === 'string' && !!total.trim()) && Number.isFinite(Number(total)) && (Array.isArray(order.products) || Array.isArray(order.bookings));
|
|
4122
|
+
};
|
|
4123
|
+
const local = await this.order.getLocalOrderByLookup(orderId, {
|
|
4124
|
+
exactOrderId: true
|
|
4125
|
+
});
|
|
4126
|
+
assertCurrentShop();
|
|
4127
|
+
if (local && String(local.order_id) === orderId) {
|
|
4128
|
+
if (local.shop_id != null && String(local.shop_id) !== shopId) {
|
|
4129
|
+
throw new Error('Cloud invoice order belongs to another shop');
|
|
4130
|
+
}
|
|
4131
|
+
if (String(local.shop_id) === shopId && hasReceiptDetail(local)) return local;
|
|
4132
|
+
}
|
|
4133
|
+
|
|
4134
|
+
// The generic detail route also matches short receipt numbers. Validate the
|
|
4135
|
+
// backend identity and live shop BEFORE its result enters the shared store.
|
|
4136
|
+
const result = await this.fetchAndPersistSalesOrderByLookup(orderId, {
|
|
4137
|
+
with: ['all']
|
|
4138
|
+
}, 'cloudOrderInvoice', undefined, fresh => {
|
|
4139
|
+
assertCurrentShop();
|
|
4140
|
+
if (String(fresh.order_id) !== orderId || fresh.shop_id != null && String(fresh.shop_id) !== shopId || !hasReceiptDetail(fresh)) {
|
|
4141
|
+
throw new Error('Cloud invoice order identity or detail is invalid');
|
|
4142
|
+
}
|
|
4143
|
+
// Some older shop-authenticated detail responses omit shop_id.
|
|
4144
|
+
return fresh.shop_id == null ? {
|
|
4145
|
+
...fresh,
|
|
4146
|
+
shop_id: Number(shopId)
|
|
4147
|
+
} : fresh;
|
|
4148
|
+
});
|
|
4149
|
+
assertCurrentShop();
|
|
4150
|
+
const saved = result.order;
|
|
4151
|
+
if (!saved || String(saved.order_id) !== orderId || String(saved.shop_id) !== shopId || !hasReceiptDetail(saved)) {
|
|
4152
|
+
throw new Error(result.message || 'Cloud invoice order detail is unavailable');
|
|
4153
|
+
}
|
|
4154
|
+
return saved;
|
|
4155
|
+
}
|
|
4156
|
+
async handleCloudOrderInvoice(input, submit) {
|
|
4157
|
+
const orderId = typeof input?.order_id === 'string' ? input.order_id.trim() : Number.isSafeInteger(input?.order_id) ? String(input.order_id) : '';
|
|
4158
|
+
if (!/^[1-9]\d*$/.test(orderId)) {
|
|
4159
|
+
return {
|
|
4160
|
+
code: 400,
|
|
4161
|
+
status: false,
|
|
4162
|
+
message: 'Invalid cloud invoice order ID',
|
|
4163
|
+
data: null
|
|
4164
|
+
};
|
|
4165
|
+
}
|
|
4166
|
+
try {
|
|
4167
|
+
const shopId = String(this.getAppData('shop_id') ?? '');
|
|
4168
|
+
const tenantId = String(this.getAppData('tenant_id') ?? '');
|
|
4169
|
+
if (!/^[1-9]\d*$/.test(shopId) || !Number.isSafeInteger(Number(shopId))) {
|
|
4170
|
+
throw new Error('Cloud invoice shop is unavailable');
|
|
4171
|
+
}
|
|
4172
|
+
const assertCurrentShop = () => {
|
|
4173
|
+
if (String(this.getAppData('shop_id') ?? '') !== shopId || String(this.getAppData('tenant_id') ?? '') !== tenantId) {
|
|
4174
|
+
throw new Error('Cloud invoice shop context changed');
|
|
4175
|
+
}
|
|
4176
|
+
};
|
|
4177
|
+
const order = await this.loadCloudInvoiceOrder(orderId, shopId, assertCurrentShop);
|
|
4178
|
+
const businessCode = order.business_code.trim();
|
|
4179
|
+
if (!submit) return {
|
|
4180
|
+
code: 200,
|
|
4181
|
+
status: true,
|
|
4182
|
+
message: '',
|
|
4183
|
+
data: {
|
|
4184
|
+
business_code: businessCode
|
|
4185
|
+
}
|
|
4186
|
+
};
|
|
4187
|
+
if (input.business_code !== businessCode || typeof input.template_settings?.template !== 'string' || !input.template_settings.template.trim() || !Array.isArray(input.template_settings.modules)) {
|
|
4188
|
+
throw new Error('Cloud invoice template is missing or belongs to another business');
|
|
4189
|
+
}
|
|
4190
|
+
const settings = this.normalizePrintInvoiceTemplateSettings(input.template_settings);
|
|
4191
|
+
const receipt = await this.rebuildOrderReceipt(order, settings);
|
|
4192
|
+
const smallTicketData = receipt.payment_info?.small_ticket_data;
|
|
4193
|
+
if (!(0, _smallTicket.hasSmallTicketData)(smallTicketData)) throw new Error('Cloud invoice snapshot is unavailable');
|
|
4194
|
+
const deviceTask = this.getDeviceTaskPlugin();
|
|
4195
|
+
if (!deviceTask?.dispatch) throw new Error('Print task service is unavailable');
|
|
4196
|
+
const deviceId = await this.getShortNumberOrDeviceId();
|
|
4197
|
+
assertCurrentShop();
|
|
4198
|
+
await deviceTask.dispatch({
|
|
4199
|
+
action: 'print_all',
|
|
4200
|
+
device_id: deviceId,
|
|
4201
|
+
name: 'PRINT_V1',
|
|
4202
|
+
source: 'server',
|
|
4203
|
+
source_type: 'order',
|
|
4204
|
+
source_id: order.order_id,
|
|
4205
|
+
payload: {
|
|
4206
|
+
type: '0',
|
|
4207
|
+
template_settings: settings,
|
|
4208
|
+
data: {
|
|
4209
|
+
order_id: order.order_id,
|
|
4210
|
+
small_ticket_data: smallTicketData
|
|
4211
|
+
}
|
|
4212
|
+
}
|
|
4213
|
+
});
|
|
4214
|
+
return {
|
|
4215
|
+
code: 200,
|
|
4216
|
+
status: true,
|
|
4217
|
+
message: '',
|
|
4218
|
+
data: null
|
|
4219
|
+
};
|
|
4220
|
+
} catch (error) {
|
|
4221
|
+
const message = this.getUnknownErrorMessage(error);
|
|
4222
|
+
this.logWarning('Cloud invoice request failed', {
|
|
4223
|
+
orderId,
|
|
4224
|
+
message
|
|
4225
|
+
});
|
|
4226
|
+
return {
|
|
4227
|
+
code: 500,
|
|
4228
|
+
status: false,
|
|
4229
|
+
message,
|
|
4230
|
+
data: null
|
|
4231
|
+
};
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4103
4234
|
handleLocalPrintOrder = async ({
|
|
4104
4235
|
data
|
|
4105
4236
|
}) => {
|
|
@@ -4232,6 +4363,23 @@ class Server {
|
|
|
4232
4363
|
if (!Array.isArray(value)) return [];
|
|
4233
4364
|
return Array.from(new Set(value.filter(locale => typeof locale === 'string').map(locale => locale.trim()).filter(Boolean)));
|
|
4234
4365
|
}
|
|
4366
|
+
rebuildOrderReceipt(order, templateSettings, locales) {
|
|
4367
|
+
const paymentInfo = {
|
|
4368
|
+
...order.payment_info
|
|
4369
|
+
};
|
|
4370
|
+
delete paymentInfo.small_ticket_data;
|
|
4371
|
+
return this.withLocalSmallTicketData({
|
|
4372
|
+
...order,
|
|
4373
|
+
small_ticket_data_flag: 1,
|
|
4374
|
+
payment_info: paymentInfo
|
|
4375
|
+
}, {
|
|
4376
|
+
locales,
|
|
4377
|
+
invoiceTemplateSettings: templateSettings,
|
|
4378
|
+
applyTemplateVisibility: true,
|
|
4379
|
+
includeReceiptKeys: templateSettings !== undefined,
|
|
4380
|
+
refreshResourceReference: true
|
|
4381
|
+
});
|
|
4382
|
+
}
|
|
4235
4383
|
handleLocalOrderReceiptSnapshot = async ({
|
|
4236
4384
|
data
|
|
4237
4385
|
}) => {
|
|
@@ -4275,21 +4423,7 @@ class Server {
|
|
|
4275
4423
|
}
|
|
4276
4424
|
sourceOrder = remoteResult.order;
|
|
4277
4425
|
}
|
|
4278
|
-
const
|
|
4279
|
-
...(sourceOrder.payment_info || {})
|
|
4280
|
-
};
|
|
4281
|
-
delete paymentInfo.small_ticket_data;
|
|
4282
|
-
const rebuiltOrder = await this.withLocalSmallTicketData({
|
|
4283
|
-
...sourceOrder,
|
|
4284
|
-
small_ticket_data_flag: 1,
|
|
4285
|
-
payment_info: paymentInfo
|
|
4286
|
-
}, {
|
|
4287
|
-
locales: this.normalizeRequestedReceiptLocales(input.locales),
|
|
4288
|
-
invoiceTemplateSettings: input.template_settings === undefined ? undefined : this.normalizePrintInvoiceTemplateSettings(input.template_settings),
|
|
4289
|
-
applyTemplateVisibility: true,
|
|
4290
|
-
includeReceiptKeys: input.template_settings !== undefined,
|
|
4291
|
-
refreshResourceReference: true
|
|
4292
|
-
});
|
|
4426
|
+
const rebuiltOrder = await this.rebuildOrderReceipt(sourceOrder, input.template_settings === undefined ? undefined : this.normalizePrintInvoiceTemplateSettings(input.template_settings), this.normalizeRequestedReceiptLocales(input.locales));
|
|
4293
4427
|
const smallTicketData = rebuiltOrder.payment_info?.small_ticket_data;
|
|
4294
4428
|
if (!(0, _smallTicket.hasSmallTicketData)(smallTicketData)) {
|
|
4295
4429
|
return {
|
|
@@ -5241,7 +5375,7 @@ class Server {
|
|
|
5241
5375
|
const code = typeof value === 'number' ? value : Number(value);
|
|
5242
5376
|
return Number.isFinite(code) ? code : 500;
|
|
5243
5377
|
}
|
|
5244
|
-
async fetchAndPersistSalesOrderByLookup(lookup, data, title, paymentIdentityOrder) {
|
|
5378
|
+
async fetchAndPersistSalesOrderByLookup(lookup, data, title, paymentIdentityOrder, prepareExactOrderForPersist) {
|
|
5245
5379
|
if (!this.order?.getLocalOrderByLookup || !this.order?.upsertOrdersFromRemote) {
|
|
5246
5380
|
this.logError(`${title}: Order 模块未注册`);
|
|
5247
5381
|
return {
|
|
@@ -5294,7 +5428,7 @@ class Server {
|
|
|
5294
5428
|
order: null
|
|
5295
5429
|
};
|
|
5296
5430
|
}
|
|
5297
|
-
const localBeforeRefresh = this.order.getLocalOrderFromMemoryByLookup?.(lookup) || (this.shouldForceRemoteSalesDetail(data) ? await this.order.getLocalOrderByLookup(lookup) : null);
|
|
5431
|
+
const localBeforeRefresh = prepareExactOrderForPersist ? this.order.getOrderByOrderId?.(lookup) : this.order.getLocalOrderFromMemoryByLookup?.(lookup) || (this.shouldForceRemoteSalesDetail(data) ? await this.order.getLocalOrderByLookup(lookup) : null);
|
|
5298
5432
|
let orderToPersist = fresh;
|
|
5299
5433
|
if (paymentIdentityOrder) {
|
|
5300
5434
|
if (String(fresh.order_id) !== String(paymentIdentityOrder.order_id) || fresh.external_sale_number && paymentIdentityOrder.external_sale_number && fresh.external_sale_number !== paymentIdentityOrder.external_sale_number || !Array.isArray(fresh.payments)) {
|
|
@@ -5326,6 +5460,7 @@ class Server {
|
|
|
5326
5460
|
})
|
|
5327
5461
|
};
|
|
5328
5462
|
}
|
|
5463
|
+
if (prepareExactOrderForPersist) orderToPersist = prepareExactOrderForPersist(orderToPersist);
|
|
5329
5464
|
if ((0, _localEftposState.requiresLocalPaymentRefresh)(localBeforeRefresh)) {
|
|
5330
5465
|
if (String(fresh.order_id) !== String(localBeforeRefresh.order_id)) {
|
|
5331
5466
|
throw new Error('远端订单身份不匹配,请重新刷新');
|
|
@@ -5334,7 +5469,9 @@ class Server {
|
|
|
5334
5469
|
} else {
|
|
5335
5470
|
await this.order.upsertOrdersFromRemote([orderToPersist]);
|
|
5336
5471
|
}
|
|
5337
|
-
let savedOrder = await this.order.getLocalOrderByLookup(lookup
|
|
5472
|
+
let savedOrder = prepareExactOrderForPersist ? await this.order.getLocalOrderByLookup(lookup, {
|
|
5473
|
+
exactOrderId: true
|
|
5474
|
+
}) : await this.order.getLocalOrderByLookup(lookup);
|
|
5338
5475
|
if (!savedOrder && fresh.order_id !== undefined && fresh.order_id !== null && String(fresh.order_id) !== String(lookup)) {
|
|
5339
5476
|
savedOrder = await this.order.getLocalOrderByLookup(fresh.order_id);
|
|
5340
5477
|
}
|
|
@@ -109,6 +109,7 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
109
109
|
getLocalOrderForPaymentReadiness(lookup: OrderId): Promise<OrderData | null>;
|
|
110
110
|
getLocalOrderByLookup(lookup: OrderId, options?: {
|
|
111
111
|
operationId?: string;
|
|
112
|
+
exactOrderId?: boolean;
|
|
112
113
|
}): Promise<OrderData | null>;
|
|
113
114
|
getLocalPayment(params: {
|
|
114
115
|
saleId: OrderId;
|
|
@@ -678,6 +678,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
678
678
|
}
|
|
679
679
|
async getLocalOrderByLookup(lookup, options = {}) {
|
|
680
680
|
const key = this.getIdKey(lookup);
|
|
681
|
+
const matches = order => options.exactOrderId ? order.order_id != null && this.getIdKey(order.order_id) === key : this.isOrderLookupMatch(order, key);
|
|
681
682
|
const logContext = {
|
|
682
683
|
operation_id: options.operationId,
|
|
683
684
|
lookup: key,
|
|
@@ -687,7 +688,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
687
688
|
this.logInfo('getLocalOrderByLookup-localPayment-开始', logContext);
|
|
688
689
|
}
|
|
689
690
|
const memoryOrderById = this.store.map.get(key);
|
|
690
|
-
if (memoryOrderById) {
|
|
691
|
+
if (memoryOrderById && (!options.exactOrderId || matches(memoryOrderById))) {
|
|
691
692
|
if (options.operationId) {
|
|
692
693
|
this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', {
|
|
693
694
|
...logContext,
|
|
@@ -696,7 +697,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
696
697
|
}
|
|
697
698
|
return memoryOrderById;
|
|
698
699
|
}
|
|
699
|
-
const memoryOrder = this.store.list.find(
|
|
700
|
+
const memoryOrder = this.store.list.find(matches);
|
|
700
701
|
if (memoryOrder) {
|
|
701
702
|
if (options.operationId) {
|
|
702
703
|
this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', {
|
|
@@ -710,7 +711,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
710
711
|
this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
|
|
711
712
|
}
|
|
712
713
|
const orders = await this.loadOrdersFromSQLite();
|
|
713
|
-
const localOrder = orders.find(
|
|
714
|
+
const localOrder = orders.find(matches);
|
|
714
715
|
if (!localOrder) {
|
|
715
716
|
if (options.operationId) {
|
|
716
717
|
this.logWarning('getLocalOrderByLookup-localPayment-SQLite未命中', {
|
|
@@ -389,7 +389,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
389
389
|
};
|
|
390
390
|
setOtherData(key: string, value: any): void;
|
|
391
391
|
getOtherData(key: string): any;
|
|
392
|
-
getProductTypeById(id: number): Promise<"
|
|
392
|
+
getProductTypeById(id: number): Promise<"duration" | "normal" | "session">;
|
|
393
393
|
/**
|
|
394
394
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
395
395
|
*
|
|
@@ -2,7 +2,7 @@ import dayjs from 'dayjs';
|
|
|
2
2
|
import { Module, ModuleOptions, PisellCore } from '../../types';
|
|
3
3
|
import { BaseModule } from '../../modules/BaseModule';
|
|
4
4
|
import type { RequestPlugin } from '../../plugins/request';
|
|
5
|
-
import { SalesState, SalesModuleAPI, Reservation, SalesResourceBookingItem, SalesResourceBookingItemWithGroups, SalesTimelineHighlights, ChangeBookingStatusParams, GetResourceBookingItemParams, SalesPrintLocalOrderReceiptOptions } from './types';
|
|
5
|
+
import { SalesState, SalesModuleAPI, Reservation, SalesResourceBookingItem, SalesResourceBookingItemWithGroups, SalesTimelineHighlights, ChangeBookingStatusParams, GetResourceBookingItemParams, SalesPrintLocalOrderReceiptOptions, CloudOrderInvoiceRequest } from './types';
|
|
6
6
|
import type { BookingData } from '../../server/modules/order/types';
|
|
7
7
|
export * from './types';
|
|
8
8
|
/**
|
|
@@ -27,9 +27,6 @@ export declare class SalesImpl extends BaseModule implements Module, SalesModule
|
|
|
27
27
|
protected request: RequestPlugin;
|
|
28
28
|
private logger;
|
|
29
29
|
private invoiceOpenDataModule;
|
|
30
|
-
private invoiceOpenDataTarget;
|
|
31
|
-
private invoiceOpenDataInFlight;
|
|
32
|
-
private invoiceOpenDataInFlightTarget;
|
|
33
30
|
constructor(name?: string, version?: string);
|
|
34
31
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
35
32
|
/** 获取当前 store 快照 */
|
|
@@ -51,10 +48,10 @@ export declare class SalesImpl extends BaseModule implements Module, SalesModule
|
|
|
51
48
|
* Legacy Sales 的系统上下文没有可打印的 system target,因此统一回退 pos。
|
|
52
49
|
*/
|
|
53
50
|
private getInvoiceSalesChannel;
|
|
54
|
-
private loadInvoiceOpenData;
|
|
55
51
|
private logInvoiceOpenDataFallback;
|
|
56
52
|
private resolveInvoiceConfigs;
|
|
57
53
|
printLocalOrderReceipt<T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions): Promise<T>;
|
|
54
|
+
printCloudOrderInvoice(input: CloudOrderInvoiceRequest): Promise<void>;
|
|
58
55
|
/** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
|
|
59
56
|
clearOpenDataCache(): void;
|
|
60
57
|
destroy(): Promise<void>;
|