@pisell/pisellos 2.3.80 → 2.3.82
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/ProductList/clientDataVariants.d.ts +50 -0
- package/dist/modules/ProductList/clientDataVariants.js +216 -0
- package/dist/modules/ProductList/index.d.ts +14 -13
- package/dist/modules/ProductList/index.js +104 -76
- package/dist/solution/BaseSales/index.d.ts +16 -1
- package/dist/solution/BaseSales/index.js +530 -260
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/UnifiedBookingSales/index.js +2 -2
- package/dist/utils/platform.d.ts +8 -0
- package/dist/utils/platform.js +15 -0
- package/lib/modules/ProductList/clientDataVariants.d.ts +50 -0
- package/lib/modules/ProductList/clientDataVariants.js +204 -0
- package/lib/modules/ProductList/index.d.ts +14 -13
- package/lib/modules/ProductList/index.js +76 -57
- package/lib/solution/BaseSales/index.d.ts +16 -1
- package/lib/solution/BaseSales/index.js +269 -65
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/UnifiedBookingSales/index.js +2 -2
- package/lib/utils/platform.d.ts +8 -0
- package/lib/utils/platform.js +22 -0
- package/package.json +1 -1
|
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
326
326
|
date: string;
|
|
327
327
|
status: string;
|
|
328
328
|
week: string;
|
|
329
|
-
weekNum: 0 | 1 |
|
|
329
|
+
weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
330
330
|
}[]>;
|
|
331
331
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
332
332
|
private getScheduleDataByIds;
|
|
@@ -334,7 +334,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
334
334
|
* 获取当前的客户搜索条件
|
|
335
335
|
* @returns 当前搜索条件
|
|
336
336
|
*/
|
|
337
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
337
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
338
338
|
/**
|
|
339
339
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
340
340
|
* @returns 客户状态
|
|
@@ -42,6 +42,7 @@ import { UnifiedBookingSalesHooks } from "./types";
|
|
|
42
42
|
import { AvailabilityRemoteOccupancyCache } from "./remoteOccupancyCache";
|
|
43
43
|
import { BookingTicket } from "../BookingTicket";
|
|
44
44
|
import { addLocalCalendarDays, captureRuntimeOffsetMinutes, formatLocalDate, formatLocalDateTime, formatLocalTime, localDateTimeToScalar, localDateToScalar, localDateToScalarStart, parseLocalDate, parseLocalDateTime } from "../../modules/ResourcePlanner/localClock";
|
|
45
|
+
import { isCustomerUserPlatform } from "../../utils/platform";
|
|
45
46
|
export * from "./types";
|
|
46
47
|
export { AvailabilityError } from "../../modules/ResourcePlanner";
|
|
47
48
|
var OPEN_DATA_SECTION_CODES = ['sale', 'reservation', 'fulfillment', 'menu', 'workflow', 'basic', 'checkout', 'availability'];
|
|
@@ -1950,8 +1951,7 @@ export var UnifiedBookingSalesImpl = /*#__PURE__*/function (_BookingTicket) {
|
|
|
1950
1951
|
key: "isAuthenticatedCustomerUserPlatform",
|
|
1951
1952
|
value: function isAuthenticatedCustomerUserPlatform() {
|
|
1952
1953
|
var _this$otherParams14;
|
|
1953
|
-
|
|
1954
|
-
return platform === 'pc' || platform === 'h5';
|
|
1954
|
+
return isCustomerUserPlatform((_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.platform);
|
|
1955
1955
|
}
|
|
1956
1956
|
}, {
|
|
1957
1957
|
key: "resolveDiscountOrderIdentity",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize the runtime platform passed through solution/module otherParams.
|
|
3
|
+
*/
|
|
4
|
+
export declare function normalizeRuntimePlatform(platform: unknown): string;
|
|
5
|
+
/**
|
|
6
|
+
* PC and H5 are authenticated-customer clients rather than staff terminals.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isCustomerUserPlatform(platform: unknown): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var CUSTOMER_USER_PLATFORMS = new Set(['pc', 'h5']);
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalize the runtime platform passed through solution/module otherParams.
|
|
5
|
+
*/
|
|
6
|
+
export function normalizeRuntimePlatform(platform) {
|
|
7
|
+
return String(platform !== null && platform !== void 0 ? platform : '').trim().toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* PC and H5 are authenticated-customer clients rather than staff terminals.
|
|
12
|
+
*/
|
|
13
|
+
export function isCustomerUserPlatform(platform) {
|
|
14
|
+
return CUSTOMER_USER_PLATFORMS.has(normalizeRuntimePlatform(platform));
|
|
15
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { PisellCore } from '../../types';
|
|
2
|
+
import type { RequestPlugin } from '../../plugins';
|
|
3
|
+
import type { ProductData } from '../Product/types';
|
|
4
|
+
export declare const PRODUCT_QUERY_DATA_VARIANT_RELATIONS: readonly ["category", "collection", "resourceRelation", "bundleGroup.bundleItem", "optionGroup.optionItem", "variantGroup.variantItem", "dataVariants"];
|
|
5
|
+
/**
|
|
6
|
+
* 判断当前商品查询是否会被本地 OS Server 接管。
|
|
7
|
+
*
|
|
8
|
+
* H5 RequestPlugin 即使收到 osServer=true 仍会直接请求远端接口,因此必须按
|
|
9
|
+
* RequestPlugin 实际 baseUrl 对应的已注册路由判断,不能只看请求选项。
|
|
10
|
+
*/
|
|
11
|
+
export declare function isProductQueryHandledByOsServer(core: PisellCore | undefined, request: RequestPlugin | undefined): boolean;
|
|
12
|
+
export interface ResolveClientDataVariantsParams {
|
|
13
|
+
core: PisellCore | undefined;
|
|
14
|
+
otherParams?: Record<string, any>;
|
|
15
|
+
products: ProductData[];
|
|
16
|
+
queryPayload: Record<string, any>;
|
|
17
|
+
handledByOsServer: boolean;
|
|
18
|
+
scheduleList?: unknown;
|
|
19
|
+
menuList?: unknown;
|
|
20
|
+
/** Quote fast paths require hydrated relations; legacy list resolution does not. */
|
|
21
|
+
requireCompleteDataVariantRelations?: boolean;
|
|
22
|
+
/** Quote fast paths require every referenced rule; legacy list resolution is best-effort. */
|
|
23
|
+
requireEvaluatorReady?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type ResolveClientDataVariantsResult = {
|
|
26
|
+
status: 'handled-by-os-server' | 'empty' | 'data-variants-unavailable' | 'evaluator-unavailable' | 'evaluator-not-ready';
|
|
27
|
+
products: ProductData[];
|
|
28
|
+
} | {
|
|
29
|
+
status: 'resolved';
|
|
30
|
+
products: ProductData[];
|
|
31
|
+
} | {
|
|
32
|
+
status: 'error';
|
|
33
|
+
products: ProductData[];
|
|
34
|
+
error: unknown;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Strict client-side Data Variant resolution for quote fast paths.
|
|
38
|
+
*
|
|
39
|
+
* Unlike resolveClientDataVariants, callers can distinguish a complete local
|
|
40
|
+
* result from a capability/readiness/error fallback and decide to query the
|
|
41
|
+
* remote product endpoint instead.
|
|
42
|
+
*/
|
|
43
|
+
export declare function tryResolveClientDataVariants({ core, otherParams, products, queryPayload, handledByOsServer, scheduleList: explicitScheduleList, menuList: explicitMenuList, requireCompleteDataVariantRelations, requireEvaluatorReady, }: ResolveClientDataVariantsParams): ResolveClientDataVariantsResult;
|
|
44
|
+
/**
|
|
45
|
+
* 未启用商品 OS 路由时,在客户端补做 Data Variant 解析。
|
|
46
|
+
*
|
|
47
|
+
* 商品列表和预约报价必须共用这个边界,避免 H5 的弹窗报价绕过客户端智能定价。
|
|
48
|
+
* OS Server 已接管时直接信任服务端结果,确保同一批商品只评估一次。
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveClientDataVariants({ core, otherParams, products, queryPayload, handledByOsServer, scheduleList: explicitScheduleList, menuList: explicitMenuList, }: ResolveClientDataVariantsParams): ProductData[];
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PRODUCT_QUERY_DATA_VARIANT_RELATIONS = void 0;
|
|
7
|
+
exports.isProductQueryHandledByOsServer = isProductQueryHandledByOsServer;
|
|
8
|
+
exports.resolveClientDataVariants = resolveClientDataVariants;
|
|
9
|
+
exports.tryResolveClientDataVariants = tryResolveClientDataVariants;
|
|
10
|
+
const PRODUCT_QUERY_DATA_VARIANT_RELATIONS = exports.PRODUCT_QUERY_DATA_VARIANT_RELATIONS = ['category', 'collection', 'resourceRelation', 'bundleGroup.bundleItem', 'optionGroup.optionItem', 'variantGroup.variantItem', 'dataVariants'];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 判断当前商品查询是否会被本地 OS Server 接管。
|
|
14
|
+
*
|
|
15
|
+
* H5 RequestPlugin 即使收到 osServer=true 仍会直接请求远端接口,因此必须按
|
|
16
|
+
* RequestPlugin 实际 baseUrl 对应的已注册路由判断,不能只看请求选项。
|
|
17
|
+
*/
|
|
18
|
+
function isProductQueryHandledByOsServer(core, request) {
|
|
19
|
+
const server = core?.server;
|
|
20
|
+
if (!server || typeof server.hasRoute !== 'function') return false;
|
|
21
|
+
const requestBaseUrl = String(request?.baseUrl || '/shop').replace(/\/+$/, '');
|
|
22
|
+
return server.hasRoute('post', `${requestBaseUrl}/product/query`) === true;
|
|
23
|
+
}
|
|
24
|
+
function getBundleItems(product) {
|
|
25
|
+
if (!Array.isArray(product.bundle_group)) return [];
|
|
26
|
+
return product.bundle_group.flatMap(group => Array.isArray(group?.bundle_item) ? group.bundle_item : []);
|
|
27
|
+
}
|
|
28
|
+
function hasCompleteDataVariantRelations(products) {
|
|
29
|
+
return products.every(product => Array.isArray(product?.data_variants));
|
|
30
|
+
}
|
|
31
|
+
function hasAnyDataVariants(products) {
|
|
32
|
+
return products.some(product => (product.data_variants?.length || 0) > 0 || getBundleItems(product).some(item => Array.isArray(item?.data_variants) && item.data_variants.length > 0));
|
|
33
|
+
}
|
|
34
|
+
function collectReferencedRuleIds(products) {
|
|
35
|
+
const ids = new Set();
|
|
36
|
+
const remember = variants => {
|
|
37
|
+
if (!Array.isArray(variants)) return;
|
|
38
|
+
variants.forEach(variant => {
|
|
39
|
+
const id = String(variant?.data_variant_rule_id ?? '').trim();
|
|
40
|
+
if (id) ids.add(id);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
products.forEach(product => {
|
|
44
|
+
remember(product.data_variants);
|
|
45
|
+
getBundleItems(product).forEach(item => remember(item?.data_variants));
|
|
46
|
+
});
|
|
47
|
+
return ids;
|
|
48
|
+
}
|
|
49
|
+
function isEvaluatorReady(evaluator, products) {
|
|
50
|
+
if (typeof evaluator.isReady === 'function') {
|
|
51
|
+
if (evaluator.isReady() === false) return false;
|
|
52
|
+
}
|
|
53
|
+
if (evaluator.isReady === false || evaluator.ready === false) return false;
|
|
54
|
+
|
|
55
|
+
// The built-in evaluator is installed before its strategy request completes.
|
|
56
|
+
// A referenced Data Variant cannot be evaluated authoritatively until those
|
|
57
|
+
// configs have arrived. Evaluators without this capability remain compatible.
|
|
58
|
+
if (typeof evaluator.getStrategyConfigs === 'function') {
|
|
59
|
+
const configs = evaluator.getStrategyConfigs();
|
|
60
|
+
if (!Array.isArray(configs) || configs.length === 0) return false;
|
|
61
|
+
const availableRuleIds = new Set(configs.map(config => String(config?.metadata?.id ?? '').trim()).filter(Boolean));
|
|
62
|
+
return Array.from(collectReferencedRuleIds(products)).every(id => availableRuleIds.has(id));
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Strict client-side Data Variant resolution for quote fast paths.
|
|
69
|
+
*
|
|
70
|
+
* Unlike resolveClientDataVariants, callers can distinguish a complete local
|
|
71
|
+
* result from a capability/readiness/error fallback and decide to query the
|
|
72
|
+
* remote product endpoint instead.
|
|
73
|
+
*/
|
|
74
|
+
function tryResolveClientDataVariants({
|
|
75
|
+
core,
|
|
76
|
+
otherParams = {},
|
|
77
|
+
products,
|
|
78
|
+
queryPayload,
|
|
79
|
+
handledByOsServer,
|
|
80
|
+
scheduleList: explicitScheduleList,
|
|
81
|
+
menuList: explicitMenuList,
|
|
82
|
+
requireCompleteDataVariantRelations = true,
|
|
83
|
+
requireEvaluatorReady = true
|
|
84
|
+
}) {
|
|
85
|
+
if (handledByOsServer) {
|
|
86
|
+
return {
|
|
87
|
+
status: 'handled-by-os-server',
|
|
88
|
+
products
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (products.length === 0) {
|
|
92
|
+
return {
|
|
93
|
+
status: 'empty',
|
|
94
|
+
products
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (requireCompleteDataVariantRelations && !hasCompleteDataVariantRelations(products)) {
|
|
98
|
+
return {
|
|
99
|
+
status: 'data-variants-unavailable',
|
|
100
|
+
products
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Explicit empty arrays mean the query hydrated the relation and there is no
|
|
105
|
+
// rule to apply. This is an authoritative local base-price result even when
|
|
106
|
+
// no evaluator has been installed.
|
|
107
|
+
if (!hasAnyDataVariants(products)) {
|
|
108
|
+
return {
|
|
109
|
+
status: 'resolved',
|
|
110
|
+
products
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const evaluator = core?.context?.dataVariantEvaluator;
|
|
114
|
+
if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
|
|
115
|
+
return {
|
|
116
|
+
status: 'evaluator-unavailable',
|
|
117
|
+
products
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
if (requireEvaluatorReady && !isEvaluatorReady(evaluator, products)) {
|
|
122
|
+
return {
|
|
123
|
+
status: 'evaluator-not-ready',
|
|
124
|
+
products
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
} catch (error) {
|
|
128
|
+
return {
|
|
129
|
+
status: 'error',
|
|
130
|
+
products,
|
|
131
|
+
error
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const strategyContext = queryPayload.strategy_context && typeof queryPayload.strategy_context === 'object' ? queryPayload.strategy_context : {};
|
|
135
|
+
const fatherModule = String(otherParams.fatherModule || '').trim();
|
|
136
|
+
const scheduleModule = (fatherModule ? core?.getModule(`${fatherModule}_schedule`) : null) || core?.getModule('schedule');
|
|
137
|
+
const moduleScheduleList = scheduleModule?.getScheduleList?.();
|
|
138
|
+
const contextScheduleList = core?.context?.scheduleList;
|
|
139
|
+
const contextMenuList = core?.context?.menuList;
|
|
140
|
+
const businessData = {
|
|
141
|
+
products,
|
|
142
|
+
scheduleDateTime: queryPayload.schedule_datetime || queryPayload.schedule_date,
|
|
143
|
+
scheduleList: Array.isArray(explicitScheduleList) && explicitScheduleList.length > 0 ? explicitScheduleList : Array.isArray(moduleScheduleList) && moduleScheduleList.length > 0 ? moduleScheduleList : Array.isArray(contextScheduleList) ? contextScheduleList : [],
|
|
144
|
+
menuList: Array.isArray(explicitMenuList) ? explicitMenuList : Array.isArray(otherParams.menuList) ? otherParams.menuList : Array.isArray(contextMenuList) ? contextMenuList : [],
|
|
145
|
+
customerId: queryPayload.customer_id,
|
|
146
|
+
channel: strategyContext.channel,
|
|
147
|
+
orderType: strategyContext.orderType || strategyContext.order_type,
|
|
148
|
+
businessCode: strategyContext.business_code ?? strategyContext.businessCode,
|
|
149
|
+
availableWalletIds: strategyContext.available_wallet_ids,
|
|
150
|
+
custom: strategyContext
|
|
151
|
+
};
|
|
152
|
+
try {
|
|
153
|
+
const result = evaluator.resolveProducts(businessData);
|
|
154
|
+
if (!Array.isArray(result?.products)) {
|
|
155
|
+
return {
|
|
156
|
+
status: 'error',
|
|
157
|
+
products,
|
|
158
|
+
error: new Error('Data Variant evaluator returned an invalid product list')
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
status: 'resolved',
|
|
163
|
+
products: result.products
|
|
164
|
+
};
|
|
165
|
+
} catch (error) {
|
|
166
|
+
return {
|
|
167
|
+
status: 'error',
|
|
168
|
+
products,
|
|
169
|
+
error
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 未启用商品 OS 路由时,在客户端补做 Data Variant 解析。
|
|
176
|
+
*
|
|
177
|
+
* 商品列表和预约报价必须共用这个边界,避免 H5 的弹窗报价绕过客户端智能定价。
|
|
178
|
+
* OS Server 已接管时直接信任服务端结果,确保同一批商品只评估一次。
|
|
179
|
+
*/
|
|
180
|
+
function resolveClientDataVariants({
|
|
181
|
+
core,
|
|
182
|
+
otherParams = {},
|
|
183
|
+
products,
|
|
184
|
+
queryPayload,
|
|
185
|
+
handledByOsServer,
|
|
186
|
+
scheduleList: explicitScheduleList,
|
|
187
|
+
menuList: explicitMenuList
|
|
188
|
+
}) {
|
|
189
|
+
const result = tryResolveClientDataVariants({
|
|
190
|
+
core,
|
|
191
|
+
otherParams,
|
|
192
|
+
products,
|
|
193
|
+
queryPayload,
|
|
194
|
+
handledByOsServer,
|
|
195
|
+
scheduleList: explicitScheduleList,
|
|
196
|
+
menuList: explicitMenuList,
|
|
197
|
+
requireCompleteDataVariantRelations: false,
|
|
198
|
+
requireEvaluatorReady: false
|
|
199
|
+
});
|
|
200
|
+
if (result.status === 'error') {
|
|
201
|
+
console.error('[ClientDataVariants] Data Variant 客户端解析失败', result.error);
|
|
202
|
+
}
|
|
203
|
+
return result.products;
|
|
204
|
+
}
|
|
@@ -9,6 +9,7 @@ export declare class ProductList extends BaseModule implements Module {
|
|
|
9
9
|
private store;
|
|
10
10
|
private request;
|
|
11
11
|
private otherParams;
|
|
12
|
+
private rawProductPriceSources;
|
|
12
13
|
constructor(name?: string, version?: string);
|
|
13
14
|
initialize(core: PisellCore, options: any): Promise<void>;
|
|
14
15
|
/**
|
|
@@ -18,19 +19,6 @@ export declare class ProductList extends BaseModule implements Module {
|
|
|
18
19
|
* productList.updateOtherParams({ channel: 'pos' });
|
|
19
20
|
*/
|
|
20
21
|
updateOtherParams(params: Record<string, any>): void;
|
|
21
|
-
/**
|
|
22
|
-
* 判断当前商品查询是否会被本地 OS Server 接管。
|
|
23
|
-
*
|
|
24
|
-
* 不能只看请求参数中的 osServer=true:H5 RequestPlugin 会透传该参数,但仍然直接请求远端接口。
|
|
25
|
-
* 这里按 RequestPlugin 实际使用的 baseUrl 检查已注册路由,避免 OS Server 与客户端重复执行
|
|
26
|
-
* Data Variant 评估。
|
|
27
|
-
*/
|
|
28
|
-
private isProductQueryHandledByOsServer;
|
|
29
|
-
/**
|
|
30
|
-
* 未启用商品 OS 路由时,在客户端补做 Data Variant 解析。
|
|
31
|
-
* OS Server 已接管时直接信任服务端结果,确保同一批商品只评估一次。
|
|
32
|
-
*/
|
|
33
|
-
private resolveClientDataVariants;
|
|
34
22
|
storeChange(path?: string, value?: any): Promise<void>;
|
|
35
23
|
/**
|
|
36
24
|
* 获取加时商品列表。
|
|
@@ -49,6 +37,19 @@ export declare class ProductList extends BaseModule implements Module {
|
|
|
49
37
|
schedule_date?: string;
|
|
50
38
|
channel?: string;
|
|
51
39
|
}): Promise<any>;
|
|
40
|
+
/**
|
|
41
|
+
* Remember raw remote product records before client-side Data Variant
|
|
42
|
+
* evaluation. Quote-only reads can then always start from a clean baseline.
|
|
43
|
+
*/
|
|
44
|
+
rememberRawProductQueryResult(products: Array<ProductData | Record<string, any>>): void;
|
|
45
|
+
private replaceRawProductQueryResult;
|
|
46
|
+
/**
|
|
47
|
+
* Return isolated raw price sources for the requested products.
|
|
48
|
+
*
|
|
49
|
+
* Missing IDs are intentionally omitted so callers can remotely fetch only
|
|
50
|
+
* the incomplete part of a batch quote.
|
|
51
|
+
*/
|
|
52
|
+
getRawProductPriceSources(ids: number[]): Map<number, ProductData>;
|
|
52
53
|
getProducts(): Promise<ProductData[]>;
|
|
53
54
|
getProduct(id: number): Promise<ProductData | undefined>;
|
|
54
55
|
getProductByIds(ids: number[]): Promise<ProductData[] | undefined>;
|
|
@@ -10,6 +10,8 @@ exports.ProductList = void 0;
|
|
|
10
10
|
var _BaseModule = require("../BaseModule");
|
|
11
11
|
var _lodashEs = require("lodash-es");
|
|
12
12
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
13
|
+
var _clientDataVariants = require("./clientDataVariants");
|
|
14
|
+
var _platform = require("../../utils/platform");
|
|
13
15
|
var _types = require("./types");
|
|
14
16
|
Object.keys(_types).forEach(function (key) {
|
|
15
17
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -29,6 +31,7 @@ class ProductList extends _BaseModule.BaseModule {
|
|
|
29
31
|
store;
|
|
30
32
|
request;
|
|
31
33
|
otherParams = {};
|
|
34
|
+
rawProductPriceSources = new Map();
|
|
32
35
|
constructor(name, version) {
|
|
33
36
|
super(name, version);
|
|
34
37
|
}
|
|
@@ -36,6 +39,7 @@ class ProductList extends _BaseModule.BaseModule {
|
|
|
36
39
|
this.core = core;
|
|
37
40
|
this.store = options.store;
|
|
38
41
|
this.otherParams = options.otherParams || {};
|
|
42
|
+
this.rawProductPriceSources.clear();
|
|
39
43
|
if (Array.isArray(options.initialState?.list)) {
|
|
40
44
|
this.store.list = options.initialState.list.slice().sort((a, b) => Number(b.sort) - Number(a.sort));
|
|
41
45
|
this.core.effects.emit(`${this.name}:changed`, this.store.list);
|
|
@@ -55,58 +59,6 @@ class ProductList extends _BaseModule.BaseModule {
|
|
|
55
59
|
updateOtherParams(params) {
|
|
56
60
|
this.otherParams = params || {};
|
|
57
61
|
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* 判断当前商品查询是否会被本地 OS Server 接管。
|
|
61
|
-
*
|
|
62
|
-
* 不能只看请求参数中的 osServer=true:H5 RequestPlugin 会透传该参数,但仍然直接请求远端接口。
|
|
63
|
-
* 这里按 RequestPlugin 实际使用的 baseUrl 检查已注册路由,避免 OS Server 与客户端重复执行
|
|
64
|
-
* Data Variant 评估。
|
|
65
|
-
*/
|
|
66
|
-
isProductQueryHandledByOsServer() {
|
|
67
|
-
const server = this.core?.server;
|
|
68
|
-
if (!server || typeof server.hasRoute !== 'function') return false;
|
|
69
|
-
const requestBaseUrl = String(this.request?.baseUrl || '/shop').replace(/\/+$/, '');
|
|
70
|
-
const routePath = `${requestBaseUrl}/product/query`;
|
|
71
|
-
return server.hasRoute('post', routePath) === true;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 未启用商品 OS 路由时,在客户端补做 Data Variant 解析。
|
|
76
|
-
* OS Server 已接管时直接信任服务端结果,确保同一批商品只评估一次。
|
|
77
|
-
*/
|
|
78
|
-
resolveClientDataVariants(products, queryPayload, handledByOsServer) {
|
|
79
|
-
if (handledByOsServer || products.length === 0) return products;
|
|
80
|
-
const evaluator = this.core?.context?.dataVariantEvaluator;
|
|
81
|
-
if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
|
|
82
|
-
return products;
|
|
83
|
-
}
|
|
84
|
-
const strategyContext = queryPayload.strategy_context && typeof queryPayload.strategy_context === 'object' ? queryPayload.strategy_context : {};
|
|
85
|
-
const fatherModule = String(this.otherParams?.fatherModule || '').trim();
|
|
86
|
-
const scheduleModule = (fatherModule ? this.core.getModule(`${fatherModule}_schedule`) : null) || this.core.getModule('schedule');
|
|
87
|
-
const scheduleList = scheduleModule?.getScheduleList?.();
|
|
88
|
-
const contextScheduleList = this.core?.context?.scheduleList;
|
|
89
|
-
const contextMenuList = this.core?.context?.menuList;
|
|
90
|
-
const businessData = {
|
|
91
|
-
products,
|
|
92
|
-
scheduleDateTime: queryPayload.schedule_datetime || queryPayload.schedule_date,
|
|
93
|
-
scheduleList: Array.isArray(scheduleList) ? scheduleList : Array.isArray(contextScheduleList) ? contextScheduleList : [],
|
|
94
|
-
menuList: Array.isArray(this.otherParams?.menuList) ? this.otherParams.menuList : Array.isArray(contextMenuList) ? contextMenuList : [],
|
|
95
|
-
customerId: queryPayload.customer_id,
|
|
96
|
-
channel: strategyContext.channel,
|
|
97
|
-
orderType: strategyContext.orderType || strategyContext.order_type,
|
|
98
|
-
businessCode: strategyContext.business_code ?? strategyContext.businessCode,
|
|
99
|
-
availableWalletIds: strategyContext.available_wallet_ids,
|
|
100
|
-
custom: strategyContext
|
|
101
|
-
};
|
|
102
|
-
try {
|
|
103
|
-
const result = evaluator.resolveProducts(businessData);
|
|
104
|
-
return Array.isArray(result?.products) ? result.products : products;
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error('[ProductList] Data Variant 客户端解析失败', error);
|
|
107
|
-
return products;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
62
|
async storeChange(path, value) {
|
|
111
63
|
// No longer needed - products are stored as plain objects instead of Product instances
|
|
112
64
|
}
|
|
@@ -170,10 +122,12 @@ class ProductList extends _BaseModule.BaseModule {
|
|
|
170
122
|
const rawApplicationCode = this.otherParams?.channel;
|
|
171
123
|
const mappedApplicationCode = typeof rawApplicationCode === 'string' ? channelMap[rawApplicationCode] || rawApplicationCode : rawApplicationCode;
|
|
172
124
|
const queryPayload = {
|
|
173
|
-
|
|
125
|
+
...((0, _platform.isCustomerUserPlatform)(this.otherParams?.platform) ? {} : {
|
|
126
|
+
open_quotation: 1
|
|
127
|
+
}),
|
|
174
128
|
open_bundle: 0,
|
|
175
129
|
exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
|
|
176
|
-
with: [
|
|
130
|
+
with: [..._clientDataVariants.PRODUCT_QUERY_DATA_VARIANT_RELATIONS],
|
|
177
131
|
status,
|
|
178
132
|
num: 500,
|
|
179
133
|
skip: 1,
|
|
@@ -201,7 +155,7 @@ class ProductList extends _BaseModule.BaseModule {
|
|
|
201
155
|
extension_type,
|
|
202
156
|
strategy_context
|
|
203
157
|
};
|
|
204
|
-
const handledByOsServer =
|
|
158
|
+
const handledByOsServer = (0, _clientDataVariants.isProductQueryHandledByOsServer)(this.core, this.request);
|
|
205
159
|
const originalCallback = options?.callback;
|
|
206
160
|
const subscriptionCallback = typeof originalCallback === 'function' ? async result => {
|
|
207
161
|
const callbackList = result?.data?.list;
|
|
@@ -209,7 +163,18 @@ class ProductList extends _BaseModule.BaseModule {
|
|
|
209
163
|
originalCallback(result);
|
|
210
164
|
return;
|
|
211
165
|
}
|
|
212
|
-
|
|
166
|
+
if (!handledByOsServer) {
|
|
167
|
+
// Subscription callbacks may contain only changed products. Upsert
|
|
168
|
+
// their raw records without evicting other IDs from the scope.
|
|
169
|
+
this.rememberRawProductQueryResult(callbackList);
|
|
170
|
+
}
|
|
171
|
+
const products = (0, _clientDataVariants.resolveClientDataVariants)({
|
|
172
|
+
core: this.core,
|
|
173
|
+
otherParams: this.otherParams,
|
|
174
|
+
products: callbackList,
|
|
175
|
+
queryPayload,
|
|
176
|
+
handledByOsServer
|
|
177
|
+
});
|
|
213
178
|
await this.addProduct(products);
|
|
214
179
|
originalCallback(handledByOsServer ? result : {
|
|
215
180
|
...result,
|
|
@@ -225,7 +190,16 @@ class ProductList extends _BaseModule.BaseModule {
|
|
|
225
190
|
subscriberId: options?.subscriberId,
|
|
226
191
|
customToast: () => {}
|
|
227
192
|
});
|
|
228
|
-
|
|
193
|
+
if (!handledByOsServer && Array.isArray(productsData.data.list)) {
|
|
194
|
+
this.replaceRawProductQueryResult(productsData.data.list, product_ids);
|
|
195
|
+
}
|
|
196
|
+
const resolvedList = (0, _clientDataVariants.resolveClientDataVariants)({
|
|
197
|
+
core: this.core,
|
|
198
|
+
otherParams: this.otherParams,
|
|
199
|
+
products: productsData.data.list || [],
|
|
200
|
+
queryPayload,
|
|
201
|
+
handledByOsServer
|
|
202
|
+
});
|
|
229
203
|
const sortedList = resolvedList.slice().sort((a, b) => Number(b.sort) - Number(a.sort));
|
|
230
204
|
// if (sortedList.length) {
|
|
231
205
|
// sortedList.forEach((n: any) => {
|
|
@@ -253,6 +227,51 @@ class ProductList extends _BaseModule.BaseModule {
|
|
|
253
227
|
});
|
|
254
228
|
return productsData.data;
|
|
255
229
|
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Remember raw remote product records before client-side Data Variant
|
|
233
|
+
* evaluation. Quote-only reads can then always start from a clean baseline.
|
|
234
|
+
*/
|
|
235
|
+
rememberRawProductQueryResult(products) {
|
|
236
|
+
if (!Array.isArray(products)) return;
|
|
237
|
+
products.forEach(product => {
|
|
238
|
+
const source = product;
|
|
239
|
+
const id = Number(source?.id ?? source?.product_id);
|
|
240
|
+
if (!Number.isFinite(id)) return;
|
|
241
|
+
this.rawProductPriceSources.set(id, (0, _lodashEs.cloneDeep)(product));
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
replaceRawProductQueryResult(products, requestedIds) {
|
|
245
|
+
if (Array.isArray(requestedIds) && requestedIds.length > 0) {
|
|
246
|
+
requestedIds.forEach(rawId => {
|
|
247
|
+
const id = Number(rawId);
|
|
248
|
+
if (Number.isFinite(id)) this.rawProductPriceSources.delete(id);
|
|
249
|
+
});
|
|
250
|
+
} else {
|
|
251
|
+
// A non-ID query represents the latest catalog scope. Clearing before
|
|
252
|
+
// replacing prevents removed products from surviving indefinitely.
|
|
253
|
+
this.rawProductPriceSources.clear();
|
|
254
|
+
}
|
|
255
|
+
this.rememberRawProductQueryResult(products);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Return isolated raw price sources for the requested products.
|
|
260
|
+
*
|
|
261
|
+
* Missing IDs are intentionally omitted so callers can remotely fetch only
|
|
262
|
+
* the incomplete part of a batch quote.
|
|
263
|
+
*/
|
|
264
|
+
getRawProductPriceSources(ids) {
|
|
265
|
+
const products = new Map();
|
|
266
|
+
if (!Array.isArray(ids)) return products;
|
|
267
|
+
ids.forEach(rawId => {
|
|
268
|
+
const id = Number(rawId);
|
|
269
|
+
if (!Number.isFinite(id) || products.has(id)) return;
|
|
270
|
+
const product = this.rawProductPriceSources.get(id);
|
|
271
|
+
if (product) products.set(id, (0, _lodashEs.cloneDeep)(product));
|
|
272
|
+
});
|
|
273
|
+
return products;
|
|
274
|
+
}
|
|
256
275
|
async getProducts() {
|
|
257
276
|
await this.core.effects.emit(`${this.name}:onGetProducts`, this.store.list);
|
|
258
277
|
return (0, _lodashEs.cloneDeep)(this.store.list);
|
|
@@ -129,8 +129,23 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
129
129
|
*/
|
|
130
130
|
protected preferAuthoritativeProductQueryPrice(): boolean;
|
|
131
131
|
private getPriceQuerySchedule;
|
|
132
|
+
private isCustomerUserPriceQuery;
|
|
133
|
+
private getPriceQueryScheduleList;
|
|
134
|
+
private buildPriceQueryPayload;
|
|
135
|
+
private getRawProductPriceSources;
|
|
136
|
+
private rememberRawProductPriceSources;
|
|
137
|
+
private getSelectedProductVariantId;
|
|
138
|
+
/**
|
|
139
|
+
* 将目录原始商品还原为本次选择的 SKU 基线。
|
|
140
|
+
*
|
|
141
|
+
* 这里绝不能复用已评估后的目录商品,否则从命中智能价切回不命中的
|
|
142
|
+
* 日期时会残留旧价格。套餐仅验证所选关系存在,最终仍由 merge 方法把
|
|
143
|
+
* 评估后的套餐价格映射回用户的选择数据。
|
|
144
|
+
*/
|
|
145
|
+
private prepareRawProductForPriceQuery;
|
|
146
|
+
private resolveLocalProductForPriceQuery;
|
|
132
147
|
private loadProductsForPriceQuery;
|
|
133
|
-
private
|
|
148
|
+
private resolveProductsForPriceQuery;
|
|
134
149
|
private getAuthoritativeBundleItems;
|
|
135
150
|
private findAuthoritativeBundleItem;
|
|
136
151
|
private getAuthoritativeBundleUnitPrice;
|