@pisell/pisellos 3.0.56 → 3.0.57
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 +2 -1
- package/dist/effects/index.d.ts +4 -3
- package/dist/effects/index.js +15 -6
- package/dist/modules/AccountList/index.d.ts +7 -1
- package/dist/modules/AccountList/index.js +81 -14
- package/dist/modules/AccountList/types.d.ts +28 -0
- package/dist/modules/AccountList/types.js +8 -0
- package/dist/modules/Cart/index.js +1 -1
- package/dist/modules/Cart/utils/changePrice.d.ts +2 -2
- package/dist/modules/Cart/utils/changePrice.js +1 -1
- package/dist/modules/Customer/constants.d.ts +7 -0
- package/dist/modules/Customer/constants.js +12 -0
- package/dist/modules/Customer/index.d.ts +122 -0
- package/dist/modules/Customer/index.js +697 -0
- package/dist/modules/Customer/types.d.ts +146 -0
- package/dist/modules/Customer/types.js +41 -0
- package/dist/modules/Payment/cash.d.ts +11 -0
- package/dist/modules/Payment/cash.js +78 -0
- package/dist/modules/Payment/eftpos.d.ts +11 -0
- package/dist/modules/Payment/eftpos.js +80 -0
- package/dist/modules/Payment/index.d.ts +273 -9
- package/dist/modules/Payment/index.js +2525 -109
- package/dist/modules/Payment/types.d.ts +382 -30
- package/dist/modules/Payment/types.js +116 -14
- package/dist/modules/Payment/wallet.d.ts +11 -0
- package/dist/modules/Payment/wallet.js +78 -0
- package/dist/modules/Payment/walletpass.d.ts +0 -0
- package/dist/modules/Payment/walletpass.js +0 -0
- package/dist/modules/ProductList/index.d.ts +13 -3
- package/dist/modules/ProductList/index.js +52 -42
- package/dist/modules/ProductList/types.d.ts +0 -1
- package/dist/modules/Rules/index.js +27 -14
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/plugins/app-types/app/app.d.ts +83 -0
- package/dist/plugins/app-types/app/const.d.ts +4 -0
- package/dist/plugins/app-types/app/index.d.ts +14 -0
- package/dist/plugins/app-types/applicationManager/application.d.ts +50 -0
- package/dist/plugins/app-types/applicationManager/index.d.ts +13 -0
- package/dist/plugins/app-types/config.d.ts +3 -0
- package/dist/plugins/app-types/cookie/index.d.ts +13 -0
- package/dist/plugins/app-types/data/index.d.ts +8 -0
- package/dist/plugins/app-types/history/config.d.ts +24 -0
- package/dist/plugins/app-types/history/index.d.ts +20 -0
- package/dist/plugins/app-types/history/type.d.ts +2 -0
- package/dist/plugins/app-types/hooks/index.d.ts +12 -0
- package/dist/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
- package/dist/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
- package/dist/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
- package/dist/plugins/app-types/hooks/useStore/index.d.ts +6 -0
- package/dist/plugins/app-types/index.d.ts +6 -0
- package/dist/plugins/app-types/indexDB/index.d.ts +178 -0
- package/dist/plugins/app-types/locales/en.d.ts +3 -0
- package/dist/plugins/app-types/locales/index.d.ts +37 -0
- package/dist/plugins/app-types/locales/original.d.ts +3 -0
- package/dist/plugins/app-types/locales/type.d.ts +19 -0
- package/dist/plugins/app-types/locales/zh-CN.d.ts +3 -0
- package/dist/plugins/app-types/locales/zh-HK.d.ts +3 -0
- package/dist/plugins/app-types/logger/feishu.d.ts +11 -0
- package/dist/plugins/app-types/logger/index.d.ts +122 -0
- package/dist/plugins/app-types/menuManager/hooks.d.ts +17 -0
- package/dist/plugins/app-types/menuManager/index.d.ts +28 -0
- package/dist/plugins/app-types/models/global.d.ts +32 -0
- package/dist/plugins/app-types/models/index.d.ts +45 -0
- package/dist/plugins/app-types/models/type.d.ts +2 -0
- package/dist/plugins/app-types/package.json +15 -0
- package/dist/plugins/app-types/plugin/index.d.ts +0 -0
- package/dist/plugins/app-types/pubsub/example.d.ts +5 -0
- package/dist/plugins/app-types/pubsub/index.d.ts +63 -0
- package/dist/plugins/app-types/request/cache.d.ts +46 -0
- package/dist/plugins/app-types/request/cancelToken.d.ts +38 -0
- package/dist/plugins/app-types/request/config.d.ts +3 -0
- package/dist/plugins/app-types/request/constants.d.ts +2 -0
- package/dist/plugins/app-types/request/index.d.ts +24 -0
- package/dist/plugins/app-types/request/pisell2Request.d.ts +6 -0
- package/dist/plugins/app-types/request/type.d.ts +41 -0
- package/dist/plugins/app-types/request/utils.d.ts +46 -0
- package/dist/plugins/app-types/routes/config.d.ts +7 -0
- package/dist/plugins/app-types/routes/index.d.ts +28 -0
- package/dist/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
- package/dist/plugins/app-types/socket/components/index.d.ts +2 -0
- package/dist/plugins/app-types/socket/constants.d.ts +33 -0
- package/dist/plugins/app-types/socket/events.d.ts +31 -0
- package/dist/plugins/app-types/socket/heartbeat.d.ts +66 -0
- package/dist/plugins/app-types/socket/index.d.ts +61 -0
- package/dist/plugins/app-types/socket/monitor.d.ts +169 -0
- package/dist/plugins/app-types/socket/reconnect.d.ts +61 -0
- package/dist/plugins/app-types/socket/socket.d.ts +129 -0
- package/dist/plugins/app-types/socket/types.d.ts +85 -0
- package/dist/plugins/app-types/storage/index.d.ts +17 -0
- package/dist/plugins/app-types/tasks/index.d.ts +77 -0
- package/dist/plugins/app-types/tasks/type.d.ts +62 -0
- package/dist/plugins/app-types/tasks/useTasks.d.ts +5 -0
- package/dist/plugins/app-types/type.d.ts +2 -0
- package/dist/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
- package/dist/plugins/app-types/variables/config.d.ts +3 -0
- package/dist/plugins/app-types/variables/index.d.ts +6 -0
- package/dist/plugins/app-types/variables/type.d.ts +2 -0
- package/dist/plugins/app-types/website/index.d.ts +6 -0
- package/dist/plugins/app.d.ts +8 -0
- package/dist/plugins/app.js +1 -0
- package/dist/plugins/window.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +59 -35
- package/dist/solution/BookingByStep/types.d.ts +3 -2
- package/dist/solution/BookingTicket/index.d.ts +172 -0
- package/dist/solution/BookingTicket/index.js +665 -0
- package/dist/solution/BookingTicket/types.d.ts +68 -0
- package/dist/solution/BookingTicket/types.js +43 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +159 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +16 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +174 -0
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +81 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +285 -0
- package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
- package/dist/solution/BookingTicket/utils/scan/scanCache.js +305 -0
- package/dist/solution/BuyTickets/index.d.ts +2 -2
- package/dist/solution/BuyTickets/index.js +1 -1
- package/dist/solution/Checkout/appointmentDemo.json +1 -0
- package/dist/solution/Checkout/index.d.ts +181 -0
- package/dist/solution/Checkout/index.js +1596 -0
- package/dist/solution/Checkout/types.d.ts +550 -0
- package/dist/solution/Checkout/types.js +132 -0
- package/dist/solution/Checkout/utils/index.d.ts +73 -0
- package/dist/solution/Checkout/utils/index.js +371 -0
- package/dist/solution/ShopDiscount/index.js +4 -2
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/utils/task.d.ts +40 -0
- package/dist/utils/task.js +171 -0
- package/dist/utils/watch.d.ts +102 -0
- package/dist/utils/watch.js +294 -0
- package/lib/core/index.js +1 -1
- package/lib/effects/index.d.ts +4 -3
- package/lib/effects/index.js +4 -1
- package/lib/modules/AccountList/index.d.ts +7 -1
- package/lib/modules/AccountList/index.js +27 -0
- package/lib/modules/AccountList/types.d.ts +28 -0
- package/lib/modules/Cart/index.js +1 -1
- package/lib/modules/Cart/utils/changePrice.d.ts +2 -2
- package/lib/modules/Cart/utils/changePrice.js +1 -1
- package/lib/modules/Customer/constants.d.ts +7 -0
- package/lib/modules/Customer/constants.js +39 -0
- package/lib/modules/Customer/index.d.ts +122 -0
- package/lib/modules/Customer/index.js +440 -0
- package/lib/modules/Customer/types.d.ts +146 -0
- package/lib/modules/Customer/types.js +37 -0
- package/lib/modules/Payment/cash.d.ts +11 -0
- package/lib/modules/Payment/cash.js +51 -0
- package/lib/modules/Payment/eftpos.d.ts +11 -0
- package/lib/modules/Payment/eftpos.js +51 -0
- package/lib/modules/Payment/index.d.ts +273 -9
- package/lib/modules/Payment/index.js +1285 -50
- package/lib/modules/Payment/types.d.ts +382 -30
- package/lib/modules/Payment/types.js +41 -6
- package/lib/modules/Payment/wallet.d.ts +11 -0
- package/lib/modules/Payment/wallet.js +51 -0
- package/lib/modules/Payment/walletpass.d.ts +0 -0
- package/lib/modules/Payment/walletpass.js +0 -0
- package/lib/modules/ProductList/index.d.ts +13 -3
- package/lib/modules/ProductList/index.js +37 -26
- package/lib/modules/ProductList/types.d.ts +0 -1
- package/lib/modules/Rules/index.js +20 -12
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +2 -0
- package/lib/plugins/app-types/app/app.d.ts +83 -0
- package/lib/plugins/app-types/app/const.d.ts +4 -0
- package/lib/plugins/app-types/app/index.d.ts +14 -0
- package/lib/plugins/app-types/applicationManager/application.d.ts +50 -0
- package/lib/plugins/app-types/applicationManager/index.d.ts +13 -0
- package/lib/plugins/app-types/config.d.ts +3 -0
- package/lib/plugins/app-types/cookie/index.d.ts +13 -0
- package/lib/plugins/app-types/data/index.d.ts +8 -0
- package/lib/plugins/app-types/history/config.d.ts +24 -0
- package/lib/plugins/app-types/history/index.d.ts +20 -0
- package/lib/plugins/app-types/history/type.d.ts +2 -0
- package/lib/plugins/app-types/hooks/index.d.ts +12 -0
- package/lib/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
- package/lib/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
- package/lib/plugins/app-types/hooks/useStore/index.d.ts +6 -0
- package/lib/plugins/app-types/index.d.ts +6 -0
- package/lib/plugins/app-types/indexDB/index.d.ts +178 -0
- package/lib/plugins/app-types/locales/en.d.ts +3 -0
- package/lib/plugins/app-types/locales/index.d.ts +37 -0
- package/lib/plugins/app-types/locales/original.d.ts +3 -0
- package/lib/plugins/app-types/locales/type.d.ts +19 -0
- package/lib/plugins/app-types/locales/zh-CN.d.ts +3 -0
- package/lib/plugins/app-types/locales/zh-HK.d.ts +3 -0
- package/lib/plugins/app-types/logger/feishu.d.ts +11 -0
- package/lib/plugins/app-types/logger/index.d.ts +122 -0
- package/lib/plugins/app-types/menuManager/hooks.d.ts +17 -0
- package/lib/plugins/app-types/menuManager/index.d.ts +28 -0
- package/lib/plugins/app-types/models/global.d.ts +32 -0
- package/lib/plugins/app-types/models/index.d.ts +45 -0
- package/lib/plugins/app-types/models/type.d.ts +2 -0
- package/lib/plugins/app-types/package.json +15 -0
- package/lib/plugins/app-types/plugin/index.d.ts +0 -0
- package/lib/plugins/app-types/pubsub/example.d.ts +5 -0
- package/lib/plugins/app-types/pubsub/index.d.ts +63 -0
- package/lib/plugins/app-types/request/cache.d.ts +46 -0
- package/lib/plugins/app-types/request/cancelToken.d.ts +38 -0
- package/lib/plugins/app-types/request/config.d.ts +3 -0
- package/lib/plugins/app-types/request/constants.d.ts +2 -0
- package/lib/plugins/app-types/request/index.d.ts +24 -0
- package/lib/plugins/app-types/request/pisell2Request.d.ts +6 -0
- package/lib/plugins/app-types/request/type.d.ts +41 -0
- package/lib/plugins/app-types/request/utils.d.ts +46 -0
- package/lib/plugins/app-types/routes/config.d.ts +7 -0
- package/lib/plugins/app-types/routes/index.d.ts +28 -0
- package/lib/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/plugins/app-types/socket/components/index.d.ts +2 -0
- package/lib/plugins/app-types/socket/constants.d.ts +33 -0
- package/lib/plugins/app-types/socket/events.d.ts +31 -0
- package/lib/plugins/app-types/socket/heartbeat.d.ts +66 -0
- package/lib/plugins/app-types/socket/index.d.ts +61 -0
- package/lib/plugins/app-types/socket/monitor.d.ts +169 -0
- package/lib/plugins/app-types/socket/reconnect.d.ts +61 -0
- package/lib/plugins/app-types/socket/socket.d.ts +129 -0
- package/lib/plugins/app-types/socket/types.d.ts +85 -0
- package/lib/plugins/app-types/storage/index.d.ts +17 -0
- package/lib/plugins/app-types/tasks/index.d.ts +77 -0
- package/lib/plugins/app-types/tasks/type.d.ts +62 -0
- package/lib/plugins/app-types/tasks/useTasks.d.ts +5 -0
- package/lib/plugins/app-types/type.d.ts +2 -0
- package/lib/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
- package/lib/plugins/app-types/variables/config.d.ts +3 -0
- package/lib/plugins/app-types/variables/index.d.ts +6 -0
- package/lib/plugins/app-types/variables/type.d.ts +2 -0
- package/lib/plugins/app-types/website/index.d.ts +6 -0
- package/lib/plugins/app.d.ts +8 -0
- package/lib/plugins/app.js +17 -0
- package/lib/plugins/window.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +40 -29
- package/lib/solution/BookingByStep/types.d.ts +3 -2
- package/lib/solution/BookingTicket/index.d.ts +172 -0
- package/lib/solution/BookingTicket/index.js +399 -0
- package/lib/solution/BookingTicket/types.d.ts +68 -0
- package/lib/solution/BookingTicket/types.js +72 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +117 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +16 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +125 -0
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +81 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +210 -0
- package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +231 -0
- package/lib/solution/BuyTickets/index.d.ts +2 -2
- package/lib/solution/BuyTickets/index.js +1 -1
- package/lib/solution/Checkout/appointmentDemo.json +1 -0
- package/lib/solution/Checkout/index.d.ts +181 -0
- package/lib/solution/Checkout/index.js +864 -0
- package/lib/solution/Checkout/types.d.ts +550 -0
- package/lib/solution/Checkout/types.js +75 -0
- package/lib/solution/Checkout/utils/index.d.ts +73 -0
- package/lib/solution/Checkout/utils/index.js +266 -0
- package/lib/solution/ShopDiscount/index.js +2 -1
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +5 -1
- package/lib/types/index.d.ts +3 -1
- package/lib/utils/task.d.ts +40 -0
- package/lib/utils/task.js +109 -0
- package/lib/utils/watch.d.ts +102 -0
- package/lib/utils/watch.js +217 -0
- package/package.json +4 -2
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/solution/Checkout/index.ts
|
|
21
|
+
var Checkout_exports = {};
|
|
22
|
+
__export(Checkout_exports, {
|
|
23
|
+
CheckoutImpl: () => CheckoutImpl
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(Checkout_exports);
|
|
26
|
+
var import_BaseModule = require("../../modules/BaseModule");
|
|
27
|
+
var import_Order = require("../../modules/Order");
|
|
28
|
+
var import_Payment = require("../../modules/Payment");
|
|
29
|
+
var import_types = require("./types");
|
|
30
|
+
var import_types2 = require("../../modules/Payment/types");
|
|
31
|
+
var import_utils = require("./utils");
|
|
32
|
+
__reExport(Checkout_exports, require("./types"), module.exports);
|
|
33
|
+
var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
34
|
+
constructor(name, version) {
|
|
35
|
+
super(name || "checkout", version || "1.0.0");
|
|
36
|
+
this.defaultName = "checkout";
|
|
37
|
+
this.defaultVersion = "1.0.0";
|
|
38
|
+
this.isSolution = true;
|
|
39
|
+
this.otherParams = {};
|
|
40
|
+
}
|
|
41
|
+
async initialize(core, options) {
|
|
42
|
+
this.core = core;
|
|
43
|
+
this.otherParams = options.otherParams || {};
|
|
44
|
+
this.request = core.getPlugin("request");
|
|
45
|
+
if (!this.request) {
|
|
46
|
+
throw new Error("Checkout 解决方案需要 request 插件支持");
|
|
47
|
+
}
|
|
48
|
+
this.store = {
|
|
49
|
+
order: new import_Order.OrderModule(),
|
|
50
|
+
payment: new import_Payment.PaymentModule(),
|
|
51
|
+
status: import_types.CheckoutStatus.Initializing,
|
|
52
|
+
step: import_types.CheckoutStep.OrderConfirmation,
|
|
53
|
+
cartItems: [],
|
|
54
|
+
paymentMethods: []
|
|
55
|
+
};
|
|
56
|
+
await this.initializeSubModules(core, options);
|
|
57
|
+
await this.preloadPaymentMethods();
|
|
58
|
+
await this.setStatus(import_types.CheckoutStatus.Ready);
|
|
59
|
+
console.log("[Checkout] 初始化完成");
|
|
60
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutInitialized, {
|
|
61
|
+
timestamp: Date.now()
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 初始化子模块
|
|
66
|
+
*/
|
|
67
|
+
async initializeSubModules(core, options) {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
core.registerModule(this.store.order, {
|
|
70
|
+
store: ((_a = options.store) == null ? void 0 : _a.order) || {},
|
|
71
|
+
otherParams: { ...this.otherParams, parentModule: this.name }
|
|
72
|
+
});
|
|
73
|
+
core.registerModule(this.store.payment, {
|
|
74
|
+
store: ((_b = options.store) == null ? void 0 : _b.payment) || {},
|
|
75
|
+
otherParams: { ...this.otherParams, parentModule: this.name }
|
|
76
|
+
});
|
|
77
|
+
this.setupPaymentEventListeners();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 设置支付模块事件监听
|
|
81
|
+
*/
|
|
82
|
+
setupPaymentEventListeners() {
|
|
83
|
+
this.core.effects.on("payment:onPaymentSyncSuccess", async (data) => {
|
|
84
|
+
var _a;
|
|
85
|
+
if (((_a = this.store.currentOrder) == null ? void 0 : _a.uuid) === data.orderUuid) {
|
|
86
|
+
await this.handlePaymentSuccess(data);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.core.effects.on("payment:onPaymentSyncError", async (data) => {
|
|
90
|
+
var _a;
|
|
91
|
+
if (((_a = this.store.currentOrder) == null ? void 0 : _a.uuid) === data.orderUuid) {
|
|
92
|
+
await this.handlePaymentError(data);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 初始化结账流程
|
|
98
|
+
*/
|
|
99
|
+
async initializeCheckoutAsync(params) {
|
|
100
|
+
try {
|
|
101
|
+
await this.setStatus(import_types.CheckoutStatus.Initializing);
|
|
102
|
+
const validation = await this.validateCheckoutParams(params);
|
|
103
|
+
if (!validation.valid) {
|
|
104
|
+
throw (0, import_utils.createCheckoutError)(
|
|
105
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
106
|
+
`参数验证失败: ${validation.errors.join(", ")}`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
this.store.cartItems = params.cartItems;
|
|
110
|
+
await this.setStatus(import_types.CheckoutStatus.Ready);
|
|
111
|
+
await this.setStep(import_types.CheckoutStep.OrderConfirmation);
|
|
112
|
+
console.log("[Checkout] 结账流程初始化完成");
|
|
113
|
+
} catch (error) {
|
|
114
|
+
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 创建本地订单 (前端模拟下单流程)
|
|
120
|
+
*
|
|
121
|
+
* 此方法用于在前端模拟整个下单流程,创建一个本地的虚拟订单。
|
|
122
|
+
* 用户在购物车点击下单时,会把购物车参数传递给此方法,
|
|
123
|
+
* 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
|
|
124
|
+
*/
|
|
125
|
+
async createLocalOrderAsync(params) {
|
|
126
|
+
try {
|
|
127
|
+
await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
128
|
+
const validation = await this.validateLocalOrderData(params.orderData);
|
|
129
|
+
if (!validation.valid) {
|
|
130
|
+
throw (0, import_utils.createCheckoutError)(
|
|
131
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
132
|
+
`订单数据验证失败: ${validation.errors.join(", ")}`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const localOrderId = this.generateLocalOrderId();
|
|
136
|
+
const amountInfo = this.extractAmountFromCartSummary(params.cartSummary);
|
|
137
|
+
this.store.localOrderData = params.orderData;
|
|
138
|
+
const paymentOrder = await this.store.payment.createPaymentOrderAsync({
|
|
139
|
+
order_id: localOrderId,
|
|
140
|
+
total_amount: amountInfo.totalAmount,
|
|
141
|
+
is_deposit: params.orderData.is_deposit || 0,
|
|
142
|
+
deposit_amount: amountInfo.depositAmount || "0.00",
|
|
143
|
+
order_info: {
|
|
144
|
+
original_order_data: params.orderData,
|
|
145
|
+
cart_summary: params.cartSummary,
|
|
146
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
147
|
+
platform: params.orderData.platform.toLowerCase(),
|
|
148
|
+
type: params.orderData.type,
|
|
149
|
+
schedule_date: params.orderData.schedule_date,
|
|
150
|
+
shop_note: params.orderData.shop_note,
|
|
151
|
+
amount_breakdown: amountInfo
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
this.store.currentOrder = paymentOrder;
|
|
155
|
+
await this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
156
|
+
await this.setStep(import_types.CheckoutStep.PaymentMethod);
|
|
157
|
+
if (params.autoPayment) {
|
|
158
|
+
await this.setStep(import_types.CheckoutStep.PaymentProcessing);
|
|
159
|
+
}
|
|
160
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
161
|
+
order: paymentOrder,
|
|
162
|
+
timestamp: Date.now()
|
|
163
|
+
});
|
|
164
|
+
console.log("[Checkout] 本地订单创建成功:", {
|
|
165
|
+
localOrderId,
|
|
166
|
+
uuid: paymentOrder.uuid,
|
|
167
|
+
totalAmount: amountInfo.totalAmount,
|
|
168
|
+
subTotal: amountInfo.subTotal,
|
|
169
|
+
taxAmount: amountInfo.taxAmount
|
|
170
|
+
});
|
|
171
|
+
return paymentOrder;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
await this.handleError(error, import_types.CheckoutErrorType.OrderCreationFailed);
|
|
174
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
|
|
175
|
+
error: this.store.lastError,
|
|
176
|
+
timestamp: Date.now()
|
|
177
|
+
});
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* 手动下单 (根据虚拟订单生成实际订单)
|
|
183
|
+
*
|
|
184
|
+
* 使用当前存储的本地订单数据调用 Order 模块创建真实订单
|
|
185
|
+
*/
|
|
186
|
+
async placeOrderAsync(params = {}) {
|
|
187
|
+
var _a, _b;
|
|
188
|
+
try {
|
|
189
|
+
if (!this.store.localOrderData) {
|
|
190
|
+
throw (0, import_utils.createCheckoutError)(
|
|
191
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
192
|
+
"没有找到本地订单数据,请先调用 createLocalOrderAsync 创建虚拟订单"
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
if (!this.store.currentOrder) {
|
|
196
|
+
throw (0, import_utils.createCheckoutError)(
|
|
197
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
198
|
+
"没有找到当前订单,请先创建虚拟订单"
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
console.log("[Checkout] 开始手动下单流程...");
|
|
202
|
+
await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
203
|
+
const orderData = {
|
|
204
|
+
cartItems: this.store.cartItems,
|
|
205
|
+
type: this.store.localOrderData.type,
|
|
206
|
+
platform: (_a = this.store.localOrderData.platform) == null ? void 0 : _a.toLowerCase()
|
|
207
|
+
};
|
|
208
|
+
const orderResponse = await this.store.order.submitOrder({
|
|
209
|
+
url: params.url,
|
|
210
|
+
// 可选的自定义 URL
|
|
211
|
+
query: orderData
|
|
212
|
+
});
|
|
213
|
+
const realOrderId = ((_b = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _b.order_id) || (orderResponse == null ? void 0 : orderResponse.order_id);
|
|
214
|
+
if (!realOrderId) {
|
|
215
|
+
throw (0, import_utils.createCheckoutError)(
|
|
216
|
+
import_types.CheckoutErrorType.OrderCreationFailed,
|
|
217
|
+
"订单创建成功但未返回订单ID"
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
console.log("[Checkout] 真实订单创建成功:", realOrderId);
|
|
221
|
+
if (params.autoReplaceOrderId !== false) {
|
|
222
|
+
console.log("[Checkout] 自动替换虚拟订单ID为真实订单ID...");
|
|
223
|
+
const updatedOrder = await this.replaceLocalOrderIdAsync(realOrderId);
|
|
224
|
+
if (updatedOrder) {
|
|
225
|
+
console.log("[Checkout] 订单ID替换成功:", {
|
|
226
|
+
oldId: this.store.currentOrder.order_id,
|
|
227
|
+
newId: realOrderId
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
await this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
232
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
233
|
+
order: this.store.currentOrder,
|
|
234
|
+
timestamp: Date.now()
|
|
235
|
+
});
|
|
236
|
+
console.log("[Checkout] 手动下单流程完成");
|
|
237
|
+
return {
|
|
238
|
+
success: true,
|
|
239
|
+
orderId: realOrderId
|
|
240
|
+
};
|
|
241
|
+
} catch (error) {
|
|
242
|
+
let errorMessage = "下单失败";
|
|
243
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
244
|
+
errorMessage = error.message;
|
|
245
|
+
} else if (error instanceof Error) {
|
|
246
|
+
errorMessage = error.message;
|
|
247
|
+
}
|
|
248
|
+
console.error("[Checkout] 手动下单失败:", errorMessage);
|
|
249
|
+
await this.handleError(error, import_types.CheckoutErrorType.OrderCreationFailed);
|
|
250
|
+
return {
|
|
251
|
+
success: false,
|
|
252
|
+
error: errorMessage
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 创建订单
|
|
258
|
+
*/
|
|
259
|
+
async createOrderAsync(params) {
|
|
260
|
+
var _a;
|
|
261
|
+
try {
|
|
262
|
+
await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
|
|
263
|
+
const checkResult = this.store.order.checkBeforeSubmitOrder({
|
|
264
|
+
cartItems: params.cartItems,
|
|
265
|
+
type: "account"
|
|
266
|
+
// 默认使用 account 类型
|
|
267
|
+
});
|
|
268
|
+
if (!checkResult) {
|
|
269
|
+
throw (0, import_utils.createCheckoutError)(
|
|
270
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
271
|
+
"购物车数据验证失败,请检查商品信息"
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
const orderResponse = await this.store.order.submitOrder({
|
|
275
|
+
query: {
|
|
276
|
+
cartItems: params.cartItems,
|
|
277
|
+
type: params.type || "appointment_booking",
|
|
278
|
+
platform: params.platform || "pc"
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
const paymentOrder = await this.store.payment.createPaymentOrderAsync({
|
|
282
|
+
order_id: ((_a = orderResponse == null ? void 0 : orderResponse.data) == null ? void 0 : _a.order_id) || `order_${Date.now()}`,
|
|
283
|
+
total_amount: this.calculateTotalAmount(params.cartItems),
|
|
284
|
+
order_info: orderResponse == null ? void 0 : orderResponse.data
|
|
285
|
+
});
|
|
286
|
+
this.store.currentOrder = paymentOrder;
|
|
287
|
+
await this.setStatus(import_types.CheckoutStatus.OrderCreated);
|
|
288
|
+
await this.setStep(import_types.CheckoutStep.PaymentMethod);
|
|
289
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
290
|
+
order: paymentOrder,
|
|
291
|
+
timestamp: Date.now()
|
|
292
|
+
});
|
|
293
|
+
console.log("[Checkout] 订单创建成功:", paymentOrder.id);
|
|
294
|
+
return paymentOrder;
|
|
295
|
+
} catch (error) {
|
|
296
|
+
await this.handleError(error, import_types.CheckoutErrorType.OrderCreationFailed);
|
|
297
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
|
|
298
|
+
error: this.store.lastError,
|
|
299
|
+
timestamp: Date.now()
|
|
300
|
+
});
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* 处理支付
|
|
306
|
+
*/
|
|
307
|
+
async processPaymentAsync(params) {
|
|
308
|
+
try {
|
|
309
|
+
if (!this.store.currentOrder) {
|
|
310
|
+
throw (0, import_utils.createCheckoutError)(
|
|
311
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
312
|
+
"未找到当前订单,请先创建订单"
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
await this.setStatus(import_types.CheckoutStatus.ProcessingPayment);
|
|
316
|
+
await this.setStep(import_types.CheckoutStep.PaymentProcessing);
|
|
317
|
+
const paymentMethod = this.store.paymentMethods.find(
|
|
318
|
+
(method) => method.code === params.paymentMethodCode
|
|
319
|
+
);
|
|
320
|
+
if (!paymentMethod) {
|
|
321
|
+
throw (0, import_utils.createCheckoutError)(
|
|
322
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
323
|
+
`未找到支付方式: ${params.paymentMethodCode}`
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
const paymentItem = {
|
|
327
|
+
code: paymentMethod.code,
|
|
328
|
+
name: paymentMethod.name,
|
|
329
|
+
type: paymentMethod.type,
|
|
330
|
+
amount: String(params.amount),
|
|
331
|
+
id: paymentMethod.id
|
|
332
|
+
};
|
|
333
|
+
await this.store.payment.pushPaymentAsync(
|
|
334
|
+
this.store.currentOrder.uuid,
|
|
335
|
+
paymentItem
|
|
336
|
+
);
|
|
337
|
+
const result = await this.store.payment.submitPayAsync(
|
|
338
|
+
this.store.currentOrder.uuid
|
|
339
|
+
);
|
|
340
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
|
|
341
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
342
|
+
paymentMethodCode: params.paymentMethodCode,
|
|
343
|
+
amount: String(params.amount),
|
|
344
|
+
timestamp: Date.now()
|
|
345
|
+
});
|
|
346
|
+
if (result.status === "success") {
|
|
347
|
+
await this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
348
|
+
await this.handlePaymentSuccess({
|
|
349
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
350
|
+
timestamp: Date.now()
|
|
351
|
+
});
|
|
352
|
+
} else {
|
|
353
|
+
throw (0, import_utils.createCheckoutError)(
|
|
354
|
+
import_types.CheckoutErrorType.PaymentFailed,
|
|
355
|
+
"支付处理失败,请重试"
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
} catch (error) {
|
|
359
|
+
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
360
|
+
throw error;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* 完成结账
|
|
365
|
+
*/
|
|
366
|
+
async completeCheckoutAsync() {
|
|
367
|
+
try {
|
|
368
|
+
if (!this.store.currentOrder) {
|
|
369
|
+
throw (0, import_utils.createCheckoutError)(
|
|
370
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
371
|
+
"未找到当前订单"
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
const order = await this.store.payment.getPaymentOrderByUuidAsync(
|
|
375
|
+
this.store.currentOrder.uuid
|
|
376
|
+
);
|
|
377
|
+
if (!order || order.payment_status !== import_types2.PaymentStatus.Finished) {
|
|
378
|
+
throw (0, import_utils.createCheckoutError)(
|
|
379
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
380
|
+
"订单支付未完成,无法完成结账"
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
await this.setStatus(import_types.CheckoutStatus.Completed);
|
|
384
|
+
await this.setStep(import_types.CheckoutStep.Complete);
|
|
385
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCompleted, {
|
|
386
|
+
orderId: order.id,
|
|
387
|
+
timestamp: Date.now()
|
|
388
|
+
});
|
|
389
|
+
console.log("[Checkout] 结账流程完成:", order.id);
|
|
390
|
+
return {
|
|
391
|
+
success: true,
|
|
392
|
+
orderId: String(order.id)
|
|
393
|
+
};
|
|
394
|
+
} catch (error) {
|
|
395
|
+
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
396
|
+
return { success: false };
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* 取消结账
|
|
401
|
+
*/
|
|
402
|
+
async cancelCheckoutAsync() {
|
|
403
|
+
try {
|
|
404
|
+
if (this.store.currentOrder) {
|
|
405
|
+
await this.store.payment.deleteOrderAsync(this.store.currentOrder.uuid);
|
|
406
|
+
this.store.currentOrder = void 0;
|
|
407
|
+
}
|
|
408
|
+
await this.setStatus(import_types.CheckoutStatus.Cancelled);
|
|
409
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCancelled, {
|
|
410
|
+
timestamp: Date.now()
|
|
411
|
+
});
|
|
412
|
+
console.log("[Checkout] 结账流程已取消");
|
|
413
|
+
} catch (error) {
|
|
414
|
+
console.error("[Checkout] 取消结账失败:", error);
|
|
415
|
+
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* 获取结账状态
|
|
420
|
+
*/
|
|
421
|
+
getCheckoutStatus() {
|
|
422
|
+
return {
|
|
423
|
+
status: this.store.status,
|
|
424
|
+
step: this.store.step,
|
|
425
|
+
progress: (0, import_utils.calculateProgress)(this.store.status, this.store.step),
|
|
426
|
+
message: this.getStatusMessage(),
|
|
427
|
+
error: this.store.lastError
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* 获取结账摘要
|
|
432
|
+
*/
|
|
433
|
+
async getCheckoutSummaryAsync() {
|
|
434
|
+
var _a, _b, _c;
|
|
435
|
+
const totalAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0.00";
|
|
436
|
+
const paidAmount = this.calculatePaidAmount();
|
|
437
|
+
const remainingAmount = ((_b = this.store.currentOrder) == null ? void 0 : _b.expect_amount) || totalAmount;
|
|
438
|
+
return {
|
|
439
|
+
order: this.store.currentOrder,
|
|
440
|
+
totalAmount,
|
|
441
|
+
paidAmount,
|
|
442
|
+
remainingAmount,
|
|
443
|
+
paymentStatus: ((_c = this.store.currentOrder) == null ? void 0 : _c.payment_status) || import_types2.PaymentStatus.Processing,
|
|
444
|
+
availablePaymentMethods: this.store.paymentMethods
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* 获取可用支付方式
|
|
449
|
+
*/
|
|
450
|
+
async getAvailablePaymentMethodsAsync() {
|
|
451
|
+
if (this.store.paymentMethods.length === 0) {
|
|
452
|
+
console.log("[Checkout] 支付方式缓存为空,重新加载...");
|
|
453
|
+
await this.preloadPaymentMethods();
|
|
454
|
+
}
|
|
455
|
+
return this.store.paymentMethods;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* 刷新支付方式缓存
|
|
459
|
+
*
|
|
460
|
+
* 强制重新从服务器获取支付方式列表,更新本地缓存
|
|
461
|
+
*/
|
|
462
|
+
async refreshPaymentMethodsAsync() {
|
|
463
|
+
console.log("[Checkout] 强制刷新支付方式缓存...");
|
|
464
|
+
await this.preloadPaymentMethods();
|
|
465
|
+
return this.store.paymentMethods;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* 获取当前订单基础信息
|
|
469
|
+
*
|
|
470
|
+
* 返回当前订单的基础信息,包括订单状态、金额、支付状态等
|
|
471
|
+
*/
|
|
472
|
+
getCurrentOrderInfo() {
|
|
473
|
+
var _a;
|
|
474
|
+
try {
|
|
475
|
+
const { currentOrder, status, step, cartItems, localOrderData } = this.store;
|
|
476
|
+
if (!currentOrder) {
|
|
477
|
+
console.log("[Checkout] 当前没有活跃订单");
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
const orderInfo = currentOrder.order_info || {};
|
|
481
|
+
const createdAt = orderInfo.created_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
482
|
+
const orderType = (localOrderData == null ? void 0 : localOrderData.type) || orderInfo.type || "virtual";
|
|
483
|
+
const platform = ((_a = localOrderData == null ? void 0 : localOrderData.platform) == null ? void 0 : _a.toLowerCase()) || orderInfo.platform || "pc";
|
|
484
|
+
const result = {
|
|
485
|
+
uuid: currentOrder.uuid,
|
|
486
|
+
orderId: currentOrder.order_id,
|
|
487
|
+
status,
|
|
488
|
+
step,
|
|
489
|
+
totalAmount: currentOrder.total_amount,
|
|
490
|
+
remainingAmount: currentOrder.expect_amount,
|
|
491
|
+
paymentStatus: currentOrder.payment_status,
|
|
492
|
+
isDeposit: Boolean(currentOrder.is_deposit),
|
|
493
|
+
depositAmount: currentOrder.deposit_amount,
|
|
494
|
+
orderType,
|
|
495
|
+
platform,
|
|
496
|
+
createdAt,
|
|
497
|
+
itemCount: cartItems.length,
|
|
498
|
+
hasLocalOrderData: Boolean(localOrderData)
|
|
499
|
+
};
|
|
500
|
+
console.log("[Checkout] 获取当前订单基础信息:", {
|
|
501
|
+
uuid: result.uuid,
|
|
502
|
+
orderId: result.orderId,
|
|
503
|
+
status: result.status,
|
|
504
|
+
totalAmount: result.totalAmount,
|
|
505
|
+
remainingAmount: result.remainingAmount
|
|
506
|
+
});
|
|
507
|
+
return result;
|
|
508
|
+
} catch (error) {
|
|
509
|
+
console.error("[Checkout] 获取当前订单基础信息失败:", error);
|
|
510
|
+
return null;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* 验证结账前置条件
|
|
515
|
+
*/
|
|
516
|
+
async validateCheckoutAsync() {
|
|
517
|
+
const errors = [];
|
|
518
|
+
if (!this.store.cartItems || this.store.cartItems.length === 0) {
|
|
519
|
+
errors.push("购物车为空");
|
|
520
|
+
}
|
|
521
|
+
if (this.store.paymentMethods.length === 0) {
|
|
522
|
+
errors.push("无可用支付方式");
|
|
523
|
+
}
|
|
524
|
+
if (this.store.status === import_types.CheckoutStatus.Error) {
|
|
525
|
+
errors.push("结账流程存在错误");
|
|
526
|
+
}
|
|
527
|
+
return {
|
|
528
|
+
valid: errors.length === 0,
|
|
529
|
+
errors
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* 重试失败的操作
|
|
534
|
+
*/
|
|
535
|
+
async retryFailedOperationAsync() {
|
|
536
|
+
try {
|
|
537
|
+
if (this.store.status === import_types.CheckoutStatus.Error && this.store.lastError) {
|
|
538
|
+
switch (this.store.lastError.type) {
|
|
539
|
+
case import_types.CheckoutErrorType.OrderCreationFailed:
|
|
540
|
+
if (this.store.cartItems.length > 0) {
|
|
541
|
+
await this.createOrderAsync({
|
|
542
|
+
cartItems: this.store.cartItems
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
break;
|
|
546
|
+
case import_types.CheckoutErrorType.PaymentFailed:
|
|
547
|
+
if (this.store.currentOrder) {
|
|
548
|
+
await this.store.payment.runPaymentSyncQueue();
|
|
549
|
+
}
|
|
550
|
+
break;
|
|
551
|
+
default:
|
|
552
|
+
console.warn("[Checkout] 无法重试此类型的错误:", this.store.lastError.type);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
} catch (error) {
|
|
556
|
+
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* 设置当前步骤
|
|
561
|
+
*/
|
|
562
|
+
setCurrentStep(step) {
|
|
563
|
+
const oldStep = this.store.step;
|
|
564
|
+
this.store.step = step;
|
|
565
|
+
this.core.effects.emit(import_types.CheckoutHooks.OnStepChanged, {
|
|
566
|
+
oldStep,
|
|
567
|
+
newStep: step,
|
|
568
|
+
timestamp: Date.now()
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* 获取订单模块
|
|
573
|
+
*/
|
|
574
|
+
getOrderModule() {
|
|
575
|
+
return this.store.order;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* 获取支付模块
|
|
579
|
+
*/
|
|
580
|
+
getPaymentModule() {
|
|
581
|
+
return this.store.payment;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* 替换本地订单ID为真实订单ID
|
|
585
|
+
*
|
|
586
|
+
* 当后端订单创建完成后,调用此方法将本地虚拟订单ID替换为真实订单ID
|
|
587
|
+
*
|
|
588
|
+
* @param newOrderId 后端返回的真实订单ID
|
|
589
|
+
* @returns 更新后的订单对象,如果当前没有订单则返回null
|
|
590
|
+
*/
|
|
591
|
+
async replaceLocalOrderIdAsync(newOrderId) {
|
|
592
|
+
try {
|
|
593
|
+
if (!this.store.currentOrder) {
|
|
594
|
+
console.warn("[Checkout] 没有当前订单,无法替换订单ID");
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
const updatedOrder = await this.store.payment.replaceOrderIdByUuidAsync(
|
|
598
|
+
this.store.currentOrder.uuid,
|
|
599
|
+
newOrderId
|
|
600
|
+
);
|
|
601
|
+
if (updatedOrder) {
|
|
602
|
+
this.store.currentOrder = updatedOrder;
|
|
603
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
604
|
+
order: updatedOrder,
|
|
605
|
+
timestamp: Date.now()
|
|
606
|
+
});
|
|
607
|
+
console.log("[Checkout] 本地订单ID替换成功:", {
|
|
608
|
+
uuid: updatedOrder.uuid,
|
|
609
|
+
newOrderId: updatedOrder.id
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
return updatedOrder;
|
|
613
|
+
} catch (error) {
|
|
614
|
+
console.error("[Checkout] 替换订单ID失败:", error);
|
|
615
|
+
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
616
|
+
return null;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* 设置状态
|
|
621
|
+
*/
|
|
622
|
+
async setStatus(status) {
|
|
623
|
+
const oldStatus = this.store.status;
|
|
624
|
+
this.store.status = status;
|
|
625
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnStatusChanged, {
|
|
626
|
+
oldStatus,
|
|
627
|
+
newStatus: status,
|
|
628
|
+
timestamp: Date.now()
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* 设置步骤
|
|
633
|
+
*/
|
|
634
|
+
async setStep(step) {
|
|
635
|
+
const oldStep = this.store.step;
|
|
636
|
+
this.store.step = step;
|
|
637
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnStepChanged, {
|
|
638
|
+
oldStep,
|
|
639
|
+
newStep: step,
|
|
640
|
+
timestamp: Date.now()
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* 处理错误
|
|
645
|
+
*/
|
|
646
|
+
async handleError(error, type) {
|
|
647
|
+
const checkoutError = error instanceof Error && "type" in error ? error : (0, import_utils.createCheckoutError)(type, error.message, error);
|
|
648
|
+
this.store.lastError = checkoutError;
|
|
649
|
+
await this.setStatus(import_types.CheckoutStatus.Error);
|
|
650
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnError, {
|
|
651
|
+
error: checkoutError,
|
|
652
|
+
context: { status: this.store.status, step: this.store.step },
|
|
653
|
+
timestamp: Date.now()
|
|
654
|
+
});
|
|
655
|
+
console.error("[Checkout] 错误:", checkoutError);
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* 处理支付成功
|
|
659
|
+
*/
|
|
660
|
+
async handlePaymentSuccess(data) {
|
|
661
|
+
var _a;
|
|
662
|
+
await this.setStatus(import_types.CheckoutStatus.PaymentCompleted);
|
|
663
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentSuccess, {
|
|
664
|
+
orderUuid: data.orderUuid,
|
|
665
|
+
paymentMethodCode: "",
|
|
666
|
+
amount: ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0",
|
|
667
|
+
timestamp: data.timestamp
|
|
668
|
+
});
|
|
669
|
+
await this.completeCheckoutAsync();
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* 处理支付错误
|
|
673
|
+
*/
|
|
674
|
+
async handlePaymentError(data) {
|
|
675
|
+
var _a;
|
|
676
|
+
const error = (0, import_utils.createCheckoutError)(
|
|
677
|
+
import_types.CheckoutErrorType.PaymentFailed,
|
|
678
|
+
data.error || "支付同步失败"
|
|
679
|
+
);
|
|
680
|
+
await this.handleError(error instanceof Error ? error : new Error(String(error)), import_types.CheckoutErrorType.PaymentFailed);
|
|
681
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentFailed, {
|
|
682
|
+
orderUuid: data.orderUuid,
|
|
683
|
+
paymentMethodCode: "",
|
|
684
|
+
amount: ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0",
|
|
685
|
+
timestamp: data.timestamp
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* 验证结账参数
|
|
690
|
+
*/
|
|
691
|
+
async validateCheckoutParams(params) {
|
|
692
|
+
return (0, import_utils.validateCheckoutData)(params);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* 验证本地订单数据
|
|
696
|
+
*/
|
|
697
|
+
async validateLocalOrderData(orderData) {
|
|
698
|
+
const errors = [];
|
|
699
|
+
if (!orderData.type) {
|
|
700
|
+
errors.push("订单类型不能为空");
|
|
701
|
+
}
|
|
702
|
+
if (!orderData.platform) {
|
|
703
|
+
errors.push("平台信息不能为空");
|
|
704
|
+
}
|
|
705
|
+
if (!orderData.bookings || orderData.bookings.length === 0) {
|
|
706
|
+
errors.push("预订信息不能为空");
|
|
707
|
+
}
|
|
708
|
+
if (orderData.bookings) {
|
|
709
|
+
orderData.bookings.forEach((booking, index) => {
|
|
710
|
+
if (!booking.product || !booking.product.product_id) {
|
|
711
|
+
errors.push(`预订项 ${index + 1} 缺少商品信息`);
|
|
712
|
+
}
|
|
713
|
+
if (!booking.start_date) {
|
|
714
|
+
errors.push(`预订项 ${index + 1} 缺少开始日期`);
|
|
715
|
+
}
|
|
716
|
+
if (!booking.start_time) {
|
|
717
|
+
errors.push(`预订项 ${index + 1} 缺少开始时间`);
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
return {
|
|
722
|
+
valid: errors.length === 0,
|
|
723
|
+
errors
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* 生成本地订单ID
|
|
728
|
+
*/
|
|
729
|
+
generateLocalOrderId() {
|
|
730
|
+
const timestamp = Date.now();
|
|
731
|
+
const random = Math.floor(Math.random() * 1e4).toString().padStart(4, "0");
|
|
732
|
+
return `local_order_${timestamp}_${random}`;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* 从购物车小计数据中提取金额信息
|
|
736
|
+
*/
|
|
737
|
+
extractAmountFromCartSummary(cartSummary) {
|
|
738
|
+
const result = {
|
|
739
|
+
totalAmount: "0.00",
|
|
740
|
+
subTotal: "0.00",
|
|
741
|
+
taxAmount: "0.00",
|
|
742
|
+
discountAmount: "0.00",
|
|
743
|
+
shopDiscountAmount: "0.00",
|
|
744
|
+
roundingAmount: "0.00"
|
|
745
|
+
};
|
|
746
|
+
cartSummary.forEach((item) => {
|
|
747
|
+
const value = Number(item.value).toFixed(2);
|
|
748
|
+
switch (item.key) {
|
|
749
|
+
case "expect_amount":
|
|
750
|
+
result.totalAmount = value;
|
|
751
|
+
break;
|
|
752
|
+
case "sub_total":
|
|
753
|
+
result.subTotal = value;
|
|
754
|
+
break;
|
|
755
|
+
case "tax":
|
|
756
|
+
result.taxAmount = value;
|
|
757
|
+
if (item.tax) {
|
|
758
|
+
result.taxDetails = item.tax;
|
|
759
|
+
}
|
|
760
|
+
break;
|
|
761
|
+
case "discount":
|
|
762
|
+
result.discountAmount = value;
|
|
763
|
+
break;
|
|
764
|
+
case "shop_discount":
|
|
765
|
+
result.shopDiscountAmount = value;
|
|
766
|
+
break;
|
|
767
|
+
case "custom_roundingAmount":
|
|
768
|
+
result.roundingAmount = value;
|
|
769
|
+
break;
|
|
770
|
+
default:
|
|
771
|
+
if (item.key.includes("deposit")) {
|
|
772
|
+
result.depositAmount = value;
|
|
773
|
+
}
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
console.log("[Checkout] 从购物车小计提取金额信息:", {
|
|
778
|
+
totalAmount: result.totalAmount,
|
|
779
|
+
subTotal: result.subTotal,
|
|
780
|
+
taxAmount: result.taxAmount,
|
|
781
|
+
discountAmount: result.discountAmount,
|
|
782
|
+
shopDiscountAmount: result.shopDiscountAmount,
|
|
783
|
+
roundingAmount: result.roundingAmount
|
|
784
|
+
});
|
|
785
|
+
return result;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* 预加载支付方式(在初始化时调用)
|
|
789
|
+
*/
|
|
790
|
+
async preloadPaymentMethods() {
|
|
791
|
+
try {
|
|
792
|
+
console.log("[Checkout] 预加载支付方式...");
|
|
793
|
+
const methods = await this.store.payment.getPayMethodListAsync();
|
|
794
|
+
this.store.paymentMethods = methods;
|
|
795
|
+
console.log(`[Checkout] 预加载完成,共 ${methods.length} 种支付方式`);
|
|
796
|
+
} catch (error) {
|
|
797
|
+
console.error("[Checkout] 预加载支付方式失败:", error);
|
|
798
|
+
this.store.paymentMethods = [];
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* 计算总金额
|
|
803
|
+
*/
|
|
804
|
+
calculateTotalAmount(cartItems) {
|
|
805
|
+
const total = cartItems.reduce((sum, item) => {
|
|
806
|
+
const price = parseFloat(String(item.price) || "0");
|
|
807
|
+
const quantity = item.quantity || 1;
|
|
808
|
+
return sum + price * quantity;
|
|
809
|
+
}, 0);
|
|
810
|
+
return total.toFixed(2);
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* 计算已支付金额
|
|
814
|
+
*/
|
|
815
|
+
calculatePaidAmount() {
|
|
816
|
+
if (!this.store.currentOrder)
|
|
817
|
+
return "0.00";
|
|
818
|
+
const paidAmount = this.store.currentOrder.payment.reduce((sum, payment) => {
|
|
819
|
+
return sum + parseFloat(payment.amount);
|
|
820
|
+
}, 0);
|
|
821
|
+
return paidAmount.toFixed(2);
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* 获取状态消息
|
|
825
|
+
*/
|
|
826
|
+
getStatusMessage() {
|
|
827
|
+
var _a;
|
|
828
|
+
switch (this.store.status) {
|
|
829
|
+
case import_types.CheckoutStatus.Initializing:
|
|
830
|
+
return "正在初始化结账流程...";
|
|
831
|
+
case import_types.CheckoutStatus.Ready:
|
|
832
|
+
return "准备就绪,可以开始结账";
|
|
833
|
+
case import_types.CheckoutStatus.CreatingOrder:
|
|
834
|
+
return "正在创建订单...";
|
|
835
|
+
case import_types.CheckoutStatus.OrderCreated:
|
|
836
|
+
return "订单创建成功,请选择支付方式";
|
|
837
|
+
case import_types.CheckoutStatus.ProcessingPayment:
|
|
838
|
+
return "正在处理支付...";
|
|
839
|
+
case import_types.CheckoutStatus.PaymentCompleted:
|
|
840
|
+
return "支付完成";
|
|
841
|
+
case import_types.CheckoutStatus.Completed:
|
|
842
|
+
return "结账完成";
|
|
843
|
+
case import_types.CheckoutStatus.Cancelled:
|
|
844
|
+
return "结账已取消";
|
|
845
|
+
case import_types.CheckoutStatus.Error:
|
|
846
|
+
return ((_a = this.store.lastError) == null ? void 0 : _a.message) || "发生未知错误";
|
|
847
|
+
default:
|
|
848
|
+
return "";
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
async destroy() {
|
|
852
|
+
var _a, _b, _c, _d;
|
|
853
|
+
this.core.effects.offByModuleDestroy(this.name);
|
|
854
|
+
await ((_b = (_a = this.store.order) == null ? void 0 : _a.destroy) == null ? void 0 : _b.call(_a));
|
|
855
|
+
await ((_d = (_c = this.store.payment) == null ? void 0 : _c.destroy) == null ? void 0 : _d.call(_c));
|
|
856
|
+
this.core.unregisterModule(this);
|
|
857
|
+
console.log("[Checkout] 已销毁");
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
861
|
+
0 && (module.exports = {
|
|
862
|
+
CheckoutImpl,
|
|
863
|
+
...require("./types")
|
|
864
|
+
});
|