@pisell/pisellos 2.2.171 → 2.2.172
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/BookingContext/index.d.ts +37 -0
- package/dist/modules/BookingContext/index.js +436 -0
- package/dist/modules/BookingContext/types.d.ts +102 -0
- package/dist/modules/BookingContext/types.js +51 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +193 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
- package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/dist/modules/BookingContext/utils/flexible.js +56 -0
- package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
- package/dist/modules/BookingContext/utils/index.d.ts +11 -0
- package/dist/modules/BookingContext/utils/index.js +11 -0
- package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/dist/modules/BookingContext/utils/noResource.js +77 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/dist/modules/BookingContext/utils/productExtend.js +339 -0
- package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
- package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
- package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
- package/dist/modules/BookingContext/utils/resources.js +486 -0
- package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
- package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
- package/dist/modules/Customer/index.d.ts +6 -0
- package/dist/modules/Customer/index.js +129 -83
- package/dist/modules/Customer/types.d.ts +2 -0
- package/dist/modules/Discount/index.d.ts +2 -4
- package/dist/modules/Discount/index.js +8 -93
- package/dist/modules/Discount/types.d.ts +1 -7
- package/dist/modules/Order/index.d.ts +47 -16
- package/dist/modules/Order/index.js +743 -334
- package/dist/modules/Order/types.d.ts +57 -17
- package/dist/modules/Order/types.js +2 -0
- package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/dist/modules/Order/utils/manualProductDiscount.js +212 -0
- package/dist/modules/Order/utils.d.ts +23 -1
- package/dist/modules/Order/utils.js +139 -30
- package/dist/modules/Quotation/index.js +16 -5
- package/dist/modules/Rules/index.d.ts +4 -0
- package/dist/modules/Rules/index.js +26 -10
- package/dist/modules/SalesSummary/index.js +4 -2
- package/dist/modules/Schedule/index.js +6 -2
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +2 -1
- package/dist/server/index.js +10 -6
- package/dist/server/modules/order/utils/filterOrders.js +20 -6
- package/dist/server/modules/products/index.js +9 -8
- package/dist/server/modules/schedule/index.js +13 -6
- package/dist/solution/BaseSales/index.d.ts +65 -7
- package/dist/solution/BaseSales/index.js +1066 -315
- package/dist/solution/BaseSales/types.d.ts +53 -1
- package/dist/solution/BaseSales/types.js +3 -1
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
- package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +65 -15
- package/dist/solution/BaseSales/utils.js +46 -8
- package/dist/solution/BookingTicket/index.d.ts +134 -2
- package/dist/solution/BookingTicket/index.js +768 -175
- package/dist/solution/BookingTicket/types.d.ts +2 -0
- package/dist/solution/BookingTicket/types.js +3 -0
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
- package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
- package/dist/solution/ScanOrder/index.d.ts +9 -3
- package/dist/solution/ScanOrder/index.js +231 -128
- package/dist/solution/ScanOrder/utils.js +46 -8
- package/dist/solution/ShopDiscount/index.d.ts +0 -1
- package/dist/solution/ShopDiscount/index.js +18 -23
- package/dist/solution/VenueBooking/index.d.ts +5 -9
- package/dist/solution/VenueBooking/index.js +103 -55
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
- package/lib/modules/BookingContext/index.d.ts +37 -0
- package/lib/modules/BookingContext/index.js +297 -0
- package/lib/modules/BookingContext/types.d.ts +102 -0
- package/lib/modules/BookingContext/types.js +34 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +207 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
- package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/lib/modules/BookingContext/utils/flexible.js +80 -0
- package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
- package/lib/modules/BookingContext/utils/index.d.ts +11 -0
- package/lib/modules/BookingContext/utils/index.js +43 -0
- package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/lib/modules/BookingContext/utils/noResource.js +90 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/lib/modules/BookingContext/utils/productExtend.js +283 -0
- package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
- package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
- package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
- package/lib/modules/BookingContext/utils/resources.js +377 -0
- package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
- package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
- package/lib/modules/Customer/index.d.ts +6 -0
- package/lib/modules/Customer/index.js +26 -11
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Discount/index.d.ts +2 -4
- package/lib/modules/Discount/index.js +8 -63
- package/lib/modules/Discount/types.d.ts +1 -7
- package/lib/modules/Order/index.d.ts +47 -16
- package/lib/modules/Order/index.js +389 -90
- package/lib/modules/Order/types.d.ts +57 -17
- package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
- package/lib/modules/Order/utils.d.ts +23 -1
- package/lib/modules/Order/utils.js +145 -21
- package/lib/modules/Quotation/index.js +17 -6
- package/lib/modules/Rules/index.d.ts +4 -0
- package/lib/modules/Rules/index.js +22 -14
- package/lib/modules/SalesSummary/index.js +4 -2
- package/lib/modules/Schedule/index.js +3 -1
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +3 -1
- package/lib/server/index.js +2 -0
- package/lib/server/modules/order/utils/filterOrders.js +12 -4
- package/lib/server/modules/products/index.js +8 -9
- package/lib/server/modules/schedule/index.js +2 -1
- package/lib/solution/BaseSales/index.d.ts +65 -7
- package/lib/solution/BaseSales/index.js +492 -20
- package/lib/solution/BaseSales/types.d.ts +53 -1
- package/lib/solution/BaseSales/types.js +3 -1
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
- package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +70 -11
- package/lib/solution/BaseSales/utils.js +46 -6
- package/lib/solution/BookingTicket/index.d.ts +134 -2
- package/lib/solution/BookingTicket/index.js +341 -8
- package/lib/solution/BookingTicket/types.d.ts +2 -0
- package/lib/solution/BookingTicket/types.js +6 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
- package/lib/solution/ScanOrder/index.d.ts +9 -3
- package/lib/solution/ScanOrder/index.js +147 -66
- package/lib/solution/ScanOrder/utils.js +46 -6
- package/lib/solution/ShopDiscount/index.d.ts +0 -1
- package/lib/solution/ShopDiscount/index.js +2 -4
- package/lib/solution/VenueBooking/index.d.ts +5 -9
- package/lib/solution/VenueBooking/index.js +50 -14
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLoggerModule as BaseSalesLoggerModule, ScheduleModule } from '../../modules';
|
|
1
|
+
import { OrderModule, ProductList, QuotationModule, SalesSummaryModule, ScanOrderLoggerModule as BaseSalesLoggerModule, ScheduleModule } from '../../modules';
|
|
2
2
|
import type { ScanOrderLogInput as BaseSalesLogInput, ScanOrderLoggerProviderConfig as BaseSalesLoggerProviderConfig, ScanOrderLoggerProviderType as BaseSalesLoggerProviderType } from '../../modules/ScanOrderLogger/types';
|
|
3
3
|
import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
|
|
4
4
|
/**
|
|
@@ -11,6 +11,8 @@ export declare const BaseSalesHookNames: {
|
|
|
11
11
|
readonly onRetryInit: "onRetryInit";
|
|
12
12
|
readonly onRefresh: "onRefresh";
|
|
13
13
|
readonly onCartValidationChanged: "onCartValidationChanged";
|
|
14
|
+
readonly onPaymentSyncStart: "onPaymentSyncStart";
|
|
15
|
+
readonly onPaymentSyncEnd: "onPaymentSyncEnd";
|
|
14
16
|
};
|
|
15
17
|
export type BaseSalesHookName = typeof BaseSalesHookNames[keyof typeof BaseSalesHookNames];
|
|
16
18
|
export declare function createBaseSalesHook(moduleName: string, hookName: BaseSalesHookName): string;
|
|
@@ -42,6 +44,9 @@ export interface BaseSalesOrderProductIdentity {
|
|
|
42
44
|
product_option_item?: any[];
|
|
43
45
|
product_bundle?: any[];
|
|
44
46
|
}
|
|
47
|
+
export interface BaseSalesUpdateOrderProductQuantityParams extends BaseSalesOrderProductIdentity {
|
|
48
|
+
num: number;
|
|
49
|
+
}
|
|
45
50
|
export interface BaseSalesOrderProduct extends BaseSalesOrderProductIdentity {
|
|
46
51
|
order_detail_id: number | null;
|
|
47
52
|
num: number;
|
|
@@ -203,6 +208,52 @@ export interface BaseSalesSubmitPayload extends Omit<BaseSalesTempOrder, 'platfo
|
|
|
203
208
|
}>;
|
|
204
209
|
products: BaseSalesSubmitProduct[];
|
|
205
210
|
}
|
|
211
|
+
export interface BaseSalesQuotationDurationConfig {
|
|
212
|
+
type: string;
|
|
213
|
+
value: number;
|
|
214
|
+
flexible_config?: {
|
|
215
|
+
is_enable_minimum_duration?: 0 | 1;
|
|
216
|
+
warning_threshold?: number;
|
|
217
|
+
block_threshold?: number;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
export interface BaseSalesCalculateProductBookingPriceParams {
|
|
221
|
+
product: Record<string, any>;
|
|
222
|
+
booking?: {
|
|
223
|
+
start_date?: string;
|
|
224
|
+
start_time?: string;
|
|
225
|
+
end_date?: string;
|
|
226
|
+
end_time?: string;
|
|
227
|
+
[key: string]: any;
|
|
228
|
+
};
|
|
229
|
+
duration?: BaseSalesQuotationDurationConfig;
|
|
230
|
+
customer_id?: number | string;
|
|
231
|
+
fallback_price?: number | string;
|
|
232
|
+
datetime?: string;
|
|
233
|
+
channel?: string;
|
|
234
|
+
}
|
|
235
|
+
export type BaseSalesProductBookingPriceSegmentSource = 'quotation' | 'fallback';
|
|
236
|
+
export interface BaseSalesProductBookingPriceSegment {
|
|
237
|
+
start_datetime: string;
|
|
238
|
+
end_datetime?: string;
|
|
239
|
+
time_point: string;
|
|
240
|
+
unit_price: string;
|
|
241
|
+
quantity: number;
|
|
242
|
+
total_price: string;
|
|
243
|
+
quotation_shelf_id: number;
|
|
244
|
+
source: BaseSalesProductBookingPriceSegmentSource;
|
|
245
|
+
}
|
|
246
|
+
export interface BaseSalesProductBookingPriceResult {
|
|
247
|
+
product_id: number | null;
|
|
248
|
+
product_variant_id: number;
|
|
249
|
+
customer_id?: number | string;
|
|
250
|
+
unit_price: string;
|
|
251
|
+
total_price: string;
|
|
252
|
+
quantity: number;
|
|
253
|
+
duration?: BaseSalesQuotationDurationConfig;
|
|
254
|
+
quotation_shelf_id: number;
|
|
255
|
+
segments: BaseSalesProductBookingPriceSegment[];
|
|
256
|
+
}
|
|
206
257
|
export type BaseSalesAvailabilityMode = 'idle' | 'shop_closed' | 'submit_disabled' | 'resource_busy' | 'additional_order_with_code' | 'additional_order';
|
|
207
258
|
export interface BaseSalesTableFormRecord {
|
|
208
259
|
policy?: string | null;
|
|
@@ -281,6 +332,7 @@ export interface BaseSalesState {
|
|
|
281
332
|
error: string | null;
|
|
282
333
|
products?: ProductList;
|
|
283
334
|
order?: OrderModule;
|
|
335
|
+
quotation?: QuotationModule;
|
|
284
336
|
salesSummary?: SalesSummaryModule;
|
|
285
337
|
baseSalesLogger?: BaseSalesLoggerModule;
|
|
286
338
|
schedule?: ScheduleModule;
|
|
@@ -7,7 +7,9 @@ export var BaseSalesHookNames = {
|
|
|
7
7
|
onDestroy: 'onDestroy',
|
|
8
8
|
onRetryInit: 'onRetryInit',
|
|
9
9
|
onRefresh: 'onRefresh',
|
|
10
|
-
onCartValidationChanged: 'onCartValidationChanged'
|
|
10
|
+
onCartValidationChanged: 'onCartValidationChanged',
|
|
11
|
+
onPaymentSyncStart: 'onPaymentSyncStart',
|
|
12
|
+
onPaymentSyncEnd: 'onPaymentSyncEnd'
|
|
11
13
|
};
|
|
12
14
|
export function createBaseSalesHook(moduleName, hookName) {
|
|
13
15
|
return "".concat(moduleName, ":").concat(hookName);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { QuotationModule } from '../../../modules/Quotation';
|
|
2
|
+
import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult } from '../types';
|
|
3
|
+
interface BuildBaseSalesQuotationPriceParams extends BaseSalesCalculateProductBookingPriceParams {
|
|
4
|
+
quotation?: Pick<QuotationModule, 'getPriceForProduct' | 'getQuotationShelfId'> | null;
|
|
5
|
+
}
|
|
6
|
+
export declare function calculateBaseSalesProductBookingPrice(params: BuildBaseSalesQuotationPriceParams): BaseSalesProductBookingPriceResult;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import Decimal from 'decimal.js';
|
|
3
|
+
function toFiniteNumber(value) {
|
|
4
|
+
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
5
|
+
var parsedValue = Number(value);
|
|
6
|
+
if (!Number.isFinite(parsedValue)) return fallback;
|
|
7
|
+
return parsedValue;
|
|
8
|
+
}
|
|
9
|
+
function toPositiveInt(value) {
|
|
10
|
+
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
11
|
+
var parsedValue = Math.floor(Number(value));
|
|
12
|
+
if (!Number.isFinite(parsedValue) || parsedValue < 1) return fallback;
|
|
13
|
+
return parsedValue;
|
|
14
|
+
}
|
|
15
|
+
function toPriceString(value) {
|
|
16
|
+
return new Decimal(Number(value) || 0).toDecimalPlaces(2).toFixed(2);
|
|
17
|
+
}
|
|
18
|
+
function normalizeDateTime(value) {
|
|
19
|
+
if (typeof value !== 'string' || !value.trim()) return null;
|
|
20
|
+
var normalized = value.includes(':') ? value : "".concat(value, " 00:00:00");
|
|
21
|
+
var datetime = dayjs(normalized);
|
|
22
|
+
if (!datetime.isValid()) return null;
|
|
23
|
+
return datetime;
|
|
24
|
+
}
|
|
25
|
+
function buildBookingDateTime(date, time) {
|
|
26
|
+
if (typeof date !== 'string' || !date.trim()) return null;
|
|
27
|
+
var timeText = typeof time === 'string' && time.trim() ? time.trim() : '00:00';
|
|
28
|
+
var datetime = dayjs("".concat(date.trim(), " ").concat(timeText));
|
|
29
|
+
if (!datetime.isValid()) return null;
|
|
30
|
+
return datetime;
|
|
31
|
+
}
|
|
32
|
+
function getDurationUnit(type) {
|
|
33
|
+
var normalizedType = String(type || '').toLowerCase();
|
|
34
|
+
if (normalizedType === 'day' || normalizedType === 'days') return 'day';
|
|
35
|
+
if (normalizedType === 'minute' || normalizedType === 'minutes') return 'minute';
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function getProductId(product) {
|
|
39
|
+
var _product$product_id;
|
|
40
|
+
var productId = toFiniteNumber((_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : product.id, NaN);
|
|
41
|
+
if (!Number.isFinite(productId)) return null;
|
|
42
|
+
return productId;
|
|
43
|
+
}
|
|
44
|
+
function getProductVariantId(product) {
|
|
45
|
+
var _product$product_vari;
|
|
46
|
+
var variantId = toFiniteNumber((_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id, 0);
|
|
47
|
+
if (!Number.isFinite(variantId) || variantId <= 0) return undefined;
|
|
48
|
+
return variantId;
|
|
49
|
+
}
|
|
50
|
+
function getFallbackPrice(params) {
|
|
51
|
+
var _ref, _ref2, _ref3, _params$fallback_pric;
|
|
52
|
+
var product = params.product || {};
|
|
53
|
+
return toPriceString((_ref = (_ref2 = (_ref3 = (_params$fallback_pric = params.fallback_price) !== null && _params$fallback_pric !== void 0 ? _params$fallback_pric : product.price) !== null && _ref3 !== void 0 ? _ref3 : product.selling_price) !== null && _ref2 !== void 0 ? _ref2 : product.original_price) !== null && _ref !== void 0 ? _ref : 0);
|
|
54
|
+
}
|
|
55
|
+
function getProductQuantity(product) {
|
|
56
|
+
var _product$num;
|
|
57
|
+
return toPositiveInt((_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity, 1);
|
|
58
|
+
}
|
|
59
|
+
function shouldSplitByDuration(duration, start, end) {
|
|
60
|
+
if (!duration) return false;
|
|
61
|
+
if (!start || !end || !end.isAfter(start)) return false;
|
|
62
|
+
var unit = getDurationUnit(duration.type);
|
|
63
|
+
var value = toFiniteNumber(duration.value);
|
|
64
|
+
return !!unit && value > 0;
|
|
65
|
+
}
|
|
66
|
+
function buildTimeSegments(params) {
|
|
67
|
+
var booking = params.booking || {};
|
|
68
|
+
var explicitDatetime = normalizeDateTime(params.datetime);
|
|
69
|
+
var bookingStart = buildBookingDateTime(booking.start_date, booking.start_time);
|
|
70
|
+
var start = bookingStart || explicitDatetime || dayjs();
|
|
71
|
+
var bookingEnd = buildBookingDateTime(booking.end_date, booking.end_time);
|
|
72
|
+
if (!shouldSplitByDuration(params.duration, start, bookingEnd)) {
|
|
73
|
+
return [{
|
|
74
|
+
start: start
|
|
75
|
+
}];
|
|
76
|
+
}
|
|
77
|
+
var unit = getDurationUnit(params.duration.type);
|
|
78
|
+
var value = toFiniteNumber(params.duration.value);
|
|
79
|
+
var segments = [];
|
|
80
|
+
var cursor = start;
|
|
81
|
+
var guard = 0;
|
|
82
|
+
while (cursor.isBefore(bookingEnd) && guard < 10000) {
|
|
83
|
+
var next = cursor.add(value, unit);
|
|
84
|
+
segments.push({
|
|
85
|
+
start: cursor,
|
|
86
|
+
end: next.isBefore(bookingEnd) ? next : bookingEnd !== null && bookingEnd !== void 0 ? bookingEnd : undefined
|
|
87
|
+
});
|
|
88
|
+
cursor = next;
|
|
89
|
+
guard += 1;
|
|
90
|
+
}
|
|
91
|
+
return segments.length ? segments : [{
|
|
92
|
+
start: start
|
|
93
|
+
}];
|
|
94
|
+
}
|
|
95
|
+
function formatTimePoint(datetime) {
|
|
96
|
+
return datetime.format('YYYY-MM-DD HH:mm:ss');
|
|
97
|
+
}
|
|
98
|
+
function buildPriceSegment(params) {
|
|
99
|
+
var timePoint = formatTimePoint(params.segment.start);
|
|
100
|
+
var quotedPrice = params.quotation && params.productId !== null ? params.quotation.getPriceForProduct({
|
|
101
|
+
productId: params.productId,
|
|
102
|
+
variantId: params.variantId,
|
|
103
|
+
datetime: timePoint,
|
|
104
|
+
customer_id: params.customerId
|
|
105
|
+
}) : null;
|
|
106
|
+
var unitPrice = toPriceString(quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : params.fallbackPrice);
|
|
107
|
+
var quotationShelfId = quotedPrice !== null && params.quotation && params.productId !== null ? params.quotation.getQuotationShelfId({
|
|
108
|
+
productId: params.productId,
|
|
109
|
+
variantId: params.variantId,
|
|
110
|
+
datetime: timePoint,
|
|
111
|
+
customer_id: params.customerId
|
|
112
|
+
}) : 0;
|
|
113
|
+
return {
|
|
114
|
+
start_datetime: timePoint,
|
|
115
|
+
end_datetime: params.segment.end ? formatTimePoint(params.segment.end) : undefined,
|
|
116
|
+
time_point: timePoint,
|
|
117
|
+
unit_price: unitPrice,
|
|
118
|
+
quantity: 1,
|
|
119
|
+
total_price: unitPrice,
|
|
120
|
+
quotation_shelf_id: quotationShelfId,
|
|
121
|
+
source: quotedPrice !== null ? 'quotation' : 'fallback'
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export function calculateBaseSalesProductBookingPrice(params) {
|
|
125
|
+
var _segments$find;
|
|
126
|
+
var product = params.product || {};
|
|
127
|
+
var productId = getProductId(product);
|
|
128
|
+
var variantId = getProductVariantId(product);
|
|
129
|
+
var productQuantity = getProductQuantity(product);
|
|
130
|
+
var fallbackPrice = getFallbackPrice(params);
|
|
131
|
+
var segments = buildTimeSegments(params).map(function (segment) {
|
|
132
|
+
return buildPriceSegment({
|
|
133
|
+
quotation: params.quotation,
|
|
134
|
+
productId: productId,
|
|
135
|
+
variantId: variantId,
|
|
136
|
+
customerId: params.customer_id,
|
|
137
|
+
fallbackPrice: fallbackPrice,
|
|
138
|
+
segment: segment
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
var unitPrice = segments.reduce(function (total, segment) {
|
|
142
|
+
return total.plus(segment.total_price);
|
|
143
|
+
}, new Decimal(0));
|
|
144
|
+
var totalPrice = unitPrice.times(productQuantity);
|
|
145
|
+
var quotationShelfId = ((_segments$find = segments.find(function (segment) {
|
|
146
|
+
return segment.quotation_shelf_id;
|
|
147
|
+
})) === null || _segments$find === void 0 ? void 0 : _segments$find.quotation_shelf_id) || 0;
|
|
148
|
+
return {
|
|
149
|
+
product_id: productId,
|
|
150
|
+
product_variant_id: variantId !== null && variantId !== void 0 ? variantId : 0,
|
|
151
|
+
customer_id: params.customer_id,
|
|
152
|
+
unit_price: unitPrice.toDecimalPlaces(2).toFixed(2),
|
|
153
|
+
total_price: totalPrice.toDecimalPlaces(2).toFixed(2),
|
|
154
|
+
quantity: productQuantity,
|
|
155
|
+
duration: params.duration,
|
|
156
|
+
quotation_shelf_id: quotationShelfId,
|
|
157
|
+
segments: segments
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
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); }
|
|
7
|
+
import { buildManualProductDiscountItem, mergeManualProductDiscountIntoList, resolveManualDiscountOriginTotal, resolveManualDiscountReasonFromSources, shouldBuildManualProductDiscount } from "../../../modules/Order/utils/manualProductDiscount";
|
|
7
8
|
function toNumber(value) {
|
|
8
9
|
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
9
10
|
var parsedValue = Number(value);
|
|
@@ -43,9 +44,19 @@ function normalizeOptionItems(optionItems) {
|
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
function normalizeBundleItems(bundleItems) {
|
|
47
|
+
var preferPriceField = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
46
48
|
if (!Array.isArray(bundleItems)) return [];
|
|
47
49
|
return bundleItems.map(function (bundleItem) {
|
|
50
|
+
var _ref2, _ref3, _ref4, _bundleItem$price, _ref5, _ref6, _ref7, _bundleItem$bundle_se, _bundleItem$num, _bundleItem$quantity, _bundleItem$price2, _ref8, _ref9, _bundleItem$original_;
|
|
51
|
+
var unitSelling = preferPriceField ? (_ref2 = (_ref3 = (_ref4 = (_bundleItem$price = bundleItem.price) !== null && _bundleItem$price !== void 0 ? _bundleItem$price : bundleItem.bundle_selling_price) !== null && _ref4 !== void 0 ? _ref4 : bundleItem.custom_price) !== null && _ref3 !== void 0 ? _ref3 : bundleItem.product_price) !== null && _ref2 !== void 0 ? _ref2 : '0' : (_ref5 = (_ref6 = (_ref7 = (_bundleItem$bundle_se = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se !== void 0 ? _bundleItem$bundle_se : bundleItem.price) !== null && _ref7 !== void 0 ? _ref7 : bundleItem.custom_price) !== null && _ref6 !== void 0 ? _ref6 : bundleItem.product_price) !== null && _ref5 !== void 0 ? _ref5 : '0';
|
|
52
|
+
var unitStr = toPriceString(unitSelling, '0.00');
|
|
53
|
+
var num = toSafePositiveInt((_bundleItem$num = bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.num) !== null && _bundleItem$num !== void 0 ? _bundleItem$num : bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.quantity, 1);
|
|
48
54
|
return _objectSpread(_objectSpread({}, bundleItem), {}, {
|
|
55
|
+
num: num,
|
|
56
|
+
quantity: (_bundleItem$quantity = bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.quantity) !== null && _bundleItem$quantity !== void 0 ? _bundleItem$quantity : num,
|
|
57
|
+
price: (_bundleItem$price2 = bundleItem.price) !== null && _bundleItem$price2 !== void 0 ? _bundleItem$price2 : unitStr,
|
|
58
|
+
bundle_selling_price: unitStr,
|
|
59
|
+
original_price: (_ref8 = (_ref9 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref9 !== void 0 ? _ref9 : bundleItem.price) !== null && _ref8 !== void 0 ? _ref8 : unitStr,
|
|
49
60
|
option: normalizeOptionItems(bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option)
|
|
50
61
|
});
|
|
51
62
|
});
|
|
@@ -64,23 +75,53 @@ function findVariantById(origin, variantId) {
|
|
|
64
75
|
* 注意:这里不生成 identity,缺省时由 OrderModule 自动补齐。
|
|
65
76
|
*/
|
|
66
77
|
export function transformBaseProductToOrderProduct(params) {
|
|
67
|
-
var
|
|
78
|
+
var _ref10, _ref11, _ref12, _payload$product_id, _ref13, _ref14, _payload$product_vari, _payload$_origin, _payload$_origin2, _ref15, _findVariantById, _ref16, _ref17, _ref18, _ref19, _ref20, _ref21, _ref22, _payload$price, _ref23, _payload$line_total, _payload$_extend, _ref24, _payload$option, _payload$bundle, _payload$unique_ident, _payload$quantity, _payload$_extend2, _extend, _extend2, _ref25, _ref26, _origin$base_price, _ref27, _ref28, _payload$line_total2, _payload$_extend3, _payload$_extend4, _extend3, _payload$_extend5, _payload$_extend6, _ref29, _ref30, _payload$tax_fee, _ref31, _ref32, _payload$is_charge_ta;
|
|
68
79
|
var payload = params.payload,
|
|
69
80
|
_params$fallbackProdu = params.fallbackProductId,
|
|
70
81
|
fallbackProductId = _params$fallbackProdu === void 0 ? null : _params$fallbackProdu;
|
|
71
82
|
if (!payload || _typeof(payload) !== 'object') return null;
|
|
72
83
|
var sourceProduct = params.sourceProduct || params.sourceItem || {};
|
|
73
|
-
var productId = toProductId((
|
|
84
|
+
var productId = toProductId((_ref10 = (_ref11 = (_ref12 = (_payload$product_id = payload.product_id) !== null && _payload$product_id !== void 0 ? _payload$product_id : payload.id) !== null && _ref12 !== void 0 ? _ref12 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.product_id) !== null && _ref11 !== void 0 ? _ref11 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.id) !== null && _ref10 !== void 0 ? _ref10 : fallbackProductId);
|
|
74
85
|
if (productId === null) return null;
|
|
75
|
-
var productVariantId = toNumber((
|
|
86
|
+
var productVariantId = toNumber((_ref13 = (_ref14 = (_payload$product_vari = payload.product_variant_id) !== null && _payload$product_vari !== void 0 ? _payload$product_vari : payload.variant_id) !== null && _ref14 !== void 0 ? _ref14 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.product_variant_id) !== null && _ref13 !== void 0 ? _ref13 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.variant_id, 0);
|
|
76
87
|
var callbackOrigin = payload.origin || ((_payload$_origin = payload._origin) === null || _payload$_origin === void 0 ? void 0 : _payload$_origin.sourceProduct) || ((_payload$_origin2 = payload._origin) === null || _payload$_origin2 === void 0 ? void 0 : _payload$_origin2.sourceItem) || payload._origin || {};
|
|
77
88
|
var origin = _objectSpread(_objectSpread({}, sourceProduct || {}), callbackOrigin || {});
|
|
78
|
-
var matchedVariant = (
|
|
79
|
-
var sourceProductPrice = toPriceString((
|
|
80
|
-
var
|
|
81
|
-
var
|
|
89
|
+
var matchedVariant = (_ref15 = (_findVariantById = findVariantById(callbackOrigin, productVariantId)) !== null && _findVariantById !== void 0 ? _findVariantById : findVariantById(sourceProduct, productVariantId)) !== null && _ref15 !== void 0 ? _ref15 : findVariantById(origin, productVariantId);
|
|
90
|
+
var sourceProductPrice = toPriceString((_ref16 = (_ref17 = (_ref18 = (_ref19 = (_ref20 = (_ref21 = (_ref22 = (_payload$price = payload.price) !== null && _payload$price !== void 0 ? _payload$price : payload.selling_price) !== null && _ref22 !== void 0 ? _ref22 : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.price) !== null && _ref21 !== void 0 ? _ref21 : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.base_price) !== null && _ref20 !== void 0 ? _ref20 : origin === null || origin === void 0 ? void 0 : origin.price) !== null && _ref19 !== void 0 ? _ref19 : origin === null || origin === void 0 ? void 0 : origin.base_price) !== null && _ref18 !== void 0 ? _ref18 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _ref17 !== void 0 ? _ref17 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.selling_price) !== null && _ref16 !== void 0 ? _ref16 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.base_price, '0.00');
|
|
91
|
+
var lineCompositeTotal = toPriceString((_ref23 = (_payload$line_total = payload.line_total) !== null && _payload$line_total !== void 0 ? _payload$line_total : payload.total) !== null && _ref23 !== void 0 ? _ref23 : (_payload$_extend = payload._extend) === null || _payload$_extend === void 0 ? void 0 : _payload$_extend.total, sourceProductPrice);
|
|
92
|
+
var hasPriceOverride = payload.price_override !== undefined && payload.price_override !== null && payload.price_override !== '';
|
|
93
|
+
var productOptionItem = normalizeOptionItems((_ref24 = (_payload$option = payload.option) !== null && _payload$option !== void 0 ? _payload$option : payload.options) !== null && _ref24 !== void 0 ? _ref24 : payload.product_option_item);
|
|
94
|
+
var productBundle = normalizeBundleItems((_payload$bundle = payload.bundle) !== null && _payload$bundle !== void 0 ? _payload$bundle : payload.product_bundle, hasPriceOverride);
|
|
82
95
|
var uniqueIdentificationNumber = (_payload$unique_ident = payload.unique_identification_number) !== null && _payload$unique_ident !== void 0 ? _payload$unique_ident : payload.unique;
|
|
83
|
-
var
|
|
96
|
+
var resolvedQuantity = toSafePositiveInt((_payload$quantity = payload.quantity) !== null && _payload$quantity !== void 0 ? _payload$quantity : payload.num, 1);
|
|
97
|
+
var originTotal = resolveManualDiscountOriginTotal({
|
|
98
|
+
originTotal: payload.origin_total,
|
|
99
|
+
extendOriginTotal: (_payload$_extend2 = payload._extend) === null || _payload$_extend2 === void 0 ? void 0 : _payload$_extend2.origin_total,
|
|
100
|
+
originExtendOriginTotal: origin === null || origin === void 0 || (_extend = origin._extend) === null || _extend === void 0 ? void 0 : _extend.origin_total,
|
|
101
|
+
sourceExtendOriginTotal: sourceProduct === null || sourceProduct === void 0 || (_extend2 = sourceProduct._extend) === null || _extend2 === void 0 ? void 0 : _extend2.origin_total,
|
|
102
|
+
catalogUnitPrice: (_ref25 = (_ref26 = (_origin$base_price = origin === null || origin === void 0 ? void 0 : origin.base_price) !== null && _origin$base_price !== void 0 ? _origin$base_price : origin === null || origin === void 0 ? void 0 : origin.price) !== null && _ref26 !== void 0 ? _ref26 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.base_price) !== null && _ref25 !== void 0 ? _ref25 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price,
|
|
103
|
+
quantity: resolvedQuantity
|
|
104
|
+
});
|
|
105
|
+
var sellingTotal = Number((_ref27 = (_ref28 = (_payload$line_total2 = payload.line_total) !== null && _payload$line_total2 !== void 0 ? _payload$line_total2 : payload.total) !== null && _ref28 !== void 0 ? _ref28 : (_payload$_extend3 = payload._extend) === null || _payload$_extend3 === void 0 ? void 0 : _payload$_extend3.total) !== null && _ref27 !== void 0 ? _ref27 : lineCompositeTotal);
|
|
106
|
+
var discountReason = resolveManualDiscountReasonFromSources({
|
|
107
|
+
discountReason: payload.discount_reason,
|
|
108
|
+
extendDiscountReason: (_payload$_extend4 = payload._extend) === null || _payload$_extend4 === void 0 ? void 0 : _payload$_extend4.discount_reason,
|
|
109
|
+
originExtendDiscountReason: origin === null || origin === void 0 || (_extend3 = origin._extend) === null || _extend3 === void 0 ? void 0 : _extend3.discount_reason
|
|
110
|
+
});
|
|
111
|
+
var lineOriginalPrice = hasPriceOverride && Number.isFinite(originTotal) ? toPriceString(originTotal) : lineCompositeTotal;
|
|
112
|
+
var manualDiscountList = shouldBuildManualProductDiscount({
|
|
113
|
+
hasPriceOverride: hasPriceOverride,
|
|
114
|
+
originTotal: originTotal,
|
|
115
|
+
sellingTotal: sellingTotal
|
|
116
|
+
}) ? mergeManualProductDiscountIntoList(payload.discount_list, buildManualProductDiscountItem({
|
|
117
|
+
originTotal: Number.isFinite(originTotal) ? originTotal : Number(lineOriginalPrice),
|
|
118
|
+
sellingTotal: Number.isFinite(sellingTotal) ? sellingTotal : Number(lineCompositeTotal),
|
|
119
|
+
quantity: resolvedQuantity,
|
|
120
|
+
message: discountReason,
|
|
121
|
+
discountway: (_payload$_extend5 = payload._extend) === null || _payload$_extend5 === void 0 ? void 0 : _payload$_extend5.discountway,
|
|
122
|
+
discount_per: (_payload$_extend6 = payload._extend) === null || _payload$_extend6 === void 0 ? void 0 : _payload$_extend6.discount_per
|
|
123
|
+
})) : payload.discount_list || [];
|
|
124
|
+
var metadata = _objectSpread(_objectSpread({
|
|
84
125
|
unique: payload.unique,
|
|
85
126
|
session: payload.session,
|
|
86
127
|
form: payload.form,
|
|
@@ -91,8 +132,15 @@ export function transformBaseProductToOrderProduct(params) {
|
|
|
91
132
|
policy_id: payload.policy_id,
|
|
92
133
|
source_shop_id: payload.source_shop_id,
|
|
93
134
|
origin: origin,
|
|
94
|
-
source_product_price: sourceProductPrice
|
|
95
|
-
|
|
135
|
+
source_product_price: sourceProductPrice,
|
|
136
|
+
main_product_selling_price: sourceProductPrice,
|
|
137
|
+
main_product_original_price: sourceProductPrice
|
|
138
|
+
}, hasPriceOverride ? {
|
|
139
|
+
price_override: String(payload.price_override),
|
|
140
|
+
is_manual_discount: 1
|
|
141
|
+
} : {}), payload.bundle_edit !== undefined ? {
|
|
142
|
+
bundle_edit: payload.bundle_edit
|
|
143
|
+
} : {});
|
|
96
144
|
if (uniqueIdentificationNumber) {
|
|
97
145
|
metadata.unique_identification_number = String(uniqueIdentificationNumber);
|
|
98
146
|
}
|
|
@@ -100,13 +148,15 @@ export function transformBaseProductToOrderProduct(params) {
|
|
|
100
148
|
product_id: productId,
|
|
101
149
|
product_variant_id: productVariantId,
|
|
102
150
|
unique_identification_number: uniqueIdentificationNumber ? String(uniqueIdentificationNumber) : undefined,
|
|
103
|
-
num:
|
|
151
|
+
num: resolvedQuantity,
|
|
104
152
|
product_option_item: productOptionItem,
|
|
105
153
|
product_bundle: productBundle,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
154
|
+
discount_list: manualDiscountList,
|
|
155
|
+
// 折后行价由 normalizeOrderProduct 按 main + bundle 合成;手动改价时 bundle 已为分摊后单价
|
|
156
|
+
selling_price: lineCompositeTotal,
|
|
157
|
+
original_price: lineOriginalPrice,
|
|
158
|
+
tax_fee: toPriceString((_ref29 = (_ref30 = (_payload$tax_fee = payload.tax_fee) !== null && _payload$tax_fee !== void 0 ? _payload$tax_fee : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.tax_fee) !== null && _ref30 !== void 0 ? _ref30 : origin === null || origin === void 0 ? void 0 : origin.tax_fee) !== null && _ref29 !== void 0 ? _ref29 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.tax_fee, '0.00'),
|
|
159
|
+
is_charge_tax: toNumber((_ref31 = (_ref32 = (_payload$is_charge_ta = payload.is_charge_tax) !== null && _payload$is_charge_ta !== void 0 ? _payload$is_charge_ta : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.is_charge_tax) !== null && _ref32 !== void 0 ? _ref32 : origin === null || origin === void 0 ? void 0 : origin.is_charge_tax) !== null && _ref31 !== void 0 ? _ref31 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.is_charge_tax, 0),
|
|
110
160
|
metadata: metadata,
|
|
111
161
|
note: payload.note != null ? String(payload.note) : '',
|
|
112
162
|
_origin: _objectSpread(_objectSpread({}, sourceProduct || {}), {}, {
|
|
@@ -5,7 +5,8 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
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); }
|
|
7
7
|
import Decimal from 'decimal.js';
|
|
8
|
-
import { composeLinePrice, createUuidV4, sumOptionUnitPrice } from "../../modules/Order/utils";
|
|
8
|
+
import { composeLinePrice, createUuidV4, resolveManualOverrideLineOriginalPrice, sumOptionUnitPrice } from "../../modules/Order/utils";
|
|
9
|
+
import { ensureManualProductDiscountList } from "../../modules/Order/utils/manualProductDiscount";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* 构建金额全为 0 的空 summary。
|
|
@@ -106,17 +107,42 @@ export function isSkuOnlyDeleteIdentity(x) {
|
|
|
106
107
|
* - 因此多次 normalize 不会重复叠加 option/bundle。
|
|
107
108
|
*/
|
|
108
109
|
export function normalizeOrderProduct(product) {
|
|
109
|
-
var _product$metadata, _metadata$origin, _variantList$find, _product$is_charge_ta;
|
|
110
|
+
var _product$metadata, _metadata$origin, _metadata$origin2, _variantList$find, _product$is_charge_ta;
|
|
110
111
|
var metadata = _objectSpread({}, product.metadata || {});
|
|
111
112
|
// 不透明 identity 契约:每条订单行必须带 identity_key。
|
|
112
113
|
// 调用方未传时由 SDK 自动生成 UUID,后续 update/remove 只做严格比对,避免猜测合成 key。
|
|
113
114
|
var resolvedIdentityKey = (_product$metadata = product.metadata) !== null && _product$metadata !== void 0 && _product$metadata.unique_identification_number ? String(product.metadata.unique_identification_number) : product.unique_identification_number && String(product.unique_identification_number).length > 0 ? String(product.unique_identification_number) : product.identity_key && String(product.identity_key).length > 0 ? String(product.identity_key) : createUuidV4();
|
|
114
115
|
metadata.unique_identification_number = resolvedIdentityKey;
|
|
115
|
-
var
|
|
116
|
-
|
|
116
|
+
var priceOverride = metadata.price_override;
|
|
117
|
+
var originOtherBundle = (_metadata$origin = metadata.origin) === null || _metadata$origin === void 0 || (_metadata$origin = _metadata$origin._extend) === null || _metadata$origin === void 0 || (_metadata$origin = _metadata$origin.other) === null || _metadata$origin === void 0 ? void 0 : _metadata$origin.bundle;
|
|
118
|
+
var bundleInput = product.product_bundle || [];
|
|
119
|
+
if (priceOverride !== undefined && priceOverride !== null && priceOverride !== '' && Array.isArray(originOtherBundle) && originOtherBundle.length > 0) {
|
|
120
|
+
var priceById = new Map();
|
|
121
|
+
originOtherBundle.forEach(function (item) {
|
|
122
|
+
var _item$price2;
|
|
123
|
+
if ((item === null || item === void 0 ? void 0 : item.id) == null) return;
|
|
124
|
+
var unit = (_item$price2 = item.price) !== null && _item$price2 !== void 0 ? _item$price2 : item.bundle_selling_price;
|
|
125
|
+
if (unit === undefined || unit === null) return;
|
|
126
|
+
priceById.set(String(item.id), String(unit));
|
|
127
|
+
});
|
|
128
|
+
var base = Array.isArray(bundleInput) && bundleInput.length > 0 ? bundleInput : originOtherBundle;
|
|
129
|
+
bundleInput = base.map(function (item) {
|
|
130
|
+
var unit = priceById.get(String(item === null || item === void 0 ? void 0 : item.id));
|
|
131
|
+
if (unit === undefined) return item;
|
|
132
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
133
|
+
price: unit,
|
|
134
|
+
bundle_selling_price: unit
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
var normalizedBundle = bundleInput.map(function (item) {
|
|
139
|
+
var _item$bundle_id2, _item$bundle_product_, _item$bundle_group_id, _ref2, _item$bundle_selling_, _ref3, _ref4, _item$price3, _ref5, _item$price_type, _ref6, _item$price_type_ext;
|
|
117
140
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
141
|
+
bundle_id: (_item$bundle_id2 = item.bundle_id) !== null && _item$bundle_id2 !== void 0 ? _item$bundle_id2 : item.id,
|
|
142
|
+
bundle_product_id: (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id,
|
|
143
|
+
bundle_group_id: (_item$bundle_group_id = item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item.group_id,
|
|
118
144
|
bundle_selling_price: (_ref2 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref2 !== void 0 ? _ref2 : '0.00',
|
|
119
|
-
price: (_ref3 = (_ref4 = (_item$
|
|
145
|
+
price: (_ref3 = (_ref4 = (_item$price3 = item.price) !== null && _item$price3 !== void 0 ? _item$price3 : item.custom_price) !== null && _ref4 !== void 0 ? _ref4 : item.bundle_selling_price) !== null && _ref3 !== void 0 ? _ref3 : '0.00',
|
|
120
146
|
price_type: (_ref5 = (_item$price_type = item.price_type) !== null && _item$price_type !== void 0 ? _item$price_type : item.custom_price_type) !== null && _ref5 !== void 0 ? _ref5 : '',
|
|
121
147
|
price_type_ext: (_ref6 = (_item$price_type_ext = item.price_type_ext) !== null && _item$price_type_ext !== void 0 ? _item$price_type_ext : item.custom_price_type_ext) !== null && _ref6 !== void 0 ? _ref6 : ''
|
|
122
148
|
});
|
|
@@ -134,7 +160,7 @@ export function normalizeOrderProduct(product) {
|
|
|
134
160
|
// 6) 入参 selling_price(最末兜底,新添加路径 caller 只给 selling_price)
|
|
135
161
|
var isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
|
|
136
162
|
var variantId = Number(product.product_variant_id || 0);
|
|
137
|
-
var variantList = variantId ? metadata === null || metadata === void 0 || (_metadata$
|
|
163
|
+
var variantList = variantId ? metadata === null || metadata === void 0 || (_metadata$origin2 = metadata.origin) === null || _metadata$origin2 === void 0 ? void 0 : _metadata$origin2.variant : null;
|
|
138
164
|
var variantPrice = Array.isArray(variantList) ? (_variantList$find = variantList.find(function (v) {
|
|
139
165
|
return Number(v === null || v === void 0 ? void 0 : v.id) === variantId;
|
|
140
166
|
})) === null || _variantList$find === void 0 ? void 0 : _variantList$find.price : undefined;
|
|
@@ -204,6 +230,18 @@ export function normalizeOrderProduct(product) {
|
|
|
204
230
|
bundle: normalizedBundle,
|
|
205
231
|
useOriginalBundle: true
|
|
206
232
|
});
|
|
233
|
+
var finalOriginalPrice = resolveManualOverrideLineOriginalPrice({
|
|
234
|
+
num: product.num,
|
|
235
|
+
metadata: metadata,
|
|
236
|
+
lineOriginalPrice: product.original_price
|
|
237
|
+
}, composedOriginalPrice);
|
|
238
|
+
var discountList = ensureManualProductDiscountList({
|
|
239
|
+
discountList: product.discount_list,
|
|
240
|
+
metadata: metadata,
|
|
241
|
+
originalPrice: finalOriginalPrice,
|
|
242
|
+
sellingPrice: composedSellingPrice,
|
|
243
|
+
quantity: getSafeProductNum(product.num)
|
|
244
|
+
});
|
|
207
245
|
return {
|
|
208
246
|
order_detail_id: product.order_detail_id || null,
|
|
209
247
|
product_id: product.product_id,
|
|
@@ -211,10 +249,10 @@ export function normalizeOrderProduct(product) {
|
|
|
211
249
|
product_variant_id: product.product_variant_id,
|
|
212
250
|
product_option_item: normalizedOptions,
|
|
213
251
|
selling_price: composedSellingPrice,
|
|
214
|
-
original_price:
|
|
252
|
+
original_price: finalOriginalPrice,
|
|
215
253
|
tax_fee: product.tax_fee || '0.00',
|
|
216
254
|
is_charge_tax: (_product$is_charge_ta = product.is_charge_tax) !== null && _product$is_charge_ta !== void 0 ? _product$is_charge_ta : 0,
|
|
217
|
-
discount_list:
|
|
255
|
+
discount_list: discountList,
|
|
218
256
|
product_bundle: normalizedBundle,
|
|
219
257
|
metadata: metadata,
|
|
220
258
|
note: product.note != null ? String(product.note) : ''
|