@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
|
@@ -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,216 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
export var PRODUCT_QUERY_DATA_VARIANT_RELATIONS = ['category', 'collection', 'resourceRelation', 'bundleGroup.bundleItem', 'optionGroup.optionItem', 'variantGroup.variantItem', 'dataVariants'];
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 判断当前商品查询是否会被本地 OS Server 接管。
|
|
6
|
+
*
|
|
7
|
+
* H5 RequestPlugin 即使收到 osServer=true 仍会直接请求远端接口,因此必须按
|
|
8
|
+
* RequestPlugin 实际 baseUrl 对应的已注册路由判断,不能只看请求选项。
|
|
9
|
+
*/
|
|
10
|
+
export function isProductQueryHandledByOsServer(core, request) {
|
|
11
|
+
var server = core === null || core === void 0 ? void 0 : core.server;
|
|
12
|
+
if (!server || typeof server.hasRoute !== 'function') return false;
|
|
13
|
+
var requestBaseUrl = String((request === null || request === void 0 ? void 0 : request.baseUrl) || '/shop').replace(/\/+$/, '');
|
|
14
|
+
return server.hasRoute('post', "".concat(requestBaseUrl, "/product/query")) === true;
|
|
15
|
+
}
|
|
16
|
+
function getBundleItems(product) {
|
|
17
|
+
if (!Array.isArray(product.bundle_group)) return [];
|
|
18
|
+
return product.bundle_group.flatMap(function (group) {
|
|
19
|
+
return Array.isArray(group === null || group === void 0 ? void 0 : group.bundle_item) ? group.bundle_item : [];
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function hasCompleteDataVariantRelations(products) {
|
|
23
|
+
return products.every(function (product) {
|
|
24
|
+
return Array.isArray(product === null || product === void 0 ? void 0 : product.data_variants);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function hasAnyDataVariants(products) {
|
|
28
|
+
return products.some(function (product) {
|
|
29
|
+
var _product$data_variant;
|
|
30
|
+
return (((_product$data_variant = product.data_variants) === null || _product$data_variant === void 0 ? void 0 : _product$data_variant.length) || 0) > 0 || getBundleItems(product).some(function (item) {
|
|
31
|
+
return Array.isArray(item === null || item === void 0 ? void 0 : item.data_variants) && item.data_variants.length > 0;
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function collectReferencedRuleIds(products) {
|
|
36
|
+
var ids = new Set();
|
|
37
|
+
var remember = function remember(variants) {
|
|
38
|
+
if (!Array.isArray(variants)) return;
|
|
39
|
+
variants.forEach(function (variant) {
|
|
40
|
+
var _variant$data_variant;
|
|
41
|
+
var id = String((_variant$data_variant = variant === null || variant === void 0 ? void 0 : variant.data_variant_rule_id) !== null && _variant$data_variant !== void 0 ? _variant$data_variant : '').trim();
|
|
42
|
+
if (id) ids.add(id);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
products.forEach(function (product) {
|
|
46
|
+
remember(product.data_variants);
|
|
47
|
+
getBundleItems(product).forEach(function (item) {
|
|
48
|
+
return remember(item === null || item === void 0 ? void 0 : item.data_variants);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
return ids;
|
|
52
|
+
}
|
|
53
|
+
function isEvaluatorReady(evaluator, products) {
|
|
54
|
+
if (typeof evaluator.isReady === 'function') {
|
|
55
|
+
if (evaluator.isReady() === false) return false;
|
|
56
|
+
}
|
|
57
|
+
if (evaluator.isReady === false || evaluator.ready === false) return false;
|
|
58
|
+
|
|
59
|
+
// The built-in evaluator is installed before its strategy request completes.
|
|
60
|
+
// A referenced Data Variant cannot be evaluated authoritatively until those
|
|
61
|
+
// configs have arrived. Evaluators without this capability remain compatible.
|
|
62
|
+
if (typeof evaluator.getStrategyConfigs === 'function') {
|
|
63
|
+
var configs = evaluator.getStrategyConfigs();
|
|
64
|
+
if (!Array.isArray(configs) || configs.length === 0) return false;
|
|
65
|
+
var availableRuleIds = new Set(configs.map(function (config) {
|
|
66
|
+
var _config$metadata$id, _config$metadata;
|
|
67
|
+
return String((_config$metadata$id = config === null || config === void 0 || (_config$metadata = config.metadata) === null || _config$metadata === void 0 ? void 0 : _config$metadata.id) !== null && _config$metadata$id !== void 0 ? _config$metadata$id : '').trim();
|
|
68
|
+
}).filter(Boolean));
|
|
69
|
+
return Array.from(collectReferencedRuleIds(products)).every(function (id) {
|
|
70
|
+
return availableRuleIds.has(id);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Strict client-side Data Variant resolution for quote fast paths.
|
|
78
|
+
*
|
|
79
|
+
* Unlike resolveClientDataVariants, callers can distinguish a complete local
|
|
80
|
+
* result from a capability/readiness/error fallback and decide to query the
|
|
81
|
+
* remote product endpoint instead.
|
|
82
|
+
*/
|
|
83
|
+
export function tryResolveClientDataVariants(_ref) {
|
|
84
|
+
var _core$context, _scheduleModule$getSc, _core$context2, _core$context3, _strategyContext$busi;
|
|
85
|
+
var core = _ref.core,
|
|
86
|
+
_ref$otherParams = _ref.otherParams,
|
|
87
|
+
otherParams = _ref$otherParams === void 0 ? {} : _ref$otherParams,
|
|
88
|
+
products = _ref.products,
|
|
89
|
+
queryPayload = _ref.queryPayload,
|
|
90
|
+
handledByOsServer = _ref.handledByOsServer,
|
|
91
|
+
explicitScheduleList = _ref.scheduleList,
|
|
92
|
+
explicitMenuList = _ref.menuList,
|
|
93
|
+
_ref$requireCompleteD = _ref.requireCompleteDataVariantRelations,
|
|
94
|
+
requireCompleteDataVariantRelations = _ref$requireCompleteD === void 0 ? true : _ref$requireCompleteD,
|
|
95
|
+
_ref$requireEvaluator = _ref.requireEvaluatorReady,
|
|
96
|
+
requireEvaluatorReady = _ref$requireEvaluator === void 0 ? true : _ref$requireEvaluator;
|
|
97
|
+
if (handledByOsServer) {
|
|
98
|
+
return {
|
|
99
|
+
status: 'handled-by-os-server',
|
|
100
|
+
products: products
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (products.length === 0) {
|
|
104
|
+
return {
|
|
105
|
+
status: 'empty',
|
|
106
|
+
products: products
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (requireCompleteDataVariantRelations && !hasCompleteDataVariantRelations(products)) {
|
|
110
|
+
return {
|
|
111
|
+
status: 'data-variants-unavailable',
|
|
112
|
+
products: products
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Explicit empty arrays mean the query hydrated the relation and there is no
|
|
117
|
+
// rule to apply. This is an authoritative local base-price result even when
|
|
118
|
+
// no evaluator has been installed.
|
|
119
|
+
if (!hasAnyDataVariants(products)) {
|
|
120
|
+
return {
|
|
121
|
+
status: 'resolved',
|
|
122
|
+
products: products
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
var evaluator = core === null || core === void 0 || (_core$context = core.context) === null || _core$context === void 0 ? void 0 : _core$context.dataVariantEvaluator;
|
|
126
|
+
if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
|
|
127
|
+
return {
|
|
128
|
+
status: 'evaluator-unavailable',
|
|
129
|
+
products: products
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
if (requireEvaluatorReady && !isEvaluatorReady(evaluator, products)) {
|
|
134
|
+
return {
|
|
135
|
+
status: 'evaluator-not-ready',
|
|
136
|
+
products: products
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return {
|
|
141
|
+
status: 'error',
|
|
142
|
+
products: products,
|
|
143
|
+
error: error
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
var strategyContext = queryPayload.strategy_context && _typeof(queryPayload.strategy_context) === 'object' ? queryPayload.strategy_context : {};
|
|
147
|
+
var fatherModule = String(otherParams.fatherModule || '').trim();
|
|
148
|
+
var scheduleModule = (fatherModule ? core === null || core === void 0 ? void 0 : core.getModule("".concat(fatherModule, "_schedule")) : null) || (core === null || core === void 0 ? void 0 : core.getModule('schedule'));
|
|
149
|
+
var moduleScheduleList = scheduleModule === null || scheduleModule === void 0 || (_scheduleModule$getSc = scheduleModule.getScheduleList) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule);
|
|
150
|
+
var contextScheduleList = core === null || core === void 0 || (_core$context2 = core.context) === null || _core$context2 === void 0 ? void 0 : _core$context2.scheduleList;
|
|
151
|
+
var contextMenuList = core === null || core === void 0 || (_core$context3 = core.context) === null || _core$context3 === void 0 ? void 0 : _core$context3.menuList;
|
|
152
|
+
var businessData = {
|
|
153
|
+
products: products,
|
|
154
|
+
scheduleDateTime: queryPayload.schedule_datetime || queryPayload.schedule_date,
|
|
155
|
+
scheduleList: Array.isArray(explicitScheduleList) && explicitScheduleList.length > 0 ? explicitScheduleList : Array.isArray(moduleScheduleList) && moduleScheduleList.length > 0 ? moduleScheduleList : Array.isArray(contextScheduleList) ? contextScheduleList : [],
|
|
156
|
+
menuList: Array.isArray(explicitMenuList) ? explicitMenuList : Array.isArray(otherParams.menuList) ? otherParams.menuList : Array.isArray(contextMenuList) ? contextMenuList : [],
|
|
157
|
+
customerId: queryPayload.customer_id,
|
|
158
|
+
channel: strategyContext.channel,
|
|
159
|
+
orderType: strategyContext.orderType || strategyContext.order_type,
|
|
160
|
+
businessCode: (_strategyContext$busi = strategyContext.business_code) !== null && _strategyContext$busi !== void 0 ? _strategyContext$busi : strategyContext.businessCode,
|
|
161
|
+
availableWalletIds: strategyContext.available_wallet_ids,
|
|
162
|
+
custom: strategyContext
|
|
163
|
+
};
|
|
164
|
+
try {
|
|
165
|
+
var result = evaluator.resolveProducts(businessData);
|
|
166
|
+
if (!Array.isArray(result === null || result === void 0 ? void 0 : result.products)) {
|
|
167
|
+
return {
|
|
168
|
+
status: 'error',
|
|
169
|
+
products: products,
|
|
170
|
+
error: new Error('Data Variant evaluator returned an invalid product list')
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
status: 'resolved',
|
|
175
|
+
products: result.products
|
|
176
|
+
};
|
|
177
|
+
} catch (error) {
|
|
178
|
+
return {
|
|
179
|
+
status: 'error',
|
|
180
|
+
products: products,
|
|
181
|
+
error: error
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 未启用商品 OS 路由时,在客户端补做 Data Variant 解析。
|
|
188
|
+
*
|
|
189
|
+
* 商品列表和预约报价必须共用这个边界,避免 H5 的弹窗报价绕过客户端智能定价。
|
|
190
|
+
* OS Server 已接管时直接信任服务端结果,确保同一批商品只评估一次。
|
|
191
|
+
*/
|
|
192
|
+
export function resolveClientDataVariants(_ref2) {
|
|
193
|
+
var core = _ref2.core,
|
|
194
|
+
_ref2$otherParams = _ref2.otherParams,
|
|
195
|
+
otherParams = _ref2$otherParams === void 0 ? {} : _ref2$otherParams,
|
|
196
|
+
products = _ref2.products,
|
|
197
|
+
queryPayload = _ref2.queryPayload,
|
|
198
|
+
handledByOsServer = _ref2.handledByOsServer,
|
|
199
|
+
explicitScheduleList = _ref2.scheduleList,
|
|
200
|
+
explicitMenuList = _ref2.menuList;
|
|
201
|
+
var result = tryResolveClientDataVariants({
|
|
202
|
+
core: core,
|
|
203
|
+
otherParams: otherParams,
|
|
204
|
+
products: products,
|
|
205
|
+
queryPayload: queryPayload,
|
|
206
|
+
handledByOsServer: handledByOsServer,
|
|
207
|
+
scheduleList: explicitScheduleList,
|
|
208
|
+
menuList: explicitMenuList,
|
|
209
|
+
requireCompleteDataVariantRelations: false,
|
|
210
|
+
requireEvaluatorReady: false
|
|
211
|
+
});
|
|
212
|
+
if (result.status === 'error') {
|
|
213
|
+
console.error('[ClientDataVariants] Data Variant 客户端解析失败', result.error);
|
|
214
|
+
}
|
|
215
|
+
return result.products;
|
|
216
|
+
}
|
|
@@ -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>;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
1
8
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
9
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
10
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
5
11
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6
12
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -20,6 +26,8 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
20
26
|
import { BaseModule } from "../BaseModule";
|
|
21
27
|
import { cloneDeep } from 'lodash-es';
|
|
22
28
|
import dayjs from 'dayjs';
|
|
29
|
+
import { isProductQueryHandledByOsServer, PRODUCT_QUERY_DATA_VARIANT_RELATIONS, resolveClientDataVariants } from "./clientDataVariants";
|
|
30
|
+
import { isCustomerUserPlatform } from "../../utils/platform";
|
|
23
31
|
export * from "./types";
|
|
24
32
|
export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
25
33
|
_inherits(ProductList, _BaseModule);
|
|
@@ -33,6 +41,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
33
41
|
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
34
42
|
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
35
43
|
_defineProperty(_assertThisInitialized(_this), "otherParams", {});
|
|
44
|
+
_defineProperty(_assertThisInitialized(_this), "rawProductPriceSources", new Map());
|
|
36
45
|
return _this;
|
|
37
46
|
}
|
|
38
47
|
_createClass(ProductList, [{
|
|
@@ -46,6 +55,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
46
55
|
this.core = core;
|
|
47
56
|
this.store = options.store;
|
|
48
57
|
this.otherParams = options.otherParams || {};
|
|
58
|
+
this.rawProductPriceSources.clear();
|
|
49
59
|
if (Array.isArray((_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
|
|
50
60
|
this.store.list = options.initialState.list.slice().sort(function (a, b) {
|
|
51
61
|
return Number(b.sort) - Number(a.sort);
|
|
@@ -56,7 +66,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
56
66
|
this.store.selectProducts = [];
|
|
57
67
|
}
|
|
58
68
|
this.request = core.getPlugin('request');
|
|
59
|
-
case
|
|
69
|
+
case 6:
|
|
60
70
|
case "end":
|
|
61
71
|
return _context.stop();
|
|
62
72
|
}
|
|
@@ -78,64 +88,6 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
78
88
|
value: function updateOtherParams(params) {
|
|
79
89
|
this.otherParams = params || {};
|
|
80
90
|
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 判断当前商品查询是否会被本地 OS Server 接管。
|
|
84
|
-
*
|
|
85
|
-
* 不能只看请求参数中的 osServer=true:H5 RequestPlugin 会透传该参数,但仍然直接请求远端接口。
|
|
86
|
-
* 这里按 RequestPlugin 实际使用的 baseUrl 检查已注册路由,避免 OS Server 与客户端重复执行
|
|
87
|
-
* Data Variant 评估。
|
|
88
|
-
*/
|
|
89
|
-
}, {
|
|
90
|
-
key: "isProductQueryHandledByOsServer",
|
|
91
|
-
value: function isProductQueryHandledByOsServer() {
|
|
92
|
-
var _this$core, _this$request;
|
|
93
|
-
var server = (_this$core = this.core) === null || _this$core === void 0 ? void 0 : _this$core.server;
|
|
94
|
-
if (!server || typeof server.hasRoute !== 'function') return false;
|
|
95
|
-
var requestBaseUrl = String(((_this$request = this.request) === null || _this$request === void 0 ? void 0 : _this$request.baseUrl) || '/shop').replace(/\/+$/, '');
|
|
96
|
-
var routePath = "".concat(requestBaseUrl, "/product/query");
|
|
97
|
-
return server.hasRoute('post', routePath) === true;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 未启用商品 OS 路由时,在客户端补做 Data Variant 解析。
|
|
102
|
-
* OS Server 已接管时直接信任服务端结果,确保同一批商品只评估一次。
|
|
103
|
-
*/
|
|
104
|
-
}, {
|
|
105
|
-
key: "resolveClientDataVariants",
|
|
106
|
-
value: function resolveClientDataVariants(products, queryPayload, handledByOsServer) {
|
|
107
|
-
var _this$core2, _this$otherParams, _scheduleModule$getSc, _this$core3, _this$core4, _this$otherParams2, _strategyContext$busi;
|
|
108
|
-
if (handledByOsServer || products.length === 0) return products;
|
|
109
|
-
var evaluator = (_this$core2 = this.core) === null || _this$core2 === void 0 || (_this$core2 = _this$core2.context) === null || _this$core2 === void 0 ? void 0 : _this$core2.dataVariantEvaluator;
|
|
110
|
-
if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
|
|
111
|
-
return products;
|
|
112
|
-
}
|
|
113
|
-
var strategyContext = queryPayload.strategy_context && _typeof(queryPayload.strategy_context) === 'object' ? queryPayload.strategy_context : {};
|
|
114
|
-
var fatherModule = String(((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.fatherModule) || '').trim();
|
|
115
|
-
var scheduleModule = (fatherModule ? this.core.getModule("".concat(fatherModule, "_schedule")) : null) || this.core.getModule('schedule');
|
|
116
|
-
var scheduleList = scheduleModule === null || scheduleModule === void 0 || (_scheduleModule$getSc = scheduleModule.getScheduleList) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule);
|
|
117
|
-
var contextScheduleList = (_this$core3 = this.core) === null || _this$core3 === void 0 || (_this$core3 = _this$core3.context) === null || _this$core3 === void 0 ? void 0 : _this$core3.scheduleList;
|
|
118
|
-
var contextMenuList = (_this$core4 = this.core) === null || _this$core4 === void 0 || (_this$core4 = _this$core4.context) === null || _this$core4 === void 0 ? void 0 : _this$core4.menuList;
|
|
119
|
-
var businessData = {
|
|
120
|
-
products: products,
|
|
121
|
-
scheduleDateTime: queryPayload.schedule_datetime || queryPayload.schedule_date,
|
|
122
|
-
scheduleList: Array.isArray(scheduleList) ? scheduleList : Array.isArray(contextScheduleList) ? contextScheduleList : [],
|
|
123
|
-
menuList: Array.isArray((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.menuList) ? this.otherParams.menuList : Array.isArray(contextMenuList) ? contextMenuList : [],
|
|
124
|
-
customerId: queryPayload.customer_id,
|
|
125
|
-
channel: strategyContext.channel,
|
|
126
|
-
orderType: strategyContext.orderType || strategyContext.order_type,
|
|
127
|
-
businessCode: (_strategyContext$busi = strategyContext.business_code) !== null && _strategyContext$busi !== void 0 ? _strategyContext$busi : strategyContext.businessCode,
|
|
128
|
-
availableWalletIds: strategyContext.available_wallet_ids,
|
|
129
|
-
custom: strategyContext
|
|
130
|
-
};
|
|
131
|
-
try {
|
|
132
|
-
var _result = evaluator.resolveProducts(businessData);
|
|
133
|
-
return Array.isArray(_result === null || _result === void 0 ? void 0 : _result.products) ? _result.products : products;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
console.error('[ProductList] Data Variant 客户端解析失败', error);
|
|
136
|
-
return products;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
91
|
}, {
|
|
140
92
|
key: "storeChange",
|
|
141
93
|
value: function () {
|
|
@@ -190,7 +142,8 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
190
142
|
key: "loadProducts",
|
|
191
143
|
value: function () {
|
|
192
144
|
var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
193
|
-
var _this$
|
|
145
|
+
var _this$otherParams,
|
|
146
|
+
_this$otherParams2,
|
|
194
147
|
_this2 = this;
|
|
195
148
|
var _ref,
|
|
196
149
|
_ref$category_ids,
|
|
@@ -259,13 +212,14 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
259
212
|
scan_to_order_2: 'mobile_order',
|
|
260
213
|
scan_to_order_3: 'scantoorder3'
|
|
261
214
|
};
|
|
262
|
-
rawApplicationCode = (_this$
|
|
215
|
+
rawApplicationCode = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel;
|
|
263
216
|
mappedApplicationCode = typeof rawApplicationCode === 'string' ? channelMap[rawApplicationCode] || rawApplicationCode : rawApplicationCode;
|
|
264
|
-
queryPayload = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
265
|
-
open_quotation: 1
|
|
217
|
+
queryPayload = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, isCustomerUserPlatform((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.platform) ? {} : {
|
|
218
|
+
open_quotation: 1
|
|
219
|
+
}), {}, {
|
|
266
220
|
open_bundle: 0,
|
|
267
221
|
exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
|
|
268
|
-
with:
|
|
222
|
+
with: _toConsumableArray(PRODUCT_QUERY_DATA_VARIANT_RELATIONS),
|
|
269
223
|
status: status,
|
|
270
224
|
num: 500,
|
|
271
225
|
skip: 1,
|
|
@@ -291,7 +245,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
291
245
|
extension_type: extension_type,
|
|
292
246
|
strategy_context: strategy_context
|
|
293
247
|
});
|
|
294
|
-
handledByOsServer = this.
|
|
248
|
+
handledByOsServer = isProductQueryHandledByOsServer(this.core, this.request);
|
|
295
249
|
originalCallback = options === null || options === void 0 ? void 0 : options.callback;
|
|
296
250
|
subscriptionCallback = typeof originalCallback === 'function' ? ( /*#__PURE__*/function () {
|
|
297
251
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(result) {
|
|
@@ -308,16 +262,27 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
308
262
|
originalCallback(result);
|
|
309
263
|
return _context4.abrupt("return");
|
|
310
264
|
case 4:
|
|
311
|
-
|
|
312
|
-
|
|
265
|
+
if (!handledByOsServer) {
|
|
266
|
+
// Subscription callbacks may contain only changed products. Upsert
|
|
267
|
+
// their raw records without evicting other IDs from the scope.
|
|
268
|
+
_this2.rememberRawProductQueryResult(callbackList);
|
|
269
|
+
}
|
|
270
|
+
products = resolveClientDataVariants({
|
|
271
|
+
core: _this2.core,
|
|
272
|
+
otherParams: _this2.otherParams,
|
|
273
|
+
products: callbackList,
|
|
274
|
+
queryPayload: queryPayload,
|
|
275
|
+
handledByOsServer: handledByOsServer
|
|
276
|
+
});
|
|
277
|
+
_context4.next = 8;
|
|
313
278
|
return _this2.addProduct(products);
|
|
314
|
-
case
|
|
279
|
+
case 8:
|
|
315
280
|
originalCallback(handledByOsServer ? result : _objectSpread(_objectSpread({}, result), {}, {
|
|
316
281
|
data: _objectSpread(_objectSpread({}, result.data), {}, {
|
|
317
282
|
list: products
|
|
318
283
|
})
|
|
319
284
|
}));
|
|
320
|
-
case
|
|
285
|
+
case 9:
|
|
321
286
|
case "end":
|
|
322
287
|
return _context4.stop();
|
|
323
288
|
}
|
|
@@ -336,7 +301,16 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
336
301
|
});
|
|
337
302
|
case 14:
|
|
338
303
|
productsData = _context5.sent;
|
|
339
|
-
|
|
304
|
+
if (!handledByOsServer && Array.isArray(productsData.data.list)) {
|
|
305
|
+
this.replaceRawProductQueryResult(productsData.data.list, product_ids);
|
|
306
|
+
}
|
|
307
|
+
resolvedList = resolveClientDataVariants({
|
|
308
|
+
core: this.core,
|
|
309
|
+
otherParams: this.otherParams,
|
|
310
|
+
products: productsData.data.list || [],
|
|
311
|
+
queryPayload: queryPayload,
|
|
312
|
+
handledByOsServer: handledByOsServer
|
|
313
|
+
});
|
|
340
314
|
sortedList = resolvedList.slice().sort(function (a, b) {
|
|
341
315
|
return Number(b.sort) - Number(a.sort);
|
|
342
316
|
}); // if (sortedList.length) {
|
|
@@ -348,7 +322,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
348
322
|
// }
|
|
349
323
|
this.addProduct(sortedList);
|
|
350
324
|
return _context5.abrupt("return", sortedList);
|
|
351
|
-
case
|
|
325
|
+
case 20:
|
|
352
326
|
case "end":
|
|
353
327
|
return _context5.stop();
|
|
354
328
|
}
|
|
@@ -391,6 +365,60 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
391
365
|
}
|
|
392
366
|
return loadProductsPrice;
|
|
393
367
|
}()
|
|
368
|
+
/**
|
|
369
|
+
* Remember raw remote product records before client-side Data Variant
|
|
370
|
+
* evaluation. Quote-only reads can then always start from a clean baseline.
|
|
371
|
+
*/
|
|
372
|
+
}, {
|
|
373
|
+
key: "rememberRawProductQueryResult",
|
|
374
|
+
value: function rememberRawProductQueryResult(products) {
|
|
375
|
+
var _this3 = this;
|
|
376
|
+
if (!Array.isArray(products)) return;
|
|
377
|
+
products.forEach(function (product) {
|
|
378
|
+
var _source$id;
|
|
379
|
+
var source = product;
|
|
380
|
+
var id = Number((_source$id = source === null || source === void 0 ? void 0 : source.id) !== null && _source$id !== void 0 ? _source$id : source === null || source === void 0 ? void 0 : source.product_id);
|
|
381
|
+
if (!Number.isFinite(id)) return;
|
|
382
|
+
_this3.rawProductPriceSources.set(id, cloneDeep(product));
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}, {
|
|
386
|
+
key: "replaceRawProductQueryResult",
|
|
387
|
+
value: function replaceRawProductQueryResult(products, requestedIds) {
|
|
388
|
+
var _this4 = this;
|
|
389
|
+
if (Array.isArray(requestedIds) && requestedIds.length > 0) {
|
|
390
|
+
requestedIds.forEach(function (rawId) {
|
|
391
|
+
var id = Number(rawId);
|
|
392
|
+
if (Number.isFinite(id)) _this4.rawProductPriceSources.delete(id);
|
|
393
|
+
});
|
|
394
|
+
} else {
|
|
395
|
+
// A non-ID query represents the latest catalog scope. Clearing before
|
|
396
|
+
// replacing prevents removed products from surviving indefinitely.
|
|
397
|
+
this.rawProductPriceSources.clear();
|
|
398
|
+
}
|
|
399
|
+
this.rememberRawProductQueryResult(products);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Return isolated raw price sources for the requested products.
|
|
404
|
+
*
|
|
405
|
+
* Missing IDs are intentionally omitted so callers can remotely fetch only
|
|
406
|
+
* the incomplete part of a batch quote.
|
|
407
|
+
*/
|
|
408
|
+
}, {
|
|
409
|
+
key: "getRawProductPriceSources",
|
|
410
|
+
value: function getRawProductPriceSources(ids) {
|
|
411
|
+
var _this5 = this;
|
|
412
|
+
var products = new Map();
|
|
413
|
+
if (!Array.isArray(ids)) return products;
|
|
414
|
+
ids.forEach(function (rawId) {
|
|
415
|
+
var id = Number(rawId);
|
|
416
|
+
if (!Number.isFinite(id) || products.has(id)) return;
|
|
417
|
+
var product = _this5.rawProductPriceSources.get(id);
|
|
418
|
+
if (product) products.set(id, cloneDeep(product));
|
|
419
|
+
});
|
|
420
|
+
return products;
|
|
421
|
+
}
|
|
394
422
|
}, {
|
|
395
423
|
key: "getProducts",
|
|
396
424
|
value: function () {
|
|
@@ -469,7 +497,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
469
497
|
key: "addProduct",
|
|
470
498
|
value: function () {
|
|
471
499
|
var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(products) {
|
|
472
|
-
var
|
|
500
|
+
var _this6 = this;
|
|
473
501
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
474
502
|
while (1) switch (_context10.prev = _context10.next) {
|
|
475
503
|
case 0:
|
|
@@ -478,13 +506,13 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
478
506
|
this.store.list = [];
|
|
479
507
|
}
|
|
480
508
|
products.forEach(function (n) {
|
|
481
|
-
var index =
|
|
509
|
+
var index = _this6.store.list.findIndex(function (m) {
|
|
482
510
|
return m.id === n.id;
|
|
483
511
|
});
|
|
484
512
|
if (index === -1) {
|
|
485
|
-
|
|
513
|
+
_this6.store.list.push(n);
|
|
486
514
|
} else {
|
|
487
|
-
|
|
515
|
+
_this6.store.list[index] = n;
|
|
488
516
|
}
|
|
489
517
|
});
|
|
490
518
|
// 根据 sort 值做降序排序(数字越大越靠前)
|
|
@@ -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;
|