@pisell/pisellos 2.3.219 → 2.3.221
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 +3 -0
- package/dist/modules/OpenData/index.js +160 -84
- package/dist/modules/Order/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/BaseSales/index.d.ts +2 -0
- package/dist/solution/BaseSales/index.js +65 -37
- package/dist/solution/BaseSales/types.d.ts +2 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +7 -0
- package/dist/solution/BookingTicket/index.js +510 -385
- package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +9 -9
- package/dist/solution/Sales/index.d.ts +2 -1
- package/dist/solution/Sales/index.js +123 -49
- package/dist/solution/Sales/types.d.ts +6 -0
- package/dist/solution/Sales/types.js +2 -0
- package/lib/modules/OpenData/index.d.ts +3 -0
- package/lib/modules/OpenData/index.js +51 -18
- package/lib/modules/Order/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/BaseSales/index.d.ts +2 -0
- package/lib/solution/BaseSales/index.js +27 -6
- package/lib/solution/BaseSales/types.d.ts +2 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +7 -0
- package/lib/solution/BookingTicket/index.js +50 -4
- package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +9 -9
- package/lib/solution/Sales/index.d.ts +2 -1
- package/lib/solution/Sales/index.js +28 -1
- package/lib/solution/Sales/types.d.ts +6 -0
- package/lib/solution/Sales/types.js +1 -0
- package/package.json +1 -1
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未命中', {
|
|
@@ -55,6 +55,8 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
55
55
|
protected store: BaseSalesState;
|
|
56
56
|
protected otherParams: Record<string, any>;
|
|
57
57
|
getInventory(): InventoryController | undefined;
|
|
58
|
+
/** Retail and standard POS opt in per sales instance; other hosts retain their member flow. */
|
|
59
|
+
isMemberCartConsistencyEnabled(): boolean;
|
|
58
60
|
prepareCheckout(signal?: AbortSignal): Promise<CheckoutRuntimeSnapshot | undefined>;
|
|
59
61
|
protected cacheId: string | undefined;
|
|
60
62
|
/**
|
|
@@ -23,6 +23,7 @@ Object.keys(_types).forEach(function (key) {
|
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
25
|
var _Order = require("../../modules/Order");
|
|
26
|
+
var _discountProductLineIdentity = require("../../modules/Order/utils/discountProductLineIdentity");
|
|
26
27
|
var _pickupTiming = require("../../modules/Order/pickupTiming");
|
|
27
28
|
var _pickupTiming2 = require("./pickupTiming");
|
|
28
29
|
var _fulfillmentItemRules = require("./fulfillmentItemRules");
|
|
@@ -156,6 +157,14 @@ function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
|
|
|
156
157
|
return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
|
|
157
158
|
});
|
|
158
159
|
}
|
|
160
|
+
|
|
161
|
+
/** Rules may split a coupon quantity into rows that still share the original UID. */
|
|
162
|
+
function applyDiscountProductLines(tempOrder, products, discounts, enableMemberCartConsistency) {
|
|
163
|
+
tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, products);
|
|
164
|
+
if (!enableMemberCartConsistency) return;
|
|
165
|
+
(0, _discountProductLineIdentity.ensureUniqueProductLineUids)(tempOrder, discounts);
|
|
166
|
+
(0, _discountProductLineIdentity.consolidateDiscountFreeProductLines)(tempOrder);
|
|
167
|
+
}
|
|
159
168
|
function isBaseSalesHistoricalDiscountEntry(discount) {
|
|
160
169
|
return Boolean(discount?.isEditMode || discount?.isDisabled || discount?.order_discount_id != null);
|
|
161
170
|
}
|
|
@@ -517,6 +526,11 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
517
526
|
getInventory() {
|
|
518
527
|
return this.otherParams.inventory;
|
|
519
528
|
}
|
|
529
|
+
|
|
530
|
+
/** Retail and standard POS opt in per sales instance; other hosts retain their member flow. */
|
|
531
|
+
isMemberCartConsistencyEnabled() {
|
|
532
|
+
return this.otherParams.enableMemberCartConsistency === true;
|
|
533
|
+
}
|
|
520
534
|
async prepareCheckout(signal) {
|
|
521
535
|
const inventory = this.getInventory();
|
|
522
536
|
const hooks = this.otherParams.checkoutHooks;
|
|
@@ -2322,7 +2336,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2322
2336
|
}
|
|
2323
2337
|
async loadDiscountConfig(params) {
|
|
2324
2338
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2325
|
-
|
|
2339
|
+
let tempOrder = this.store.order.ensureTempOrder();
|
|
2326
2340
|
const orderStore = this.store.order.store || {};
|
|
2327
2341
|
const discountModule = orderStore.discount;
|
|
2328
2342
|
const rulesModule = orderStore.rules;
|
|
@@ -2337,7 +2351,11 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2337
2351
|
let requestEpoch = this.store.order.getCustomerWalletPrepareConfigEpoch?.();
|
|
2338
2352
|
const isCurrentRequest = () => {
|
|
2339
2353
|
const currentTempOrder = this.store.order?.getTempOrder?.();
|
|
2340
|
-
|
|
2354
|
+
const current = Boolean(currentTempOrder && (requestEpoch === undefined || this.store.order?.getCustomerWalletPrepareConfigEpoch?.() === requestEpoch) && this.resolveDiscountConfigCustomerId(currentTempOrder) === customerId && this.getDiscountConfigOrderIdentityKey(currentTempOrder) === requestOrderIdentityKey);
|
|
2355
|
+
// Cart edits can replace the object while member configuration is pending.
|
|
2356
|
+
// Keep the logical-order guard, but apply coupons to its latest rows.
|
|
2357
|
+
if (current && this.isMemberCartConsistencyEnabled()) tempOrder = currentTempOrder;
|
|
2358
|
+
return current;
|
|
2341
2359
|
};
|
|
2342
2360
|
const getCurrentResult = () => {
|
|
2343
2361
|
const currentTempOrder = this.store.order?.getTempOrder?.();
|
|
@@ -2466,7 +2484,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2466
2484
|
discountList: nextDiscountList
|
|
2467
2485
|
};
|
|
2468
2486
|
if (result.productList) {
|
|
2469
|
-
tempOrder
|
|
2487
|
+
applyDiscountProductLines(tempOrder, result.productList, result.discountList || nextDiscountList, this.isMemberCartConsistencyEnabled());
|
|
2470
2488
|
}
|
|
2471
2489
|
for (const product of tempOrder.products || []) {
|
|
2472
2490
|
const productUid = product.metadata?.unique_identification_number;
|
|
@@ -2559,7 +2577,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2559
2577
|
preserveEntitlementSelection: false
|
|
2560
2578
|
}) || result;
|
|
2561
2579
|
if (result.productList) {
|
|
2562
|
-
tempOrder
|
|
2580
|
+
applyDiscountProductLines(tempOrder, result.productList, result.discountList || nextDiscountList, this.isMemberCartConsistencyEnabled());
|
|
2563
2581
|
}
|
|
2564
2582
|
if (result.discountList) {
|
|
2565
2583
|
nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
|
|
@@ -2686,7 +2704,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2686
2704
|
discountList: updated
|
|
2687
2705
|
};
|
|
2688
2706
|
if (result?.productList) {
|
|
2689
|
-
tempOrder
|
|
2707
|
+
applyDiscountProductLines(tempOrder, result.productList, result.discountList || updated, this.isMemberCartConsistencyEnabled());
|
|
2690
2708
|
}
|
|
2691
2709
|
if (result?.discountList) {
|
|
2692
2710
|
nextDiscountList = result.discountList;
|
|
@@ -2774,7 +2792,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2774
2792
|
const orderStore = this.store.order.store || {};
|
|
2775
2793
|
const discountModule = orderStore.discount;
|
|
2776
2794
|
if (result.productList) {
|
|
2777
|
-
tempOrder.
|
|
2795
|
+
applyDiscountProductLines(tempOrder, result.productList, result.discountList || this.getDiscountList(), this.isMemberCartConsistencyEnabled());
|
|
2778
2796
|
}
|
|
2779
2797
|
if (result.discountList) {
|
|
2780
2798
|
_Order.OrderModule.populateSavedAmounts(tempOrder.products, result.discountList);
|
|
@@ -4416,6 +4434,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4416
4434
|
const currentOrderCustomerId = this.getCurrentOrderCustomerId();
|
|
4417
4435
|
const resolvedChannels = paramsList.map(params => this.getPriceQueryChannel(params.channel));
|
|
4418
4436
|
const authoritativeProducts = await this.resolveProductBookingPriceGroups(paramsList, currentOrderCustomerId);
|
|
4437
|
+
if (paramsList.some((params, index) => params.requireAuthoritativePrice && !authoritativeProducts[index])) {
|
|
4438
|
+
throw new Error('The current customer product price is unavailable. Please retry before paying.');
|
|
4439
|
+
}
|
|
4419
4440
|
const plans = paramsList.map((params, index) => {
|
|
4420
4441
|
if (!isPos) return null;
|
|
4421
4442
|
const product = authoritativeProducts[index];
|
|
@@ -305,6 +305,8 @@ export interface BaseSalesQuotationDurationConfig {
|
|
|
305
305
|
}
|
|
306
306
|
export interface BaseSalesCalculateProductBookingPriceParams {
|
|
307
307
|
product: Record<string, any>;
|
|
308
|
+
/** Fail closed when the current customer price cannot be resolved; no old-line fallback. */
|
|
309
|
+
requireAuthoritativePrice?: boolean;
|
|
308
310
|
booking?: {
|
|
309
311
|
start_date?: string;
|
|
310
312
|
start_time?: string;
|
|
@@ -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 | 2 | 1 |
|
|
345
|
+
weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
|
|
346
346
|
}[]>;
|
|
347
347
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
348
348
|
private getScheduleDataByIds;
|
|
@@ -32,6 +32,8 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
32
32
|
private orderCustomerDiscountRefreshCustomerId;
|
|
33
33
|
private orderCustomerDiscountRefreshTarget;
|
|
34
34
|
private orderCustomerPromotionRefreshInFlight;
|
|
35
|
+
private orderCustomerRefreshTask;
|
|
36
|
+
private orderCustomerRefreshRevision;
|
|
35
37
|
private orderCustomerContactRequest;
|
|
36
38
|
private readonly customerResolveRequests;
|
|
37
39
|
protected loadOpenDataInFlight: Promise<OpenDataConfig> | null;
|
|
@@ -283,6 +285,9 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
283
285
|
setOrderCustomer(customer: ICustomer | null, options?: {
|
|
284
286
|
source?: OrderCustomerChangePayload['source'];
|
|
285
287
|
}): void;
|
|
288
|
+
/** Shared by customer changes and an explicit retry; keep the selected customer/cart intact. */
|
|
289
|
+
private refreshMemberCartContext;
|
|
290
|
+
retryOrderCustomerRefresh(): Promise<void>;
|
|
286
291
|
private resetOrderCustomerContactInfo;
|
|
287
292
|
/** Explicit edits, including clearing the contact, must win over a pending default. */
|
|
288
293
|
updateTempOrderContactsInfo(contact: Record<string, any> | null): Record<string, any> | null;
|
|
@@ -321,6 +326,8 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
321
326
|
private buildOrderCustomerPayload;
|
|
322
327
|
protected refreshDiscountConfigAfterOrderCustomerChange(customerId: number | null): Promise<void>;
|
|
323
328
|
protected waitForOrderCustomerPromotionRefresh(): Promise<void>;
|
|
329
|
+
/** Wait before reading cart rows: member coupons can split or consolidate them. */
|
|
330
|
+
waitForOrderCustomerRefresh(): Promise<void>;
|
|
324
331
|
protected prepareProductPriceQueryContext(customerId?: number | string): Promise<void>;
|
|
325
332
|
protected preferAuthoritativeProductQueryPrice(): boolean;
|
|
326
333
|
/**
|
|
@@ -168,6 +168,9 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
168
168
|
orderCustomerDiscountRefreshCustomerId = null;
|
|
169
169
|
orderCustomerDiscountRefreshTarget = null;
|
|
170
170
|
orderCustomerPromotionRefreshInFlight = null;
|
|
171
|
+
// Retain the settled result too: a failed refresh must remain observable by checkout callers.
|
|
172
|
+
orderCustomerRefreshTask = Promise.resolve();
|
|
173
|
+
orderCustomerRefreshRevision = 0;
|
|
171
174
|
orderCustomerContactRequest = null;
|
|
172
175
|
customerResolveRequests = new Map();
|
|
173
176
|
loadOpenDataInFlight = null;
|
|
@@ -1084,13 +1087,17 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
1084
1087
|
}
|
|
1085
1088
|
return;
|
|
1086
1089
|
}
|
|
1090
|
+
const enableMemberCartConsistency = this.isMemberCartConsistencyEnabled();
|
|
1087
1091
|
const next = this.buildOrderCustomerPayload();
|
|
1088
1092
|
this.core.effects.emit(`${this.name}:onOrderCustomerChange`, next && options?.source ? {
|
|
1089
1093
|
...next,
|
|
1090
1094
|
source: options.source
|
|
1091
1095
|
} : next);
|
|
1092
|
-
|
|
1093
|
-
|
|
1096
|
+
if (enableMemberCartConsistency) {
|
|
1097
|
+
this.refreshMemberCartContext(patch.customer_id);
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
void this.refreshDiscountConfigAfterOrderCustomerChange(patch.customer_id);
|
|
1094
1101
|
const promotionRefreshTask = this.store.order.applyPromotion().then(() => undefined);
|
|
1095
1102
|
this.orderCustomerPromotionRefreshInFlight = promotionRefreshTask;
|
|
1096
1103
|
void promotionRefreshTask.then(() => {
|
|
@@ -1102,6 +1109,31 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
1102
1109
|
this.orderCustomerPromotionRefreshInFlight = null;
|
|
1103
1110
|
});
|
|
1104
1111
|
}
|
|
1112
|
+
|
|
1113
|
+
/** Shared by customer changes and an explicit retry; keep the selected customer/cart intact. */
|
|
1114
|
+
refreshMemberCartContext(customerId) {
|
|
1115
|
+
const revision = ++this.orderCustomerRefreshRevision;
|
|
1116
|
+
const orderKey = this.getCustomerContactOrderKey();
|
|
1117
|
+
const isCurrent = () => revision === this.orderCustomerRefreshRevision && this.getCustomerContactOrderKey() === orderKey && Number(this.store.order.getOrderCustomer()?.customer_id || 0) === Number(customerId || 0);
|
|
1118
|
+
const task = (async () => {
|
|
1119
|
+
if (customerId) await this.refreshDiscountConfigAfterOrderCustomerChange(customerId);else await this.loadDiscountConfig({
|
|
1120
|
+
force: true
|
|
1121
|
+
});
|
|
1122
|
+
if (isCurrent()) await this.store.order.applyPromotion();
|
|
1123
|
+
})();
|
|
1124
|
+
this.orderCustomerRefreshTask = task;
|
|
1125
|
+
this.orderCustomerPromotionRefreshInFlight = task;
|
|
1126
|
+
void task.catch(error => {
|
|
1127
|
+
if (isCurrent()) console.error('[BookingTicket] Member cart refresh failed', error);
|
|
1128
|
+
}).finally(() => {
|
|
1129
|
+
if (this.orderCustomerPromotionRefreshInFlight === task) this.orderCustomerPromotionRefreshInFlight = null;
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
async retryOrderCustomerRefresh() {
|
|
1133
|
+
if (!this.isMemberCartConsistencyEnabled()) return;
|
|
1134
|
+
this.refreshMemberCartContext(this.store.order.getOrderCustomer()?.customer_id ?? null);
|
|
1135
|
+
await this.waitForOrderCustomerRefresh();
|
|
1136
|
+
}
|
|
1105
1137
|
resetOrderCustomerContactInfo() {
|
|
1106
1138
|
this.orderCustomerContactRequest = null;
|
|
1107
1139
|
const order = this.getTempOrder();
|
|
@@ -1220,6 +1252,8 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
1220
1252
|
* 清空下单客户(协议字段 + snapshot)。
|
|
1221
1253
|
*/
|
|
1222
1254
|
clearOrderCustomer(options) {
|
|
1255
|
+
const enableMemberCartConsistency = this.isMemberCartConsistencyEnabled();
|
|
1256
|
+
const refreshRevision = enableMemberCartConsistency ? ++this.orderCustomerRefreshRevision : undefined;
|
|
1223
1257
|
this.orderCustomerContactRequest = null;
|
|
1224
1258
|
if (!options?.preserveContactInfo) this.resetOrderCustomerContactInfo();
|
|
1225
1259
|
if (!options?.preserveContactInfo) this.store.order.updateTempOrderContactsInfo(null);
|
|
@@ -1231,9 +1265,11 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
1231
1265
|
void discountModule?.setOriginalDiscountList?.([]);
|
|
1232
1266
|
void discountModule?.setDiscountList?.([]);
|
|
1233
1267
|
this.store.order.applyDiscount();
|
|
1234
|
-
|
|
1268
|
+
const customerOrderKey = enableMemberCartConsistency ? this.getCustomerContactOrderKey() : undefined;
|
|
1269
|
+
const refreshTask = this.store.order.recalculateSummary({
|
|
1235
1270
|
createIfMissing: true
|
|
1236
1271
|
}).then(() => {
|
|
1272
|
+
if (enableMemberCartConsistency && (this.orderCustomerRefreshRevision !== refreshRevision || this.getCustomerContactOrderKey() !== customerOrderKey)) return;
|
|
1237
1273
|
const tempOrder = this.store.order.ensureTempOrder();
|
|
1238
1274
|
this.store.order.persistTempOrder();
|
|
1239
1275
|
return this.effectsEmit('onDiscountApplied', {
|
|
@@ -1242,7 +1278,9 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
1242
1278
|
selectedDiscountList: tempOrder.discount_list || [],
|
|
1243
1279
|
tempOrder
|
|
1244
1280
|
});
|
|
1245
|
-
})
|
|
1281
|
+
});
|
|
1282
|
+
if (enableMemberCartConsistency) this.orderCustomerRefreshTask = refreshTask.then(() => undefined);
|
|
1283
|
+
void (enableMemberCartConsistency ? this.orderCustomerRefreshTask : refreshTask).catch(error => {
|
|
1246
1284
|
console.error('Failed to recalculate summary after clearing customer:', error);
|
|
1247
1285
|
});
|
|
1248
1286
|
this.core.effects.emit(`${this.name}:onOrderCustomerChange`, null);
|
|
@@ -1326,6 +1364,14 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
1326
1364
|
waitForOrderCustomerPromotionRefresh() {
|
|
1327
1365
|
return this.orderCustomerPromotionRefreshInFlight || Promise.resolve();
|
|
1328
1366
|
}
|
|
1367
|
+
|
|
1368
|
+
/** Wait before reading cart rows: member coupons can split or consolidate them. */
|
|
1369
|
+
async waitForOrderCustomerRefresh() {
|
|
1370
|
+
if (!this.isMemberCartConsistencyEnabled()) return;
|
|
1371
|
+
// Customer-change listeners run synchronously before setOrderCustomer assigns its task.
|
|
1372
|
+
await Promise.resolve();
|
|
1373
|
+
await this.orderCustomerRefreshTask;
|
|
1374
|
+
}
|
|
1329
1375
|
async prepareProductPriceQueryContext(customerId) {
|
|
1330
1376
|
// onOrderCustomerChange 的订阅回调会立即开始重报价,而客户 Wallet/优惠资产
|
|
1331
1377
|
// 在事件派发后才创建异步刷新任务。先让出一个微任务,确保能观察到该任务。
|
|
@@ -25,21 +25,18 @@ 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
|
-
|
|
30
|
-
|
|
28
|
+
status: string;
|
|
29
|
+
customer_id: number | null;
|
|
30
|
+
schedule_date: string;
|
|
31
|
+
business_code?: string | undefined;
|
|
31
32
|
order_id: number | null;
|
|
32
|
-
external_sale_number: string;
|
|
33
33
|
order_number: string | null;
|
|
34
34
|
shop_order_number: string | null;
|
|
35
35
|
shop_full_order_number: string | null;
|
|
36
36
|
type: string;
|
|
37
|
-
business_code?: string | undefined;
|
|
38
37
|
sales_channel: string;
|
|
39
38
|
order_sales_channel: string;
|
|
40
|
-
status: string;
|
|
41
39
|
shipping_status: string;
|
|
42
|
-
customer_id: number | null;
|
|
43
40
|
customer_name: string;
|
|
44
41
|
country_calling_code: string;
|
|
45
42
|
phone: string;
|
|
@@ -54,18 +51,21 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
|
|
|
54
51
|
deposit_amount: string;
|
|
55
52
|
shop_discount: string;
|
|
56
53
|
surcharge_fee: string;
|
|
54
|
+
note: string;
|
|
57
55
|
buzzer?: string | undefined;
|
|
58
56
|
delivery_type?: string | undefined;
|
|
59
57
|
table_number?: Record<string, any> | undefined;
|
|
60
|
-
schedule_date: string;
|
|
61
58
|
bookings: any[];
|
|
62
59
|
payments: any[];
|
|
63
|
-
refunds?: any[] | undefined;
|
|
64
60
|
surcharges: any[];
|
|
65
61
|
relation_forms: any[];
|
|
66
62
|
contacts: any[];
|
|
67
63
|
contacts_info: Record<string, any> | null;
|
|
68
64
|
holder: Record<string, any> | null;
|
|
65
|
+
metadata: Record<string, any>;
|
|
66
|
+
external_sale_number: string;
|
|
67
|
+
holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
|
|
68
|
+
refunds?: any[] | undefined;
|
|
69
69
|
order_meta_list?: import("../../../modules/Order/types").OrderMetaList | undefined;
|
|
70
70
|
};
|
|
71
71
|
export declare function describeChangedBookings(before: OrderTempOrder['bookings'], after: OrderTempOrder['bookings']): {
|
|
@@ -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
|
/**
|
|
@@ -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<void>;
|
|
58
59
|
/** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
|
|
59
60
|
clearOpenDataCache(): void;
|
|
60
61
|
destroy(): Promise<void>;
|
|
@@ -28,7 +28,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
28
28
|
const UNPAID_PAYMENT_STATUSES = new Set(['unpaid', 'partially_paid', 'payment_processing']);
|
|
29
29
|
const INVOICE_OPEN_DATA_SECTION_CODES = ['documents'];
|
|
30
30
|
const INVOICE_OPEN_DATA_CACHE_TTL = 5 * 60 * 1000;
|
|
31
|
-
|
|
32
31
|
/**
|
|
33
32
|
* Sales 解决方案基础骨架
|
|
34
33
|
*
|
|
@@ -287,6 +286,34 @@ class SalesImpl extends _BaseModule.BaseModule {
|
|
|
287
286
|
customToast: () => {}
|
|
288
287
|
});
|
|
289
288
|
}
|
|
289
|
+
async printCloudOrderInvoice(input) {
|
|
290
|
+
const orderId = input?.order_id;
|
|
291
|
+
const channel = typeof input?.channel === 'string' ? input.channel.trim() : '';
|
|
292
|
+
if (!channel) throw new Error('Cloud Invoice requires a channel');
|
|
293
|
+
const openData = this.invoiceOpenDataModule;
|
|
294
|
+
if (!openData) throw new Error('Cloud Invoice is not initialized');
|
|
295
|
+
const requestOptions = {
|
|
296
|
+
osServer: true,
|
|
297
|
+
customToast: () => {}
|
|
298
|
+
};
|
|
299
|
+
const lookup = await this.request.post('/shop/local/cloud-order-invoice/lookup', {
|
|
300
|
+
order_id: orderId
|
|
301
|
+
}, requestOptions);
|
|
302
|
+
if (lookup?.status !== true || lookup.code !== 200) {
|
|
303
|
+
throw new Error(lookup?.message || 'Cloud Invoice order lookup failed');
|
|
304
|
+
}
|
|
305
|
+
const businessCode = lookup.data?.business_code?.trim();
|
|
306
|
+
if (!businessCode) throw new Error('Cloud Invoice order has no business_code');
|
|
307
|
+
const settings = await openData.loadCloudInvoiceTemplate(`${businessCode}+${channel}`);
|
|
308
|
+
const result = await this.request.post('/shop/local/cloud-order-invoice/submit', {
|
|
309
|
+
order_id: orderId,
|
|
310
|
+
business_code: businessCode,
|
|
311
|
+
template_settings: settings
|
|
312
|
+
}, requestOptions);
|
|
313
|
+
if (result?.status !== true || result.code !== 200) {
|
|
314
|
+
throw new Error(result?.message || 'Cloud Invoice dispatch failed');
|
|
315
|
+
}
|
|
316
|
+
}
|
|
290
317
|
|
|
291
318
|
/** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
|
|
292
319
|
clearOpenDataCache() {
|