@pisell/pisellos 0.0.479 → 0.0.481
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.d.ts +3 -2
- package/dist/core/index.js +7 -0
- package/dist/effects/index.d.ts +2 -2
- package/dist/effects/index.js +34 -81
- package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
- package/dist/model/strategy/adapter/walletPass/type.d.ts +9 -2
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +6 -6
- package/dist/model/strategy/adapter/walletPass/utils.js +111 -72
- package/dist/modules/Customer/index.js +1 -1
- package/dist/modules/Discount/index.d.ts +6 -2
- package/dist/modules/Discount/index.js +14 -8
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/index.js +18 -13
- package/dist/modules/Payment/index.d.ts +4 -0
- package/dist/modules/Payment/index.js +774 -649
- package/dist/modules/Payment/walletpass.js +44 -17
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/types.d.ts +2 -0
- package/dist/modules/ProductList/index.d.ts +3 -0
- package/dist/modules/ProductList/index.js +9 -7
- package/dist/modules/Rules/index.d.ts +2 -2
- package/dist/modules/Rules/index.js +37 -31
- package/dist/modules/Rules/types.d.ts +2 -2
- package/dist/modules/Schedule/index.d.ts +9 -0
- package/dist/modules/Schedule/index.js +15 -2
- package/dist/plugins/app-types/app/app.d.ts +1 -0
- package/dist/plugins/request.d.ts +2 -0
- package/dist/server/index.d.ts +107 -2
- package/dist/server/index.js +1507 -279
- package/dist/server/modules/index.d.ts +6 -0
- package/dist/server/modules/index.js +7 -0
- package/dist/server/modules/menu/index.d.ts +19 -0
- package/dist/server/modules/menu/index.js +221 -71
- package/dist/server/modules/order/index.d.ts +87 -0
- package/dist/server/modules/order/index.js +916 -0
- package/dist/server/modules/order/types.d.ts +530 -0
- package/dist/server/modules/order/types.js +141 -0
- package/dist/server/modules/order/utils/filterBookings.d.ts +6 -0
- package/dist/server/modules/order/utils/filterBookings.js +350 -0
- package/dist/server/modules/order/utils/filterOrders.d.ts +15 -0
- package/dist/server/modules/order/utils/filterOrders.js +226 -0
- package/dist/server/modules/products/index.d.ts +117 -5
- package/dist/server/modules/products/index.js +1450 -240
- package/dist/server/modules/products/types.d.ts +25 -1
- package/dist/server/modules/products/types.js +3 -0
- package/dist/server/modules/resource/index.d.ts +86 -0
- package/dist/server/modules/resource/index.js +1128 -0
- package/dist/server/modules/resource/types.d.ts +121 -0
- package/dist/server/modules/resource/types.js +47 -0
- package/dist/server/modules/schedule/index.d.ts +19 -0
- package/dist/server/modules/schedule/index.js +229 -68
- package/dist/server/utils/product.d.ts +5 -0
- package/dist/server/utils/product.js +71 -31
- package/dist/solution/BookingTicket/index.d.ts +10 -2
- package/dist/solution/BookingTicket/index.js +41 -28
- package/dist/solution/BookingTicket/utils/scan/index.js +1 -1
- package/dist/solution/Checkout/index.d.ts +1 -0
- package/dist/solution/Checkout/index.js +286 -188
- package/dist/solution/Checkout/utils/index.d.ts +2 -1
- package/dist/solution/Checkout/utils/index.js +6 -4
- package/dist/solution/RegisterAndLogin/config.js +340 -1
- package/dist/solution/Sales/index.d.ts +96 -0
- package/dist/solution/Sales/index.js +566 -0
- package/dist/solution/Sales/types.d.ts +67 -0
- package/dist/solution/Sales/types.js +26 -0
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +35 -22
- package/dist/solution/ShopDiscount/types.d.ts +6 -0
- package/dist/solution/ShopDiscount/utils.d.ts +9 -0
- package/dist/solution/ShopDiscount/utils.js +21 -27
- package/dist/solution/index.d.ts +2 -1
- package/dist/solution/index.js +2 -1
- package/dist/types/index.d.ts +5 -0
- package/lib/core/index.d.ts +3 -2
- package/lib/core/index.js +4 -0
- package/lib/effects/index.d.ts +2 -2
- package/lib/effects/index.js +22 -31
- package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
- package/lib/model/strategy/adapter/walletPass/type.d.ts +9 -2
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +6 -6
- package/lib/model/strategy/adapter/walletPass/utils.js +115 -48
- package/lib/modules/Customer/index.js +1 -1
- package/lib/modules/Discount/index.d.ts +6 -2
- package/lib/modules/Discount/index.js +3 -1
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/index.js +20 -18
- package/lib/modules/Payment/index.d.ts +4 -0
- package/lib/modules/Payment/index.js +134 -66
- package/lib/modules/Payment/walletpass.js +23 -4
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/types.d.ts +2 -0
- package/lib/modules/ProductList/index.d.ts +3 -0
- package/lib/modules/ProductList/index.js +2 -2
- package/lib/modules/Rules/index.d.ts +2 -2
- package/lib/modules/Rules/index.js +69 -73
- package/lib/modules/Rules/types.d.ts +2 -2
- package/lib/modules/Schedule/index.d.ts +9 -0
- package/lib/modules/Schedule/index.js +11 -0
- package/lib/plugins/app-types/app/app.d.ts +1 -0
- package/lib/plugins/request.d.ts +2 -0
- package/lib/server/index.d.ts +107 -2
- package/lib/server/index.js +773 -51
- package/lib/server/modules/index.d.ts +6 -0
- package/lib/server/modules/index.js +16 -2
- package/lib/server/modules/menu/index.d.ts +19 -0
- package/lib/server/modules/menu/index.js +121 -2
- package/lib/server/modules/order/index.d.ts +87 -0
- package/lib/server/modules/order/index.js +543 -0
- package/lib/server/modules/order/types.d.ts +530 -0
- package/lib/server/modules/order/types.js +34 -0
- package/lib/server/modules/order/utils/filterBookings.d.ts +6 -0
- package/lib/server/modules/order/utils/filterBookings.js +320 -0
- package/lib/server/modules/order/utils/filterOrders.d.ts +15 -0
- package/lib/server/modules/order/utils/filterOrders.js +197 -0
- package/lib/server/modules/products/index.d.ts +117 -5
- package/lib/server/modules/products/index.js +799 -62
- package/lib/server/modules/products/types.d.ts +25 -1
- package/lib/server/modules/products/types.js +1 -0
- package/lib/server/modules/resource/index.d.ts +86 -0
- package/lib/server/modules/resource/index.js +557 -0
- package/lib/server/modules/resource/types.d.ts +121 -0
- package/lib/server/modules/resource/types.js +35 -0
- package/lib/server/modules/schedule/index.d.ts +19 -0
- package/lib/server/modules/schedule/index.js +141 -12
- package/lib/server/utils/product.d.ts +5 -0
- package/lib/server/utils/product.js +56 -27
- package/lib/solution/BookingTicket/index.d.ts +10 -2
- package/lib/solution/BookingTicket/index.js +10 -2
- package/lib/solution/BookingTicket/utils/scan/index.js +0 -1
- package/lib/solution/Checkout/index.d.ts +1 -0
- package/lib/solution/Checkout/index.js +399 -331
- package/lib/solution/Checkout/utils/index.d.ts +2 -1
- package/lib/solution/Checkout/utils/index.js +6 -4
- package/lib/solution/RegisterAndLogin/config.js +266 -1
- package/lib/solution/Sales/index.d.ts +96 -0
- package/lib/solution/Sales/index.js +416 -0
- package/lib/solution/Sales/types.d.ts +67 -0
- package/lib/solution/Sales/types.js +35 -0
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +14 -6
- package/lib/solution/ShopDiscount/types.d.ts +6 -0
- package/lib/solution/ShopDiscount/utils.d.ts +9 -0
- package/lib/solution/ShopDiscount/utils.js +6 -10
- package/lib/solution/index.d.ts +2 -1
- package/lib/solution/index.js +4 -2
- package/lib/types/index.d.ts +5 -0
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -176,6 +203,20 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
176
203
|
}
|
|
177
204
|
});
|
|
178
205
|
}
|
|
206
|
+
async filterPayMethods(payMethods) {
|
|
207
|
+
payMethods = payMethods.filter((method) => method.status === 1 && method.disable === 0);
|
|
208
|
+
const walletPassMethod = payMethods.find((method) => method.code === "WALLET_PASS");
|
|
209
|
+
if (walletPassMethod) {
|
|
210
|
+
payMethods.forEach((method) => {
|
|
211
|
+
if (method.code === "PRODUCTVOUCHER" || method.code === "GIFTCARD" || method.code === "POINTCARD") {
|
|
212
|
+
method.channel_application = walletPassMethod.channel_application;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
} else {
|
|
216
|
+
payMethods = payMethods.filter((method) => method.code !== "PRODUCTVOUCHER" && method.code !== "GIFTCARD" && method.code !== "POINTCARD");
|
|
217
|
+
}
|
|
218
|
+
return payMethods;
|
|
219
|
+
}
|
|
179
220
|
/**
|
|
180
221
|
* 获取支付方式列表
|
|
181
222
|
*/
|
|
@@ -193,7 +234,8 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
193
234
|
this.refreshPaymentMethodsInBackground(cachedMethods);
|
|
194
235
|
return cachedMethods;
|
|
195
236
|
}
|
|
196
|
-
const response = await this.request.get("/pay/custom-payment/
|
|
237
|
+
const response = await this.request.get("/pay/custom-payment/all");
|
|
238
|
+
response.data = this.filterPayMethods(response.data);
|
|
197
239
|
const payMethods = response.data || [];
|
|
198
240
|
try {
|
|
199
241
|
for (const method of payMethods) {
|
|
@@ -207,8 +249,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
207
249
|
payMethods
|
|
208
250
|
);
|
|
209
251
|
this.logInfo("getPayMethodListAsync completed successfully", {
|
|
210
|
-
|
|
211
|
-
hasCache: cachedMethods.length > 0
|
|
252
|
+
payMethods
|
|
212
253
|
});
|
|
213
254
|
return payMethods;
|
|
214
255
|
} catch (error) {
|
|
@@ -226,7 +267,8 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
226
267
|
});
|
|
227
268
|
try {
|
|
228
269
|
console.log("[PaymentModule] 后台刷新支付方式列表...");
|
|
229
|
-
const response = await this.request.get("/pay/custom-payment/
|
|
270
|
+
const response = await this.request.get("/pay/custom-payment/all");
|
|
271
|
+
response.data = this.filterPayMethods(response.data);
|
|
230
272
|
const newPayMethods = response.data || [];
|
|
231
273
|
const hasChanges = this.hasPaymentMethodsChanged(
|
|
232
274
|
cachedMethods,
|
|
@@ -713,76 +755,102 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
713
755
|
* 这是一个覆盖式更新,确保代金券支付项的一致性
|
|
714
756
|
*/
|
|
715
757
|
async updateVoucherPaymentItemsAsync(orderUuid, voucherPaymentItems) {
|
|
716
|
-
this.
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
voucherItems: voucherPaymentItems.map((item) => ({
|
|
720
|
-
code: item.code,
|
|
721
|
-
amount: item.amount,
|
|
722
|
-
voucher_id: item.voucher_id,
|
|
723
|
-
order_payment_type: item.order_payment_type
|
|
724
|
-
}))
|
|
725
|
-
});
|
|
726
|
-
try {
|
|
727
|
-
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
728
|
-
if (!order) {
|
|
729
|
-
throw new Error(`订单不存在: ${orderUuid}`);
|
|
730
|
-
}
|
|
731
|
-
const existingVoucherItems = order.payment.filter(
|
|
732
|
-
(payment) => payment.voucher_id && payment.status !== "voided" && !payment.isSynced
|
|
733
|
-
);
|
|
734
|
-
console.log("[PaymentModule] 发现现有代金券支付项:", {
|
|
758
|
+
return this.runVoucherUpdateLocked(orderUuid, async () => {
|
|
759
|
+
const { items: normalizedVoucherItems, originalCount, normalizedCount } = this.normalizeVoucherPaymentItems(voucherPaymentItems);
|
|
760
|
+
this.logInfo("Starting updateVoucherPaymentItemsAsync", {
|
|
735
761
|
orderUuid,
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
762
|
+
originalVoucherCount: originalCount,
|
|
763
|
+
normalizedVoucherCount: normalizedCount,
|
|
764
|
+
voucherItems: normalizedVoucherItems.map((item) => ({
|
|
739
765
|
code: item.code,
|
|
740
766
|
amount: item.amount,
|
|
741
767
|
voucher_id: item.voucher_id,
|
|
742
|
-
|
|
768
|
+
order_payment_type: item.order_payment_type
|
|
743
769
|
}))
|
|
744
770
|
});
|
|
745
|
-
|
|
746
|
-
console.
|
|
747
|
-
|
|
771
|
+
if (originalCount !== normalizedCount) {
|
|
772
|
+
console.warn("[PaymentModule] voucherPaymentItems detected duplicates (deduped by voucher_id + order_payment_type)", {
|
|
773
|
+
orderUuid,
|
|
774
|
+
originalCount,
|
|
775
|
+
normalizedCount
|
|
776
|
+
});
|
|
748
777
|
}
|
|
749
|
-
|
|
750
|
-
orderUuid
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
778
|
+
try {
|
|
779
|
+
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
780
|
+
if (!order) {
|
|
781
|
+
throw new Error(`订单不存在: ${orderUuid}`);
|
|
782
|
+
}
|
|
783
|
+
const existingVoucherItems = order.payment.filter(
|
|
784
|
+
(payment) => payment.voucher_id && payment.status !== "voided" && !payment.isSynced
|
|
785
|
+
);
|
|
786
|
+
console.log("[PaymentModule] 发现现有代金券支付项:", {
|
|
787
|
+
orderUuid,
|
|
788
|
+
existingVoucherCount: existingVoucherItems.length,
|
|
789
|
+
existingItems: existingVoucherItems.map((item) => ({
|
|
790
|
+
uuid: item.uuid,
|
|
791
|
+
code: item.code,
|
|
792
|
+
amount: item.amount,
|
|
793
|
+
voucher_id: item.voucher_id,
|
|
794
|
+
isSynced: item.isSynced
|
|
795
|
+
}))
|
|
796
|
+
});
|
|
797
|
+
for (const voucherItem of existingVoucherItems) {
|
|
798
|
+
console.log(`[PaymentModule] 删除现有代金券支付项: ${voucherItem.uuid}`);
|
|
799
|
+
await this.deletePaymentAsync(orderUuid, voucherItem.uuid);
|
|
800
|
+
}
|
|
801
|
+
const orderAfterDelete = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
802
|
+
if (!orderAfterDelete) {
|
|
803
|
+
throw new Error(`订单不存在: ${orderUuid}`);
|
|
756
804
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
805
|
+
const existingActiveVoucherKeys = new Set(
|
|
806
|
+
orderAfterDelete.payment.filter((p) => p.voucher_id && p.status !== "voided" && !p.isSynced).map((p) => `${p.voucher_id}|${p.order_payment_type || "normal"}`)
|
|
807
|
+
);
|
|
808
|
+
console.log("[PaymentModule] 添加新的代金券支付项:", {
|
|
809
|
+
orderUuid,
|
|
810
|
+
newItemCount: normalizedVoucherItems.length
|
|
811
|
+
});
|
|
812
|
+
for (const voucherItem of normalizedVoucherItems) {
|
|
813
|
+
const orderPaymentType = voucherItem.order_payment_type || "normal";
|
|
814
|
+
const key = `${voucherItem.voucher_id}|${orderPaymentType}`;
|
|
815
|
+
if (existingActiveVoucherKeys.has(key)) {
|
|
816
|
+
console.warn("[PaymentModule] Skip adding voucher payment item because it already exists (active)", {
|
|
817
|
+
orderUuid,
|
|
818
|
+
voucher_id: voucherItem.voucher_id,
|
|
819
|
+
order_payment_type: orderPaymentType
|
|
820
|
+
});
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
console.log(`[PaymentModule] 添加代金券支付项:`, {
|
|
824
|
+
code: voucherItem.code,
|
|
825
|
+
amount: voucherItem.amount,
|
|
826
|
+
voucher_id: voucherItem.voucher_id,
|
|
827
|
+
order_payment_type: orderPaymentType
|
|
828
|
+
});
|
|
829
|
+
await this.addPaymentItemAsync(orderUuid, voucherItem);
|
|
830
|
+
existingActiveVoucherKeys.add(key);
|
|
831
|
+
}
|
|
832
|
+
const updatedOrder = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
833
|
+
await this.core.effects.emit(`${this.name}:onPaymentAdded`, {
|
|
834
|
+
orderUuid,
|
|
835
|
+
order: updatedOrder,
|
|
836
|
+
payment: null
|
|
837
|
+
// 批量操作不提供单个支付项
|
|
838
|
+
});
|
|
839
|
+
this.logInfo("updateVoucherPaymentItemsAsync completed successfully", {
|
|
840
|
+
orderUuid,
|
|
841
|
+
removedVoucherCount: existingVoucherItems.length,
|
|
842
|
+
addedVoucherCount: normalizedVoucherItems.length,
|
|
843
|
+
finalExpectAmount: updatedOrder == null ? void 0 : updatedOrder.expect_amount
|
|
762
844
|
});
|
|
763
|
-
|
|
845
|
+
} catch (error) {
|
|
846
|
+
console.error("[PaymentModule] 批量更新代金券支付项失败:", error);
|
|
847
|
+
this.logError("updateVoucherPaymentItemsAsync failed", error, {
|
|
848
|
+
orderUuid,
|
|
849
|
+
voucherPaymentItems
|
|
850
|
+
});
|
|
851
|
+
throw error;
|
|
764
852
|
}
|
|
765
|
-
|
|
766
|
-
await this.core.effects.emit(`${this.name}:onPaymentAdded`, {
|
|
767
|
-
orderUuid,
|
|
768
|
-
order: updatedOrder,
|
|
769
|
-
payment: null
|
|
770
|
-
// 批量操作不提供单个支付项
|
|
771
|
-
});
|
|
772
|
-
this.logInfo("updateVoucherPaymentItemsAsync completed successfully", {
|
|
773
|
-
orderUuid,
|
|
774
|
-
removedVoucherCount: existingVoucherItems.length,
|
|
775
|
-
addedVoucherCount: voucherPaymentItems.length,
|
|
776
|
-
finalExpectAmount: updatedOrder == null ? void 0 : updatedOrder.expect_amount
|
|
777
|
-
});
|
|
778
|
-
} catch (error) {
|
|
779
|
-
console.error("[PaymentModule] 批量更新代金券支付项失败:", error);
|
|
780
|
-
this.logError("updateVoucherPaymentItemsAsync failed", error, {
|
|
781
|
-
orderUuid,
|
|
782
|
-
voucherPaymentItems
|
|
783
|
-
});
|
|
784
|
-
throw error;
|
|
785
|
-
}
|
|
853
|
+
});
|
|
786
854
|
}
|
|
787
855
|
/**
|
|
788
856
|
* 更新一个支付项
|
|
@@ -963,7 +1031,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
963
1031
|
}
|
|
964
1032
|
const paymentAmount = new import_decimal.Decimal(payment.amount || 0);
|
|
965
1033
|
const roundingAmount = new import_decimal.Decimal(payment.rounding_amount || 0);
|
|
966
|
-
const effectiveAmount = paymentAmount.
|
|
1034
|
+
const effectiveAmount = paymentAmount.minus(roundingAmount);
|
|
967
1035
|
return sum.plus(effectiveAmount);
|
|
968
1036
|
} catch (error) {
|
|
969
1037
|
console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
|
|
@@ -985,7 +1053,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
985
1053
|
code: p.code,
|
|
986
1054
|
amount: p.amount,
|
|
987
1055
|
rounding_amount: p.rounding_amount || "0.00",
|
|
988
|
-
effective_amount: new import_decimal.Decimal(p.amount || 0).
|
|
1056
|
+
effective_amount: new import_decimal.Decimal(p.amount || 0).minus(new import_decimal.Decimal(p.rounding_amount || 0)).toFixed(2)
|
|
989
1057
|
})),
|
|
990
1058
|
说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
|
|
991
1059
|
});
|
|
@@ -90,6 +90,11 @@ var WalletPassPaymentImpl = class {
|
|
|
90
90
|
order_wait_pay_amount: walletParams.order_wait_pay_amount,
|
|
91
91
|
products_count: ((_b = walletParams.products) == null ? void 0 : _b.length) || 0
|
|
92
92
|
});
|
|
93
|
+
this.walletInitData = {
|
|
94
|
+
transformList: [],
|
|
95
|
+
noApplicableVoucher: [],
|
|
96
|
+
products: products || []
|
|
97
|
+
};
|
|
93
98
|
return walletParams;
|
|
94
99
|
}
|
|
95
100
|
/**
|
|
@@ -124,6 +129,12 @@ var WalletPassPaymentImpl = class {
|
|
|
124
129
|
products: []
|
|
125
130
|
};
|
|
126
131
|
}
|
|
132
|
+
if ([1, 0].includes((walletParams == null ? void 0 : walletParams.customer_id) || 0)) {
|
|
133
|
+
return {
|
|
134
|
+
walletRecommendList: [],
|
|
135
|
+
userIdentificationCodes: []
|
|
136
|
+
};
|
|
137
|
+
}
|
|
127
138
|
this.emitEvent(import_types.WalletPassHooks.OnWalletInitializationStarted, {
|
|
128
139
|
businessData,
|
|
129
140
|
startTime
|
|
@@ -335,6 +346,7 @@ var WalletPassPaymentImpl = class {
|
|
|
335
346
|
* 特殊逻辑:当识别码长度为9位且前3位为"000"时,调用 /wallet/detail/search 接口
|
|
336
347
|
*/
|
|
337
348
|
async searchIdentificationCodeAsync(params, config = {}) {
|
|
349
|
+
var _a;
|
|
338
350
|
try {
|
|
339
351
|
const { code } = params;
|
|
340
352
|
this.paymentModule.logInfo("[WalletPass] 开始搜索识别码", {
|
|
@@ -392,10 +404,17 @@ var WalletPassPaymentImpl = class {
|
|
|
392
404
|
multiple: searchParams.multiple,
|
|
393
405
|
payment_order_id: baseWalletParams == null ? void 0 : baseWalletParams.payment_order_id
|
|
394
406
|
});
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
407
|
+
let response;
|
|
408
|
+
if (!searchParams.products || ((_a = searchParams.products || []) == null ? void 0 : _a.length) === 0) {
|
|
409
|
+
response = {
|
|
410
|
+
data: []
|
|
411
|
+
};
|
|
412
|
+
} else {
|
|
413
|
+
response = await this.paymentModule.request.post(
|
|
414
|
+
"/machinecode/prepare/deduction/search",
|
|
415
|
+
searchParams
|
|
416
|
+
);
|
|
417
|
+
}
|
|
399
418
|
const searchResults = (response == null ? void 0 : response.data) || [];
|
|
400
419
|
if (config.noCache) {
|
|
401
420
|
return {
|
|
@@ -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(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -162,6 +162,8 @@ export interface ProductData {
|
|
|
162
162
|
categories: ProductCategory[];
|
|
163
163
|
/** 套餐组 */
|
|
164
164
|
bundle_groups: ProductBundleGroup[];
|
|
165
|
+
/** 套餐组 */
|
|
166
|
+
bundle_group: ProductBundleGroup[];
|
|
165
167
|
/** 商品资源 */
|
|
166
168
|
product_resource?: {
|
|
167
169
|
resources?: ProductResourceItem[];
|
|
@@ -22,6 +22,9 @@ export declare class ProductList extends BaseModule implements Module {
|
|
|
22
22
|
schedule_datetime?: string;
|
|
23
23
|
with_count?: string[];
|
|
24
24
|
with_schedule?: number;
|
|
25
|
+
}, options?: {
|
|
26
|
+
callback?: (result: any) => void;
|
|
27
|
+
subscriberId?: string;
|
|
25
28
|
}): Promise<any>;
|
|
26
29
|
loadProductsPrice({ ids, customer_id, schedule_date, channel, }: {
|
|
27
30
|
ids?: number[];
|
|
@@ -60,7 +60,7 @@ var ProductList = class extends import_BaseModule.BaseModule {
|
|
|
60
60
|
schedule_date,
|
|
61
61
|
cacheId,
|
|
62
62
|
with_schedule
|
|
63
|
-
}) {
|
|
63
|
+
}, options) {
|
|
64
64
|
var _a, _b;
|
|
65
65
|
let userPlugin = this.core.getPlugin("user");
|
|
66
66
|
let customer_id = void 0;
|
|
@@ -100,7 +100,7 @@ var ProductList = class extends import_BaseModule.BaseModule {
|
|
|
100
100
|
application_code: (_b = this.otherParams) == null ? void 0 : _b.channel,
|
|
101
101
|
is_eject: 1
|
|
102
102
|
},
|
|
103
|
-
{ osServer: true }
|
|
103
|
+
{ osServer: true, callback: options == null ? void 0 : options.callback, subscriberId: options == null ? void 0 : options.subscriberId }
|
|
104
104
|
);
|
|
105
105
|
const sortedList = (productsData.data.list || []).slice().sort((a, b) => Number(b.sort) - Number(a.sort));
|
|
106
106
|
this.addProduct(sortedList);
|
|
@@ -33,14 +33,14 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
|
|
|
33
33
|
};
|
|
34
34
|
filterDiscountListByType(discountList: Discount[], type: string): Discount[];
|
|
35
35
|
private getUnavailableReason;
|
|
36
|
-
calcDiscount({ discountList, productList,
|
|
36
|
+
calcDiscount({ discountList, productList, holders, isFormSubject, orderTotalAmount }: {
|
|
37
37
|
discountList: Discount[];
|
|
38
38
|
productList: any[];
|
|
39
|
-
orderTotalAmount: number;
|
|
40
39
|
holders: {
|
|
41
40
|
form_record_id: number;
|
|
42
41
|
}[];
|
|
43
42
|
isFormSubject: boolean;
|
|
43
|
+
orderTotalAmount: number;
|
|
44
44
|
}, options?: {
|
|
45
45
|
isSelected?: boolean;
|
|
46
46
|
discountId?: number;
|
|
@@ -39,6 +39,8 @@ var import_utils2 = require("../Cart/utils");
|
|
|
39
39
|
var import_decimal = __toESM(require("decimal.js"));
|
|
40
40
|
var import_lodash_es = require("lodash-es");
|
|
41
41
|
var import_dayjs = __toESM(require("dayjs"));
|
|
42
|
+
var import_utils3 = require("../../solution/ShopDiscount/utils");
|
|
43
|
+
var import_utils4 = require("../../solution/ShopDiscount/utils");
|
|
42
44
|
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
43
45
|
constructor(name, version) {
|
|
44
46
|
super(name, version);
|
|
@@ -111,18 +113,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
111
113
|
...filteredOldDiscountList,
|
|
112
114
|
...newDiscountList
|
|
113
115
|
]);
|
|
114
|
-
const result = this.calcDiscount(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
scan: true
|
|
124
|
-
}
|
|
125
|
-
);
|
|
116
|
+
const result = this.calcDiscount({
|
|
117
|
+
discountList: mergedDiscountList,
|
|
118
|
+
productList: [...productList],
|
|
119
|
+
holders,
|
|
120
|
+
orderTotalAmount,
|
|
121
|
+
isFormSubject
|
|
122
|
+
}, {
|
|
123
|
+
scan: true
|
|
124
|
+
});
|
|
126
125
|
let hasApplicableDiscount = false;
|
|
127
126
|
const newDiscountIds = newDiscountList.map((discount) => discount.id);
|
|
128
127
|
result.productList.forEach((product) => {
|
|
@@ -192,9 +191,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
192
191
|
calcDiscount({
|
|
193
192
|
discountList,
|
|
194
193
|
productList,
|
|
195
|
-
orderTotalAmount,
|
|
196
194
|
holders,
|
|
197
|
-
isFormSubject
|
|
195
|
+
isFormSubject,
|
|
196
|
+
orderTotalAmount
|
|
198
197
|
}, options) {
|
|
199
198
|
const editModeDiscount = [];
|
|
200
199
|
const addModeDiscount = [];
|
|
@@ -481,7 +480,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
481
480
|
return isLimitedProduct && isBundleAvailable;
|
|
482
481
|
};
|
|
483
482
|
const selectedOrderLevelDiscounts = sortedDiscountList.filter((discount) => {
|
|
484
|
-
return (0,
|
|
483
|
+
return (0, import_utils3.isOrderLevelFixedAmountDiscount)(discount) && discount.isSelected !== false;
|
|
485
484
|
});
|
|
486
485
|
selectedOrderLevelDiscounts.forEach((discount) => {
|
|
487
486
|
const applicableItemIds = /* @__PURE__ */ new Set();
|
|
@@ -513,7 +512,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
513
512
|
});
|
|
514
513
|
console.log("occupiedItems", occupiedItems, "orderLevelDiscountApplicableItems", orderLevelDiscountApplicableItems);
|
|
515
514
|
sortedDiscountList.forEach((discount) => {
|
|
516
|
-
if (!(0,
|
|
515
|
+
if (!(0, import_utils3.isOrderLevelFixedAmountDiscount)(discount)) {
|
|
517
516
|
return;
|
|
518
517
|
}
|
|
519
518
|
const applicableProducts = [];
|
|
@@ -551,7 +550,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
551
550
|
applicableProducts.push(productData);
|
|
552
551
|
});
|
|
553
552
|
if (applicableProducts.length > 0) {
|
|
554
|
-
const allocation = (0,
|
|
553
|
+
const allocation = (0, import_utils4.calculateOrderLevelDiscountAllocation)(discount, applicableProducts);
|
|
555
554
|
orderLevelDiscountAllocations.set(discount.id, allocation);
|
|
556
555
|
}
|
|
557
556
|
});
|
|
@@ -712,11 +711,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
712
711
|
}
|
|
713
712
|
}
|
|
714
713
|
const limitedData = discount.limited_relation_product_data;
|
|
715
|
-
let timeLimit = true;
|
|
716
|
-
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
717
|
-
if (!timeLimit) {
|
|
718
|
-
return false;
|
|
719
|
-
}
|
|
720
714
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
721
715
|
const isHolderMatch = this.checkHolderMatch(
|
|
722
716
|
discount,
|
|
@@ -728,6 +722,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
728
722
|
);
|
|
729
723
|
if (!isHolderMatch)
|
|
730
724
|
return false;
|
|
725
|
+
let timeLimit = true;
|
|
726
|
+
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
727
|
+
if (!timeLimit) {
|
|
728
|
+
return false;
|
|
729
|
+
}
|
|
731
730
|
if (limitedData.type === "product_all") {
|
|
732
731
|
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
733
732
|
return false;
|
|
@@ -930,12 +929,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
930
929
|
const arr = [];
|
|
931
930
|
if (flatItem.type === "main") {
|
|
932
931
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
932
|
+
let total = product.origin_total ?? product.total;
|
|
933
|
+
if ((product.discount_list || []).some((item) => item.type === "promotion")) {
|
|
934
|
+
total = product.total ?? product.origin_total;
|
|
935
|
+
}
|
|
933
936
|
arr.push(
|
|
934
937
|
this.hooks.setProduct(originProduct, {
|
|
935
938
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
|
|
936
939
|
quantity: totalQuantity - splitCount,
|
|
937
940
|
_id: product._id.split("___")[0],
|
|
938
|
-
total
|
|
941
|
+
total
|
|
939
942
|
})
|
|
940
943
|
);
|
|
941
944
|
}
|
|
@@ -959,7 +962,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
959
962
|
if (Number(((_x = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _x.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
960
963
|
productOriginTotal = product.total;
|
|
961
964
|
}
|
|
962
|
-
const isOrderLevel = (0,
|
|
965
|
+
const isOrderLevel = (0, import_utils3.isOrderLevelFixedAmountDiscount)(selectedDiscount);
|
|
963
966
|
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
|
|
964
967
|
const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
965
968
|
let targetProductTotal;
|
|
@@ -974,17 +977,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
974
977
|
amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
|
|
975
978
|
}
|
|
976
979
|
const currentDiscountType = currentSelectedDiscount.tag === "product_discount_card" ? "discount_card" : currentSelectedDiscount.tag;
|
|
977
|
-
const
|
|
980
|
+
const discountType2 = selectedDiscount.tag || selectedDiscount.type;
|
|
978
981
|
const currentIsGoodPass = currentDiscountType === "good_pass";
|
|
979
982
|
const discountDetail = {
|
|
980
|
-
amount
|
|
981
|
-
type:
|
|
983
|
+
amount,
|
|
984
|
+
type: selectedDiscount.tag === "product_discount_card" ? "discount_card" : discountType2,
|
|
982
985
|
discount: {
|
|
983
|
-
discount_card_type: (_y =
|
|
984
|
-
fixed_amount:
|
|
985
|
-
discount_calculation_mode: (_z =
|
|
986
|
-
resource_id:
|
|
987
|
-
title:
|
|
986
|
+
discount_card_type: (_y = selectedDiscount == null ? void 0 : selectedDiscount.metadata) == null ? void 0 : _y.discount_card_type,
|
|
987
|
+
fixed_amount: amount,
|
|
988
|
+
discount_calculation_mode: (_z = selectedDiscount == null ? void 0 : selectedDiscount.metadata) == null ? void 0 : _z.discount_calculation_mode,
|
|
989
|
+
resource_id: selectedDiscount.id,
|
|
990
|
+
title: selectedDiscount.format_title,
|
|
988
991
|
original_amount: product.price,
|
|
989
992
|
product_id: originProduct.id,
|
|
990
993
|
percent: currentSelectedDiscount.par_value,
|
|
@@ -1025,7 +1028,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1025
1028
|
}),
|
|
1026
1029
|
variant: originProduct._productInit.variant,
|
|
1027
1030
|
original_price: new import_decimal.default(product.price || 0).toNumber(),
|
|
1028
|
-
total
|
|
1031
|
+
total
|
|
1029
1032
|
})
|
|
1030
1033
|
);
|
|
1031
1034
|
} else {
|
|
@@ -1035,7 +1038,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1035
1038
|
_id: product._id.split("___")[0] + "___" + currentSelectedDiscount.id + "_" + i + "_" + index,
|
|
1036
1039
|
price: currentIsGoodPass ? 0 : product.price,
|
|
1037
1040
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1038
|
-
total
|
|
1041
|
+
total,
|
|
1039
1042
|
origin_total: productOriginTotal,
|
|
1040
1043
|
main_product_selling_price: targetProductTotal
|
|
1041
1044
|
})
|
|
@@ -1339,7 +1342,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1339
1342
|
usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentNoSplitCount + bundleQuantity);
|
|
1340
1343
|
}
|
|
1341
1344
|
const productOriginTotal = product.original_price || product.price || 0;
|
|
1342
|
-
const isOrderLevel = (0,
|
|
1345
|
+
const isOrderLevel = (0, import_utils3.isOrderLevelFixedAmountDiscount)(selectedDiscount);
|
|
1343
1346
|
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
|
|
1344
1347
|
const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
1345
1348
|
let targetProductTotal;
|
|
@@ -1663,48 +1666,41 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1663
1666
|
const mainProductData = this.hooks.getProduct(mainProduct);
|
|
1664
1667
|
const newBundle = [];
|
|
1665
1668
|
if (product.bundle && Array.isArray(product.bundle)) {
|
|
1666
|
-
product.bundle.forEach(
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
metadata
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
};
|
|
1685
|
-
});
|
|
1686
|
-
newBundle.push({
|
|
1687
|
-
...bundleItem,
|
|
1688
|
-
_id: item._id,
|
|
1689
|
-
product_id: bundleItem.product_id,
|
|
1690
|
-
price: item.price,
|
|
1691
|
-
num: item.num,
|
|
1692
|
-
quantity: item.num,
|
|
1693
|
-
discount_list: updatedDiscountList2
|
|
1694
|
-
});
|
|
1669
|
+
product.bundle.forEach((bundleItem, bundleIndex) => {
|
|
1670
|
+
const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
|
|
1671
|
+
const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
|
|
1672
|
+
if (!processedBundleItems || processedBundleItems.length === 0) {
|
|
1673
|
+
newBundle.push(bundleItem);
|
|
1674
|
+
} else {
|
|
1675
|
+
processedBundleItems.forEach((item) => {
|
|
1676
|
+
const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
|
|
1677
|
+
var _a2;
|
|
1678
|
+
return {
|
|
1679
|
+
...discount,
|
|
1680
|
+
metadata: {
|
|
1681
|
+
...discount.metadata,
|
|
1682
|
+
num: item.num,
|
|
1683
|
+
custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
|
|
1684
|
+
}
|
|
1685
|
+
// num: item.num, // 使用拆分后的 num
|
|
1686
|
+
};
|
|
1695
1687
|
});
|
|
1696
|
-
|
|
1688
|
+
newBundle.push({
|
|
1689
|
+
...bundleItem,
|
|
1690
|
+
_id: item._id,
|
|
1691
|
+
product_id: bundleItem.product_id,
|
|
1692
|
+
price: item.price,
|
|
1693
|
+
num: item.num,
|
|
1694
|
+
discount_list: updatedDiscountList2,
|
|
1695
|
+
bundle_selling_price: bundleItem.bundle_selling_price !== void 0 ? item.price : void 0
|
|
1696
|
+
});
|
|
1697
|
+
});
|
|
1697
1698
|
}
|
|
1698
|
-
);
|
|
1699
|
+
});
|
|
1699
1700
|
}
|
|
1700
1701
|
let newTotal = Number(mainProductData.price || 0);
|
|
1701
|
-
let newOriginTotal = Number(
|
|
1702
|
-
|
|
1703
|
-
);
|
|
1704
|
-
const isManualDiscount = typeof mainProductData.isManualDiscount === "boolean" ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_a = mainProductData.discount_list) == null ? void 0 : _a.length) || ((_c = (_b = mainProductData == null ? void 0 : mainProductData.discount_list) == null ? void 0 : _b.every) == null ? void 0 : _c.call(
|
|
1705
|
-
_b,
|
|
1706
|
-
(item) => item.type === "product"
|
|
1707
|
-
)));
|
|
1702
|
+
let newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
|
|
1703
|
+
const isManualDiscount = typeof mainProductData.isManualDiscount === "boolean" ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_a = mainProductData.discount_list) == null ? void 0 : _a.length) || ((_c = (_b = mainProductData == null ? void 0 : mainProductData.discount_list) == null ? void 0 : _b.every) == null ? void 0 : _c.call(_b, (item) => item.type === "product")));
|
|
1708
1704
|
if (isManualDiscount) {
|
|
1709
1705
|
newTotal = mainProductData.total ?? newTotal;
|
|
1710
1706
|
newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
|