@pisell/pisellos 2.2.19 → 2.2.21
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/modules/Payment/index.d.ts +3 -0
- package/dist/modules/Payment/index.js +456 -368
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/index.js +11 -5
- package/lib/modules/Payment/index.d.ts +3 -0
- package/lib/modules/Payment/index.js +113 -60
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/index.js +5 -2
- package/package.json +1 -1
|
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
123
123
|
* 获取当前的客户搜索条件
|
|
124
124
|
* @returns 当前搜索条件
|
|
125
125
|
*/
|
|
126
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
126
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
127
127
|
/**
|
|
128
128
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
129
129
|
* @returns 客户状态
|
|
@@ -270,14 +270,20 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
270
270
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
271
271
|
while (1) switch (_context4.prev = _context4.next) {
|
|
272
272
|
case 0:
|
|
273
|
+
if (!(this.isWalkIn() && this.isWalkIn(customer === null || customer === void 0 ? void 0 : customer.id))) {
|
|
274
|
+
_context4.next = 2;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
return _context4.abrupt("return");
|
|
278
|
+
case 2:
|
|
273
279
|
if (!(((_this$store$customer = this.store.customer) === null || _this$store$customer === void 0 ? void 0 : _this$store$customer.id) !== customer.id)) {
|
|
274
|
-
_context4.next =
|
|
280
|
+
_context4.next = 6;
|
|
275
281
|
break;
|
|
276
282
|
}
|
|
277
283
|
this.store.customer = customer;
|
|
278
|
-
_context4.next =
|
|
284
|
+
_context4.next = 6;
|
|
279
285
|
return this.core.effects.emit("".concat(this.name, ":onCustomerChange"), customer);
|
|
280
|
-
case
|
|
286
|
+
case 6:
|
|
281
287
|
case "end":
|
|
282
288
|
return _context4.stop();
|
|
283
289
|
}
|
|
@@ -522,9 +528,9 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
522
528
|
// 是否是walkIn
|
|
523
529
|
}, {
|
|
524
530
|
key: "isWalkIn",
|
|
525
|
-
value: function isWalkIn() {
|
|
531
|
+
value: function isWalkIn(id) {
|
|
526
532
|
var _this$getCustomer;
|
|
527
|
-
return (((_this$getCustomer = this.getCustomer()) === null || _this$getCustomer === void 0 ? void 0 : _this$getCustomer.id) || 1) === 1;
|
|
533
|
+
return (id !== null && id !== void 0 ? id : ((_this$getCustomer = this.getCustomer()) === null || _this$getCustomer === void 0 ? void 0 : _this$getCustomer.id) || 1) === 1;
|
|
528
534
|
}
|
|
529
535
|
|
|
530
536
|
// 触发优惠列表变更事件
|
|
@@ -23,11 +23,14 @@ export declare class PaymentModule extends BaseModule implements Module, Payment
|
|
|
23
23
|
private store;
|
|
24
24
|
private dbManager;
|
|
25
25
|
private logger;
|
|
26
|
+
private voucherUpdateLockByOrderUuid;
|
|
26
27
|
protected otherParams: any;
|
|
27
28
|
cash: CashPayment;
|
|
28
29
|
eftpos: EftposPayment;
|
|
29
30
|
wallet: WalletPassPayment;
|
|
30
31
|
constructor(name?: string, version?: string);
|
|
32
|
+
private runVoucherUpdateLocked;
|
|
33
|
+
private normalizeVoucherPaymentItems;
|
|
31
34
|
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
32
35
|
/**
|
|
33
36
|
* 记录信息日志
|
|
@@ -68,11 +68,38 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
68
68
|
this.defaultName = "pay";
|
|
69
69
|
this.defaultVersion = "1.0.0";
|
|
70
70
|
// LoggerManager 实例
|
|
71
|
+
this.voucherUpdateLockByOrderUuid = /* @__PURE__ */ new Map();
|
|
71
72
|
this.otherParams = {};
|
|
72
73
|
this.cash = new import_cash.CashPaymentImpl(this);
|
|
73
74
|
this.eftpos = new import_eftpos.EftposPaymentImpl(this);
|
|
74
75
|
this.wallet = new import_walletpass.WalletPassPaymentImpl(this);
|
|
75
76
|
}
|
|
77
|
+
runVoucherUpdateLocked(orderUuid, task) {
|
|
78
|
+
const previous = this.voucherUpdateLockByOrderUuid.get(orderUuid) || Promise.resolve();
|
|
79
|
+
const next = previous.catch(() => void 0).then(task).finally(() => {
|
|
80
|
+
if (this.voucherUpdateLockByOrderUuid.get(orderUuid) === next) {
|
|
81
|
+
this.voucherUpdateLockByOrderUuid.delete(orderUuid);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
this.voucherUpdateLockByOrderUuid.set(orderUuid, next);
|
|
85
|
+
return next;
|
|
86
|
+
}
|
|
87
|
+
normalizeVoucherPaymentItems(voucherPaymentItems) {
|
|
88
|
+
const normalized = /* @__PURE__ */ new Map();
|
|
89
|
+
for (const item of voucherPaymentItems || []) {
|
|
90
|
+
if (!(item == null ? void 0 : item.voucher_id)) {
|
|
91
|
+
throw new Error(`代金券支付项缺少 voucher_id: ${JSON.stringify(item)}`);
|
|
92
|
+
}
|
|
93
|
+
const orderPaymentType = item.order_payment_type || "normal";
|
|
94
|
+
const key = `${item.voucher_id}|${orderPaymentType}`;
|
|
95
|
+
normalized.set(key, { ...item, order_payment_type: orderPaymentType });
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
items: Array.from(normalized.values()),
|
|
99
|
+
originalCount: (voucherPaymentItems == null ? void 0 : voucherPaymentItems.length) || 0,
|
|
100
|
+
normalizedCount: normalized.size
|
|
101
|
+
};
|
|
102
|
+
}
|
|
76
103
|
async initialize(core, options) {
|
|
77
104
|
this.core = core;
|
|
78
105
|
this.store = options.store;
|
|
@@ -726,76 +753,102 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
726
753
|
* 这是一个覆盖式更新,确保代金券支付项的一致性
|
|
727
754
|
*/
|
|
728
755
|
async updateVoucherPaymentItemsAsync(orderUuid, voucherPaymentItems) {
|
|
729
|
-
this.
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
voucherItems: voucherPaymentItems.map((item) => ({
|
|
733
|
-
code: item.code,
|
|
734
|
-
amount: item.amount,
|
|
735
|
-
voucher_id: item.voucher_id,
|
|
736
|
-
order_payment_type: item.order_payment_type
|
|
737
|
-
}))
|
|
738
|
-
});
|
|
739
|
-
try {
|
|
740
|
-
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
741
|
-
if (!order) {
|
|
742
|
-
throw new Error(`订单不存在: ${orderUuid}`);
|
|
743
|
-
}
|
|
744
|
-
const existingVoucherItems = order.payment.filter(
|
|
745
|
-
(payment) => payment.voucher_id && payment.status !== "voided" && !payment.isSynced
|
|
746
|
-
);
|
|
747
|
-
console.log("[PaymentModule] 发现现有代金券支付项:", {
|
|
756
|
+
return this.runVoucherUpdateLocked(orderUuid, async () => {
|
|
757
|
+
const { items: normalizedVoucherItems, originalCount, normalizedCount } = this.normalizeVoucherPaymentItems(voucherPaymentItems);
|
|
758
|
+
this.logInfo("Starting updateVoucherPaymentItemsAsync", {
|
|
748
759
|
orderUuid,
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
760
|
+
originalVoucherCount: originalCount,
|
|
761
|
+
normalizedVoucherCount: normalizedCount,
|
|
762
|
+
voucherItems: normalizedVoucherItems.map((item) => ({
|
|
752
763
|
code: item.code,
|
|
753
764
|
amount: item.amount,
|
|
754
765
|
voucher_id: item.voucher_id,
|
|
755
|
-
|
|
766
|
+
order_payment_type: item.order_payment_type
|
|
756
767
|
}))
|
|
757
768
|
});
|
|
758
|
-
|
|
759
|
-
console.
|
|
760
|
-
|
|
769
|
+
if (originalCount !== normalizedCount) {
|
|
770
|
+
console.warn("[PaymentModule] voucherPaymentItems detected duplicates (deduped by voucher_id + order_payment_type)", {
|
|
771
|
+
orderUuid,
|
|
772
|
+
originalCount,
|
|
773
|
+
normalizedCount
|
|
774
|
+
});
|
|
761
775
|
}
|
|
762
|
-
|
|
763
|
-
orderUuid
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
776
|
+
try {
|
|
777
|
+
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
778
|
+
if (!order) {
|
|
779
|
+
throw new Error(`订单不存在: ${orderUuid}`);
|
|
780
|
+
}
|
|
781
|
+
const existingVoucherItems = order.payment.filter(
|
|
782
|
+
(payment) => payment.voucher_id && payment.status !== "voided" && !payment.isSynced
|
|
783
|
+
);
|
|
784
|
+
console.log("[PaymentModule] 发现现有代金券支付项:", {
|
|
785
|
+
orderUuid,
|
|
786
|
+
existingVoucherCount: existingVoucherItems.length,
|
|
787
|
+
existingItems: existingVoucherItems.map((item) => ({
|
|
788
|
+
uuid: item.uuid,
|
|
789
|
+
code: item.code,
|
|
790
|
+
amount: item.amount,
|
|
791
|
+
voucher_id: item.voucher_id,
|
|
792
|
+
isSynced: item.isSynced
|
|
793
|
+
}))
|
|
794
|
+
});
|
|
795
|
+
for (const voucherItem of existingVoucherItems) {
|
|
796
|
+
console.log(`[PaymentModule] 删除现有代金券支付项: ${voucherItem.uuid}`);
|
|
797
|
+
await this.deletePaymentAsync(orderUuid, voucherItem.uuid);
|
|
769
798
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
799
|
+
const orderAfterDelete = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
800
|
+
if (!orderAfterDelete) {
|
|
801
|
+
throw new Error(`订单不存在: ${orderUuid}`);
|
|
802
|
+
}
|
|
803
|
+
const existingActiveVoucherKeys = new Set(
|
|
804
|
+
orderAfterDelete.payment.filter((p) => p.voucher_id && p.status !== "voided").map((p) => `${p.voucher_id}|${p.order_payment_type || "normal"}`)
|
|
805
|
+
);
|
|
806
|
+
console.log("[PaymentModule] 添加新的代金券支付项:", {
|
|
807
|
+
orderUuid,
|
|
808
|
+
newItemCount: normalizedVoucherItems.length
|
|
809
|
+
});
|
|
810
|
+
for (const voucherItem of normalizedVoucherItems) {
|
|
811
|
+
const orderPaymentType = voucherItem.order_payment_type || "normal";
|
|
812
|
+
const key = `${voucherItem.voucher_id}|${orderPaymentType}`;
|
|
813
|
+
if (existingActiveVoucherKeys.has(key)) {
|
|
814
|
+
console.warn("[PaymentModule] Skip adding voucher payment item because it already exists (active)", {
|
|
815
|
+
orderUuid,
|
|
816
|
+
voucher_id: voucherItem.voucher_id,
|
|
817
|
+
order_payment_type: orderPaymentType
|
|
818
|
+
});
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
console.log(`[PaymentModule] 添加代金券支付项:`, {
|
|
822
|
+
code: voucherItem.code,
|
|
823
|
+
amount: voucherItem.amount,
|
|
824
|
+
voucher_id: voucherItem.voucher_id,
|
|
825
|
+
order_payment_type: orderPaymentType
|
|
826
|
+
});
|
|
827
|
+
await this.addPaymentItemAsync(orderUuid, voucherItem);
|
|
828
|
+
existingActiveVoucherKeys.add(key);
|
|
829
|
+
}
|
|
830
|
+
const updatedOrder = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
831
|
+
await this.core.effects.emit(`${this.name}:onPaymentAdded`, {
|
|
832
|
+
orderUuid,
|
|
833
|
+
order: updatedOrder,
|
|
834
|
+
payment: null
|
|
835
|
+
// 批量操作不提供单个支付项
|
|
836
|
+
});
|
|
837
|
+
this.logInfo("updateVoucherPaymentItemsAsync completed successfully", {
|
|
838
|
+
orderUuid,
|
|
839
|
+
removedVoucherCount: existingVoucherItems.length,
|
|
840
|
+
addedVoucherCount: normalizedVoucherItems.length,
|
|
841
|
+
finalExpectAmount: updatedOrder == null ? void 0 : updatedOrder.expect_amount
|
|
842
|
+
});
|
|
843
|
+
} catch (error) {
|
|
844
|
+
console.error("[PaymentModule] 批量更新代金券支付项失败:", error);
|
|
845
|
+
this.logError("updateVoucherPaymentItemsAsync failed", error, {
|
|
846
|
+
orderUuid,
|
|
847
|
+
voucherPaymentItems
|
|
775
848
|
});
|
|
776
|
-
|
|
849
|
+
throw error;
|
|
777
850
|
}
|
|
778
|
-
|
|
779
|
-
await this.core.effects.emit(`${this.name}:onPaymentAdded`, {
|
|
780
|
-
orderUuid,
|
|
781
|
-
order: updatedOrder,
|
|
782
|
-
payment: null
|
|
783
|
-
// 批量操作不提供单个支付项
|
|
784
|
-
});
|
|
785
|
-
this.logInfo("updateVoucherPaymentItemsAsync completed successfully", {
|
|
786
|
-
orderUuid,
|
|
787
|
-
removedVoucherCount: existingVoucherItems.length,
|
|
788
|
-
addedVoucherCount: voucherPaymentItems.length,
|
|
789
|
-
finalExpectAmount: updatedOrder == null ? void 0 : updatedOrder.expect_amount
|
|
790
|
-
});
|
|
791
|
-
} catch (error) {
|
|
792
|
-
console.error("[PaymentModule] 批量更新代金券支付项失败:", error);
|
|
793
|
-
this.logError("updateVoucherPaymentItemsAsync failed", error, {
|
|
794
|
-
orderUuid,
|
|
795
|
-
voucherPaymentItems
|
|
796
|
-
});
|
|
797
|
-
throw error;
|
|
798
|
-
}
|
|
851
|
+
});
|
|
799
852
|
}
|
|
800
853
|
/**
|
|
801
854
|
* 更新一个支付项
|
|
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
123
123
|
* 获取当前的客户搜索条件
|
|
124
124
|
* @returns 当前搜索条件
|
|
125
125
|
*/
|
|
126
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
126
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
127
127
|
/**
|
|
128
128
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
129
129
|
* @returns 客户状态
|
|
@@ -185,6 +185,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
185
185
|
// 设置客户
|
|
186
186
|
async setCustomer(customer) {
|
|
187
187
|
var _a;
|
|
188
|
+
if (this.isWalkIn() && this.isWalkIn(customer == null ? void 0 : customer.id)) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
188
191
|
if (((_a = this.store.customer) == null ? void 0 : _a.id) !== customer.id) {
|
|
189
192
|
this.store.customer = customer;
|
|
190
193
|
await this.core.effects.emit(
|
|
@@ -348,9 +351,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
348
351
|
return this.store.customer;
|
|
349
352
|
}
|
|
350
353
|
// 是否是walkIn
|
|
351
|
-
isWalkIn() {
|
|
354
|
+
isWalkIn(id) {
|
|
352
355
|
var _a;
|
|
353
|
-
return (((_a = this.getCustomer()) == null ? void 0 : _a.id) || 1) === 1;
|
|
356
|
+
return (id ?? (((_a = this.getCustomer()) == null ? void 0 : _a.id) || 1)) === 1;
|
|
354
357
|
}
|
|
355
358
|
// 触发优惠列表变更事件
|
|
356
359
|
async emitDiscountListChange(discountList) {
|