@pisell/pisellos 0.0.327 → 0.0.329
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/Payment/index.js +56 -46
- package/dist/solution/BookingTicket/index.d.ts +4 -0
- package/dist/solution/BookingTicket/index.js +10 -1
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +4 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +25 -16
- package/dist/solution/Checkout/index.d.ts +46 -1
- package/dist/solution/Checkout/index.js +820 -503
- package/dist/solution/ShopDiscount/index.js +8 -8
- 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/Payment/index.js +27 -40
- package/lib/solution/BookingTicket/index.d.ts +4 -0
- package/lib/solution/BookingTicket/index.js +6 -0
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +4 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +7 -1
- package/lib/solution/Checkout/index.d.ts +46 -1
- package/lib/solution/Checkout/index.js +258 -63
- package/lib/solution/ShopDiscount/index.js +9 -9
- package/lib/types/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -195,7 +195,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
195
195
|
key: "registerEventListeners",
|
|
196
196
|
value: function registerEventListeners() {
|
|
197
197
|
var _this2 = this;
|
|
198
|
-
this.core.effects.
|
|
198
|
+
this.core.effects.only("".concat(this.name, ":onCustomerChange"), function (customer) {
|
|
199
199
|
var _this2$options$otherP;
|
|
200
200
|
if ((_this2$options$otherP = _this2.options.otherParams) !== null && _this2$options$otherP !== void 0 && _this2$options$otherP.cacheId && _this2.getDiscountList().length) {
|
|
201
201
|
return;
|
|
@@ -306,7 +306,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
306
306
|
}
|
|
307
307
|
this.store.customer = customer;
|
|
308
308
|
_context6.next = 4;
|
|
309
|
-
return this.core.effects.emit(
|
|
309
|
+
return this.core.effects.emit("".concat(this.name, ":onCustomerChange"), customer);
|
|
310
310
|
case 4:
|
|
311
311
|
case "end":
|
|
312
312
|
return _context6.stop();
|
|
@@ -531,7 +531,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
531
531
|
while (1) switch (_context8.prev = _context8.next) {
|
|
532
532
|
case 0:
|
|
533
533
|
_context8.next = 2;
|
|
534
|
-
return this.core.effects.emit(
|
|
534
|
+
return this.core.effects.emit("".concat(this.name, ":onDiscountListChange"), discountList);
|
|
535
535
|
case 2:
|
|
536
536
|
case "end":
|
|
537
537
|
return _context8.stop();
|
|
@@ -662,7 +662,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
662
662
|
customer = Object.assign({}, (_objectDestructuringEmpty(_result2.data), _result2.data));
|
|
663
663
|
this.setCustomer(customer);
|
|
664
664
|
_context9.next = 9;
|
|
665
|
-
return this.core.effects.emit(
|
|
665
|
+
return this.core.effects.emit("".concat(this.name, ":onScanCustomerChange"), customer);
|
|
666
666
|
case 9:
|
|
667
667
|
_context9.next = 14;
|
|
668
668
|
break;
|
|
@@ -699,10 +699,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
699
699
|
_result3 = this.calcDiscount(this.store.productList);
|
|
700
700
|
cb === null || cb === void 0 || cb(_result3);
|
|
701
701
|
_context10.next = 7;
|
|
702
|
-
return this.core.effects.emit(
|
|
702
|
+
return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"), _result3);
|
|
703
703
|
case 7:
|
|
704
704
|
_context10.next = 9;
|
|
705
|
-
return this.core.effects.emit(
|
|
705
|
+
return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), newDiscountList);
|
|
706
706
|
case 9:
|
|
707
707
|
case "end":
|
|
708
708
|
return _context10.stop();
|
|
@@ -759,10 +759,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
759
759
|
}
|
|
760
760
|
_result4 = this.calcDiscount(this.store.productList);
|
|
761
761
|
_context11.next = 19;
|
|
762
|
-
return this.core.effects.emit(
|
|
762
|
+
return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"), _result4);
|
|
763
763
|
case 19:
|
|
764
764
|
_context11.next = 21;
|
|
765
|
-
return this.core.effects.emit(
|
|
765
|
+
return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), filteredDiscountList);
|
|
766
766
|
case 21:
|
|
767
767
|
_context11.next = 26;
|
|
768
768
|
break;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface PisellCore {
|
|
|
40
40
|
effects: {
|
|
41
41
|
on: (event: string, callback: (payload: any) => void) => () => void;
|
|
42
42
|
once: (event: string, callback: (payload: any) => void) => () => void;
|
|
43
|
+
only: (event: string, callback: (payload: any) => void) => () => void;
|
|
43
44
|
off: (event: string, callback: (payload: any) => void) => void;
|
|
44
45
|
emit: (event: string, payload: any, value?: any) => Promise<{
|
|
45
46
|
status: boolean;
|
package/lib/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/lib/effects/index.js
CHANGED
|
@@ -35,6 +35,19 @@ var EffectsManager = class {
|
|
|
35
35
|
this.off(event, callback);
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
+
// 设置单例监听器,只能存在一个,新的会替换旧的
|
|
39
|
+
only(event, callback) {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
if (this.listeners.has(event)) {
|
|
42
|
+
(_a = this.listeners.get(event)) == null ? void 0 : _a.clear();
|
|
43
|
+
} else {
|
|
44
|
+
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
45
|
+
}
|
|
46
|
+
(_b = this.listeners.get(event)) == null ? void 0 : _b.add(callback);
|
|
47
|
+
return () => {
|
|
48
|
+
this.off(event, callback);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
38
51
|
off(event, callback) {
|
|
39
52
|
var _a;
|
|
40
53
|
(_a = this.listeners.get(event)) == null ? void 0 : _a.delete(callback);
|
|
@@ -323,48 +323,35 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
323
323
|
totalAmount: params.total_amount
|
|
324
324
|
});
|
|
325
325
|
try {
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
326
|
+
const newOrder = {
|
|
327
|
+
uuid: (0, import_utils.getUniqueId)("pay_order_"),
|
|
328
|
+
id: params.order_id,
|
|
329
|
+
order_id: params.order_id,
|
|
330
|
+
order_info: params.order_info,
|
|
331
|
+
payment_status: import_types.PaymentStatus.Processing,
|
|
332
|
+
payment: [],
|
|
333
|
+
adjust_offline_payments: [],
|
|
334
|
+
total_amount: params.total_amount,
|
|
335
|
+
expect_amount: params.total_amount,
|
|
336
|
+
tax_fee: "0.00",
|
|
337
|
+
is_deposit: params.is_deposit || 0,
|
|
338
|
+
deposit_amount: params.deposit_amount || "0.00"
|
|
339
|
+
};
|
|
340
|
+
const dbAddStartTime = Date.now();
|
|
341
|
+
await this.dbManager.add("order", newOrder);
|
|
342
|
+
const dbAddDuration = Date.now() - dbAddStartTime;
|
|
343
|
+
this.logInfo("Database add operation completed", {
|
|
344
|
+
operation: "dbManager.add",
|
|
345
|
+
table: "order",
|
|
346
|
+
orderUuid: newOrder.uuid,
|
|
347
|
+
orderId: newOrder.order_id,
|
|
348
|
+
duration: `${dbAddDuration}ms`,
|
|
349
|
+
performance: dbAddDuration > 100 ? "slow" : dbAddDuration > 50 ? "medium" : "fast"
|
|
329
350
|
});
|
|
330
|
-
|
|
331
|
-
this.logInfo(
|
|
332
|
-
`createPaymentOrderAsync found duplicate order ID: ${params.order_id}, updating existing payment order`
|
|
333
|
-
);
|
|
334
|
-
existingOrder.order_info = params.order_info;
|
|
335
|
-
existingOrder.total_amount = params.total_amount;
|
|
336
|
-
existingOrder.is_deposit = params.is_deposit || 0;
|
|
337
|
-
existingOrder.deposit_amount = params.deposit_amount || "0.00";
|
|
338
|
-
this.recalculateOrderAmount(existingOrder);
|
|
339
|
-
await this.dbManager.update("order", existingOrder);
|
|
340
|
-
await this.core.effects.emit(
|
|
341
|
-
`${this.name}:onOrderUpdated`,
|
|
342
|
-
existingOrder
|
|
343
|
-
);
|
|
344
|
-
return existingOrder;
|
|
345
|
-
} else {
|
|
346
|
-
const newOrder = {
|
|
347
|
-
uuid: (0, import_utils.getUniqueId)("pay_order_"),
|
|
348
|
-
id: params.order_id,
|
|
349
|
-
order_id: params.order_id,
|
|
350
|
-
order_info: params.order_info,
|
|
351
|
-
payment_status: import_types.PaymentStatus.Processing,
|
|
352
|
-
payment: [],
|
|
353
|
-
adjust_offline_payments: [],
|
|
354
|
-
total_amount: params.total_amount,
|
|
355
|
-
expect_amount: params.total_amount,
|
|
356
|
-
tax_fee: "0.00",
|
|
357
|
-
is_deposit: params.is_deposit || 0,
|
|
358
|
-
deposit_amount: params.deposit_amount || "0.00"
|
|
359
|
-
};
|
|
360
|
-
await this.dbManager.add("order", newOrder);
|
|
351
|
+
setTimeout(() => {
|
|
361
352
|
this.core.effects.emit(`${this.name}:onOrderAdded`, newOrder);
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
orderId: newOrder.id
|
|
365
|
-
});
|
|
366
|
-
return newOrder;
|
|
367
|
-
}
|
|
353
|
+
}, 0);
|
|
354
|
+
return newOrder;
|
|
368
355
|
} catch (error) {
|
|
369
356
|
console.error("[PaymentModule] 创建支付订单失败", error);
|
|
370
357
|
this.logError("createPaymentOrderAsync failed", error, {
|
|
@@ -22,6 +22,10 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
22
22
|
* @returns 商品列表
|
|
23
23
|
*/
|
|
24
24
|
loadProducts(params?: ILoadProductsParams): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* 初始化外设扫码结果监听
|
|
27
|
+
*/
|
|
28
|
+
initPeripheralsListener(): void;
|
|
25
29
|
/**
|
|
26
30
|
* 获取商品列表(不加载到模块中)
|
|
27
31
|
* @returns 商品列表
|
|
@@ -122,6 +122,12 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
122
122
|
throw error;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* 初始化外设扫码结果监听
|
|
127
|
+
*/
|
|
128
|
+
initPeripheralsListener() {
|
|
129
|
+
this.scan.initPeripheralsListener();
|
|
130
|
+
}
|
|
125
131
|
/**
|
|
126
132
|
* 获取商品列表(不加载到模块中)
|
|
127
133
|
* @returns 商品列表
|
|
@@ -37,9 +37,15 @@ var import_task = __toESM(require("../../../../utils/task"));
|
|
|
37
37
|
var Scan = class {
|
|
38
38
|
constructor(solution, watchKey) {
|
|
39
39
|
this.listenerConfig = /* @__PURE__ */ new Map();
|
|
40
|
-
var _a, _b, _c, _d, _e;
|
|
41
40
|
this.solution = solution;
|
|
42
41
|
this.watchKey = watchKey;
|
|
42
|
+
this.initPeripheralsListener();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 初始化外设扫码结果监听
|
|
46
|
+
*/
|
|
47
|
+
initPeripheralsListener() {
|
|
48
|
+
var _a, _b, _c, _d, _e;
|
|
43
49
|
(_e = (_d = (_c = (_b = (_a = this.solution) == null ? void 0 : _a.window) == null ? void 0 : _b.interaction) == null ? void 0 : _c.utils) == null ? void 0 : _d.mountFunction) == null ? void 0 : _e.call(
|
|
44
50
|
_d,
|
|
45
51
|
"global",
|
|
@@ -19,6 +19,7 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
19
19
|
private store;
|
|
20
20
|
private otherParams;
|
|
21
21
|
private logger;
|
|
22
|
+
private calculationCache;
|
|
22
23
|
order: OrderModule;
|
|
23
24
|
payment: PaymentModule;
|
|
24
25
|
constructor(name?: string, version?: string);
|
|
@@ -302,16 +303,46 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
302
303
|
* 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
|
|
303
304
|
*/
|
|
304
305
|
private cleanupExpiredOrdersAsync;
|
|
306
|
+
/**
|
|
307
|
+
* 清除计算缓存
|
|
308
|
+
*/
|
|
309
|
+
private clearCalculationCache;
|
|
310
|
+
/**
|
|
311
|
+
* 批量获取订单数据(用于性能优化)
|
|
312
|
+
* 一次性获取所有需要的数据,避免重复查询
|
|
313
|
+
*/
|
|
314
|
+
private fetchOrderDataBatch;
|
|
315
|
+
/**
|
|
316
|
+
* 从支付项数组计算已支付金额(纯计算,不查询数据库)
|
|
317
|
+
*/
|
|
318
|
+
private calculatePaidAmountFromItems;
|
|
305
319
|
/**
|
|
306
320
|
* 计算已支付金额(从 Payment 模块获取最新数据)
|
|
321
|
+
*
|
|
322
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
323
|
+
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
307
324
|
*/
|
|
308
325
|
private calculatePaidAmountAsync;
|
|
326
|
+
/**
|
|
327
|
+
* 从订单和支付项计算剩余金额(纯计算,不查询数据库)
|
|
328
|
+
*/
|
|
329
|
+
private calculateRemainingAmountFromData;
|
|
330
|
+
/**
|
|
331
|
+
* 从订单和支付项计算剩余总金额(纯计算,排除定金)
|
|
332
|
+
*/
|
|
333
|
+
private calculateRemainingTotalAmountFromData;
|
|
309
334
|
/**
|
|
310
335
|
* 计算剩余未支付金额(从 Payment 模块获取最新数据)
|
|
336
|
+
*
|
|
337
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
338
|
+
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
311
339
|
*/
|
|
312
340
|
private calculateRemainingAmountAsync;
|
|
313
341
|
/**
|
|
314
342
|
* 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
|
|
343
|
+
*
|
|
344
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
345
|
+
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
315
346
|
*/
|
|
316
347
|
private calculateRemainingTotalAmountAsync;
|
|
317
348
|
/**
|
|
@@ -320,12 +351,24 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
320
351
|
private updateBalanceDueAmount;
|
|
321
352
|
/**
|
|
322
353
|
* 更新 stateAmount 为当前剩余未支付金额
|
|
354
|
+
*
|
|
355
|
+
* 优化版本:批量获取数据,避免重复查询数据库
|
|
323
356
|
*/
|
|
324
357
|
private updateStateAmountToRemaining;
|
|
358
|
+
/**
|
|
359
|
+
* 检查订单支付是否完成(优化版,复用已获取的数据)
|
|
360
|
+
*
|
|
361
|
+
* @param paymentItems 已获取的支付项数据
|
|
362
|
+
* @param remainingAmount 已计算的剩余金额
|
|
363
|
+
*/
|
|
364
|
+
private checkOrderPaymentCompletionOptimized;
|
|
325
365
|
/**
|
|
326
366
|
* 检查订单支付是否完成
|
|
327
367
|
*
|
|
328
368
|
* 当剩余待付款金额 <= 0 时,触发订单支付完成事件
|
|
369
|
+
*
|
|
370
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
371
|
+
* 在 updateStateAmountToRemaining 中会使用优化版本。
|
|
329
372
|
*/
|
|
330
373
|
private checkOrderPaymentCompletion;
|
|
331
374
|
/**
|
|
@@ -381,6 +424,8 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
381
424
|
* 重置 store 状态
|
|
382
425
|
*
|
|
383
426
|
* 在创建新订单前调用,确保状态完全干净
|
|
427
|
+
*
|
|
428
|
+
* 🚀 性能优化:改为同步方法,事件发射不阻塞主流程
|
|
384
429
|
*/
|
|
385
|
-
private
|
|
430
|
+
private resetStoreState;
|
|
386
431
|
}
|