@pisell/pisellos 2.2.323 → 2.2.325
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inventory/index.d.ts +92 -0
- package/dist/inventory/index.js +509 -0
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/BookingContext/index.d.ts +2 -2
- package/dist/modules/BookingContext/index.js +55 -25
- package/dist/modules/BookingContext/types.d.ts +2 -0
- package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
- package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
- package/dist/modules/BookingContext/utils/index.d.ts +1 -0
- package/dist/modules/BookingContext/utils/index.js +1 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +20 -1
- package/dist/modules/BookingContext/utils/productExtend.js +122 -29
- package/dist/modules/Date/index.d.ts +1 -1
- package/dist/modules/Date/index.js +60 -14
- package/dist/modules/Date/types.d.ts +5 -0
- package/dist/modules/Discount/index.js +1 -0
- package/dist/modules/OpenData/index.d.ts +1 -0
- package/dist/modules/OpenData/index.js +1 -0
- package/dist/modules/OpenData/salesSettings.d.ts +32 -0
- package/dist/modules/OpenData/salesSettings.js +80 -0
- package/dist/modules/OpenData/types.d.ts +16 -0
- package/dist/modules/OpenData/utils.d.ts +1 -1
- package/dist/modules/OpenData/utils.js +3 -2
- package/dist/modules/Order/index.d.ts +55 -12
- package/dist/modules/Order/index.js +2699 -1411
- package/dist/modules/Order/types.d.ts +43 -5
- package/dist/modules/Order/types.js +4 -0
- package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
- package/dist/modules/Order/unpaidAmountGap.js +72 -0
- package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
- package/dist/modules/Order/utils/productVoucherGroups.d.ts +15 -0
- package/dist/modules/Order/utils/productVoucherGroups.js +115 -0
- package/dist/modules/Order/utils.d.ts +3 -1
- package/dist/modules/Order/utils.js +6 -2
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/clientDataVariants.js +6 -2
- package/dist/modules/ProductList/index.d.ts +2 -0
- package/dist/modules/ProductList/index.js +161 -51
- package/dist/modules/ResourcePlanner/planner.js +58 -2
- package/dist/modules/ResourcePlanner/types.d.ts +13 -0
- package/dist/modules/Rules/index.d.ts +2 -0
- package/dist/modules/Rules/index.js +58 -39
- package/dist/modules/Schedule/index.d.ts +7 -1
- package/dist/modules/Schedule/index.js +155 -39
- package/dist/modules/Schedule/types.d.ts +2 -0
- package/dist/modules/bookingReadValidation.d.ts +6 -0
- package/dist/modules/bookingReadValidation.js +72 -0
- package/dist/plugins/request.d.ts +2 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +1458 -1166
- package/dist/server/modules/order/index.js +2 -1
- package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
- package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
- package/dist/shared/receipt/small-ticket.d.ts +4 -0
- package/dist/shared/receipt/small-ticket.js +70 -12
- package/dist/solution/BaseSales/index.d.ts +39 -5
- package/dist/solution/BaseSales/index.js +1828 -1462
- package/dist/solution/BaseSales/types.d.ts +1 -0
- package/dist/solution/BaseSales/types.js +1 -0
- package/dist/solution/BookingByStep/index.d.ts +16 -2
- package/dist/solution/BookingByStep/index.js +676 -361
- package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/dist/solution/BookingByStep/utils/resources.js +117 -76
- package/dist/solution/BookingTicket/index.d.ts +15 -3
- package/dist/solution/BookingTicket/index.js +249 -135
- package/dist/solution/BookingTicket/types.d.ts +14 -2
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
- package/dist/solution/BookingTicket/utils/addProductDecision.js +39 -11
- package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
- package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +88 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
- package/dist/solution/OrderInvoicePreview/index.js +14 -8
- package/dist/solution/ScanOrder/index.d.ts +2 -0
- package/dist/solution/ScanOrder/index.js +166 -67
- package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
- package/dist/solution/ScanOrder/menuAvailability.js +363 -0
- package/dist/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
- package/dist/solution/UnifiedBookingSales/catalogQueryBatch.js +202 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +96 -4
- package/dist/solution/UnifiedBookingSales/index.js +3374 -1177
- package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
- package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.js +4 -0
- package/dist/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
- package/dist/solution/UnifiedBookingSales/salesSettings.js +81 -0
- package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
- package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +271 -0
- package/dist/solution/UnifiedBookingSales/types.d.ts +71 -2
- package/dist/solution/UnifiedBookingSales/types.js +7 -1
- package/dist/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
- package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +283 -0
- package/dist/utils/platform.d.ts +2 -0
- package/dist/utils/platform.js +6 -0
- package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
- package/dist/utils/pos-receipt-auto-print.js +14 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +12 -0
- package/lib/inventory/index.d.ts +92 -0
- package/lib/inventory/index.js +287 -0
- package/lib/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/BookingContext/index.d.ts +2 -2
- package/lib/modules/BookingContext/index.js +42 -10
- package/lib/modules/BookingContext/types.d.ts +2 -0
- package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
- package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
- package/lib/modules/BookingContext/utils/index.d.ts +1 -0
- package/lib/modules/BookingContext/utils/index.js +11 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +20 -1
- package/lib/modules/BookingContext/utils/productExtend.js +96 -7
- package/lib/modules/Date/index.d.ts +1 -1
- package/lib/modules/Date/index.js +28 -5
- package/lib/modules/Date/types.d.ts +5 -0
- package/lib/modules/Discount/index.js +1 -0
- package/lib/modules/OpenData/index.d.ts +1 -0
- package/lib/modules/OpenData/index.js +12 -0
- package/lib/modules/OpenData/salesSettings.d.ts +32 -0
- package/lib/modules/OpenData/salesSettings.js +70 -0
- package/lib/modules/OpenData/types.d.ts +16 -0
- package/lib/modules/OpenData/utils.d.ts +1 -1
- package/lib/modules/OpenData/utils.js +3 -2
- package/lib/modules/Order/index.d.ts +55 -12
- package/lib/modules/Order/index.js +659 -80
- package/lib/modules/Order/types.d.ts +43 -5
- package/lib/modules/Order/types.js +2 -0
- package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
- package/lib/modules/Order/unpaidAmountGap.js +60 -0
- package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
- package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
- package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
- package/lib/modules/Order/utils.d.ts +3 -1
- package/lib/modules/Order/utils.js +6 -2
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/ProductList/clientDataVariants.js +6 -2
- package/lib/modules/ProductList/index.d.ts +2 -0
- package/lib/modules/ProductList/index.js +74 -0
- package/lib/modules/ResourcePlanner/planner.js +52 -1
- package/lib/modules/ResourcePlanner/types.d.ts +13 -0
- package/lib/modules/Rules/index.d.ts +2 -0
- package/lib/modules/Rules/index.js +25 -9
- package/lib/modules/Schedule/index.d.ts +7 -1
- package/lib/modules/Schedule/index.js +68 -4
- package/lib/modules/Schedule/types.d.ts +2 -0
- package/lib/modules/bookingReadValidation.d.ts +6 -0
- package/lib/modules/bookingReadValidation.js +56 -0
- package/lib/plugins/request.d.ts +2 -0
- package/lib/server/index.d.ts +8 -0
- package/lib/server/index.js +194 -19
- package/lib/server/modules/order/index.js +2 -1
- package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
- package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
- package/lib/shared/receipt/small-ticket.d.ts +4 -0
- package/lib/shared/receipt/small-ticket.js +63 -8
- package/lib/solution/BaseSales/index.d.ts +39 -5
- package/lib/solution/BaseSales/index.js +212 -18
- package/lib/solution/BaseSales/types.d.ts +1 -0
- package/lib/solution/BaseSales/types.js +1 -0
- package/lib/solution/BookingByStep/index.d.ts +16 -2
- package/lib/solution/BookingByStep/index.js +222 -14
- package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/lib/solution/BookingByStep/utils/resources.js +25 -15
- package/lib/solution/BookingTicket/index.d.ts +15 -3
- package/lib/solution/BookingTicket/index.js +47 -4
- package/lib/solution/BookingTicket/types.d.ts +14 -2
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
- package/lib/solution/BookingTicket/utils/addProductDecision.js +37 -6
- package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
- package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +54 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
- package/lib/solution/OrderInvoicePreview/index.js +7 -1
- package/lib/solution/ScanOrder/index.d.ts +2 -0
- package/lib/solution/ScanOrder/index.js +72 -2
- package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
- package/lib/solution/ScanOrder/menuAvailability.js +203 -0
- package/lib/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
- package/lib/solution/UnifiedBookingSales/catalogQueryBatch.js +109 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +96 -4
- package/lib/solution/UnifiedBookingSales/index.js +1316 -73
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +2 -0
- package/lib/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
- package/lib/solution/UnifiedBookingSales/salesSettings.js +72 -0
- package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
- package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +199 -0
- package/lib/solution/UnifiedBookingSales/types.d.ts +71 -2
- package/lib/solution/UnifiedBookingSales/types.js +4 -1
- package/lib/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
- package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +155 -0
- package/lib/utils/platform.d.ts +2 -0
- package/lib/utils/platform.js +7 -0
- package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
- package/lib/utils/pos-receipt-auto-print.js +13 -0
- package/package.json +1 -1
package/lib/server/index.js
CHANGED
|
@@ -33,6 +33,7 @@ var _paymentUtils = require("../modules/Order/payment-utils");
|
|
|
33
33
|
var _salesNotes = require("../modules/Order/salesNotes");
|
|
34
34
|
var _orderCollectionIdentity = require("../modules/Order/utils/orderCollectionIdentity");
|
|
35
35
|
var _osPrivatePayload = require("../utils/os-private-payload");
|
|
36
|
+
var _posReceiptAutoPrint = require("../utils/pos-receipt-auto-print");
|
|
36
37
|
var _OpenData = require("../modules/OpenData");
|
|
37
38
|
var _modules = require("./modules");
|
|
38
39
|
Object.keys(_modules).forEach(function (key) {
|
|
@@ -123,6 +124,8 @@ class Server {
|
|
|
123
124
|
salesSearchSubscribers = new Map();
|
|
124
125
|
deviceTaskActionsRegistered = false;
|
|
125
126
|
localPaymentUpdateQueues = new Map();
|
|
127
|
+
paymentIdentityRefreshes = new Map();
|
|
128
|
+
receiptFulfillmentConfigInFlight = new Map();
|
|
126
129
|
floorPlanQuerySubscribers = new Map();
|
|
127
130
|
|
|
128
131
|
// 模块注册表 - 定义所有可用的模块配置
|
|
@@ -873,8 +876,52 @@ class Server {
|
|
|
873
876
|
order_id: fresh?.order_id
|
|
874
877
|
});
|
|
875
878
|
}
|
|
879
|
+
if (syncedOrder) {
|
|
880
|
+
// 不占用 sync_sales 的执行超时:慢速补取不能让已成功的 checkout 被再次提交。
|
|
881
|
+
void this.refreshMissingPaymentIds(syncedOrder, title).catch(error => {
|
|
882
|
+
this.logWarning(`${title}: 后台补齐付款 ID 失败`, {
|
|
883
|
+
order_id: syncedOrder?.order_id,
|
|
884
|
+
error: this.getUnknownErrorMessage(error)
|
|
885
|
+
});
|
|
886
|
+
});
|
|
887
|
+
}
|
|
876
888
|
return syncedOrder;
|
|
877
889
|
}
|
|
890
|
+
hasPaidPaymentWithoutId(order) {
|
|
891
|
+
return (order?.payments || []).some(payment => {
|
|
892
|
+
const paymentId = payment.order_payment_id ?? payment.id;
|
|
893
|
+
return payment.status === 'paid' && (paymentId === undefined || paymentId === null || String(paymentId).trim() === '');
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
async refreshMissingPaymentIds(order, title) {
|
|
897
|
+
if (!this.hasPaidPaymentWithoutId(order) || !(Number(order.order_id) > 0) || Number(order.need_sync || 0) === 1 || Number(order.is_draft_order || 0) === 1) {
|
|
898
|
+
return order;
|
|
899
|
+
}
|
|
900
|
+
const key = String(order.order_id);
|
|
901
|
+
let refresh = this.paymentIdentityRefreshes.get(key);
|
|
902
|
+
if (!refresh) {
|
|
903
|
+
// checkout 已成功,只补取付款身份;补取失败不能让 sync_sales 重试 checkout。
|
|
904
|
+
refresh = this.fetchAndPersistSalesOrderByLookup(key, {
|
|
905
|
+
forceRemote: true
|
|
906
|
+
}, `${title}.paymentIdentityRefresh`, order);
|
|
907
|
+
this.paymentIdentityRefreshes.set(key, refresh);
|
|
908
|
+
}
|
|
909
|
+
try {
|
|
910
|
+
const result = await refresh;
|
|
911
|
+
const refreshedOrder = result.order || this.order?.getLocalOrderFromMemoryByLookup?.(key) || order;
|
|
912
|
+
if (this.hasPaidPaymentWithoutId(refreshedOrder)) {
|
|
913
|
+
this.logWarning(`${title}: 付款 ID 尚未补齐,下次读取详情重试`, {
|
|
914
|
+
order_id: order.order_id,
|
|
915
|
+
code: result.code
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
return refreshedOrder;
|
|
919
|
+
} finally {
|
|
920
|
+
if (this.paymentIdentityRefreshes.get(key) === refresh) {
|
|
921
|
+
this.paymentIdentityRefreshes.delete(key);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
878
925
|
|
|
879
926
|
/**
|
|
880
927
|
* 将普通层 QuotationModule 的报价单计算能力桥接到 Server Products 模块。
|
|
@@ -1685,6 +1732,7 @@ class Server {
|
|
|
1685
1732
|
customer_id,
|
|
1686
1733
|
ids,
|
|
1687
1734
|
extension_type,
|
|
1735
|
+
application_code,
|
|
1688
1736
|
strategy_context
|
|
1689
1737
|
} = data;
|
|
1690
1738
|
const {
|
|
@@ -1719,6 +1767,7 @@ class Server {
|
|
|
1719
1767
|
schedule_datetime,
|
|
1720
1768
|
customer_id,
|
|
1721
1769
|
extension_type,
|
|
1770
|
+
application_code,
|
|
1722
1771
|
strategy_context
|
|
1723
1772
|
}
|
|
1724
1773
|
});
|
|
@@ -1734,6 +1783,7 @@ class Server {
|
|
|
1734
1783
|
schedule_datetime,
|
|
1735
1784
|
customer_id,
|
|
1736
1785
|
extension_type,
|
|
1786
|
+
application_code,
|
|
1737
1787
|
strategy_context
|
|
1738
1788
|
});
|
|
1739
1789
|
if (subscriberId && typeof callback === 'function') {
|
|
@@ -1834,7 +1884,12 @@ class Server {
|
|
|
1834
1884
|
return this.computeProductQueryResult({
|
|
1835
1885
|
schedule_date,
|
|
1836
1886
|
schedule_datetime: scheduleDatetime,
|
|
1837
|
-
product_id: productId
|
|
1887
|
+
product_id: productId,
|
|
1888
|
+
application_code: data?.application_code ?? this.extractQueryParam(url || '', 'application_code') ?? undefined,
|
|
1889
|
+
...(data && typeof data === 'object' ? {
|
|
1890
|
+
customer_id: data.customer_id,
|
|
1891
|
+
strategy_context: data.strategy_context
|
|
1892
|
+
} : {})
|
|
1838
1893
|
});
|
|
1839
1894
|
};
|
|
1840
1895
|
|
|
@@ -3465,8 +3520,13 @@ class Server {
|
|
|
3465
3520
|
}
|
|
3466
3521
|
getSmallTicketShopInfo() {
|
|
3467
3522
|
const shopInfo = this.getAppData('shop_info') || {};
|
|
3523
|
+
// WebPOS getData does not expose core/default_domain; read the business
|
|
3524
|
+
// shop model directly when the expanded shop_info has not loaded it yet.
|
|
3525
|
+
const shopCore = this.app?.models?.getStore?.().getDataByModel?.('core', 'core') || this.app?.data?.store?.getStore?.().getDataByModel?.('core', 'core') || {};
|
|
3468
3526
|
return {
|
|
3469
3527
|
...shopInfo,
|
|
3528
|
+
default_domain: shopInfo.default_domain || shopCore.default_domain,
|
|
3529
|
+
private_domain_protocol: shopInfo.private_domain_protocol || shopCore.private_domain_protocol,
|
|
3470
3530
|
currency_symbol: shopInfo.currency_symbol || this.getAppData('shop_symbol') || this.getAppData('currency_symbol'),
|
|
3471
3531
|
currency_code: shopInfo.currency_code || this.getAppData('shop_currency_code') || this.getAppData('currency_code'),
|
|
3472
3532
|
tax_title: shopInfo.tax_title || this.getAppData('tax_title'),
|
|
@@ -3652,6 +3712,69 @@ class Server {
|
|
|
3652
3712
|
});
|
|
3653
3713
|
return values.join(',');
|
|
3654
3714
|
}
|
|
3715
|
+
|
|
3716
|
+
/** Refresh derived references on receipt copies; manual references and stored orders stay intact. */
|
|
3717
|
+
async withCurrentReceiptResourceReference(order) {
|
|
3718
|
+
const resourceReference = this.buildCheckoutResourceIdentifierBuzzer(order.bookings);
|
|
3719
|
+
if (!resourceReference || resourceReference === String(order.buzzer ?? '')) return order;
|
|
3720
|
+
const businessCode = String(order.business_code || '').trim();
|
|
3721
|
+
const channel = String(order.order_sales_channel || '').trim();
|
|
3722
|
+
const shopId = this.getAppData('shop_id');
|
|
3723
|
+
const tenantId = this.getAppData('tenant_id');
|
|
3724
|
+
if (!businessCode || !channel || !shopId || !this.app?.request?.post) return order;
|
|
3725
|
+
|
|
3726
|
+
// A receipt can be printed outside a Sales instance. Read the order's own
|
|
3727
|
+
// business/channel settings rather than borrowing the currently open page.
|
|
3728
|
+
const key = JSON.stringify([String(shopId), String(tenantId ?? ''), businessCode, channel]);
|
|
3729
|
+
let inFlight = this.receiptFulfillmentConfigInFlight.get(key);
|
|
3730
|
+
if (!inFlight) {
|
|
3731
|
+
inFlight = (async () => {
|
|
3732
|
+
const response = await this.app.request.post(`/open/my-pisell/${shopId}/setting`, {
|
|
3733
|
+
scope: 'board',
|
|
3734
|
+
target: `${businessCode}+${channel}`,
|
|
3735
|
+
section_code: ['fulfillment']
|
|
3736
|
+
}, {
|
|
3737
|
+
pisell2: true,
|
|
3738
|
+
isPisell2: true,
|
|
3739
|
+
prefix: false,
|
|
3740
|
+
customToast: () => {},
|
|
3741
|
+
...(tenantId ? {
|
|
3742
|
+
headers: {
|
|
3743
|
+
'Tenant-Id': String(tenantId)
|
|
3744
|
+
}
|
|
3745
|
+
} : {})
|
|
3746
|
+
});
|
|
3747
|
+
if (response?.status === false || response?.code != null && Number(response.code) !== 200) {
|
|
3748
|
+
throw new Error('Receipt fulfillment settings are unavailable');
|
|
3749
|
+
}
|
|
3750
|
+
return response?.data?.['fulfillment.fulfillment_ref_mode'];
|
|
3751
|
+
})();
|
|
3752
|
+
this.receiptFulfillmentConfigInFlight.set(key, inFlight);
|
|
3753
|
+
}
|
|
3754
|
+
try {
|
|
3755
|
+
const mode = await inFlight;
|
|
3756
|
+
if (mode !== 'resource_identifier' || String(this.getAppData('shop_id')) !== String(shopId) || String(this.getAppData('tenant_id') ?? '') !== String(tenantId ?? '')) return order;
|
|
3757
|
+
return {
|
|
3758
|
+
...order,
|
|
3759
|
+
buzzer: resourceReference
|
|
3760
|
+
};
|
|
3761
|
+
} catch (error) {
|
|
3762
|
+
// Offline/manual printing still works. Without a confirmed policy, do not
|
|
3763
|
+
// mistake a manually entered pickup reference for an obsolete table name.
|
|
3764
|
+
this.logWarning('withCurrentReceiptResourceReference: 配置不可用,保留原取单号', {
|
|
3765
|
+
order_id: order.order_id,
|
|
3766
|
+
target: `${businessCode}+${channel}`,
|
|
3767
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3768
|
+
});
|
|
3769
|
+
return order;
|
|
3770
|
+
} finally {
|
|
3771
|
+
// Only coalesce concurrent outputs; settings changes and failures must be
|
|
3772
|
+
// re-read on the next receipt instead of becoming a permanent cache.
|
|
3773
|
+
if (this.receiptFulfillmentConfigInFlight.get(key) === inFlight) {
|
|
3774
|
+
this.receiptFulfillmentConfigInFlight.delete(key);
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3655
3778
|
getCheckoutResourceIdentifier(resource, fallbackName) {
|
|
3656
3779
|
if (!resource || typeof resource !== 'object') return '';
|
|
3657
3780
|
const candidates = [resource.main_field, resource.name, resource.title, resource.metadata?.resource_name, resource.metadata?.name, fallbackName, resource.relation_id, resource.id];
|
|
@@ -3920,7 +4043,8 @@ class Server {
|
|
|
3920
4043
|
const printableOrder = await this.withLocalSmallTicketData(params.order, {
|
|
3921
4044
|
requireFullyPaid: params.requireFullyPaid,
|
|
3922
4045
|
invoiceTemplateSettings: params.invoiceTemplateSettings,
|
|
3923
|
-
applyTemplateVisibility: true
|
|
4046
|
+
applyTemplateVisibility: true,
|
|
4047
|
+
refreshResourceReference: true
|
|
3924
4048
|
});
|
|
3925
4049
|
if (!(0, _smallTicket.hasSmallTicketData)(printableOrder.payment_info?.small_ticket_data)) {
|
|
3926
4050
|
return {
|
|
@@ -4158,7 +4282,8 @@ class Server {
|
|
|
4158
4282
|
locales: this.normalizeRequestedReceiptLocales(input.locales),
|
|
4159
4283
|
invoiceTemplateSettings: input.template_settings === undefined ? undefined : this.normalizePrintInvoiceTemplateSettings(input.template_settings),
|
|
4160
4284
|
applyTemplateVisibility: true,
|
|
4161
|
-
includeReceiptKeys: input.template_settings !== undefined
|
|
4285
|
+
includeReceiptKeys: input.template_settings !== undefined,
|
|
4286
|
+
refreshResourceReference: true
|
|
4162
4287
|
});
|
|
4163
4288
|
const smallTicketData = rebuiltOrder.payment_info?.small_ticket_data;
|
|
4164
4289
|
if (!(0, _smallTicket.hasSmallTicketData)(smallTicketData)) {
|
|
@@ -4319,7 +4444,11 @@ class Server {
|
|
|
4319
4444
|
});
|
|
4320
4445
|
return;
|
|
4321
4446
|
}
|
|
4322
|
-
|
|
4447
|
+
let localOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
4448
|
+
const orderId = data?.order_id ?? data?.orderId;
|
|
4449
|
+
if (!localOrder && orderId !== undefined && orderId !== null && orderId !== '' && String(orderId) !== String(lookup)) {
|
|
4450
|
+
localOrder = await this.order.getLocalOrderByLookup(orderId);
|
|
4451
|
+
}
|
|
4323
4452
|
if (!localOrder) {
|
|
4324
4453
|
this.logWarning(`${title}: 本地订单不存在,跳过核销状态更新`, {
|
|
4325
4454
|
lookup,
|
|
@@ -4410,6 +4539,7 @@ class Server {
|
|
|
4410
4539
|
const data = extractedTemplateSettings.data;
|
|
4411
4540
|
const invoiceLayoutConfig = extractedInvoice.invoiceLayoutConfig;
|
|
4412
4541
|
const invoiceTemplateSettings = this.normalizePrintInvoiceTemplateSettings(extractedTemplateSettings.invoiceTemplateSettings);
|
|
4542
|
+
const receiptAutoPrintPaymentStatuses = (0, _posReceiptAutoPrint.normalizePosReceiptAutoPrintPaymentStatuses)(data?.[_posReceiptAutoPrint.OS_POS_RECEIPT_AUTO_PRINT_PAYMENT_STATUSES_FIELD]);
|
|
4413
4543
|
this.logInfo(`${title}: 开始处理`, {
|
|
4414
4544
|
backendPath,
|
|
4415
4545
|
order_id: data?.order_id,
|
|
@@ -4422,7 +4552,8 @@ class Server {
|
|
|
4422
4552
|
data,
|
|
4423
4553
|
title,
|
|
4424
4554
|
invoiceLayoutConfig,
|
|
4425
|
-
invoiceTemplateSettings
|
|
4555
|
+
invoiceTemplateSettings,
|
|
4556
|
+
receiptAutoPrintPaymentStatuses
|
|
4426
4557
|
});
|
|
4427
4558
|
}
|
|
4428
4559
|
const normalizedData = await this.normalizeCheckoutSubmitData(data, title);
|
|
@@ -4437,13 +4568,13 @@ class Server {
|
|
|
4437
4568
|
});
|
|
4438
4569
|
if (pendingResult?.status === true) {
|
|
4439
4570
|
const pendingOrder = pendingResult.data;
|
|
4440
|
-
if (pendingOrder && this.shouldBuildSmallTicketData(checkoutData, invoiceTemplateSettings) && this.
|
|
4571
|
+
if (pendingOrder && this.shouldBuildSmallTicketData(checkoutData, invoiceTemplateSettings) && this.shouldAutoPrintReceiptForPaymentStatus(pendingOrder, receiptAutoPrintPaymentStatuses) && this.shouldAutoPrintCheckoutReceipt()) {
|
|
4441
4572
|
try {
|
|
4442
4573
|
await this.dispatchLocalReceiptPrint({
|
|
4443
4574
|
checkoutData,
|
|
4444
4575
|
order: pendingOrder,
|
|
4445
4576
|
response: pendingResult,
|
|
4446
|
-
requireFullyPaid:
|
|
4577
|
+
requireFullyPaid: receiptAutoPrintPaymentStatuses === undefined,
|
|
4447
4578
|
invoiceLayoutConfig,
|
|
4448
4579
|
invoiceTemplateSettings
|
|
4449
4580
|
});
|
|
@@ -4481,7 +4612,8 @@ class Server {
|
|
|
4481
4612
|
data,
|
|
4482
4613
|
title,
|
|
4483
4614
|
invoiceLayoutConfig,
|
|
4484
|
-
invoiceTemplateSettings
|
|
4615
|
+
invoiceTemplateSettings,
|
|
4616
|
+
receiptAutoPrintPaymentStatuses
|
|
4485
4617
|
} = params;
|
|
4486
4618
|
if (!this.app?.request?.post) {
|
|
4487
4619
|
this.logError(`${title}: sync checkout app.request 不可用`);
|
|
@@ -4512,13 +4644,13 @@ class Server {
|
|
|
4512
4644
|
}
|
|
4513
4645
|
const response = this.withSyncedOrderIdInCheckoutResponse(syncResult.normalizedResponse, syncResult.syncedOrder);
|
|
4514
4646
|
const syncedOrder = syncResult.syncedOrder;
|
|
4515
|
-
if (syncedOrder && this.shouldBuildSmallTicketData(syncResult.checkoutData, invoiceTemplateSettings) && this.
|
|
4647
|
+
if (syncedOrder && this.shouldBuildSmallTicketData(syncResult.checkoutData, invoiceTemplateSettings) && this.shouldAutoPrintReceiptForPaymentStatus(syncedOrder, receiptAutoPrintPaymentStatuses) && (receiptAutoPrintPaymentStatuses === undefined || this.shouldAutoPrintCheckoutReceipt())) {
|
|
4516
4648
|
try {
|
|
4517
4649
|
await this.dispatchLocalReceiptPrint({
|
|
4518
4650
|
checkoutData: syncResult.checkoutData,
|
|
4519
4651
|
order: syncedOrder,
|
|
4520
4652
|
response: syncResult.normalizedResponse,
|
|
4521
|
-
requireFullyPaid:
|
|
4653
|
+
requireFullyPaid: receiptAutoPrintPaymentStatuses === undefined,
|
|
4522
4654
|
invoiceLayoutConfig,
|
|
4523
4655
|
invoiceTemplateSettings
|
|
4524
4656
|
});
|
|
@@ -4738,6 +4870,13 @@ class Server {
|
|
|
4738
4870
|
if (this.core.context?.getPlatform?.() !== 'android') return true;
|
|
4739
4871
|
return this.app?.storage?.getStorage?.(AUTO_PRINT_STORAGE_KEY) !== 'false';
|
|
4740
4872
|
}
|
|
4873
|
+
|
|
4874
|
+
/** Only receipt auto-printing uses this policy; vouchers retain their paid-order gate. */
|
|
4875
|
+
shouldAutoPrintReceiptForPaymentStatus(order, statuses) {
|
|
4876
|
+
if (statuses === undefined) return this.isSalesOrderFullyPaid(order);
|
|
4877
|
+
const paymentStatus = String(order?.payment_status || '').toLowerCase();
|
|
4878
|
+
return statuses.some(status => status === 'paid' ? this.isSalesOrderFullyPaid(order) : paymentStatus === status);
|
|
4879
|
+
}
|
|
4741
4880
|
shouldBuildSmallTicketData(order, invoiceTemplateSettings) {
|
|
4742
4881
|
if (!order || typeof order !== 'object') return false;
|
|
4743
4882
|
const flag = order.small_ticket_data_flag ?? order.smallTicketDataFlag;
|
|
@@ -5066,7 +5205,8 @@ class Server {
|
|
|
5066
5205
|
collapsed_duplicate_counts: collapsedDuplicateCounts
|
|
5067
5206
|
});
|
|
5068
5207
|
}
|
|
5069
|
-
const
|
|
5208
|
+
const receiptOrder = options?.refreshResourceReference ? await this.withCurrentReceiptResourceReference(normalizedOrder) : normalizedOrder;
|
|
5209
|
+
const enrichedOrder = await this.enrichPaymentNamesByCode(receiptOrder);
|
|
5070
5210
|
const productMap = options?.productMap ?? (await this.buildSmallTicketProductMap(enrichedOrder));
|
|
5071
5211
|
const smallTicketData = (0, _smallTicket.buildSmallTicketData)({
|
|
5072
5212
|
order: enrichedOrder,
|
|
@@ -5096,7 +5236,7 @@ class Server {
|
|
|
5096
5236
|
const code = typeof value === 'number' ? value : Number(value);
|
|
5097
5237
|
return Number.isFinite(code) ? code : 500;
|
|
5098
5238
|
}
|
|
5099
|
-
async fetchAndPersistSalesOrderByLookup(lookup, data, title) {
|
|
5239
|
+
async fetchAndPersistSalesOrderByLookup(lookup, data, title, paymentIdentityOrder) {
|
|
5100
5240
|
if (!this.order?.getLocalOrderByLookup || !this.order?.upsertOrdersFromRemote) {
|
|
5101
5241
|
this.logError(`${title}: Order 模块未注册`);
|
|
5102
5242
|
return {
|
|
@@ -5150,13 +5290,44 @@ class Server {
|
|
|
5150
5290
|
};
|
|
5151
5291
|
}
|
|
5152
5292
|
const localBeforeRefresh = this.order.getLocalOrderFromMemoryByLookup?.(lookup) || (this.shouldForceRemoteSalesDetail(data) ? await this.order.getLocalOrderByLookup(lookup) : null);
|
|
5293
|
+
let orderToPersist = fresh;
|
|
5294
|
+
if (paymentIdentityOrder) {
|
|
5295
|
+
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)) {
|
|
5296
|
+
throw new Error('远端订单身份不匹配或缺少付款明细,暂不补齐付款 ID');
|
|
5297
|
+
}
|
|
5298
|
+
// 请求期间可能又产生本地改动,不能用这次补取清除待同步状态。
|
|
5299
|
+
if (!localBeforeRefresh || Number(localBeforeRefresh.need_sync || 0) === 1 || Number(localBeforeRefresh.is_draft_order || 0) === 1) {
|
|
5300
|
+
return {
|
|
5301
|
+
code: 200,
|
|
5302
|
+
message: '',
|
|
5303
|
+
order: localBeforeRefresh || paymentIdentityOrder
|
|
5304
|
+
};
|
|
5305
|
+
}
|
|
5306
|
+
const remotePayments = fresh.payments;
|
|
5307
|
+
const paidPayments = (localBeforeRefresh.payments || []).filter(payment => payment.status === 'paid');
|
|
5308
|
+
const paymentIdsComplete = paidPayments.every(payment => {
|
|
5309
|
+
const localKeys = new Set((0, _paymentUtils.getOrderPaymentIdentityKeys)(payment));
|
|
5310
|
+
const matches = remotePayments.filter(remotePayment => (0, _paymentUtils.getOrderPaymentIdentityKeys)(remotePayment).some(key => localKeys.has(key)));
|
|
5311
|
+
const paymentId = matches[0]?.order_payment_id ?? matches[0]?.id;
|
|
5312
|
+
return matches.length === 1 && paymentId !== undefined && paymentId !== null && String(paymentId).trim() !== '';
|
|
5313
|
+
});
|
|
5314
|
+
if (!paymentIdsComplete) {
|
|
5315
|
+
throw new Error('远端付款 ID 尚未齐全或付款身份匹配不唯一,保留本地付款等待重试');
|
|
5316
|
+
}
|
|
5317
|
+
orderToPersist = {
|
|
5318
|
+
...fresh,
|
|
5319
|
+
payments: (0, _paymentUtils.mergeOrderPaymentListsByIdentity)(localBeforeRefresh.payments, remotePayments, {
|
|
5320
|
+
preserveUnmatchedExisting: true
|
|
5321
|
+
})
|
|
5322
|
+
};
|
|
5323
|
+
}
|
|
5153
5324
|
if ((0, _localEftposState.requiresLocalPaymentRefresh)(localBeforeRefresh)) {
|
|
5154
5325
|
if (String(fresh.order_id) !== String(localBeforeRefresh.order_id)) {
|
|
5155
5326
|
throw new Error('远端订单身份不匹配,请重新刷新');
|
|
5156
5327
|
}
|
|
5157
|
-
await this.order.completeLocalPaymentRefresh(
|
|
5328
|
+
await this.order.completeLocalPaymentRefresh(orderToPersist);
|
|
5158
5329
|
} else {
|
|
5159
|
-
await this.order.upsertOrdersFromRemote([
|
|
5330
|
+
await this.order.upsertOrdersFromRemote([orderToPersist]);
|
|
5160
5331
|
}
|
|
5161
5332
|
let savedOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
5162
5333
|
if (!savedOrder && fresh.order_id !== undefined && fresh.order_id !== null && String(fresh.order_id) !== String(lookup)) {
|
|
@@ -5251,7 +5422,8 @@ class Server {
|
|
|
5251
5422
|
if (!this.shouldForceRemoteSalesDetail(data)) {
|
|
5252
5423
|
const localOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
5253
5424
|
if (localOrder) {
|
|
5254
|
-
const
|
|
5425
|
+
const refreshedOrder = await this.refreshMissingPaymentIds(localOrder, 'handleOrderSalesDetail');
|
|
5426
|
+
const enrichedOrder = await this.withSalesDetailProductSnapshots(refreshedOrder);
|
|
5255
5427
|
this.logInfo('handleOrderSalesDetail: 命中本地订单', {
|
|
5256
5428
|
lookup
|
|
5257
5429
|
});
|
|
@@ -5982,8 +6154,11 @@ class Server {
|
|
|
5982
6154
|
customer_id,
|
|
5983
6155
|
extension_type,
|
|
5984
6156
|
product_id,
|
|
6157
|
+
application_code,
|
|
5985
6158
|
strategy_context
|
|
5986
6159
|
} = context;
|
|
6160
|
+
// 仅 Kiosk 查询额外按商品销售渠道过滤。
|
|
6161
|
+
const isVisibleProduct = product => (product?.status || 'published') === 'published' && (application_code !== 'kiosk' || Array.isArray(product?.channel_application) && product.channel_application.includes('kiosk'));
|
|
5987
6162
|
const queryIds = Array.isArray(ids) ? ids.map(id => Number(id)).filter(id => Number.isFinite(id)) : [];
|
|
5988
6163
|
this.logInfo('computeProductQueryResult 开始', {
|
|
5989
6164
|
menuListIdsCount: menu_list_ids?.length ?? 0,
|
|
@@ -6031,7 +6206,7 @@ class Server {
|
|
|
6031
6206
|
count: productsWithPrice.length,
|
|
6032
6207
|
ids: uniqueIds
|
|
6033
6208
|
});
|
|
6034
|
-
const filteredProducts = productsWithPrice.filter(p => uniqueIds.includes(Number(p?.id))).filter(
|
|
6209
|
+
const filteredProducts = productsWithPrice.filter(p => uniqueIds.includes(Number(p?.id))).filter(isVisibleProduct);
|
|
6035
6210
|
const extensionFilteredProducts = this.filterProductsByExtensionTypes(filteredProducts, extension_type);
|
|
6036
6211
|
(0, _product.perfMark)('computeProductQueryResult', performance.now() - tTotal, {
|
|
6037
6212
|
mode: 'ids',
|
|
@@ -6061,7 +6236,7 @@ class Server {
|
|
|
6061
6236
|
count: allProductsWithPrice.length,
|
|
6062
6237
|
productId: pid
|
|
6063
6238
|
});
|
|
6064
|
-
const published = this.filterProductsByExtensionTypes(allProductsWithPrice.filter(
|
|
6239
|
+
const published = this.filterProductsByExtensionTypes(allProductsWithPrice.filter(isVisibleProduct), extension_type);
|
|
6065
6240
|
const item = published.find(p => Number(p.id) === pid) ?? null;
|
|
6066
6241
|
(0, _product.perfMark)('computeProductQueryResult', performance.now() - tTotal, {
|
|
6067
6242
|
mode: 'single',
|
|
@@ -6090,7 +6265,7 @@ class Server {
|
|
|
6090
6265
|
});
|
|
6091
6266
|
const tStatus = performance.now();
|
|
6092
6267
|
const beforeStatusCount = filteredProducts.length;
|
|
6093
|
-
filteredProducts = filteredProducts.filter(
|
|
6268
|
+
filteredProducts = filteredProducts.filter(isVisibleProduct);
|
|
6094
6269
|
(0, _product.perfMark)('computeQuery.filterByStatus(extensionType)', performance.now() - tStatus, {
|
|
6095
6270
|
before: beforeStatusCount,
|
|
6096
6271
|
after: filteredProducts.length
|
|
@@ -6173,7 +6348,7 @@ class Server {
|
|
|
6173
6348
|
});
|
|
6174
6349
|
const tStatus = performance.now();
|
|
6175
6350
|
const beforeStatusCount = filteredProducts.length;
|
|
6176
|
-
filteredProducts = filteredProducts.filter(
|
|
6351
|
+
filteredProducts = filteredProducts.filter(isVisibleProduct);
|
|
6177
6352
|
(0, _product.perfMark)('computeQuery.filterByStatus', performance.now() - tStatus, {
|
|
6178
6353
|
before: beforeStatusCount,
|
|
6179
6354
|
after: filteredProducts.length
|
|
@@ -8,6 +8,7 @@ var _lodashEs = require("lodash-es");
|
|
|
8
8
|
var _localEftposState = require("../../../modules/Order/localEftposState");
|
|
9
9
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
10
10
|
var _BaseModule = require("../../../modules/BaseModule");
|
|
11
|
+
var _unpaidAmountGap = require("../../../modules/Order/unpaidAmountGap");
|
|
11
12
|
var _orderCollectionIdentity = require("../../../modules/Order/utils/orderCollectionIdentity");
|
|
12
13
|
var _types = require("./types");
|
|
13
14
|
var _paymentUtils = require("../../../modules/Order/payment-utils");
|
|
@@ -251,7 +252,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
251
252
|
this.logInfo('订单子项身份已规范化', context);
|
|
252
253
|
}
|
|
253
254
|
}
|
|
254
|
-
return result.order;
|
|
255
|
+
return (0, _unpaidAmountGap.normalizeUnpaidOrderAmountGap)(result.order);
|
|
255
256
|
}
|
|
256
257
|
|
|
257
258
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type CustomerInvoiceLanguageCode = 'en' | 'zh_CN' | 'zh_HK' | 'ja' | 'pt' | 'cn_en';
|
|
1
|
+
export type CustomerInvoiceLanguageCode = 'en' | 'zh_CN' | 'zh_HK' | 'ja' | 'pt' | 'cn_en' | 'ja_en';
|
|
2
2
|
export interface CustomerInvoiceLanguageOption {
|
|
3
3
|
code: CustomerInvoiceLanguageCode;
|
|
4
4
|
locales: string[];
|
|
@@ -26,15 +26,17 @@ const aliases = {
|
|
|
26
26
|
pt_br: 'pt',
|
|
27
27
|
pt_pt: 'pt',
|
|
28
28
|
cn_en: 'cn_en',
|
|
29
|
-
en_cn: 'cn_en'
|
|
29
|
+
en_cn: 'cn_en',
|
|
30
|
+
ja_en: 'ja_en'
|
|
30
31
|
};
|
|
31
32
|
function normalizeCustomerInvoiceLanguage(value) {
|
|
32
33
|
return aliases[value.trim().toLowerCase().replace(/-/g, '_')];
|
|
33
34
|
}
|
|
34
35
|
function option(code) {
|
|
36
|
+
const locales = code === 'cn_en' ? ['en', 'zh_CN'] : code === 'ja_en' ? ['ja', 'en'] : [code];
|
|
35
37
|
return {
|
|
36
38
|
code,
|
|
37
|
-
locales
|
|
39
|
+
locales
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -53,6 +55,6 @@ function resolveCustomerInvoiceLanguages(language, pageLocale) {
|
|
|
53
55
|
const normalized = normalizeCustomerInvoiceLanguage(pageLocale);
|
|
54
56
|
// A page locale is a single language, never a bilingual printer mode.
|
|
55
57
|
const requested = pageLocale.toLowerCase().replace(/_/g, '-');
|
|
56
|
-
const fallback = normalized && normalized !== 'cn_en' ? normalized : requested.startsWith('zh-tw') || requested.startsWith('zh-hk') ? 'zh_HK' : requested.startsWith('zh') ? 'zh_CN' : requested.startsWith('ja') ? 'ja' : requested.startsWith('pt') ? 'pt' : 'en';
|
|
58
|
+
const fallback = normalized && normalized !== 'cn_en' && normalized !== 'ja_en' ? normalized : requested.startsWith('zh-tw') || requested.startsWith('zh-hk') ? 'zh_HK' : requested.startsWith('zh') ? 'zh_CN' : requested.startsWith('ja') ? 'ja' : requested.startsWith('pt') ? 'pt' : 'en';
|
|
57
59
|
return [option(fallback)];
|
|
58
60
|
}
|
|
@@ -15,6 +15,10 @@ export interface SmallTicketShopInfo {
|
|
|
15
15
|
currency_code?: string;
|
|
16
16
|
primary_locale?: string;
|
|
17
17
|
timezone?: string;
|
|
18
|
+
/** Customer-facing shop domain, supplied by the host shop context. */
|
|
19
|
+
default_domain?: string;
|
|
20
|
+
private_domain?: string;
|
|
21
|
+
private_domain_protocol?: string;
|
|
18
22
|
[key: string]: any;
|
|
19
23
|
}
|
|
20
24
|
export interface BuildSmallTicketDataParams {
|
|
@@ -7,11 +7,13 @@ exports.buildSmallTicketData = buildSmallTicketData;
|
|
|
7
7
|
exports.hasSmallTicketData = hasSmallTicketData;
|
|
8
8
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
9
9
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
10
|
+
var _unpaidAmountGap = require("../../modules/Order/unpaidAmountGap");
|
|
10
11
|
var _holderRelations = require("../../modules/Order/holderRelations");
|
|
11
12
|
var _pickupTiming = require("../../modules/Order/pickupTiming");
|
|
12
13
|
var _templateVisibility = require("./templateVisibility");
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
15
|
const DEFAULT_LOCALES = ['en', 'zh_CN'];
|
|
16
|
+
const BOOKING_ID_UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
15
17
|
|
|
16
18
|
// Attach provenance to a private copy BEFORE any locale-dependent filtering.
|
|
17
19
|
// Symbols survive the existing spread-based normalization, never enter JSON,
|
|
@@ -84,6 +86,7 @@ const LABELS = {
|
|
|
84
86
|
cashReceived: 'Cash received',
|
|
85
87
|
changeDue: 'Change due',
|
|
86
88
|
eftpos: 'Eftpos',
|
|
89
|
+
creditCard: 'Credit card',
|
|
87
90
|
wallet: 'Wallet',
|
|
88
91
|
giftCard: 'Gift card',
|
|
89
92
|
pointCard: 'Point card',
|
|
@@ -130,6 +133,7 @@ const LABELS = {
|
|
|
130
133
|
cashReceived: '收取现金',
|
|
131
134
|
changeDue: '找零',
|
|
132
135
|
eftpos: '刷卡支付',
|
|
136
|
+
creditCard: '信用卡',
|
|
133
137
|
wallet: '钱包支付',
|
|
134
138
|
giftCard: '礼品卡',
|
|
135
139
|
pointCard: '积分卡',
|
|
@@ -176,6 +180,7 @@ const LABELS = {
|
|
|
176
180
|
cashReceived: '收取現金',
|
|
177
181
|
changeDue: '找零',
|
|
178
182
|
eftpos: '刷卡支付',
|
|
183
|
+
creditCard: '信用卡',
|
|
179
184
|
wallet: '錢包支付',
|
|
180
185
|
giftCard: '禮品卡',
|
|
181
186
|
pointCard: '積分卡',
|
|
@@ -220,6 +225,7 @@ const LABELS = {
|
|
|
220
225
|
asap: 'できるだけ早く',
|
|
221
226
|
cash: '現金',
|
|
222
227
|
eftpos: 'カード',
|
|
228
|
+
creditCard: 'クレジットカード',
|
|
223
229
|
wallet: 'ウォレット',
|
|
224
230
|
giftCard: 'ギフトカード',
|
|
225
231
|
pointCard: 'ポイントカード',
|
|
@@ -265,6 +271,7 @@ const LABELS = {
|
|
|
265
271
|
asap: 'Assim que possível',
|
|
266
272
|
cash: 'Dinheiro',
|
|
267
273
|
eftpos: 'Cartão',
|
|
274
|
+
creditCard: 'Cartão de crédito',
|
|
268
275
|
wallet: 'Carteira',
|
|
269
276
|
giftCard: 'Cartão-presente',
|
|
270
277
|
pointCard: 'Cartão de pontos',
|
|
@@ -294,7 +301,8 @@ const LABELS = {
|
|
|
294
301
|
}
|
|
295
302
|
};
|
|
296
303
|
function buildSmallTicketData(params) {
|
|
297
|
-
const
|
|
304
|
+
const normalizedOrder = (0, _unpaidAmountGap.normalizeUnpaidOrderAmountGap)(params.order || {});
|
|
305
|
+
const order = params.includeReceiptKeys ? copyReceiptSource(normalizedOrder) : normalizedOrder;
|
|
298
306
|
const shopInfo = params.shopInfo || {};
|
|
299
307
|
const locales = resolveLocales(shopInfo, params.locales);
|
|
300
308
|
const productMap = params.productMap || {};
|
|
@@ -387,10 +395,14 @@ function buildBaseData(params) {
|
|
|
387
395
|
financials
|
|
388
396
|
} = params;
|
|
389
397
|
const orderNumber = stringify(order.buzzer || order.shop_full_order_number);
|
|
398
|
+
const rewardClaim = buildRewardClaimUrl(shopInfo, order.shop_order_number);
|
|
390
399
|
return {
|
|
391
400
|
shop_name: stringify(shopInfo.name || order.shop_name),
|
|
392
401
|
note: stringify(order.note),
|
|
393
402
|
shop_order_number: stringify(order.shop_order_number),
|
|
403
|
+
...(rewardClaim ? {
|
|
404
|
+
reward_claim: rewardClaim
|
|
405
|
+
} : {}),
|
|
394
406
|
order_number: orderNumber,
|
|
395
407
|
shop_tax_number: stringify(shopInfo.tax_number || order.shop_tax_number),
|
|
396
408
|
shop_phone: stringify(shopInfo.phone || order.shop_phone),
|
|
@@ -409,6 +421,26 @@ function buildBaseData(params) {
|
|
|
409
421
|
} : {})
|
|
410
422
|
};
|
|
411
423
|
}
|
|
424
|
+
function buildRewardClaimUrl(shopInfo, shopOrderNumber) {
|
|
425
|
+
const default_domain = typeof shopInfo.default_domain === 'string' ? shopInfo.default_domain.trim() : '';
|
|
426
|
+
const private_domain = typeof shopInfo.private_domain === 'string' ? shopInfo.private_domain.trim() : '';
|
|
427
|
+
// 私有域名优先于默认域名
|
|
428
|
+
const domain = default_domain;
|
|
429
|
+
const orderNumber = typeof shopOrderNumber === 'string' ? shopOrderNumber.trim() : typeof shopOrderNumber === 'number' && Number.isFinite(shopOrderNumber) ? String(shopOrderNumber) : '';
|
|
430
|
+
if (!domain || !orderNumber) return undefined;
|
|
431
|
+
try {
|
|
432
|
+
const protocol = shopInfo.private_domain_protocol === 'http' ? 'http' : 'https';
|
|
433
|
+
const base = new URL(/^[a-z][a-z\d+.-]*:\/\//i.test(domain) ? domain : `${protocol}://${domain}`);
|
|
434
|
+
if (!['http:', 'https:'].includes(base.protocol) || base.username || base.password) {
|
|
435
|
+
return undefined;
|
|
436
|
+
}
|
|
437
|
+
const url = new URL('/claim-purchase-rewards', base);
|
|
438
|
+
url.searchParams.set('shop_order_number', orderNumber);
|
|
439
|
+
return url.toString();
|
|
440
|
+
} catch {
|
|
441
|
+
return undefined;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
412
444
|
function buildProducts(order, locale, productMap) {
|
|
413
445
|
const products = Array.isArray(order.products) ? order.products : [];
|
|
414
446
|
const allergyByProductUid = buildProductAllergyMap(order, locale);
|
|
@@ -1190,7 +1222,9 @@ function buildFees(params) {
|
|
|
1190
1222
|
total_amount: formatMoney(firstPresentValue(summary.total_amount, order.total_amount) ?? 0, currencySymbol),
|
|
1191
1223
|
original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
|
|
1192
1224
|
product_expect_amount: formatMoney(productExpectAmount ?? 0, currencySymbol),
|
|
1193
|
-
|
|
1225
|
+
...(isNonZero(itemDiscountAmount) ? {
|
|
1226
|
+
item_discount_amount: formatCalculatedMoney(itemDiscountAmount, currencySymbol)
|
|
1227
|
+
} : {}),
|
|
1194
1228
|
expect_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
1195
1229
|
product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce((sum, product) => sum + product.product_quantity, 0)), 0),
|
|
1196
1230
|
has_pay: formatMoney(financials.orderPaidAmount, currencySymbol),
|
|
@@ -1384,7 +1418,8 @@ function buildAppointmentRows(params) {
|
|
|
1384
1418
|
return [{
|
|
1385
1419
|
...receiptKey(booking, 'booking-id'),
|
|
1386
1420
|
item: label(locale, 'bookingId'),
|
|
1387
|
-
|
|
1421
|
+
// 异步落单时可能只有内部关联 UUID;留空后由下方过滤移除整行。
|
|
1422
|
+
value: BOOKING_ID_UUID_PATTERN.test(bookingId) ? '' : bookingId,
|
|
1388
1423
|
...association
|
|
1389
1424
|
}, {
|
|
1390
1425
|
...receiptKey(booking, 'booking-time', 'shared'),
|
|
@@ -2434,12 +2469,30 @@ function appendMaskedCardCode(name, code) {
|
|
|
2434
2469
|
function trimDecimal(value) {
|
|
2435
2470
|
return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
|
|
2436
2471
|
}
|
|
2472
|
+
function getLocalizedPaymentName(value, locale) {
|
|
2473
|
+
if (typeof value === 'string') return value.trim();
|
|
2474
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return '';
|
|
2475
|
+
const candidates = [value[locale], value[locale.replace('_', '-')], value[locale.replace('-', '_')], value.original, value.auto, value.default, value.en];
|
|
2476
|
+
for (const candidate of candidates) {
|
|
2477
|
+
if (typeof candidate === 'string' && candidate.trim()) return candidate.trim();
|
|
2478
|
+
}
|
|
2479
|
+
return '';
|
|
2480
|
+
}
|
|
2481
|
+
function getExplicitPaymentName(payment, locale) {
|
|
2482
|
+
// Cloud order snapshots retain the localized name in metadata after reload.
|
|
2483
|
+
const candidates = [payment.name, payment.title, payment.payment_method_name, payment.method_name, payment.metadata?.custom_payment_name];
|
|
2484
|
+
for (const candidate of candidates) {
|
|
2485
|
+
const name = getLocalizedPaymentName(candidate, locale);
|
|
2486
|
+
if (name) return name;
|
|
2487
|
+
}
|
|
2488
|
+
return '';
|
|
2489
|
+
}
|
|
2437
2490
|
function getFundRecordPaymentName(payment, locale) {
|
|
2438
2491
|
const fundRecord = getFundRecord(payment);
|
|
2439
2492
|
if (!fundRecord) return '';
|
|
2440
|
-
const name =
|
|
2493
|
+
const name = getLocalizedPaymentName(fundRecord.wallet_pass_name, locale);
|
|
2441
2494
|
if (!name && !maskMachineCode(fundRecord.code)) return '';
|
|
2442
|
-
const fallbackName =
|
|
2495
|
+
const fallbackName = getExplicitPaymentName(payment, locale) || getLocalizedPaymentName(payment.code, locale);
|
|
2443
2496
|
return appendMaskedCardCode(name || fallbackName, fundRecord.code);
|
|
2444
2497
|
}
|
|
2445
2498
|
function appendMachineCodeToName(name, payment) {
|
|
@@ -2449,13 +2502,15 @@ function appendMachineCodeToName(name, payment) {
|
|
|
2449
2502
|
function paymentMethodName(payment, locale) {
|
|
2450
2503
|
const fundRecordName = getFundRecordPaymentName(payment, locale);
|
|
2451
2504
|
if (fundRecordName) return fundRecordName;
|
|
2452
|
-
const
|
|
2453
|
-
if (
|
|
2505
|
+
const name = getExplicitPaymentName(payment, locale);
|
|
2506
|
+
if (name) return appendMachineCodeToName(name, payment);
|
|
2454
2507
|
const code = stringify(payment.code || payment.type || payment.payment_method || payment.method).toLowerCase();
|
|
2455
2508
|
if (code.includes('cash')) return label(locale, 'cash');
|
|
2456
|
-
if (code.includes('eftpos')
|
|
2509
|
+
if (code.includes('eftpos')) return label(locale, 'eftpos');
|
|
2457
2510
|
if (code.includes('wallet')) return label(locale, 'wallet');
|
|
2458
2511
|
if (code.includes('gift')) return label(locale, 'giftCard');
|
|
2512
|
+
if (code === 'credit_card' || code.startsWith('credit_card_')) return label(locale, 'creditCard');
|
|
2513
|
+
if (code.includes('card')) return label(locale, 'eftpos');
|
|
2459
2514
|
return stringify(payment.code || payment.type || payment.payment_method || payment.method);
|
|
2460
2515
|
}
|
|
2461
2516
|
function getSummary(order) {
|