@pisell/pisellos 2.3.190 → 2.3.191
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/server/index.d.ts +3 -0
- package/dist/server/index.js +1100 -974
- package/dist/shared/receipt/small-ticket.js +33 -5
- package/lib/server/index.d.ts +3 -0
- package/lib/server/index.js +81 -4
- package/lib/shared/receipt/small-ticket.js +30 -5
- package/package.json +1 -1
|
@@ -103,6 +103,7 @@ var LABELS = {
|
|
|
103
103
|
cashReceived: 'Cash received',
|
|
104
104
|
changeDue: 'Change due',
|
|
105
105
|
eftpos: 'Eftpos',
|
|
106
|
+
creditCard: 'Credit card',
|
|
106
107
|
wallet: 'Wallet',
|
|
107
108
|
giftCard: 'Gift card',
|
|
108
109
|
pointCard: 'Point card',
|
|
@@ -149,6 +150,7 @@ var LABELS = {
|
|
|
149
150
|
cashReceived: '收取现金',
|
|
150
151
|
changeDue: '找零',
|
|
151
152
|
eftpos: '刷卡支付',
|
|
153
|
+
creditCard: '信用卡',
|
|
152
154
|
wallet: '钱包支付',
|
|
153
155
|
giftCard: '礼品卡',
|
|
154
156
|
pointCard: '积分卡',
|
|
@@ -195,6 +197,7 @@ var LABELS = {
|
|
|
195
197
|
cashReceived: '收取現金',
|
|
196
198
|
changeDue: '找零',
|
|
197
199
|
eftpos: '刷卡支付',
|
|
200
|
+
creditCard: '信用卡',
|
|
198
201
|
wallet: '錢包支付',
|
|
199
202
|
giftCard: '禮品卡',
|
|
200
203
|
pointCard: '積分卡',
|
|
@@ -239,6 +242,7 @@ var LABELS = {
|
|
|
239
242
|
asap: 'できるだけ早く',
|
|
240
243
|
cash: '現金',
|
|
241
244
|
eftpos: 'カード',
|
|
245
|
+
creditCard: 'クレジットカード',
|
|
242
246
|
wallet: 'ウォレット',
|
|
243
247
|
giftCard: 'ギフトカード',
|
|
244
248
|
pointCard: 'ポイントカード',
|
|
@@ -284,6 +288,7 @@ var LABELS = {
|
|
|
284
288
|
asap: 'Assim que possível',
|
|
285
289
|
cash: 'Dinheiro',
|
|
286
290
|
eftpos: 'Cartão',
|
|
291
|
+
creditCard: 'Cartão de crédito',
|
|
287
292
|
wallet: 'Carteira',
|
|
288
293
|
giftCard: 'Cartão-presente',
|
|
289
294
|
pointCard: 'Cartão de pontos',
|
|
@@ -2639,12 +2644,33 @@ function appendMaskedCardCode(name, code) {
|
|
|
2639
2644
|
function trimDecimal(value) {
|
|
2640
2645
|
return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
|
|
2641
2646
|
}
|
|
2647
|
+
function getLocalizedPaymentName(value, locale) {
|
|
2648
|
+
if (typeof value === 'string') return value.trim();
|
|
2649
|
+
if (!value || _typeof(value) !== 'object' || Array.isArray(value)) return '';
|
|
2650
|
+
var candidates = [value[locale], value[locale.replace('_', '-')], value[locale.replace('-', '_')], value.original, value.auto, value.default, value.en];
|
|
2651
|
+
for (var _i24 = 0, _candidates2 = candidates; _i24 < _candidates2.length; _i24++) {
|
|
2652
|
+
var candidate = _candidates2[_i24];
|
|
2653
|
+
if (typeof candidate === 'string' && candidate.trim()) return candidate.trim();
|
|
2654
|
+
}
|
|
2655
|
+
return '';
|
|
2656
|
+
}
|
|
2657
|
+
function getExplicitPaymentName(payment, locale) {
|
|
2658
|
+
var _payment$metadata4;
|
|
2659
|
+
// Cloud order snapshots retain the localized name in metadata after reload.
|
|
2660
|
+
var candidates = [payment.name, payment.title, payment.payment_method_name, payment.method_name, (_payment$metadata4 = payment.metadata) === null || _payment$metadata4 === void 0 ? void 0 : _payment$metadata4.custom_payment_name];
|
|
2661
|
+
for (var _i25 = 0, _candidates3 = candidates; _i25 < _candidates3.length; _i25++) {
|
|
2662
|
+
var candidate = _candidates3[_i25];
|
|
2663
|
+
var name = getLocalizedPaymentName(candidate, locale);
|
|
2664
|
+
if (name) return name;
|
|
2665
|
+
}
|
|
2666
|
+
return '';
|
|
2667
|
+
}
|
|
2642
2668
|
function getFundRecordPaymentName(payment, locale) {
|
|
2643
2669
|
var fundRecord = getFundRecord(payment);
|
|
2644
2670
|
if (!fundRecord) return '';
|
|
2645
|
-
var name =
|
|
2671
|
+
var name = getLocalizedPaymentName(fundRecord.wallet_pass_name, locale);
|
|
2646
2672
|
if (!name && !maskMachineCode(fundRecord.code)) return '';
|
|
2647
|
-
var fallbackName =
|
|
2673
|
+
var fallbackName = getExplicitPaymentName(payment, locale) || getLocalizedPaymentName(payment.code, locale);
|
|
2648
2674
|
return appendMaskedCardCode(name || fallbackName, fundRecord.code);
|
|
2649
2675
|
}
|
|
2650
2676
|
function appendMachineCodeToName(name, payment) {
|
|
@@ -2654,13 +2680,15 @@ function appendMachineCodeToName(name, payment) {
|
|
|
2654
2680
|
function paymentMethodName(payment, locale) {
|
|
2655
2681
|
var fundRecordName = getFundRecordPaymentName(payment, locale);
|
|
2656
2682
|
if (fundRecordName) return fundRecordName;
|
|
2657
|
-
var
|
|
2658
|
-
if (
|
|
2683
|
+
var name = getExplicitPaymentName(payment, locale);
|
|
2684
|
+
if (name) return appendMachineCodeToName(name, payment);
|
|
2659
2685
|
var code = stringify(payment.code || payment.type || payment.payment_method || payment.method).toLowerCase();
|
|
2660
2686
|
if (code.includes('cash')) return label(locale, 'cash');
|
|
2661
|
-
if (code.includes('eftpos')
|
|
2687
|
+
if (code.includes('eftpos')) return label(locale, 'eftpos');
|
|
2662
2688
|
if (code.includes('wallet')) return label(locale, 'wallet');
|
|
2663
2689
|
if (code.includes('gift')) return label(locale, 'giftCard');
|
|
2690
|
+
if (code === 'credit_card' || code.startsWith('credit_card_')) return label(locale, 'creditCard');
|
|
2691
|
+
if (code.includes('card')) return label(locale, 'eftpos');
|
|
2664
2692
|
return stringify(payment.code || payment.type || payment.payment_method || payment.method);
|
|
2665
2693
|
}
|
|
2666
2694
|
function getSummary(order) {
|
package/lib/server/index.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ declare class Server {
|
|
|
64
64
|
private salesSearchSubscribers;
|
|
65
65
|
private deviceTaskActionsRegistered;
|
|
66
66
|
private localPaymentUpdateQueues;
|
|
67
|
+
private paymentIdentityRefreshes;
|
|
67
68
|
private floorPlanQuerySubscribers;
|
|
68
69
|
private moduleRegistry;
|
|
69
70
|
constructor(core: PisellCore);
|
|
@@ -133,6 +134,8 @@ declare class Server {
|
|
|
133
134
|
private resolveKioskCheckoutOperatorId;
|
|
134
135
|
private mergeCheckoutSyncPayments;
|
|
135
136
|
private persistSyncedCheckoutOrder;
|
|
137
|
+
private hasPaidPaymentWithoutId;
|
|
138
|
+
private refreshMissingPaymentIds;
|
|
136
139
|
/**
|
|
137
140
|
* 将普通层 QuotationModule 的报价单计算能力桥接到 Server Products 模块。
|
|
138
141
|
*/
|
package/lib/server/index.js
CHANGED
|
@@ -123,6 +123,7 @@ class Server {
|
|
|
123
123
|
salesSearchSubscribers = new Map();
|
|
124
124
|
deviceTaskActionsRegistered = false;
|
|
125
125
|
localPaymentUpdateQueues = new Map();
|
|
126
|
+
paymentIdentityRefreshes = new Map();
|
|
126
127
|
floorPlanQuerySubscribers = new Map();
|
|
127
128
|
|
|
128
129
|
// 模块注册表 - 定义所有可用的模块配置
|
|
@@ -873,8 +874,52 @@ class Server {
|
|
|
873
874
|
order_id: fresh?.order_id
|
|
874
875
|
});
|
|
875
876
|
}
|
|
877
|
+
if (syncedOrder) {
|
|
878
|
+
// 不占用 sync_sales 的执行超时:慢速补取不能让已成功的 checkout 被再次提交。
|
|
879
|
+
void this.refreshMissingPaymentIds(syncedOrder, title).catch(error => {
|
|
880
|
+
this.logWarning(`${title}: 后台补齐付款 ID 失败`, {
|
|
881
|
+
order_id: syncedOrder?.order_id,
|
|
882
|
+
error: this.getUnknownErrorMessage(error)
|
|
883
|
+
});
|
|
884
|
+
});
|
|
885
|
+
}
|
|
876
886
|
return syncedOrder;
|
|
877
887
|
}
|
|
888
|
+
hasPaidPaymentWithoutId(order) {
|
|
889
|
+
return (order?.payments || []).some(payment => {
|
|
890
|
+
const paymentId = payment.order_payment_id ?? payment.id;
|
|
891
|
+
return payment.status === 'paid' && (paymentId === undefined || paymentId === null || String(paymentId).trim() === '');
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
async refreshMissingPaymentIds(order, title) {
|
|
895
|
+
if (!this.hasPaidPaymentWithoutId(order) || !(Number(order.order_id) > 0) || Number(order.need_sync || 0) === 1 || Number(order.is_draft_order || 0) === 1) {
|
|
896
|
+
return order;
|
|
897
|
+
}
|
|
898
|
+
const key = String(order.order_id);
|
|
899
|
+
let refresh = this.paymentIdentityRefreshes.get(key);
|
|
900
|
+
if (!refresh) {
|
|
901
|
+
// checkout 已成功,只补取付款身份;补取失败不能让 sync_sales 重试 checkout。
|
|
902
|
+
refresh = this.fetchAndPersistSalesOrderByLookup(key, {
|
|
903
|
+
forceRemote: true
|
|
904
|
+
}, `${title}.paymentIdentityRefresh`, order);
|
|
905
|
+
this.paymentIdentityRefreshes.set(key, refresh);
|
|
906
|
+
}
|
|
907
|
+
try {
|
|
908
|
+
const result = await refresh;
|
|
909
|
+
const refreshedOrder = result.order || this.order?.getLocalOrderFromMemoryByLookup?.(key) || order;
|
|
910
|
+
if (this.hasPaidPaymentWithoutId(refreshedOrder)) {
|
|
911
|
+
this.logWarning(`${title}: 付款 ID 尚未补齐,下次读取详情重试`, {
|
|
912
|
+
order_id: order.order_id,
|
|
913
|
+
code: result.code
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
return refreshedOrder;
|
|
917
|
+
} finally {
|
|
918
|
+
if (this.paymentIdentityRefreshes.get(key) === refresh) {
|
|
919
|
+
this.paymentIdentityRefreshes.delete(key);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
878
923
|
|
|
879
924
|
/**
|
|
880
925
|
* 将普通层 QuotationModule 的报价单计算能力桥接到 Server Products 模块。
|
|
@@ -5096,7 +5141,7 @@ class Server {
|
|
|
5096
5141
|
const code = typeof value === 'number' ? value : Number(value);
|
|
5097
5142
|
return Number.isFinite(code) ? code : 500;
|
|
5098
5143
|
}
|
|
5099
|
-
async fetchAndPersistSalesOrderByLookup(lookup, data, title) {
|
|
5144
|
+
async fetchAndPersistSalesOrderByLookup(lookup, data, title, paymentIdentityOrder) {
|
|
5100
5145
|
if (!this.order?.getLocalOrderByLookup || !this.order?.upsertOrdersFromRemote) {
|
|
5101
5146
|
this.logError(`${title}: Order 模块未注册`);
|
|
5102
5147
|
return {
|
|
@@ -5150,13 +5195,44 @@ class Server {
|
|
|
5150
5195
|
};
|
|
5151
5196
|
}
|
|
5152
5197
|
const localBeforeRefresh = this.order.getLocalOrderFromMemoryByLookup?.(lookup) || (this.shouldForceRemoteSalesDetail(data) ? await this.order.getLocalOrderByLookup(lookup) : null);
|
|
5198
|
+
let orderToPersist = fresh;
|
|
5199
|
+
if (paymentIdentityOrder) {
|
|
5200
|
+
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)) {
|
|
5201
|
+
throw new Error('远端订单身份不匹配或缺少付款明细,暂不补齐付款 ID');
|
|
5202
|
+
}
|
|
5203
|
+
// 请求期间可能又产生本地改动,不能用这次补取清除待同步状态。
|
|
5204
|
+
if (!localBeforeRefresh || Number(localBeforeRefresh.need_sync || 0) === 1 || Number(localBeforeRefresh.is_draft_order || 0) === 1) {
|
|
5205
|
+
return {
|
|
5206
|
+
code: 200,
|
|
5207
|
+
message: '',
|
|
5208
|
+
order: localBeforeRefresh || paymentIdentityOrder
|
|
5209
|
+
};
|
|
5210
|
+
}
|
|
5211
|
+
const remotePayments = fresh.payments;
|
|
5212
|
+
const paidPayments = (localBeforeRefresh.payments || []).filter(payment => payment.status === 'paid');
|
|
5213
|
+
const paymentIdsComplete = paidPayments.every(payment => {
|
|
5214
|
+
const localKeys = new Set((0, _paymentUtils.getOrderPaymentIdentityKeys)(payment));
|
|
5215
|
+
const matches = remotePayments.filter(remotePayment => (0, _paymentUtils.getOrderPaymentIdentityKeys)(remotePayment).some(key => localKeys.has(key)));
|
|
5216
|
+
const paymentId = matches[0]?.order_payment_id ?? matches[0]?.id;
|
|
5217
|
+
return matches.length === 1 && paymentId !== undefined && paymentId !== null && String(paymentId).trim() !== '';
|
|
5218
|
+
});
|
|
5219
|
+
if (!paymentIdsComplete) {
|
|
5220
|
+
throw new Error('远端付款 ID 尚未齐全或付款身份匹配不唯一,保留本地付款等待重试');
|
|
5221
|
+
}
|
|
5222
|
+
orderToPersist = {
|
|
5223
|
+
...fresh,
|
|
5224
|
+
payments: (0, _paymentUtils.mergeOrderPaymentListsByIdentity)(localBeforeRefresh.payments, remotePayments, {
|
|
5225
|
+
preserveUnmatchedExisting: true
|
|
5226
|
+
})
|
|
5227
|
+
};
|
|
5228
|
+
}
|
|
5153
5229
|
if ((0, _localEftposState.requiresLocalPaymentRefresh)(localBeforeRefresh)) {
|
|
5154
5230
|
if (String(fresh.order_id) !== String(localBeforeRefresh.order_id)) {
|
|
5155
5231
|
throw new Error('远端订单身份不匹配,请重新刷新');
|
|
5156
5232
|
}
|
|
5157
|
-
await this.order.completeLocalPaymentRefresh(
|
|
5233
|
+
await this.order.completeLocalPaymentRefresh(orderToPersist);
|
|
5158
5234
|
} else {
|
|
5159
|
-
await this.order.upsertOrdersFromRemote([
|
|
5235
|
+
await this.order.upsertOrdersFromRemote([orderToPersist]);
|
|
5160
5236
|
}
|
|
5161
5237
|
let savedOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
5162
5238
|
if (!savedOrder && fresh.order_id !== undefined && fresh.order_id !== null && String(fresh.order_id) !== String(lookup)) {
|
|
@@ -5251,7 +5327,8 @@ class Server {
|
|
|
5251
5327
|
if (!this.shouldForceRemoteSalesDetail(data)) {
|
|
5252
5328
|
const localOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
5253
5329
|
if (localOrder) {
|
|
5254
|
-
const
|
|
5330
|
+
const refreshedOrder = await this.refreshMissingPaymentIds(localOrder, 'handleOrderSalesDetail');
|
|
5331
|
+
const enrichedOrder = await this.withSalesDetailProductSnapshots(refreshedOrder);
|
|
5255
5332
|
this.logInfo('handleOrderSalesDetail: 命中本地订单', {
|
|
5256
5333
|
lookup
|
|
5257
5334
|
});
|
|
@@ -85,6 +85,7 @@ const LABELS = {
|
|
|
85
85
|
cashReceived: 'Cash received',
|
|
86
86
|
changeDue: 'Change due',
|
|
87
87
|
eftpos: 'Eftpos',
|
|
88
|
+
creditCard: 'Credit card',
|
|
88
89
|
wallet: 'Wallet',
|
|
89
90
|
giftCard: 'Gift card',
|
|
90
91
|
pointCard: 'Point card',
|
|
@@ -131,6 +132,7 @@ const LABELS = {
|
|
|
131
132
|
cashReceived: '收取现金',
|
|
132
133
|
changeDue: '找零',
|
|
133
134
|
eftpos: '刷卡支付',
|
|
135
|
+
creditCard: '信用卡',
|
|
134
136
|
wallet: '钱包支付',
|
|
135
137
|
giftCard: '礼品卡',
|
|
136
138
|
pointCard: '积分卡',
|
|
@@ -177,6 +179,7 @@ const LABELS = {
|
|
|
177
179
|
cashReceived: '收取現金',
|
|
178
180
|
changeDue: '找零',
|
|
179
181
|
eftpos: '刷卡支付',
|
|
182
|
+
creditCard: '信用卡',
|
|
180
183
|
wallet: '錢包支付',
|
|
181
184
|
giftCard: '禮品卡',
|
|
182
185
|
pointCard: '積分卡',
|
|
@@ -221,6 +224,7 @@ const LABELS = {
|
|
|
221
224
|
asap: 'できるだけ早く',
|
|
222
225
|
cash: '現金',
|
|
223
226
|
eftpos: 'カード',
|
|
227
|
+
creditCard: 'クレジットカード',
|
|
224
228
|
wallet: 'ウォレット',
|
|
225
229
|
giftCard: 'ギフトカード',
|
|
226
230
|
pointCard: 'ポイントカード',
|
|
@@ -266,6 +270,7 @@ const LABELS = {
|
|
|
266
270
|
asap: 'Assim que possível',
|
|
267
271
|
cash: 'Dinheiro',
|
|
268
272
|
eftpos: 'Cartão',
|
|
273
|
+
creditCard: 'Cartão de crédito',
|
|
269
274
|
wallet: 'Carteira',
|
|
270
275
|
giftCard: 'Cartão-presente',
|
|
271
276
|
pointCard: 'Cartão de pontos',
|
|
@@ -2438,12 +2443,30 @@ function appendMaskedCardCode(name, code) {
|
|
|
2438
2443
|
function trimDecimal(value) {
|
|
2439
2444
|
return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
|
|
2440
2445
|
}
|
|
2446
|
+
function getLocalizedPaymentName(value, locale) {
|
|
2447
|
+
if (typeof value === 'string') return value.trim();
|
|
2448
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return '';
|
|
2449
|
+
const candidates = [value[locale], value[locale.replace('_', '-')], value[locale.replace('-', '_')], value.original, value.auto, value.default, value.en];
|
|
2450
|
+
for (const candidate of candidates) {
|
|
2451
|
+
if (typeof candidate === 'string' && candidate.trim()) return candidate.trim();
|
|
2452
|
+
}
|
|
2453
|
+
return '';
|
|
2454
|
+
}
|
|
2455
|
+
function getExplicitPaymentName(payment, locale) {
|
|
2456
|
+
// Cloud order snapshots retain the localized name in metadata after reload.
|
|
2457
|
+
const candidates = [payment.name, payment.title, payment.payment_method_name, payment.method_name, payment.metadata?.custom_payment_name];
|
|
2458
|
+
for (const candidate of candidates) {
|
|
2459
|
+
const name = getLocalizedPaymentName(candidate, locale);
|
|
2460
|
+
if (name) return name;
|
|
2461
|
+
}
|
|
2462
|
+
return '';
|
|
2463
|
+
}
|
|
2441
2464
|
function getFundRecordPaymentName(payment, locale) {
|
|
2442
2465
|
const fundRecord = getFundRecord(payment);
|
|
2443
2466
|
if (!fundRecord) return '';
|
|
2444
|
-
const name =
|
|
2467
|
+
const name = getLocalizedPaymentName(fundRecord.wallet_pass_name, locale);
|
|
2445
2468
|
if (!name && !maskMachineCode(fundRecord.code)) return '';
|
|
2446
|
-
const fallbackName =
|
|
2469
|
+
const fallbackName = getExplicitPaymentName(payment, locale) || getLocalizedPaymentName(payment.code, locale);
|
|
2447
2470
|
return appendMaskedCardCode(name || fallbackName, fundRecord.code);
|
|
2448
2471
|
}
|
|
2449
2472
|
function appendMachineCodeToName(name, payment) {
|
|
@@ -2453,13 +2476,15 @@ function appendMachineCodeToName(name, payment) {
|
|
|
2453
2476
|
function paymentMethodName(payment, locale) {
|
|
2454
2477
|
const fundRecordName = getFundRecordPaymentName(payment, locale);
|
|
2455
2478
|
if (fundRecordName) return fundRecordName;
|
|
2456
|
-
const
|
|
2457
|
-
if (
|
|
2479
|
+
const name = getExplicitPaymentName(payment, locale);
|
|
2480
|
+
if (name) return appendMachineCodeToName(name, payment);
|
|
2458
2481
|
const code = stringify(payment.code || payment.type || payment.payment_method || payment.method).toLowerCase();
|
|
2459
2482
|
if (code.includes('cash')) return label(locale, 'cash');
|
|
2460
|
-
if (code.includes('eftpos')
|
|
2483
|
+
if (code.includes('eftpos')) return label(locale, 'eftpos');
|
|
2461
2484
|
if (code.includes('wallet')) return label(locale, 'wallet');
|
|
2462
2485
|
if (code.includes('gift')) return label(locale, 'giftCard');
|
|
2486
|
+
if (code === 'credit_card' || code.startsWith('credit_card_')) return label(locale, 'creditCard');
|
|
2487
|
+
if (code.includes('card')) return label(locale, 'eftpos');
|
|
2463
2488
|
return stringify(payment.code || payment.type || payment.payment_method || payment.method);
|
|
2464
2489
|
}
|
|
2465
2490
|
function getSummary(order) {
|