@pisell/pisellos 2.2.243 → 2.2.244
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/model/strategy/adapter/promotion/evaluator.js +2 -3
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +4 -7
- package/dist/modules/Cart/utils/cartProduct.js +3 -24
- package/dist/modules/Cart/utils/changePrice.js +11 -11
- package/dist/modules/Customer/index.d.ts +0 -20
- package/dist/modules/Customer/index.js +83 -172
- package/dist/modules/Customer/types.d.ts +0 -2
- package/dist/modules/Discount/index.js +3 -4
- package/dist/modules/Discount/types.d.ts +0 -1
- package/dist/modules/OpenData/index.d.ts +0 -8
- package/dist/modules/OpenData/index.js +17 -37
- package/dist/modules/Order/index.d.ts +18 -268
- package/dist/modules/Order/index.js +757 -3306
- package/dist/modules/Order/types.d.ts +31 -279
- package/dist/modules/Order/types.js +0 -38
- package/dist/modules/Order/utils.d.ts +5 -147
- package/dist/modules/Order/utils.js +103 -746
- package/dist/modules/Payment/index.d.ts +13 -10
- package/dist/modules/Payment/index.js +837 -467
- package/dist/modules/Payment/types.d.ts +0 -2
- package/dist/modules/Payment/utils.js +1 -2
- package/dist/modules/Payment/walletpass.js +7 -14
- package/dist/modules/ProductList/index.d.ts +12 -16
- package/dist/modules/ProductList/index.js +59 -133
- package/dist/modules/ProductList/types.d.ts +0 -14
- package/dist/modules/Quotation/index.d.ts +1 -0
- package/dist/modules/Quotation/index.js +22 -25
- package/dist/modules/Rules/index.d.ts +0 -4
- package/dist/modules/Rules/index.js +69 -93
- package/dist/modules/Rules/types.d.ts +0 -1
- package/dist/modules/SalesSummary/index.d.ts +25 -8
- package/dist/modules/SalesSummary/index.js +35 -86
- package/dist/modules/SalesSummary/types.d.ts +1 -4
- package/dist/modules/SalesSummary/utils.d.ts +25 -2
- package/dist/modules/SalesSummary/utils.js +162 -794
- package/dist/modules/Schedule/index.d.ts +0 -7
- package/dist/modules/Schedule/index.js +2 -24
- package/dist/modules/Summary/index.js +3 -4
- package/dist/modules/index.d.ts +0 -2
- package/dist/modules/index.js +1 -3
- package/dist/plugins/request.d.ts +0 -1
- package/dist/server/index.d.ts +1 -204
- package/dist/server/index.js +928 -3658
- package/dist/server/modules/index.d.ts +0 -2
- package/dist/server/modules/index.js +0 -2
- package/dist/server/modules/order/index.d.ts +4 -120
- package/dist/server/modules/order/index.js +483 -1779
- package/dist/server/modules/order/types.d.ts +3 -32
- package/dist/server/modules/order/types.js +0 -8
- package/dist/server/modules/order/utils/filterBookings.js +3 -26
- package/dist/server/modules/order/utils/filterOrders.js +8 -23
- package/dist/server/modules/products/index.d.ts +7 -34
- package/dist/server/modules/products/index.js +317 -631
- package/dist/server/modules/resource/index.d.ts +0 -2
- package/dist/server/modules/resource/index.js +3 -29
- package/dist/server/modules/schedule/index.d.ts +4 -4
- package/dist/server/modules/schedule/index.js +88 -111
- package/dist/solution/BaseSales/index.d.ts +9 -131
- package/dist/solution/BaseSales/index.js +447 -1944
- package/dist/solution/BaseSales/types.d.ts +6 -76
- package/dist/solution/BaseSales/types.js +4 -5
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -105
- package/dist/solution/BaseSales/utils.d.ts +1 -1
- package/dist/solution/BaseSales/utils.js +21 -62
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +10 -270
- package/dist/solution/BookingTicket/index.js +237 -1772
- package/dist/solution/BookingTicket/types.d.ts +1 -118
- package/dist/solution/BookingTicket/types.js +2 -41
- package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
- package/dist/solution/BookingTicket/utils/bookingStatus.js +0 -70
- package/dist/solution/BookingTicket/utils/cartView.d.ts +1 -9
- package/dist/solution/BookingTicket/utils/cartView.js +7 -94
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +0 -5
- package/dist/solution/BookingTicket/utils/scan/index.js +8 -20
- package/dist/solution/Checkout/appointmentDemo.json +1 -0
- package/dist/solution/Checkout/index.d.ts +0 -1
- package/dist/solution/Checkout/index.js +9 -10
- package/dist/solution/RegisterAndLogin/config.js +10 -2
- package/dist/solution/ScanOrder/index.d.ts +3 -9
- package/dist/solution/ScanOrder/index.js +134 -241
- package/dist/solution/ScanOrder/types.d.ts +5 -9
- package/dist/solution/ScanOrder/types.js +3 -2
- package/dist/solution/ScanOrder/utils.d.ts +1 -1
- package/dist/solution/ScanOrder/utils.js +22 -84
- package/dist/solution/VenueBooking/index.d.ts +2 -5
- package/dist/solution/VenueBooking/index.js +59 -110
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +2 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
- package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
- package/dist/types/index.d.ts +0 -10
- package/lib/model/strategy/adapter/promotion/evaluator.js +1 -2
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/model/strategy/adapter/walletPass/utils.js +2 -3
- package/lib/modules/Cart/utils/cartProduct.js +3 -20
- package/lib/modules/Cart/utils/changePrice.js +20 -12
- package/lib/modules/Customer/index.d.ts +0 -20
- package/lib/modules/Customer/index.js +11 -64
- package/lib/modules/Customer/types.d.ts +0 -2
- package/lib/modules/Discount/index.js +1 -5
- package/lib/modules/Discount/types.d.ts +0 -1
- package/lib/modules/OpenData/index.d.ts +0 -8
- package/lib/modules/OpenData/index.js +5 -19
- package/lib/modules/Order/index.d.ts +18 -268
- package/lib/modules/Order/index.js +344 -2149
- package/lib/modules/Order/types.d.ts +31 -279
- package/lib/modules/Order/types.js +0 -1
- package/lib/modules/Order/utils.d.ts +5 -147
- package/lib/modules/Order/utils.js +46 -614
- package/lib/modules/Payment/index.d.ts +13 -10
- package/lib/modules/Payment/index.js +150 -18
- package/lib/modules/Payment/types.d.ts +0 -2
- package/lib/modules/Payment/utils.js +1 -2
- package/lib/modules/Payment/walletpass.js +3 -7
- package/lib/modules/ProductList/index.d.ts +12 -16
- package/lib/modules/ProductList/index.js +4 -41
- package/lib/modules/ProductList/types.d.ts +0 -14
- package/lib/modules/Quotation/index.d.ts +1 -0
- package/lib/modules/Quotation/index.js +16 -19
- package/lib/modules/Rules/index.d.ts +0 -4
- package/lib/modules/Rules/index.js +120 -136
- package/lib/modules/Rules/types.d.ts +0 -1
- package/lib/modules/SalesSummary/index.d.ts +25 -8
- package/lib/modules/SalesSummary/index.js +4 -30
- package/lib/modules/SalesSummary/types.d.ts +1 -4
- package/lib/modules/SalesSummary/utils.d.ts +25 -2
- package/lib/modules/SalesSummary/utils.js +91 -645
- package/lib/modules/Schedule/index.d.ts +0 -7
- package/lib/modules/Schedule/index.js +1 -17
- package/lib/modules/Summary/index.js +4 -5
- package/lib/modules/index.d.ts +0 -2
- package/lib/modules/index.js +1 -5
- package/lib/plugins/request.d.ts +0 -1
- package/lib/server/index.d.ts +1 -204
- package/lib/server/index.js +57 -1888
- package/lib/server/modules/index.d.ts +0 -2
- package/lib/server/modules/index.js +0 -3
- package/lib/server/modules/order/index.d.ts +4 -120
- package/lib/server/modules/order/index.js +142 -919
- package/lib/server/modules/order/types.d.ts +3 -32
- package/lib/server/modules/order/utils/filterBookings.js +5 -24
- package/lib/server/modules/order/utils/filterOrders.js +6 -15
- package/lib/server/modules/products/index.d.ts +7 -34
- package/lib/server/modules/products/index.js +54 -189
- package/lib/server/modules/resource/index.d.ts +0 -2
- package/lib/server/modules/resource/index.js +3 -27
- package/lib/server/modules/schedule/index.d.ts +4 -4
- package/lib/server/modules/schedule/index.js +40 -47
- package/lib/solution/BaseSales/index.d.ts +9 -131
- package/lib/solution/BaseSales/index.js +63 -1106
- package/lib/solution/BaseSales/types.d.ts +6 -76
- package/lib/solution/BaseSales/types.js +1 -3
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +18 -106
- package/lib/solution/BaseSales/utils.d.ts +1 -1
- package/lib/solution/BaseSales/utils.js +10 -54
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +10 -270
- package/lib/solution/BookingTicket/index.js +29 -922
- package/lib/solution/BookingTicket/types.d.ts +1 -118
- package/lib/solution/BookingTicket/types.js +0 -11
- package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
- package/lib/solution/BookingTicket/utils/bookingStatus.js +2 -44
- package/lib/solution/BookingTicket/utils/cartView.d.ts +1 -9
- package/lib/solution/BookingTicket/utils/cartView.js +6 -61
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +0 -5
- package/lib/solution/BookingTicket/utils/scan/index.js +3 -17
- package/lib/solution/Checkout/appointmentDemo.json +1 -0
- package/lib/solution/Checkout/index.d.ts +0 -1
- package/lib/solution/Checkout/index.js +2 -1
- package/lib/solution/RegisterAndLogin/config.js +10 -2
- package/lib/solution/ScanOrder/index.d.ts +3 -9
- package/lib/solution/ScanOrder/index.js +70 -153
- package/lib/solution/ScanOrder/types.d.ts +5 -9
- package/lib/solution/ScanOrder/utils.d.ts +1 -1
- package/lib/solution/ScanOrder/utils.js +17 -83
- package/lib/solution/VenueBooking/index.d.ts +2 -5
- package/lib/solution/VenueBooking/index.js +17 -54
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +2 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
- package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
- package/lib/types/index.d.ts +0 -10
- package/package.json +1 -1
- package/dist/modules/BookingContext/index.d.ts +0 -48
- package/dist/modules/BookingContext/index.js +0 -566
- package/dist/modules/BookingContext/types.d.ts +0 -102
- package/dist/modules/BookingContext/types.js +0 -51
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -284
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -145
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -218
- package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
- package/dist/modules/BookingContext/utils/flexible.js +0 -56
- package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
- package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
- package/dist/modules/BookingContext/utils/index.d.ts +0 -11
- package/dist/modules/BookingContext/utils/index.js +0 -11
- package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
- package/dist/modules/BookingContext/utils/noResource.js +0 -77
- package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
- package/dist/modules/BookingContext/utils/orderLineDisplay.js +0 -36
- package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
- package/dist/modules/BookingContext/utils/productExtend.js +0 -339
- package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
- package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
- package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
- package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
- package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
- package/dist/modules/BookingContext/utils/resources.js +0 -486
- package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
- package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
- package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
- package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
- package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
- package/dist/modules/Order/utils/manualProductDiscount.js +0 -210
- package/dist/modules/SurchargeList/index.d.ts +0 -16
- package/dist/modules/SurchargeList/index.js +0 -162
- package/dist/modules/SurchargeList/types.d.ts +0 -11
- package/dist/modules/SurchargeList/types.js +0 -1
- package/dist/server/modules/payment/index.d.ts +0 -28
- package/dist/server/modules/payment/index.js +0 -305
- package/dist/server/modules/payment/types.d.ts +0 -9
- package/dist/server/modules/payment/types.js +0 -1
- package/dist/server/test.json +0 -713
- package/dist/server/utils/small-ticket.d.ts +0 -71
- package/dist/server/utils/small-ticket.js +0 -830
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
- package/dist/solution/BaseSales/utils/cartPromotion.js +0 -1438
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
- package/dist/solution/BaseSales/utils/quotationPrice.js +0 -237
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
- package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
- package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
- package/dist/solution/BookingTicket/utils/addTimeAvailability.js +0 -95
- package/dist/solution/BookingTicket/utils/exampleData.d.ts +0 -123
- package/dist/solution/BookingTicket/utils/exampleData.js +0 -183
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -438
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -399
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -56
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +0 -150
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +0 -78
- package/lib/modules/BookingContext/index.d.ts +0 -48
- package/lib/modules/BookingContext/index.js +0 -368
- package/lib/modules/BookingContext/types.d.ts +0 -102
- package/lib/modules/BookingContext/types.js +0 -34
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -276
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -151
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -201
- package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
- package/lib/modules/BookingContext/utils/flexible.js +0 -80
- package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
- package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
- package/lib/modules/BookingContext/utils/index.d.ts +0 -11
- package/lib/modules/BookingContext/utils/index.js +0 -43
- package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
- package/lib/modules/BookingContext/utils/noResource.js +0 -90
- package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +0 -56
- package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
- package/lib/modules/BookingContext/utils/productExtend.js +0 -283
- package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
- package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
- package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
- package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
- package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
- package/lib/modules/BookingContext/utils/resources.js +0 -377
- package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
- package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
- package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
- package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
- package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
- package/lib/modules/Order/utils/manualProductDiscount.js +0 -206
- package/lib/modules/SurchargeList/index.d.ts +0 -16
- package/lib/modules/SurchargeList/index.js +0 -89
- package/lib/modules/SurchargeList/types.d.ts +0 -11
- package/lib/modules/SurchargeList/types.js +0 -17
- package/lib/server/modules/payment/index.d.ts +0 -28
- package/lib/server/modules/payment/index.js +0 -192
- package/lib/server/modules/payment/types.d.ts +0 -9
- package/lib/server/modules/payment/types.js +0 -17
- package/lib/server/test.json +0 -713
- package/lib/server/utils/small-ticket.d.ts +0 -71
- package/lib/server/utils/small-ticket.js +0 -781
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
- package/lib/solution/BaseSales/utils/cartPromotion.js +0 -992
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
- package/lib/solution/BaseSales/utils/quotationPrice.js +0 -277
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
- package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
- package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +0 -125
- package/lib/solution/BookingTicket/utils/exampleData.d.ts +0 -123
- package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -254
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -168
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -51
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +0 -127
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +0 -85
package/lib/server/index.js
CHANGED
|
@@ -41,7 +41,6 @@ var import_schedule = require("./modules/schedule");
|
|
|
41
41
|
var import_resource = require("./modules/resource");
|
|
42
42
|
var import_floor_plan = require("./modules/floor-plan");
|
|
43
43
|
var import_types = require("./modules/floor-plan/types");
|
|
44
|
-
var import_payment = require("./modules/payment");
|
|
45
44
|
var import_schedule2 = require("./utils/schedule");
|
|
46
45
|
var import_types2 = require("./modules/products/types");
|
|
47
46
|
var import_product = require("./utils/product");
|
|
@@ -49,22 +48,9 @@ var import_order = require("./modules/order");
|
|
|
49
48
|
var import_types3 = require("./modules/order/types");
|
|
50
49
|
var import_filterOrders = require("./modules/order/utils/filterOrders");
|
|
51
50
|
var import_filterBookings = require("./modules/order/utils/filterBookings");
|
|
52
|
-
var import_small_ticket = require("./utils/small-ticket");
|
|
53
51
|
__reExport(server_exports, require("./modules"), module.exports);
|
|
54
|
-
var PRODUCT_TITLE_SNAPSHOT_KEYS = [
|
|
55
|
-
"en",
|
|
56
|
-
"ja",
|
|
57
|
-
"pt",
|
|
58
|
-
"auto",
|
|
59
|
-
"zh-CN",
|
|
60
|
-
"zh-HK",
|
|
61
|
-
"kitchen",
|
|
62
|
-
"original"
|
|
63
|
-
];
|
|
64
52
|
var Server = class {
|
|
65
53
|
constructor(core) {
|
|
66
|
-
this.quotationAvailableCache = /* @__PURE__ */ new Map();
|
|
67
|
-
this.quotationAvailableInFlight = /* @__PURE__ */ new Map();
|
|
68
54
|
/** GET 前缀路由(最长前缀优先匹配) */
|
|
69
55
|
this.prefixRouterGet = [];
|
|
70
56
|
// 路由注册表
|
|
@@ -83,8 +69,6 @@ var Server = class {
|
|
|
83
69
|
this.bookingRemoteCache = /* @__PURE__ */ new Map();
|
|
84
70
|
this.BOOKING_REMOTE_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
85
71
|
this.BOOKING_REMOTE_CACHE_MAX_ENTRIES = 80;
|
|
86
|
-
this.salesSearchSubscribers = /* @__PURE__ */ new Map();
|
|
87
|
-
this.deviceTaskActionsRegistered = false;
|
|
88
72
|
this.floorPlanQuerySubscribers = /* @__PURE__ */ new Map();
|
|
89
73
|
// 模块注册表 - 定义所有可用的模块配置
|
|
90
74
|
this.moduleRegistry = {
|
|
@@ -136,15 +120,6 @@ var Server = class {
|
|
|
136
120
|
list: []
|
|
137
121
|
}
|
|
138
122
|
},
|
|
139
|
-
payment: {
|
|
140
|
-
name: "payment",
|
|
141
|
-
moduleClass: import_payment.PaymentServerModule,
|
|
142
|
-
moduleName: "server_payment",
|
|
143
|
-
version: "1.0.0",
|
|
144
|
-
defaultStore: {
|
|
145
|
-
payMethods: []
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
123
|
resource: {
|
|
149
124
|
name: "resource",
|
|
150
125
|
moduleClass: import_resource.ResourceModule,
|
|
@@ -168,67 +143,31 @@ var Server = class {
|
|
|
168
143
|
}
|
|
169
144
|
}
|
|
170
145
|
};
|
|
171
|
-
this.handlePaymentMethods = async ({ data, config }) => {
|
|
172
|
-
const payment = await this.getPaymentRouteModule();
|
|
173
|
-
const payMethods = await payment.getPayMethodListAsync({
|
|
174
|
-
shouldFilter: (data == null ? void 0 : data.filterPaymentMethods) === true || (config == null ? void 0 : config.filterPaymentMethods) === true
|
|
175
|
-
});
|
|
176
|
-
return {
|
|
177
|
-
code: 200,
|
|
178
|
-
status: true,
|
|
179
|
-
data: payMethods
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
this.handleQuotationAvailable = async ({ data }) => {
|
|
183
|
-
const queryPayload = data && typeof data === "object" ? { ...data } : {};
|
|
184
|
-
const cacheKey = this.stableSerialize(queryPayload);
|
|
185
|
-
if (this.quotationAvailableCache.has(cacheKey)) {
|
|
186
|
-
this.logInfo("handleQuotationAvailable: 命中运行时缓存", { cacheKey });
|
|
187
|
-
return this.quotationAvailableCache.get(cacheKey);
|
|
188
|
-
}
|
|
189
|
-
const inFlight = this.quotationAvailableInFlight.get(cacheKey);
|
|
190
|
-
if (inFlight) {
|
|
191
|
-
this.logInfo("handleQuotationAvailable: 复用进行中的请求", { cacheKey });
|
|
192
|
-
return inFlight;
|
|
193
|
-
}
|
|
194
|
-
const requestPromise = this.fetchQuotationAvailableFromAPI(queryPayload).then((response) => {
|
|
195
|
-
if (this.isSuccessfulRemoteResponse(response)) {
|
|
196
|
-
this.quotationAvailableCache.set(cacheKey, response);
|
|
197
|
-
}
|
|
198
|
-
return response;
|
|
199
|
-
}).finally(() => {
|
|
200
|
-
this.quotationAvailableInFlight.delete(cacheKey);
|
|
201
|
-
});
|
|
202
|
-
this.quotationAvailableInFlight.set(cacheKey, requestPromise);
|
|
203
|
-
return requestPromise;
|
|
204
|
-
};
|
|
205
146
|
/**
|
|
206
147
|
* 处理商品查询请求
|
|
207
148
|
* 存储订阅者信息,便于数据变更时推送最新结果
|
|
208
149
|
*/
|
|
209
150
|
this.handleProductQuery = async ({ url, method, data, config }) => {
|
|
210
151
|
console.log("[Server] handleProductQuery:", url, method, data, config);
|
|
211
|
-
const { menu_list_ids, schedule_datetime, schedule_date, customer_id
|
|
152
|
+
const { menu_list_ids, schedule_datetime, schedule_date, customer_id } = data;
|
|
212
153
|
const { callback, subscriberId } = config || {};
|
|
213
154
|
this.logInfo("handleProductQuery: 开始处理商品查询请求", {
|
|
214
155
|
menu_list_ids,
|
|
215
|
-
ids,
|
|
216
156
|
schedule_datetime,
|
|
217
157
|
schedule_date,
|
|
218
|
-
customer_id
|
|
219
|
-
extension_type
|
|
158
|
+
customer_id
|
|
220
159
|
});
|
|
221
160
|
if (subscriberId && typeof callback === "function") {
|
|
222
161
|
this.productQuerySubscribers.set(subscriberId, {
|
|
223
162
|
callback,
|
|
224
|
-
context: { menu_list_ids,
|
|
163
|
+
context: { menu_list_ids, schedule_date, schedule_datetime, customer_id }
|
|
225
164
|
});
|
|
226
165
|
this.logInfo("handleProductQuery: 已注册订阅者", {
|
|
227
166
|
subscriberId,
|
|
228
167
|
totalSubscribers: this.productQuerySubscribers.size
|
|
229
168
|
});
|
|
230
169
|
}
|
|
231
|
-
return this.computeProductQueryResult({ menu_list_ids,
|
|
170
|
+
return this.computeProductQueryResult({ menu_list_ids, schedule_date, schedule_datetime, customer_id });
|
|
232
171
|
};
|
|
233
172
|
/**
|
|
234
173
|
* 按商品 id 查询单条(GET /shop/product/query/:productId)
|
|
@@ -330,41 +269,6 @@ var Server = class {
|
|
|
330
269
|
}
|
|
331
270
|
return { code: 200, message: "ok", status: true };
|
|
332
271
|
};
|
|
333
|
-
/**
|
|
334
|
-
* 处理 sales 单模块搜索:请求透传后端,仅在 OS 层维护已返回订单号集合。
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* await this.handleSalesSearchModule({ url: '/shop/es/search/sales', method: 'post', data: { keyword: 'A' } })
|
|
338
|
-
*/
|
|
339
|
-
this.handleSalesSearchModule = async ({ data, config }) => {
|
|
340
|
-
return this.handleSalesSearchRequest("single", "/shop/es/search/sales", data, config);
|
|
341
|
-
};
|
|
342
|
-
/**
|
|
343
|
-
* 处理 sales 聚合搜索:请求透传后端,仅订阅 sales 分组的已返回订单号。
|
|
344
|
-
*
|
|
345
|
-
* @example
|
|
346
|
-
* await this.handleSalesSearchAggregate({ url: '/shop/es/search', method: 'post', data: { modules: [] } })
|
|
347
|
-
*/
|
|
348
|
-
this.handleSalesSearchAggregate = async ({ data, config }) => {
|
|
349
|
-
return this.handleSalesSearchRequest("aggregate", "/shop/es/search", data, config);
|
|
350
|
-
};
|
|
351
|
-
/**
|
|
352
|
-
* 取消 sales 搜索订阅。
|
|
353
|
-
*
|
|
354
|
-
* @example
|
|
355
|
-
* await this.handleUnsubscribeSalesSearch({ data: { subscriberId: 'global-search-order' } } as any)
|
|
356
|
-
*/
|
|
357
|
-
this.handleUnsubscribeSalesSearch = async ({ data }) => {
|
|
358
|
-
const { subscriberId } = data || {};
|
|
359
|
-
if (subscriberId) {
|
|
360
|
-
this.salesSearchSubscribers.delete(subscriberId);
|
|
361
|
-
this.logInfo("handleUnsubscribeSalesSearch: 已移除订阅者", {
|
|
362
|
-
subscriberId,
|
|
363
|
-
remaining: this.salesSearchSubscribers.size
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
return { code: 200, message: "ok", status: true };
|
|
367
|
-
};
|
|
368
272
|
/**
|
|
369
273
|
* 日历(compact_fields)场景下要直接在 SSE 层排除的订单类型:
|
|
370
274
|
* 这些类型不会出现在日历上,拉取它们只会浪费带宽并增加前端过滤成本。
|
|
@@ -468,13 +372,7 @@ var Server = class {
|
|
|
468
372
|
* @example 批量:GET /update/localOrder?order_ids=96971,96972,96973
|
|
469
373
|
*/
|
|
470
374
|
this.handleUpdateLocalOrder = async ({ url, data }) => {
|
|
471
|
-
var _a
|
|
472
|
-
if (typeof (data == null ? void 0 : data.order_id) === "string" && ((_a = data == null ? void 0 : data.order_id) == null ? void 0 : _a.startsWith("LOCAL_"))) {
|
|
473
|
-
return {
|
|
474
|
-
code: 200,
|
|
475
|
-
status: true
|
|
476
|
-
};
|
|
477
|
-
}
|
|
375
|
+
var _a;
|
|
478
376
|
const batchIds = this.parseOrderIdsParam(url, data);
|
|
479
377
|
if (batchIds.length > 0) {
|
|
480
378
|
return this.handleUpdateLocalOrdersBatch(batchIds);
|
|
@@ -490,7 +388,7 @@ var Server = class {
|
|
|
490
388
|
this.logError("handleUpdateLocalOrder: Order 模块未注册");
|
|
491
389
|
return { code: 500, status: false, message: "Order 模块未注册", data: null };
|
|
492
390
|
}
|
|
493
|
-
if (!((
|
|
391
|
+
if (!((_a = this.app) == null ? void 0 : _a.request)) {
|
|
494
392
|
this.logError("handleUpdateLocalOrder: app.request 不可用");
|
|
495
393
|
return { code: 500, status: false, message: "app.request 不可用", data: null };
|
|
496
394
|
}
|
|
@@ -553,149 +451,34 @@ var Server = class {
|
|
|
553
451
|
};
|
|
554
452
|
}
|
|
555
453
|
};
|
|
556
|
-
this.handleOrderSalesCheckout = async ({ data }) => {
|
|
557
|
-
return this.handleOrderCheckoutSubmit({
|
|
558
|
-
backendPath: "/shop/order/sales/checkout",
|
|
559
|
-
data,
|
|
560
|
-
title: "handleOrderSalesCheckout"
|
|
561
|
-
});
|
|
562
|
-
};
|
|
563
|
-
this.handleOrderCheckout = async ({ data }) => {
|
|
564
|
-
return this.handleOrderCheckoutSubmit({
|
|
565
|
-
backendPath: "/order/checkout",
|
|
566
|
-
data,
|
|
567
|
-
title: "handleOrderCheckout"
|
|
568
|
-
});
|
|
569
|
-
};
|
|
570
|
-
this.handleLocalPrintOrder = async ({ data }) => {
|
|
571
|
-
var _a;
|
|
572
|
-
try {
|
|
573
|
-
const inputOrder = (data == null ? void 0 : data.order) && typeof data.order === "object" ? data.order : data;
|
|
574
|
-
if (!inputOrder || typeof inputOrder !== "object") {
|
|
575
|
-
return {
|
|
576
|
-
code: 400,
|
|
577
|
-
status: false,
|
|
578
|
-
message: "订单数据不能为空",
|
|
579
|
-
data: { printed: false, order: null }
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
const shouldLookup = this.shouldLookupLocalPrintOrder(inputOrder) || this.shouldLookupLocalPrintOrder(data);
|
|
583
|
-
this.logInfo("handleLocalPrintOrder: 是否需要查找本地订单", {
|
|
584
|
-
shouldLookup,
|
|
585
|
-
inputOrder,
|
|
586
|
-
data
|
|
587
|
-
});
|
|
588
|
-
const lookup = shouldLookup ? this.getLocalPrintOrderLookup(inputOrder) ?? this.getLocalPrintOrderLookup(data) : void 0;
|
|
589
|
-
let sourceOrder = inputOrder;
|
|
590
|
-
if (shouldLookup) {
|
|
591
|
-
if (lookup === void 0) {
|
|
592
|
-
return {
|
|
593
|
-
code: 400,
|
|
594
|
-
status: false,
|
|
595
|
-
message: "订单 lookup 缺失",
|
|
596
|
-
data: { printed: false, order: null }
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
if (!((_a = this.order) == null ? void 0 : _a.getLocalOrderByLookup)) {
|
|
600
|
-
return {
|
|
601
|
-
code: 500,
|
|
602
|
-
status: false,
|
|
603
|
-
message: "Order 模块未注册",
|
|
604
|
-
data: { printed: false, order: null }
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
const localOrder = await this.order.getLocalOrderByLookup(lookup);
|
|
608
|
-
if (!localOrder) {
|
|
609
|
-
return {
|
|
610
|
-
code: 404,
|
|
611
|
-
status: false,
|
|
612
|
-
message: "订单不存在",
|
|
613
|
-
data: { printed: false, order: null }
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
sourceOrder = {
|
|
617
|
-
...localOrder,
|
|
618
|
-
...inputOrder,
|
|
619
|
-
order_id: localOrder.order_id ?? inputOrder.order_id ?? inputOrder.orderId,
|
|
620
|
-
external_sale_number: localOrder.external_sale_number ?? inputOrder.external_sale_number ?? inputOrder.externalSaleNumber
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
const checkoutData = await this.ensureCheckoutOrderNumbers(
|
|
624
|
-
{
|
|
625
|
-
...sourceOrder,
|
|
626
|
-
small_ticket_data_flag: 1
|
|
627
|
-
},
|
|
628
|
-
"handleLocalPrintOrder"
|
|
629
|
-
);
|
|
630
|
-
const printableOrder = {
|
|
631
|
-
...checkoutData,
|
|
632
|
-
need_sync: checkoutData.need_sync ?? 1
|
|
633
|
-
};
|
|
634
|
-
this.logInfo("handleLocalPrintOrder: 本地打印小票,构建触发任务前", {
|
|
635
|
-
checkoutData,
|
|
636
|
-
printableOrder
|
|
637
|
-
});
|
|
638
|
-
const printResult = await this.dispatchLocalReceiptPrint({
|
|
639
|
-
checkoutData,
|
|
640
|
-
order: printableOrder,
|
|
641
|
-
response: null,
|
|
642
|
-
requireFullyPaid: false
|
|
643
|
-
});
|
|
644
|
-
return {
|
|
645
|
-
code: 200,
|
|
646
|
-
status: true,
|
|
647
|
-
message: "",
|
|
648
|
-
data: {
|
|
649
|
-
printed: printResult.printed,
|
|
650
|
-
order: printResult.order
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
|
-
} catch (error) {
|
|
654
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
655
|
-
this.logError("handleLocalPrintOrder: 本地打印小票失败", { error: message });
|
|
656
|
-
return {
|
|
657
|
-
code: 500,
|
|
658
|
-
status: false,
|
|
659
|
-
message,
|
|
660
|
-
data: { printed: false, order: null }
|
|
661
|
-
};
|
|
662
|
-
}
|
|
663
|
-
};
|
|
664
454
|
this.handleOrderSalesDetail = async ({ url, data, path }) => {
|
|
665
455
|
var _a;
|
|
666
456
|
const requestPath = this.parseRequestPath(url, path);
|
|
667
|
-
const
|
|
668
|
-
this.logInfo("handleOrderSalesDetail: 开始处理", { url, path: requestPath,
|
|
669
|
-
if (!
|
|
670
|
-
this.logWarning("handleOrderSalesDetail:
|
|
671
|
-
return { code: 400, status: false, message: "
|
|
457
|
+
const orderId = this.extractOrderSalesDetailId(requestPath);
|
|
458
|
+
this.logInfo("handleOrderSalesDetail: 开始处理", { url, path: requestPath, orderId });
|
|
459
|
+
if (!orderId) {
|
|
460
|
+
this.logWarning("handleOrderSalesDetail: order_id 缺失", { url, path: requestPath });
|
|
461
|
+
return { code: 400, status: false, message: "order_id 缺失", data: null };
|
|
672
462
|
}
|
|
673
463
|
if (!this.order) {
|
|
674
464
|
this.logError("handleOrderSalesDetail: Order 模块未注册");
|
|
675
465
|
return { code: 500, status: false, message: "Order 模块未注册", data: null };
|
|
676
466
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
};
|
|
687
|
-
}
|
|
467
|
+
const localOrder = await this.order.getLocalOrderByOrderId(orderId);
|
|
468
|
+
if (localOrder) {
|
|
469
|
+
this.logInfo("handleOrderSalesDetail: 命中本地订单", { orderId });
|
|
470
|
+
return {
|
|
471
|
+
code: 200,
|
|
472
|
+
status: true,
|
|
473
|
+
message: "",
|
|
474
|
+
data: localOrder
|
|
475
|
+
};
|
|
688
476
|
}
|
|
689
477
|
if (!((_a = this.app) == null ? void 0 : _a.request)) {
|
|
690
478
|
this.logError("handleOrderSalesDetail: app.request 不可用");
|
|
691
|
-
return {
|
|
692
|
-
code: 500,
|
|
693
|
-
status: false,
|
|
694
|
-
message: "app.request 不可用",
|
|
695
|
-
data: null
|
|
696
|
-
};
|
|
479
|
+
return { code: 500, status: false, message: "app.request 不可用", data: null };
|
|
697
480
|
}
|
|
698
|
-
const backendPath = this.buildOrderSalesDetailBackendPath(
|
|
481
|
+
const backendPath = this.buildOrderSalesDetailBackendPath(orderId, data);
|
|
699
482
|
try {
|
|
700
483
|
const response = await this.app.request.get(backendPath, {
|
|
701
484
|
lookup_mode: "multi"
|
|
@@ -706,8 +489,8 @@ var Server = class {
|
|
|
706
489
|
});
|
|
707
490
|
const fresh = (response == null ? void 0 : response.data) ?? response;
|
|
708
491
|
if (!fresh || typeof fresh !== "object" || fresh.order_id == null) {
|
|
709
|
-
this.
|
|
710
|
-
|
|
492
|
+
this.logError("handleOrderSalesDetail: 后端返回订单为空", {
|
|
493
|
+
orderId,
|
|
711
494
|
backendPath
|
|
712
495
|
});
|
|
713
496
|
return {
|
|
@@ -718,9 +501,9 @@ var Server = class {
|
|
|
718
501
|
};
|
|
719
502
|
}
|
|
720
503
|
await this.order.upsertOrdersFromRemote([fresh]);
|
|
721
|
-
const savedOrder = await this.order.
|
|
504
|
+
const savedOrder = await this.order.getLocalOrderByOrderId(orderId);
|
|
722
505
|
if (!savedOrder) {
|
|
723
|
-
this.logError("handleOrderSalesDetail: 订单写入后回读失败", {
|
|
506
|
+
this.logError("handleOrderSalesDetail: 订单写入后回读失败", { orderId });
|
|
724
507
|
return {
|
|
725
508
|
code: 500,
|
|
726
509
|
status: false,
|
|
@@ -728,7 +511,7 @@ var Server = class {
|
|
|
728
511
|
data: null
|
|
729
512
|
};
|
|
730
513
|
}
|
|
731
|
-
this.logInfo("handleOrderSalesDetail: 远端订单已同步到本地", {
|
|
514
|
+
this.logInfo("handleOrderSalesDetail: 远端订单已同步到本地", { orderId });
|
|
732
515
|
return {
|
|
733
516
|
code: 200,
|
|
734
517
|
status: true,
|
|
@@ -738,7 +521,7 @@ var Server = class {
|
|
|
738
521
|
} catch (error) {
|
|
739
522
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
740
523
|
this.logError("handleOrderSalesDetail: 请求失败", {
|
|
741
|
-
|
|
524
|
+
orderId,
|
|
742
525
|
backendPath,
|
|
743
526
|
error: errorMessage
|
|
744
527
|
});
|
|
@@ -1107,7 +890,6 @@ var Server = class {
|
|
|
1107
890
|
moduleConfigs
|
|
1108
891
|
});
|
|
1109
892
|
this.registerServerRoutes();
|
|
1110
|
-
this.registerDeviceTaskActions();
|
|
1111
893
|
const registeredModules = await this.registerModules(moduleConfigs);
|
|
1112
894
|
if (autoPreload) {
|
|
1113
895
|
await this.preloadModulesData(registeredModules, options);
|
|
@@ -1123,11 +905,10 @@ var Server = class {
|
|
|
1123
905
|
this.core.effects.on(import_types.FloorPlanHooks.onFloorPlansChanged, () => {
|
|
1124
906
|
void this.recomputeAndNotifyFloorPlanQuery();
|
|
1125
907
|
});
|
|
1126
|
-
this.core.effects.on(import_types3.OrderHooks.onOrdersChanged, (
|
|
908
|
+
this.core.effects.on(import_types3.OrderHooks.onOrdersChanged, () => {
|
|
1127
909
|
this.recomputeAndNotifyOrderQuery();
|
|
1128
910
|
this.recomputeAndNotifyBookingQuery();
|
|
1129
911
|
this.syncBookingRemoteCacheFromOrderChanges();
|
|
1130
|
-
this.notifySalesSearchSubscribers(payload);
|
|
1131
912
|
});
|
|
1132
913
|
const duration = Date.now() - startTime;
|
|
1133
914
|
this.logInfo("Server 初始化完成", {
|
|
@@ -1136,236 +917,20 @@ var Server = class {
|
|
|
1136
917
|
});
|
|
1137
918
|
return registeredModules;
|
|
1138
919
|
}
|
|
1139
|
-
registerDeviceTaskActions() {
|
|
1140
|
-
if (this.deviceTaskActionsRegistered)
|
|
1141
|
-
return;
|
|
1142
|
-
const deviceTask = this.getDeviceTaskPlugin();
|
|
1143
|
-
if (!(deviceTask == null ? void 0 : deviceTask.registerAction)) {
|
|
1144
|
-
this.logWarning("registerDeviceTaskActions: deviceTask 插件不可用");
|
|
1145
|
-
return;
|
|
1146
|
-
}
|
|
1147
|
-
const registeredActions = new Set(
|
|
1148
|
-
typeof deviceTask.getActions === "function" ? (deviceTask.getActions() || []).map((action) => action == null ? void 0 : action.action).filter(Boolean) : []
|
|
1149
|
-
);
|
|
1150
|
-
const register = (definition) => {
|
|
1151
|
-
var _a;
|
|
1152
|
-
if (registeredActions.has(definition.action))
|
|
1153
|
-
return;
|
|
1154
|
-
(_a = deviceTask.registerAction) == null ? void 0 : _a.call(deviceTask, definition);
|
|
1155
|
-
registeredActions.add(definition.action);
|
|
1156
|
-
};
|
|
1157
|
-
register({
|
|
1158
|
-
action: "sync_sales",
|
|
1159
|
-
name: "同步订单",
|
|
1160
|
-
validate: (payload) => (payload == null ? void 0 : payload.backendPath) && (payload == null ? void 0 : payload.data) ? null : "缺少 backendPath 或 data",
|
|
1161
|
-
handler: (ctx) => this.handleSyncSalesTask(ctx)
|
|
1162
|
-
});
|
|
1163
|
-
this.deviceTaskActionsRegistered = true;
|
|
1164
|
-
this.logInfo("DeviceTask actions 已注册", {
|
|
1165
|
-
actions: ["sync_sales"]
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
async handleSyncSalesTask(ctx) {
|
|
1169
|
-
var _a, _b, _c;
|
|
1170
|
-
const payload = ((_a = ctx.task) == null ? void 0 : _a.payload) || {};
|
|
1171
|
-
const backendPath = payload.backendPath;
|
|
1172
|
-
const data = payload.data;
|
|
1173
|
-
const title = payload.title || "sync_sales";
|
|
1174
|
-
if (!backendPath || !data) {
|
|
1175
|
-
return this.taskFail("INVALID_PAYLOAD", "缺少 backendPath 或 data");
|
|
1176
|
-
}
|
|
1177
|
-
if (!((_b = this.app) == null ? void 0 : _b.request)) {
|
|
1178
|
-
this.logError(`${title}: sync_sales app.request 不可用`);
|
|
1179
|
-
return this.taskTimeout("app.request 不可用");
|
|
1180
|
-
}
|
|
1181
|
-
try {
|
|
1182
|
-
const syncResult = await this.runCheckoutSync({
|
|
1183
|
-
backendPath,
|
|
1184
|
-
data,
|
|
1185
|
-
title,
|
|
1186
|
-
externalSaleNumber: payload.external_sale_number,
|
|
1187
|
-
deviceId: (_c = ctx.task) == null ? void 0 : _c.device_id,
|
|
1188
|
-
persistCheckoutDataWithResponse: false
|
|
1189
|
-
});
|
|
1190
|
-
if (syncResult.rejected) {
|
|
1191
|
-
this.logError(`${title}: sync_sales 后端明确失败`, {
|
|
1192
|
-
backendPath,
|
|
1193
|
-
response: syncResult.errorResponse
|
|
1194
|
-
});
|
|
1195
|
-
return this.taskFail(
|
|
1196
|
-
"BACKEND_REJECTED",
|
|
1197
|
-
syncResult.message || "后端明确拒绝 checkout",
|
|
1198
|
-
syncResult.errorResponse
|
|
1199
|
-
);
|
|
1200
|
-
}
|
|
1201
|
-
return this.taskOk({
|
|
1202
|
-
order: syncResult.syncedOrder ?? null,
|
|
1203
|
-
response: syncResult.normalizedResponse
|
|
1204
|
-
});
|
|
1205
|
-
} catch (error) {
|
|
1206
|
-
const backendError = this.extractBackendErrorResponse(error);
|
|
1207
|
-
if (backendError) {
|
|
1208
|
-
const message = (backendError == null ? void 0 : backendError.message) || "后端明确拒绝 checkout";
|
|
1209
|
-
this.logError(`${title}: sync_sales 后端明确失败`, {
|
|
1210
|
-
backendPath,
|
|
1211
|
-
backendError
|
|
1212
|
-
});
|
|
1213
|
-
return this.taskFail("BACKEND_REJECTED", message, backendError);
|
|
1214
|
-
}
|
|
1215
|
-
const errorMessage = this.getUnknownErrorMessage(error);
|
|
1216
|
-
this.logError(`${title}: sync_sales 请求未明确成功`, {
|
|
1217
|
-
backendPath,
|
|
1218
|
-
error: errorMessage,
|
|
1219
|
-
error_detail: this.normalizeUnknownError(error)
|
|
1220
|
-
});
|
|
1221
|
-
return this.taskTimeout(errorMessage);
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
async runCheckoutSync(params) {
|
|
1225
|
-
var _a, _b;
|
|
1226
|
-
const { backendPath, title } = params;
|
|
1227
|
-
const normalizedData = await this.normalizeCheckoutSubmitData(params.data, title);
|
|
1228
|
-
const checkoutData = await this.ensureCheckoutOrderNumbers(normalizedData, title);
|
|
1229
|
-
const remoteCheckoutData = this.omitCheckoutSyncMode(checkoutData);
|
|
1230
|
-
if (!((_b = (_a = this.app) == null ? void 0 : _a.request) == null ? void 0 : _b.post)) {
|
|
1231
|
-
throw new Error("app.request 不可用");
|
|
1232
|
-
}
|
|
1233
|
-
const response = await this.app.request.post(backendPath, remoteCheckoutData, {
|
|
1234
|
-
isShopApi: true,
|
|
1235
|
-
customToast: () => {
|
|
1236
|
-
}
|
|
1237
|
-
});
|
|
1238
|
-
if (this.isCheckoutResponseRejected(response)) {
|
|
1239
|
-
return {
|
|
1240
|
-
rejected: true,
|
|
1241
|
-
message: (response == null ? void 0 : response.message) || "后端明确拒绝 checkout",
|
|
1242
|
-
errorResponse: response,
|
|
1243
|
-
response,
|
|
1244
|
-
normalizedResponse: this.normalizeCheckoutResponse(response),
|
|
1245
|
-
checkoutData: remoteCheckoutData
|
|
1246
|
-
};
|
|
1247
|
-
}
|
|
1248
|
-
const fresh = this.extractOrderDataFromCheckoutResponse(response);
|
|
1249
|
-
const externalSaleNumber = this.getCheckoutExternalSaleNumber(
|
|
1250
|
-
remoteCheckoutData,
|
|
1251
|
-
{
|
|
1252
|
-
external_sale_number: params.externalSaleNumber,
|
|
1253
|
-
data: remoteCheckoutData
|
|
1254
|
-
}
|
|
1255
|
-
);
|
|
1256
|
-
const syncedOrder = await this.persistSyncedCheckoutOrder({
|
|
1257
|
-
backendPath,
|
|
1258
|
-
checkoutData: remoteCheckoutData,
|
|
1259
|
-
externalSaleNumber,
|
|
1260
|
-
fresh,
|
|
1261
|
-
title,
|
|
1262
|
-
persistCheckoutDataWithResponse: params.persistCheckoutDataWithResponse === true
|
|
1263
|
-
});
|
|
1264
|
-
const printableSyncedOrder = syncedOrder ? this.buildSyncedOrderForPrint({
|
|
1265
|
-
syncedOrder,
|
|
1266
|
-
checkoutResponseOrder: fresh
|
|
1267
|
-
}) : void 0;
|
|
1268
|
-
if (printableSyncedOrder && this.shouldPrintSyncedOrder({
|
|
1269
|
-
checkoutData: remoteCheckoutData,
|
|
1270
|
-
syncedOrder: printableSyncedOrder
|
|
1271
|
-
})) {
|
|
1272
|
-
await this.dispatchPrintOtherReceiptTask({
|
|
1273
|
-
checkoutData: remoteCheckoutData,
|
|
1274
|
-
syncedOrder: printableSyncedOrder,
|
|
1275
|
-
response,
|
|
1276
|
-
deviceId: params.deviceId
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
return {
|
|
1280
|
-
rejected: false,
|
|
1281
|
-
response,
|
|
1282
|
-
normalizedResponse: this.normalizeCheckoutResponse(response),
|
|
1283
|
-
checkoutData: remoteCheckoutData,
|
|
1284
|
-
syncedOrder,
|
|
1285
|
-
fresh
|
|
1286
|
-
};
|
|
1287
|
-
}
|
|
1288
|
-
omitCheckoutSyncMode(data) {
|
|
1289
|
-
if (!data || typeof data !== "object")
|
|
1290
|
-
return data;
|
|
1291
|
-
const next = { ...data };
|
|
1292
|
-
delete next.sync_mode;
|
|
1293
|
-
delete next.syncMode;
|
|
1294
|
-
return next;
|
|
1295
|
-
}
|
|
1296
|
-
async persistSyncedCheckoutOrder(params) {
|
|
1297
|
-
const {
|
|
1298
|
-
backendPath,
|
|
1299
|
-
checkoutData,
|
|
1300
|
-
externalSaleNumber,
|
|
1301
|
-
fresh,
|
|
1302
|
-
title,
|
|
1303
|
-
persistCheckoutDataWithResponse
|
|
1304
|
-
} = params;
|
|
1305
|
-
const shouldMergeRemoteOrder = fresh ? this.isMergeableCheckoutOrder(fresh, externalSaleNumber) : false;
|
|
1306
|
-
let syncedOrder;
|
|
1307
|
-
if (this.order && fresh && (shouldMergeRemoteOrder || persistCheckoutDataWithResponse)) {
|
|
1308
|
-
syncedOrder = persistCheckoutDataWithResponse ? {
|
|
1309
|
-
...checkoutData,
|
|
1310
|
-
...fresh,
|
|
1311
|
-
external_sale_number: fresh.external_sale_number ?? externalSaleNumber,
|
|
1312
|
-
need_sync: 0
|
|
1313
|
-
} : {
|
|
1314
|
-
...fresh,
|
|
1315
|
-
external_sale_number: fresh.external_sale_number ?? externalSaleNumber,
|
|
1316
|
-
need_sync: 0
|
|
1317
|
-
};
|
|
1318
|
-
await this.order.upsertOrdersFromRemote([syncedOrder]);
|
|
1319
|
-
this.logInfo(`${title}: sync_sales 完整订单已同步到本地`, {
|
|
1320
|
-
order_id: fresh.order_id,
|
|
1321
|
-
external_sale_number: syncedOrder.external_sale_number,
|
|
1322
|
-
order_number: fresh.order_number,
|
|
1323
|
-
mergedRemoteOrder: shouldMergeRemoteOrder,
|
|
1324
|
-
persistedCheckoutDataWithResponse: persistCheckoutDataWithResponse
|
|
1325
|
-
});
|
|
1326
|
-
} else if (this.order && externalSaleNumber && typeof this.order.markOrderSyncedByExternalSaleNumber === "function") {
|
|
1327
|
-
const patch = this.buildCheckoutSyncSuccessPatch(fresh);
|
|
1328
|
-
const result = await this.order.markOrderSyncedByExternalSaleNumber({
|
|
1329
|
-
externalSaleNumber,
|
|
1330
|
-
patch
|
|
1331
|
-
});
|
|
1332
|
-
syncedOrder = (result == null ? void 0 : result.order) || {
|
|
1333
|
-
...checkoutData,
|
|
1334
|
-
...patch,
|
|
1335
|
-
external_sale_number: externalSaleNumber,
|
|
1336
|
-
need_sync: 0
|
|
1337
|
-
};
|
|
1338
|
-
this.logInfo(`${title}: sync_sales 已按 external_sale_number 标记本地订单`, {
|
|
1339
|
-
order_id: (syncedOrder == null ? void 0 : syncedOrder.order_id) ?? null,
|
|
1340
|
-
external_sale_number: externalSaleNumber,
|
|
1341
|
-
hasRemoteOrder: !!fresh,
|
|
1342
|
-
mergedRemoteOrder: false
|
|
1343
|
-
});
|
|
1344
|
-
} else {
|
|
1345
|
-
this.logWarning(`${title}: sync_sales Order 模块未注册`, {
|
|
1346
|
-
backendPath,
|
|
1347
|
-
external_sale_number: externalSaleNumber,
|
|
1348
|
-
order_id: fresh == null ? void 0 : fresh.order_id
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
|
-
return syncedOrder;
|
|
1352
|
-
}
|
|
1353
920
|
/**
|
|
1354
921
|
* 将普通层 QuotationModule 的报价单计算能力桥接到 Server Products 模块。
|
|
1355
922
|
*/
|
|
1356
923
|
async setupProductsQuotationPriceBridge() {
|
|
1357
924
|
var _a;
|
|
1358
925
|
if (!this.products) {
|
|
1359
|
-
this.
|
|
926
|
+
this.logWarning("setupProductsQuotationPriceBridge: Products 模块未注册");
|
|
1360
927
|
return;
|
|
1361
928
|
}
|
|
1362
929
|
if (!this.schedule) {
|
|
1363
|
-
this.
|
|
930
|
+
this.logWarning("setupProductsQuotationPriceBridge: Schedule 模块未注册");
|
|
1364
931
|
return;
|
|
1365
932
|
}
|
|
1366
933
|
try {
|
|
1367
|
-
await this.schedule.loadAllSchedule();
|
|
1368
|
-
this.products.clearPriceCache();
|
|
1369
934
|
await this.products.setupQuotationPriceBridge({
|
|
1370
935
|
scheduleModule: this.schedule,
|
|
1371
936
|
channel: (_a = this.core.context) == null ? void 0 : _a.channel
|
|
@@ -1653,26 +1218,6 @@ var Server = class {
|
|
|
1653
1218
|
path: "/shop/order/v2/list/unsubscribe",
|
|
1654
1219
|
handler: this.handleUnsubscribeOrderQuery.bind(this)
|
|
1655
1220
|
},
|
|
1656
|
-
{
|
|
1657
|
-
method: "post",
|
|
1658
|
-
path: "/shop/es/search/sales",
|
|
1659
|
-
handler: this.handleSalesSearchModule.bind(this)
|
|
1660
|
-
},
|
|
1661
|
-
{
|
|
1662
|
-
method: "post",
|
|
1663
|
-
path: "/shop/es/search/sales/unsubscribe",
|
|
1664
|
-
handler: this.handleUnsubscribeSalesSearch.bind(this)
|
|
1665
|
-
},
|
|
1666
|
-
{
|
|
1667
|
-
method: "post",
|
|
1668
|
-
path: "/shop/es/search",
|
|
1669
|
-
handler: this.handleSalesSearchAggregate.bind(this)
|
|
1670
|
-
},
|
|
1671
|
-
{
|
|
1672
|
-
method: "post",
|
|
1673
|
-
path: "/shop/es/search/unsubscribe",
|
|
1674
|
-
handler: this.handleUnsubscribeSalesSearch.bind(this)
|
|
1675
|
-
},
|
|
1676
1221
|
{
|
|
1677
1222
|
method: "get",
|
|
1678
1223
|
path: "/shop/schedule/booking",
|
|
@@ -1692,36 +1237,6 @@ var Server = class {
|
|
|
1692
1237
|
method: "get",
|
|
1693
1238
|
path: "/update/localOrder",
|
|
1694
1239
|
handler: this.handleUpdateLocalOrder.bind(this)
|
|
1695
|
-
},
|
|
1696
|
-
{
|
|
1697
|
-
method: "get",
|
|
1698
|
-
path: "/shop/pay/custom-payment/all",
|
|
1699
|
-
handler: this.handlePaymentMethods.bind(this)
|
|
1700
|
-
},
|
|
1701
|
-
{
|
|
1702
|
-
method: "get",
|
|
1703
|
-
path: "/shop/quotation/available",
|
|
1704
|
-
handler: this.handleQuotationAvailable.bind(this)
|
|
1705
|
-
},
|
|
1706
|
-
{
|
|
1707
|
-
method: "get",
|
|
1708
|
-
path: "/quotation/available",
|
|
1709
|
-
handler: this.handleQuotationAvailable.bind(this)
|
|
1710
|
-
},
|
|
1711
|
-
{
|
|
1712
|
-
method: "post",
|
|
1713
|
-
path: "/shop/order/sales/checkout",
|
|
1714
|
-
handler: this.handleOrderSalesCheckout.bind(this)
|
|
1715
|
-
},
|
|
1716
|
-
{
|
|
1717
|
-
method: "post",
|
|
1718
|
-
path: "/order/checkout",
|
|
1719
|
-
handler: this.handleOrderCheckout.bind(this)
|
|
1720
|
-
},
|
|
1721
|
-
{
|
|
1722
|
-
method: "post",
|
|
1723
|
-
path: "/shop/local/print-order",
|
|
1724
|
-
handler: this.handleLocalPrintOrder.bind(this)
|
|
1725
1240
|
}
|
|
1726
1241
|
]);
|
|
1727
1242
|
this.registerPrefixRoutes([
|
|
@@ -1737,50 +1252,6 @@ var Server = class {
|
|
|
1737
1252
|
}
|
|
1738
1253
|
]);
|
|
1739
1254
|
}
|
|
1740
|
-
async getPaymentRouteModule() {
|
|
1741
|
-
if (this.payment)
|
|
1742
|
-
return this.payment;
|
|
1743
|
-
if (this.paymentRouteModule)
|
|
1744
|
-
return this.paymentRouteModule;
|
|
1745
|
-
if (this.paymentRouteModuleInFlight)
|
|
1746
|
-
return this.paymentRouteModuleInFlight;
|
|
1747
|
-
this.paymentRouteModuleInFlight = (async () => {
|
|
1748
|
-
const module2 = new import_payment.PaymentServerModule("server_payment_route", "1.0.0");
|
|
1749
|
-
await module2.initialize(this.core, {
|
|
1750
|
-
store: { payMethods: [] }
|
|
1751
|
-
});
|
|
1752
|
-
this.paymentRouteModule = module2;
|
|
1753
|
-
return module2;
|
|
1754
|
-
})().finally(() => {
|
|
1755
|
-
this.paymentRouteModuleInFlight = void 0;
|
|
1756
|
-
});
|
|
1757
|
-
return this.paymentRouteModuleInFlight;
|
|
1758
|
-
}
|
|
1759
|
-
async fetchQuotationAvailableFromAPI(data) {
|
|
1760
|
-
var _a;
|
|
1761
|
-
const requester = ((_a = this.app) == null ? void 0 : _a.request) || this.core.getPlugin("request");
|
|
1762
|
-
if (!(requester == null ? void 0 : requester.get)) {
|
|
1763
|
-
this.logError("fetchQuotationAvailableFromAPI: request 不可用");
|
|
1764
|
-
return {
|
|
1765
|
-
code: 500,
|
|
1766
|
-
message: "request 不可用",
|
|
1767
|
-
data: { list: [] },
|
|
1768
|
-
status: false
|
|
1769
|
-
};
|
|
1770
|
-
}
|
|
1771
|
-
return requester.get("/shop/quotation/available", data);
|
|
1772
|
-
}
|
|
1773
|
-
isSuccessfulRemoteResponse(response) {
|
|
1774
|
-
if (!response)
|
|
1775
|
-
return false;
|
|
1776
|
-
if (response.status === false)
|
|
1777
|
-
return false;
|
|
1778
|
-
if (typeof response.status === "number" && response.status >= 400)
|
|
1779
|
-
return false;
|
|
1780
|
-
if (response.code !== void 0 && response.code !== 200 && response.code !== "200")
|
|
1781
|
-
return false;
|
|
1782
|
-
return true;
|
|
1783
|
-
}
|
|
1784
1255
|
/**
|
|
1785
1256
|
* 根据 subscriberId 移除商品查询订阅者
|
|
1786
1257
|
*/
|
|
@@ -1794,192 +1265,36 @@ var Server = class {
|
|
|
1794
1265
|
}
|
|
1795
1266
|
}
|
|
1796
1267
|
/**
|
|
1797
|
-
*
|
|
1798
|
-
* 搜索参数完全透传后端,OS 不做过滤、筛选、排序。
|
|
1268
|
+
* 从查询值中提取 YYYY-MM-DD 日期串。
|
|
1799
1269
|
*
|
|
1800
1270
|
* @example
|
|
1801
|
-
*
|
|
1271
|
+
* this.extractQueryDate('2026-04-15 09:58:00') // => '2026-04-15'
|
|
1802
1272
|
*/
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
const
|
|
1807
|
-
if (
|
|
1808
|
-
|
|
1809
|
-
const existing = this.salesSearchSubscribers.get(subscriberId);
|
|
1810
|
-
const shouldReset = resetVisibleOrderIds === true || !existing || existing.kind !== kind || existing.contextSignature !== contextSignature;
|
|
1811
|
-
const visibleOrderIds = shouldReset ? /* @__PURE__ */ new Set() : new Set(existing.visibleOrderIds);
|
|
1812
|
-
for (const orderId of this.extractSalesSearchOrderIds(kind, result)) {
|
|
1813
|
-
visibleOrderIds.add(orderId);
|
|
1814
|
-
}
|
|
1815
|
-
this.salesSearchSubscribers.set(subscriberId, {
|
|
1816
|
-
callback,
|
|
1817
|
-
kind,
|
|
1818
|
-
contextSignature,
|
|
1819
|
-
visibleOrderIds,
|
|
1820
|
-
lastResponseData: this.extractSalesSearchResponseData(result)
|
|
1821
|
-
});
|
|
1822
|
-
this.logInfo("handleSalesSearchRequest: 已注册/更新订阅者", {
|
|
1823
|
-
subscriberId,
|
|
1824
|
-
kind,
|
|
1825
|
-
shouldReset,
|
|
1826
|
-
visibleCount: visibleOrderIds.size
|
|
1827
|
-
});
|
|
1273
|
+
extractQueryDate(raw) {
|
|
1274
|
+
if (raw == null)
|
|
1275
|
+
return null;
|
|
1276
|
+
const date = (0, import_dayjs.default)(raw);
|
|
1277
|
+
if (date.isValid()) {
|
|
1278
|
+
return date.format("YYYY-MM-DD");
|
|
1828
1279
|
}
|
|
1829
|
-
|
|
1280
|
+
const text = String(raw).trim();
|
|
1281
|
+
if (!text)
|
|
1282
|
+
return null;
|
|
1283
|
+
return text.split("T")[0].split(" ")[0] || null;
|
|
1830
1284
|
}
|
|
1831
1285
|
/**
|
|
1832
|
-
*
|
|
1286
|
+
* 判断时间范围是否「开始和结束都不是今天」。
|
|
1833
1287
|
*
|
|
1834
1288
|
* @example
|
|
1835
|
-
*
|
|
1289
|
+
* this.isRangeBothNotToday('2026-04-13', '2026-04-14') // => true
|
|
1836
1290
|
*/
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
return
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
data: backendPath === "/shop/es/search" ? { results: [] } : { list: [], count: 0 },
|
|
1845
|
-
status: false
|
|
1846
|
-
};
|
|
1847
|
-
}
|
|
1848
|
-
try {
|
|
1849
|
-
const response = await this.app.request.post(backendPath, data, {
|
|
1850
|
-
isShopApi: true
|
|
1851
|
-
});
|
|
1852
|
-
const payload = (response == null ? void 0 : response.data) ?? response;
|
|
1853
|
-
return {
|
|
1854
|
-
code: (response == null ? void 0 : response.code) ?? 200,
|
|
1855
|
-
status: (response == null ? void 0 : response.status) ?? true,
|
|
1856
|
-
message: (response == null ? void 0 : response.message) ?? "",
|
|
1857
|
-
data: payload
|
|
1858
|
-
};
|
|
1859
|
-
} catch (error) {
|
|
1860
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1861
|
-
this.logError("fetchSalesSearchFromAPI: 请求失败", {
|
|
1862
|
-
backendPath,
|
|
1863
|
-
error: errorMessage
|
|
1864
|
-
});
|
|
1865
|
-
return {
|
|
1866
|
-
code: 500,
|
|
1867
|
-
message: errorMessage,
|
|
1868
|
-
data: backendPath === "/shop/es/search" ? { results: [] } : { list: [], count: 0 },
|
|
1869
|
-
status: false
|
|
1870
|
-
};
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
/**
|
|
1874
|
-
* 构建搜索订阅签名;页码变化不重置,可继续累计 visibleOrderIds。
|
|
1875
|
-
*
|
|
1876
|
-
* @example
|
|
1877
|
-
* const signature = this.buildSalesSearchSignature('single', { keyword: 'A', page: 2 })
|
|
1878
|
-
*/
|
|
1879
|
-
buildSalesSearchSignature(kind, payload) {
|
|
1880
|
-
return this.stableSerialize({
|
|
1881
|
-
kind,
|
|
1882
|
-
payload: this.stripSalesSearchPageParams(payload)
|
|
1883
|
-
});
|
|
1884
|
-
}
|
|
1885
|
-
/**
|
|
1886
|
-
* 移除页码参数,保留 page size、keyword、filters、sort 等查询语义参数。
|
|
1887
|
-
*
|
|
1888
|
-
* @example
|
|
1889
|
-
* this.stripSalesSearchPageParams({ page: 2, per_page: 20, keyword: 'A' })
|
|
1890
|
-
*/
|
|
1891
|
-
stripSalesSearchPageParams(value) {
|
|
1892
|
-
if (Array.isArray(value)) {
|
|
1893
|
-
return value.map((item) => this.stripSalesSearchPageParams(item));
|
|
1894
|
-
}
|
|
1895
|
-
if (!value || typeof value !== "object")
|
|
1896
|
-
return value;
|
|
1897
|
-
const next = {};
|
|
1898
|
-
for (const [key, item] of Object.entries(value)) {
|
|
1899
|
-
if (key === "page" || key === "skip")
|
|
1900
|
-
continue;
|
|
1901
|
-
next[key] = this.stripSalesSearchPageParams(item);
|
|
1902
|
-
}
|
|
1903
|
-
return next;
|
|
1904
|
-
}
|
|
1905
|
-
/**
|
|
1906
|
-
* 提取响应 data,兼容 OS 包装结构与后端直接响应结构。
|
|
1907
|
-
*
|
|
1908
|
-
* @example
|
|
1909
|
-
* const data = this.extractSalesSearchResponseData(result)
|
|
1910
|
-
*/
|
|
1911
|
-
extractSalesSearchResponseData(result) {
|
|
1912
|
-
return (result == null ? void 0 : result.data) ?? result;
|
|
1913
|
-
}
|
|
1914
|
-
/**
|
|
1915
|
-
* 从搜索响应中提取 sales 命中的订单号。
|
|
1916
|
-
*
|
|
1917
|
-
* @example
|
|
1918
|
-
* const ids = this.extractSalesSearchOrderIds('single', result)
|
|
1919
|
-
*/
|
|
1920
|
-
extractSalesSearchOrderIds(kind, result) {
|
|
1921
|
-
var _a;
|
|
1922
|
-
const data = this.extractSalesSearchResponseData(result);
|
|
1923
|
-
const list = kind === "aggregate" ? (_a = this.findSalesSearchAggregateGroup(data)) == null ? void 0 : _a.list : data == null ? void 0 : data.list;
|
|
1924
|
-
if (!Array.isArray(list))
|
|
1925
|
-
return [];
|
|
1926
|
-
return list.map((item) => this.getSalesSearchOrderId(item)).filter((id) => !!id);
|
|
1927
|
-
}
|
|
1928
|
-
/**
|
|
1929
|
-
* 查找聚合搜索响应中的 sales 分组。
|
|
1930
|
-
*
|
|
1931
|
-
* @example
|
|
1932
|
-
* const group = this.findSalesSearchAggregateGroup({ results: [{ module: 'sales' }] })
|
|
1933
|
-
*/
|
|
1934
|
-
findSalesSearchAggregateGroup(data) {
|
|
1935
|
-
const results = Array.isArray(data == null ? void 0 : data.results) ? data.results : [];
|
|
1936
|
-
return results.find((item) => (item == null ? void 0 : item.module) === "sales") || null;
|
|
1937
|
-
}
|
|
1938
|
-
/**
|
|
1939
|
-
* 从订单或搜索命中项中取订单号。
|
|
1940
|
-
*
|
|
1941
|
-
* @example
|
|
1942
|
-
* const id = this.getSalesSearchOrderId({ order_id: 1001 })
|
|
1943
|
-
*/
|
|
1944
|
-
getSalesSearchOrderId(order) {
|
|
1945
|
-
if (!order || typeof order !== "object")
|
|
1946
|
-
return null;
|
|
1947
|
-
const raw = order.order_id ?? order.id;
|
|
1948
|
-
if (raw === void 0 || raw === null || raw === "")
|
|
1949
|
-
return null;
|
|
1950
|
-
return String(raw);
|
|
1951
|
-
}
|
|
1952
|
-
/**
|
|
1953
|
-
* 从查询值中提取 YYYY-MM-DD 日期串。
|
|
1954
|
-
*
|
|
1955
|
-
* @example
|
|
1956
|
-
* this.extractQueryDate('2026-04-15 09:58:00') // => '2026-04-15'
|
|
1957
|
-
*/
|
|
1958
|
-
extractQueryDate(raw) {
|
|
1959
|
-
if (raw == null)
|
|
1960
|
-
return null;
|
|
1961
|
-
const date = (0, import_dayjs.default)(raw);
|
|
1962
|
-
if (date.isValid()) {
|
|
1963
|
-
return date.format("YYYY-MM-DD");
|
|
1964
|
-
}
|
|
1965
|
-
const text = String(raw).trim();
|
|
1966
|
-
if (!text)
|
|
1967
|
-
return null;
|
|
1968
|
-
return text.split("T")[0].split(" ")[0] || null;
|
|
1969
|
-
}
|
|
1970
|
-
/**
|
|
1971
|
-
* 判断时间范围是否「开始和结束都不是今天」。
|
|
1972
|
-
*
|
|
1973
|
-
* @example
|
|
1974
|
-
* this.isRangeBothNotToday('2026-04-13', '2026-04-14') // => true
|
|
1975
|
-
*/
|
|
1976
|
-
isRangeBothNotToday(startRaw, endRaw) {
|
|
1977
|
-
const startDate = this.extractQueryDate(startRaw);
|
|
1978
|
-
const endDate = this.extractQueryDate(endRaw);
|
|
1979
|
-
if (!startDate || !endDate)
|
|
1980
|
-
return false;
|
|
1981
|
-
const today = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
1982
|
-
return startDate !== today && endDate !== today;
|
|
1291
|
+
isRangeBothNotToday(startRaw, endRaw) {
|
|
1292
|
+
const startDate = this.extractQueryDate(startRaw);
|
|
1293
|
+
const endDate = this.extractQueryDate(endRaw);
|
|
1294
|
+
if (!startDate || !endDate)
|
|
1295
|
+
return false;
|
|
1296
|
+
const today = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
1297
|
+
return startDate !== today && endDate !== today;
|
|
1983
1298
|
}
|
|
1984
1299
|
/**
|
|
1985
1300
|
* 订单查询是否走本地:
|
|
@@ -2389,733 +1704,6 @@ var Server = class {
|
|
|
2389
1704
|
};
|
|
2390
1705
|
}
|
|
2391
1706
|
}
|
|
2392
|
-
getDeviceTaskPlugin() {
|
|
2393
|
-
var _a, _b;
|
|
2394
|
-
return ((_b = (_a = this.app) == null ? void 0 : _a.getPlugin) == null ? void 0 : _b.call(_a, "deviceTask")) || null;
|
|
2395
|
-
}
|
|
2396
|
-
getIdGeneratorPlugin() {
|
|
2397
|
-
var _a, _b;
|
|
2398
|
-
return ((_b = (_a = this.app) == null ? void 0 : _a.getPlugin) == null ? void 0 : _b.call(_a, "idGenerator")) || null;
|
|
2399
|
-
}
|
|
2400
|
-
getAppData(key) {
|
|
2401
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2402
|
-
const getData = (_b = (_a = this.core.getPlugin("app")) == null ? void 0 : _a.getData) == null ? void 0 : _b.call(_a);
|
|
2403
|
-
if (typeof getData === "function")
|
|
2404
|
-
return getData(key);
|
|
2405
|
-
const directValue = (_d = (_c = this.app) == null ? void 0 : _c.getData) == null ? void 0 : _d.call(_c, key);
|
|
2406
|
-
if (directValue !== void 0)
|
|
2407
|
-
return directValue;
|
|
2408
|
-
const coreData = ((_i = (_g = (_f = (_e = this.app) == null ? void 0 : _e.models) == null ? void 0 : _f.getStore) == null ? void 0 : (_h = _g.call(_f)).getDataByModel) == null ? void 0 : _i.call(_h, "core", "core")) || ((_o = (_m = (_l = (_k = (_j = this.app) == null ? void 0 : _j.data) == null ? void 0 : _k.store) == null ? void 0 : _l.getStore) == null ? void 0 : (_n = _m.call(_l)).getDataByModel) == null ? void 0 : _o.call(_n, "core", "core")) || ((_v = (_u = (_s = (_r = (_q = (_p = this.app) == null ? void 0 : _p.data) == null ? void 0 : _q.store) == null ? void 0 : _r.getStore) == null ? void 0 : (_t = _s.call(_r)).getDataByModel) == null ? void 0 : _u.call(_t, "core")) == null ? void 0 : _v.core);
|
|
2409
|
-
return coreData == null ? void 0 : coreData[key];
|
|
2410
|
-
}
|
|
2411
|
-
getSmallTicketShopInfo() {
|
|
2412
|
-
const shopInfo = this.getAppData("shop_info") || {};
|
|
2413
|
-
return {
|
|
2414
|
-
...shopInfo,
|
|
2415
|
-
currency_symbol: shopInfo.currency_symbol || this.getAppData("shop_symbol") || this.getAppData("currency_symbol"),
|
|
2416
|
-
currency_code: shopInfo.currency_code || this.getAppData("shop_currency_code") || this.getAppData("currency_code"),
|
|
2417
|
-
tax_title: shopInfo.tax_title || this.getAppData("tax_title"),
|
|
2418
|
-
tax_country_code: shopInfo.tax_country_code || this.getAppData("tax_country_code"),
|
|
2419
|
-
is_price_include_tax: shopInfo.is_price_include_tax ?? this.getAppData("is_price_include_tax")
|
|
2420
|
-
};
|
|
2421
|
-
}
|
|
2422
|
-
taskOk(result) {
|
|
2423
|
-
return { status: "success", result };
|
|
2424
|
-
}
|
|
2425
|
-
taskFail(code, message, result) {
|
|
2426
|
-
return {
|
|
2427
|
-
status: "failed",
|
|
2428
|
-
error: { code, message },
|
|
2429
|
-
...result !== void 0 ? { result } : {}
|
|
2430
|
-
};
|
|
2431
|
-
}
|
|
2432
|
-
taskTimeout(message) {
|
|
2433
|
-
return {
|
|
2434
|
-
status: "timeout",
|
|
2435
|
-
error: { code: "TIMEOUT", message }
|
|
2436
|
-
};
|
|
2437
|
-
}
|
|
2438
|
-
async getShortNumberOrDeviceId() {
|
|
2439
|
-
const getAsyncIotDeviceInfo = this.getAppData("async_iot_device_info");
|
|
2440
|
-
if (getAsyncIotDeviceInfo) {
|
|
2441
|
-
const res = await (getAsyncIotDeviceInfo == null ? void 0 : getAsyncIotDeviceInfo());
|
|
2442
|
-
if (res == null ? void 0 : res.short_number) {
|
|
2443
|
-
return res == null ? void 0 : res.short_number;
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
return String(this.getAppData("device_id") || 0).slice(-2);
|
|
2447
|
-
}
|
|
2448
|
-
buildCheckoutTaskIdempotencyKey(data) {
|
|
2449
|
-
const identity = (data == null ? void 0 : data.request_unique_idempotency_token) || (data == null ? void 0 : data.external_sale_number) || (data == null ? void 0 : data.order_id) || (data == null ? void 0 : data.shop_order_number) || (data == null ? void 0 : data.shop_full_order_number);
|
|
2450
|
-
if (identity === void 0 || identity === null || identity === "")
|
|
2451
|
-
return void 0;
|
|
2452
|
-
return `sync_sales:${identity}`;
|
|
2453
|
-
}
|
|
2454
|
-
isBlankCheckoutValue(value) {
|
|
2455
|
-
return value === void 0 || value === null || value === "";
|
|
2456
|
-
}
|
|
2457
|
-
isLocalCheckoutOrderId(orderId) {
|
|
2458
|
-
return typeof orderId === "string" && orderId.startsWith("LOCAL_");
|
|
2459
|
-
}
|
|
2460
|
-
async normalizeCheckoutSubmitData(data, title) {
|
|
2461
|
-
if (!data || typeof data !== "object")
|
|
2462
|
-
return data;
|
|
2463
|
-
const next = { ...data };
|
|
2464
|
-
const externalSaleNumber = next.external_sale_number;
|
|
2465
|
-
const shouldClearLocalOrderId = this.isLocalCheckoutOrderId(next.order_id);
|
|
2466
|
-
if (shouldClearLocalOrderId)
|
|
2467
|
-
next.order_id = null;
|
|
2468
|
-
const hasCheckoutOrderNumbers = !this.isBlankCheckoutValue(next.shop_order_number) && !this.isBlankCheckoutValue(next.shop_full_order_number);
|
|
2469
|
-
if (hasCheckoutOrderNumbers) {
|
|
2470
|
-
this.logInfo(`${title}: checkout 已携带订单号,跳过查重`, {
|
|
2471
|
-
original_order_id: data.order_id,
|
|
2472
|
-
order_id: next.order_id,
|
|
2473
|
-
external_sale_number: externalSaleNumber,
|
|
2474
|
-
shop_order_number: next.shop_order_number,
|
|
2475
|
-
shop_full_order_number: next.shop_full_order_number
|
|
2476
|
-
});
|
|
2477
|
-
return next;
|
|
2478
|
-
}
|
|
2479
|
-
if (this.isBlankCheckoutValue(externalSaleNumber)) {
|
|
2480
|
-
if (shouldClearLocalOrderId) {
|
|
2481
|
-
this.logInfo(`${title}: checkout 本地订单号已清理`, {
|
|
2482
|
-
original_order_id: data.order_id,
|
|
2483
|
-
order_id: next.order_id
|
|
2484
|
-
});
|
|
2485
|
-
}
|
|
2486
|
-
return next;
|
|
2487
|
-
}
|
|
2488
|
-
if (!this.order || typeof this.order.getLocalOrderFromMemoryByLookup !== "function") {
|
|
2489
|
-
if (shouldClearLocalOrderId) {
|
|
2490
|
-
this.logInfo(`${title}: checkout 本地订单号已清理`, {
|
|
2491
|
-
original_order_id: data.order_id,
|
|
2492
|
-
external_sale_number: externalSaleNumber
|
|
2493
|
-
});
|
|
2494
|
-
}
|
|
2495
|
-
return next;
|
|
2496
|
-
}
|
|
2497
|
-
try {
|
|
2498
|
-
const localOrder = this.order.getLocalOrderFromMemoryByLookup(externalSaleNumber);
|
|
2499
|
-
if (!localOrder) {
|
|
2500
|
-
if (shouldClearLocalOrderId) {
|
|
2501
|
-
this.logInfo(`${title}: checkout 本地订单号已清理`, {
|
|
2502
|
-
original_order_id: data.order_id,
|
|
2503
|
-
external_sale_number: externalSaleNumber,
|
|
2504
|
-
localOrderFound: false
|
|
2505
|
-
});
|
|
2506
|
-
}
|
|
2507
|
-
return next;
|
|
2508
|
-
}
|
|
2509
|
-
if (this.isBlankCheckoutValue(next.shop_order_number)) {
|
|
2510
|
-
next.shop_order_number = localOrder.shop_order_number;
|
|
2511
|
-
}
|
|
2512
|
-
if (this.isBlankCheckoutValue(next.shop_full_order_number)) {
|
|
2513
|
-
next.shop_full_order_number = localOrder.shop_full_order_number;
|
|
2514
|
-
}
|
|
2515
|
-
this.logInfo(`${title}: checkout 已复用本地订单号`, {
|
|
2516
|
-
original_order_id: data.order_id,
|
|
2517
|
-
order_id: next.order_id,
|
|
2518
|
-
external_sale_number: externalSaleNumber,
|
|
2519
|
-
local_order_id: localOrder.order_id,
|
|
2520
|
-
shop_order_number: next.shop_order_number,
|
|
2521
|
-
shop_full_order_number: next.shop_full_order_number
|
|
2522
|
-
});
|
|
2523
|
-
return next;
|
|
2524
|
-
} catch (error) {
|
|
2525
|
-
this.logWarning(`${title}: checkout 查找本地订单失败`, {
|
|
2526
|
-
external_sale_number: externalSaleNumber,
|
|
2527
|
-
error: this.getUnknownErrorMessage(error),
|
|
2528
|
-
error_detail: this.normalizeUnknownError(error)
|
|
2529
|
-
});
|
|
2530
|
-
return next;
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
async ensureCheckoutOrderNumbers(data, title) {
|
|
2534
|
-
if (!data || typeof data !== "object")
|
|
2535
|
-
return data;
|
|
2536
|
-
const next = { ...data };
|
|
2537
|
-
const needsShopOrderNumber = next.shop_order_number === void 0 || next.shop_order_number === null || next.shop_order_number === "";
|
|
2538
|
-
const needsShopFullOrderNumber = next.shop_full_order_number === void 0 || next.shop_full_order_number === null || next.shop_full_order_number === "";
|
|
2539
|
-
if (!needsShopOrderNumber && !needsShopFullOrderNumber)
|
|
2540
|
-
return next;
|
|
2541
|
-
const idGenerator = this.getIdGeneratorPlugin();
|
|
2542
|
-
if (!idGenerator) {
|
|
2543
|
-
this.logWarning(`${title}: idGenerator 插件不可用,无法生成订单号`, {
|
|
2544
|
-
needsShopOrderNumber,
|
|
2545
|
-
needsShopFullOrderNumber
|
|
2546
|
-
});
|
|
2547
|
-
return next;
|
|
2548
|
-
}
|
|
2549
|
-
try {
|
|
2550
|
-
if (needsShopOrderNumber && idGenerator.generateShopOrderNumber) {
|
|
2551
|
-
next.shop_order_number = await idGenerator.generateShopOrderNumber({
|
|
2552
|
-
biz: next.business_code || "ticket"
|
|
2553
|
-
});
|
|
2554
|
-
}
|
|
2555
|
-
if (needsShopFullOrderNumber && idGenerator.generateReceiptId) {
|
|
2556
|
-
next.shop_full_order_number = await idGenerator.generateReceiptId({
|
|
2557
|
-
biz: next.business_code || "ticket"
|
|
2558
|
-
});
|
|
2559
|
-
}
|
|
2560
|
-
this.logInfo(`${title}: checkout 订单号已准备`, {
|
|
2561
|
-
shop_order_number: next.shop_order_number,
|
|
2562
|
-
shop_full_order_number: next.shop_full_order_number
|
|
2563
|
-
});
|
|
2564
|
-
} catch (error) {
|
|
2565
|
-
this.logError(`${title}: 生成 checkout 订单号失败`, {
|
|
2566
|
-
error: error instanceof Error ? error.message : String(error)
|
|
2567
|
-
});
|
|
2568
|
-
}
|
|
2569
|
-
return next;
|
|
2570
|
-
}
|
|
2571
|
-
async dispatchCheckoutSyncTask(params) {
|
|
2572
|
-
var _a, _b, _c, _d;
|
|
2573
|
-
this.registerDeviceTaskActions();
|
|
2574
|
-
const deviceTask = this.getDeviceTaskPlugin();
|
|
2575
|
-
const debugDeviceId = await this.getShortNumberOrDeviceId();
|
|
2576
|
-
const debugIdempotencyKey = this.buildCheckoutTaskIdempotencyKey(params.data);
|
|
2577
|
-
if (!(deviceTask == null ? void 0 : deviceTask.dispatch)) {
|
|
2578
|
-
this.logError(`${params.title}: deviceTask.dispatch 不可用`);
|
|
2579
|
-
return;
|
|
2580
|
-
}
|
|
2581
|
-
try {
|
|
2582
|
-
const result = await deviceTask.dispatch({
|
|
2583
|
-
action: "sync_sales",
|
|
2584
|
-
device_id: debugDeviceId,
|
|
2585
|
-
payload: {
|
|
2586
|
-
backendPath: params.backendPath,
|
|
2587
|
-
data: params.data,
|
|
2588
|
-
external_sale_number: (_a = params.data) == null ? void 0 : _a.external_sale_number,
|
|
2589
|
-
title: params.title
|
|
2590
|
-
},
|
|
2591
|
-
retry_limit: 5,
|
|
2592
|
-
idempotency_key: debugIdempotencyKey,
|
|
2593
|
-
name: "同步订单",
|
|
2594
|
-
source: "server",
|
|
2595
|
-
source_type: "order",
|
|
2596
|
-
source_id: ((_b = params.data) == null ? void 0 : _b.order_id) || ((_c = params.data) == null ? void 0 : _c.external_sale_number) || ((_d = params.data) == null ? void 0 : _d.shop_order_number)
|
|
2597
|
-
});
|
|
2598
|
-
this.logInfo(`${params.title}: sync_sales 任务已派发`, {
|
|
2599
|
-
uuid: result == null ? void 0 : result.uuid,
|
|
2600
|
-
status: result == null ? void 0 : result.status,
|
|
2601
|
-
reused: result == null ? void 0 : result.reused
|
|
2602
|
-
});
|
|
2603
|
-
} catch (error) {
|
|
2604
|
-
this.logError(`${params.title}: 派发 sync_sales 任务失败`, {
|
|
2605
|
-
error: error instanceof Error ? error.message : String(error)
|
|
2606
|
-
});
|
|
2607
|
-
}
|
|
2608
|
-
}
|
|
2609
|
-
async dispatchPrintOtherReceiptTask(params) {
|
|
2610
|
-
var _a, _b, _c, _d, _e;
|
|
2611
|
-
const deviceTask = this.getDeviceTaskPlugin();
|
|
2612
|
-
if (!(deviceTask == null ? void 0 : deviceTask.dispatch)) {
|
|
2613
|
-
this.logWarning("dispatchPrintOtherReceiptTask: deviceTask.dispatch 不可用");
|
|
2614
|
-
return;
|
|
2615
|
-
}
|
|
2616
|
-
try {
|
|
2617
|
-
let printIdentity = this.getPrintOrderIdentity(params.syncedOrder);
|
|
2618
|
-
const deviceId = await this.getShortNumberOrDeviceId();
|
|
2619
|
-
await deviceTask.dispatch({
|
|
2620
|
-
action: "print_all",
|
|
2621
|
-
device_id: params.deviceId ?? deviceId,
|
|
2622
|
-
payload: {
|
|
2623
|
-
type: params.receiptOnly ? "0" : "99",
|
|
2624
|
-
data: params.receiptOnly ? {
|
|
2625
|
-
order_id: printIdentity,
|
|
2626
|
-
small_ticket_data: (_b = (_a = params.syncedOrder) == null ? void 0 : _a.payment_info) == null ? void 0 : _b.small_ticket_data
|
|
2627
|
-
} : {
|
|
2628
|
-
order_id: printIdentity,
|
|
2629
|
-
machine_code_print_info: (_d = (_c = params.syncedOrder) == null ? void 0 : _c.payment_info) == null ? void 0 : _d.machine_code_print_info,
|
|
2630
|
-
machine_code_print_info_v2: (_e = params.syncedOrder) == null ? void 0 : _e.machine_code_print_info_v2,
|
|
2631
|
-
skip_receipt: true
|
|
2632
|
-
}
|
|
2633
|
-
},
|
|
2634
|
-
idempotency_key: this.buildPrintOtherReceiptIdempotencyKey(params.syncedOrder, {
|
|
2635
|
-
receiptOnly: params.receiptOnly
|
|
2636
|
-
}),
|
|
2637
|
-
name: "打印转发",
|
|
2638
|
-
source: "server",
|
|
2639
|
-
source_type: "order",
|
|
2640
|
-
source_id: printIdentity
|
|
2641
|
-
});
|
|
2642
|
-
} catch (error) {
|
|
2643
|
-
this.logError("dispatchPrintOtherReceiptTask: 派发失败", {
|
|
2644
|
-
error: error instanceof Error ? error.message : String(error)
|
|
2645
|
-
});
|
|
2646
|
-
}
|
|
2647
|
-
}
|
|
2648
|
-
buildPrintOtherReceiptIdempotencyKey(order, options) {
|
|
2649
|
-
const identity = (order == null ? void 0 : order.external_sale_number) || (order == null ? void 0 : order.shop_order_number) || (order == null ? void 0 : order.shop_full_order_number) || (order == null ? void 0 : order.order_id);
|
|
2650
|
-
if (identity === void 0 || identity === null || identity === "")
|
|
2651
|
-
return void 0;
|
|
2652
|
-
return `${(options == null ? void 0 : options.receiptOnly) ? "print_receipt" : "print_voucher"}:${identity}:${Date.now()}`;
|
|
2653
|
-
}
|
|
2654
|
-
getPrintOrderIdentity(order) {
|
|
2655
|
-
return (order == null ? void 0 : order.order_id) || (order == null ? void 0 : order.external_sale_number) || (order == null ? void 0 : order.shop_order_number) || (order == null ? void 0 : order.shop_full_order_number);
|
|
2656
|
-
}
|
|
2657
|
-
async dispatchLocalReceiptPrint(params) {
|
|
2658
|
-
var _a;
|
|
2659
|
-
if (params.requireFullyPaid && !this.isSalesOrderFullyPaid(params.order)) {
|
|
2660
|
-
return { printed: false, order: params.order };
|
|
2661
|
-
}
|
|
2662
|
-
const printableOrder = await this.withLocalSmallTicketData(params.order, {
|
|
2663
|
-
requireFullyPaid: params.requireFullyPaid
|
|
2664
|
-
});
|
|
2665
|
-
if (!(0, import_small_ticket.hasSmallTicketData)((_a = printableOrder.payment_info) == null ? void 0 : _a.small_ticket_data)) {
|
|
2666
|
-
return { printed: false, order: printableOrder };
|
|
2667
|
-
}
|
|
2668
|
-
this.logInfo("dispatchLocalReceiptPrint: 构建触发任务前", {
|
|
2669
|
-
checkoutData: params.checkoutData,
|
|
2670
|
-
printableOrder,
|
|
2671
|
-
response: params.response
|
|
2672
|
-
});
|
|
2673
|
-
await this.dispatchPrintOtherReceiptTask({
|
|
2674
|
-
checkoutData: params.checkoutData,
|
|
2675
|
-
syncedOrder: printableOrder,
|
|
2676
|
-
response: params.response,
|
|
2677
|
-
receiptOnly: true
|
|
2678
|
-
});
|
|
2679
|
-
return { printed: true, order: printableOrder };
|
|
2680
|
-
}
|
|
2681
|
-
shouldLookupLocalPrintOrder(input) {
|
|
2682
|
-
const flag = (input == null ? void 0 : input.lookup_order_from_db) ?? (input == null ? void 0 : input.lookupOrderFromDb);
|
|
2683
|
-
return flag === true || flag === 1 || flag === "1";
|
|
2684
|
-
}
|
|
2685
|
-
getLocalPrintOrderLookup(input) {
|
|
2686
|
-
const orderId = (input == null ? void 0 : input.order_id) ?? (input == null ? void 0 : input.orderId);
|
|
2687
|
-
if (orderId !== void 0 && orderId !== null && orderId !== "")
|
|
2688
|
-
return orderId;
|
|
2689
|
-
const externalSaleNumber = (input == null ? void 0 : input.external_sale_number) ?? (input == null ? void 0 : input.externalSaleNumber);
|
|
2690
|
-
if (externalSaleNumber !== void 0 && externalSaleNumber !== null && externalSaleNumber !== "") {
|
|
2691
|
-
return externalSaleNumber;
|
|
2692
|
-
}
|
|
2693
|
-
return void 0;
|
|
2694
|
-
}
|
|
2695
|
-
async handleOrderCheckoutSubmit(params) {
|
|
2696
|
-
const { backendPath, data, title } = params;
|
|
2697
|
-
this.logInfo(`${title}: 开始处理`, {
|
|
2698
|
-
backendPath,
|
|
2699
|
-
order_id: data == null ? void 0 : data.order_id,
|
|
2700
|
-
external_sale_number: data == null ? void 0 : data.external_sale_number,
|
|
2701
|
-
order_number: data == null ? void 0 : data.order_number
|
|
2702
|
-
});
|
|
2703
|
-
if ((data == null ? void 0 : data.sync_mode) || (data == null ? void 0 : data.syncMode)) {
|
|
2704
|
-
return this.handleSyncCheckoutSubmit({
|
|
2705
|
-
backendPath,
|
|
2706
|
-
data,
|
|
2707
|
-
title
|
|
2708
|
-
});
|
|
2709
|
-
}
|
|
2710
|
-
const normalizedData = await this.normalizeCheckoutSubmitData(data, title);
|
|
2711
|
-
const checkoutData = await this.ensureCheckoutOrderNumbers(normalizedData, title);
|
|
2712
|
-
const pendingResult = await this.handlePendingSyncCheckoutOrder({
|
|
2713
|
-
backendPath,
|
|
2714
|
-
data: checkoutData,
|
|
2715
|
-
title,
|
|
2716
|
-
reason: "checkout 已转入设备任务同步"
|
|
2717
|
-
});
|
|
2718
|
-
if ((pendingResult == null ? void 0 : pendingResult.status) === true) {
|
|
2719
|
-
const pendingOrder = pendingResult.data;
|
|
2720
|
-
if (pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder) && // TODO 这里先加个兼容,只有 type 为 virtual 才走打印
|
|
2721
|
-
// 后期需要迁移到 picoding ,根据工作流配置
|
|
2722
|
-
checkoutData.type === "virtual") {
|
|
2723
|
-
await this.dispatchLocalReceiptPrint({
|
|
2724
|
-
checkoutData,
|
|
2725
|
-
order: pendingOrder,
|
|
2726
|
-
response: pendingResult,
|
|
2727
|
-
requireFullyPaid: true
|
|
2728
|
-
});
|
|
2729
|
-
}
|
|
2730
|
-
await this.dispatchCheckoutSyncTask({
|
|
2731
|
-
backendPath,
|
|
2732
|
-
data: checkoutData,
|
|
2733
|
-
title
|
|
2734
|
-
});
|
|
2735
|
-
}
|
|
2736
|
-
if (!pendingResult.data.order_id) {
|
|
2737
|
-
return {
|
|
2738
|
-
...pendingResult,
|
|
2739
|
-
data: {
|
|
2740
|
-
...pendingResult.data,
|
|
2741
|
-
order_id: pendingResult.data.external_sale_number
|
|
2742
|
-
}
|
|
2743
|
-
};
|
|
2744
|
-
}
|
|
2745
|
-
return pendingResult;
|
|
2746
|
-
}
|
|
2747
|
-
async handleSyncCheckoutSubmit(params) {
|
|
2748
|
-
var _a, _b;
|
|
2749
|
-
const { backendPath, data, title } = params;
|
|
2750
|
-
if (!((_b = (_a = this.app) == null ? void 0 : _a.request) == null ? void 0 : _b.post)) {
|
|
2751
|
-
this.logError(`${title}: sync checkout app.request 不可用`);
|
|
2752
|
-
return {
|
|
2753
|
-
code: 500,
|
|
2754
|
-
status: false,
|
|
2755
|
-
message: "app.request 不可用",
|
|
2756
|
-
data: null
|
|
2757
|
-
};
|
|
2758
|
-
}
|
|
2759
|
-
try {
|
|
2760
|
-
const syncResult = await this.runCheckoutSync({
|
|
2761
|
-
backendPath,
|
|
2762
|
-
data,
|
|
2763
|
-
title,
|
|
2764
|
-
persistCheckoutDataWithResponse: true
|
|
2765
|
-
});
|
|
2766
|
-
if (syncResult.rejected) {
|
|
2767
|
-
const normalized = this.normalizeCheckoutResponse(syncResult.errorResponse);
|
|
2768
|
-
return {
|
|
2769
|
-
...normalized,
|
|
2770
|
-
status: false,
|
|
2771
|
-
message: syncResult.message || (normalized == null ? void 0 : normalized.message) || "后端明确拒绝 checkout",
|
|
2772
|
-
data: (normalized == null ? void 0 : normalized.data) ?? null
|
|
2773
|
-
};
|
|
2774
|
-
}
|
|
2775
|
-
return this.withSyncedOrderIdInCheckoutResponse(
|
|
2776
|
-
syncResult.normalizedResponse,
|
|
2777
|
-
syncResult.syncedOrder
|
|
2778
|
-
);
|
|
2779
|
-
} catch (error) {
|
|
2780
|
-
const backendError = this.extractBackendErrorResponse(error);
|
|
2781
|
-
if (backendError) {
|
|
2782
|
-
const normalized = this.normalizeCheckoutResponse(backendError);
|
|
2783
|
-
return {
|
|
2784
|
-
...normalized,
|
|
2785
|
-
status: false,
|
|
2786
|
-
message: (backendError == null ? void 0 : backendError.message) || (normalized == null ? void 0 : normalized.message) || "后端明确拒绝 checkout",
|
|
2787
|
-
data: (normalized == null ? void 0 : normalized.data) ?? null
|
|
2788
|
-
};
|
|
2789
|
-
}
|
|
2790
|
-
const message = this.getUnknownErrorMessage(error);
|
|
2791
|
-
this.logError(`${title}: sync checkout 请求未明确成功`, {
|
|
2792
|
-
backendPath,
|
|
2793
|
-
error: message,
|
|
2794
|
-
error_detail: this.normalizeUnknownError(error)
|
|
2795
|
-
});
|
|
2796
|
-
return {
|
|
2797
|
-
code: 500,
|
|
2798
|
-
status: false,
|
|
2799
|
-
message,
|
|
2800
|
-
data: null
|
|
2801
|
-
};
|
|
2802
|
-
}
|
|
2803
|
-
}
|
|
2804
|
-
async handlePendingSyncCheckoutOrder(params) {
|
|
2805
|
-
var _a, _b, _c, _d;
|
|
2806
|
-
const { backendPath, data, title, reason } = params;
|
|
2807
|
-
const pendingOrder = await this.buildPendingSyncCheckoutOrder(data);
|
|
2808
|
-
if (!pendingOrder) {
|
|
2809
|
-
this.logError(`${title}: checkout 失败且订单缺少本地存储标识`, {
|
|
2810
|
-
backendPath,
|
|
2811
|
-
reason
|
|
2812
|
-
});
|
|
2813
|
-
return {
|
|
2814
|
-
code: 500,
|
|
2815
|
-
status: false,
|
|
2816
|
-
message: "订单缺少本地存储标识,无法写入待同步队列",
|
|
2817
|
-
data: null
|
|
2818
|
-
};
|
|
2819
|
-
}
|
|
2820
|
-
if (!this.order || typeof this.order.upsertPendingSyncOrders !== "function") {
|
|
2821
|
-
this.logError(`${title}: Order 模块不支持本地待同步写入`, {
|
|
2822
|
-
backendPath,
|
|
2823
|
-
reason
|
|
2824
|
-
});
|
|
2825
|
-
return {
|
|
2826
|
-
code: 500,
|
|
2827
|
-
status: false,
|
|
2828
|
-
message: "Order 模块不支持本地待同步写入",
|
|
2829
|
-
data: null
|
|
2830
|
-
};
|
|
2831
|
-
}
|
|
2832
|
-
try {
|
|
2833
|
-
await this.order.upsertPendingSyncOrders([pendingOrder]);
|
|
2834
|
-
this.logInfo(`${title}: 订单已写入本地待同步`, {
|
|
2835
|
-
backendPath,
|
|
2836
|
-
reason,
|
|
2837
|
-
order_id: pendingOrder.order_id,
|
|
2838
|
-
external_sale_number: pendingOrder.external_sale_number,
|
|
2839
|
-
order_number: pendingOrder.order_number
|
|
2840
|
-
});
|
|
2841
|
-
const changeGivenAmount = (_a = pendingOrder == null ? void 0 : pendingOrder.payments) == null ? void 0 : _a.reduce((sum, payment) => {
|
|
2842
|
-
var _a2;
|
|
2843
|
-
return sum + this.toAmountNumber((_a2 = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a2.change_given_amount);
|
|
2844
|
-
}, 0);
|
|
2845
|
-
return {
|
|
2846
|
-
code: 200,
|
|
2847
|
-
status: true,
|
|
2848
|
-
message: "",
|
|
2849
|
-
data: {
|
|
2850
|
-
...pendingOrder,
|
|
2851
|
-
amount_gap: (_b = pendingOrder == null ? void 0 : pendingOrder.summary) == null ? void 0 : _b.amount_gap,
|
|
2852
|
-
expect_amount: (_c = pendingOrder == null ? void 0 : pendingOrder.summary) == null ? void 0 : _c.expect_amount,
|
|
2853
|
-
total_amount: (_d = pendingOrder == null ? void 0 : pendingOrder.summary) == null ? void 0 : _d.total_amount,
|
|
2854
|
-
payment_status: pendingOrder == null ? void 0 : pendingOrder.payment_status,
|
|
2855
|
-
payment_info: {
|
|
2856
|
-
...(pendingOrder == null ? void 0 : pendingOrder.payment_info) || {},
|
|
2857
|
-
current_change_given_amount: changeGivenAmount
|
|
2858
|
-
}
|
|
2859
|
-
}
|
|
2860
|
-
};
|
|
2861
|
-
} catch (error) {
|
|
2862
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2863
|
-
this.logError(`${title}: 写入本地待同步订单失败`, {
|
|
2864
|
-
backendPath,
|
|
2865
|
-
reason,
|
|
2866
|
-
error: errorMessage
|
|
2867
|
-
});
|
|
2868
|
-
return { code: 500, status: false, message: errorMessage, data: null };
|
|
2869
|
-
}
|
|
2870
|
-
}
|
|
2871
|
-
async buildPendingSyncCheckoutOrder(data) {
|
|
2872
|
-
if (!data || typeof data !== "object")
|
|
2873
|
-
return null;
|
|
2874
|
-
const hasStorageKey = data.external_sale_number !== void 0 && data.external_sale_number !== null && data.external_sale_number !== "" ? true : data.order_id !== void 0 && data.order_id !== null && data.order_id !== "";
|
|
2875
|
-
if (!hasStorageKey)
|
|
2876
|
-
return null;
|
|
2877
|
-
const pendingOrder = {
|
|
2878
|
-
...data,
|
|
2879
|
-
need_sync: 1
|
|
2880
|
-
};
|
|
2881
|
-
const productMap = await this.buildSmallTicketProductMap(pendingOrder);
|
|
2882
|
-
const orderWithProductTitles = this.withPendingSyncProductTitles(
|
|
2883
|
-
pendingOrder,
|
|
2884
|
-
productMap
|
|
2885
|
-
);
|
|
2886
|
-
return this.withLocalSmallTicketData(
|
|
2887
|
-
orderWithProductTitles,
|
|
2888
|
-
{ requireFullyPaid: true, productMap }
|
|
2889
|
-
);
|
|
2890
|
-
}
|
|
2891
|
-
shouldBuildSmallTicketData(order) {
|
|
2892
|
-
var _a;
|
|
2893
|
-
if (!order || typeof order !== "object")
|
|
2894
|
-
return false;
|
|
2895
|
-
if ((0, import_small_ticket.hasSmallTicketData)((_a = order.payment_info) == null ? void 0 : _a.small_ticket_data))
|
|
2896
|
-
return false;
|
|
2897
|
-
return Number(order.small_ticket_data_flag ?? order.smallTicketDataFlag ?? 0) === 1;
|
|
2898
|
-
}
|
|
2899
|
-
shouldPrintSyncedOrder(params) {
|
|
2900
|
-
if (this.hasPaymentStatus(params.syncedOrder)) {
|
|
2901
|
-
return this.isSalesOrderFullyPaid(params.syncedOrder);
|
|
2902
|
-
}
|
|
2903
|
-
return this.isSalesOrderFullyPaid(params.checkoutData);
|
|
2904
|
-
}
|
|
2905
|
-
hasPaymentStatus(order) {
|
|
2906
|
-
return (order == null ? void 0 : order.payment_status) !== void 0 && (order == null ? void 0 : order.payment_status) !== null && (order == null ? void 0 : order.payment_status) !== "";
|
|
2907
|
-
}
|
|
2908
|
-
isSalesOrderFullyPaid(order) {
|
|
2909
|
-
var _a, _b, _c;
|
|
2910
|
-
if (!order || typeof order !== "object")
|
|
2911
|
-
return false;
|
|
2912
|
-
const paymentStatus = String(order.payment_status || "").toLowerCase();
|
|
2913
|
-
if (paymentStatus === "paid" || paymentStatus === "finished")
|
|
2914
|
-
return true;
|
|
2915
|
-
if (paymentStatus === "partially_paid" || paymentStatus === "payment_processing" || paymentStatus === "pending" || paymentStatus === "unpaid") {
|
|
2916
|
-
return false;
|
|
2917
|
-
}
|
|
2918
|
-
const amountGap = ((_a = order.summary) == null ? void 0 : _a.amount_gap) ?? order.amount_gap;
|
|
2919
|
-
if (amountGap !== void 0 && amountGap !== null && amountGap !== "") {
|
|
2920
|
-
return this.toAmountNumber(amountGap) <= 0;
|
|
2921
|
-
}
|
|
2922
|
-
const paidAmount = this.sumPaidOrderPayments(order.payments);
|
|
2923
|
-
const targetAmount = this.toAmountNumber(
|
|
2924
|
-
((_b = order.summary) == null ? void 0 : _b.expect_amount) ?? ((_c = order.summary) == null ? void 0 : _c.total_amount) ?? order.expect_amount ?? order.total_amount
|
|
2925
|
-
);
|
|
2926
|
-
if (targetAmount <= 0)
|
|
2927
|
-
return paidAmount > 0;
|
|
2928
|
-
return paidAmount >= targetAmount;
|
|
2929
|
-
}
|
|
2930
|
-
sumPaidOrderPayments(payments) {
|
|
2931
|
-
if (!Array.isArray(payments))
|
|
2932
|
-
return 0;
|
|
2933
|
-
return payments.reduce((sum, payment) => {
|
|
2934
|
-
const status = String((payment == null ? void 0 : payment.status) || "").toLowerCase();
|
|
2935
|
-
if (status === "voided" || status === "failed" || status === "cancelled")
|
|
2936
|
-
return sum;
|
|
2937
|
-
return sum + this.toAmountNumber((payment == null ? void 0 : payment.amount) ?? (payment == null ? void 0 : payment.origin_amount));
|
|
2938
|
-
}, 0);
|
|
2939
|
-
}
|
|
2940
|
-
toAmountNumber(value) {
|
|
2941
|
-
if (typeof value === "number")
|
|
2942
|
-
return Number.isFinite(value) ? value : 0;
|
|
2943
|
-
if (typeof value !== "string")
|
|
2944
|
-
return 0;
|
|
2945
|
-
const parsed = Number(value.replace(/[^\d.-]/g, ""));
|
|
2946
|
-
return Number.isFinite(parsed) ? parsed : 0;
|
|
2947
|
-
}
|
|
2948
|
-
async buildSmallTicketProductMap(order) {
|
|
2949
|
-
var _a;
|
|
2950
|
-
const products = Array.isArray(order == null ? void 0 : order.products) ? order.products : [];
|
|
2951
|
-
const productIdSet = /* @__PURE__ */ new Set();
|
|
2952
|
-
products.forEach((product) => {
|
|
2953
|
-
const productId = (product == null ? void 0 : product.product_id) ?? (product == null ? void 0 : product.id);
|
|
2954
|
-
if (productId !== void 0 && productId !== null && productId !== "") {
|
|
2955
|
-
productIdSet.add(productId);
|
|
2956
|
-
}
|
|
2957
|
-
if (Array.isArray(product == null ? void 0 : product.product_bundle)) {
|
|
2958
|
-
product.product_bundle.forEach((bundle) => {
|
|
2959
|
-
const bundleProductId = (bundle == null ? void 0 : bundle.bundle_product_id) ?? (bundle == null ? void 0 : bundle._bundle_product_id) ?? (bundle == null ? void 0 : bundle.product_id);
|
|
2960
|
-
if (bundleProductId !== void 0 && bundleProductId !== null && bundleProductId !== "") {
|
|
2961
|
-
productIdSet.add(bundleProductId);
|
|
2962
|
-
}
|
|
2963
|
-
});
|
|
2964
|
-
}
|
|
2965
|
-
});
|
|
2966
|
-
const productIds = Array.from(productIdSet);
|
|
2967
|
-
if (!productIds.length || typeof ((_a = this.products) == null ? void 0 : _a.getProductById) !== "function")
|
|
2968
|
-
return {};
|
|
2969
|
-
const entries = await Promise.all(
|
|
2970
|
-
productIds.map(async (id) => {
|
|
2971
|
-
var _a2, _b;
|
|
2972
|
-
try {
|
|
2973
|
-
const product = await ((_b = (_a2 = this.products) == null ? void 0 : _a2.getProductById) == null ? void 0 : _b.call(_a2, Number(id)));
|
|
2974
|
-
return product ? [String(id), product] : null;
|
|
2975
|
-
} catch (error) {
|
|
2976
|
-
this.logWarning("buildSmallTicketProductMap: 查询本地商品失败", {
|
|
2977
|
-
product_id: id,
|
|
2978
|
-
error: error instanceof Error ? error.message : String(error)
|
|
2979
|
-
});
|
|
2980
|
-
return null;
|
|
2981
|
-
}
|
|
2982
|
-
})
|
|
2983
|
-
);
|
|
2984
|
-
return entries.reduce((map, entry) => {
|
|
2985
|
-
if (!entry)
|
|
2986
|
-
return map;
|
|
2987
|
-
const [id, product] = entry;
|
|
2988
|
-
map[id] = product;
|
|
2989
|
-
return map;
|
|
2990
|
-
}, {});
|
|
2991
|
-
}
|
|
2992
|
-
withPendingSyncProductTitles(order, productMap) {
|
|
2993
|
-
const products = Array.isArray(order.products) ? order.products : null;
|
|
2994
|
-
if (!(products == null ? void 0 : products.length))
|
|
2995
|
-
return order;
|
|
2996
|
-
return {
|
|
2997
|
-
...order,
|
|
2998
|
-
products: products.map((product) => ({
|
|
2999
|
-
...product,
|
|
3000
|
-
product_title: this.buildProductTitleSnapshot(product, productMap)
|
|
3001
|
-
}))
|
|
3002
|
-
};
|
|
3003
|
-
}
|
|
3004
|
-
buildProductTitleSnapshot(product, productMap) {
|
|
3005
|
-
var _a, _b;
|
|
3006
|
-
const productId = product.product_id ?? product.id;
|
|
3007
|
-
const fallbackProduct = productId !== void 0 && productId !== null ? productMap[productId] || productMap[String(productId)] : null;
|
|
3008
|
-
const ownTitle = product.product_title || product.title || product.name || ((_a = product.product) == null ? void 0 : _a.title);
|
|
3009
|
-
const fallbackTitle = (fallbackProduct == null ? void 0 : fallbackProduct.product_title) || (fallbackProduct == null ? void 0 : fallbackProduct.title) || (fallbackProduct == null ? void 0 : fallbackProduct.name) || (fallbackProduct == null ? void 0 : fallbackProduct.format_title) || ((_b = fallbackProduct == null ? void 0 : fallbackProduct.product) == null ? void 0 : _b.title);
|
|
3010
|
-
const currentLocale = this.getProductTitleSnapshotCurrentLocale();
|
|
3011
|
-
const autoTitle = this.resolveFirstProductTitleValue(ownTitle) || this.resolveFirstProductTitleValue(fallbackTitle);
|
|
3012
|
-
return PRODUCT_TITLE_SNAPSHOT_KEYS.reduce((snapshot, key) => {
|
|
3013
|
-
snapshot[key] = this.resolveProductTitleValue(ownTitle, key, currentLocale) || this.resolveProductTitleValue(fallbackTitle, key, currentLocale) || (key === "auto" || key === "original" ? autoTitle : null);
|
|
3014
|
-
return snapshot;
|
|
3015
|
-
}, {});
|
|
3016
|
-
}
|
|
3017
|
-
getProductTitleSnapshotCurrentLocale() {
|
|
3018
|
-
var _a, _b;
|
|
3019
|
-
const shopInfo = this.getSmallTicketShopInfo();
|
|
3020
|
-
const rawLocale = shopInfo.primary_locale || this.getAppData("locale") || this.getAppData("language") || ((_a = this.core.context) == null ? void 0 : _a.locale) || ((_b = this.core.context) == null ? void 0 : _b.language);
|
|
3021
|
-
return this.normalizeProductTitleSnapshotLocale(rawLocale);
|
|
3022
|
-
}
|
|
3023
|
-
normalizeProductTitleSnapshotLocale(value) {
|
|
3024
|
-
if (typeof value !== "string" || !value)
|
|
3025
|
-
return null;
|
|
3026
|
-
const normalized = value.replace("_", "-");
|
|
3027
|
-
const matchedKey = PRODUCT_TITLE_SNAPSHOT_KEYS.find((key) => key === normalized);
|
|
3028
|
-
return matchedKey ?? null;
|
|
3029
|
-
}
|
|
3030
|
-
resolveProductTitleValue(value, key, currentLocale) {
|
|
3031
|
-
if (value === void 0 || value === null || value === "")
|
|
3032
|
-
return null;
|
|
3033
|
-
if (typeof value !== "object") {
|
|
3034
|
-
const title = String(value);
|
|
3035
|
-
if (key === "auto" || key === "original")
|
|
3036
|
-
return title;
|
|
3037
|
-
if (key === currentLocale && this.canAssignStringProductTitleToLocale(title, currentLocale))
|
|
3038
|
-
return title;
|
|
3039
|
-
return null;
|
|
3040
|
-
}
|
|
3041
|
-
const normalizedKey = key.replace("-", "_");
|
|
3042
|
-
const dashedKey = key.replace("_", "-");
|
|
3043
|
-
const rawValue = value[key] ?? value[normalizedKey] ?? value[dashedKey] ?? (key === "auto" ? value.default : void 0);
|
|
3044
|
-
if (rawValue === void 0 || rawValue === null || rawValue === "")
|
|
3045
|
-
return null;
|
|
3046
|
-
if (typeof rawValue === "object")
|
|
3047
|
-
return this.resolveFirstProductTitleValue(rawValue);
|
|
3048
|
-
return String(rawValue);
|
|
3049
|
-
}
|
|
3050
|
-
canAssignStringProductTitleToLocale(title, locale) {
|
|
3051
|
-
if (!locale)
|
|
3052
|
-
return false;
|
|
3053
|
-
if (locale === "zh-CN" || locale === "zh-HK" || locale === "kitchen") {
|
|
3054
|
-
return this.hasCjkText(title);
|
|
3055
|
-
}
|
|
3056
|
-
if (locale === "ja")
|
|
3057
|
-
return /[\u3040-\u30ff]/.test(title) || this.hasCjkText(title);
|
|
3058
|
-
if (locale === "en" || locale === "pt")
|
|
3059
|
-
return !this.hasCjkText(title);
|
|
3060
|
-
return false;
|
|
3061
|
-
}
|
|
3062
|
-
hasCjkText(value) {
|
|
3063
|
-
return /[\u3400-\u9fff]/.test(value);
|
|
3064
|
-
}
|
|
3065
|
-
resolveFirstProductTitleValue(value) {
|
|
3066
|
-
if (value === void 0 || value === null || value === "")
|
|
3067
|
-
return null;
|
|
3068
|
-
if (typeof value !== "object")
|
|
3069
|
-
return String(value);
|
|
3070
|
-
const preferredKeys = [
|
|
3071
|
-
"auto",
|
|
3072
|
-
"en",
|
|
3073
|
-
"original",
|
|
3074
|
-
"zh-CN",
|
|
3075
|
-
"zh_CN",
|
|
3076
|
-
"zh-HK",
|
|
3077
|
-
"zh_HK",
|
|
3078
|
-
"kitchen",
|
|
3079
|
-
"ja",
|
|
3080
|
-
"pt",
|
|
3081
|
-
"default"
|
|
3082
|
-
];
|
|
3083
|
-
for (const key of preferredKeys) {
|
|
3084
|
-
const rawValue = value[key];
|
|
3085
|
-
if (rawValue !== void 0 && rawValue !== null && rawValue !== "")
|
|
3086
|
-
return String(rawValue);
|
|
3087
|
-
}
|
|
3088
|
-
const firstValue = Object.values(value).find(
|
|
3089
|
-
(item) => item !== void 0 && item !== null && item !== ""
|
|
3090
|
-
);
|
|
3091
|
-
return firstValue === void 0 ? null : String(firstValue);
|
|
3092
|
-
}
|
|
3093
|
-
async withLocalSmallTicketData(order, options) {
|
|
3094
|
-
if (!this.shouldBuildSmallTicketData(order))
|
|
3095
|
-
return order;
|
|
3096
|
-
if ((options == null ? void 0 : options.requireFullyPaid) && !this.isSalesOrderFullyPaid(order))
|
|
3097
|
-
return order;
|
|
3098
|
-
try {
|
|
3099
|
-
const productMap = (options == null ? void 0 : options.productMap) ?? await this.buildSmallTicketProductMap(order);
|
|
3100
|
-
const smallTicketData = (0, import_small_ticket.buildSmallTicketData)({
|
|
3101
|
-
order,
|
|
3102
|
-
shopInfo: this.getSmallTicketShopInfo(),
|
|
3103
|
-
productMap
|
|
3104
|
-
});
|
|
3105
|
-
return {
|
|
3106
|
-
...order,
|
|
3107
|
-
payment_info: {
|
|
3108
|
-
...order.payment_info || {},
|
|
3109
|
-
small_ticket_data: smallTicketData
|
|
3110
|
-
}
|
|
3111
|
-
};
|
|
3112
|
-
} catch (error) {
|
|
3113
|
-
this.logError("withLocalSmallTicketData: 生成本地小票数据失败", {
|
|
3114
|
-
error: error instanceof Error ? error.message : String(error)
|
|
3115
|
-
});
|
|
3116
|
-
return order;
|
|
3117
|
-
}
|
|
3118
|
-
}
|
|
3119
1707
|
/**
|
|
3120
1708
|
* 解析 order_ids 入参,兼容 url query / data 字段、字符串(csv) / 数组两种形态。
|
|
3121
1709
|
* 自动 trim、去空、按字符串去重,输出归一化后的字符串数组。
|
|
@@ -3268,15 +1856,12 @@ var Server = class {
|
|
|
3268
1856
|
return null;
|
|
3269
1857
|
}
|
|
3270
1858
|
}
|
|
3271
|
-
|
|
1859
|
+
extractOrderSalesDetailId(url) {
|
|
3272
1860
|
const path = this.parseRequestPath(url);
|
|
3273
1861
|
const match = path.match(/^\/shop\/order\/sales\/([^/?#]+)$/);
|
|
3274
1862
|
return (match == null ? void 0 : match[1]) ? decodeURIComponent(match[1]) : null;
|
|
3275
1863
|
}
|
|
3276
|
-
|
|
3277
|
-
return (data == null ? void 0 : data.forceRemote) === true || (data == null ? void 0 : data.force_remote) === true;
|
|
3278
|
-
}
|
|
3279
|
-
buildOrderSalesDetailBackendPath(lookup, data) {
|
|
1864
|
+
buildOrderSalesDetailBackendPath(orderId, data) {
|
|
3280
1865
|
const rawWith = data && typeof data === "object" ? data.with : void 0;
|
|
3281
1866
|
const withFields = Array.isArray(rawWith) && rawWith.length > 0 ? rawWith : ["products", "scheduleEvents"];
|
|
3282
1867
|
const searchParams = new URLSearchParams();
|
|
@@ -3287,198 +1872,7 @@ var Server = class {
|
|
|
3287
1872
|
});
|
|
3288
1873
|
searchParams.append("lookup_mode", "multi");
|
|
3289
1874
|
const query = searchParams.toString();
|
|
3290
|
-
return `/shop/order/sales/${encodeURIComponent(
|
|
3291
|
-
}
|
|
3292
|
-
extractOrderDataFromCheckoutResponse(response) {
|
|
3293
|
-
var _a, _b;
|
|
3294
|
-
const candidates = [
|
|
3295
|
-
(_a = response == null ? void 0 : response.data) == null ? void 0 : _a.order,
|
|
3296
|
-
(_b = response == null ? void 0 : response.data) == null ? void 0 : _b.sales,
|
|
3297
|
-
response == null ? void 0 : response.data,
|
|
3298
|
-
response == null ? void 0 : response.order,
|
|
3299
|
-
response == null ? void 0 : response.sales,
|
|
3300
|
-
response
|
|
3301
|
-
];
|
|
3302
|
-
for (const candidate of candidates) {
|
|
3303
|
-
if (!candidate || typeof candidate !== "object")
|
|
3304
|
-
continue;
|
|
3305
|
-
if (candidate.order_id !== void 0 && candidate.order_id !== null) {
|
|
3306
|
-
return candidate;
|
|
3307
|
-
}
|
|
3308
|
-
}
|
|
3309
|
-
return null;
|
|
3310
|
-
}
|
|
3311
|
-
getCheckoutExternalSaleNumber(data, payload) {
|
|
3312
|
-
var _a;
|
|
3313
|
-
const candidates = [
|
|
3314
|
-
payload == null ? void 0 : payload.external_sale_number,
|
|
3315
|
-
data == null ? void 0 : data.external_sale_number,
|
|
3316
|
-
(_a = payload == null ? void 0 : payload.data) == null ? void 0 : _a.external_sale_number
|
|
3317
|
-
];
|
|
3318
|
-
const value = candidates.find((candidate) => candidate !== void 0 && candidate !== null && candidate !== "");
|
|
3319
|
-
return value === void 0 ? void 0 : String(value);
|
|
3320
|
-
}
|
|
3321
|
-
buildCheckoutSyncSuccessPatch(fresh) {
|
|
3322
|
-
if (!fresh)
|
|
3323
|
-
return {};
|
|
3324
|
-
const patch = {};
|
|
3325
|
-
if (fresh.order_id !== void 0 && fresh.order_id !== null)
|
|
3326
|
-
patch.order_id = fresh.order_id;
|
|
3327
|
-
if (fresh.order_number !== void 0 && fresh.order_number !== null) {
|
|
3328
|
-
patch.order_number = fresh.order_number;
|
|
3329
|
-
}
|
|
3330
|
-
return patch;
|
|
3331
|
-
}
|
|
3332
|
-
buildSyncedOrderForPrint(params) {
|
|
3333
|
-
const { syncedOrder, checkoutResponseOrder } = params;
|
|
3334
|
-
if (!checkoutResponseOrder || typeof checkoutResponseOrder !== "object")
|
|
3335
|
-
return syncedOrder;
|
|
3336
|
-
const printableOrder = { ...syncedOrder };
|
|
3337
|
-
const responseOrder = checkoutResponseOrder;
|
|
3338
|
-
if (responseOrder.order_id !== void 0 && responseOrder.order_id !== null) {
|
|
3339
|
-
printableOrder.order_id = responseOrder.order_id;
|
|
3340
|
-
}
|
|
3341
|
-
if (responseOrder.payment_status !== void 0 && responseOrder.payment_status !== null) {
|
|
3342
|
-
printableOrder.payment_status = responseOrder.payment_status;
|
|
3343
|
-
}
|
|
3344
|
-
if (responseOrder.expect_amount !== void 0 && responseOrder.expect_amount !== null) {
|
|
3345
|
-
printableOrder.expect_amount = responseOrder.expect_amount;
|
|
3346
|
-
}
|
|
3347
|
-
if (responseOrder.machine_code_print_info_v2 !== void 0) {
|
|
3348
|
-
printableOrder.machine_code_print_info_v2 = responseOrder.machine_code_print_info_v2;
|
|
3349
|
-
}
|
|
3350
|
-
if (responseOrder.payment_info && typeof responseOrder.payment_info === "object") {
|
|
3351
|
-
printableOrder.payment_info = {
|
|
3352
|
-
...syncedOrder.payment_info || {},
|
|
3353
|
-
...responseOrder.payment_info
|
|
3354
|
-
};
|
|
3355
|
-
}
|
|
3356
|
-
return printableOrder;
|
|
3357
|
-
}
|
|
3358
|
-
isMergeableCheckoutOrder(order, externalSaleNumber) {
|
|
3359
|
-
if (!order || typeof order !== "object")
|
|
3360
|
-
return false;
|
|
3361
|
-
const orderExternalSaleNumber = order.external_sale_number;
|
|
3362
|
-
if (externalSaleNumber && orderExternalSaleNumber !== void 0 && orderExternalSaleNumber !== null && String(orderExternalSaleNumber) !== externalSaleNumber) {
|
|
3363
|
-
return false;
|
|
3364
|
-
}
|
|
3365
|
-
if (externalSaleNumber && (orderExternalSaleNumber === void 0 || orderExternalSaleNumber === null || orderExternalSaleNumber === "")) {
|
|
3366
|
-
return false;
|
|
3367
|
-
}
|
|
3368
|
-
return Array.isArray(order.products) || Array.isArray(order.bookings) || Array.isArray(order.payments) || !!order.summary || order.order_number !== void 0 || order.payment_status !== void 0 || order.status !== void 0;
|
|
3369
|
-
}
|
|
3370
|
-
normalizeCheckoutResponse(response) {
|
|
3371
|
-
if (response && typeof response === "object" && (response.code !== void 0 || response.status !== void 0)) {
|
|
3372
|
-
return response;
|
|
3373
|
-
}
|
|
3374
|
-
return {
|
|
3375
|
-
code: 200,
|
|
3376
|
-
status: true,
|
|
3377
|
-
message: "",
|
|
3378
|
-
data: response
|
|
3379
|
-
};
|
|
3380
|
-
}
|
|
3381
|
-
withSyncedOrderIdInCheckoutResponse(response, syncedOrder) {
|
|
3382
|
-
const normalized = this.normalizeCheckoutResponse(response);
|
|
3383
|
-
const orderId = syncedOrder == null ? void 0 : syncedOrder.order_id;
|
|
3384
|
-
if (orderId === void 0 || orderId === null)
|
|
3385
|
-
return normalized;
|
|
3386
|
-
if (!(normalized == null ? void 0 : normalized.data) || typeof normalized.data !== "object")
|
|
3387
|
-
return normalized;
|
|
3388
|
-
return {
|
|
3389
|
-
...normalized,
|
|
3390
|
-
data: {
|
|
3391
|
-
...normalized.data,
|
|
3392
|
-
order_id: normalized.data.order_id ?? orderId
|
|
3393
|
-
}
|
|
3394
|
-
};
|
|
3395
|
-
}
|
|
3396
|
-
isCheckoutResponseRejected(response) {
|
|
3397
|
-
const normalized = this.normalizeCheckoutResponse(response);
|
|
3398
|
-
const isErrorCode = (normalized == null ? void 0 : normalized.code) !== void 0 && normalized.code !== 200 && normalized.code !== "200";
|
|
3399
|
-
const isErrorStatus = (normalized == null ? void 0 : normalized.status) === false || typeof (normalized == null ? void 0 : normalized.status) === "number" && normalized.status >= 400;
|
|
3400
|
-
const isErrorSuccess = (normalized == null ? void 0 : normalized.success) === false;
|
|
3401
|
-
return isErrorCode || isErrorStatus || isErrorSuccess;
|
|
3402
|
-
}
|
|
3403
|
-
getUnknownErrorMessage(error) {
|
|
3404
|
-
var _a, _b, _c, _d, _e, _f;
|
|
3405
|
-
if (error instanceof Error && error.message)
|
|
3406
|
-
return error.message;
|
|
3407
|
-
if (typeof error === "string")
|
|
3408
|
-
return error;
|
|
3409
|
-
const candidates = [
|
|
3410
|
-
error == null ? void 0 : error.message,
|
|
3411
|
-
(_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message,
|
|
3412
|
-
(_c = error == null ? void 0 : error.data) == null ? void 0 : _c.message,
|
|
3413
|
-
(_e = (_d = error == null ? void 0 : error.response) == null ? void 0 : _d.body) == null ? void 0 : _e.message,
|
|
3414
|
-
(_f = error == null ? void 0 : error.body) == null ? void 0 : _f.message
|
|
3415
|
-
];
|
|
3416
|
-
const message = candidates.find((candidate) => typeof candidate === "string" && candidate !== "");
|
|
3417
|
-
if (message)
|
|
3418
|
-
return message;
|
|
3419
|
-
const normalized = this.normalizeUnknownError(error);
|
|
3420
|
-
if (typeof normalized === "string")
|
|
3421
|
-
return normalized;
|
|
3422
|
-
try {
|
|
3423
|
-
return JSON.stringify(normalized);
|
|
3424
|
-
} catch {
|
|
3425
|
-
return String(error);
|
|
3426
|
-
}
|
|
3427
|
-
}
|
|
3428
|
-
normalizeUnknownError(error) {
|
|
3429
|
-
var _a, _b;
|
|
3430
|
-
if (error instanceof Error) {
|
|
3431
|
-
const normalized = {
|
|
3432
|
-
name: error.name,
|
|
3433
|
-
message: error.message,
|
|
3434
|
-
stack: error.stack
|
|
3435
|
-
};
|
|
3436
|
-
const record = error;
|
|
3437
|
-
if (((_a = record.response) == null ? void 0 : _a.data) !== void 0)
|
|
3438
|
-
normalized.responseData = record.response.data;
|
|
3439
|
-
if (record.data !== void 0)
|
|
3440
|
-
normalized.data = record.data;
|
|
3441
|
-
if (((_b = record.response) == null ? void 0 : _b.body) !== void 0)
|
|
3442
|
-
normalized.responseBody = record.response.body;
|
|
3443
|
-
if (record.body !== void 0)
|
|
3444
|
-
normalized.body = record.body;
|
|
3445
|
-
return this.safeJsonClone(normalized);
|
|
3446
|
-
}
|
|
3447
|
-
if (!error || typeof error !== "object")
|
|
3448
|
-
return String(error);
|
|
3449
|
-
return this.safeJsonClone(error);
|
|
3450
|
-
}
|
|
3451
|
-
safeJsonClone(value) {
|
|
3452
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
3453
|
-
try {
|
|
3454
|
-
return JSON.parse(JSON.stringify(value, (_key, current) => {
|
|
3455
|
-
if (!current || typeof current !== "object")
|
|
3456
|
-
return current;
|
|
3457
|
-
if (seen.has(current))
|
|
3458
|
-
return "[Circular]";
|
|
3459
|
-
seen.add(current);
|
|
3460
|
-
return current;
|
|
3461
|
-
}));
|
|
3462
|
-
} catch {
|
|
3463
|
-
return String(value);
|
|
3464
|
-
}
|
|
3465
|
-
}
|
|
3466
|
-
extractBackendErrorResponse(error) {
|
|
3467
|
-
var _a, _b;
|
|
3468
|
-
const candidates = [
|
|
3469
|
-
(_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data,
|
|
3470
|
-
error == null ? void 0 : error.data,
|
|
3471
|
-
(_b = error == null ? void 0 : error.response) == null ? void 0 : _b.body,
|
|
3472
|
-
error == null ? void 0 : error.body
|
|
3473
|
-
];
|
|
3474
|
-
return candidates.find(
|
|
3475
|
-
(candidate) => this.isExplicitBackendErrorResponse(candidate)
|
|
3476
|
-
) || null;
|
|
3477
|
-
}
|
|
3478
|
-
isExplicitBackendErrorResponse(candidate) {
|
|
3479
|
-
if (!candidate || typeof candidate !== "object")
|
|
3480
|
-
return false;
|
|
3481
|
-
return candidate.code !== void 0 || candidate.status !== void 0 || typeof candidate.message === "string";
|
|
1875
|
+
return `/shop/order/sales/${encodeURIComponent(orderId)}${query ? `?${query}` : ""}`;
|
|
3482
1876
|
}
|
|
3483
1877
|
/**
|
|
3484
1878
|
* 从 url 或路由 path 解析 pathname(不含 query,去掉末尾 /)
|
|
@@ -3646,38 +2040,6 @@ var Server = class {
|
|
|
3646
2040
|
status: true
|
|
3647
2041
|
};
|
|
3648
2042
|
}
|
|
3649
|
-
/**
|
|
3650
|
-
* 规范商品扩展类型过滤参数。
|
|
3651
|
-
*
|
|
3652
|
-
* @example
|
|
3653
|
-
* const types = this.normalizeProductExtensionTypes(['product_add_time']);
|
|
3654
|
-
*/
|
|
3655
|
-
normalizeProductExtensionTypes(extension_type) {
|
|
3656
|
-
if (!Array.isArray(extension_type))
|
|
3657
|
-
return [];
|
|
3658
|
-
return extension_type.map((item) => String(item || "").trim()).filter(Boolean);
|
|
3659
|
-
}
|
|
3660
|
-
/**
|
|
3661
|
-
* 请求包含 product_add_time 时,按传入 extension_type 数组配置过滤商品。
|
|
3662
|
-
*
|
|
3663
|
-
* @example
|
|
3664
|
-
* const list = this.filterProductsByExtensionTypes(products, ['product_add_time']);
|
|
3665
|
-
*/
|
|
3666
|
-
filterProductsByExtensionTypes(products, extension_type) {
|
|
3667
|
-
const extensionTypes = this.normalizeProductExtensionTypes(extension_type);
|
|
3668
|
-
if (!extensionTypes.includes("product_add_time"))
|
|
3669
|
-
return products;
|
|
3670
|
-
return products.filter((product) => extensionTypes.includes(String((product == null ? void 0 : product.extension_type) || "")));
|
|
3671
|
-
}
|
|
3672
|
-
/**
|
|
3673
|
-
* 判断本次查询是否需要跳过餐牌过滤,直接按扩展类型拉商品。
|
|
3674
|
-
*
|
|
3675
|
-
* @example
|
|
3676
|
-
* const skipMenu = this.shouldQueryProductsByExtensionTypes(['product_add_time']);
|
|
3677
|
-
*/
|
|
3678
|
-
shouldQueryProductsByExtensionTypes(extension_type) {
|
|
3679
|
-
return this.normalizeProductExtensionTypes(extension_type).includes("product_add_time");
|
|
3680
|
-
}
|
|
3681
2043
|
/**
|
|
3682
2044
|
* 商品查询的核心计算逻辑(编排 Products、Menu、Schedule 模块)
|
|
3683
2045
|
* 供 handleProductQuery 首次返回及 pubsub 变更推送复用
|
|
@@ -3687,15 +2049,12 @@ var Server = class {
|
|
|
3687
2049
|
*/
|
|
3688
2050
|
async computeProductQueryResult(context, options) {
|
|
3689
2051
|
const tTotal = performance.now();
|
|
3690
|
-
const { menu_list_ids,
|
|
3691
|
-
const queryIds = Array.isArray(ids) ? ids.map((id) => Number(id)).filter((id) => Number.isFinite(id)) : [];
|
|
2052
|
+
const { menu_list_ids, schedule_date, schedule_datetime, customer_id, product_id } = context;
|
|
3692
2053
|
this.logInfo("computeProductQueryResult 开始", {
|
|
3693
2054
|
menuListIdsCount: (menu_list_ids == null ? void 0 : menu_list_ids.length) ?? 0,
|
|
3694
|
-
ids: queryIds,
|
|
3695
2055
|
schedule_datetime,
|
|
3696
2056
|
schedule_date,
|
|
3697
2057
|
customer_id,
|
|
3698
|
-
extension_type,
|
|
3699
2058
|
product_id,
|
|
3700
2059
|
changedIds: options == null ? void 0 : options.changedIds
|
|
3701
2060
|
});
|
|
@@ -3703,39 +2062,6 @@ var Server = class {
|
|
|
3703
2062
|
this.logError("computeProductQueryResult: Products 模块未注册");
|
|
3704
2063
|
return { message: "Products 模块未注册", data: { list: [], count: 0 } };
|
|
3705
2064
|
}
|
|
3706
|
-
if (queryIds.length > 0) {
|
|
3707
|
-
const uniqueIds = Array.from(new Set(queryIds));
|
|
3708
|
-
const tPrice2 = performance.now();
|
|
3709
|
-
const productsWithPrice = await this.products.getProductsWithPrice(schedule_date, {
|
|
3710
|
-
scheduleModule: this.getSchedule(),
|
|
3711
|
-
schedule_datetime,
|
|
3712
|
-
customer_id
|
|
3713
|
-
}, {
|
|
3714
|
-
changedIds: options == null ? void 0 : options.changedIds,
|
|
3715
|
-
productIds: uniqueIds
|
|
3716
|
-
});
|
|
3717
|
-
(0, import_product.perfMark)("computeQuery.getProductsWithPrice(ids)", performance.now() - tPrice2, {
|
|
3718
|
-
count: productsWithPrice.length,
|
|
3719
|
-
ids: uniqueIds
|
|
3720
|
-
});
|
|
3721
|
-
const filteredProducts2 = productsWithPrice.filter((p) => uniqueIds.includes(Number(p == null ? void 0 : p.id))).filter((p) => ((p == null ? void 0 : p.status) || "published") === "published");
|
|
3722
|
-
const extensionFilteredProducts = this.filterProductsByExtensionTypes(filteredProducts2, extension_type);
|
|
3723
|
-
(0, import_product.perfMark)("computeProductQueryResult", performance.now() - tTotal, {
|
|
3724
|
-
mode: "ids",
|
|
3725
|
-
ids: uniqueIds,
|
|
3726
|
-
count: extensionFilteredProducts.length
|
|
3727
|
-
});
|
|
3728
|
-
this.logInfo("computeProductQueryResult 完成(ids)", {
|
|
3729
|
-
ids: uniqueIds,
|
|
3730
|
-
count: extensionFilteredProducts.length
|
|
3731
|
-
});
|
|
3732
|
-
return {
|
|
3733
|
-
code: 200,
|
|
3734
|
-
data: { list: extensionFilteredProducts, count: extensionFilteredProducts.length },
|
|
3735
|
-
message: "",
|
|
3736
|
-
status: true
|
|
3737
|
-
};
|
|
3738
|
-
}
|
|
3739
2065
|
if (product_id != null && Number.isFinite(Number(product_id))) {
|
|
3740
2066
|
const pid = Number(product_id);
|
|
3741
2067
|
const tPrice2 = performance.now();
|
|
@@ -3748,10 +2074,7 @@ var Server = class {
|
|
|
3748
2074
|
count: allProductsWithPrice.length,
|
|
3749
2075
|
productId: pid
|
|
3750
2076
|
});
|
|
3751
|
-
const published =
|
|
3752
|
-
allProductsWithPrice.filter((p) => ((p == null ? void 0 : p.status) || "published") === "published"),
|
|
3753
|
-
extension_type
|
|
3754
|
-
);
|
|
2077
|
+
const published = allProductsWithPrice.filter((p) => ((p == null ? void 0 : p.status) || "published") === "published");
|
|
3755
2078
|
const item = published.find((p) => Number(p.id) === pid) ?? null;
|
|
3756
2079
|
(0, import_product.perfMark)("computeProductQueryResult", performance.now() - tTotal, {
|
|
3757
2080
|
mode: "single",
|
|
@@ -3769,57 +2092,6 @@ var Server = class {
|
|
|
3769
2092
|
status: true
|
|
3770
2093
|
};
|
|
3771
2094
|
}
|
|
3772
|
-
if (this.shouldQueryProductsByExtensionTypes(extension_type)) {
|
|
3773
|
-
const tPrice2 = performance.now();
|
|
3774
|
-
let filteredProducts2 = await this.products.getProductsWithPrice(schedule_date, {
|
|
3775
|
-
scheduleModule: this.getSchedule(),
|
|
3776
|
-
schedule_datetime,
|
|
3777
|
-
customer_id
|
|
3778
|
-
}, {
|
|
3779
|
-
changedIds: options == null ? void 0 : options.changedIds
|
|
3780
|
-
});
|
|
3781
|
-
(0, import_product.perfMark)("computeQuery.getProductsWithPrice(extensionType)", performance.now() - tPrice2, {
|
|
3782
|
-
count: filteredProducts2.length,
|
|
3783
|
-
extension_type
|
|
3784
|
-
});
|
|
3785
|
-
const tStatus2 = performance.now();
|
|
3786
|
-
const beforeStatusCount2 = filteredProducts2.length;
|
|
3787
|
-
filteredProducts2 = filteredProducts2.filter((p) => ((p == null ? void 0 : p.status) || "published") === "published");
|
|
3788
|
-
(0, import_product.perfMark)("computeQuery.filterByStatus(extensionType)", performance.now() - tStatus2, {
|
|
3789
|
-
before: beforeStatusCount2,
|
|
3790
|
-
after: filteredProducts2.length
|
|
3791
|
-
});
|
|
3792
|
-
const tExtensionType2 = performance.now();
|
|
3793
|
-
const beforeExtensionTypeCount2 = filteredProducts2.length;
|
|
3794
|
-
filteredProducts2 = this.filterProductsByExtensionTypes(filteredProducts2, extension_type);
|
|
3795
|
-
(0, import_product.perfMark)("computeQuery.filterByExtensionType(extensionType)", performance.now() - tExtensionType2, {
|
|
3796
|
-
before: beforeExtensionTypeCount2,
|
|
3797
|
-
after: filteredProducts2.length,
|
|
3798
|
-
extension_type
|
|
3799
|
-
});
|
|
3800
|
-
const tSort2 = performance.now();
|
|
3801
|
-
filteredProducts2 = filteredProducts2.sort((a, b) => {
|
|
3802
|
-
const sortDiff = Number(b.sort) - Number(a.sort);
|
|
3803
|
-
if (sortDiff !== 0)
|
|
3804
|
-
return sortDiff;
|
|
3805
|
-
return (a.title || "").localeCompare(b.title || "");
|
|
3806
|
-
});
|
|
3807
|
-
(0, import_product.perfMark)("computeQuery.sort(extensionType)", performance.now() - tSort2, { count: filteredProducts2.length });
|
|
3808
|
-
(0, import_product.perfMark)("computeProductQueryResult", performance.now() - tTotal, {
|
|
3809
|
-
mode: "extensionType",
|
|
3810
|
-
filteredCount: filteredProducts2.length
|
|
3811
|
-
});
|
|
3812
|
-
this.logInfo("computeProductQueryResult 完成(extension_type)", {
|
|
3813
|
-
filteredCount: filteredProducts2.length,
|
|
3814
|
-
extension_type
|
|
3815
|
-
});
|
|
3816
|
-
return {
|
|
3817
|
-
code: 200,
|
|
3818
|
-
data: { list: filteredProducts2, count: filteredProducts2.length },
|
|
3819
|
-
message: "",
|
|
3820
|
-
status: true
|
|
3821
|
-
};
|
|
3822
|
-
}
|
|
3823
2095
|
if (!this.menu) {
|
|
3824
2096
|
this.logError("computeProductQueryResult: Menu 模块未注册");
|
|
3825
2097
|
return { message: "Menu 模块未注册", data: { list: [], count: 0 } };
|
|
@@ -3869,14 +2141,6 @@ var Server = class {
|
|
|
3869
2141
|
before: beforeStatusCount,
|
|
3870
2142
|
after: filteredProducts.length
|
|
3871
2143
|
});
|
|
3872
|
-
const tExtensionType = performance.now();
|
|
3873
|
-
const beforeExtensionTypeCount = filteredProducts.length;
|
|
3874
|
-
filteredProducts = this.filterProductsByExtensionTypes(filteredProducts, extension_type);
|
|
3875
|
-
(0, import_product.perfMark)("computeQuery.filterByExtensionType", performance.now() - tExtensionType, {
|
|
3876
|
-
before: beforeExtensionTypeCount,
|
|
3877
|
-
after: filteredProducts.length,
|
|
3878
|
-
extension_type
|
|
3879
|
-
});
|
|
3880
2144
|
const tSort = performance.now();
|
|
3881
2145
|
filteredProducts = filteredProducts.sort((a, b) => {
|
|
3882
2146
|
const sortDiff = Number(b.sort) - Number(a.sort);
|
|
@@ -3970,101 +2234,6 @@ var Server = class {
|
|
|
3970
2234
|
totalNotifyDurationMs: notifyEndAt - notifyStartAt
|
|
3971
2235
|
});
|
|
3972
2236
|
}
|
|
3973
|
-
/**
|
|
3974
|
-
* 订单变更后通知 sales 搜索订阅者。
|
|
3975
|
-
* 仅回传当前查询已返回订单号集合中的变更订单。
|
|
3976
|
-
*
|
|
3977
|
-
* @example
|
|
3978
|
-
* this.notifySalesSearchSubscribers({ list: [], changedOrders: [order], source: 'pubsub.bodyUpsert' })
|
|
3979
|
-
*/
|
|
3980
|
-
notifySalesSearchSubscribers(payload) {
|
|
3981
|
-
if (this.salesSearchSubscribers.size === 0)
|
|
3982
|
-
return;
|
|
3983
|
-
const changedOrders = this.extractChangedOrdersFromPayload(payload);
|
|
3984
|
-
if (changedOrders.length === 0) {
|
|
3985
|
-
return;
|
|
3986
|
-
}
|
|
3987
|
-
for (const [subscriberId, subscriber] of this.salesSearchSubscribers.entries()) {
|
|
3988
|
-
try {
|
|
3989
|
-
const changedVisibleOrders = changedOrders.filter((order) => {
|
|
3990
|
-
const orderId = this.getSalesSearchOrderId(order);
|
|
3991
|
-
return !!orderId && subscriber.visibleOrderIds.has(orderId);
|
|
3992
|
-
});
|
|
3993
|
-
if (changedVisibleOrders.length === 0) {
|
|
3994
|
-
continue;
|
|
3995
|
-
}
|
|
3996
|
-
subscriber.callback(
|
|
3997
|
-
this.buildSalesSearchDeltaResponse(subscriber, changedVisibleOrders)
|
|
3998
|
-
);
|
|
3999
|
-
this.logInfo("notifySalesSearchSubscribers: 已推送 delta", {
|
|
4000
|
-
subscriberId,
|
|
4001
|
-
kind: subscriber.kind,
|
|
4002
|
-
count: changedVisibleOrders.length
|
|
4003
|
-
});
|
|
4004
|
-
} catch (error) {
|
|
4005
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4006
|
-
this.logError("notifySalesSearchSubscribers: 推送失败", {
|
|
4007
|
-
subscriberId,
|
|
4008
|
-
error: errorMessage
|
|
4009
|
-
});
|
|
4010
|
-
}
|
|
4011
|
-
}
|
|
4012
|
-
}
|
|
4013
|
-
/**
|
|
4014
|
-
* 从订单变更事件中提取明确 delta。
|
|
4015
|
-
*
|
|
4016
|
-
* @example
|
|
4017
|
-
* const list = this.extractChangedOrdersFromPayload(payload)
|
|
4018
|
-
*/
|
|
4019
|
-
extractChangedOrdersFromPayload(payload) {
|
|
4020
|
-
if (!payload || Array.isArray(payload))
|
|
4021
|
-
return [];
|
|
4022
|
-
return Array.isArray(payload.changedOrders) ? payload.changedOrders : [];
|
|
4023
|
-
}
|
|
4024
|
-
/**
|
|
4025
|
-
* 构建与当前搜索接口一致的 delta 响应。
|
|
4026
|
-
*
|
|
4027
|
-
* @example
|
|
4028
|
-
* const response = this.buildSalesSearchDeltaResponse(subscriber, [order])
|
|
4029
|
-
*/
|
|
4030
|
-
buildSalesSearchDeltaResponse(subscriber, changedOrders) {
|
|
4031
|
-
if (subscriber.kind === "aggregate") {
|
|
4032
|
-
return this.buildAggregateSalesSearchDeltaResponse(subscriber, changedOrders);
|
|
4033
|
-
}
|
|
4034
|
-
const data = subscriber.lastResponseData || {};
|
|
4035
|
-
return {
|
|
4036
|
-
code: 200,
|
|
4037
|
-
status: true,
|
|
4038
|
-
message: "",
|
|
4039
|
-
data: {
|
|
4040
|
-
...data,
|
|
4041
|
-
list: changedOrders
|
|
4042
|
-
}
|
|
4043
|
-
};
|
|
4044
|
-
}
|
|
4045
|
-
/**
|
|
4046
|
-
* 构建聚合搜索接口的 sales 分组 delta 响应。
|
|
4047
|
-
*
|
|
4048
|
-
* @example
|
|
4049
|
-
* const response = this.buildAggregateSalesSearchDeltaResponse(subscriber, [order])
|
|
4050
|
-
*/
|
|
4051
|
-
buildAggregateSalesSearchDeltaResponse(subscriber, changedOrders) {
|
|
4052
|
-
const data = subscriber.lastResponseData || {};
|
|
4053
|
-
const results = Array.isArray(data == null ? void 0 : data.results) ? data.results : [];
|
|
4054
|
-
const hasSalesGroup = results.some((item) => (item == null ? void 0 : item.module) === "sales");
|
|
4055
|
-
const nextResults = hasSalesGroup ? results.map(
|
|
4056
|
-
(item) => (item == null ? void 0 : item.module) === "sales" ? { ...item, list: changedOrders } : item
|
|
4057
|
-
) : [{ module: "sales", list: changedOrders, count: changedOrders.length }];
|
|
4058
|
-
return {
|
|
4059
|
-
code: 200,
|
|
4060
|
-
status: true,
|
|
4061
|
-
message: "",
|
|
4062
|
-
data: {
|
|
4063
|
-
...data,
|
|
4064
|
-
results: nextResults
|
|
4065
|
-
}
|
|
4066
|
-
};
|
|
4067
|
-
}
|
|
4068
2237
|
/**
|
|
4069
2238
|
* 预约数据变更后,遍历订阅者重新计算并通过 callback 推送
|
|
4070
2239
|
*/
|