@pisell/pisellos 2.2.8 → 2.2.9
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/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +1 -1
- package/dist/modules/Payment/cash.js +1 -1
- package/dist/modules/Payment/eftpos.js +1 -1
- package/dist/modules/Payment/index.js +102 -32
- package/dist/modules/Payment/types.d.ts +21 -2
- package/dist/modules/Payment/walletpass.js +5 -2
- package/dist/modules/Rules/index.d.ts +9 -2
- package/dist/modules/Rules/index.js +39 -6
- package/dist/modules/Rules/types.d.ts +4 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/Checkout/index.d.ts +2 -0
- package/dist/solution/Checkout/index.js +217 -72
- package/dist/solution/Checkout/types.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.d.ts +3 -0
- package/dist/solution/ShopDiscount/index.js +16 -5
- package/dist/solution/ShopDiscount/types.d.ts +5 -0
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +1 -1
- package/lib/modules/Payment/cash.js +1 -1
- package/lib/modules/Payment/eftpos.js +1 -1
- package/lib/modules/Payment/index.js +71 -11
- package/lib/modules/Payment/types.d.ts +21 -2
- package/lib/modules/Payment/walletpass.js +6 -4
- package/lib/modules/Rules/index.d.ts +9 -2
- package/lib/modules/Rules/index.js +40 -9
- package/lib/modules/Rules/types.d.ts +4 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/Checkout/index.d.ts +2 -0
- package/lib/solution/Checkout/index.js +121 -10
- package/lib/solution/Checkout/types.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.d.ts +3 -0
- package/lib/solution/ShopDiscount/index.js +12 -4
- package/lib/solution/ShopDiscount/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -196,6 +196,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
196
196
|
throw error;
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
|
+
getHolderIdFromBooking(obj) {
|
|
200
|
+
var _a;
|
|
201
|
+
if (!obj)
|
|
202
|
+
return void 0;
|
|
203
|
+
let ret = obj.holder_id || ((_a = obj.holder) == null ? void 0 : _a.form_record);
|
|
204
|
+
if (Array.isArray(ret)) {
|
|
205
|
+
return ret.length > 0 ? Number(ret[0]) : void 0;
|
|
206
|
+
}
|
|
207
|
+
return Number(ret) || void 0;
|
|
208
|
+
}
|
|
199
209
|
getProductListByOrder() {
|
|
200
210
|
var _a, _b, _c, _d, _e;
|
|
201
211
|
if (!this.store.currentOrder) {
|
|
@@ -211,7 +221,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
211
221
|
product_id: item.product.product_id,
|
|
212
222
|
product_variant_id: item.product.product_variant_id,
|
|
213
223
|
quantity: item.product.num,
|
|
214
|
-
selling_price: item.product.calculated_selling_price
|
|
224
|
+
selling_price: item.product.calculated_selling_price,
|
|
225
|
+
holder_id: this.getHolderIdFromBooking(item)
|
|
215
226
|
})
|
|
216
227
|
)) || [];
|
|
217
228
|
const relationProducts = ((_e = (_d = (_c = this.store.currentOrder.order_info) == null ? void 0 : _c.original_order_data) == null ? void 0 : _d.relation_products) == null ? void 0 : _e.map(
|
|
@@ -225,7 +236,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
225
236
|
return [...productList, ...relationProducts];
|
|
226
237
|
}
|
|
227
238
|
async initWalletData(params) {
|
|
228
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
239
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
229
240
|
this.logInfo("initWalletData called", {
|
|
230
241
|
params
|
|
231
242
|
});
|
|
@@ -238,17 +249,18 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
238
249
|
}
|
|
239
250
|
const walletBusinessData = {
|
|
240
251
|
customer_id: ((_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id) ? Number(this.store.currentCustomer.customer_id) : void 0,
|
|
252
|
+
holder: (_f = (_e = (_d = this.store.currentOrder) == null ? void 0 : _d.order_info) == null ? void 0 : _e.original_order_data) == null ? void 0 : _f.holder,
|
|
241
253
|
amountInfo: {
|
|
242
254
|
totalAmount: amountInfo.totalAmount,
|
|
243
255
|
subTotal: amountInfo.subTotal,
|
|
244
|
-
depositAmount: (
|
|
245
|
-
isDeposit: (
|
|
256
|
+
depositAmount: (_g = this.store.currentOrder) == null ? void 0 : _g.deposit_amount,
|
|
257
|
+
isDeposit: (_h = this.store.currentOrder) == null ? void 0 : _h.is_deposit
|
|
246
258
|
},
|
|
247
259
|
products: this.getProductListByOrder(),
|
|
248
260
|
...params
|
|
249
261
|
};
|
|
250
262
|
if (this.store.isOrderSynced) {
|
|
251
|
-
walletBusinessData.payment_order_id = (
|
|
263
|
+
walletBusinessData.payment_order_id = (_i = this.store.currentOrder) == null ? void 0 : _i.order_id;
|
|
252
264
|
}
|
|
253
265
|
this.logInfo("开始拉取:initializeWalletDataFromBusinessAsync", {
|
|
254
266
|
walletBusinessData
|
|
@@ -266,7 +278,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
266
278
|
currentOrder: this.store.currentOrder
|
|
267
279
|
});
|
|
268
280
|
await this.core.effects.emit(`${this.name}:onWalletDataInitialized`, {
|
|
269
|
-
orderUuid: (
|
|
281
|
+
orderUuid: (_j = this.store.currentOrder) == null ? void 0 : _j.uuid,
|
|
270
282
|
customerId: walletBusinessData.customer_id,
|
|
271
283
|
walletBusinessData: {
|
|
272
284
|
customer_id: walletBusinessData.customer_id,
|
|
@@ -441,7 +453,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
441
453
|
* 会覆盖 order_info 与金额等字段,并重新计算待付金额,最后设置为 currentOrder。
|
|
442
454
|
*/
|
|
443
455
|
async updateLocalOrderAsync(params) {
|
|
444
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
456
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
445
457
|
this.logInfo("updateLocalOrderAsync called", {
|
|
446
458
|
orderId: params.orderId,
|
|
447
459
|
orderDataType: (_a = params.orderData) == null ? void 0 : _a.type,
|
|
@@ -479,6 +491,82 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
479
491
|
(o) => String(o.id) === String(params.orderId) || String(o.order_id) === String(params.orderId)
|
|
480
492
|
);
|
|
481
493
|
if (existingOrder) {
|
|
494
|
+
if (params.existPayment && params.existPayment.length > 0) {
|
|
495
|
+
this.logInfo("检测到云端支付项,将替换本地订单的支付项列表", {
|
|
496
|
+
orderId: params.orderId,
|
|
497
|
+
existingPaymentCount: ((_m = existingOrder.payment) == null ? void 0 : _m.length) || 0,
|
|
498
|
+
newPaymentCount: params.existPayment.length
|
|
499
|
+
});
|
|
500
|
+
this.store.isOrderSynced = true;
|
|
501
|
+
const currentTime = (0, import_utils.formatDateTime)(/* @__PURE__ */ new Date());
|
|
502
|
+
const formattedExistPayments = params.existPayment.map((payment) => ({
|
|
503
|
+
...payment,
|
|
504
|
+
isSynced: true,
|
|
505
|
+
// 标记为已同步
|
|
506
|
+
status: payment.status || "active",
|
|
507
|
+
created_at: payment.created_at || currentTime,
|
|
508
|
+
updated_at: payment.updated_at || currentTime
|
|
509
|
+
}));
|
|
510
|
+
const isNeedDeposit3 = this.checkIsNeedDepositAsync(
|
|
511
|
+
params.orderData.bookings,
|
|
512
|
+
params.orderData.relation_products
|
|
513
|
+
);
|
|
514
|
+
await this.payment.updateOrderAsync(existingOrder.uuid, {
|
|
515
|
+
total_amount: amountInfo.totalAmount,
|
|
516
|
+
is_deposit: isNeedDeposit3.hasDeposit ? 1 : 0,
|
|
517
|
+
deposit_amount: isNeedDeposit3.total ? isNeedDeposit3.total.toString() : "0.00",
|
|
518
|
+
payment: formattedExistPayments,
|
|
519
|
+
// 🔧 替换支付项列表
|
|
520
|
+
order_info: {
|
|
521
|
+
original_order_data: params.orderData,
|
|
522
|
+
cart_summary: params.cartSummary,
|
|
523
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
524
|
+
platform: params.orderData.platform,
|
|
525
|
+
type: params.orderData.type,
|
|
526
|
+
schedule_date: params.orderData.schedule_date,
|
|
527
|
+
shop_note: params.orderData.shop_note,
|
|
528
|
+
amount_breakdown: amountInfo
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
const updated2 = await this.payment.getPaymentOrderByUuidAsync(
|
|
532
|
+
existingOrder.uuid
|
|
533
|
+
);
|
|
534
|
+
if (!updated2)
|
|
535
|
+
throw (0, import_utils.createCheckoutError)(
|
|
536
|
+
import_types.CheckoutErrorType.UnknownError,
|
|
537
|
+
"订单更新失败"
|
|
538
|
+
);
|
|
539
|
+
this.store.currentOrder = updated2;
|
|
540
|
+
await this.updateStateAmountToRemaining(false);
|
|
541
|
+
this.logInfo("本地订单更新成功(已替换云端支付项):", {
|
|
542
|
+
orderId: params.orderId,
|
|
543
|
+
uuid: updated2.uuid,
|
|
544
|
+
payments: ((_n = updated2.payment) == null ? void 0 : _n.length) || 0,
|
|
545
|
+
totalAmount: updated2.total_amount,
|
|
546
|
+
expectAmount: updated2.expect_amount,
|
|
547
|
+
isOrderSynced: true
|
|
548
|
+
});
|
|
549
|
+
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
550
|
+
order: updated2,
|
|
551
|
+
timestamp: Date.now()
|
|
552
|
+
});
|
|
553
|
+
const syncedPayments = updated2.payment.filter((p) => p.isSynced && p.status !== "voided");
|
|
554
|
+
const syncedAmount2 = syncedPayments.reduce((sum, p) => {
|
|
555
|
+
const amt = new import_decimal.default(p.amount || "0");
|
|
556
|
+
const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
|
|
557
|
+
return sum.plus(amt).plus(rounding);
|
|
558
|
+
}, new import_decimal.default(0));
|
|
559
|
+
const totalAmount2 = new import_decimal.default(amountInfo.totalAmount || "0");
|
|
560
|
+
const remainingExpectAmount2 = import_decimal.default.max(0, totalAmount2.minus(syncedAmount2)).toFixed(2);
|
|
561
|
+
let depositDiffAmount2 = new import_decimal.default(0).toFixed(2);
|
|
562
|
+
if (updated2.is_deposit === 1) {
|
|
563
|
+
depositDiffAmount2 = new import_decimal.default(updated2.deposit_amount).minus(syncedAmount2).toFixed(2);
|
|
564
|
+
}
|
|
565
|
+
this.initWalletData({
|
|
566
|
+
order_wait_pay_amount: Number(depositDiffAmount2) > 0 ? Number(depositDiffAmount2) : Number(remainingExpectAmount2)
|
|
567
|
+
});
|
|
568
|
+
return updated2;
|
|
569
|
+
}
|
|
482
570
|
const totalAmount = new import_decimal.default(amountInfo.totalAmount || "0");
|
|
483
571
|
const activePayments = (existingOrder.payment || []).filter(
|
|
484
572
|
(p) => p.status !== "voided"
|
|
@@ -524,7 +612,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
524
612
|
this.logInfo("本地订单更新成功(保留支付项):", {
|
|
525
613
|
orderId: params.orderId,
|
|
526
614
|
uuid: updated.uuid,
|
|
527
|
-
payments: ((
|
|
615
|
+
payments: ((_o = updated.payment) == null ? void 0 : _o.length) || 0,
|
|
528
616
|
totalAmount: updated.total_amount,
|
|
529
617
|
expectAmount: updated.expect_amount
|
|
530
618
|
});
|
|
@@ -558,6 +646,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
558
646
|
total_amount: amountInfo.totalAmount,
|
|
559
647
|
is_deposit: isNeedDeposit.hasDeposit ? 1 : 0,
|
|
560
648
|
deposit_amount: isNeedDeposit.total ? isNeedDeposit.total.toString() : "0.00",
|
|
649
|
+
existPayment: params.existPayment,
|
|
650
|
+
// 🔧 新增: 传递云端支付项
|
|
561
651
|
order_info: {
|
|
562
652
|
original_order_data: params.orderData,
|
|
563
653
|
cart_summary: params.cartSummary,
|
|
@@ -570,7 +660,28 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
570
660
|
}
|
|
571
661
|
});
|
|
572
662
|
this.store.currentOrder = created;
|
|
573
|
-
|
|
663
|
+
if (params.existPayment && params.existPayment.length > 0) {
|
|
664
|
+
this.store.isOrderSynced = true;
|
|
665
|
+
const syncedPayments = created.payment.filter((p) => p.isSynced && p.status !== "voided");
|
|
666
|
+
const syncedAmount = syncedPayments.reduce((sum, p) => {
|
|
667
|
+
const amt = new import_decimal.default(p.amount || "0");
|
|
668
|
+
const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
|
|
669
|
+
return sum.plus(amt).plus(rounding);
|
|
670
|
+
}, new import_decimal.default(0));
|
|
671
|
+
this.logInfo("云端订单初始化钱包数据", {
|
|
672
|
+
orderId: params.orderId,
|
|
673
|
+
totalAmount: created.total_amount,
|
|
674
|
+
expectAmount: created.expect_amount,
|
|
675
|
+
syncedAmount: syncedAmount.toFixed(2),
|
|
676
|
+
syncedPaymentCount: syncedPayments.length,
|
|
677
|
+
isOrderSynced: true
|
|
678
|
+
});
|
|
679
|
+
this.initWalletData({
|
|
680
|
+
order_wait_pay_amount: Number(created.expect_amount)
|
|
681
|
+
});
|
|
682
|
+
} else {
|
|
683
|
+
this.initWalletData();
|
|
684
|
+
}
|
|
574
685
|
return created;
|
|
575
686
|
}
|
|
576
687
|
/**
|
|
@@ -1967,7 +2078,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1967
2078
|
const depositPaidAmount = paymentItems.filter(
|
|
1968
2079
|
(item) => item.order_payment_type === "deposit" && item.status !== "voided"
|
|
1969
2080
|
).reduce((sum, item) => {
|
|
1970
|
-
if (item.voucher_id && !item.isSynced) {
|
|
2081
|
+
if (item.voucher_id && !item.isSynced && paymentItems.filter((item2) => !item2.voucher_id).length === 0) {
|
|
1971
2082
|
return sum;
|
|
1972
2083
|
}
|
|
1973
2084
|
const amount = new import_decimal.default(item.amount || "0");
|
|
@@ -103,6 +103,8 @@ export interface UpdateLocalOrderParams {
|
|
|
103
103
|
cartSummary: CartSummaryItem[];
|
|
104
104
|
/** total 信息(用于拆解金额) */
|
|
105
105
|
totalInfo: any;
|
|
106
|
+
/** 云端已存在的支付项(可选,用于处理订单在其他设备或云端生成的场景) */
|
|
107
|
+
existPayment?: PaymentItem[];
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
108
110
|
* 本地订单数据结构 (基于 appointmentDemo.json)
|
|
@@ -19,6 +19,9 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
19
19
|
private registerDependentModules;
|
|
20
20
|
private registerEventListeners;
|
|
21
21
|
setCustomer(customer: Customer): Promise<void>;
|
|
22
|
+
setHolders(holders: {
|
|
23
|
+
form_record_id: number;
|
|
24
|
+
}[]): void;
|
|
22
25
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
23
26
|
productList: Record<string, any>[];
|
|
24
27
|
discountList: Discount[];
|
|
@@ -50,7 +50,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
50
50
|
productList: [],
|
|
51
51
|
discount: null,
|
|
52
52
|
rules: null,
|
|
53
|
-
originalDiscountList: []
|
|
53
|
+
originalDiscountList: [],
|
|
54
|
+
holders: []
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
57
|
// =========== 生命周期方法 ===========
|
|
@@ -150,6 +151,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
150
151
|
);
|
|
151
152
|
}
|
|
152
153
|
}
|
|
154
|
+
// 设置holders
|
|
155
|
+
setHolders(holders) {
|
|
156
|
+
this.store.holders = holders;
|
|
157
|
+
}
|
|
153
158
|
// 计算优惠券
|
|
154
159
|
calcDiscount(productList, options) {
|
|
155
160
|
this.store.productList = productList;
|
|
@@ -160,7 +165,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
160
165
|
let { productList: newProductList, discountList: newDiscountList } = rulesModule.calcDiscount(
|
|
161
166
|
{
|
|
162
167
|
productList,
|
|
163
|
-
discountList: this.getDiscountList()
|
|
168
|
+
discountList: this.getDiscountList(),
|
|
169
|
+
holders: this.store.holders || []
|
|
164
170
|
},
|
|
165
171
|
options
|
|
166
172
|
) || { productList, discountList: this.getDiscountList() };
|
|
@@ -249,7 +255,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
249
255
|
} = rulesModule.isDiscountListAvailable({
|
|
250
256
|
productList: this.store.productList || [],
|
|
251
257
|
oldDiscountList: this.getDiscountList(),
|
|
252
|
-
newDiscountList: withScanList
|
|
258
|
+
newDiscountList: withScanList,
|
|
259
|
+
holders: this.store.holders || []
|
|
253
260
|
}) || {
|
|
254
261
|
isAvailable: false,
|
|
255
262
|
productList: this.store.productList || [],
|
|
@@ -432,7 +439,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
432
439
|
customer_id: customerId,
|
|
433
440
|
action: "create",
|
|
434
441
|
with_good_pass: 1,
|
|
435
|
-
with_discount_card: 1
|
|
442
|
+
with_discount_card: 1,
|
|
443
|
+
with_wallet_pass_holder: 1
|
|
436
444
|
}));
|
|
437
445
|
const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
|
|
438
446
|
(item) => item.isScan
|
|
@@ -23,6 +23,11 @@ export interface ShopDiscountState {
|
|
|
23
23
|
rules: RulesModule | null;
|
|
24
24
|
productList: Record<string, any>[];
|
|
25
25
|
originalDiscountList: Discount[];
|
|
26
|
+
holders?: {
|
|
27
|
+
form_record_id: number;
|
|
28
|
+
form_id?: number;
|
|
29
|
+
main_field?: string;
|
|
30
|
+
}[];
|
|
26
31
|
}
|
|
27
32
|
export interface SetDiscountSelectedParams {
|
|
28
33
|
discountId: number;
|