@pisell/pisellos 0.0.567 → 0.0.568
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/core/index.js +6 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/dist/model/strategy/adapter/walletPass/example.js +3 -26
- package/dist/model/strategy/adapter/walletPass/utils.js +0 -3
- package/dist/model/strategy/strategy-example.js +5 -19
- package/dist/modules/Cart/index.js +0 -3
- package/dist/modules/Cart/utils/cartProduct.js +0 -1
- package/dist/modules/Date/index.js +1 -5
- package/dist/modules/Discount/index.js +1 -4
- package/dist/modules/OpenData/index.js +0 -2
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/index.js +14 -41
- package/dist/modules/Payment/index.js +142 -270
- package/dist/modules/Payment/walletpass.js +4 -5
- package/dist/modules/Rules/index.js +0 -7
- package/dist/modules/Schedule/utils.js +0 -1
- package/dist/modules/Step/index.js +0 -1
- package/dist/plugins/request.js +1 -4
- package/dist/plugins/window.js +2 -6
- package/dist/server/index.js +88 -121
- package/dist/server/modules/menu/index.js +32 -41
- package/dist/server/modules/products/index.js +29 -49
- package/dist/server/modules/quotation/index.js +29 -38
- package/dist/server/modules/resource/index.js +3 -4
- package/dist/server/modules/schedule/index.js +32 -40
- package/dist/server/utils/product.js +0 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +7 -59
- package/dist/solution/BookingByStep/utils/capacity.js +1 -11
- package/dist/solution/BookingByStep/utils/resources.js +1 -3
- package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +5 -7
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
- package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
- package/dist/solution/BuyTickets/index.js +9 -12
- package/dist/solution/Checkout/index.js +177 -246
- package/dist/solution/Checkout/utils/index.js +4 -16
- package/dist/solution/RegisterAndLogin/index.js +30 -76
- package/dist/solution/ScanOrder/index.js +50 -60
- package/dist/solution/ShopDiscount/index.js +2 -7
- package/dist/solution/VenueBooking/index.d.ts +5 -0
- package/dist/solution/VenueBooking/index.js +364 -327
- package/dist/utils/task.js +15 -18
- package/dist/utils/watch.js +0 -1
- package/lib/apis/picoding.js +2 -0
- package/lib/core/index.js +130 -131
- package/lib/effects/index.js +46 -57
- package/lib/index.js +92 -53
- package/lib/model/index.js +14 -21
- package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
- package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
- package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
- package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
- package/lib/model/strategy/adapter/index.js +100 -64
- package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
- package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
- package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
- package/lib/model/strategy/adapter/itemRule/index.js +83 -57
- package/lib/model/strategy/adapter/itemRule/type.js +97 -36
- package/lib/model/strategy/adapter/promotion/adapter.js +84 -63
- package/lib/model/strategy/adapter/promotion/evaluator.js +381 -231
- package/lib/model/strategy/adapter/promotion/examples.js +139 -159
- package/lib/model/strategy/adapter/promotion/index.js +1 -49
- package/lib/model/strategy/adapter/promotion/type.js +199 -35
- package/lib/model/strategy/adapter/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -152
- package/lib/model/strategy/adapter/walletPass/example.js +217 -190
- package/lib/model/strategy/adapter/walletPass/index.js +75 -51
- package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
- package/lib/model/strategy/adapter/walletPass/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/utils.js +652 -402
- package/lib/model/strategy/engine.js +270 -168
- package/lib/model/strategy/index.js +49 -34
- package/lib/model/strategy/strategy-example.js +243 -239
- package/lib/model/strategy/type.js +100 -40
- package/lib/modules/Account/index.js +39 -53
- package/lib/modules/Account/types.js +20 -33
- package/lib/modules/AccountList/index.js +116 -154
- package/lib/modules/AccountList/types.js +30 -31
- package/lib/modules/AccountList/utils.js +18 -30
- package/lib/modules/BaseModule.js +22 -45
- package/lib/modules/Cart/index.js +170 -124
- package/lib/modules/Cart/types.js +46 -51
- package/lib/modules/Cart/utils/cartAccount.js +40 -39
- package/lib/modules/Cart/utils/cartDate.js +56 -61
- package/lib/modules/Cart/utils/cartDiscount.js +28 -33
- package/lib/modules/Cart/utils/cartNote.js +27 -32
- package/lib/modules/Cart/utils/cartProduct.js +306 -241
- package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
- package/lib/modules/Cart/utils/cartResource.js +72 -78
- package/lib/modules/Cart/utils/changePrice.js +26 -62
- package/lib/modules/Cart/utils/index.js +106 -48
- package/lib/modules/Customer/constants.js +13 -34
- package/lib/modules/Customer/index.js +216 -153
- package/lib/modules/Customer/types.js +38 -35
- package/lib/modules/Date/index.js +116 -115
- package/lib/modules/Date/types.js +16 -28
- package/lib/modules/Date/utils.js +174 -123
- package/lib/modules/Discount/index.js +117 -113
- package/lib/modules/Discount/types.js +9 -31
- package/lib/modules/Guests/index.js +30 -56
- package/lib/modules/Guests/types.js +23 -33
- package/lib/modules/Holder/index.js +209 -189
- package/lib/modules/Holder/types.js +4 -16
- package/lib/modules/Holder/utils.js +20 -49
- package/lib/modules/OpenData/index.js +63 -74
- package/lib/modules/OpenData/types.js +4 -16
- package/lib/modules/OpenData/utils.js +44 -78
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/index.js +332 -320
- package/lib/modules/Order/types.js +24 -33
- package/lib/modules/Order/utils.js +350 -284
- package/lib/modules/Payment/cash.js +20 -33
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
- package/lib/modules/Payment/eftpos.js +16 -30
- package/lib/modules/Payment/index.js +566 -432
- package/lib/modules/Payment/mx51.js +1 -0
- package/lib/modules/Payment/types.js +216 -107
- package/lib/modules/Payment/utils.js +50 -47
- package/lib/modules/Payment/walletpass.js +221 -203
- package/lib/modules/Product/index.js +51 -46
- package/lib/modules/Product/types.js +4 -16
- package/lib/modules/Product/utils.js +32 -33
- package/lib/modules/ProductList/index.js +111 -110
- package/lib/modules/ProductList/types.js +9 -31
- package/lib/modules/Quotation/index.js +60 -82
- package/lib/modules/Quotation/types.js +4 -16
- package/lib/modules/Resource/index.js +27 -59
- package/lib/modules/Resource/types.js +22 -32
- package/lib/modules/Resource/utils.js +30 -38
- package/lib/modules/Rules/index.js +1172 -872
- package/lib/modules/Rules/types.js +17 -40
- package/lib/modules/SalesSummary/index.js +59 -68
- package/lib/modules/SalesSummary/types.js +4 -16
- package/lib/modules/SalesSummary/utils.js +176 -193
- package/lib/modules/ScanOrderLogger/index.js +59 -79
- package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
- package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
- package/lib/modules/ScanOrderLogger/types.js +4 -16
- package/lib/modules/Schedule/getDateIsInSchedule.js +334 -167
- package/lib/modules/Schedule/index.js +97 -107
- package/lib/modules/Schedule/type.js +4 -16
- package/lib/modules/Schedule/types.js +4 -16
- package/lib/modules/Schedule/utils.js +433 -291
- package/lib/modules/Step/index.js +40 -52
- package/lib/modules/Step/tyeps.js +4 -16
- package/lib/modules/Summary/index.js +66 -70
- package/lib/modules/Summary/types.js +4 -16
- package/lib/modules/Summary/utils.js +782 -429
- package/lib/modules/index.js +212 -57
- package/lib/plugins/app.js +4 -16
- package/lib/plugins/index.js +36 -25
- package/lib/plugins/request.js +137 -126
- package/lib/plugins/shopStore.js +4 -16
- package/lib/plugins/user.js +4 -16
- package/lib/plugins/window.js +171 -179
- package/lib/server/index.js +882 -623
- package/lib/server/modules/index.js +85 -59
- package/lib/server/modules/menu/index.js +146 -122
- package/lib/server/modules/menu/types.js +18 -31
- package/lib/server/modules/order/index.js +195 -231
- package/lib/server/modules/order/types.js +107 -32
- package/lib/server/modules/order/utils/filterBookings.js +174 -140
- package/lib/server/modules/order/utils/filterOrders.js +89 -60
- package/lib/server/modules/products/index.js +430 -335
- package/lib/server/modules/products/types.js +41 -34
- package/lib/server/modules/quotation/index.js +76 -77
- package/lib/server/modules/quotation/types.js +21 -31
- package/lib/server/modules/resource/index.js +216 -187
- package/lib/server/modules/resource/types.js +42 -33
- package/lib/server/modules/schedule/index.js +134 -119
- package/lib/server/modules/schedule/types.js +14 -21
- package/lib/server/modules/schedule/utils.js +334 -163
- package/lib/server/types.js +4 -16
- package/lib/server/utils/index.js +25 -23
- package/lib/server/utils/product.js +196 -139
- package/lib/server/utils/schedule.js +34 -41
- package/lib/server/utils/time.js +40 -49
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +1530 -1343
- package/lib/solution/BookingByStep/types.js +40 -99
- package/lib/solution/BookingByStep/utils/capacity.js +192 -160
- package/lib/solution/BookingByStep/utils/products.js +42 -52
- package/lib/solution/BookingByStep/utils/resources.js +527 -330
- package/lib/solution/BookingByStep/utils/stock.js +65 -44
- package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +147 -122
- package/lib/solution/BookingTicket/types.js +38 -64
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +64 -80
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +82 -80
- package/lib/solution/BookingTicket/utils/scan/index.js +90 -94
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
- package/lib/solution/BuyTickets/index.js +67 -70
- package/lib/solution/BuyTickets/types.js +22 -38
- package/lib/solution/Checkout/index.js +1451 -1158
- package/lib/solution/Checkout/types.js +91 -61
- package/lib/solution/Checkout/utils/index.js +227 -158
- package/lib/solution/PlaceOrder/index.js +55 -0
- package/lib/solution/RegisterAndLogin/config.js +493 -460
- package/lib/solution/RegisterAndLogin/index.js +633 -630
- package/lib/solution/RegisterAndLogin/types.js +189 -76
- package/lib/solution/RegisterAndLogin/utils.js +183 -125
- package/lib/solution/Sales/index.js +218 -200
- package/lib/solution/Sales/types.js +27 -33
- package/lib/solution/ScanOrder/index.js +803 -840
- package/lib/solution/ScanOrder/types.js +34 -34
- package/lib/solution/ScanOrder/utils.js +372 -331
- package/lib/solution/ShopDiscount/index.js +230 -236
- package/lib/solution/ShopDiscount/types.js +15 -37
- package/lib/solution/ShopDiscount/utils.js +309 -172
- package/lib/solution/VenueBooking/index.d.ts +5 -0
- package/lib/solution/VenueBooking/index.js +886 -929
- package/lib/solution/VenueBooking/types.js +20 -40
- package/lib/solution/VenueBooking/utils/dateSummary.js +22 -54
- package/lib/solution/VenueBooking/utils/resource.js +31 -54
- package/lib/solution/VenueBooking/utils/slotMerge.js +88 -106
- package/lib/solution/VenueBooking/utils/smartPricing.js +112 -100
- package/lib/solution/VenueBooking/utils/timeSlot.js +133 -132
- package/lib/solution/VenueBooking/utils.js +130 -67
- package/lib/solution/index.js +102 -37
- package/lib/store/createStore.js +32 -29
- package/lib/types/index.js +4 -16
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +81 -47
- package/package.json +2 -1
|
@@ -1,55 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/solution/Checkout/utils/index.ts
|
|
20
|
-
var utils_exports = {};
|
|
21
|
-
__export(utils_exports, {
|
|
22
|
-
calculateTotalAmount: () => calculateTotalAmount,
|
|
23
|
-
createCheckoutError: () => createCheckoutError,
|
|
24
|
-
debounce: () => debounce,
|
|
25
|
-
deepClone: () => deepClone,
|
|
26
|
-
extractAmountFromCartSummary: () => extractAmountFromCartSummary,
|
|
27
|
-
formatAmount: () => formatAmount,
|
|
28
|
-
formatDateTime: () => formatDateTime,
|
|
29
|
-
generateLocalOrderId: () => generateLocalOrderId,
|
|
30
|
-
generateOrderId: () => generateOrderId,
|
|
31
|
-
getErrorMessage: () => getErrorMessage,
|
|
32
|
-
isCashPayment: () => isCashPayment,
|
|
33
|
-
isEmpty: () => isEmpty,
|
|
34
|
-
isProduction: () => isProduction,
|
|
35
|
-
isValidPaymentMethodCode: () => isValidPaymentMethodCode,
|
|
36
|
-
isVirtualOrderId: () => isVirtualOrderId,
|
|
37
|
-
logger: () => logger,
|
|
38
|
-
retry: () => retry,
|
|
39
|
-
safeJsonParse: () => safeJsonParse,
|
|
40
|
-
shouldSyncOrderForPayment: () => shouldSyncOrderForPayment,
|
|
41
|
-
throttle: () => throttle,
|
|
42
|
-
validateAmount: () => validateAmount,
|
|
43
|
-
validateCheckoutData: () => validateCheckoutData,
|
|
44
|
-
validateLocalOrderData: () => validateLocalOrderData
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
45
5
|
});
|
|
46
|
-
|
|
47
|
-
|
|
6
|
+
exports.calculateTotalAmount = calculateTotalAmount;
|
|
7
|
+
exports.createCheckoutError = createCheckoutError;
|
|
8
|
+
exports.debounce = debounce;
|
|
9
|
+
exports.deepClone = deepClone;
|
|
10
|
+
exports.extractAmountFromCartSummary = extractAmountFromCartSummary;
|
|
11
|
+
exports.formatAmount = formatAmount;
|
|
12
|
+
exports.formatDateTime = formatDateTime;
|
|
13
|
+
exports.generateLocalOrderId = generateLocalOrderId;
|
|
14
|
+
exports.generateOrderId = generateOrderId;
|
|
15
|
+
exports.getErrorMessage = getErrorMessage;
|
|
16
|
+
exports.isCashPayment = isCashPayment;
|
|
17
|
+
exports.isEmpty = isEmpty;
|
|
18
|
+
exports.isProduction = isProduction;
|
|
19
|
+
exports.isValidPaymentMethodCode = isValidPaymentMethodCode;
|
|
20
|
+
exports.isVirtualOrderId = isVirtualOrderId;
|
|
21
|
+
exports.logger = void 0;
|
|
22
|
+
exports.retry = retry;
|
|
23
|
+
exports.safeJsonParse = safeJsonParse;
|
|
24
|
+
exports.shouldSyncOrderForPayment = shouldSyncOrderForPayment;
|
|
25
|
+
exports.throttle = throttle;
|
|
26
|
+
exports.validateAmount = validateAmount;
|
|
27
|
+
exports.validateCheckoutData = validateCheckoutData;
|
|
28
|
+
exports.validateLocalOrderData = validateLocalOrderData;
|
|
29
|
+
var _types = require("../../../modules/Payment/types");
|
|
30
|
+
/**
|
|
31
|
+
* 验证结账数据
|
|
32
|
+
*/
|
|
48
33
|
function validateCheckoutData(params) {
|
|
49
34
|
const errors = [];
|
|
35
|
+
|
|
36
|
+
// 验证购物车商品
|
|
50
37
|
if (!params.cartItems || params.cartItems.length === 0) {
|
|
51
|
-
errors.push(
|
|
38
|
+
errors.push('购物车不能为空');
|
|
52
39
|
}
|
|
40
|
+
|
|
41
|
+
// 验证购物车商品数据完整性
|
|
53
42
|
if (params.cartItems) {
|
|
54
43
|
params.cartItems.forEach((item, index) => {
|
|
55
44
|
if (!item.id) {
|
|
@@ -63,17 +52,25 @@ function validateCheckoutData(params) {
|
|
|
63
52
|
}
|
|
64
53
|
});
|
|
65
54
|
}
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
|
|
56
|
+
// 验证订单类型
|
|
57
|
+
if (params.orderType && !['virtual', 'appointment_booking'].includes(params.orderType)) {
|
|
58
|
+
errors.push('订单类型无效,必须是 virtual 或 appointment_booking');
|
|
68
59
|
}
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
|
|
61
|
+
// 验证平台类型
|
|
62
|
+
if (params.platform && !['pc', 'h5'].includes(params.platform)) {
|
|
63
|
+
errors.push('平台类型无效,必须是 pc 或 h5');
|
|
71
64
|
}
|
|
72
65
|
return {
|
|
73
66
|
valid: errors.length === 0,
|
|
74
67
|
errors
|
|
75
68
|
};
|
|
76
69
|
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 创建结账错误对象
|
|
73
|
+
*/
|
|
77
74
|
function createCheckoutError(type, message, details) {
|
|
78
75
|
return {
|
|
79
76
|
type,
|
|
@@ -82,24 +79,44 @@ function createCheckoutError(type, message, details) {
|
|
|
82
79
|
timestamp: Date.now()
|
|
83
80
|
};
|
|
84
81
|
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 格式化金额
|
|
85
|
+
*/
|
|
85
86
|
function formatAmount(amount) {
|
|
86
|
-
const numAmount = typeof amount ===
|
|
87
|
-
if (isNaN(numAmount))
|
|
88
|
-
return "0.00";
|
|
87
|
+
const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
|
|
88
|
+
if (isNaN(numAmount)) return '0.00';
|
|
89
89
|
return numAmount.toFixed(2);
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 验证金额
|
|
94
|
+
*/
|
|
91
95
|
function validateAmount(amount) {
|
|
92
|
-
const numAmount = typeof amount ===
|
|
96
|
+
const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
|
|
93
97
|
return !isNaN(numAmount) && numAmount >= 0;
|
|
94
98
|
}
|
|
95
|
-
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 生成唯一订单ID
|
|
102
|
+
*/
|
|
103
|
+
function generateOrderId(prefix = 'order') {
|
|
96
104
|
const timestamp = Date.now();
|
|
97
|
-
const random = Math.floor(Math.random() *
|
|
105
|
+
const random = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
|
|
98
106
|
return `${prefix}_${timestamp}_${random}`;
|
|
99
107
|
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 检查是否为有效的支付方式代码
|
|
111
|
+
*/
|
|
100
112
|
function isValidPaymentMethodCode(code) {
|
|
101
|
-
|
|
113
|
+
// 基本的支付方式代码验证
|
|
114
|
+
return typeof code === 'string' && code.length > 0 && /^[a-zA-Z0-9_-]+$/.test(code);
|
|
102
115
|
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 安全地解析JSON
|
|
119
|
+
*/
|
|
103
120
|
function safeJsonParse(jsonString, defaultValue) {
|
|
104
121
|
try {
|
|
105
122
|
return JSON.parse(jsonString);
|
|
@@ -107,17 +124,21 @@ function safeJsonParse(jsonString, defaultValue) {
|
|
|
107
124
|
return defaultValue;
|
|
108
125
|
}
|
|
109
126
|
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 深度克隆对象
|
|
130
|
+
*/
|
|
110
131
|
function deepClone(obj) {
|
|
111
|
-
if (obj === null || typeof obj !==
|
|
132
|
+
if (obj === null || typeof obj !== 'object') {
|
|
112
133
|
return obj;
|
|
113
134
|
}
|
|
114
135
|
if (obj instanceof Date) {
|
|
115
136
|
return new Date(obj.getTime());
|
|
116
137
|
}
|
|
117
138
|
if (obj instanceof Array) {
|
|
118
|
-
return obj.map(
|
|
139
|
+
return obj.map(item => deepClone(item));
|
|
119
140
|
}
|
|
120
|
-
if (typeof obj ===
|
|
141
|
+
if (typeof obj === 'object') {
|
|
121
142
|
const clonedObj = {};
|
|
122
143
|
for (const key in obj) {
|
|
123
144
|
if (obj.hasOwnProperty(key)) {
|
|
@@ -128,6 +149,10 @@ function deepClone(obj) {
|
|
|
128
149
|
}
|
|
129
150
|
return obj;
|
|
130
151
|
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 防抖函数
|
|
155
|
+
*/
|
|
131
156
|
function debounce(func, wait) {
|
|
132
157
|
let timeout = null;
|
|
133
158
|
return (...args) => {
|
|
@@ -139,6 +164,10 @@ function debounce(func, wait) {
|
|
|
139
164
|
}, wait);
|
|
140
165
|
};
|
|
141
166
|
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 节流函数
|
|
170
|
+
*/
|
|
142
171
|
function throttle(func, wait) {
|
|
143
172
|
let lastTime = 0;
|
|
144
173
|
return (...args) => {
|
|
@@ -149,7 +178,11 @@ function throttle(func, wait) {
|
|
|
149
178
|
}
|
|
150
179
|
};
|
|
151
180
|
}
|
|
152
|
-
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 重试函数
|
|
184
|
+
*/
|
|
185
|
+
async function retry(fn, maxAttempts = 3, delay = 1000) {
|
|
153
186
|
let lastError;
|
|
154
187
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
155
188
|
try {
|
|
@@ -159,39 +192,52 @@ async function retry(fn, maxAttempts = 3, delay = 1e3) {
|
|
|
159
192
|
if (attempt === maxAttempts) {
|
|
160
193
|
throw lastError;
|
|
161
194
|
}
|
|
162
|
-
|
|
195
|
+
|
|
196
|
+
// 等待指定时间后重试
|
|
197
|
+
await new Promise(resolve => setTimeout(resolve, delay * attempt));
|
|
163
198
|
}
|
|
164
199
|
}
|
|
165
200
|
throw lastError;
|
|
166
201
|
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 检查对象是否为空
|
|
205
|
+
*/
|
|
167
206
|
function isEmpty(obj) {
|
|
168
|
-
if (obj == null)
|
|
169
|
-
|
|
170
|
-
if (
|
|
171
|
-
return obj.length === 0;
|
|
172
|
-
if (typeof obj === "object")
|
|
173
|
-
return Object.keys(obj).length === 0;
|
|
207
|
+
if (obj == null) return true;
|
|
208
|
+
if (Array.isArray(obj) || typeof obj === 'string') return obj.length === 0;
|
|
209
|
+
if (typeof obj === 'object') return Object.keys(obj).length === 0;
|
|
174
210
|
return false;
|
|
175
211
|
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 获取错误消息
|
|
215
|
+
*/
|
|
176
216
|
function getErrorMessage(error) {
|
|
177
217
|
if (error instanceof Error) {
|
|
178
218
|
return error.message;
|
|
179
219
|
}
|
|
180
|
-
if (typeof error ===
|
|
220
|
+
if (typeof error === 'string') {
|
|
181
221
|
return error;
|
|
182
222
|
}
|
|
183
|
-
if (error && typeof error ===
|
|
223
|
+
if (error && typeof error === 'object' && 'message' in error) {
|
|
184
224
|
return String(error.message);
|
|
185
225
|
}
|
|
186
|
-
return
|
|
226
|
+
return '未知错误';
|
|
187
227
|
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 检查是否为生产环境
|
|
231
|
+
*/
|
|
188
232
|
function isProduction() {
|
|
189
|
-
return process.env.NODE_ENV ===
|
|
233
|
+
return process.env.NODE_ENV === 'production';
|
|
190
234
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 日志记录器
|
|
238
|
+
*/
|
|
239
|
+
const logger = exports.logger = {
|
|
240
|
+
info: (message, ...args) => {},
|
|
195
241
|
warn: (message, ...args) => {
|
|
196
242
|
console.warn(`[Checkout] ${message}`, ...args);
|
|
197
243
|
},
|
|
@@ -199,23 +245,30 @@ var logger = {
|
|
|
199
245
|
console.error(`[Checkout] ${message}`, ...args);
|
|
200
246
|
},
|
|
201
247
|
debug: (message, ...args) => {
|
|
202
|
-
if (!isProduction()) {
|
|
203
|
-
console.debug(`[Checkout] ${message}`, ...args);
|
|
204
|
-
}
|
|
248
|
+
if (!isProduction()) {}
|
|
205
249
|
}
|
|
206
250
|
};
|
|
251
|
+
|
|
252
|
+
// ========== 从 CheckoutImpl 类中移出的纯静态方法 ==========
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* 验证本地订单数据
|
|
256
|
+
*/
|
|
207
257
|
function validateLocalOrderData(orderData) {
|
|
208
|
-
var _a;
|
|
209
258
|
const errors = [];
|
|
259
|
+
|
|
260
|
+
// 验证基本字段
|
|
210
261
|
if (!orderData.type) {
|
|
211
|
-
errors.push(
|
|
262
|
+
errors.push('订单类型不能为空');
|
|
212
263
|
}
|
|
213
264
|
if (!orderData.platform) {
|
|
214
|
-
errors.push(
|
|
265
|
+
errors.push('平台信息不能为空');
|
|
215
266
|
}
|
|
216
|
-
if ((!orderData.bookings || orderData.bookings.length === 0) && !
|
|
217
|
-
errors.push(
|
|
267
|
+
if ((!orderData.bookings || orderData.bookings.length === 0) && !orderData?.relation_products?.length) {
|
|
268
|
+
errors.push('预订信息不能为空');
|
|
218
269
|
}
|
|
270
|
+
|
|
271
|
+
// 验证预订信息
|
|
219
272
|
if (orderData.bookings) {
|
|
220
273
|
orderData.bookings.forEach((booking, index) => {
|
|
221
274
|
if (!booking.product || !booking.product.product_id) {
|
|
@@ -234,131 +287,147 @@ function validateLocalOrderData(orderData) {
|
|
|
234
287
|
errors
|
|
235
288
|
};
|
|
236
289
|
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 生成本地订单ID
|
|
293
|
+
*/
|
|
237
294
|
function generateLocalOrderId() {
|
|
238
295
|
const timestamp = Date.now();
|
|
239
|
-
const random = Math.floor(Math.random() *
|
|
296
|
+
const random = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
|
|
240
297
|
return `local_order_${timestamp}_${random}`;
|
|
241
298
|
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* 格式化日期时间为 YYYY-MM-DD hh:mm:ss 格式
|
|
302
|
+
*
|
|
303
|
+
* @param date 要格式化的日期对象
|
|
304
|
+
* @returns 格式化后的日期时间字符串
|
|
305
|
+
*/
|
|
242
306
|
function formatDateTime(date) {
|
|
243
307
|
const year = date.getFullYear();
|
|
244
|
-
const month = String(date.getMonth() + 1).padStart(2,
|
|
245
|
-
const day = String(date.getDate()).padStart(2,
|
|
246
|
-
const hours = String(date.getHours()).padStart(2,
|
|
247
|
-
const minutes = String(date.getMinutes()).padStart(2,
|
|
248
|
-
const seconds = String(date.getSeconds()).padStart(2,
|
|
308
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
309
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
310
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
|
311
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
312
|
+
const seconds = String(date.getSeconds()).padStart(2, '0');
|
|
249
313
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
250
314
|
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* 从购物车小计数据中提取金额信息
|
|
318
|
+
*/
|
|
251
319
|
function extractAmountFromCartSummary(cartSummary) {
|
|
252
320
|
const result = {
|
|
253
|
-
totalAmount:
|
|
254
|
-
subTotal:
|
|
255
|
-
taxAmount:
|
|
256
|
-
discountAmount:
|
|
257
|
-
shopDiscountAmount:
|
|
258
|
-
roundingAmount:
|
|
321
|
+
totalAmount: '0.00',
|
|
322
|
+
subTotal: '0.00',
|
|
323
|
+
taxAmount: '0.00',
|
|
324
|
+
discountAmount: '0.00',
|
|
325
|
+
shopDiscountAmount: '0.00',
|
|
326
|
+
roundingAmount: '0.00'
|
|
259
327
|
};
|
|
260
|
-
cartSummary.forEach(
|
|
328
|
+
cartSummary.forEach(item => {
|
|
261
329
|
const value = Number(item.value).toFixed(2);
|
|
262
330
|
switch (item.key) {
|
|
263
|
-
case
|
|
331
|
+
case 'expect_amount':
|
|
264
332
|
result.totalAmount = value;
|
|
265
333
|
break;
|
|
266
|
-
case
|
|
334
|
+
case 'sub_total':
|
|
267
335
|
result.subTotal = value;
|
|
268
336
|
break;
|
|
269
|
-
case
|
|
337
|
+
case 'tax':
|
|
270
338
|
result.taxAmount = value;
|
|
271
339
|
if (item.tax) {
|
|
272
340
|
result.taxDetails = item.tax;
|
|
273
341
|
}
|
|
274
342
|
break;
|
|
275
|
-
case
|
|
343
|
+
case 'discount':
|
|
276
344
|
result.discountAmount = value;
|
|
277
345
|
break;
|
|
278
|
-
case
|
|
346
|
+
case 'shop_discount':
|
|
279
347
|
result.shopDiscountAmount = value;
|
|
280
348
|
break;
|
|
281
|
-
case
|
|
349
|
+
case 'custom_roundingAmount':
|
|
282
350
|
result.roundingAmount = value;
|
|
283
351
|
break;
|
|
284
352
|
default:
|
|
285
|
-
|
|
353
|
+
// 处理其他可能的键,如定金等
|
|
354
|
+
if (item.key.includes('deposit')) {
|
|
286
355
|
result.depositAmount = value;
|
|
287
356
|
}
|
|
288
357
|
break;
|
|
289
358
|
}
|
|
290
359
|
});
|
|
291
|
-
console.log("[Checkout] 从购物车小计提取金额信息:", {
|
|
292
|
-
totalAmount: result.totalAmount,
|
|
293
|
-
subTotal: result.subTotal,
|
|
294
|
-
taxAmount: result.taxAmount,
|
|
295
|
-
discountAmount: result.discountAmount,
|
|
296
|
-
shopDiscountAmount: result.shopDiscountAmount,
|
|
297
|
-
roundingAmount: result.roundingAmount
|
|
298
|
-
});
|
|
299
360
|
return result;
|
|
300
361
|
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* 计算购物车总金额
|
|
365
|
+
*/
|
|
301
366
|
function calculateTotalAmount(cartItems) {
|
|
302
367
|
const total = cartItems.reduce((sum, item) => {
|
|
303
|
-
const price = parseFloat(String(item.price) ||
|
|
368
|
+
const price = parseFloat(String(item.price) || '0');
|
|
304
369
|
const quantity = item.quantity || 1;
|
|
305
370
|
return sum + price * quantity;
|
|
306
371
|
}, 0);
|
|
307
372
|
return total.toFixed(2);
|
|
308
373
|
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* 判断订单ID是否为本地生成的虚拟ID
|
|
377
|
+
*
|
|
378
|
+
* @param orderId 订单ID
|
|
379
|
+
* @returns true 表示是虚拟ID,false 表示是真实的后端ID
|
|
380
|
+
*/
|
|
309
381
|
function isVirtualOrderId(orderId) {
|
|
310
|
-
return orderId.startsWith(
|
|
382
|
+
return orderId.startsWith('local_order_');
|
|
311
383
|
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* 判断支付方式是否需要同步订单到后端
|
|
387
|
+
*
|
|
388
|
+
* 现金支付(CASHMANUAL)和自定义支付不需要同步,其他支付方式需要同步
|
|
389
|
+
*
|
|
390
|
+
* @param paymentCode 支付方式代码
|
|
391
|
+
* @param paymentType 支付方式类型
|
|
392
|
+
* @returns 是否需要同步订单
|
|
393
|
+
*/
|
|
312
394
|
function shouldSyncOrderForPayment(paymentCode, paymentType) {
|
|
313
|
-
const codeUpper =
|
|
314
|
-
const typeUpper =
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
)) {
|
|
395
|
+
const codeUpper = paymentCode?.toUpperCase() || '';
|
|
396
|
+
const typeUpper = paymentType?.toUpperCase() || '';
|
|
397
|
+
|
|
398
|
+
// 现金支付不需要同步 - 支持多种现金支付识别方式
|
|
399
|
+
const cashIdentifiers = ['CASHMANUAL', 'CASH', 'MANUAL'];
|
|
400
|
+
if (cashIdentifiers.some(id => codeUpper.includes(id) || typeUpper.includes(id))) {
|
|
319
401
|
return false;
|
|
320
402
|
}
|
|
321
|
-
|
|
403
|
+
|
|
404
|
+
// 标准现金支付代码检查
|
|
405
|
+
if (paymentCode === _types.PaymentMethodType.Cash || paymentType === _types.PaymentMethodType.Cash) {
|
|
322
406
|
return false;
|
|
323
407
|
}
|
|
324
|
-
|
|
408
|
+
|
|
409
|
+
// 自定义支付不需要同步
|
|
410
|
+
if (codeUpper.includes('CUSTOM') || typeUpper.includes('CUSTOM')) {
|
|
325
411
|
return false;
|
|
326
412
|
}
|
|
413
|
+
|
|
414
|
+
// 其他支付方式都需要同步
|
|
327
415
|
return true;
|
|
328
416
|
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* 判断是否为现金支付
|
|
420
|
+
*
|
|
421
|
+
* @param paymentCode 支付方式代码
|
|
422
|
+
* @param paymentType 支付方式类型
|
|
423
|
+
* @returns 是否为现金支付
|
|
424
|
+
*/
|
|
329
425
|
function isCashPayment(paymentItem) {
|
|
330
|
-
|
|
331
|
-
const
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
340
|
-
0 && (module.exports = {
|
|
341
|
-
calculateTotalAmount,
|
|
342
|
-
createCheckoutError,
|
|
343
|
-
debounce,
|
|
344
|
-
deepClone,
|
|
345
|
-
extractAmountFromCartSummary,
|
|
346
|
-
formatAmount,
|
|
347
|
-
formatDateTime,
|
|
348
|
-
generateLocalOrderId,
|
|
349
|
-
generateOrderId,
|
|
350
|
-
getErrorMessage,
|
|
351
|
-
isCashPayment,
|
|
352
|
-
isEmpty,
|
|
353
|
-
isProduction,
|
|
354
|
-
isValidPaymentMethodCode,
|
|
355
|
-
isVirtualOrderId,
|
|
356
|
-
logger,
|
|
357
|
-
retry,
|
|
358
|
-
safeJsonParse,
|
|
359
|
-
shouldSyncOrderForPayment,
|
|
360
|
-
throttle,
|
|
361
|
-
validateAmount,
|
|
362
|
-
validateCheckoutData,
|
|
363
|
-
validateLocalOrderData
|
|
364
|
-
});
|
|
426
|
+
const codeUpper = paymentItem.code?.toUpperCase() || '';
|
|
427
|
+
const typeUpper = paymentItem.type?.toUpperCase() || '';
|
|
428
|
+
const isNameCash = paymentItem.name?.toLowerCase().includes('cash');
|
|
429
|
+
|
|
430
|
+
// 现金支付识别规则
|
|
431
|
+
const cashIdentifiers = ['CASH', 'CASHMANUAL', 'MANUAL'];
|
|
432
|
+
return cashIdentifiers.some(identifier => codeUpper.includes(identifier) || typeUpper.includes(identifier)) || isNameCash;
|
|
433
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// // 只是一个示例工程
|
|
2
|
+
|
|
3
|
+
// import { Module, PisellCore, ModuleOptions } from '../types';
|
|
4
|
+
// import { CartModuleAPI } from '../modules/cart';
|
|
5
|
+
// import { StockModuleAPI } from '../modules/stock';
|
|
6
|
+
// import { CheckoutModuleAPI } from '../modules/checkout';
|
|
7
|
+
|
|
8
|
+
// class OrderSolution implements Module {
|
|
9
|
+
// name = 'orderSolution';
|
|
10
|
+
// version = '1.0.0';
|
|
11
|
+
|
|
12
|
+
// private core!: PisellCore;
|
|
13
|
+
// private cart!: CartModuleAPI;
|
|
14
|
+
// private stock!: StockModuleAPI;
|
|
15
|
+
// private checkout!: CheckoutModuleAPI;
|
|
16
|
+
|
|
17
|
+
// public exports = {
|
|
18
|
+
// submitOrder: this.submitOrder.bind(this),
|
|
19
|
+
// };
|
|
20
|
+
|
|
21
|
+
// async initialize(core: PisellCore): Promise<void> {
|
|
22
|
+
// this.core = core;
|
|
23
|
+
|
|
24
|
+
// // 获取依赖的模块 API
|
|
25
|
+
// this.cart = core.getModuleExports<CartModuleAPI>('cart');
|
|
26
|
+
// this.stock = core.getModuleExports<StockModuleAPI>('stock');
|
|
27
|
+
// this.checkout = core.getModuleExports<CheckoutModuleAPI>('checkout');
|
|
28
|
+
|
|
29
|
+
// console.log('[OrderSolution] 初始化完成');
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
// async destroy(): Promise<void> {
|
|
33
|
+
// console.log('[OrderSolution] 已销毁');
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
// /**
|
|
37
|
+
// * 下单流程(商品 → 库存校验 → 结算 → 提交)
|
|
38
|
+
// */
|
|
39
|
+
// async submitOrder(): Promise<void> {
|
|
40
|
+
// const cartItems = await this.cart.getItems();
|
|
41
|
+
|
|
42
|
+
// const stockResult = await this.stock.checkAvailability(cartItems);
|
|
43
|
+
// if (!stockResult.ok) {
|
|
44
|
+
// throw new Error('部分商品库存不足');
|
|
45
|
+
// }
|
|
46
|
+
|
|
47
|
+
// const summary = await this.checkout.calculate(cartItems);
|
|
48
|
+
|
|
49
|
+
// await this.checkout.submit(summary);
|
|
50
|
+
// console.log('[OrderSolution] 下单完成');
|
|
51
|
+
// }
|
|
52
|
+
// }
|
|
53
|
+
|
|
54
|
+
// export default new OrderSolution();
|
|
55
|
+
"use strict";
|