@pisell/pisellos 1.0.68 → 1.0.70
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/effects/index.d.ts +1 -0
- package/dist/effects/index.js +29 -6
- package/dist/modules/Account/index.js +2 -3
- package/dist/modules/BaseModule.d.ts +3 -0
- package/dist/modules/BaseModule.js +15 -0
- package/dist/modules/Customer/index.js +9 -10
- package/dist/modules/Customer/types.d.ts +2 -2
- package/dist/modules/Customer/types.js +2 -2
- package/dist/modules/Discount/index.js +1 -1
- package/dist/modules/Guests/index.js +9 -9
- package/dist/modules/Order/index.js +1 -1
- package/dist/modules/Payment/index.js +75 -65
- package/dist/modules/Payment/walletpass.js +4 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +2 -3
- package/dist/modules/Resource/index.js +1 -1
- package/dist/modules/Rules/index.js +2 -3
- package/dist/solution/BookingByStep/index.js +2 -2
- package/dist/solution/BookingTicket/index.d.ts +5 -1
- package/dist/solution/BookingTicket/index.js +17 -8
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +4 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +25 -16
- package/dist/solution/BuyTickets/index.js +7 -8
- package/dist/solution/Checkout/index.d.ts +50 -1
- package/dist/solution/Checkout/index.js +964 -544
- package/dist/solution/ShopDiscount/index.js +9 -10
- package/dist/types/index.d.ts +1 -0
- package/lib/effects/index.d.ts +1 -0
- package/lib/effects/index.js +13 -0
- package/lib/modules/Account/index.js +2 -3
- package/lib/modules/BaseModule.d.ts +3 -0
- package/lib/modules/BaseModule.js +9 -0
- package/lib/modules/Customer/index.js +9 -10
- package/lib/modules/Customer/types.d.ts +2 -2
- package/lib/modules/Customer/types.js +2 -2
- package/lib/modules/Discount/index.js +1 -1
- package/lib/modules/Guests/index.js +9 -9
- package/lib/modules/Order/index.js +1 -1
- package/lib/modules/Payment/index.js +46 -59
- package/lib/modules/Payment/walletpass.js +3 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +2 -3
- package/lib/modules/Resource/index.js +1 -1
- package/lib/modules/Rules/index.js +2 -3
- package/lib/solution/BookingByStep/index.js +1 -1
- package/lib/solution/BookingTicket/index.d.ts +5 -1
- package/lib/solution/BookingTicket/index.js +6 -6
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +4 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +7 -1
- package/lib/solution/BuyTickets/index.js +7 -8
- package/lib/solution/Checkout/index.d.ts +50 -1
- package/lib/solution/Checkout/index.js +343 -96
- package/lib/solution/ShopDiscount/index.js +10 -11
- package/lib/types/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/effects/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ type UnsubscribeFunction = () => void;
|
|
|
6
6
|
declare class EffectsManager {
|
|
7
7
|
private listeners;
|
|
8
8
|
on(event: string, callback: EffectCallback): UnsubscribeFunction;
|
|
9
|
+
only(event: string, callback: EffectCallback): UnsubscribeFunction;
|
|
9
10
|
off(event: string, callback: EffectCallback): void;
|
|
10
11
|
offByModuleDestroy(module: string): void;
|
|
11
12
|
once(event: string, callback: EffectCallback): UnsubscribeFunction;
|
package/dist/effects/index.js
CHANGED
|
@@ -30,28 +30,51 @@ var EffectsManager = /*#__PURE__*/function () {
|
|
|
30
30
|
_this.off(event, callback);
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
// 设置单例监听器,只能存在一个,新的会替换旧的
|
|
35
|
+
}, {
|
|
36
|
+
key: "only",
|
|
37
|
+
value: function only(event, callback) {
|
|
38
|
+
var _this$listeners$get3,
|
|
39
|
+
_this2 = this;
|
|
40
|
+
// 清除该事件的所有现有监听器
|
|
41
|
+
if (this.listeners.has(event)) {
|
|
42
|
+
var _this$listeners$get2;
|
|
43
|
+
(_this$listeners$get2 = this.listeners.get(event)) === null || _this$listeners$get2 === void 0 || _this$listeners$get2.clear();
|
|
44
|
+
} else {
|
|
45
|
+
this.listeners.set(event, new Set());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 添加新的监听器
|
|
49
|
+
(_this$listeners$get3 = this.listeners.get(event)) === null || _this$listeners$get3 === void 0 || _this$listeners$get3.add(callback);
|
|
50
|
+
|
|
51
|
+
// 返回取消函数
|
|
52
|
+
return function () {
|
|
53
|
+
_this2.off(event, callback);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
33
56
|
}, {
|
|
34
57
|
key: "off",
|
|
35
58
|
value: function off(event, callback) {
|
|
36
|
-
var _this$listeners$
|
|
37
|
-
(_this$listeners$
|
|
59
|
+
var _this$listeners$get4;
|
|
60
|
+
(_this$listeners$get4 = this.listeners.get(event)) === null || _this$listeners$get4 === void 0 || _this$listeners$get4.delete(callback);
|
|
38
61
|
}
|
|
39
62
|
|
|
40
63
|
// 模块销毁时,删除所有以模块名开头的监听
|
|
41
64
|
}, {
|
|
42
65
|
key: "offByModuleDestroy",
|
|
43
66
|
value: function offByModuleDestroy(module) {
|
|
44
|
-
var
|
|
67
|
+
var _this3 = this;
|
|
45
68
|
Array.from(this.listeners.keys()).forEach(function (item) {
|
|
46
69
|
if (item.startsWith(module)) {
|
|
47
|
-
|
|
70
|
+
_this3.listeners.delete(item);
|
|
48
71
|
}
|
|
49
72
|
});
|
|
50
73
|
}
|
|
51
74
|
}, {
|
|
52
75
|
key: "once",
|
|
53
76
|
value: function once(event, callback) {
|
|
54
|
-
var
|
|
77
|
+
var _this4 = this;
|
|
55
78
|
var wrapper = /*#__PURE__*/function () {
|
|
56
79
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(payload) {
|
|
57
80
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -60,7 +83,7 @@ var EffectsManager = /*#__PURE__*/function () {
|
|
|
60
83
|
_context.next = 2;
|
|
61
84
|
return callback(payload);
|
|
62
85
|
case 2:
|
|
63
|
-
|
|
86
|
+
_this4.off(event, wrapper);
|
|
64
87
|
case 3:
|
|
65
88
|
case "end":
|
|
66
89
|
return _context.stop();
|
|
@@ -18,7 +18,6 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
18
18
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
19
19
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
20
|
import { BaseModule } from "../BaseModule";
|
|
21
|
-
import { AccountHooks } from "./types";
|
|
22
21
|
export * from "./types";
|
|
23
22
|
export var AccountModule = /*#__PURE__*/function (_BaseModule) {
|
|
24
23
|
_inherits(AccountModule, _BaseModule);
|
|
@@ -85,7 +84,7 @@ export var AccountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
85
84
|
this.store.accountInfo = account;
|
|
86
85
|
this.store.isLoggedIn = true;
|
|
87
86
|
_context2.next = 5;
|
|
88
|
-
return this.core.effects.emit(
|
|
87
|
+
return this.core.effects.emit("".concat(this.name, ":onLogin"), account);
|
|
89
88
|
case 5:
|
|
90
89
|
case "end":
|
|
91
90
|
return _context2.stop();
|
|
@@ -117,7 +116,7 @@ export var AccountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
117
116
|
case 2:
|
|
118
117
|
this.store.accountInfo = _objectSpread(_objectSpread({}, this.store.accountInfo), updates);
|
|
119
118
|
_context3.next = 5;
|
|
120
|
-
return this.core.effects.emit(
|
|
119
|
+
return this.core.effects.emit("".concat(this.name, ":onProfileUpdate"), this.store.accountInfo);
|
|
121
120
|
case 5:
|
|
122
121
|
case "end":
|
|
123
122
|
return _context3.stop();
|
|
@@ -14,4 +14,7 @@ export declare class BaseModule {
|
|
|
14
14
|
store: any;
|
|
15
15
|
cacheKey: string[];
|
|
16
16
|
}): void;
|
|
17
|
+
effectsOn(eventType: string, callback: (payload: any) => void): () => void;
|
|
18
|
+
effectsOff(eventType: string, callback: (payload: any) => void): void;
|
|
19
|
+
effectsOnce(eventType: string, callback: (payload: any) => void): () => void;
|
|
17
20
|
}
|
|
@@ -66,6 +66,21 @@ export var BaseModule = /*#__PURE__*/function () {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
}, {
|
|
70
|
+
key: "effectsOn",
|
|
71
|
+
value: function effectsOn(eventType, callback) {
|
|
72
|
+
return this.core.effects.on("".concat(this.name, ":").concat(eventType), callback);
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "effectsOff",
|
|
76
|
+
value: function effectsOff(eventType, callback) {
|
|
77
|
+
return this.core.effects.off("".concat(this.name, ":").concat(eventType), callback);
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "effectsOnce",
|
|
81
|
+
value: function effectsOnce(eventType, callback) {
|
|
82
|
+
return this.core.effects.once("".concat(this.name, ":").concat(eventType), callback);
|
|
83
|
+
}
|
|
69
84
|
}]);
|
|
70
85
|
return BaseModule;
|
|
71
86
|
}();
|
|
@@ -29,7 +29,6 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
29
29
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
30
30
|
import { cloneDeep } from 'lodash-es';
|
|
31
31
|
import { BaseModule } from "../BaseModule";
|
|
32
|
-
import { CustomerHooks } from "./types";
|
|
33
32
|
import { DEFAULT_CUSTOMER, DEFAULT_PAGE_SIZE, SORT_BY } from "./constants";
|
|
34
33
|
export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
35
34
|
_inherits(CustomerModule, _BaseModule);
|
|
@@ -203,7 +202,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
203
202
|
console.error("Failed to ".concat(operation, ":"), error);
|
|
204
203
|
this.store.error = error instanceof Error ? error.message : "Failed to ".concat(operation);
|
|
205
204
|
_context3.next = 4;
|
|
206
|
-
return this.core.effects.emit(
|
|
205
|
+
return this.core.effects.emit("".concat(this.name, ":onCustomerListError"), this.store.error);
|
|
207
206
|
case 4:
|
|
208
207
|
case "end":
|
|
209
208
|
return _context3.stop();
|
|
@@ -266,7 +265,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
266
265
|
// 设置客户列表(替换模式)
|
|
267
266
|
this.store.customerList = cloneDeep(customerList);
|
|
268
267
|
_context4.next = 20;
|
|
269
|
-
return this.core.effects.emit(
|
|
268
|
+
return this.core.effects.emit("".concat(this.name, ":onCustomerListUpdate"), this.store);
|
|
270
269
|
case 20:
|
|
271
270
|
// 触发分页变化事件
|
|
272
271
|
this.triggerPaginationChange({
|
|
@@ -329,7 +328,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
329
328
|
key: "setSelectedCustomer",
|
|
330
329
|
value: function setSelectedCustomer(customer) {
|
|
331
330
|
this.store.selectedCustomer = !customer ? DEFAULT_CUSTOMER : cloneDeep(customer);
|
|
332
|
-
this.core.effects.emit(
|
|
331
|
+
this.core.effects.emit("".concat(this.name, ":onCustomerSelected"), this.store.selectedCustomer);
|
|
333
332
|
this.storeChange();
|
|
334
333
|
}
|
|
335
334
|
|
|
@@ -380,7 +379,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
380
379
|
this.store.hasMore = true;
|
|
381
380
|
this.store.loadingMore = false;
|
|
382
381
|
this.store.searchParams = {};
|
|
383
|
-
this.core.effects.emit(
|
|
382
|
+
this.core.effects.emit("".concat(this.name, ":onCustomerListUpdate"), this.store);
|
|
384
383
|
this.storeChange();
|
|
385
384
|
}
|
|
386
385
|
|
|
@@ -401,7 +400,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
401
400
|
this.store.total += 1;
|
|
402
401
|
|
|
403
402
|
// 触发客户列表更新事件
|
|
404
|
-
this.core.effects.emit(
|
|
403
|
+
this.core.effects.emit("".concat(this.name, ":onCustomerListUpdate"), this.store);
|
|
405
404
|
|
|
406
405
|
// 保存状态变化
|
|
407
406
|
this.storeChange();
|
|
@@ -439,7 +438,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
439
438
|
}, {
|
|
440
439
|
key: "triggerPaginationChange",
|
|
441
440
|
value: function triggerPaginationChange(pagination) {
|
|
442
|
-
this.core.effects.emit(
|
|
441
|
+
this.core.effects.emit("".concat(this.name, ":onPaginationChange"), pagination);
|
|
443
442
|
}
|
|
444
443
|
|
|
445
444
|
/**
|
|
@@ -552,7 +551,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
552
551
|
|
|
553
552
|
// 触发滚动加载特定事件
|
|
554
553
|
_context6.next = 20;
|
|
555
|
-
return this.core.effects.emit(
|
|
554
|
+
return this.core.effects.emit("".concat(this.name, ":onScrollLoadMore"), {
|
|
556
555
|
newCustomers: newCustomers,
|
|
557
556
|
allCustomers: this.store.customerList,
|
|
558
557
|
currentPage: page,
|
|
@@ -560,7 +559,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
560
559
|
});
|
|
561
560
|
case 20:
|
|
562
561
|
_context6.next = 22;
|
|
563
|
-
return this.core.effects.emit(
|
|
562
|
+
return this.core.effects.emit("".concat(this.name, ":onCustomerListUpdate"), this.store);
|
|
564
563
|
case 22:
|
|
565
564
|
// 触发分页变化事件
|
|
566
565
|
this.triggerPaginationChange({
|
|
@@ -634,7 +633,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
634
633
|
case 8:
|
|
635
634
|
response = _context7.sent;
|
|
636
635
|
_context7.next = 11;
|
|
637
|
-
return this.core.effects.emit(
|
|
636
|
+
return this.core.effects.emit("".concat(this.name, ":onScrollLoadComplete"), {
|
|
638
637
|
customers: this.store.customerList,
|
|
639
638
|
total: this.store.total,
|
|
640
639
|
hasMore: this.store.hasMore
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ICustomer } from "../AccountList/types";
|
|
2
2
|
export declare enum CustomerHooks {
|
|
3
|
-
OnCustomerListUpdate = "customer:
|
|
3
|
+
OnCustomerListUpdate = "customer:onCustomerListUpdate",
|
|
4
4
|
OnCustomerListError = "customer:onError",
|
|
5
|
-
OnCustomerSelected = "customer:
|
|
5
|
+
OnCustomerSelected = "customer:onCustomerSelected",
|
|
6
6
|
OnPaginationChange = "customer:onPaginationChange",
|
|
7
7
|
OnScrollLoadMore = "customer:onScrollLoadMore",
|
|
8
8
|
OnScrollLoadComplete = "customer:onScrollLoadComplete"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export var CustomerHooks = /*#__PURE__*/function (CustomerHooks) {
|
|
2
|
-
CustomerHooks["OnCustomerListUpdate"] = "customer:
|
|
2
|
+
CustomerHooks["OnCustomerListUpdate"] = "customer:onCustomerListUpdate";
|
|
3
3
|
CustomerHooks["OnCustomerListError"] = "customer:onError";
|
|
4
|
-
CustomerHooks["OnCustomerSelected"] = "customer:
|
|
4
|
+
CustomerHooks["OnCustomerSelected"] = "customer:onCustomerSelected";
|
|
5
5
|
CustomerHooks["OnPaginationChange"] = "customer:onPaginationChange";
|
|
6
6
|
CustomerHooks["OnScrollLoadMore"] = "customer:onScrollLoadMore";
|
|
7
7
|
CustomerHooks["OnScrollLoadComplete"] = "customer:onScrollLoadComplete";
|
|
@@ -283,7 +283,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
283
283
|
this.store.discountList = [];
|
|
284
284
|
this.core.effects.offByModuleDestroy(this.name);
|
|
285
285
|
_context5.next = 4;
|
|
286
|
-
return this.core.effects.emit(
|
|
286
|
+
return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
|
|
287
287
|
case 4:
|
|
288
288
|
console.log('[Discount] 已销毁');
|
|
289
289
|
case 5:
|
|
@@ -70,10 +70,10 @@ export var GuestListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
70
70
|
case 0:
|
|
71
71
|
this.state.list.push(guest);
|
|
72
72
|
_context2.next = 3;
|
|
73
|
-
return this.core.effects.emit(
|
|
73
|
+
return this.core.effects.emit("".concat(this.name, ":onGuestAdd"), guest);
|
|
74
74
|
case 3:
|
|
75
75
|
_context2.next = 5;
|
|
76
|
-
return this.core.effects.emit(
|
|
76
|
+
return this.core.effects.emit("".concat(this.name, ":onGuestChange"), this.state.list);
|
|
77
77
|
case 5:
|
|
78
78
|
case "end":
|
|
79
79
|
return _context2.stop();
|
|
@@ -107,7 +107,7 @@ export var GuestListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
107
107
|
return this.core.effects.emit(GuestHooks.OnGuestUpdate, this.state.list[index]);
|
|
108
108
|
case 6:
|
|
109
109
|
_context3.next = 8;
|
|
110
|
-
return this.core.effects.emit(
|
|
110
|
+
return this.core.effects.emit("".concat(this.name, ":onGuestChange"), this.state.list);
|
|
111
111
|
case 8:
|
|
112
112
|
case "end":
|
|
113
113
|
return _context3.stop();
|
|
@@ -138,10 +138,10 @@ export var GuestListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
138
138
|
case 3:
|
|
139
139
|
_this$state$list$spli = this.state.list.splice(index, 1), _this$state$list$spli2 = _slicedToArray(_this$state$list$spli, 1), removed = _this$state$list$spli2[0];
|
|
140
140
|
_context4.next = 6;
|
|
141
|
-
return this.core.effects.emit(
|
|
141
|
+
return this.core.effects.emit("".concat(this.name, ":onGuestRemove"), removed);
|
|
142
142
|
case 6:
|
|
143
143
|
_context4.next = 8;
|
|
144
|
-
return this.core.effects.emit(
|
|
144
|
+
return this.core.effects.emit("".concat(this.name, ":onGuestChange"), this.state.list);
|
|
145
145
|
case 8:
|
|
146
146
|
case "end":
|
|
147
147
|
return _context4.stop();
|
|
@@ -196,10 +196,10 @@ export var GuestListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
196
196
|
case 3:
|
|
197
197
|
guest.items.push(item);
|
|
198
198
|
_context6.next = 6;
|
|
199
|
-
return this.core.effects.emit(
|
|
199
|
+
return this.core.effects.emit("".concat(this.name, ":onGuestUpdate"), guest);
|
|
200
200
|
case 6:
|
|
201
201
|
_context6.next = 8;
|
|
202
|
-
return this.core.effects.emit(
|
|
202
|
+
return this.core.effects.emit("".concat(this.name, ":onGuestChange"), this.state.list);
|
|
203
203
|
case 8:
|
|
204
204
|
case "end":
|
|
205
205
|
return _context6.stop();
|
|
@@ -239,10 +239,10 @@ export var GuestListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
239
239
|
case 6:
|
|
240
240
|
guest.items.splice(index, 1);
|
|
241
241
|
_context7.next = 9;
|
|
242
|
-
return this.core.effects.emit(
|
|
242
|
+
return this.core.effects.emit("".concat(this.name, ":onGuestUpdate"), guest);
|
|
243
243
|
case 9:
|
|
244
244
|
_context7.next = 11;
|
|
245
|
-
return this.core.effects.emit(
|
|
245
|
+
return this.core.effects.emit("".concat(this.name, ":onGuestChange"), this.state.list);
|
|
246
246
|
case 11:
|
|
247
247
|
case "end":
|
|
248
248
|
return _context7.stop();
|
|
@@ -35,7 +35,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
35
35
|
function OrderModule(name, version) {
|
|
36
36
|
var _this;
|
|
37
37
|
_classCallCheck(this, OrderModule);
|
|
38
|
-
_this = _super.call(this, name, version);
|
|
38
|
+
_this = _super.call(this, name || "order", version);
|
|
39
39
|
_defineProperty(_assertThisInitialized(_this), "defaultName", 'order');
|
|
40
40
|
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
41
41
|
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
@@ -21,7 +21,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
21
21
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
22
22
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23
23
|
import { BaseModule } from "../BaseModule";
|
|
24
|
-
import { PaymentStatus,
|
|
24
|
+
import { PaymentStatus, PaymentMethodType, RoundingRule } from "./types";
|
|
25
25
|
import { getUniqueId } from "../Cart/utils";
|
|
26
26
|
import { CashPaymentImpl } from "./cash";
|
|
27
27
|
import { EftposPaymentImpl } from "./eftpos";
|
|
@@ -73,7 +73,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
73
73
|
function PaymentModule(name, version) {
|
|
74
74
|
var _this;
|
|
75
75
|
_classCallCheck(this, PaymentModule);
|
|
76
|
-
_this = _super.call(this, name, version);
|
|
76
|
+
_this = _super.call(this, name || "payment", version);
|
|
77
77
|
// 初始化支付方式实例
|
|
78
78
|
_defineProperty(_assertThisInitialized(_this), "defaultName", 'pay');
|
|
79
79
|
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
@@ -131,6 +131,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
131
131
|
return this.ensurePaymentTables();
|
|
132
132
|
case 14:
|
|
133
133
|
this.registerNetworkHandlers();
|
|
134
|
+
|
|
135
|
+
// // 预连接数据库
|
|
136
|
+
// this.dbManager.connect()
|
|
137
|
+
|
|
134
138
|
console.log('[PaymentModule] 初始化完成');
|
|
135
139
|
this.logInfo('PaymentModule initialized successfully');
|
|
136
140
|
case 17:
|
|
@@ -334,7 +338,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
334
338
|
console.warn('[PaymentModule] 无法缓存支付方式,pay_method 表不存在');
|
|
335
339
|
case 43:
|
|
336
340
|
_context3.next = 45;
|
|
337
|
-
return this.core.effects.emit(
|
|
341
|
+
return this.core.effects.emit("".concat(this.name, ":onPaymentMethodsLoaded"), payMethods);
|
|
338
342
|
case 45:
|
|
339
343
|
this.logInfo('getPayMethodListAsync completed successfully', {
|
|
340
344
|
methodCount: payMethods.length,
|
|
@@ -465,7 +469,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
465
469
|
newMethods: newPayMethods
|
|
466
470
|
};
|
|
467
471
|
_context4.next = 54;
|
|
468
|
-
return this.core.effects.emit(
|
|
472
|
+
return this.core.effects.emit("".concat(this.name, ":onPaymentMethodsChanged"), eventData);
|
|
469
473
|
case 54:
|
|
470
474
|
_context4.next = 57;
|
|
471
475
|
break;
|
|
@@ -657,7 +661,8 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
657
661
|
key: "createPaymentOrderAsync",
|
|
658
662
|
value: (function () {
|
|
659
663
|
var _createPaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
|
|
660
|
-
var
|
|
664
|
+
var _this3 = this;
|
|
665
|
+
var newOrder, dbAddStartTime, dbAddDuration;
|
|
661
666
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
662
667
|
while (1) switch (_context7.prev = _context7.next) {
|
|
663
668
|
case 0:
|
|
@@ -666,41 +671,41 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
666
671
|
totalAmount: params.total_amount
|
|
667
672
|
});
|
|
668
673
|
_context7.prev = 1;
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
this.logInfo('createPaymentOrderAsync existingOrder', {
|
|
674
|
-
existingOrder: existingOrder
|
|
675
|
-
});
|
|
674
|
+
// 检测是否有重复的 order_id
|
|
675
|
+
// console.time('createLocalOrderAsync: getExistingOrder')
|
|
676
|
+
// const existingOrder = await this.dbManager.get('order', params.order_id);
|
|
677
|
+
// const existingOrders = await this.dbManager.getAll('order');
|
|
676
678
|
// const existingOrder = existingOrders.find(
|
|
677
679
|
// (order: PaymentOrder) => String(order.id) === String(params.order_id),
|
|
678
680
|
// );
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
//
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
//
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
//
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
//
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
681
|
+
// this.logInfo('createPaymentOrderAsync existingOrder', {
|
|
682
|
+
// existingOrder
|
|
683
|
+
// });
|
|
684
|
+
// console.timeEnd('createLocalOrderAsync: getExistingOrder')
|
|
685
|
+
// const existingOrder = existingOrders.find(
|
|
686
|
+
// (order: PaymentOrder) => String(order.id) === String(params.order_id),
|
|
687
|
+
// );
|
|
688
|
+
// if (existingOrder) {
|
|
689
|
+
// // 如果存在相同 order_id 的订单,更新该订单信息
|
|
690
|
+
// this.logInfo(
|
|
691
|
+
// `createPaymentOrderAsync found duplicate order ID: ${params.order_id}, updating existing payment order`,
|
|
692
|
+
// );
|
|
693
|
+
// // const originalOrder = { ...existingOrder };
|
|
694
|
+
// existingOrder.order_info = params.order_info;
|
|
695
|
+
// existingOrder.total_amount = params.total_amount;
|
|
696
|
+
// existingOrder.is_deposit = params.is_deposit || 0;
|
|
697
|
+
// existingOrder.deposit_amount = params.deposit_amount || '0.00';
|
|
698
|
+
// // 重新计算待付金额
|
|
699
|
+
// this.recalculateOrderAmount(existingOrder);
|
|
700
|
+
// // 更新到数据库
|
|
701
|
+
// await this.dbManager.update('order', existingOrder);
|
|
702
|
+
// // 触发更新事件
|
|
703
|
+
// this.core.effects.emit(
|
|
704
|
+
// `${this.name}:onOrderUpdated`,
|
|
705
|
+
// existingOrder,
|
|
706
|
+
// );
|
|
707
|
+
// return existingOrder;
|
|
708
|
+
// } else {
|
|
704
709
|
// 创建新的支付订单
|
|
705
710
|
newOrder = {
|
|
706
711
|
uuid: getUniqueId('pay_order_'),
|
|
@@ -715,32 +720,37 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
715
720
|
tax_fee: '0.00',
|
|
716
721
|
is_deposit: params.is_deposit || 0,
|
|
717
722
|
deposit_amount: params.deposit_amount || '0.00'
|
|
718
|
-
};
|
|
719
|
-
|
|
723
|
+
}; // 🚀 性能监控:记录数据库添加操作耗时
|
|
724
|
+
dbAddStartTime = Date.now();
|
|
725
|
+
_context7.next = 6;
|
|
720
726
|
return this.dbManager.add('order', newOrder);
|
|
721
|
-
case
|
|
722
|
-
|
|
723
|
-
this.logInfo('
|
|
727
|
+
case 6:
|
|
728
|
+
dbAddDuration = Date.now() - dbAddStartTime;
|
|
729
|
+
this.logInfo('Database add operation completed', {
|
|
730
|
+
operation: 'dbManager.add',
|
|
731
|
+
table: 'order',
|
|
724
732
|
orderUuid: newOrder.uuid,
|
|
725
|
-
orderId: newOrder.
|
|
733
|
+
orderId: newOrder.order_id,
|
|
734
|
+
duration: "".concat(dbAddDuration, "ms"),
|
|
735
|
+
performance: dbAddDuration > 100 ? 'slow' : dbAddDuration > 50 ? 'medium' : 'fast'
|
|
726
736
|
});
|
|
737
|
+
setTimeout(function () {
|
|
738
|
+
_this3.core.effects.emit("".concat(_this3.name, ":onOrderAdded"), newOrder);
|
|
739
|
+
}, 0);
|
|
727
740
|
return _context7.abrupt("return", newOrder);
|
|
728
|
-
case
|
|
729
|
-
_context7.
|
|
730
|
-
break;
|
|
731
|
-
case 28:
|
|
732
|
-
_context7.prev = 28;
|
|
741
|
+
case 12:
|
|
742
|
+
_context7.prev = 12;
|
|
733
743
|
_context7.t0 = _context7["catch"](1);
|
|
734
744
|
console.error('[PaymentModule] 创建支付订单失败', _context7.t0);
|
|
735
745
|
this.logError('createPaymentOrderAsync failed', _context7.t0, {
|
|
736
746
|
orderId: params.order_id
|
|
737
747
|
});
|
|
738
748
|
throw _context7.t0;
|
|
739
|
-
case
|
|
749
|
+
case 17:
|
|
740
750
|
case "end":
|
|
741
751
|
return _context7.stop();
|
|
742
752
|
}
|
|
743
|
-
}, _callee7, this, [[1,
|
|
753
|
+
}, _callee7, this, [[1, 12]]);
|
|
744
754
|
}));
|
|
745
755
|
function createPaymentOrderAsync(_x6) {
|
|
746
756
|
return _createPaymentOrderAsync.apply(this, arguments);
|
|
@@ -772,7 +782,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
772
782
|
return this.dbManager.delete('order', orderUuid);
|
|
773
783
|
case 7:
|
|
774
784
|
_context8.next = 9;
|
|
775
|
-
return this.core.effects.emit(
|
|
785
|
+
return this.core.effects.emit("".concat(this.name, ":onOrderDeleted"), order);
|
|
776
786
|
case 9:
|
|
777
787
|
console.log('[PaymentModule] 支付订单删除成功:', orderUuid);
|
|
778
788
|
case 10:
|
|
@@ -821,10 +831,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
821
831
|
return this.dbManager.update('order', updatedOrder);
|
|
822
832
|
case 9:
|
|
823
833
|
_context9.next = 11;
|
|
824
|
-
return this.core.effects.emit(
|
|
834
|
+
return this.core.effects.emit("".concat(this.name, ":onOrderUpdated"), updatedOrder);
|
|
825
835
|
case 11:
|
|
826
836
|
_context9.next = 13;
|
|
827
|
-
return this.core.effects.emit(
|
|
837
|
+
return this.core.effects.emit("".concat(this.name, ":onOrderChanged"), {
|
|
828
838
|
action: 'update',
|
|
829
839
|
order: updatedOrder,
|
|
830
840
|
originalOrder: order
|
|
@@ -919,10 +929,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
919
929
|
return this.dbManager.update('order', updatedOrder);
|
|
920
930
|
case 19:
|
|
921
931
|
_context10.next = 21;
|
|
922
|
-
return this.core.effects.emit(
|
|
932
|
+
return this.core.effects.emit("".concat(this.name, ":onOrderUpdated"), updatedOrder);
|
|
923
933
|
case 21:
|
|
924
934
|
_context10.next = 23;
|
|
925
|
-
return this.core.effects.emit(
|
|
935
|
+
return this.core.effects.emit("".concat(this.name, ":onOrderChanged"), {
|
|
926
936
|
action: 'order_id_replaced',
|
|
927
937
|
order: updatedOrder,
|
|
928
938
|
originalOrder: existingOrder,
|
|
@@ -1119,7 +1129,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1119
1129
|
return this.dbManager.update('order', order);
|
|
1120
1130
|
case 21:
|
|
1121
1131
|
_context13.next = 23;
|
|
1122
|
-
return this.core.effects.emit(
|
|
1132
|
+
return this.core.effects.emit("".concat(this.name, ":onPaymentAdded"), {
|
|
1123
1133
|
orderUuid: orderUuid,
|
|
1124
1134
|
payment: newPaymentItem
|
|
1125
1135
|
});
|
|
@@ -1221,13 +1231,13 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1221
1231
|
return this.dbManager.update('order', order);
|
|
1222
1232
|
case 20:
|
|
1223
1233
|
_context14.next = 22;
|
|
1224
|
-
return this.core.effects.emit(
|
|
1234
|
+
return this.core.effects.emit("".concat(this.name, ":onPaymentDeleted"), {
|
|
1225
1235
|
order: order,
|
|
1226
1236
|
paymentItem: paymentItem
|
|
1227
1237
|
});
|
|
1228
1238
|
case 22:
|
|
1229
1239
|
_context14.next = 24;
|
|
1230
|
-
return this.core.effects.emit(
|
|
1240
|
+
return this.core.effects.emit("".concat(this.name, ":onOrderChanged"), {
|
|
1231
1241
|
action: 'payment_delete',
|
|
1232
1242
|
order: order,
|
|
1233
1243
|
paymentItem: paymentItem
|
|
@@ -1394,7 +1404,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1394
1404
|
case 50:
|
|
1395
1405
|
updatedOrder = _context15.sent;
|
|
1396
1406
|
_context15.next = 53;
|
|
1397
|
-
return this.core.effects.emit(
|
|
1407
|
+
return this.core.effects.emit("".concat(this.name, ":onPaymentAdded"), {
|
|
1398
1408
|
orderUuid: orderUuid,
|
|
1399
1409
|
order: updatedOrder,
|
|
1400
1410
|
payment: null // 批量操作不提供单个支付项
|
|
@@ -1473,13 +1483,13 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1473
1483
|
return this.dbManager.update('order', order);
|
|
1474
1484
|
case 14:
|
|
1475
1485
|
_context16.next = 16;
|
|
1476
|
-
return this.core.effects.emit(
|
|
1486
|
+
return this.core.effects.emit("".concat(this.name, ":onPaymentUpdated"), {
|
|
1477
1487
|
order: order,
|
|
1478
1488
|
paymentItem: paymentItem
|
|
1479
1489
|
});
|
|
1480
1490
|
case 16:
|
|
1481
1491
|
_context16.next = 18;
|
|
1482
|
-
return this.core.effects.emit(
|
|
1492
|
+
return this.core.effects.emit("".concat(this.name, ":onOrderChanged"), {
|
|
1483
1493
|
action: 'payment_update',
|
|
1484
1494
|
order: order,
|
|
1485
1495
|
paymentItem: paymentItem
|
|
@@ -1658,10 +1668,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1658
1668
|
return _context18.abrupt("return");
|
|
1659
1669
|
case 12:
|
|
1660
1670
|
_context18.next = 14;
|
|
1661
|
-
return this.core.effects.emit(
|
|
1671
|
+
return this.core.effects.emit("".concat(this.name, ":onPaymentSubmitted"), order);
|
|
1662
1672
|
case 14:
|
|
1663
1673
|
_context18.next = 16;
|
|
1664
|
-
return this.core.effects.emit(
|
|
1674
|
+
return this.core.effects.emit("".concat(this.name, ":onOrderChanged"), {
|
|
1665
1675
|
action: 'submit',
|
|
1666
1676
|
order: order
|
|
1667
1677
|
});
|
|
@@ -1808,7 +1818,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1808
1818
|
// 例如:amount=15, rounding_amount=-0.2,有效支付=15.2(抹掉0.2元零头)
|
|
1809
1819
|
var paymentAmount = new Decimal(payment.amount || 0);
|
|
1810
1820
|
var roundingAmount = new Decimal(payment.rounding_amount || 0);
|
|
1811
|
-
var effectiveAmount = paymentAmount.plus(roundingAmount.abs());
|
|
1821
|
+
var effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
|
|
1812
1822
|
return sum.plus(effectiveAmount);
|
|
1813
1823
|
} catch (error) {
|
|
1814
1824
|
console.warn("[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: amount=".concat(payment.amount, ", rounding_amount=").concat(payment.rounding_amount, "\uFF0C\u8DF3\u8FC7\u8BA1\u7B97"));
|
|
@@ -1836,7 +1846,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1836
1846
|
code: p.code,
|
|
1837
1847
|
amount: p.amount,
|
|
1838
1848
|
rounding_amount: p.rounding_amount || '0.00',
|
|
1839
|
-
effective_amount: new Decimal(p.amount || 0).plus(new Decimal(p.rounding_amount || 0).abs()).toFixed(2)
|
|
1849
|
+
effective_amount: new Decimal(p.amount || 0).plus(new Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || 0).abs()).toFixed(2)
|
|
1840
1850
|
};
|
|
1841
1851
|
}),
|
|
1842
1852
|
说明: '有效支付金额包含抹零计算(amount + |rounding_amount|)'
|
|
@@ -40,7 +40,10 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
|
|
|
40
40
|
key: "emitEvent",
|
|
41
41
|
value: function emitEvent(hook, data) {
|
|
42
42
|
try {
|
|
43
|
-
|
|
43
|
+
// 提取事件名称,去掉模块前缀
|
|
44
|
+
var eventName = hook.split(':')[1] || hook.replace(/^[A-Z][a-z]+/, '').replace(/^On/, '').toLowerCase();
|
|
45
|
+
var fullEventName = "".concat(this.paymentModule.name, ":").concat(eventName);
|
|
46
|
+
this.paymentModule.core.effects.emit(fullEventName, data);
|
|
44
47
|
} catch (error) {
|
|
45
48
|
this.paymentModule.logError('[WalletPass] 发送事件失败', error, {
|
|
46
49
|
hook: hook
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "normal" | "duration" | "session";
|
|
53
53
|
}
|