@pisell/pisellos 0.10.95 → 0.10.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/OpenData/index.d.ts +13 -0
- package/dist/modules/OpenData/index.js +243 -93
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +1036 -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 +2 -2
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +16 -16
- package/dist/solution/Sales/index.d.ts +2 -1
- package/dist/solution/Sales/index.js +154 -48
- package/dist/solution/Sales/types.d.ts +12 -0
- package/dist/solution/Sales/types.js +2 -0
- package/lib/modules/OpenData/index.d.ts +13 -0
- package/lib/modules/OpenData/index.js +97 -18
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/server/index.d.ts +7 -0
- package/lib/server/index.js +240 -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 +2 -2
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +16 -16
- package/lib/solution/Sales/index.d.ts +2 -1
- package/lib/solution/Sales/index.js +53 -0
- package/lib/solution/Sales/types.d.ts +12 -0
- package/lib/solution/Sales/types.js +1 -0
- package/package.json +1 -1
package/lib/server/index.js
CHANGED
|
@@ -126,6 +126,7 @@ class Server {
|
|
|
126
126
|
localPaymentUpdateQueues = new Map();
|
|
127
127
|
paymentIdentityRefreshes = new Map();
|
|
128
128
|
receiptFulfillmentConfigInFlight = new Map();
|
|
129
|
+
cloudInvoiceSubmissions = new Map();
|
|
129
130
|
floorPlanQuerySubscribers = new Map();
|
|
130
131
|
|
|
131
132
|
// 模块注册表 - 定义所有可用的模块配置
|
|
@@ -1387,6 +1388,18 @@ class Server {
|
|
|
1387
1388
|
method: 'post',
|
|
1388
1389
|
path: '/shop/local/print-order',
|
|
1389
1390
|
handler: this.handleLocalPrintOrder.bind(this)
|
|
1391
|
+
}, {
|
|
1392
|
+
method: 'post',
|
|
1393
|
+
path: '/shop/local/cloud-order-invoice/lookup',
|
|
1394
|
+
handler: ({
|
|
1395
|
+
data
|
|
1396
|
+
}) => this.handleCloudOrderInvoice(data, false)
|
|
1397
|
+
}, {
|
|
1398
|
+
method: 'post',
|
|
1399
|
+
path: '/shop/local/cloud-order-invoice/submit',
|
|
1400
|
+
handler: ({
|
|
1401
|
+
data
|
|
1402
|
+
}) => this.handleCloudOrderInvoice(data, true)
|
|
1390
1403
|
}, {
|
|
1391
1404
|
method: 'post',
|
|
1392
1405
|
path: '/shop/local/order-receipt-snapshot',
|
|
@@ -4133,6 +4146,209 @@ class Server {
|
|
|
4133
4146
|
external_sale_number: localOrder.external_sale_number ?? definedInput.external_sale_number ?? definedInput.externalSaleNumber
|
|
4134
4147
|
};
|
|
4135
4148
|
}
|
|
4149
|
+
async getCloudInvoiceDevice(shopId) {
|
|
4150
|
+
const readDevice = this.getAppData('async_iot_device_info');
|
|
4151
|
+
const iot = await readDevice?.();
|
|
4152
|
+
if (iot?.shop_id != null && String(iot.shop_id) !== shopId) {
|
|
4153
|
+
throw new Error('Cloud invoice device belongs to another shop');
|
|
4154
|
+
}
|
|
4155
|
+
const iotId = String(iot?.id || '').trim();
|
|
4156
|
+
const fullNumber = String(iot?.number || !iotId && this.getAppData('device_id') || '').trim();
|
|
4157
|
+
if (fullNumber && fullNumber !== '0') {
|
|
4158
|
+
return {
|
|
4159
|
+
id: fullNumber,
|
|
4160
|
+
target: iot?.short_number || fullNumber.slice(-2)
|
|
4161
|
+
};
|
|
4162
|
+
}
|
|
4163
|
+
if (iotId && iotId !== '0') return {
|
|
4164
|
+
id: 'iot-id:' + iotId,
|
|
4165
|
+
target: iot?.short_number || iotId
|
|
4166
|
+
};
|
|
4167
|
+
throw new Error('Cloud invoice device is unavailable');
|
|
4168
|
+
}
|
|
4169
|
+
assertCloudInvoiceContext(context) {
|
|
4170
|
+
if (String(this.getAppData('shop_id') ?? '') !== context.shopId || String(this.getAppData('tenant_id') ?? '') !== context.tenantId) {
|
|
4171
|
+
throw new Error('Cloud invoice shop context changed');
|
|
4172
|
+
}
|
|
4173
|
+
}
|
|
4174
|
+
async loadCloudInvoiceOrder(context) {
|
|
4175
|
+
if (!this.order) throw new Error('Cloud invoice order service is unavailable');
|
|
4176
|
+
const {
|
|
4177
|
+
orderId,
|
|
4178
|
+
shopId
|
|
4179
|
+
} = context;
|
|
4180
|
+
const hasReceiptDetail = order => {
|
|
4181
|
+
// Use the same amount fields as the receipt builder, including historical
|
|
4182
|
+
// top-level amounts. Zero is a valid total; a missing total in a list row is not.
|
|
4183
|
+
const total = [order.summary?.expect_amount, order.expect_amount, order.summary?.total_amount, order.total_amount].find(value => value != null && value !== '');
|
|
4184
|
+
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));
|
|
4185
|
+
};
|
|
4186
|
+
const local = await this.order.getLocalOrderByLookup(orderId, {
|
|
4187
|
+
exactOrderId: true
|
|
4188
|
+
});
|
|
4189
|
+
this.assertCloudInvoiceContext(context);
|
|
4190
|
+
if (local && String(local.order_id) === orderId) {
|
|
4191
|
+
if (local.shop_id != null && String(local.shop_id) !== shopId) {
|
|
4192
|
+
throw new Error('Cloud invoice order belongs to another shop');
|
|
4193
|
+
}
|
|
4194
|
+
if (String(local.shop_id) === shopId && hasReceiptDetail(local)) return local;
|
|
4195
|
+
}
|
|
4196
|
+
|
|
4197
|
+
// The generic detail route also matches short receipt numbers. Validate the
|
|
4198
|
+
// backend identity and live shop BEFORE its result enters the shared store.
|
|
4199
|
+
const result = await this.fetchAndPersistSalesOrderByLookup(orderId, {
|
|
4200
|
+
with: ['all']
|
|
4201
|
+
}, 'cloudOrderInvoice', undefined, fresh => {
|
|
4202
|
+
this.assertCloudInvoiceContext(context);
|
|
4203
|
+
if (String(fresh.order_id) !== orderId || fresh.shop_id != null && String(fresh.shop_id) !== shopId || !hasReceiptDetail(fresh)) {
|
|
4204
|
+
throw new Error('Cloud invoice order identity or detail is invalid');
|
|
4205
|
+
}
|
|
4206
|
+
// Some older shop-authenticated detail responses omit shop_id.
|
|
4207
|
+
return fresh.shop_id == null ? {
|
|
4208
|
+
...fresh,
|
|
4209
|
+
shop_id: Number(shopId)
|
|
4210
|
+
} : fresh;
|
|
4211
|
+
});
|
|
4212
|
+
this.assertCloudInvoiceContext(context);
|
|
4213
|
+
const saved = result.order;
|
|
4214
|
+
if (!saved || String(saved.order_id) !== orderId || String(saved.shop_id) !== shopId || !hasReceiptDetail(saved)) {
|
|
4215
|
+
throw new Error(result.message || 'Cloud invoice order detail is unavailable');
|
|
4216
|
+
}
|
|
4217
|
+
return saved;
|
|
4218
|
+
}
|
|
4219
|
+
async resolveCloudOrderInvoice(context, input, submit) {
|
|
4220
|
+
const deviceTask = this.getDeviceTaskPlugin();
|
|
4221
|
+
if (!deviceTask?.findByIdempotencyKey || !deviceTask.dispatch) {
|
|
4222
|
+
throw new Error('Cloud invoice task service is unavailable');
|
|
4223
|
+
}
|
|
4224
|
+
const prior = await deviceTask.findByIdempotencyKey(context.taskKey);
|
|
4225
|
+
this.assertCloudInvoiceContext(context);
|
|
4226
|
+
if (prior) {
|
|
4227
|
+
if (!prior.uuid || String(prior.payload?.data?.order_id) !== context.orderId || prior.payload?.channel !== context.channel) {
|
|
4228
|
+
throw new Error('Cloud invoice message UUID conflicts with another task');
|
|
4229
|
+
}
|
|
4230
|
+
// Acceptance transfers ownership to DeviceTask, including its retry lifecycle.
|
|
4231
|
+
return {
|
|
4232
|
+
task_uuid: prior.uuid
|
|
4233
|
+
};
|
|
4234
|
+
}
|
|
4235
|
+
const order = await this.loadCloudInvoiceOrder(context);
|
|
4236
|
+
const businessCode = order.business_code.trim();
|
|
4237
|
+
if (!submit) return {
|
|
4238
|
+
business_code: businessCode,
|
|
4239
|
+
device_id: context.deviceId
|
|
4240
|
+
};
|
|
4241
|
+
if (input.business_code !== businessCode || typeof input.template_settings?.template !== 'string' || !input.template_settings.template.trim() || !Array.isArray(input.template_settings.modules)) {
|
|
4242
|
+
throw new Error('Cloud invoice template is missing or belongs to another business');
|
|
4243
|
+
}
|
|
4244
|
+
const settings = this.normalizePrintInvoiceTemplateSettings(input.template_settings);
|
|
4245
|
+
const receipt = await this.rebuildOrderReceipt(order, settings);
|
|
4246
|
+
const smallTicketData = receipt.payment_info?.small_ticket_data;
|
|
4247
|
+
if (!(0, _smallTicket.hasSmallTicketData)(smallTicketData)) throw new Error('Cloud invoice snapshot is unavailable');
|
|
4248
|
+
const device = await this.getCloudInvoiceDevice(context.shopId);
|
|
4249
|
+
if (device.id !== context.deviceId) throw new Error('Cloud invoice device changed');
|
|
4250
|
+
this.assertCloudInvoiceContext(context);
|
|
4251
|
+
const task = await deviceTask.dispatch({
|
|
4252
|
+
action: 'print_all',
|
|
4253
|
+
device_id: device.target,
|
|
4254
|
+
name: 'PRINT_V1',
|
|
4255
|
+
source: 'server',
|
|
4256
|
+
source_type: 'cloud_order_invoice',
|
|
4257
|
+
source_id: order.order_id,
|
|
4258
|
+
durability: 'durable',
|
|
4259
|
+
idempotency_key: context.taskKey,
|
|
4260
|
+
payload: {
|
|
4261
|
+
type: '0',
|
|
4262
|
+
shop_id: context.shopId,
|
|
4263
|
+
device_id: context.deviceId,
|
|
4264
|
+
message_uuid: context.messageUuid,
|
|
4265
|
+
channel: context.channel,
|
|
4266
|
+
template_settings: settings,
|
|
4267
|
+
data: {
|
|
4268
|
+
order_id: order.order_id,
|
|
4269
|
+
small_ticket_data: smallTicketData
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
});
|
|
4273
|
+
if (!task?.uuid) throw new Error('Cloud invoice task was not accepted');
|
|
4274
|
+
return {
|
|
4275
|
+
task_uuid: task.uuid
|
|
4276
|
+
};
|
|
4277
|
+
}
|
|
4278
|
+
async handleCloudOrderInvoice(input, submit) {
|
|
4279
|
+
const orderId = String(input?.order_id ?? '').trim();
|
|
4280
|
+
const shopId = String(input?.shop_id ?? '').trim();
|
|
4281
|
+
const messageUuid = typeof input?.message_uuid === 'string' ? input.message_uuid.trim() : '';
|
|
4282
|
+
const channel = typeof input?.channel === 'string' ? input.channel.trim() : '';
|
|
4283
|
+
if (!/^[1-9]\d*$/.test(orderId) || !/^[1-9]\d*$/.test(shopId) || !Number.isSafeInteger(Number(shopId)) || typeof input.order_id === 'number' && !Number.isSafeInteger(input.order_id) || !messageUuid || !channel) {
|
|
4284
|
+
return {
|
|
4285
|
+
code: 400,
|
|
4286
|
+
status: false,
|
|
4287
|
+
message: 'Invalid cloud invoice command',
|
|
4288
|
+
data: null
|
|
4289
|
+
};
|
|
4290
|
+
}
|
|
4291
|
+
try {
|
|
4292
|
+
const tenantId = String(this.getAppData('tenant_id') ?? '');
|
|
4293
|
+
const {
|
|
4294
|
+
id: deviceId
|
|
4295
|
+
} = await this.getCloudInvoiceDevice(shopId);
|
|
4296
|
+
if (submit && input.device_id !== deviceId) throw new Error('Cloud invoice device changed');
|
|
4297
|
+
const taskKey = 'cloud_order_invoice:' + JSON.stringify([shopId, deviceId, messageUuid]);
|
|
4298
|
+
const context = {
|
|
4299
|
+
taskKey,
|
|
4300
|
+
shopId,
|
|
4301
|
+
tenantId,
|
|
4302
|
+
deviceId,
|
|
4303
|
+
orderId,
|
|
4304
|
+
messageUuid,
|
|
4305
|
+
channel
|
|
4306
|
+
};
|
|
4307
|
+
this.assertCloudInvoiceContext(context);
|
|
4308
|
+
let result;
|
|
4309
|
+
const pending = this.cloudInvoiceSubmissions.get(taskKey);
|
|
4310
|
+
if (pending) {
|
|
4311
|
+
if (pending.context.orderId !== orderId || pending.context.channel !== channel || pending.context.tenantId !== tenantId) {
|
|
4312
|
+
throw new Error('Cloud invoice message UUID conflicts with an in-flight order');
|
|
4313
|
+
}
|
|
4314
|
+
result = await pending.result;
|
|
4315
|
+
} else if (submit) {
|
|
4316
|
+
const submission = this.resolveCloudOrderInvoice(context, input, true);
|
|
4317
|
+
this.cloudInvoiceSubmissions.set(taskKey, {
|
|
4318
|
+
context,
|
|
4319
|
+
result: submission
|
|
4320
|
+
});
|
|
4321
|
+
try {
|
|
4322
|
+
result = await submission;
|
|
4323
|
+
} finally {
|
|
4324
|
+
this.cloudInvoiceSubmissions.delete(taskKey);
|
|
4325
|
+
}
|
|
4326
|
+
} else {
|
|
4327
|
+
result = await this.resolveCloudOrderInvoice(context, input, false);
|
|
4328
|
+
}
|
|
4329
|
+
return {
|
|
4330
|
+
code: 200,
|
|
4331
|
+
status: true,
|
|
4332
|
+
message: '',
|
|
4333
|
+
data: result
|
|
4334
|
+
};
|
|
4335
|
+
} catch (error) {
|
|
4336
|
+
const message = this.getUnknownErrorMessage(error);
|
|
4337
|
+
this.logWarning('Cloud invoice request failed', {
|
|
4338
|
+
shopId,
|
|
4339
|
+
orderId,
|
|
4340
|
+
messageUuid,
|
|
4341
|
+
channel,
|
|
4342
|
+
message
|
|
4343
|
+
});
|
|
4344
|
+
return {
|
|
4345
|
+
code: 500,
|
|
4346
|
+
status: false,
|
|
4347
|
+
message,
|
|
4348
|
+
data: null
|
|
4349
|
+
};
|
|
4350
|
+
}
|
|
4351
|
+
}
|
|
4136
4352
|
handleLocalPrintOrder = async ({
|
|
4137
4353
|
data
|
|
4138
4354
|
}) => {
|
|
@@ -4265,6 +4481,23 @@ class Server {
|
|
|
4265
4481
|
if (!Array.isArray(value)) return [];
|
|
4266
4482
|
return Array.from(new Set(value.filter(locale => typeof locale === 'string').map(locale => locale.trim()).filter(Boolean)));
|
|
4267
4483
|
}
|
|
4484
|
+
rebuildOrderReceipt(order, templateSettings, locales) {
|
|
4485
|
+
const paymentInfo = {
|
|
4486
|
+
...order.payment_info
|
|
4487
|
+
};
|
|
4488
|
+
delete paymentInfo.small_ticket_data;
|
|
4489
|
+
return this.withLocalSmallTicketData({
|
|
4490
|
+
...order,
|
|
4491
|
+
small_ticket_data_flag: 1,
|
|
4492
|
+
payment_info: paymentInfo
|
|
4493
|
+
}, {
|
|
4494
|
+
locales,
|
|
4495
|
+
invoiceTemplateSettings: templateSettings,
|
|
4496
|
+
applyTemplateVisibility: true,
|
|
4497
|
+
includeReceiptKeys: templateSettings !== undefined,
|
|
4498
|
+
refreshResourceReference: true
|
|
4499
|
+
});
|
|
4500
|
+
}
|
|
4268
4501
|
handleLocalOrderReceiptSnapshot = async ({
|
|
4269
4502
|
data
|
|
4270
4503
|
}) => {
|
|
@@ -4308,21 +4541,7 @@ class Server {
|
|
|
4308
4541
|
}
|
|
4309
4542
|
sourceOrder = remoteResult.order;
|
|
4310
4543
|
}
|
|
4311
|
-
const
|
|
4312
|
-
...(sourceOrder.payment_info || {})
|
|
4313
|
-
};
|
|
4314
|
-
delete paymentInfo.small_ticket_data;
|
|
4315
|
-
const rebuiltOrder = await this.withLocalSmallTicketData({
|
|
4316
|
-
...sourceOrder,
|
|
4317
|
-
small_ticket_data_flag: 1,
|
|
4318
|
-
payment_info: paymentInfo
|
|
4319
|
-
}, {
|
|
4320
|
-
locales: this.normalizeRequestedReceiptLocales(input.locales),
|
|
4321
|
-
invoiceTemplateSettings: input.template_settings === undefined ? undefined : this.normalizePrintInvoiceTemplateSettings(input.template_settings),
|
|
4322
|
-
applyTemplateVisibility: true,
|
|
4323
|
-
includeReceiptKeys: input.template_settings !== undefined,
|
|
4324
|
-
refreshResourceReference: true
|
|
4325
|
-
});
|
|
4544
|
+
const rebuiltOrder = await this.rebuildOrderReceipt(sourceOrder, input.template_settings === undefined ? undefined : this.normalizePrintInvoiceTemplateSettings(input.template_settings), this.normalizeRequestedReceiptLocales(input.locales));
|
|
4326
4545
|
const smallTicketData = rebuiltOrder.payment_info?.small_ticket_data;
|
|
4327
4546
|
if (!(0, _smallTicket.hasSmallTicketData)(smallTicketData)) {
|
|
4328
4547
|
return {
|
|
@@ -5274,7 +5493,7 @@ class Server {
|
|
|
5274
5493
|
const code = typeof value === 'number' ? value : Number(value);
|
|
5275
5494
|
return Number.isFinite(code) ? code : 500;
|
|
5276
5495
|
}
|
|
5277
|
-
async fetchAndPersistSalesOrderByLookup(lookup, data, title, paymentIdentityOrder) {
|
|
5496
|
+
async fetchAndPersistSalesOrderByLookup(lookup, data, title, paymentIdentityOrder, prepareExactOrderForPersist) {
|
|
5278
5497
|
if (!this.order?.getLocalOrderByLookup || !this.order?.upsertOrdersFromRemote) {
|
|
5279
5498
|
this.logError(`${title}: Order 模块未注册`);
|
|
5280
5499
|
return {
|
|
@@ -5327,7 +5546,7 @@ class Server {
|
|
|
5327
5546
|
order: null
|
|
5328
5547
|
};
|
|
5329
5548
|
}
|
|
5330
|
-
const localBeforeRefresh = this.order.getLocalOrderFromMemoryByLookup?.(lookup) || (this.shouldForceRemoteSalesDetail(data) ? await this.order.getLocalOrderByLookup(lookup) : null);
|
|
5549
|
+
const localBeforeRefresh = prepareExactOrderForPersist ? this.order.getOrderByOrderId?.(lookup) : this.order.getLocalOrderFromMemoryByLookup?.(lookup) || (this.shouldForceRemoteSalesDetail(data) ? await this.order.getLocalOrderByLookup(lookup) : null);
|
|
5331
5550
|
let orderToPersist = fresh;
|
|
5332
5551
|
if (paymentIdentityOrder) {
|
|
5333
5552
|
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)) {
|
|
@@ -5359,6 +5578,7 @@ class Server {
|
|
|
5359
5578
|
})
|
|
5360
5579
|
};
|
|
5361
5580
|
}
|
|
5581
|
+
if (prepareExactOrderForPersist) orderToPersist = prepareExactOrderForPersist(orderToPersist);
|
|
5362
5582
|
if ((0, _localEftposState.requiresLocalPaymentRefresh)(localBeforeRefresh)) {
|
|
5363
5583
|
if (String(fresh.order_id) !== String(localBeforeRefresh.order_id)) {
|
|
5364
5584
|
throw new Error('远端订单身份不匹配,请重新刷新');
|
|
@@ -5367,7 +5587,9 @@ class Server {
|
|
|
5367
5587
|
} else {
|
|
5368
5588
|
await this.order.upsertOrdersFromRemote([orderToPersist]);
|
|
5369
5589
|
}
|
|
5370
|
-
let savedOrder = await this.order.getLocalOrderByLookup(lookup
|
|
5590
|
+
let savedOrder = prepareExactOrderForPersist ? await this.order.getLocalOrderByLookup(lookup, {
|
|
5591
|
+
exactOrderId: true
|
|
5592
|
+
}) : await this.order.getLocalOrderByLookup(lookup);
|
|
5371
5593
|
if (!savedOrder && fresh.order_id !== undefined && fresh.order_id !== null && String(fresh.order_id) !== String(lookup)) {
|
|
5372
5594
|
savedOrder = await this.order.getLocalOrderByLookup(fresh.order_id);
|
|
5373
5595
|
}
|
|
@@ -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未命中', {
|
|
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
342
342
|
date: string;
|
|
343
343
|
status: string;
|
|
344
344
|
week: string;
|
|
345
|
-
weekNum: 0 |
|
|
345
|
+
weekNum: 0 | 5 | 1 | 2 | 4 | 3 | 6;
|
|
346
346
|
}[]>;
|
|
347
347
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
348
348
|
private getScheduleDataByIds;
|
|
@@ -361,7 +361,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
361
361
|
count: number;
|
|
362
362
|
left: number;
|
|
363
363
|
summaryCount: number;
|
|
364
|
-
status: "
|
|
364
|
+
status: "lots_of_space" | "filling_up_fast" | "sold_out";
|
|
365
365
|
}[];
|
|
366
366
|
/**
|
|
367
367
|
* 找到多个资源的公共可用时间段
|
|
@@ -366,7 +366,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
366
366
|
* 获取当前的客户搜索条件
|
|
367
367
|
* @returns 当前搜索条件
|
|
368
368
|
*/
|
|
369
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
369
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
370
370
|
/**
|
|
371
371
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
372
372
|
* @returns 客户状态
|
|
@@ -24,23 +24,19 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
|
|
|
24
24
|
products: import("../../../modules/Order/types").OrderSubmitProduct[];
|
|
25
25
|
notes?: import("../../../modules/Order/types").SalesNote[] | undefined;
|
|
26
26
|
summary?: import("../../../modules/Order/types").OrderSummary | undefined;
|
|
27
|
-
|
|
28
|
-
type: string;
|
|
29
|
-
note: string;
|
|
30
|
-
holder: Record<string, any> | null;
|
|
31
|
-
relation_forms: any[];
|
|
32
|
-
holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
|
|
33
|
-
order_id: number | null;
|
|
27
|
+
bookings: any[];
|
|
34
28
|
external_sale_number: string;
|
|
29
|
+
payments: any[];
|
|
30
|
+
customer_id: number | null;
|
|
31
|
+
order_id: number | null;
|
|
35
32
|
order_number: string | null;
|
|
36
33
|
shop_order_number: string | null;
|
|
37
|
-
|
|
34
|
+
type: string;
|
|
38
35
|
business_code?: string | undefined;
|
|
39
36
|
sales_channel: string;
|
|
40
37
|
order_sales_channel: string;
|
|
41
38
|
status: string;
|
|
42
39
|
shipping_status: string;
|
|
43
|
-
customer_id: number | null;
|
|
44
40
|
customer_name: string;
|
|
45
41
|
country_calling_code: string;
|
|
46
42
|
phone: string;
|
|
@@ -55,17 +51,21 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
|
|
|
55
51
|
deposit_amount: string;
|
|
56
52
|
shop_discount: string;
|
|
57
53
|
surcharge_fee: string;
|
|
58
|
-
|
|
59
|
-
delivery_type?: string | undefined;
|
|
60
|
-
table_number?: Record<string, any> | undefined;
|
|
54
|
+
note: string;
|
|
61
55
|
schedule_date: string;
|
|
62
|
-
bookings: any[];
|
|
63
|
-
payments: any[];
|
|
64
|
-
contacts_info: Record<string, any> | null;
|
|
65
|
-
order_meta_list?: import("../../../modules/Order/types").OrderMetaList | undefined;
|
|
66
56
|
refunds?: any[] | undefined;
|
|
67
57
|
surcharges: any[];
|
|
58
|
+
relation_forms: any[];
|
|
68
59
|
contacts: any[];
|
|
60
|
+
contacts_info: Record<string, any> | null;
|
|
61
|
+
holder: Record<string, any> | null;
|
|
62
|
+
holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
|
|
63
|
+
order_meta_list?: import("../../../modules/Order/types").OrderMetaList | undefined;
|
|
64
|
+
metadata: Record<string, any>;
|
|
65
|
+
buzzer?: string | undefined;
|
|
66
|
+
shop_full_order_number: string | null;
|
|
67
|
+
delivery_type?: string | undefined;
|
|
68
|
+
table_number?: Record<string, any> | undefined;
|
|
69
69
|
};
|
|
70
70
|
export declare function describeChangedBookings(before: OrderTempOrder['bookings'], after: OrderTempOrder['bookings']): {
|
|
71
71
|
schedule_event_id: any;
|
|
@@ -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, CloudOrderInvoiceResult } from './types';
|
|
6
6
|
import type { BookingData } from '../../server/modules/order/types';
|
|
7
7
|
export * from './types';
|
|
8
8
|
/**
|
|
@@ -55,6 +55,7 @@ export declare class SalesImpl extends BaseModule implements Module, SalesModule
|
|
|
55
55
|
private logInvoiceOpenDataFallback;
|
|
56
56
|
private resolveInvoiceConfigs;
|
|
57
57
|
printLocalOrderReceipt<T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions): Promise<T>;
|
|
58
|
+
printCloudOrderInvoice(input: CloudOrderInvoiceRequest): Promise<CloudOrderInvoiceResult>;
|
|
58
59
|
/** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
|
|
59
60
|
clearOpenDataCache(): void;
|
|
60
61
|
destroy(): Promise<void>;
|
|
@@ -287,6 +287,59 @@ class SalesImpl extends _BaseModule.BaseModule {
|
|
|
287
287
|
customToast: () => {}
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
|
+
async printCloudOrderInvoice(input) {
|
|
291
|
+
const openData = this.invoiceOpenDataModule;
|
|
292
|
+
if (!openData) throw new Error('Cloud Invoice is not initialized');
|
|
293
|
+
const orderId = typeof input?.order_id === 'string' ? input.order_id.trim() : Number.isSafeInteger(input?.order_id) ? String(input.order_id) : '';
|
|
294
|
+
const channel = typeof input?.channel === 'string' ? input.channel.trim() : '';
|
|
295
|
+
const messageUuid = typeof input?.message_uuid === 'string' ? input.message_uuid.trim() : '';
|
|
296
|
+
if (!/^[1-9]\d*$/.test(orderId) || !channel || !messageUuid) {
|
|
297
|
+
throw new Error('Cloud Invoice requires order_id, channel and message_uuid');
|
|
298
|
+
}
|
|
299
|
+
const scope = openData.captureCloudInvoiceScope(input.shop_id);
|
|
300
|
+
const event = {
|
|
301
|
+
order_id: orderId,
|
|
302
|
+
channel,
|
|
303
|
+
message_uuid: messageUuid,
|
|
304
|
+
shop_id: scope.shopId
|
|
305
|
+
};
|
|
306
|
+
const requestOptions = {
|
|
307
|
+
osServer: true,
|
|
308
|
+
customToast: () => {}
|
|
309
|
+
};
|
|
310
|
+
const lookup = await this.request.post('/shop/local/cloud-order-invoice/lookup', event, requestOptions);
|
|
311
|
+
scope.assertCurrent();
|
|
312
|
+
if (lookup?.status !== true || lookup.code !== 200) {
|
|
313
|
+
throw new Error(lookup?.message || 'Cloud Invoice order lookup failed');
|
|
314
|
+
}
|
|
315
|
+
const accepted = lookup.data?.task_uuid;
|
|
316
|
+
if (typeof accepted === 'string' && accepted.trim()) return {
|
|
317
|
+
task_uuid: accepted
|
|
318
|
+
};
|
|
319
|
+
const rawBusinessCode = lookup.data?.business_code;
|
|
320
|
+
const businessCode = typeof rawBusinessCode === 'string' ? rawBusinessCode.trim() : '';
|
|
321
|
+
if (!businessCode) throw new Error('Cloud Invoice order has no business_code');
|
|
322
|
+
const deviceId = lookup.data?.device_id;
|
|
323
|
+
if (typeof deviceId !== 'string' || !deviceId.trim()) {
|
|
324
|
+
throw new Error('Cloud Invoice lookup has no device_id');
|
|
325
|
+
}
|
|
326
|
+
const settings = await openData.loadCloudInvoiceTemplate(`${businessCode}+${channel}`, scope);
|
|
327
|
+
scope.assertCurrent();
|
|
328
|
+
const submitted = await this.request.post('/shop/local/cloud-order-invoice/submit', {
|
|
329
|
+
...event,
|
|
330
|
+
business_code: businessCode,
|
|
331
|
+
device_id: deviceId,
|
|
332
|
+
template_settings: (0, _lodashEs.cloneDeep)(settings)
|
|
333
|
+
}, requestOptions);
|
|
334
|
+
scope.assertCurrent();
|
|
335
|
+
const taskUuid = submitted?.data?.task_uuid;
|
|
336
|
+
if (submitted?.status !== true || submitted.code !== 200 || typeof taskUuid !== 'string' || !taskUuid.trim()) {
|
|
337
|
+
throw new Error(submitted?.message || 'Cloud Invoice task was not accepted');
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
task_uuid: taskUuid
|
|
341
|
+
};
|
|
342
|
+
}
|
|
290
343
|
|
|
291
344
|
/** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
|
|
292
345
|
clearOpenDataCache() {
|
|
@@ -56,6 +56,17 @@ export interface SalesPrintLocalOrderReceiptOptions {
|
|
|
56
56
|
/** 当前销售入口;缺失或为 system 时按 pos 处理。 */
|
|
57
57
|
channel?: string;
|
|
58
58
|
}
|
|
59
|
+
/** Order and delivery identity supplied by the native cloud-print listener. */
|
|
60
|
+
export interface CloudOrderInvoiceRequest {
|
|
61
|
+
shop_id: string | number;
|
|
62
|
+
order_id: string | number;
|
|
63
|
+
message_uuid: string;
|
|
64
|
+
channel: string;
|
|
65
|
+
}
|
|
66
|
+
export interface CloudOrderInvoiceResult {
|
|
67
|
+
/** DeviceTask accepted for this message on the current device. */
|
|
68
|
+
task_uuid: string;
|
|
69
|
+
}
|
|
59
70
|
/**
|
|
60
71
|
* Sales 解决方案状态
|
|
61
72
|
*
|
|
@@ -90,6 +101,7 @@ export interface SalesModuleAPI {
|
|
|
90
101
|
changeBookingStatus: (params: ChangeBookingStatusParams) => Promise<any>;
|
|
91
102
|
/** 按本地订单标识打印小票;本地未命中时由 OS Server 负责远端兜底。 */
|
|
92
103
|
printLocalOrderReceipt: <T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions) => Promise<T>;
|
|
104
|
+
printCloudOrderInvoice: (request: CloudOrderInvoiceRequest) => Promise<CloudOrderInvoiceResult>;
|
|
93
105
|
/** 清除 Legacy Sales 独立维护的 Documents OpenData 缓存。 */
|
|
94
106
|
clearOpenDataCache: () => void;
|
|
95
107
|
/** 获取资源维度的预约占用列表 */
|
|
@@ -18,6 +18,7 @@ let SalesHooks = exports.SalesHooks = /*#__PURE__*/function (SalesHooks) {
|
|
|
18
18
|
* 将 Server/Order 原始数据转换为真正的 Reservation DTO,
|
|
19
19
|
* 当前不要直接把 OrderData 当作最终 UI 数据结构。
|
|
20
20
|
*/
|
|
21
|
+
/** Order and delivery identity supplied by the native cloud-print listener. */
|
|
21
22
|
/**
|
|
22
23
|
* Sales 解决方案状态
|
|
23
24
|
*
|