@pisell/pisellos 2.3.220 → 2.3.222
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 +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 +850 -591
- 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/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +11 -11
- 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/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 +154 -17
- 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/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +11 -11
- 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
|
@@ -642,7 +642,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
642
642
|
generateIdempotencyToken(): string;
|
|
643
643
|
syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
|
|
644
644
|
createOrder(params: CommitOrderParams['query']): {
|
|
645
|
-
type: "
|
|
645
|
+
type: "appointment_booking" | "virtual";
|
|
646
646
|
platform: string;
|
|
647
647
|
sales_channel: string;
|
|
648
648
|
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(): "normal" | "
|
|
52
|
+
getProductType(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
package/lib/server/index.d.ts
CHANGED
|
@@ -541,8 +541,11 @@ declare class Server {
|
|
|
541
541
|
private shouldLookupLocalPrintOrder;
|
|
542
542
|
private getLocalPrintOrderLookup;
|
|
543
543
|
private mergeLocalPrintOrderInput;
|
|
544
|
+
private loadCloudInvoiceOrder;
|
|
545
|
+
private handleCloudOrderInvoice;
|
|
544
546
|
private handleLocalPrintOrder;
|
|
545
547
|
private normalizeRequestedReceiptLocales;
|
|
548
|
+
private rebuildOrderReceipt;
|
|
546
549
|
private handleLocalOrderReceiptSnapshot;
|
|
547
550
|
private handleMachinecodeBatchMeta;
|
|
548
551
|
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',
|
|
@@ -4030,6 +4042,125 @@ class Server {
|
|
|
4030
4042
|
external_sale_number: localOrder.external_sale_number ?? definedInput.external_sale_number ?? definedInput.externalSaleNumber
|
|
4031
4043
|
};
|
|
4032
4044
|
}
|
|
4045
|
+
async loadCloudInvoiceOrder(orderId, shopId, assertCurrentShop) {
|
|
4046
|
+
if (!this.order) throw new Error('Cloud invoice order service is unavailable');
|
|
4047
|
+
const hasReceiptDetail = order => {
|
|
4048
|
+
// Use the same amount fields as the receipt builder, including historical
|
|
4049
|
+
// top-level amounts. Zero is a valid total; a missing total in a list row is not.
|
|
4050
|
+
const total = [order.summary?.expect_amount, order.expect_amount, order.summary?.total_amount, order.total_amount].find(value => value != null && value !== '');
|
|
4051
|
+
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));
|
|
4052
|
+
};
|
|
4053
|
+
const local = await this.order.getLocalOrderByLookup(orderId, {
|
|
4054
|
+
exactOrderId: true
|
|
4055
|
+
});
|
|
4056
|
+
assertCurrentShop();
|
|
4057
|
+
if (local && String(local.order_id) === orderId) {
|
|
4058
|
+
if (local.shop_id != null && String(local.shop_id) !== shopId) {
|
|
4059
|
+
throw new Error('Cloud invoice order belongs to another shop');
|
|
4060
|
+
}
|
|
4061
|
+
if (String(local.shop_id) === shopId && hasReceiptDetail(local)) return local;
|
|
4062
|
+
}
|
|
4063
|
+
|
|
4064
|
+
// The generic detail route also matches short receipt numbers. Validate the
|
|
4065
|
+
// backend identity and live shop BEFORE its result enters the shared store.
|
|
4066
|
+
const result = await this.fetchAndPersistSalesOrderByLookup(orderId, {
|
|
4067
|
+
with: ['all']
|
|
4068
|
+
}, 'cloudOrderInvoice', undefined, fresh => {
|
|
4069
|
+
assertCurrentShop();
|
|
4070
|
+
if (String(fresh.order_id) !== orderId || fresh.shop_id != null && String(fresh.shop_id) !== shopId || !hasReceiptDetail(fresh)) {
|
|
4071
|
+
throw new Error('Cloud invoice order identity or detail is invalid');
|
|
4072
|
+
}
|
|
4073
|
+
// Some older shop-authenticated detail responses omit shop_id.
|
|
4074
|
+
return fresh.shop_id == null ? {
|
|
4075
|
+
...fresh,
|
|
4076
|
+
shop_id: Number(shopId)
|
|
4077
|
+
} : fresh;
|
|
4078
|
+
});
|
|
4079
|
+
assertCurrentShop();
|
|
4080
|
+
const saved = result.order;
|
|
4081
|
+
if (!saved || String(saved.order_id) !== orderId || String(saved.shop_id) !== shopId || !hasReceiptDetail(saved)) {
|
|
4082
|
+
throw new Error(result.message || 'Cloud invoice order detail is unavailable');
|
|
4083
|
+
}
|
|
4084
|
+
return saved;
|
|
4085
|
+
}
|
|
4086
|
+
async handleCloudOrderInvoice(input, submit) {
|
|
4087
|
+
const orderId = typeof input?.order_id === 'string' ? input.order_id.trim() : Number.isSafeInteger(input?.order_id) ? String(input.order_id) : '';
|
|
4088
|
+
if (!/^[1-9]\d*$/.test(orderId)) {
|
|
4089
|
+
return {
|
|
4090
|
+
code: 400,
|
|
4091
|
+
status: false,
|
|
4092
|
+
message: 'Invalid cloud invoice order ID',
|
|
4093
|
+
data: null
|
|
4094
|
+
};
|
|
4095
|
+
}
|
|
4096
|
+
try {
|
|
4097
|
+
const shopId = String(this.getAppData('shop_id') ?? '');
|
|
4098
|
+
const tenantId = String(this.getAppData('tenant_id') ?? '');
|
|
4099
|
+
if (!/^[1-9]\d*$/.test(shopId) || !Number.isSafeInteger(Number(shopId))) {
|
|
4100
|
+
throw new Error('Cloud invoice shop is unavailable');
|
|
4101
|
+
}
|
|
4102
|
+
const assertCurrentShop = () => {
|
|
4103
|
+
if (String(this.getAppData('shop_id') ?? '') !== shopId || String(this.getAppData('tenant_id') ?? '') !== tenantId) {
|
|
4104
|
+
throw new Error('Cloud invoice shop context changed');
|
|
4105
|
+
}
|
|
4106
|
+
};
|
|
4107
|
+
const order = await this.loadCloudInvoiceOrder(orderId, shopId, assertCurrentShop);
|
|
4108
|
+
const businessCode = order.business_code.trim();
|
|
4109
|
+
if (!submit) return {
|
|
4110
|
+
code: 200,
|
|
4111
|
+
status: true,
|
|
4112
|
+
message: '',
|
|
4113
|
+
data: {
|
|
4114
|
+
business_code: businessCode
|
|
4115
|
+
}
|
|
4116
|
+
};
|
|
4117
|
+
if (input.business_code !== businessCode || typeof input.template_settings?.template !== 'string' || !input.template_settings.template.trim() || !Array.isArray(input.template_settings.modules)) {
|
|
4118
|
+
throw new Error('Cloud invoice template is missing or belongs to another business');
|
|
4119
|
+
}
|
|
4120
|
+
const settings = this.normalizePrintInvoiceTemplateSettings(input.template_settings);
|
|
4121
|
+
const receipt = await this.rebuildOrderReceipt(order, settings);
|
|
4122
|
+
const smallTicketData = receipt.payment_info?.small_ticket_data;
|
|
4123
|
+
if (!(0, _smallTicket.hasSmallTicketData)(smallTicketData)) throw new Error('Cloud invoice snapshot is unavailable');
|
|
4124
|
+
const deviceTask = this.getDeviceTaskPlugin();
|
|
4125
|
+
if (!deviceTask?.dispatch) throw new Error('Print task service is unavailable');
|
|
4126
|
+
const deviceId = await this.getShortNumberOrDeviceId();
|
|
4127
|
+
assertCurrentShop();
|
|
4128
|
+
await deviceTask.dispatch({
|
|
4129
|
+
action: 'print_all',
|
|
4130
|
+
device_id: deviceId,
|
|
4131
|
+
name: 'PRINT_V1',
|
|
4132
|
+
source: 'server',
|
|
4133
|
+
source_type: 'order',
|
|
4134
|
+
source_id: order.order_id,
|
|
4135
|
+
payload: {
|
|
4136
|
+
type: '0',
|
|
4137
|
+
template_settings: settings,
|
|
4138
|
+
data: {
|
|
4139
|
+
order_id: order.order_id,
|
|
4140
|
+
small_ticket_data: smallTicketData
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
});
|
|
4144
|
+
return {
|
|
4145
|
+
code: 200,
|
|
4146
|
+
status: true,
|
|
4147
|
+
message: '',
|
|
4148
|
+
data: null
|
|
4149
|
+
};
|
|
4150
|
+
} catch (error) {
|
|
4151
|
+
const message = this.getUnknownErrorMessage(error);
|
|
4152
|
+
this.logWarning('Cloud invoice request failed', {
|
|
4153
|
+
orderId,
|
|
4154
|
+
message
|
|
4155
|
+
});
|
|
4156
|
+
return {
|
|
4157
|
+
code: 500,
|
|
4158
|
+
status: false,
|
|
4159
|
+
message,
|
|
4160
|
+
data: null
|
|
4161
|
+
};
|
|
4162
|
+
}
|
|
4163
|
+
}
|
|
4033
4164
|
handleLocalPrintOrder = async ({
|
|
4034
4165
|
data
|
|
4035
4166
|
}) => {
|
|
@@ -4162,6 +4293,22 @@ class Server {
|
|
|
4162
4293
|
if (!Array.isArray(value)) return [];
|
|
4163
4294
|
return Array.from(new Set(value.filter(locale => typeof locale === 'string').map(locale => locale.trim()).filter(Boolean)));
|
|
4164
4295
|
}
|
|
4296
|
+
rebuildOrderReceipt(order, templateSettings, locales) {
|
|
4297
|
+
const paymentInfo = {
|
|
4298
|
+
...order.payment_info
|
|
4299
|
+
};
|
|
4300
|
+
delete paymentInfo.small_ticket_data;
|
|
4301
|
+
return this.withLocalSmallTicketData({
|
|
4302
|
+
...order,
|
|
4303
|
+
small_ticket_data_flag: 1,
|
|
4304
|
+
payment_info: paymentInfo
|
|
4305
|
+
}, {
|
|
4306
|
+
locales,
|
|
4307
|
+
invoiceTemplateSettings: templateSettings,
|
|
4308
|
+
applyTemplateVisibility: true,
|
|
4309
|
+
includeReceiptKeys: templateSettings !== undefined
|
|
4310
|
+
});
|
|
4311
|
+
}
|
|
4165
4312
|
handleLocalOrderReceiptSnapshot = async ({
|
|
4166
4313
|
data
|
|
4167
4314
|
}) => {
|
|
@@ -4205,20 +4352,7 @@ class Server {
|
|
|
4205
4352
|
}
|
|
4206
4353
|
sourceOrder = remoteResult.order;
|
|
4207
4354
|
}
|
|
4208
|
-
const
|
|
4209
|
-
...(sourceOrder.payment_info || {})
|
|
4210
|
-
};
|
|
4211
|
-
delete paymentInfo.small_ticket_data;
|
|
4212
|
-
const rebuiltOrder = await this.withLocalSmallTicketData({
|
|
4213
|
-
...sourceOrder,
|
|
4214
|
-
small_ticket_data_flag: 1,
|
|
4215
|
-
payment_info: paymentInfo
|
|
4216
|
-
}, {
|
|
4217
|
-
locales: this.normalizeRequestedReceiptLocales(input.locales),
|
|
4218
|
-
invoiceTemplateSettings: input.template_settings === undefined ? undefined : this.normalizePrintInvoiceTemplateSettings(input.template_settings),
|
|
4219
|
-
applyTemplateVisibility: true,
|
|
4220
|
-
includeReceiptKeys: input.template_settings !== undefined
|
|
4221
|
-
});
|
|
4355
|
+
const rebuiltOrder = await this.rebuildOrderReceipt(sourceOrder, input.template_settings === undefined ? undefined : this.normalizePrintInvoiceTemplateSettings(input.template_settings), this.normalizeRequestedReceiptLocales(input.locales));
|
|
4222
4356
|
const smallTicketData = rebuiltOrder.payment_info?.small_ticket_data;
|
|
4223
4357
|
if (!(0, _smallTicket.hasSmallTicketData)(smallTicketData)) {
|
|
4224
4358
|
return {
|
|
@@ -5169,7 +5303,7 @@ class Server {
|
|
|
5169
5303
|
const code = typeof value === 'number' ? value : Number(value);
|
|
5170
5304
|
return Number.isFinite(code) ? code : 500;
|
|
5171
5305
|
}
|
|
5172
|
-
async fetchAndPersistSalesOrderByLookup(lookup, data, title, paymentIdentityOrder) {
|
|
5306
|
+
async fetchAndPersistSalesOrderByLookup(lookup, data, title, paymentIdentityOrder, prepareExactOrderForPersist) {
|
|
5173
5307
|
if (!this.order?.getLocalOrderByLookup || !this.order?.upsertOrdersFromRemote) {
|
|
5174
5308
|
this.logError(`${title}: Order 模块未注册`);
|
|
5175
5309
|
return {
|
|
@@ -5222,7 +5356,7 @@ class Server {
|
|
|
5222
5356
|
order: null
|
|
5223
5357
|
};
|
|
5224
5358
|
}
|
|
5225
|
-
const localBeforeRefresh = this.order.getLocalOrderFromMemoryByLookup?.(lookup) || (this.shouldForceRemoteSalesDetail(data) ? await this.order.getLocalOrderByLookup(lookup) : null);
|
|
5359
|
+
const localBeforeRefresh = prepareExactOrderForPersist ? this.order.getOrderByOrderId?.(lookup) : this.order.getLocalOrderFromMemoryByLookup?.(lookup) || (this.shouldForceRemoteSalesDetail(data) ? await this.order.getLocalOrderByLookup(lookup) : null);
|
|
5226
5360
|
let orderToPersist = fresh;
|
|
5227
5361
|
if (paymentIdentityOrder) {
|
|
5228
5362
|
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)) {
|
|
@@ -5254,6 +5388,7 @@ class Server {
|
|
|
5254
5388
|
})
|
|
5255
5389
|
};
|
|
5256
5390
|
}
|
|
5391
|
+
if (prepareExactOrderForPersist) orderToPersist = prepareExactOrderForPersist(orderToPersist);
|
|
5257
5392
|
if ((0, _localEftposState.requiresLocalPaymentRefresh)(localBeforeRefresh)) {
|
|
5258
5393
|
if (String(fresh.order_id) !== String(localBeforeRefresh.order_id)) {
|
|
5259
5394
|
throw new Error('远端订单身份不匹配,请重新刷新');
|
|
@@ -5262,7 +5397,9 @@ class Server {
|
|
|
5262
5397
|
} else {
|
|
5263
5398
|
await this.order.upsertOrdersFromRemote([orderToPersist]);
|
|
5264
5399
|
}
|
|
5265
|
-
let savedOrder = await this.order.getLocalOrderByLookup(lookup
|
|
5400
|
+
let savedOrder = prepareExactOrderForPersist ? await this.order.getLocalOrderByLookup(lookup, {
|
|
5401
|
+
exactOrderId: true
|
|
5402
|
+
}) : await this.order.getLocalOrderByLookup(lookup);
|
|
5266
5403
|
if (!savedOrder && fresh.order_id !== undefined && fresh.order_id !== null && String(fresh.order_id) !== String(lookup)) {
|
|
5267
5404
|
savedOrder = await this.order.getLocalOrderByLookup(fresh.order_id);
|
|
5268
5405
|
}
|
|
@@ -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;
|
|
@@ -373,7 +373,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
373
373
|
* 获取当前的客户搜索条件
|
|
374
374
|
* @returns 当前搜索条件
|
|
375
375
|
*/
|
|
376
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
376
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
377
377
|
/**
|
|
378
378
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
379
379
|
* @returns 客户状态
|
|
@@ -25,21 +25,19 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
|
|
|
25
25
|
notes?: import("../../../modules/Order/types").SalesNote[] | undefined;
|
|
26
26
|
summary?: import("../../../modules/Order/types").OrderSummary | undefined;
|
|
27
27
|
small_ticket_data_flag?: number | undefined;
|
|
28
|
-
|
|
29
|
-
metadata: Record<string, any>;
|
|
30
|
-
note: string;
|
|
31
|
-
order_id: number | null;
|
|
28
|
+
bookings: any[];
|
|
32
29
|
external_sale_number: string;
|
|
30
|
+
payments: any[];
|
|
31
|
+
customer_id: number | null;
|
|
32
|
+
order_id: number | null;
|
|
33
33
|
order_number: string | null;
|
|
34
34
|
shop_order_number: string | null;
|
|
35
|
-
shop_full_order_number: string | null;
|
|
36
35
|
type: string;
|
|
37
36
|
business_code?: string | undefined;
|
|
38
37
|
sales_channel: string;
|
|
39
38
|
order_sales_channel: string;
|
|
40
39
|
status: string;
|
|
41
40
|
shipping_status: string;
|
|
42
|
-
customer_id: number | null;
|
|
43
41
|
customer_name: string;
|
|
44
42
|
country_calling_code: string;
|
|
45
43
|
phone: string;
|
|
@@ -54,19 +52,21 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
|
|
|
54
52
|
deposit_amount: string;
|
|
55
53
|
shop_discount: string;
|
|
56
54
|
surcharge_fee: string;
|
|
57
|
-
|
|
58
|
-
delivery_type?: string | undefined;
|
|
59
|
-
table_number?: Record<string, any> | undefined;
|
|
55
|
+
note: string;
|
|
60
56
|
schedule_date: string;
|
|
61
|
-
bookings: any[];
|
|
62
|
-
payments: any[];
|
|
63
57
|
refunds?: any[] | undefined;
|
|
64
58
|
surcharges: any[];
|
|
65
59
|
relation_forms: any[];
|
|
66
60
|
contacts: any[];
|
|
67
61
|
contacts_info: Record<string, any> | null;
|
|
68
62
|
holder: Record<string, any> | null;
|
|
63
|
+
holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
|
|
69
64
|
order_meta_list?: import("../../../modules/Order/types").OrderMetaList | undefined;
|
|
65
|
+
metadata: Record<string, any>;
|
|
66
|
+
buzzer?: string | undefined;
|
|
67
|
+
shop_full_order_number: string | null;
|
|
68
|
+
delivery_type?: string | undefined;
|
|
69
|
+
table_number?: Record<string, any> | undefined;
|
|
70
70
|
};
|
|
71
71
|
export declare function describeChangedBookings(before: OrderTempOrder['bookings'], after: OrderTempOrder['bookings']): {
|
|
72
72
|
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 } 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>;
|
|
@@ -26,9 +26,6 @@ Object.keys(_types).forEach(function (key) {
|
|
|
26
26
|
var _OpenData = require("../../modules/OpenData");
|
|
27
27
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
28
|
const UNPAID_PAYMENT_STATUSES = new Set(['unpaid', 'partially_paid', 'payment_processing']);
|
|
29
|
-
const INVOICE_OPEN_DATA_SECTION_CODES = ['documents'];
|
|
30
|
-
const INVOICE_OPEN_DATA_CACHE_TTL = 5 * 60 * 1000;
|
|
31
|
-
|
|
32
29
|
/**
|
|
33
30
|
* Sales 解决方案基础骨架
|
|
34
31
|
*
|
|
@@ -51,9 +48,6 @@ class SalesImpl extends _BaseModule.BaseModule {
|
|
|
51
48
|
request;
|
|
52
49
|
logger; // LoggerManager 实例
|
|
53
50
|
invoiceOpenDataModule = null;
|
|
54
|
-
invoiceOpenDataTarget = null;
|
|
55
|
-
invoiceOpenDataInFlight = null;
|
|
56
|
-
invoiceOpenDataInFlightTarget = null;
|
|
57
51
|
constructor(name, version) {
|
|
58
52
|
super(name, version);
|
|
59
53
|
}
|
|
@@ -86,9 +80,6 @@ class SalesImpl extends _BaseModule.BaseModule {
|
|
|
86
80
|
// 在这里补充从 Server/Order 读取 currentDay 原始数据并转换为预约列表。
|
|
87
81
|
|
|
88
82
|
this.logger = appPlugin?.getApp().logger;
|
|
89
|
-
this.invoiceOpenDataTarget = null;
|
|
90
|
-
this.invoiceOpenDataInFlight = null;
|
|
91
|
-
this.invoiceOpenDataInFlightTarget = null;
|
|
92
83
|
this.invoiceOpenDataModule = new _OpenData.OpenDataModule(`${this.name}_invoiceOpenData`);
|
|
93
84
|
this.core.registerModule(this.invoiceOpenDataModule, {
|
|
94
85
|
initialState: {},
|
|
@@ -175,51 +166,6 @@ class SalesImpl extends _BaseModule.BaseModule {
|
|
|
175
166
|
const normalized = String(channel ?? contextChannel ?? '').trim();
|
|
176
167
|
return !normalized || normalized === 'system' ? 'pos' : normalized;
|
|
177
168
|
}
|
|
178
|
-
async loadInvoiceOpenData(businessCode, channel) {
|
|
179
|
-
if (!this.invoiceOpenDataModule) {
|
|
180
|
-
throw new Error('Sales Invoice OpenData 模块未初始化');
|
|
181
|
-
}
|
|
182
|
-
const target = `${businessCode}+${channel}`;
|
|
183
|
-
const cachedData = this.invoiceOpenDataModule.getOpenData();
|
|
184
|
-
const lastFetchedAt = this.invoiceOpenDataModule.getLastFetchedAt();
|
|
185
|
-
if (cachedData && this.invoiceOpenDataTarget === target && typeof lastFetchedAt === 'number' && Date.now() - lastFetchedAt < INVOICE_OPEN_DATA_CACHE_TTL) {
|
|
186
|
-
if (typeof this.invoiceOpenDataModule.ensureInvoiceTemplateSettings === 'function') {
|
|
187
|
-
await this.invoiceOpenDataModule.ensureInvoiceTemplateSettings(target);
|
|
188
|
-
}
|
|
189
|
-
return cachedData;
|
|
190
|
-
}
|
|
191
|
-
if (this.invoiceOpenDataInFlight) {
|
|
192
|
-
if (this.invoiceOpenDataInFlightTarget === target) {
|
|
193
|
-
return this.invoiceOpenDataInFlight;
|
|
194
|
-
}
|
|
195
|
-
try {
|
|
196
|
-
await this.invoiceOpenDataInFlight;
|
|
197
|
-
} catch {
|
|
198
|
-
// 另一 target 的失败不应阻断当前 target 获取自己的 Documents 配置。
|
|
199
|
-
}
|
|
200
|
-
return this.loadInvoiceOpenData(businessCode, channel);
|
|
201
|
-
}
|
|
202
|
-
const request = this.invoiceOpenDataModule.fetchOpenData({
|
|
203
|
-
scope: 'board',
|
|
204
|
-
target,
|
|
205
|
-
section_code: [...INVOICE_OPEN_DATA_SECTION_CODES]
|
|
206
|
-
});
|
|
207
|
-
this.invoiceOpenDataInFlight = request;
|
|
208
|
-
this.invoiceOpenDataInFlightTarget = target;
|
|
209
|
-
try {
|
|
210
|
-
const openData = await request;
|
|
211
|
-
// clearOpenDataCache() 或后续请求接管后,旧响应不得复活 target 归属。
|
|
212
|
-
if (this.invoiceOpenDataInFlight === request) {
|
|
213
|
-
this.invoiceOpenDataTarget = target;
|
|
214
|
-
}
|
|
215
|
-
return openData;
|
|
216
|
-
} finally {
|
|
217
|
-
if (this.invoiceOpenDataInFlight === request) {
|
|
218
|
-
this.invoiceOpenDataInFlight = null;
|
|
219
|
-
this.invoiceOpenDataInFlightTarget = null;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
169
|
logInvoiceOpenDataFallback(error) {
|
|
224
170
|
const message = error instanceof Error ? error.message : String(error);
|
|
225
171
|
if (this.logger?.addLog) {
|
|
@@ -236,16 +182,11 @@ class SalesImpl extends _BaseModule.BaseModule {
|
|
|
236
182
|
}
|
|
237
183
|
async resolveInvoiceConfigs(businessCode, channel) {
|
|
238
184
|
try {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return {
|
|
242
|
-
invoice: (0, _OpenData.getDefaultInvoiceLayoutConfig)(),
|
|
243
|
-
templateSettings: (0, _OpenData.getDefaultInvoiceTemplateSettings)()
|
|
244
|
-
};
|
|
245
|
-
}
|
|
185
|
+
if (!this.invoiceOpenDataModule) throw new Error('Sales Invoice OpenData 模块未初始化');
|
|
186
|
+
const templateSettings = await this.invoiceOpenDataModule.loadPrintInvoiceTemplate(`${businessCode}+${channel}`, 'manual');
|
|
246
187
|
return {
|
|
247
|
-
invoice:
|
|
248
|
-
templateSettings
|
|
188
|
+
invoice: (0, _OpenData.normalizeInvoiceLayoutFromTemplateSettings)(templateSettings),
|
|
189
|
+
templateSettings
|
|
249
190
|
};
|
|
250
191
|
} catch (error) {
|
|
251
192
|
this.logInvoiceOpenDataFallback(error);
|
|
@@ -287,12 +228,37 @@ class SalesImpl extends _BaseModule.BaseModule {
|
|
|
287
228
|
customToast: () => {}
|
|
288
229
|
});
|
|
289
230
|
}
|
|
231
|
+
async printCloudOrderInvoice(input) {
|
|
232
|
+
const orderId = input?.order_id;
|
|
233
|
+
const channel = typeof input?.channel === 'string' ? input.channel.trim() : '';
|
|
234
|
+
if (!channel) throw new Error('Cloud Invoice requires a channel');
|
|
235
|
+
const openData = this.invoiceOpenDataModule;
|
|
236
|
+
if (!openData) throw new Error('Cloud Invoice is not initialized');
|
|
237
|
+
const requestOptions = {
|
|
238
|
+
osServer: true,
|
|
239
|
+
customToast: () => {}
|
|
240
|
+
};
|
|
241
|
+
const lookup = await this.request.post('/shop/local/cloud-order-invoice/lookup', {
|
|
242
|
+
order_id: orderId
|
|
243
|
+
}, requestOptions);
|
|
244
|
+
if (lookup?.status !== true || lookup.code !== 200) {
|
|
245
|
+
throw new Error(lookup?.message || 'Cloud Invoice order lookup failed');
|
|
246
|
+
}
|
|
247
|
+
const businessCode = lookup.data?.business_code?.trim();
|
|
248
|
+
if (!businessCode) throw new Error('Cloud Invoice order has no business_code');
|
|
249
|
+
const settings = await openData.loadCloudInvoiceTemplate(`${businessCode}+${channel}`);
|
|
250
|
+
const result = await this.request.post('/shop/local/cloud-order-invoice/submit', {
|
|
251
|
+
order_id: orderId,
|
|
252
|
+
business_code: businessCode,
|
|
253
|
+
template_settings: settings
|
|
254
|
+
}, requestOptions);
|
|
255
|
+
if (result?.status !== true || result.code !== 200) {
|
|
256
|
+
throw new Error(result?.message || 'Cloud Invoice dispatch failed');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
290
259
|
|
|
291
260
|
/** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
|
|
292
261
|
clearOpenDataCache() {
|
|
293
|
-
this.invoiceOpenDataInFlight = null;
|
|
294
|
-
this.invoiceOpenDataInFlightTarget = null;
|
|
295
|
-
this.invoiceOpenDataTarget = null;
|
|
296
262
|
this.invoiceOpenDataModule?.clearCache();
|
|
297
263
|
}
|
|
298
264
|
|
|
@@ -56,6 +56,11 @@ export interface SalesPrintLocalOrderReceiptOptions {
|
|
|
56
56
|
/** 当前销售入口;缺失或为 system 时按 pos 处理。 */
|
|
57
57
|
channel?: string;
|
|
58
58
|
}
|
|
59
|
+
/** Native cloud-order notification. */
|
|
60
|
+
export interface CloudOrderInvoiceRequest {
|
|
61
|
+
order_id: string | number;
|
|
62
|
+
channel: string;
|
|
63
|
+
}
|
|
59
64
|
/**
|
|
60
65
|
* Sales 解决方案状态
|
|
61
66
|
*
|
|
@@ -90,6 +95,7 @@ export interface SalesModuleAPI {
|
|
|
90
95
|
changeBookingStatus: (params: ChangeBookingStatusParams) => Promise<any>;
|
|
91
96
|
/** 按本地订单标识打印小票;本地未命中时由 OS Server 负责远端兜底。 */
|
|
92
97
|
printLocalOrderReceipt: <T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions) => Promise<T>;
|
|
98
|
+
printCloudOrderInvoice: (request: CloudOrderInvoiceRequest) => Promise<void>;
|
|
93
99
|
/** 清除 Legacy Sales 独立维护的 Documents OpenData 缓存。 */
|
|
94
100
|
clearOpenDataCache: () => void;
|
|
95
101
|
/** 获取资源维度的预约占用列表 */
|