@pisell/pisellos 2.2.8 → 2.2.10
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/Cart/utils/cartProduct.js +41 -26
- package/dist/modules/Customer/index.js +1 -1
- package/dist/modules/Discount/index.d.ts +3 -0
- package/dist/modules/Discount/index.js +70 -37
- package/dist/modules/Discount/types.d.ts +16 -0
- package/dist/modules/Order/index.js +4 -1
- package/dist/modules/Order/utils.d.ts +1 -0
- package/dist/modules/Order/utils.js +9 -0
- package/dist/modules/Payment/cash.js +1 -1
- package/dist/modules/Payment/eftpos.js +1 -1
- package/dist/modules/Payment/index.js +101 -31
- package/dist/modules/Payment/types.d.ts +22 -2
- package/dist/modules/Payment/walletpass.js +8 -3
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +8 -9
- package/dist/modules/Rules/index.d.ts +16 -2
- package/dist/modules/Rules/index.js +1102 -200
- package/dist/modules/Rules/types.d.ts +8 -1
- package/dist/solution/BookingByStep/index.js +30 -8
- package/dist/solution/BookingByStep/utils/products.d.ts +6 -0
- package/dist/solution/BookingByStep/utils/products.js +10 -0
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/Checkout/index.d.ts +2 -0
- package/dist/solution/Checkout/index.js +277 -88
- package/dist/solution/Checkout/types.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.d.ts +5 -0
- package/dist/solution/ShopDiscount/index.js +96 -24
- package/dist/solution/ShopDiscount/types.d.ts +9 -1
- package/dist/solution/ShopDiscount/utils.d.ts +55 -0
- package/dist/solution/ShopDiscount/utils.js +432 -3
- package/lib/modules/Cart/utils/cartProduct.js +35 -22
- package/lib/modules/Customer/index.js +1 -1
- package/lib/modules/Discount/index.d.ts +3 -0
- package/lib/modules/Discount/index.js +20 -5
- package/lib/modules/Discount/types.d.ts +16 -0
- package/lib/modules/Order/index.js +2 -0
- package/lib/modules/Order/utils.d.ts +1 -0
- package/lib/modules/Order/utils.js +11 -0
- 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 +22 -2
- package/lib/modules/Payment/walletpass.js +15 -4
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +0 -7
- package/lib/modules/Rules/index.d.ts +16 -2
- package/lib/modules/Rules/index.js +857 -184
- package/lib/modules/Rules/types.d.ts +8 -1
- package/lib/solution/BookingByStep/index.js +19 -2
- package/lib/solution/BookingByStep/utils/products.d.ts +6 -0
- package/lib/solution/BookingByStep/utils/products.js +8 -2
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/Checkout/index.d.ts +2 -0
- package/lib/solution/Checkout/index.js +185 -25
- package/lib/solution/Checkout/types.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.d.ts +5 -0
- package/lib/solution/ShopDiscount/index.js +67 -13
- package/lib/solution/ShopDiscount/types.d.ts +9 -1
- package/lib/solution/ShopDiscount/utils.d.ts +55 -0
- package/lib/solution/ShopDiscount/utils.js +266 -3
- package/package.json +2 -2
|
@@ -22,6 +22,9 @@ export interface RulesModuleAPI {
|
|
|
22
22
|
calcDiscount: (params: {
|
|
23
23
|
discountList: any[];
|
|
24
24
|
productList: any[];
|
|
25
|
+
holders: {
|
|
26
|
+
form_record_id: number;
|
|
27
|
+
}[];
|
|
25
28
|
}) => DiscountResult;
|
|
26
29
|
}
|
|
27
30
|
type ProductDetail = {
|
|
@@ -40,6 +43,8 @@ type ProductDetail = {
|
|
|
40
43
|
num?: number;
|
|
41
44
|
quantity: number;
|
|
42
45
|
vouchersApplicable?: boolean;
|
|
46
|
+
holder_id?: number;
|
|
47
|
+
startDate?: any;
|
|
43
48
|
};
|
|
44
49
|
export interface RulesParamsHooks {
|
|
45
50
|
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
@@ -50,8 +55,10 @@ export interface RulesParamsHooks {
|
|
|
50
55
|
origin_total?: number;
|
|
51
56
|
price?: string | number;
|
|
52
57
|
variant?: any[];
|
|
53
|
-
original_price?: number;
|
|
58
|
+
original_price?: number | string;
|
|
54
59
|
quantity?: number;
|
|
60
|
+
bundle?: any[];
|
|
61
|
+
main_product_selling_price?: string | number;
|
|
55
62
|
}) => Record<string, any>;
|
|
56
63
|
}
|
|
57
64
|
export {};
|
|
@@ -185,13 +185,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
185
185
|
collection = [],
|
|
186
186
|
schedule_date
|
|
187
187
|
}) {
|
|
188
|
-
|
|
188
|
+
const res = await this.store.products.loadProducts({
|
|
189
189
|
category_ids,
|
|
190
190
|
product_ids,
|
|
191
191
|
collection,
|
|
192
192
|
schedule_date,
|
|
193
193
|
cacheId: this.cacheId
|
|
194
194
|
});
|
|
195
|
+
this.getAvailableDate({
|
|
196
|
+
startDate: schedule_date || (0, import_dayjs.default)().format("YYYY-MM-DD"),
|
|
197
|
+
endDate: schedule_date || (0, import_dayjs.default)().format("YYYY-MM-DD"),
|
|
198
|
+
products: [...res]
|
|
199
|
+
});
|
|
200
|
+
return res;
|
|
195
201
|
}
|
|
196
202
|
/**
|
|
197
203
|
* 通过 schedule 来读取商品,适用于 session 类商品
|
|
@@ -228,11 +234,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
228
234
|
const allProductIds = [...newProductIds, ...otherProductsIds].filter(
|
|
229
235
|
(n, index, self) => self.indexOf(n) === index
|
|
230
236
|
);
|
|
231
|
-
|
|
237
|
+
const res = await this.loadProducts({
|
|
232
238
|
product_ids: allProductIds,
|
|
233
239
|
category_ids,
|
|
234
240
|
schedule_date: date
|
|
235
241
|
});
|
|
242
|
+
return res;
|
|
236
243
|
}
|
|
237
244
|
/**
|
|
238
245
|
* 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
|
|
@@ -599,6 +606,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
599
606
|
quantity = 1
|
|
600
607
|
} = product || {};
|
|
601
608
|
const productData = { ...origin, product_variant_id };
|
|
609
|
+
debugger;
|
|
610
|
+
if ((0, import_products.isSessionProduct)(productData)) {
|
|
611
|
+
if (!date || !date.startTime || !date.endTime) {
|
|
612
|
+
return { success: false, errorCode: "date_or_time_required" };
|
|
613
|
+
}
|
|
614
|
+
}
|
|
602
615
|
const currentCartItems = this.store.cart.getItems();
|
|
603
616
|
const stockCheckResult = (0, import_stock.checkProductStock)({
|
|
604
617
|
productData,
|
|
@@ -1606,6 +1619,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1606
1619
|
}
|
|
1607
1620
|
});
|
|
1608
1621
|
});
|
|
1622
|
+
this.core.effects.emit(
|
|
1623
|
+
`${this.store.cart.name}:onUpdateBookingDate`,
|
|
1624
|
+
{}
|
|
1625
|
+
);
|
|
1609
1626
|
}
|
|
1610
1627
|
getScheduleDataByIds(scheduleIds) {
|
|
1611
1628
|
const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
@@ -9,3 +9,9 @@ export declare const getAvailableProductResources: (products: ProductData[]) =>
|
|
|
9
9
|
rules: any[];
|
|
10
10
|
resourcesMap: Record<number, ProductResourceItem>;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* 判断商品是否是 session 商品
|
|
14
|
+
* @param product 商品数据
|
|
15
|
+
* @returns 是否是 session 商品
|
|
16
|
+
*/
|
|
17
|
+
export declare const isSessionProduct: (product: ProductData) => boolean;
|
|
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/solution/BookingByStep/utils/products.ts
|
|
20
20
|
var products_exports = {};
|
|
21
21
|
__export(products_exports, {
|
|
22
|
-
getAvailableProductResources: () => getAvailableProductResources
|
|
22
|
+
getAvailableProductResources: () => getAvailableProductResources,
|
|
23
|
+
isSessionProduct: () => isSessionProduct
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(products_exports);
|
|
25
26
|
var getAvailableProductResources = (products) => {
|
|
@@ -57,7 +58,12 @@ var getAvailableProductResources = (products) => {
|
|
|
57
58
|
});
|
|
58
59
|
return { resourceIds: [...new Set(resourceIds)], rules, resourcesMap };
|
|
59
60
|
};
|
|
61
|
+
var isSessionProduct = (product) => {
|
|
62
|
+
var _a;
|
|
63
|
+
return (((_a = product == null ? void 0 : product["schedule.ids"]) == null ? void 0 : _a.length) ?? 0) > 0;
|
|
64
|
+
};
|
|
60
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
66
|
0 && (module.exports = {
|
|
62
|
-
getAvailableProductResources
|
|
67
|
+
getAvailableProductResources,
|
|
68
|
+
isSessionProduct
|
|
63
69
|
});
|
|
@@ -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, "skip" | "num">;
|
|
127
127
|
/**
|
|
128
128
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
129
129
|
* @returns 客户状态
|
|
@@ -48,11 +48,13 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
48
48
|
* 初始化结账流程
|
|
49
49
|
*/
|
|
50
50
|
initializeCheckoutAsync(params: CheckoutInitParams): Promise<void>;
|
|
51
|
+
getHolderIdFromBooking(obj: any): number | undefined;
|
|
51
52
|
getProductListByOrder(): {
|
|
52
53
|
product_id: number;
|
|
53
54
|
product_variant_id: string;
|
|
54
55
|
quantity: number;
|
|
55
56
|
selling_price: number;
|
|
57
|
+
holder_id?: number;
|
|
56
58
|
}[];
|
|
57
59
|
initWalletData(params?: {
|
|
58
60
|
order_wait_pay_amount: number;
|
|
@@ -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) {
|
|
@@ -206,26 +216,74 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
206
216
|
return pre + (item.amount || 0);
|
|
207
217
|
}, 0);
|
|
208
218
|
};
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
219
|
+
const formatProduct = (items) => {
|
|
220
|
+
return items.map(
|
|
221
|
+
(item) => ({
|
|
222
|
+
product_id: item.product_id,
|
|
223
|
+
product_variant_id: item.product_variant_id,
|
|
224
|
+
quantity: item.num,
|
|
225
|
+
// 商品是否含税:1;0
|
|
226
|
+
is_charge_tax: item.is_charge_tax ?? 0,
|
|
227
|
+
// 若商品不含税,计算得到的税费,单位(元)
|
|
228
|
+
tax_fee: item.tax_fee,
|
|
229
|
+
// 整个商品折扣后的总金额
|
|
230
|
+
selling_price: item.calculated_selling_price,
|
|
231
|
+
// 使用者id
|
|
232
|
+
holder_id: item.holder_id,
|
|
233
|
+
// 整个商品折扣前的总金额
|
|
234
|
+
original_price: item.calculated_original_price,
|
|
235
|
+
// 主商品折扣前金额,不包含套餐子商品
|
|
236
|
+
main_product_original_price: item.price,
|
|
237
|
+
// 主商品折扣后金额,不包含套餐子商品
|
|
238
|
+
main_product_selling_price: item.main_product_selling_price,
|
|
239
|
+
metadata: {
|
|
240
|
+
// 主商品+非原价(加减价)子商品税费
|
|
241
|
+
"main_product_attached_bundle_tax_fee": item.metadata.main_product_attached_bundle_tax_fee,
|
|
242
|
+
// 主商品+非原价(加减价)子商品附加费
|
|
243
|
+
"main_product_attached_bundle_surcharge_fee": item.metadata.main_product_attached_bundle_surcharge_fee,
|
|
244
|
+
// 可选,附加费均摊舍入金额
|
|
245
|
+
"surcharge_rounding_remainder": item.metadata.surcharge_rounding_remainder
|
|
246
|
+
},
|
|
247
|
+
product_bundle: item.product_bundle.map((bundle) => {
|
|
248
|
+
return {
|
|
249
|
+
bundle_id: bundle.bundle_id,
|
|
250
|
+
bundle_product_id: bundle.bundle_product_id,
|
|
251
|
+
bundle_variant_id: bundle.bundle_variant_id,
|
|
252
|
+
price_type: bundle.price_type,
|
|
253
|
+
price_type_ext: bundle.price_type_ext,
|
|
254
|
+
// 套餐子商品总价,不包含折扣金额
|
|
255
|
+
bundle_sum_price: bundle.bundle_sum_price,
|
|
256
|
+
// 套餐子商品折扣后金额
|
|
257
|
+
bundle_selling_price: bundle.bundle_selling_price,
|
|
258
|
+
num: bundle.num,
|
|
259
|
+
is_charge_tax: bundle.is_charge_tax,
|
|
260
|
+
tax_fee: bundle.tax_fee,
|
|
261
|
+
metadata: {
|
|
262
|
+
// 子商品单数量附加费
|
|
263
|
+
"surcharge_fee": bundle.metadata.surcharge_fee,
|
|
264
|
+
// 可选,附加费均摊舍入金额
|
|
265
|
+
"surcharge_rounding_remainder": bundle.metadata.surcharge_rounding_remainder
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
})
|
|
269
|
+
})
|
|
270
|
+
) || [];
|
|
271
|
+
};
|
|
272
|
+
const productList = formatProduct(
|
|
273
|
+
((_c = (_b = (_a = this.store.currentOrder.order_info) == null ? void 0 : _a.original_order_data) == null ? void 0 : _b.bookings) == null ? void 0 : _c.map(
|
|
274
|
+
(item) => {
|
|
275
|
+
return {
|
|
276
|
+
...item.product,
|
|
277
|
+
holder_id: this.getHolderIdFromBooking(item)
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
)) || []
|
|
281
|
+
);
|
|
282
|
+
const relationProducts = formatProduct(((_e = (_d = this.store.currentOrder.order_info) == null ? void 0 : _d.original_order_data) == null ? void 0 : _e.relation_products) || []);
|
|
225
283
|
return [...productList, ...relationProducts];
|
|
226
284
|
}
|
|
227
285
|
async initWalletData(params) {
|
|
228
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
286
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
229
287
|
this.logInfo("initWalletData called", {
|
|
230
288
|
params
|
|
231
289
|
});
|
|
@@ -238,17 +296,20 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
238
296
|
}
|
|
239
297
|
const walletBusinessData = {
|
|
240
298
|
customer_id: ((_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id) ? Number(this.store.currentCustomer.customer_id) : void 0,
|
|
299
|
+
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
300
|
amountInfo: {
|
|
242
301
|
totalAmount: amountInfo.totalAmount,
|
|
243
302
|
subTotal: amountInfo.subTotal,
|
|
244
|
-
depositAmount: (
|
|
245
|
-
isDeposit: (
|
|
303
|
+
depositAmount: (_g = this.store.currentOrder) == null ? void 0 : _g.deposit_amount,
|
|
304
|
+
isDeposit: (_h = this.store.currentOrder) == null ? void 0 : _h.is_deposit
|
|
246
305
|
},
|
|
247
306
|
products: this.getProductListByOrder(),
|
|
307
|
+
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
308
|
+
// core 有
|
|
248
309
|
...params
|
|
249
310
|
};
|
|
250
311
|
if (this.store.isOrderSynced) {
|
|
251
|
-
walletBusinessData.payment_order_id = (
|
|
312
|
+
walletBusinessData.payment_order_id = (_i = this.store.currentOrder) == null ? void 0 : _i.order_id;
|
|
252
313
|
}
|
|
253
314
|
this.logInfo("开始拉取:initializeWalletDataFromBusinessAsync", {
|
|
254
315
|
walletBusinessData
|
|
@@ -266,7 +327,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
266
327
|
currentOrder: this.store.currentOrder
|
|
267
328
|
});
|
|
268
329
|
await this.core.effects.emit(`${this.name}:onWalletDataInitialized`, {
|
|
269
|
-
orderUuid: (
|
|
330
|
+
orderUuid: (_j = this.store.currentOrder) == null ? void 0 : _j.uuid,
|
|
270
331
|
customerId: walletBusinessData.customer_id,
|
|
271
332
|
walletBusinessData: {
|
|
272
333
|
customer_id: walletBusinessData.customer_id,
|
|
@@ -441,7 +502,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
441
502
|
* 会覆盖 order_info 与金额等字段,并重新计算待付金额,最后设置为 currentOrder。
|
|
442
503
|
*/
|
|
443
504
|
async updateLocalOrderAsync(params) {
|
|
444
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
505
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
445
506
|
this.logInfo("updateLocalOrderAsync called", {
|
|
446
507
|
orderId: params.orderId,
|
|
447
508
|
orderDataType: (_a = params.orderData) == null ? void 0 : _a.type,
|
|
@@ -479,6 +540,82 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
479
540
|
(o) => String(o.id) === String(params.orderId) || String(o.order_id) === String(params.orderId)
|
|
480
541
|
);
|
|
481
542
|
if (existingOrder) {
|
|
543
|
+
if (params.existPayment && params.existPayment.length > 0) {
|
|
544
|
+
this.logInfo("检测到云端支付项,将替换本地订单的支付项列表", {
|
|
545
|
+
orderId: params.orderId,
|
|
546
|
+
existingPaymentCount: ((_m = existingOrder.payment) == null ? void 0 : _m.length) || 0,
|
|
547
|
+
newPaymentCount: params.existPayment.length
|
|
548
|
+
});
|
|
549
|
+
this.store.isOrderSynced = true;
|
|
550
|
+
const currentTime = (0, import_utils.formatDateTime)(/* @__PURE__ */ new Date());
|
|
551
|
+
const formattedExistPayments = params.existPayment.map((payment) => ({
|
|
552
|
+
...payment,
|
|
553
|
+
isSynced: true,
|
|
554
|
+
// 标记为已同步
|
|
555
|
+
status: payment.status || "active",
|
|
556
|
+
created_at: payment.created_at || currentTime,
|
|
557
|
+
updated_at: payment.updated_at || currentTime
|
|
558
|
+
}));
|
|
559
|
+
const isNeedDeposit3 = this.checkIsNeedDepositAsync(
|
|
560
|
+
params.orderData.bookings,
|
|
561
|
+
params.orderData.relation_products
|
|
562
|
+
);
|
|
563
|
+
await this.payment.updateOrderAsync(existingOrder.uuid, {
|
|
564
|
+
total_amount: amountInfo.totalAmount,
|
|
565
|
+
is_deposit: isNeedDeposit3.hasDeposit ? 1 : 0,
|
|
566
|
+
deposit_amount: isNeedDeposit3.total ? isNeedDeposit3.total.toString() : "0.00",
|
|
567
|
+
payment: formattedExistPayments,
|
|
568
|
+
// 🔧 替换支付项列表
|
|
569
|
+
order_info: {
|
|
570
|
+
original_order_data: params.orderData,
|
|
571
|
+
cart_summary: params.cartSummary,
|
|
572
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
573
|
+
platform: params.orderData.platform,
|
|
574
|
+
type: params.orderData.type,
|
|
575
|
+
schedule_date: params.orderData.schedule_date,
|
|
576
|
+
shop_note: params.orderData.shop_note,
|
|
577
|
+
amount_breakdown: amountInfo
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
const updated2 = await this.payment.getPaymentOrderByUuidAsync(
|
|
581
|
+
existingOrder.uuid
|
|
582
|
+
);
|
|
583
|
+
if (!updated2)
|
|
584
|
+
throw (0, import_utils.createCheckoutError)(
|
|
585
|
+
import_types.CheckoutErrorType.UnknownError,
|
|
586
|
+
"订单更新失败"
|
|
587
|
+
);
|
|
588
|
+
this.store.currentOrder = updated2;
|
|
589
|
+
await this.updateStateAmountToRemaining(false);
|
|
590
|
+
this.logInfo("本地订单更新成功(已替换云端支付项):", {
|
|
591
|
+
orderId: params.orderId,
|
|
592
|
+
uuid: updated2.uuid,
|
|
593
|
+
payments: ((_n = updated2.payment) == null ? void 0 : _n.length) || 0,
|
|
594
|
+
totalAmount: updated2.total_amount,
|
|
595
|
+
expectAmount: updated2.expect_amount,
|
|
596
|
+
isOrderSynced: true
|
|
597
|
+
});
|
|
598
|
+
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
599
|
+
order: updated2,
|
|
600
|
+
timestamp: Date.now()
|
|
601
|
+
});
|
|
602
|
+
const syncedPayments = updated2.payment.filter((p) => p.isSynced && p.status !== "voided");
|
|
603
|
+
const syncedAmount2 = syncedPayments.reduce((sum, p) => {
|
|
604
|
+
const amt = new import_decimal.default(p.amount || "0");
|
|
605
|
+
const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
|
|
606
|
+
return sum.plus(amt).plus(rounding);
|
|
607
|
+
}, new import_decimal.default(0));
|
|
608
|
+
const totalAmount2 = new import_decimal.default(amountInfo.totalAmount || "0");
|
|
609
|
+
const remainingExpectAmount2 = import_decimal.default.max(0, totalAmount2.minus(syncedAmount2)).toFixed(2);
|
|
610
|
+
let depositDiffAmount2 = new import_decimal.default(0).toFixed(2);
|
|
611
|
+
if (updated2.is_deposit === 1) {
|
|
612
|
+
depositDiffAmount2 = new import_decimal.default(updated2.deposit_amount).minus(syncedAmount2).toFixed(2);
|
|
613
|
+
}
|
|
614
|
+
this.initWalletData({
|
|
615
|
+
order_wait_pay_amount: Number(depositDiffAmount2) > 0 ? Number(depositDiffAmount2) : Number(remainingExpectAmount2)
|
|
616
|
+
});
|
|
617
|
+
return updated2;
|
|
618
|
+
}
|
|
482
619
|
const totalAmount = new import_decimal.default(amountInfo.totalAmount || "0");
|
|
483
620
|
const activePayments = (existingOrder.payment || []).filter(
|
|
484
621
|
(p) => p.status !== "voided"
|
|
@@ -524,7 +661,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
524
661
|
this.logInfo("本地订单更新成功(保留支付项):", {
|
|
525
662
|
orderId: params.orderId,
|
|
526
663
|
uuid: updated.uuid,
|
|
527
|
-
payments: ((
|
|
664
|
+
payments: ((_o = updated.payment) == null ? void 0 : _o.length) || 0,
|
|
528
665
|
totalAmount: updated.total_amount,
|
|
529
666
|
expectAmount: updated.expect_amount
|
|
530
667
|
});
|
|
@@ -558,6 +695,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
558
695
|
total_amount: amountInfo.totalAmount,
|
|
559
696
|
is_deposit: isNeedDeposit.hasDeposit ? 1 : 0,
|
|
560
697
|
deposit_amount: isNeedDeposit.total ? isNeedDeposit.total.toString() : "0.00",
|
|
698
|
+
existPayment: params.existPayment,
|
|
699
|
+
// 🔧 新增: 传递云端支付项
|
|
561
700
|
order_info: {
|
|
562
701
|
original_order_data: params.orderData,
|
|
563
702
|
cart_summary: params.cartSummary,
|
|
@@ -570,7 +709,28 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
570
709
|
}
|
|
571
710
|
});
|
|
572
711
|
this.store.currentOrder = created;
|
|
573
|
-
|
|
712
|
+
if (params.existPayment && params.existPayment.length > 0) {
|
|
713
|
+
this.store.isOrderSynced = true;
|
|
714
|
+
const syncedPayments = created.payment.filter((p) => p.isSynced && p.status !== "voided");
|
|
715
|
+
const syncedAmount = syncedPayments.reduce((sum, p) => {
|
|
716
|
+
const amt = new import_decimal.default(p.amount || "0");
|
|
717
|
+
const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
|
|
718
|
+
return sum.plus(amt).plus(rounding);
|
|
719
|
+
}, new import_decimal.default(0));
|
|
720
|
+
this.logInfo("云端订单初始化钱包数据", {
|
|
721
|
+
orderId: params.orderId,
|
|
722
|
+
totalAmount: created.total_amount,
|
|
723
|
+
expectAmount: created.expect_amount,
|
|
724
|
+
syncedAmount: syncedAmount.toFixed(2),
|
|
725
|
+
syncedPaymentCount: syncedPayments.length,
|
|
726
|
+
isOrderSynced: true
|
|
727
|
+
});
|
|
728
|
+
this.initWalletData({
|
|
729
|
+
order_wait_pay_amount: Number(created.expect_amount)
|
|
730
|
+
});
|
|
731
|
+
} else {
|
|
732
|
+
this.initWalletData();
|
|
733
|
+
}
|
|
574
734
|
return created;
|
|
575
735
|
}
|
|
576
736
|
/**
|
|
@@ -1967,7 +2127,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1967
2127
|
const depositPaidAmount = paymentItems.filter(
|
|
1968
2128
|
(item) => item.order_payment_type === "deposit" && item.status !== "voided"
|
|
1969
2129
|
).reduce((sum, item) => {
|
|
1970
|
-
if (item.voucher_id && !item.isSynced) {
|
|
2130
|
+
if (item.voucher_id && !item.isSynced && paymentItems.filter((item2) => !item2.voucher_id).length === 0) {
|
|
1971
2131
|
return sum;
|
|
1972
2132
|
}
|
|
1973
2133
|
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)
|
|
@@ -18,7 +18,12 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
18
18
|
private initializePlugins;
|
|
19
19
|
private registerDependentModules;
|
|
20
20
|
private registerEventListeners;
|
|
21
|
+
getCurrentBookingTime(): string | null;
|
|
22
|
+
private filterDiscountListByBookingTime;
|
|
21
23
|
setCustomer(customer: Customer): Promise<void>;
|
|
24
|
+
setHolders(holders: {
|
|
25
|
+
form_record_id: number;
|
|
26
|
+
}[]): void;
|
|
22
27
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
23
28
|
productList: Record<string, any>[];
|
|
24
29
|
discountList: Discount[];
|
|
@@ -36,6 +36,7 @@ module.exports = __toCommonJS(ShopDiscount_exports);
|
|
|
36
36
|
var import_BaseModule = require("../../modules/BaseModule");
|
|
37
37
|
var import_Discount = require("../../modules/Discount");
|
|
38
38
|
var import_Rules = require("../../modules/Rules");
|
|
39
|
+
var import_utils = require("./utils");
|
|
39
40
|
var import_decimal = __toESM(require("decimal.js"));
|
|
40
41
|
var import_lodash_es = require("lodash-es");
|
|
41
42
|
var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
@@ -50,7 +51,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
50
51
|
productList: [],
|
|
51
52
|
discount: null,
|
|
52
53
|
rules: null,
|
|
53
|
-
originalDiscountList: []
|
|
54
|
+
originalDiscountList: [],
|
|
55
|
+
currentBookingTime: "",
|
|
56
|
+
filteredDiscountList: [],
|
|
57
|
+
holders: []
|
|
54
58
|
};
|
|
55
59
|
}
|
|
56
60
|
// =========== 生命周期方法 ===========
|
|
@@ -139,6 +143,44 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
139
143
|
);
|
|
140
144
|
}
|
|
141
145
|
// =========== 公共 API ===========
|
|
146
|
+
// 设置预约时间
|
|
147
|
+
// public async setBookingTime(bookingTime: string | null): Promise<void> {
|
|
148
|
+
// if (this.store.currentBookingTime !== bookingTime) {
|
|
149
|
+
// this.store.currentBookingTime = bookingTime;
|
|
150
|
+
//
|
|
151
|
+
// // 更新过滤后的优惠券列表
|
|
152
|
+
// await this.updateFilteredDiscountList();
|
|
153
|
+
// }
|
|
154
|
+
// }
|
|
155
|
+
// 获取当前预约时间
|
|
156
|
+
getCurrentBookingTime() {
|
|
157
|
+
return this.store.currentBookingTime;
|
|
158
|
+
}
|
|
159
|
+
// 根据预约时间过滤优惠券列表
|
|
160
|
+
filterDiscountListByBookingTime(discountList, bookingTime) {
|
|
161
|
+
if ((0, import_utils.isAllNormalProduct)(this.store.productList || [])) {
|
|
162
|
+
return discountList;
|
|
163
|
+
}
|
|
164
|
+
return (0, import_utils.filterDiscountListByBookingTime)(discountList, bookingTime);
|
|
165
|
+
}
|
|
166
|
+
// 更新过滤后的优惠券列表
|
|
167
|
+
// private async updateFilteredDiscountList(): Promise<void> {
|
|
168
|
+
// const originalList = this.store.originalDiscountList;
|
|
169
|
+
// const filteredList = this.filterDiscountListByBookingTime(originalList, this.store.currentBookingTime);
|
|
170
|
+
//
|
|
171
|
+
// this.store.filteredDiscountList = filteredList;
|
|
172
|
+
//
|
|
173
|
+
// // 更新 DiscountModule 中的优惠券列表
|
|
174
|
+
// this.setDiscountList(filteredList);
|
|
175
|
+
//
|
|
176
|
+
// if (this.store.productList?.length) {
|
|
177
|
+
// const result = this.calcDiscount(this.store.productList);
|
|
178
|
+
// await this.core.effects.emit(
|
|
179
|
+
// ShopDiscountHooks.onLoadPrepareCalcResult,
|
|
180
|
+
// result,
|
|
181
|
+
// );
|
|
182
|
+
// }
|
|
183
|
+
// }
|
|
142
184
|
// 设置客户
|
|
143
185
|
async setCustomer(customer) {
|
|
144
186
|
var _a;
|
|
@@ -150,6 +192,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
150
192
|
);
|
|
151
193
|
}
|
|
152
194
|
}
|
|
195
|
+
// 设置holders
|
|
196
|
+
setHolders(holders) {
|
|
197
|
+
this.store.holders = holders;
|
|
198
|
+
}
|
|
153
199
|
// 计算优惠券
|
|
154
200
|
calcDiscount(productList, options) {
|
|
155
201
|
this.store.productList = productList;
|
|
@@ -160,7 +206,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
160
206
|
let { productList: newProductList, discountList: newDiscountList } = rulesModule.calcDiscount(
|
|
161
207
|
{
|
|
162
208
|
productList,
|
|
163
|
-
discountList: this.getDiscountList()
|
|
209
|
+
discountList: this.getDiscountList(),
|
|
210
|
+
holders: this.store.holders || []
|
|
164
211
|
},
|
|
165
212
|
options
|
|
166
213
|
) || { productList, discountList: this.getDiscountList() };
|
|
@@ -249,7 +296,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
249
296
|
} = rulesModule.isDiscountListAvailable({
|
|
250
297
|
productList: this.store.productList || [],
|
|
251
298
|
oldDiscountList: this.getDiscountList(),
|
|
252
|
-
newDiscountList: withScanList
|
|
299
|
+
newDiscountList: withScanList,
|
|
300
|
+
holders: this.store.holders || []
|
|
253
301
|
}) || {
|
|
254
302
|
isAvailable: false,
|
|
255
303
|
productList: this.store.productList || [],
|
|
@@ -324,7 +372,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
324
372
|
editModeDiscountList[index] = {
|
|
325
373
|
...editModeDiscountList[index],
|
|
326
374
|
amount: new import_decimal.default(discount.amount || 0).plus(new import_decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
|
|
327
|
-
savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
375
|
+
savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
328
376
|
};
|
|
329
377
|
} else {
|
|
330
378
|
if (discount.type && !discount.tag) {
|
|
@@ -335,7 +383,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
335
383
|
name: discount.name || discount.discount.title.auto,
|
|
336
384
|
isEditMode: true,
|
|
337
385
|
limited_relation_product_data: {},
|
|
338
|
-
savedAmount: discount.amount * ((product == null ? void 0 : product.num) || 1),
|
|
386
|
+
savedAmount: discount.amount * ((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1),
|
|
339
387
|
isAvailable: true,
|
|
340
388
|
id: ((_a3 = discount.discount) == null ? void 0 : _a3.resource_id) || discount.id,
|
|
341
389
|
format_title: ((_b = discount.discount) == null ? void 0 : _b.title) || discount.format_title,
|
|
@@ -355,15 +403,17 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
355
403
|
const isProductFree = (id) => {
|
|
356
404
|
var _a2;
|
|
357
405
|
const targetProduct = productList.find((n) => n.id === id);
|
|
406
|
+
if (!targetProduct)
|
|
407
|
+
return false;
|
|
358
408
|
const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
|
|
359
409
|
return Number(product == null ? void 0 : product.total) <= 0 && (Number(product == null ? void 0 : product.origin_total) <= 0 || !(product == null ? void 0 : product.origin_total)) || (0, import_lodash_es.isBoolean)(product == null ? void 0 : product.vouchersApplicable) && !(product == null ? void 0 : product.vouchersApplicable);
|
|
360
410
|
};
|
|
361
|
-
const allUsedProductIds = newDiscountList.map((n) => {
|
|
411
|
+
const allUsedProductIds = newDiscountList.filter((item) => !(item == null ? void 0 : item.isEditMode)).map((n) => {
|
|
362
412
|
var _a2;
|
|
363
|
-
return n.isSelected ? (_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
|
|
413
|
+
return n.isSelected ? ((_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
|
|
364
414
|
var _a3;
|
|
365
415
|
return (_a3 = n2.discount) == null ? void 0 : _a3.product_id;
|
|
366
|
-
}) : [];
|
|
416
|
+
})) || n.product_id : [];
|
|
367
417
|
}).flat();
|
|
368
418
|
newDiscountList.forEach((item) => {
|
|
369
419
|
var _a2;
|
|
@@ -425,14 +475,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
425
475
|
}
|
|
426
476
|
// 加载准备配置
|
|
427
477
|
async loadPrepareConfig(params) {
|
|
428
|
-
var _a, _b, _c, _d;
|
|
478
|
+
var _a, _b, _c, _d, _e;
|
|
429
479
|
try {
|
|
430
480
|
const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
|
|
431
481
|
const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
432
482
|
customer_id: customerId,
|
|
433
483
|
action: "create",
|
|
434
484
|
with_good_pass: 1,
|
|
435
|
-
with_discount_card: 1
|
|
485
|
+
with_discount_card: 1,
|
|
486
|
+
with_wallet_pass_holder: 1
|
|
436
487
|
}));
|
|
437
488
|
const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
|
|
438
489
|
(item) => item.isScan
|
|
@@ -441,8 +492,11 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
441
492
|
const newGoodPassList = goodPassList == null ? void 0 : goodPassList.filter((n) => !scanDiscountIds.includes(n.id));
|
|
442
493
|
const newDiscountList = [...scanDiscount, ...newGoodPassList || []];
|
|
443
494
|
this.store.originalDiscountList = newDiscountList;
|
|
444
|
-
this.
|
|
445
|
-
|
|
495
|
+
await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(newDiscountList));
|
|
496
|
+
const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
497
|
+
this.store.filteredDiscountList = filteredDiscountList;
|
|
498
|
+
this.setDiscountList(filteredDiscountList || []);
|
|
499
|
+
if ((_e = this.store.productList) == null ? void 0 : _e.length) {
|
|
446
500
|
const result = this.calcDiscount(this.store.productList);
|
|
447
501
|
await this.core.effects.emit(
|
|
448
502
|
`${this.name}:onLoadPrepareCalcResult`,
|
|
@@ -451,7 +505,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
451
505
|
}
|
|
452
506
|
await this.core.effects.emit(
|
|
453
507
|
`${this.name}:onLoadDiscountList`,
|
|
454
|
-
|
|
508
|
+
filteredDiscountList
|
|
455
509
|
);
|
|
456
510
|
} catch (error) {
|
|
457
511
|
console.error("[ShopDiscount] 加载准备配置出错:", error);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DiscountModule
|
|
1
|
+
import { DiscountModule } from '../../modules/Discount';
|
|
2
2
|
import { RulesModule } from '../../modules/Rules';
|
|
3
|
+
import { Discount } from "../../modules/Discount/types";
|
|
3
4
|
export declare enum ShopDiscountHooks {
|
|
4
5
|
onInited = "shopDiscount:onInited",
|
|
5
6
|
onDestroy = "shopDiscount:onDestroy",
|
|
@@ -23,6 +24,13 @@ export interface ShopDiscountState {
|
|
|
23
24
|
rules: RulesModule | null;
|
|
24
25
|
productList: Record<string, any>[];
|
|
25
26
|
originalDiscountList: Discount[];
|
|
27
|
+
holders?: {
|
|
28
|
+
form_record_id: number;
|
|
29
|
+
form_id?: number;
|
|
30
|
+
main_field?: string;
|
|
31
|
+
}[];
|
|
32
|
+
currentBookingTime: string | null;
|
|
33
|
+
filteredDiscountList: Discount[];
|
|
26
34
|
}
|
|
27
35
|
export interface SetDiscountSelectedParams {
|
|
28
36
|
discountId: number;
|