@pisell/pisellos 2.2.235 → 2.2.237
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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/Order/index.d.ts +1 -0
- package/dist/modules/Order/index.js +37 -16
- package/dist/modules/Order/utils.d.ts +21 -1
- package/dist/modules/Order/utils.js +278 -70
- package/dist/server/modules/order/index.js +1 -1
- package/dist/server/modules/resource/index.d.ts +2 -0
- package/dist/server/modules/resource/index.js +29 -3
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/modules/Order/index.d.ts +1 -0
- package/lib/modules/Order/index.js +34 -10
- package/lib/modules/Order/utils.d.ts +21 -1
- package/lib/modules/Order/utils.js +171 -0
- package/lib/server/modules/order/index.js +1 -0
- package/lib/server/modules/resource/index.d.ts +2 -0
- package/lib/server/modules/resource/index.js +27 -3
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// 导出评估器
|
|
2
|
+
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
+
|
|
4
|
+
// 导出适配器
|
|
5
|
+
export { PromotionAdapter } from "./adapter";
|
|
6
|
+
export { default } from "./adapter";
|
|
7
|
+
|
|
8
|
+
// 导出策略配置示例常量
|
|
9
|
+
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
|
|
@@ -234,6 +234,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
234
234
|
private findBookingIndexByUniqueIdentificationNumber;
|
|
235
235
|
private removeLinkedBookingsForProduct;
|
|
236
236
|
private getSalesSummary;
|
|
237
|
+
private applyOrderProductsDepositSummary;
|
|
237
238
|
recalculateSummary(options?: {
|
|
238
239
|
createIfMissing?: boolean;
|
|
239
240
|
}): Promise<OrderSummary | null>;
|
|
@@ -30,7 +30,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
30
30
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
31
31
|
import { BaseModule } from "../BaseModule";
|
|
32
32
|
import { OrderHooks } from "./types";
|
|
33
|
-
import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, mergeOrderProductDisplayFields } from "./utils";
|
|
33
|
+
import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, mergeOrderProductDisplayFields } from "./utils";
|
|
34
34
|
import { isNormalProduct } from "../Product/utils";
|
|
35
35
|
import dayjs from 'dayjs';
|
|
36
36
|
import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid } from "../../solution/BaseSales/utils/cartPromotion";
|
|
@@ -2308,12 +2308,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2308
2308
|
if (!this.salesSummaryModuleName) return null;
|
|
2309
2309
|
return this.core.getModule(this.salesSummaryModuleName);
|
|
2310
2310
|
}
|
|
2311
|
+
}, {
|
|
2312
|
+
key: "applyOrderProductsDepositSummary",
|
|
2313
|
+
value: function applyOrderProductsDepositSummary(tempOrder, summary) {
|
|
2314
|
+
var _tempOrder$_extend5;
|
|
2315
|
+
var depositSummary = calculateOrderProductsDeposit(tempOrder.products || [], {
|
|
2316
|
+
productsByUid: (_tempOrder$_extend5 = tempOrder._extend) === null || _tempOrder$_extend5 === void 0 ? void 0 : _tempOrder$_extend5.productsByUid
|
|
2317
|
+
});
|
|
2318
|
+
var nextSummary = _objectSpread(_objectSpread({}, summary), {}, {
|
|
2319
|
+
deposit_amount: depositSummary.totalText,
|
|
2320
|
+
deposit: depositSummary.hasDeposit ? {
|
|
2321
|
+
total: depositSummary.totalText,
|
|
2322
|
+
deposit_policy_ids: depositSummary.deposit_policy_ids,
|
|
2323
|
+
deposit_policy_data: depositSummary.protocols,
|
|
2324
|
+
hasDeposit: true
|
|
2325
|
+
} : undefined
|
|
2326
|
+
});
|
|
2327
|
+
tempOrder.deposit_amount = depositSummary.totalText;
|
|
2328
|
+
tempOrder.is_deposit = depositSummary.hasDeposit ? 1 : 0;
|
|
2329
|
+
return nextSummary;
|
|
2330
|
+
}
|
|
2311
2331
|
}, {
|
|
2312
2332
|
key: "recalculateSummary",
|
|
2313
2333
|
value: function () {
|
|
2314
2334
|
var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(options) {
|
|
2315
2335
|
var _ref45, _salesSummaryResult$e;
|
|
2316
|
-
var tempOrder, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
|
|
2336
|
+
var tempOrder, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummaryBase, emptySummaryWithDeposit, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
|
|
2317
2337
|
return _regeneratorRuntime().wrap(function _callee10$(_context12) {
|
|
2318
2338
|
while (1) switch (_context12.prev = _context12.next) {
|
|
2319
2339
|
case 0:
|
|
@@ -2342,22 +2362,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2342
2362
|
totalRefundAmount = existedSummary.total_refund_amount || '0.00';
|
|
2343
2363
|
paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
|
|
2344
2364
|
if (salesSummary) {
|
|
2345
|
-
_context12.next =
|
|
2365
|
+
_context12.next = 23;
|
|
2346
2366
|
break;
|
|
2347
2367
|
}
|
|
2348
2368
|
emptyBaseSummary = _objectSpread(_objectSpread(_objectSpread({}, createEmptySummary()), existedSummary), {}, {
|
|
2349
2369
|
total_refund_amount: totalRefundAmount
|
|
2350
2370
|
});
|
|
2351
|
-
|
|
2371
|
+
emptySummaryBase = _objectSpread(_objectSpread({}, emptyBaseSummary), {}, {
|
|
2352
2372
|
customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
|
|
2353
2373
|
order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
|
|
2374
|
+
pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2),
|
|
2375
|
+
rounding_amount: paidPaymentSummary.roundingAmount.toFixed(2)
|
|
2376
|
+
});
|
|
2377
|
+
emptySummaryWithDeposit = this.applyOrderProductsDepositSummary(tempOrder, emptySummaryBase);
|
|
2378
|
+
emptySummary = _objectSpread(_objectSpread({}, emptySummaryWithDeposit), {}, {
|
|
2354
2379
|
amount_gap: this.calculateSummaryAmountGap({
|
|
2355
2380
|
tempOrder: tempOrder,
|
|
2356
|
-
summary:
|
|
2381
|
+
summary: emptySummaryWithDeposit,
|
|
2357
2382
|
orderPaidAmount: paidPaymentSummary.gapPaidAmount
|
|
2358
|
-
})
|
|
2359
|
-
pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2),
|
|
2360
|
-
rounding_amount: paidPaymentSummary.roundingAmount.toFixed(2)
|
|
2383
|
+
})
|
|
2361
2384
|
});
|
|
2362
2385
|
tempOrder.surcharge_fee = emptySummary.surcharge_fee;
|
|
2363
2386
|
this.store.summary = emptySummary;
|
|
@@ -2366,14 +2389,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2366
2389
|
summary: emptySummary
|
|
2367
2390
|
});
|
|
2368
2391
|
return _context12.abrupt("return", this.store.summary);
|
|
2369
|
-
case
|
|
2370
|
-
_context12.next =
|
|
2392
|
+
case 23:
|
|
2393
|
+
_context12.next = 25;
|
|
2371
2394
|
return salesSummary.getSummary({
|
|
2372
2395
|
products: summaryProducts,
|
|
2373
2396
|
isPriceIncludeTax: tempOrder.is_price_include_tax,
|
|
2374
2397
|
shopDiscount: tempOrder.shop_discount
|
|
2375
2398
|
});
|
|
2376
|
-
case
|
|
2399
|
+
case 25:
|
|
2377
2400
|
salesSummaryResult = _context12.sent;
|
|
2378
2401
|
if (shouldFullRecalculateFromSnapshot) {
|
|
2379
2402
|
tempOrder.products = summaryProducts;
|
|
@@ -2391,10 +2414,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2391
2414
|
normalizedExpectAmountPatch = expectAmount && salesSummaryResult.expect_amount === undefined ? {
|
|
2392
2415
|
expect_amount: expectAmount.toFixed(2)
|
|
2393
2416
|
} : {};
|
|
2394
|
-
summaryForGap = _objectSpread(_objectSpread(_objectSpread({}, salesSummaryResult), {}, {
|
|
2417
|
+
summaryForGap = this.applyOrderProductsDepositSummary(tempOrder, _objectSpread(_objectSpread(_objectSpread({}, salesSummaryResult), {}, {
|
|
2395
2418
|
total_refund_amount: totalRefundAmount
|
|
2396
|
-
}, amountPaymentPatch), normalizedExpectAmountPatch);
|
|
2397
|
-
summary = _objectSpread(_objectSpread(_objectSpread(_objectSpread({},
|
|
2419
|
+
}, amountPaymentPatch), normalizedExpectAmountPatch));
|
|
2420
|
+
summary = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, summaryForGap), {}, {
|
|
2398
2421
|
total_refund_amount: totalRefundAmount,
|
|
2399
2422
|
customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
|
|
2400
2423
|
order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2)
|
|
@@ -2415,8 +2438,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2415
2438
|
}
|
|
2416
2439
|
tempOrder.surcharge_fee = summary.surcharge_fee;
|
|
2417
2440
|
tempOrder.surcharges = summary.surcharges || [];
|
|
2418
|
-
tempOrder.deposit_amount = summary.deposit_amount || '0.00';
|
|
2419
|
-
tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
|
|
2420
2441
|
this.updateTempOrderPaymentStatus(tempOrder, {
|
|
2421
2442
|
previousSummary: existedSummary,
|
|
2422
2443
|
summary: summary
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
import type { CartItem } from "../Cart";
|
|
3
|
-
import type { OrderProductDiscountItem, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder } from './types';
|
|
3
|
+
import type { OrderProductDiscountItem, OrderProduct, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder } from './types';
|
|
4
4
|
import type { RulesParamsHooks } from '../Rules/types';
|
|
5
5
|
import type { MapOrderPaymentsOptions, OrderPaymentData, OrderPaymentSource } from './types';
|
|
6
|
+
export interface OrderProductsDepositProtocol {
|
|
7
|
+
id: number;
|
|
8
|
+
title: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OrderProductsDepositSummary {
|
|
11
|
+
total: number;
|
|
12
|
+
totalText: string;
|
|
13
|
+
protocols: OrderProductsDepositProtocol[];
|
|
14
|
+
deposit_policy_ids: number[];
|
|
15
|
+
hasDeposit: boolean;
|
|
16
|
+
}
|
|
6
17
|
/**
|
|
7
18
|
* 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。
|
|
8
19
|
*
|
|
@@ -53,6 +64,15 @@ export declare function sumOptionUnitPrice(options?: Array<{
|
|
|
53
64
|
price?: any;
|
|
54
65
|
num?: any;
|
|
55
66
|
}> | null): Decimal;
|
|
67
|
+
/**
|
|
68
|
+
* 仅基于 tempOrder.products 重算整单定金。
|
|
69
|
+
*
|
|
70
|
+
* 对齐 Checkout relation_products 分支:商品定金先按商品规则计算,
|
|
71
|
+
* 再扣减商品券/折扣卡抵扣金额;tempOrder.bookings 不参与这里的计算。
|
|
72
|
+
*/
|
|
73
|
+
export declare function calculateOrderProductsDeposit(products?: OrderProduct[], options?: {
|
|
74
|
+
productsByUid?: Record<string, Record<string, any>>;
|
|
75
|
+
}): OrderProductsDepositSummary;
|
|
56
76
|
/**
|
|
57
77
|
* 判定套餐子商品是否为 markdown(减价)类型。
|
|
58
78
|
* 与后端口径一致:price_type='markdown' 且 price_type_ext 非 'product_price'(原价子商品)。
|
|
@@ -107,6 +107,214 @@ export function sumOptionUnitPrice(options) {
|
|
|
107
107
|
}
|
|
108
108
|
return total;
|
|
109
109
|
}
|
|
110
|
+
function getSafeOrderProductNum(num) {
|
|
111
|
+
var parsedNum = Number(num !== null && num !== void 0 ? num : 1);
|
|
112
|
+
if (!Number.isFinite(parsedNum) || parsedNum < 1) return 1;
|
|
113
|
+
return Math.floor(parsedNum);
|
|
114
|
+
}
|
|
115
|
+
function getOrderProductDepositUnitTotal(product) {
|
|
116
|
+
var _ref2;
|
|
117
|
+
var metadata = product.metadata || {};
|
|
118
|
+
var paymentPrice = metadata.main_product_attached_bundle_payment_price;
|
|
119
|
+
var mainSellingPrice = metadata.main_product_selling_price;
|
|
120
|
+
var fallbackPrice = product.selling_price;
|
|
121
|
+
return new Decimal(Number((_ref2 = paymentPrice !== null && paymentPrice !== void 0 ? paymentPrice : mainSellingPrice) !== null && _ref2 !== void 0 ? _ref2 : fallbackPrice) || 0);
|
|
122
|
+
}
|
|
123
|
+
function normalizeDepositProtocols(protocols) {
|
|
124
|
+
if (!Array.isArray(protocols)) return [];
|
|
125
|
+
return protocols.reduce(function (result, protocol) {
|
|
126
|
+
var id = Number(protocol === null || protocol === void 0 ? void 0 : protocol.id);
|
|
127
|
+
if (!Number.isFinite(id)) return result;
|
|
128
|
+
result.push({
|
|
129
|
+
id: Math.floor(id),
|
|
130
|
+
title: String((protocol === null || protocol === void 0 ? void 0 : protocol.title) || '')
|
|
131
|
+
});
|
|
132
|
+
return result;
|
|
133
|
+
}, []);
|
|
134
|
+
}
|
|
135
|
+
function getDepositPolicyIds(depositData) {
|
|
136
|
+
var ids = [].concat(_toConsumableArray(Array.isArray(depositData === null || depositData === void 0 ? void 0 : depositData.self_deposit_policy_ids) ? depositData.self_deposit_policy_ids : []), _toConsumableArray(Array.isArray(depositData === null || depositData === void 0 ? void 0 : depositData.deposit_policy_ids) ? depositData.deposit_policy_ids : []));
|
|
137
|
+
return ids.reduce(function (result, id) {
|
|
138
|
+
var normalizedId = Number(id);
|
|
139
|
+
if (!Number.isFinite(normalizedId)) return result;
|
|
140
|
+
result.push(Math.floor(normalizedId));
|
|
141
|
+
return result;
|
|
142
|
+
}, []);
|
|
143
|
+
}
|
|
144
|
+
function handleOrderProductDeposit(params) {
|
|
145
|
+
var depositData = params.depositData,
|
|
146
|
+
total = params.total,
|
|
147
|
+
num = params.num;
|
|
148
|
+
if (!depositData) return {
|
|
149
|
+
result: false,
|
|
150
|
+
depositTotal: new Decimal(0)
|
|
151
|
+
};
|
|
152
|
+
var deposit_fixed = depositData.deposit_fixed,
|
|
153
|
+
deposit_percentage = depositData.deposit_percentage;
|
|
154
|
+
if (typeof deposit_fixed !== 'string' || typeof deposit_percentage !== 'string') {
|
|
155
|
+
return {
|
|
156
|
+
result: false,
|
|
157
|
+
depositTotal: new Decimal(0)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
var depositFixed = new Decimal(deposit_fixed || 0);
|
|
161
|
+
var depositPercent = new Decimal(deposit_percentage || 0);
|
|
162
|
+
var productTotalPrice = new Decimal(total || 0);
|
|
163
|
+
var deposit = depositFixed.plus(depositPercent.times(productTotalPrice));
|
|
164
|
+
return {
|
|
165
|
+
depositTotal: deposit.times(num),
|
|
166
|
+
result: true
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function resolveOrderProductDepositSource(product, runtimeOrigin) {
|
|
170
|
+
var _ref3, _record$custom_deposi, _ref4, _record$variant;
|
|
171
|
+
var record = product;
|
|
172
|
+
var origin = record._origin || runtimeOrigin || {};
|
|
173
|
+
var originProduct = origin.product || {};
|
|
174
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, originProduct), origin), record), {}, {
|
|
175
|
+
custom_deposit_data: (_ref3 = (_record$custom_deposi = record.custom_deposit_data) !== null && _record$custom_deposi !== void 0 ? _record$custom_deposi : origin.custom_deposit_data) !== null && _ref3 !== void 0 ? _ref3 : originProduct.custom_deposit_data,
|
|
176
|
+
variant: (_ref4 = (_record$variant = record.variant) !== null && _record$variant !== void 0 ? _record$variant : origin.variant) !== null && _ref4 !== void 0 ? _ref4 : originProduct.variant
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function getOrderProductDeposit(product, runtimeOrigin) {
|
|
180
|
+
var depositProduct = resolveOrderProductDepositSource(product, runtimeOrigin);
|
|
181
|
+
var depositData = depositProduct.custom_deposit_data;
|
|
182
|
+
if ((depositData === null || depositData === void 0 ? void 0 : depositData.has_deposit) != 1) return null;
|
|
183
|
+
var num = getSafeOrderProductNum(product.num);
|
|
184
|
+
var total = getOrderProductDepositUnitTotal(product).times(num);
|
|
185
|
+
var allProtocols = normalizeDepositProtocols(depositData.deposit_policy_data);
|
|
186
|
+
var protocolIds = [];
|
|
187
|
+
var depositTotal = new Decimal(0);
|
|
188
|
+
var hasDeposit = false;
|
|
189
|
+
if (typeof depositData.deposit_fixed === 'string' && typeof depositData.deposit_percentage === 'string') {
|
|
190
|
+
var result = handleOrderProductDeposit({
|
|
191
|
+
depositData: depositData,
|
|
192
|
+
total: total,
|
|
193
|
+
num: num
|
|
194
|
+
});
|
|
195
|
+
if (result.result) {
|
|
196
|
+
depositTotal = result.depositTotal;
|
|
197
|
+
protocolIds.push.apply(protocolIds, _toConsumableArray(getDepositPolicyIds({
|
|
198
|
+
self_deposit_policy_ids: depositData.self_deposit_policy_ids
|
|
199
|
+
})));
|
|
200
|
+
hasDeposit = true;
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
var _depositProduct$produ;
|
|
204
|
+
var productVariantId = (_depositProduct$produ = depositProduct.product_variant_id) !== null && _depositProduct$produ !== void 0 ? _depositProduct$produ : product.product_variant_id;
|
|
205
|
+
if (productVariantId) {
|
|
206
|
+
var variantProduct = (depositProduct.variant || []).find(function (item) {
|
|
207
|
+
return (item === null || item === void 0 ? void 0 : item.id) === productVariantId;
|
|
208
|
+
});
|
|
209
|
+
var variantDepositData = variantProduct === null || variantProduct === void 0 ? void 0 : variantProduct.custom_deposit_data;
|
|
210
|
+
var _result = handleOrderProductDeposit({
|
|
211
|
+
depositData: variantDepositData,
|
|
212
|
+
total: total,
|
|
213
|
+
num: num
|
|
214
|
+
});
|
|
215
|
+
if (_result.result) {
|
|
216
|
+
depositTotal = _result.depositTotal;
|
|
217
|
+
protocolIds.push.apply(protocolIds, _toConsumableArray(getDepositPolicyIds({
|
|
218
|
+
self_deposit_policy_ids: variantDepositData === null || variantDepositData === void 0 ? void 0 : variantDepositData.self_deposit_policy_ids
|
|
219
|
+
})));
|
|
220
|
+
hasDeposit = true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (Array.isArray(product.product_bundle) && product.product_bundle.length) {
|
|
224
|
+
depositTotal = product.product_bundle.reduce(function (accumulator, bundleProduct) {
|
|
225
|
+
var bundleDepositData = bundleProduct === null || bundleProduct === void 0 ? void 0 : bundleProduct.custom_deposit_data;
|
|
226
|
+
var result = handleOrderProductDeposit({
|
|
227
|
+
depositData: bundleDepositData,
|
|
228
|
+
total: bundleProduct === null || bundleProduct === void 0 ? void 0 : bundleProduct.price,
|
|
229
|
+
num: getSafeOrderProductNum((bundleProduct === null || bundleProduct === void 0 ? void 0 : bundleProduct.num) || 1)
|
|
230
|
+
});
|
|
231
|
+
if (!result.result) return accumulator;
|
|
232
|
+
protocolIds.push.apply(protocolIds, _toConsumableArray(getDepositPolicyIds({
|
|
233
|
+
self_deposit_policy_ids: bundleDepositData === null || bundleDepositData === void 0 ? void 0 : bundleDepositData.self_deposit_policy_ids
|
|
234
|
+
})));
|
|
235
|
+
hasDeposit = true;
|
|
236
|
+
return accumulator.plus(result.depositTotal);
|
|
237
|
+
}, new Decimal(0));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (!hasDeposit) return null;
|
|
241
|
+
var protocolIdSet = new Set(protocolIds);
|
|
242
|
+
var protocols = allProtocols.filter(function (protocol) {
|
|
243
|
+
return protocolIdSet.has(protocol.id);
|
|
244
|
+
});
|
|
245
|
+
return {
|
|
246
|
+
total: depositTotal.toNumber(),
|
|
247
|
+
protocols: protocols
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* 仅基于 tempOrder.products 重算整单定金。
|
|
253
|
+
*
|
|
254
|
+
* 对齐 Checkout relation_products 分支:商品定金先按商品规则计算,
|
|
255
|
+
* 再扣减商品券/折扣卡抵扣金额;tempOrder.bookings 不参与这里的计算。
|
|
256
|
+
*/
|
|
257
|
+
export function calculateOrderProductsDeposit() {
|
|
258
|
+
var products = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
259
|
+
var options = arguments.length > 1 ? arguments[1] : undefined;
|
|
260
|
+
var protocolMap = new Map();
|
|
261
|
+
var total = new Decimal(0);
|
|
262
|
+
var hasDeposit = false;
|
|
263
|
+
var _iterator3 = _createForOfIteratorHelper(products || []),
|
|
264
|
+
_step3;
|
|
265
|
+
try {
|
|
266
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
267
|
+
var _product$metadata, _options$productsByUi;
|
|
268
|
+
var product = _step3.value;
|
|
269
|
+
var productUid = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number;
|
|
270
|
+
var runtimeOrigin = productUid ? options === null || options === void 0 || (_options$productsByUi = options.productsByUid) === null || _options$productsByUi === void 0 || (_options$productsByUi = _options$productsByUi[productUid]) === null || _options$productsByUi === void 0 ? void 0 : _options$productsByUi.origin : undefined;
|
|
271
|
+
var deposit = getOrderProductDeposit(product, runtimeOrigin);
|
|
272
|
+
product.deposit = deposit;
|
|
273
|
+
if (!(deposit !== null && deposit !== void 0 && deposit.total) || Number(deposit.total) <= 0) continue;
|
|
274
|
+
total = total.plus(deposit.total);
|
|
275
|
+
var _iterator4 = _createForOfIteratorHelper(product.discount_list || []),
|
|
276
|
+
_step4;
|
|
277
|
+
try {
|
|
278
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
279
|
+
var discount = _step4.value;
|
|
280
|
+
total = total.minus((discount === null || discount === void 0 ? void 0 : discount.amount) || 0);
|
|
281
|
+
}
|
|
282
|
+
} catch (err) {
|
|
283
|
+
_iterator4.e(err);
|
|
284
|
+
} finally {
|
|
285
|
+
_iterator4.f();
|
|
286
|
+
}
|
|
287
|
+
var _iterator5 = _createForOfIteratorHelper(deposit.protocols || []),
|
|
288
|
+
_step5;
|
|
289
|
+
try {
|
|
290
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
291
|
+
var protocol = _step5.value;
|
|
292
|
+
if (!protocolMap.has(protocol.id)) protocolMap.set(protocol.id, protocol);
|
|
293
|
+
}
|
|
294
|
+
} catch (err) {
|
|
295
|
+
_iterator5.e(err);
|
|
296
|
+
} finally {
|
|
297
|
+
_iterator5.f();
|
|
298
|
+
}
|
|
299
|
+
hasDeposit = true;
|
|
300
|
+
}
|
|
301
|
+
} catch (err) {
|
|
302
|
+
_iterator3.e(err);
|
|
303
|
+
} finally {
|
|
304
|
+
_iterator3.f();
|
|
305
|
+
}
|
|
306
|
+
var roundedTotal = total.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
|
|
307
|
+
var protocols = _toConsumableArray(protocolMap.values());
|
|
308
|
+
return {
|
|
309
|
+
total: roundedTotal.toNumber(),
|
|
310
|
+
totalText: roundedTotal.toFixed(2),
|
|
311
|
+
protocols: protocols,
|
|
312
|
+
deposit_policy_ids: protocols.map(function (protocol) {
|
|
313
|
+
return protocol.id;
|
|
314
|
+
}),
|
|
315
|
+
hasDeposit: hasDeposit
|
|
316
|
+
};
|
|
317
|
+
}
|
|
110
318
|
|
|
111
319
|
/**
|
|
112
320
|
* 判定套餐子商品是否为 markdown(减价)类型。
|
|
@@ -129,12 +337,12 @@ export function isMarkdownBundle(bundle) {
|
|
|
129
337
|
* - markup(加价)/原价子商品:维持 `+(bundle_selling_price ?? price)`,行为不变。
|
|
130
338
|
*/
|
|
131
339
|
export function getBundleSignedUnit(bundle, options) {
|
|
132
|
-
var _options$useOriginal,
|
|
340
|
+
var _options$useOriginal, _ref11, _bundle$original_pric2, _bundle$bundle_sellin;
|
|
133
341
|
if (!bundle || _typeof(bundle) !== 'object') return new Decimal(0);
|
|
134
342
|
var useOriginal = (_options$useOriginal = options === null || options === void 0 ? void 0 : options.useOriginal) !== null && _options$useOriginal !== void 0 ? _options$useOriginal : false;
|
|
135
343
|
if (isMarkdownBundle(bundle)) {
|
|
136
|
-
var
|
|
137
|
-
var catalog = useOriginal ? (
|
|
344
|
+
var _ref5, _ref6, _ref7, _bundle$original_pric, _ref8, _ref9, _ref10, _bundle$custom_price;
|
|
345
|
+
var catalog = useOriginal ? (_ref5 = (_ref6 = (_ref7 = (_bundle$original_pric = bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle.product_price) !== null && _ref7 !== void 0 ? _ref7 : bundle.custom_price) !== null && _ref6 !== void 0 ? _ref6 : bundle.base_price) !== null && _ref5 !== void 0 ? _ref5 : bundle.price : (_ref8 = (_ref9 = (_ref10 = (_bundle$custom_price = bundle.custom_price) !== null && _bundle$custom_price !== void 0 ? _bundle$custom_price : bundle.product_price) !== null && _ref10 !== void 0 ? _ref10 : bundle.original_price) !== null && _ref9 !== void 0 ? _ref9 : bundle.base_price) !== null && _ref8 !== void 0 ? _ref8 : bundle.price;
|
|
138
346
|
if (catalog !== undefined && catalog !== null && catalog !== '') {
|
|
139
347
|
var raw = new Decimal(Number(catalog) || 0);
|
|
140
348
|
// 负值表示价格已是「带符号净额」(如 cart/changePrice 产出的 -3.7),直接取用不再扣 option,
|
|
@@ -145,7 +353,7 @@ export function getBundleSignedUnit(bundle, options) {
|
|
|
145
353
|
// 仅剩净额(无毛价)兜底:直接取负,不再扣 option
|
|
146
354
|
return new Decimal(Number(bundle.bundle_selling_price) || 0).abs().negated();
|
|
147
355
|
}
|
|
148
|
-
var rawPrice = useOriginal ? (
|
|
356
|
+
var rawPrice = useOriginal ? (_ref11 = (_bundle$original_pric2 = bundle.original_price) !== null && _bundle$original_pric2 !== void 0 ? _bundle$original_pric2 : bundle.product_price) !== null && _ref11 !== void 0 ? _ref11 : bundle.price : (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.price;
|
|
149
357
|
return new Decimal(Number(rawPrice) || 0);
|
|
150
358
|
}
|
|
151
359
|
|
|
@@ -314,8 +522,8 @@ export function createDefaultOrderRulesHooks() {
|
|
|
314
522
|
return new Decimal(Number(totalLike) || 0).dividedBy(effectiveNum).toDecimalPlaces(2).toString();
|
|
315
523
|
};
|
|
316
524
|
var getBundleIdentity = function getBundleIdentity(bundle) {
|
|
317
|
-
var
|
|
318
|
-
return [(
|
|
525
|
+
var _ref12, _bundle$bundle_id, _ref13, _ref14, _bundle$bundle_produc, _ref15, _ref16, _bundle$bundle_varian, _ref17, _bundle$bundle_group_;
|
|
526
|
+
return [(_ref12 = (_bundle$bundle_id = bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle.id) !== null && _ref12 !== void 0 ? _ref12 : '', (_ref13 = (_ref14 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref14 !== void 0 ? _ref14 : bundle.product_id) !== null && _ref13 !== void 0 ? _ref13 : '', (_ref15 = (_ref16 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref16 !== void 0 ? _ref16 : bundle.product_variant_id) !== null && _ref15 !== void 0 ? _ref15 : 0, (_ref17 = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id) !== null && _ref17 !== void 0 ? _ref17 : ''].join('|');
|
|
319
527
|
};
|
|
320
528
|
var mergeRulesBundlePrices = function mergeRulesBundlePrices(currentBundle, rulesBundle) {
|
|
321
529
|
if (!Array.isArray(rulesBundle)) return rulesBundle;
|
|
@@ -325,14 +533,14 @@ export function createDefaultOrderRulesHooks() {
|
|
|
325
533
|
currentByIdentity.set(getBundleIdentity(bundle), bundle);
|
|
326
534
|
});
|
|
327
535
|
return rulesBundle.map(function (bundle) {
|
|
328
|
-
var _bundle$price_type_ex2,
|
|
536
|
+
var _bundle$price_type_ex2, _ref18, _ref19, _current$price, _ref20, _ref21, _ref22, _current$original_pri;
|
|
329
537
|
if (!bundle || _typeof(bundle) !== 'object') return bundle;
|
|
330
538
|
var current = currentByIdentity.get(getBundleIdentity(bundle));
|
|
331
539
|
if (!current) return bundle;
|
|
332
540
|
var isProductPriceBundle = ((_bundle$price_type_ex2 = bundle.price_type_ext) !== null && _bundle$price_type_ex2 !== void 0 ? _bundle$price_type_ex2 : current.price_type_ext) === 'product_price';
|
|
333
541
|
if (!isProductPriceBundle) return bundle;
|
|
334
|
-
var sourcePrice = (
|
|
335
|
-
var originalPrice = (
|
|
542
|
+
var sourcePrice = (_ref18 = (_ref19 = (_current$price = current.price) !== null && _current$price !== void 0 ? _current$price : current.custom_price) !== null && _ref19 !== void 0 ? _ref19 : current.original_price) !== null && _ref18 !== void 0 ? _ref18 : current.bundle_selling_price;
|
|
543
|
+
var originalPrice = (_ref20 = (_ref21 = (_ref22 = (_current$original_pri = current.original_price) !== null && _current$original_pri !== void 0 ? _current$original_pri : current.product_price) !== null && _ref22 !== void 0 ? _ref22 : current.price) !== null && _ref21 !== void 0 ? _ref21 : current.custom_price) !== null && _ref20 !== void 0 ? _ref20 : sourcePrice;
|
|
336
544
|
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, bundle), sourcePrice !== undefined ? {
|
|
337
545
|
price: sourcePrice
|
|
338
546
|
} : {}), originalPrice !== undefined ? {
|
|
@@ -344,7 +552,7 @@ export function createDefaultOrderRulesHooks() {
|
|
|
344
552
|
};
|
|
345
553
|
return {
|
|
346
554
|
getProduct: function getProduct(product) {
|
|
347
|
-
var _product$
|
|
555
|
+
var _product$metadata2, _product$metadata3, _product$metadata4, _product$metadata5, _product$metadata6, _metadataAny$_promoti;
|
|
348
556
|
// source_product_price 是权威源;兜底链:source → mainSelling − options(反推)→ 行 selling_price
|
|
349
557
|
var metadataAny = product.metadata || {};
|
|
350
558
|
var optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
|
|
@@ -371,7 +579,7 @@ export function createDefaultOrderRulesHooks() {
|
|
|
371
579
|
// 否则同 SKU 不同小料会在 calcDiscount 重组时互相覆盖。
|
|
372
580
|
// 不透明 identity 契约下,normalizeOrderProduct / hydrate 已保证唯一值存在;
|
|
373
581
|
// 留 fingerprint 分支仅作 Rules 单测里直接传裸 product 时的兜底。
|
|
374
|
-
_id: (_product$
|
|
582
|
+
_id: (_product$metadata2 = product.metadata) !== null && _product$metadata2 !== void 0 && _product$metadata2.unique_identification_number ? "".concat(product.product_id, "_").concat(product.product_variant_id, "_").concat(product.metadata.unique_identification_number) : "".concat(product.product_id, "_").concat(product.product_variant_id, "_").concat(buildProductLineFingerprint(getProductSkuOptions(product), product.product_bundle)),
|
|
375
583
|
// Rules 内部 getProductTotalPrice / getProductOriginTotalPrice 会各自再叠加 bundle + option,
|
|
376
584
|
// 所以这里必须喂 source-level(不含 option、不含 bundle、不含折扣)单价,避免双加 option。
|
|
377
585
|
price: sourcePrice,
|
|
@@ -383,23 +591,23 @@ export function createDefaultOrderRulesHooks() {
|
|
|
383
591
|
num: product.num || 1,
|
|
384
592
|
discount_list: product.discount_list || [],
|
|
385
593
|
bundle: product.product_bundle || [],
|
|
386
|
-
booking_id: ((_product$
|
|
594
|
+
booking_id: ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.booking_id) || null,
|
|
387
595
|
isClient: false,
|
|
388
596
|
// 勿写死 false:否则 Rules 不会走 total≠origin_total 的手动价推断,
|
|
389
597
|
// 无券时会把 bundle 价还原成 original_price(手动改价套餐会从 20 回到 30)。
|
|
390
598
|
isManualDiscount: resolveRulesManualDiscountFlag(metadataAny),
|
|
391
|
-
holder_id: (_product$
|
|
392
|
-
startDate: ((_product$
|
|
599
|
+
holder_id: (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.holder_id,
|
|
600
|
+
startDate: ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.start_date) || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.startDate),
|
|
393
601
|
main_product_selling_price: metadataAny.main_product_selling_price !== undefined ? new Decimal(Number(metadataAny.main_product_selling_price) || 0).minus(optionSum).toDecimalPlaces(2).toString() : undefined,
|
|
394
602
|
inPromotion: ((_metadataAny$_promoti = metadataAny._promotion) === null || _metadataAny$_promoti === void 0 ? void 0 : _metadataAny$_promoti.inPromotion) === true,
|
|
395
603
|
_promotion: metadataAny._promotion
|
|
396
604
|
};
|
|
397
605
|
},
|
|
398
606
|
setProduct: function setProduct(product, values) {
|
|
399
|
-
var
|
|
400
|
-
var nextNum = Number((
|
|
607
|
+
var _ref23, _values$quantity, _ref24, _metadataAny$source_p, _values$discount_list, _values$quantity2;
|
|
608
|
+
var nextNum = Number((_ref23 = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref23 !== void 0 ? _ref23 : 1) || 1;
|
|
401
609
|
var metadataAny = product.metadata || {};
|
|
402
|
-
var existedSource = (
|
|
610
|
+
var existedSource = (_ref24 = (_metadataAny$source_p = metadataAny.source_product_price) !== null && _metadataAny$source_p !== void 0 ? _metadataAny$source_p : product.selling_price) !== null && _ref24 !== void 0 ? _ref24 : '0';
|
|
403
611
|
var nextOptions = getProductSkuOptions(product);
|
|
404
612
|
var optionSum = sumOptionUnitPrice(nextOptions);
|
|
405
613
|
|
|
@@ -572,7 +780,7 @@ function toMoneyString(value) {
|
|
|
572
780
|
function formatSubmitBundleItems(bundle) {
|
|
573
781
|
if (!Array.isArray(bundle)) return [];
|
|
574
782
|
return bundle.map(function (b) {
|
|
575
|
-
var
|
|
783
|
+
var _ref25, _rawBundle$price, _rawBundle$surcharge_, _rawBundle$num, _rawBundle$is_charge_, _rawBundle$bundle_var, _rawBundle$quantity, _rawBundle$extension_, _rawBundle$extension_2, _ref26, _rawBundle$price_type, _ref27, _rawBundle$price_type2, _rawBundle$bundle_gro, _rawBundle$bundle_id, _rawBundle$bundle_pro;
|
|
576
784
|
var rawBundle = b && _typeof(b) === 'object' ? b : {};
|
|
577
785
|
var existedMetadata = rawBundle.metadata && _typeof(rawBundle.metadata) === 'object' ? rawBundle.metadata : {};
|
|
578
786
|
|
|
@@ -581,7 +789,7 @@ function formatSubmitBundleItems(bundle) {
|
|
|
581
789
|
var sellingPrice = getBundleSellingMagnitude(rawBundle).toFixed(2);
|
|
582
790
|
// payment 价由整单折扣均摊层产出;缺省(无折扣)时与 selling 净额同义。
|
|
583
791
|
var paymentPrice = rawBundle.bundle_payment_price !== undefined && rawBundle.bundle_payment_price !== null && rawBundle.bundle_payment_price !== '' ? toMoneyString(rawBundle.bundle_payment_price) : sellingPrice;
|
|
584
|
-
var priceValue = (
|
|
792
|
+
var priceValue = (_ref25 = (_rawBundle$price = rawBundle.price) !== null && _rawBundle$price !== void 0 ? _rawBundle$price : rawBundle.custom_price) !== null && _ref25 !== void 0 ? _ref25 : rawBundle.bundle_selling_price;
|
|
585
793
|
var relationSurchargeIds = Array.isArray(rawBundle.relation_surcharge_ids) ? rawBundle.relation_surcharge_ids : Array.isArray(existedMetadata.relation_surcharge_ids) ? existedMetadata.relation_surcharge_ids : [];
|
|
586
794
|
var surchargeFee = toMoneyString((_rawBundle$surcharge_ = rawBundle.surcharge_fee) !== null && _rawBundle$surcharge_ !== void 0 ? _rawBundle$surcharge_ : existedMetadata.surcharge_fee);
|
|
587
795
|
var productDiscountDifference = toBundleNumber(existedMetadata.product_discount_difference, 0);
|
|
@@ -594,8 +802,8 @@ function formatSubmitBundleItems(bundle) {
|
|
|
594
802
|
extension_id: (_rawBundle$extension_ = rawBundle.extension_id) !== null && _rawBundle$extension_ !== void 0 ? _rawBundle$extension_ : 0,
|
|
595
803
|
extension_type: (_rawBundle$extension_2 = rawBundle.extension_type) !== null && _rawBundle$extension_2 !== void 0 ? _rawBundle$extension_2 : 'normal',
|
|
596
804
|
price: priceValue,
|
|
597
|
-
price_type: (
|
|
598
|
-
price_type_ext: (
|
|
805
|
+
price_type: (_ref26 = (_rawBundle$price_type = rawBundle.price_type) !== null && _rawBundle$price_type !== void 0 ? _rawBundle$price_type : rawBundle.custom_price_type) !== null && _ref26 !== void 0 ? _ref26 : '',
|
|
806
|
+
price_type_ext: (_ref27 = (_rawBundle$price_type2 = rawBundle.price_type_ext) !== null && _rawBundle$price_type2 !== void 0 ? _rawBundle$price_type2 : rawBundle.custom_price_type_ext) !== null && _ref27 !== void 0 ? _ref27 : '',
|
|
599
807
|
bundle_selling_price: sellingPrice,
|
|
600
808
|
bundle_payment_price: paymentPrice,
|
|
601
809
|
option: formatSubmitOptionItems(rawBundle.option),
|
|
@@ -629,9 +837,9 @@ function formatSubmitBundleItems(bundle) {
|
|
|
629
837
|
*/
|
|
630
838
|
function normalizeSubmitProduct(product) {
|
|
631
839
|
var _rawMetadata$product_, _submitProduct$produc, _submitProduct$paymen;
|
|
632
|
-
var
|
|
633
|
-
_runtimeUid =
|
|
634
|
-
submitProduct = _objectWithoutProperties(
|
|
840
|
+
var _ref28 = product,
|
|
841
|
+
_runtimeUid = _ref28.unique_identification_number,
|
|
842
|
+
submitProduct = _objectWithoutProperties(_ref28, _excluded);
|
|
635
843
|
var num = submitProduct.num,
|
|
636
844
|
_productSurchargeFee = submitProduct.surcharge_fee,
|
|
637
845
|
_deprecatedDiscountAmount = submitProduct.discount_amount,
|
|
@@ -691,19 +899,19 @@ export function normalizeBookingSubType(booking) {
|
|
|
691
899
|
export function normalizeSubmitBooking(booking) {
|
|
692
900
|
var rawMetadata = booking.metadata || {};
|
|
693
901
|
var cleanMetadata = {};
|
|
694
|
-
var
|
|
695
|
-
|
|
902
|
+
var _iterator6 = _createForOfIteratorHelper(SUBMIT_BOOKING_METADATA_WHITELIST),
|
|
903
|
+
_step6;
|
|
696
904
|
try {
|
|
697
|
-
for (
|
|
698
|
-
var key =
|
|
905
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
906
|
+
var key = _step6.value;
|
|
699
907
|
if (rawMetadata[key] !== undefined) {
|
|
700
908
|
cleanMetadata[key] = rawMetadata[key];
|
|
701
909
|
}
|
|
702
910
|
}
|
|
703
911
|
} catch (err) {
|
|
704
|
-
|
|
912
|
+
_iterator6.e(err);
|
|
705
913
|
} finally {
|
|
706
|
-
|
|
914
|
+
_iterator6.f();
|
|
707
915
|
}
|
|
708
916
|
if (cleanMetadata.holder_id === undefined) cleanMetadata.holder_id = null;
|
|
709
917
|
var bookingRecord = booking;
|
|
@@ -795,7 +1003,7 @@ export function createDefaultTempOrder(params) {
|
|
|
795
1003
|
};
|
|
796
1004
|
}
|
|
797
1005
|
export function buildSubmitPayload(params) {
|
|
798
|
-
var _tempOrder$customer_i, _tempOrder$order_numb, _tempOrder$shop_order, _tempOrder$shop_full_,
|
|
1006
|
+
var _tempOrder$customer_i, _tempOrder$order_numb, _tempOrder$shop_order, _tempOrder$shop_full_, _ref30, _tempOrder$is_price_i, _tempOrder$is_deposit, _enhancedPayload$summ;
|
|
799
1007
|
var tempOrder = params.tempOrder,
|
|
800
1008
|
cacheId = params.cacheId,
|
|
801
1009
|
_params$now = params.now,
|
|
@@ -808,26 +1016,26 @@ export function buildSubmitPayload(params) {
|
|
|
808
1016
|
enhance = params.enhance;
|
|
809
1017
|
var scheduleDate = tempOrder.schedule_date || tempOrder.created_at || formatDateTime(now);
|
|
810
1018
|
var bookingUuid = createUuidV4();
|
|
811
|
-
var
|
|
812
|
-
_extend =
|
|
813
|
-
_relationId =
|
|
814
|
-
_tableFormId =
|
|
815
|
-
_resourceId =
|
|
816
|
-
_summary =
|
|
817
|
-
_lastOrderInfo =
|
|
818
|
-
_paidAmount =
|
|
819
|
-
_shopId =
|
|
820
|
-
_shopNote =
|
|
821
|
-
_shopServiceType =
|
|
822
|
-
_startTime =
|
|
823
|
-
_customer =
|
|
824
|
-
_discountList =
|
|
825
|
-
_rootTaxFee =
|
|
826
|
-
_totalAmount =
|
|
827
|
-
_totalRefundAmount =
|
|
828
|
-
_createDate =
|
|
829
|
-
_holderId =
|
|
830
|
-
tempOrderRest = _objectWithoutProperties(
|
|
1019
|
+
var _ref29 = tempOrder,
|
|
1020
|
+
_extend = _ref29._extend,
|
|
1021
|
+
_relationId = _ref29.relation_id,
|
|
1022
|
+
_tableFormId = _ref29.table_form_id,
|
|
1023
|
+
_resourceId = _ref29.resource_id,
|
|
1024
|
+
_summary = _ref29.summary,
|
|
1025
|
+
_lastOrderInfo = _ref29.lastOrderInfo,
|
|
1026
|
+
_paidAmount = _ref29.paid_amount,
|
|
1027
|
+
_shopId = _ref29.shop_id,
|
|
1028
|
+
_shopNote = _ref29.shop_note,
|
|
1029
|
+
_shopServiceType = _ref29.shop_service_type,
|
|
1030
|
+
_startTime = _ref29.start_time,
|
|
1031
|
+
_customer = _ref29.customer,
|
|
1032
|
+
_discountList = _ref29.discount_list,
|
|
1033
|
+
_rootTaxFee = _ref29.tax_fee,
|
|
1034
|
+
_totalAmount = _ref29.total_amount,
|
|
1035
|
+
_totalRefundAmount = _ref29.total_refund_amount,
|
|
1036
|
+
_createDate = _ref29.create_date,
|
|
1037
|
+
_holderId = _ref29.holder_id,
|
|
1038
|
+
tempOrderRest = _objectWithoutProperties(_ref29, _excluded3);
|
|
831
1039
|
var submitType = type !== null && type !== void 0 ? type : tempOrder.type;
|
|
832
1040
|
if (!submitType) {
|
|
833
1041
|
var _tempOrder$bookings;
|
|
@@ -849,7 +1057,7 @@ export function buildSubmitPayload(params) {
|
|
|
849
1057
|
type: submitType,
|
|
850
1058
|
business_code: businessCode !== null && businessCode !== void 0 ? businessCode : tempOrder.business_code,
|
|
851
1059
|
sales_channel: tempOrder.sales_channel || 'my_pisel',
|
|
852
|
-
order_sales_channel: (
|
|
1060
|
+
order_sales_channel: (_ref30 = channel !== null && channel !== void 0 ? channel : tempOrder.order_sales_channel) !== null && _ref30 !== void 0 ? _ref30 : 'online_store',
|
|
853
1061
|
status: tempOrder.status || 'normal',
|
|
854
1062
|
payment_status: tempOrder.payment_status || 'payment_processing',
|
|
855
1063
|
// shipping_status: tempOrder.shipping_status || 'unfulfilled',
|
|
@@ -875,10 +1083,10 @@ export function buildSubmitPayload(params) {
|
|
|
875
1083
|
// holder: tempOrder.holder || null,
|
|
876
1084
|
summary: summary || tempOrder.summary || createEmptySummary(),
|
|
877
1085
|
metadata: function () {
|
|
878
|
-
var
|
|
879
|
-
_collectPax =
|
|
880
|
-
_tableOccupancyDuration =
|
|
881
|
-
rest = _objectWithoutProperties(
|
|
1086
|
+
var _ref31 = tempOrder.metadata || {},
|
|
1087
|
+
_collectPax = _ref31.collect_pax,
|
|
1088
|
+
_tableOccupancyDuration = _ref31.table_occupancy_duration,
|
|
1089
|
+
rest = _objectWithoutProperties(_ref31, _excluded4);
|
|
882
1090
|
return _objectSpread({}, rest);
|
|
883
1091
|
}(),
|
|
884
1092
|
products: (tempOrder.products || []).map(function (product) {
|
|
@@ -1013,25 +1221,25 @@ export function clearTempOrderHolderAssignments(tempOrder) {
|
|
|
1013
1221
|
target[key] = null;
|
|
1014
1222
|
changed = true;
|
|
1015
1223
|
};
|
|
1016
|
-
var
|
|
1017
|
-
|
|
1224
|
+
var _iterator7 = _createForOfIteratorHelper(tempOrder.products || []),
|
|
1225
|
+
_step7;
|
|
1018
1226
|
try {
|
|
1019
|
-
for (
|
|
1020
|
-
var product =
|
|
1227
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1228
|
+
var product = _step7.value;
|
|
1021
1229
|
if (product.metadata && _typeof(product.metadata) === 'object') {
|
|
1022
1230
|
resetHolderField(product.metadata);
|
|
1023
1231
|
}
|
|
1024
1232
|
}
|
|
1025
1233
|
} catch (err) {
|
|
1026
|
-
|
|
1234
|
+
_iterator7.e(err);
|
|
1027
1235
|
} finally {
|
|
1028
|
-
|
|
1236
|
+
_iterator7.f();
|
|
1029
1237
|
}
|
|
1030
|
-
var
|
|
1031
|
-
|
|
1238
|
+
var _iterator8 = _createForOfIteratorHelper(tempOrder.bookings || []),
|
|
1239
|
+
_step8;
|
|
1032
1240
|
try {
|
|
1033
|
-
for (
|
|
1034
|
-
var booking =
|
|
1241
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1242
|
+
var booking = _step8.value;
|
|
1035
1243
|
var bookingRecord = booking;
|
|
1036
1244
|
if (booking.metadata && _typeof(booking.metadata) === 'object') {
|
|
1037
1245
|
resetHolderField(booking.metadata);
|
|
@@ -1042,9 +1250,9 @@ export function clearTempOrderHolderAssignments(tempOrder) {
|
|
|
1042
1250
|
}
|
|
1043
1251
|
}
|
|
1044
1252
|
} catch (err) {
|
|
1045
|
-
|
|
1253
|
+
_iterator8.e(err);
|
|
1046
1254
|
} finally {
|
|
1047
|
-
|
|
1255
|
+
_iterator8.f();
|
|
1048
1256
|
}
|
|
1049
1257
|
var productsByUid = (_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.productsByUid;
|
|
1050
1258
|
if (productsByUid && _typeof(productsByUid) === 'object') {
|
|
@@ -1070,9 +1278,9 @@ export function clearTempOrderHolderAssignments(tempOrder) {
|
|
|
1070
1278
|
* getOrderProductLineUid({ metadata: { unique_identification_number: 'line-1' } }); // 'line-1'
|
|
1071
1279
|
*/
|
|
1072
1280
|
export function getOrderProductLineUid(product) {
|
|
1073
|
-
var _product$metadata$uni, _product$
|
|
1281
|
+
var _product$metadata$uni, _product$metadata7;
|
|
1074
1282
|
if (!product || _typeof(product) !== 'object') return null;
|
|
1075
|
-
var uid = (_product$metadata$uni = (_product$
|
|
1283
|
+
var uid = (_product$metadata$uni = (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number) !== null && _product$metadata$uni !== void 0 ? _product$metadata$uni : product.unique_identification_number;
|
|
1076
1284
|
if (uid === undefined || uid === null || uid === '') return null;
|
|
1077
1285
|
return String(uid);
|
|
1078
1286
|
}
|
|
@@ -1944,7 +1944,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1944
1944
|
var secondary = preferred === existing ? incoming : existing;
|
|
1945
1945
|
var merged = _objectSpread(_objectSpread({}, secondary), preferred);
|
|
1946
1946
|
var fieldsToPreserve = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number'];
|
|
1947
|
-
var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'summary', 'payments', 'products', 'bookings'];
|
|
1947
|
+
var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'payments', 'products', 'bookings'];
|
|
1948
1948
|
var mergedRecord = merged;
|
|
1949
1949
|
var preferredRecord = preferred;
|
|
1950
1950
|
var secondaryRecord = secondary;
|
|
@@ -61,6 +61,8 @@ export declare class ResourceModule extends BaseModule implements Module {
|
|
|
61
61
|
*/
|
|
62
62
|
clear(): Promise<void>;
|
|
63
63
|
private attachBookingsToResource;
|
|
64
|
+
private normalizeIntegerIdValue;
|
|
65
|
+
private normalizeResourceIdFields;
|
|
64
66
|
private normalizeResource;
|
|
65
67
|
private safeEmit;
|
|
66
68
|
private syncResourcesMap;
|
|
@@ -428,15 +428,41 @@ export var ResourceModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
428
428
|
bookings: this.getBookingsByResourceId(resource.id)
|
|
429
429
|
});
|
|
430
430
|
}
|
|
431
|
+
}, {
|
|
432
|
+
key: "normalizeIntegerIdValue",
|
|
433
|
+
value: function normalizeIntegerIdValue(value) {
|
|
434
|
+
if (typeof value !== 'string') return value;
|
|
435
|
+
var matched = value.match(/^(-?\d+)\.0+$/);
|
|
436
|
+
if (!matched) return value;
|
|
437
|
+
return matched[1];
|
|
438
|
+
}
|
|
439
|
+
}, {
|
|
440
|
+
key: "normalizeResourceIdFields",
|
|
441
|
+
value: function normalizeResourceIdFields(resource) {
|
|
442
|
+
resource.id = this.normalizeIntegerIdValue(resource.id);
|
|
443
|
+
if (resource.form_record_id !== undefined) {
|
|
444
|
+
resource.form_record_id = this.normalizeIntegerIdValue(resource.form_record_id);
|
|
445
|
+
}
|
|
446
|
+
if (resource.form_id !== undefined) {
|
|
447
|
+
resource.form_id = this.normalizeIntegerIdValue(resource.form_id);
|
|
448
|
+
}
|
|
449
|
+
if (resource.resource_form_id !== undefined) {
|
|
450
|
+
resource.resource_form_id = this.normalizeIntegerIdValue(resource.resource_form_id);
|
|
451
|
+
}
|
|
452
|
+
if (resource.resource_id !== undefined) {
|
|
453
|
+
resource.resource_id = this.normalizeIntegerIdValue(resource.resource_id);
|
|
454
|
+
}
|
|
455
|
+
return resource;
|
|
456
|
+
}
|
|
431
457
|
}, {
|
|
432
458
|
key: "normalizeResource",
|
|
433
459
|
value: function normalizeResource(resource) {
|
|
434
460
|
var _ref2,
|
|
435
461
|
_resource$id,
|
|
436
462
|
_this7 = this;
|
|
437
|
-
var normalized = _objectSpread(_objectSpread({}, resource), {}, {
|
|
438
|
-
id: (_ref2 = (_resource$id = resource === null || resource === void 0 ? void 0 : resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource === null || resource === void 0 ? void 0 : resource.form_record_id) !== null && _ref2 !== void 0 ? _ref2 : ''
|
|
439
|
-
});
|
|
463
|
+
var normalized = this.normalizeResourceIdFields(_objectSpread(_objectSpread({}, resource), {}, {
|
|
464
|
+
id: this.normalizeIntegerIdValue((_ref2 = (_resource$id = resource === null || resource === void 0 ? void 0 : resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource === null || resource === void 0 ? void 0 : resource.form_record_id) !== null && _ref2 !== void 0 ? _ref2 : '')
|
|
465
|
+
}));
|
|
440
466
|
if (normalized.form_record_id === undefined && normalized.id !== '') {
|
|
441
467
|
normalized.form_record_id = normalized.id;
|
|
442
468
|
}
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 | 1 | 2 | 3 |
|
|
314
|
+
weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -322,7 +322,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
322
322
|
* 获取当前的客户搜索条件
|
|
323
323
|
* @returns 当前搜索条件
|
|
324
324
|
*/
|
|
325
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
325
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
326
326
|
/**
|
|
327
327
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
328
328
|
* @returns 客户状态
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/model/strategy/adapter/promotion/index.ts
|
|
30
|
-
var promotion_exports = {};
|
|
31
|
-
__export(promotion_exports, {
|
|
32
|
-
BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
|
|
33
|
-
PromotionAdapter: () => import_adapter.PromotionAdapter,
|
|
34
|
-
PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
|
|
35
|
-
X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
|
|
36
|
-
default: () => import_adapter2.default
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(promotion_exports);
|
|
39
|
-
var import_evaluator = require("./evaluator");
|
|
40
|
-
var import_adapter = require("./adapter");
|
|
41
|
-
var import_adapter2 = __toESM(require("./adapter"));
|
|
42
|
-
var import_examples = require("./examples");
|
|
43
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
-
0 && (module.exports = {
|
|
45
|
-
BUY_X_GET_Y_FREE_STRATEGY,
|
|
46
|
-
PromotionAdapter,
|
|
47
|
-
PromotionEvaluator,
|
|
48
|
-
X_ITEMS_FOR_Y_PRICE_STRATEGY
|
|
49
|
-
});
|
|
@@ -234,6 +234,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
234
234
|
private findBookingIndexByUniqueIdentificationNumber;
|
|
235
235
|
private removeLinkedBookingsForProduct;
|
|
236
236
|
private getSalesSummary;
|
|
237
|
+
private applyOrderProductsDepositSummary;
|
|
237
238
|
recalculateSummary(options?: {
|
|
238
239
|
createIfMissing?: boolean;
|
|
239
240
|
}): Promise<OrderSummary | null>;
|
|
@@ -1645,6 +1645,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1645
1645
|
return null;
|
|
1646
1646
|
return this.core.getModule(this.salesSummaryModuleName);
|
|
1647
1647
|
}
|
|
1648
|
+
applyOrderProductsDepositSummary(tempOrder, summary) {
|
|
1649
|
+
var _a;
|
|
1650
|
+
const depositSummary = (0, import_utils.calculateOrderProductsDeposit)(tempOrder.products || [], {
|
|
1651
|
+
productsByUid: (_a = tempOrder._extend) == null ? void 0 : _a.productsByUid
|
|
1652
|
+
});
|
|
1653
|
+
const nextSummary = {
|
|
1654
|
+
...summary,
|
|
1655
|
+
deposit_amount: depositSummary.totalText,
|
|
1656
|
+
deposit: depositSummary.hasDeposit ? {
|
|
1657
|
+
total: depositSummary.totalText,
|
|
1658
|
+
deposit_policy_ids: depositSummary.deposit_policy_ids,
|
|
1659
|
+
deposit_policy_data: depositSummary.protocols,
|
|
1660
|
+
hasDeposit: true
|
|
1661
|
+
} : void 0
|
|
1662
|
+
};
|
|
1663
|
+
tempOrder.deposit_amount = depositSummary.totalText;
|
|
1664
|
+
tempOrder.is_deposit = depositSummary.hasDeposit ? 1 : 0;
|
|
1665
|
+
return nextSummary;
|
|
1666
|
+
}
|
|
1648
1667
|
async recalculateSummary(options) {
|
|
1649
1668
|
const tempOrder = (options == null ? void 0 : options.createIfMissing) ? this.ensureTempOrder() : this.store.tempOrder;
|
|
1650
1669
|
if (!tempOrder)
|
|
@@ -1670,17 +1689,24 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1670
1689
|
...existedSummary,
|
|
1671
1690
|
total_refund_amount: totalRefundAmount
|
|
1672
1691
|
};
|
|
1673
|
-
const
|
|
1692
|
+
const emptySummaryBase = {
|
|
1674
1693
|
...emptyBaseSummary,
|
|
1675
1694
|
customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
|
|
1676
1695
|
order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
|
|
1696
|
+
pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2),
|
|
1697
|
+
rounding_amount: paidPaymentSummary.roundingAmount.toFixed(2)
|
|
1698
|
+
};
|
|
1699
|
+
const emptySummaryWithDeposit = this.applyOrderProductsDepositSummary(
|
|
1700
|
+
tempOrder,
|
|
1701
|
+
emptySummaryBase
|
|
1702
|
+
);
|
|
1703
|
+
const emptySummary = {
|
|
1704
|
+
...emptySummaryWithDeposit,
|
|
1677
1705
|
amount_gap: this.calculateSummaryAmountGap({
|
|
1678
1706
|
tempOrder,
|
|
1679
|
-
summary:
|
|
1707
|
+
summary: emptySummaryWithDeposit,
|
|
1680
1708
|
orderPaidAmount: paidPaymentSummary.gapPaidAmount
|
|
1681
|
-
})
|
|
1682
|
-
pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2),
|
|
1683
|
-
rounding_amount: paidPaymentSummary.roundingAmount.toFixed(2)
|
|
1709
|
+
})
|
|
1684
1710
|
};
|
|
1685
1711
|
tempOrder.surcharge_fee = emptySummary.surcharge_fee;
|
|
1686
1712
|
this.store.summary = emptySummary;
|
|
@@ -1713,14 +1739,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1713
1739
|
} : {}
|
|
1714
1740
|
} : {};
|
|
1715
1741
|
const normalizedExpectAmountPatch = expectAmount && salesSummaryResult.expect_amount === void 0 ? { expect_amount: expectAmount.toFixed(2) } : {};
|
|
1716
|
-
const summaryForGap = {
|
|
1742
|
+
const summaryForGap = this.applyOrderProductsDepositSummary(tempOrder, {
|
|
1717
1743
|
...salesSummaryResult,
|
|
1718
1744
|
total_refund_amount: totalRefundAmount,
|
|
1719
1745
|
...amountPaymentPatch,
|
|
1720
1746
|
...normalizedExpectAmountPatch
|
|
1721
|
-
};
|
|
1747
|
+
});
|
|
1722
1748
|
const summary = {
|
|
1723
|
-
...
|
|
1749
|
+
...summaryForGap,
|
|
1724
1750
|
total_refund_amount: totalRefundAmount,
|
|
1725
1751
|
customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
|
|
1726
1752
|
order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
|
|
@@ -1742,8 +1768,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1742
1768
|
}
|
|
1743
1769
|
tempOrder.surcharge_fee = summary.surcharge_fee;
|
|
1744
1770
|
tempOrder.surcharges = summary.surcharges || [];
|
|
1745
|
-
tempOrder.deposit_amount = summary.deposit_amount || "0.00";
|
|
1746
|
-
tempOrder.is_deposit = summary.deposit_amount !== "0.00" ? 1 : 0;
|
|
1747
1771
|
this.updateTempOrderPaymentStatus(tempOrder, {
|
|
1748
1772
|
previousSummary: existedSummary,
|
|
1749
1773
|
summary
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
import type { CartItem } from "../Cart";
|
|
3
|
-
import type { OrderProductDiscountItem, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder } from './types';
|
|
3
|
+
import type { OrderProductDiscountItem, OrderProduct, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder } from './types';
|
|
4
4
|
import type { RulesParamsHooks } from '../Rules/types';
|
|
5
5
|
import type { MapOrderPaymentsOptions, OrderPaymentData, OrderPaymentSource } from './types';
|
|
6
|
+
export interface OrderProductsDepositProtocol {
|
|
7
|
+
id: number;
|
|
8
|
+
title: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OrderProductsDepositSummary {
|
|
11
|
+
total: number;
|
|
12
|
+
totalText: string;
|
|
13
|
+
protocols: OrderProductsDepositProtocol[];
|
|
14
|
+
deposit_policy_ids: number[];
|
|
15
|
+
hasDeposit: boolean;
|
|
16
|
+
}
|
|
6
17
|
/**
|
|
7
18
|
* 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。
|
|
8
19
|
*
|
|
@@ -53,6 +64,15 @@ export declare function sumOptionUnitPrice(options?: Array<{
|
|
|
53
64
|
price?: any;
|
|
54
65
|
num?: any;
|
|
55
66
|
}> | null): Decimal;
|
|
67
|
+
/**
|
|
68
|
+
* 仅基于 tempOrder.products 重算整单定金。
|
|
69
|
+
*
|
|
70
|
+
* 对齐 Checkout relation_products 分支:商品定金先按商品规则计算,
|
|
71
|
+
* 再扣减商品券/折扣卡抵扣金额;tempOrder.bookings 不参与这里的计算。
|
|
72
|
+
*/
|
|
73
|
+
export declare function calculateOrderProductsDeposit(products?: OrderProduct[], options?: {
|
|
74
|
+
productsByUid?: Record<string, Record<string, any>>;
|
|
75
|
+
}): OrderProductsDepositSummary;
|
|
56
76
|
/**
|
|
57
77
|
* 判定套餐子商品是否为 markdown(减价)类型。
|
|
58
78
|
* 与后端口径一致:price_type='markdown' 且 price_type_ext 非 'product_price'(原价子商品)。
|
|
@@ -31,6 +31,7 @@ var utils_exports = {};
|
|
|
31
31
|
__export(utils_exports, {
|
|
32
32
|
buildManualProductDiscountItem: () => import_manualProductDiscount.buildManualProductDiscountItem,
|
|
33
33
|
buildSubmitPayload: () => buildSubmitPayload,
|
|
34
|
+
calculateOrderProductsDeposit: () => calculateOrderProductsDeposit,
|
|
34
35
|
clearTempOrderHolderAssignments: () => clearTempOrderHolderAssignments,
|
|
35
36
|
composeLinePrice: () => composeLinePrice,
|
|
36
37
|
createDefaultOrderRulesHooks: () => createDefaultOrderRulesHooks,
|
|
@@ -131,6 +132,175 @@ function sumOptionUnitPrice(options) {
|
|
|
131
132
|
}
|
|
132
133
|
return total;
|
|
133
134
|
}
|
|
135
|
+
function getSafeOrderProductNum(num) {
|
|
136
|
+
const parsedNum = Number(num ?? 1);
|
|
137
|
+
if (!Number.isFinite(parsedNum) || parsedNum < 1)
|
|
138
|
+
return 1;
|
|
139
|
+
return Math.floor(parsedNum);
|
|
140
|
+
}
|
|
141
|
+
function getOrderProductDepositUnitTotal(product) {
|
|
142
|
+
const metadata = product.metadata || {};
|
|
143
|
+
const paymentPrice = metadata.main_product_attached_bundle_payment_price;
|
|
144
|
+
const mainSellingPrice = metadata.main_product_selling_price;
|
|
145
|
+
const fallbackPrice = product.selling_price;
|
|
146
|
+
return new import_decimal.default(Number(paymentPrice ?? mainSellingPrice ?? fallbackPrice) || 0);
|
|
147
|
+
}
|
|
148
|
+
function normalizeDepositProtocols(protocols) {
|
|
149
|
+
if (!Array.isArray(protocols))
|
|
150
|
+
return [];
|
|
151
|
+
return protocols.reduce((result, protocol) => {
|
|
152
|
+
const id = Number(protocol == null ? void 0 : protocol.id);
|
|
153
|
+
if (!Number.isFinite(id))
|
|
154
|
+
return result;
|
|
155
|
+
result.push({
|
|
156
|
+
id: Math.floor(id),
|
|
157
|
+
title: String((protocol == null ? void 0 : protocol.title) || "")
|
|
158
|
+
});
|
|
159
|
+
return result;
|
|
160
|
+
}, []);
|
|
161
|
+
}
|
|
162
|
+
function getDepositPolicyIds(depositData) {
|
|
163
|
+
const ids = [
|
|
164
|
+
...Array.isArray(depositData == null ? void 0 : depositData.self_deposit_policy_ids) ? depositData.self_deposit_policy_ids : [],
|
|
165
|
+
...Array.isArray(depositData == null ? void 0 : depositData.deposit_policy_ids) ? depositData.deposit_policy_ids : []
|
|
166
|
+
];
|
|
167
|
+
return ids.reduce((result, id) => {
|
|
168
|
+
const normalizedId = Number(id);
|
|
169
|
+
if (!Number.isFinite(normalizedId))
|
|
170
|
+
return result;
|
|
171
|
+
result.push(Math.floor(normalizedId));
|
|
172
|
+
return result;
|
|
173
|
+
}, []);
|
|
174
|
+
}
|
|
175
|
+
function handleOrderProductDeposit(params) {
|
|
176
|
+
const { depositData, total, num } = params;
|
|
177
|
+
if (!depositData)
|
|
178
|
+
return { result: false, depositTotal: new import_decimal.default(0) };
|
|
179
|
+
const { deposit_fixed, deposit_percentage } = depositData;
|
|
180
|
+
if (typeof deposit_fixed !== "string" || typeof deposit_percentage !== "string") {
|
|
181
|
+
return { result: false, depositTotal: new import_decimal.default(0) };
|
|
182
|
+
}
|
|
183
|
+
const depositFixed = new import_decimal.default(deposit_fixed || 0);
|
|
184
|
+
const depositPercent = new import_decimal.default(deposit_percentage || 0);
|
|
185
|
+
const productTotalPrice = new import_decimal.default(total || 0);
|
|
186
|
+
const deposit = depositFixed.plus(depositPercent.times(productTotalPrice));
|
|
187
|
+
return { depositTotal: deposit.times(num), result: true };
|
|
188
|
+
}
|
|
189
|
+
function resolveOrderProductDepositSource(product, runtimeOrigin) {
|
|
190
|
+
const record = product;
|
|
191
|
+
const origin = record._origin || runtimeOrigin || {};
|
|
192
|
+
const originProduct = origin.product || {};
|
|
193
|
+
return {
|
|
194
|
+
...originProduct,
|
|
195
|
+
...origin,
|
|
196
|
+
...record,
|
|
197
|
+
custom_deposit_data: record.custom_deposit_data ?? origin.custom_deposit_data ?? originProduct.custom_deposit_data,
|
|
198
|
+
variant: record.variant ?? origin.variant ?? originProduct.variant
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function getOrderProductDeposit(product, runtimeOrigin) {
|
|
202
|
+
const depositProduct = resolveOrderProductDepositSource(product, runtimeOrigin);
|
|
203
|
+
const depositData = depositProduct.custom_deposit_data;
|
|
204
|
+
if ((depositData == null ? void 0 : depositData.has_deposit) != 1)
|
|
205
|
+
return null;
|
|
206
|
+
const num = getSafeOrderProductNum(product.num);
|
|
207
|
+
const total = getOrderProductDepositUnitTotal(product).times(num);
|
|
208
|
+
const allProtocols = normalizeDepositProtocols(depositData.deposit_policy_data);
|
|
209
|
+
const protocolIds = [];
|
|
210
|
+
let depositTotal = new import_decimal.default(0);
|
|
211
|
+
let hasDeposit = false;
|
|
212
|
+
if (typeof depositData.deposit_fixed === "string" && typeof depositData.deposit_percentage === "string") {
|
|
213
|
+
const result = handleOrderProductDeposit({
|
|
214
|
+
depositData,
|
|
215
|
+
total,
|
|
216
|
+
num
|
|
217
|
+
});
|
|
218
|
+
if (result.result) {
|
|
219
|
+
depositTotal = result.depositTotal;
|
|
220
|
+
protocolIds.push(...getDepositPolicyIds({
|
|
221
|
+
self_deposit_policy_ids: depositData.self_deposit_policy_ids
|
|
222
|
+
}));
|
|
223
|
+
hasDeposit = true;
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
const productVariantId = depositProduct.product_variant_id ?? product.product_variant_id;
|
|
227
|
+
if (productVariantId) {
|
|
228
|
+
const variantProduct = (depositProduct.variant || []).find(
|
|
229
|
+
(item) => (item == null ? void 0 : item.id) === productVariantId
|
|
230
|
+
);
|
|
231
|
+
const variantDepositData = variantProduct == null ? void 0 : variantProduct.custom_deposit_data;
|
|
232
|
+
const result = handleOrderProductDeposit({
|
|
233
|
+
depositData: variantDepositData,
|
|
234
|
+
total,
|
|
235
|
+
num
|
|
236
|
+
});
|
|
237
|
+
if (result.result) {
|
|
238
|
+
depositTotal = result.depositTotal;
|
|
239
|
+
protocolIds.push(...getDepositPolicyIds({
|
|
240
|
+
self_deposit_policy_ids: variantDepositData == null ? void 0 : variantDepositData.self_deposit_policy_ids
|
|
241
|
+
}));
|
|
242
|
+
hasDeposit = true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (Array.isArray(product.product_bundle) && product.product_bundle.length) {
|
|
246
|
+
depositTotal = product.product_bundle.reduce((accumulator, bundleProduct) => {
|
|
247
|
+
const bundleDepositData = bundleProduct == null ? void 0 : bundleProduct.custom_deposit_data;
|
|
248
|
+
const result = handleOrderProductDeposit({
|
|
249
|
+
depositData: bundleDepositData,
|
|
250
|
+
total: bundleProduct == null ? void 0 : bundleProduct.price,
|
|
251
|
+
num: getSafeOrderProductNum((bundleProduct == null ? void 0 : bundleProduct.num) || 1)
|
|
252
|
+
});
|
|
253
|
+
if (!result.result)
|
|
254
|
+
return accumulator;
|
|
255
|
+
protocolIds.push(...getDepositPolicyIds({
|
|
256
|
+
self_deposit_policy_ids: bundleDepositData == null ? void 0 : bundleDepositData.self_deposit_policy_ids
|
|
257
|
+
}));
|
|
258
|
+
hasDeposit = true;
|
|
259
|
+
return accumulator.plus(result.depositTotal);
|
|
260
|
+
}, new import_decimal.default(0));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (!hasDeposit)
|
|
264
|
+
return null;
|
|
265
|
+
const protocolIdSet = new Set(protocolIds);
|
|
266
|
+
const protocols = allProtocols.filter((protocol) => protocolIdSet.has(protocol.id));
|
|
267
|
+
return {
|
|
268
|
+
total: depositTotal.toNumber(),
|
|
269
|
+
protocols
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function calculateOrderProductsDeposit(products = [], options) {
|
|
273
|
+
var _a, _b, _c;
|
|
274
|
+
const protocolMap = /* @__PURE__ */ new Map();
|
|
275
|
+
let total = new import_decimal.default(0);
|
|
276
|
+
let hasDeposit = false;
|
|
277
|
+
for (const product of products || []) {
|
|
278
|
+
const productUid = (_a = product.metadata) == null ? void 0 : _a.unique_identification_number;
|
|
279
|
+
const runtimeOrigin = productUid ? (_c = (_b = options == null ? void 0 : options.productsByUid) == null ? void 0 : _b[productUid]) == null ? void 0 : _c.origin : void 0;
|
|
280
|
+
const deposit = getOrderProductDeposit(product, runtimeOrigin);
|
|
281
|
+
product.deposit = deposit;
|
|
282
|
+
if (!(deposit == null ? void 0 : deposit.total) || Number(deposit.total) <= 0)
|
|
283
|
+
continue;
|
|
284
|
+
total = total.plus(deposit.total);
|
|
285
|
+
for (const discount of product.discount_list || []) {
|
|
286
|
+
total = total.minus((discount == null ? void 0 : discount.amount) || 0);
|
|
287
|
+
}
|
|
288
|
+
for (const protocol of deposit.protocols || []) {
|
|
289
|
+
if (!protocolMap.has(protocol.id))
|
|
290
|
+
protocolMap.set(protocol.id, protocol);
|
|
291
|
+
}
|
|
292
|
+
hasDeposit = true;
|
|
293
|
+
}
|
|
294
|
+
const roundedTotal = total.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
|
|
295
|
+
const protocols = [...protocolMap.values()];
|
|
296
|
+
return {
|
|
297
|
+
total: roundedTotal.toNumber(),
|
|
298
|
+
totalText: roundedTotal.toFixed(2),
|
|
299
|
+
protocols,
|
|
300
|
+
deposit_policy_ids: protocols.map((protocol) => protocol.id),
|
|
301
|
+
hasDeposit
|
|
302
|
+
};
|
|
303
|
+
}
|
|
134
304
|
function isMarkdownBundle(bundle) {
|
|
135
305
|
if (!bundle || typeof bundle !== "object")
|
|
136
306
|
return false;
|
|
@@ -985,6 +1155,7 @@ function indexOrderProductsByUid(products) {
|
|
|
985
1155
|
0 && (module.exports = {
|
|
986
1156
|
buildManualProductDiscountItem,
|
|
987
1157
|
buildSubmitPayload,
|
|
1158
|
+
calculateOrderProductsDeposit,
|
|
988
1159
|
clearTempOrderHolderAssignments,
|
|
989
1160
|
composeLinePrice,
|
|
990
1161
|
createDefaultOrderRulesHooks,
|
|
@@ -61,6 +61,8 @@ export declare class ResourceModule extends BaseModule implements Module {
|
|
|
61
61
|
*/
|
|
62
62
|
clear(): Promise<void>;
|
|
63
63
|
private attachBookingsToResource;
|
|
64
|
+
private normalizeIntegerIdValue;
|
|
65
|
+
private normalizeResourceIdFields;
|
|
64
66
|
private normalizeResource;
|
|
65
67
|
private safeEmit;
|
|
66
68
|
private syncResourcesMap;
|
|
@@ -268,11 +268,35 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
|
|
|
268
268
|
bookings: this.getBookingsByResourceId(resource.id)
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
|
+
normalizeIntegerIdValue(value) {
|
|
272
|
+
if (typeof value !== "string")
|
|
273
|
+
return value;
|
|
274
|
+
const matched = value.match(/^(-?\d+)\.0+$/);
|
|
275
|
+
if (!matched)
|
|
276
|
+
return value;
|
|
277
|
+
return matched[1];
|
|
278
|
+
}
|
|
279
|
+
normalizeResourceIdFields(resource) {
|
|
280
|
+
resource.id = this.normalizeIntegerIdValue(resource.id);
|
|
281
|
+
if (resource.form_record_id !== void 0) {
|
|
282
|
+
resource.form_record_id = this.normalizeIntegerIdValue(resource.form_record_id);
|
|
283
|
+
}
|
|
284
|
+
if (resource.form_id !== void 0) {
|
|
285
|
+
resource.form_id = this.normalizeIntegerIdValue(resource.form_id);
|
|
286
|
+
}
|
|
287
|
+
if (resource.resource_form_id !== void 0) {
|
|
288
|
+
resource.resource_form_id = this.normalizeIntegerIdValue(resource.resource_form_id);
|
|
289
|
+
}
|
|
290
|
+
if (resource.resource_id !== void 0) {
|
|
291
|
+
resource.resource_id = this.normalizeIntegerIdValue(resource.resource_id);
|
|
292
|
+
}
|
|
293
|
+
return resource;
|
|
294
|
+
}
|
|
271
295
|
normalizeResource(resource) {
|
|
272
|
-
const normalized = {
|
|
296
|
+
const normalized = this.normalizeResourceIdFields({
|
|
273
297
|
...resource,
|
|
274
|
-
id: (resource == null ? void 0 : resource.id) ?? (resource == null ? void 0 : resource.form_record_id) ?? ""
|
|
275
|
-
};
|
|
298
|
+
id: this.normalizeIntegerIdValue((resource == null ? void 0 : resource.id) ?? (resource == null ? void 0 : resource.form_record_id) ?? "")
|
|
299
|
+
});
|
|
276
300
|
if (normalized.form_record_id === void 0 && normalized.id !== "") {
|
|
277
301
|
normalized.form_record_id = normalized.id;
|
|
278
302
|
}
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 | 1 | 2 | 3 |
|
|
314
|
+
weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -322,7 +322,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
322
322
|
* 获取当前的客户搜索条件
|
|
323
323
|
* @returns 当前搜索条件
|
|
324
324
|
*/
|
|
325
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
325
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
326
326
|
/**
|
|
327
327
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
328
328
|
* @returns 客户状态
|