user-merchant.js
3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* 解析详情、保存、周历接口使用的 4S 店 merchantId,兼容各业务默认门店结构。
* @param {Object} [userInfo={}] 登录用户信息
* @param {string|number} [hint] 显式门店 ID
* @returns {string|number} 4S 店 merchantId
*/
function resolveShopMerchantId(userInfo = {}, hint) {
if (hint != null && hint !== '') {
return hint
}
return (
userInfo.shopMerchantId ||
userInfo.default4SStoreInfo?.merchantId ||
userInfo.default4SStoreInfo_crowdFunding?.merchantId ||
userInfo.default4SStoreInfo_usedCar?.merchantId ||
''
)
}
/**
* 解析导航标题和保存请求使用的 4S 店名称。
* @param {Object} [userInfo={}] 登录用户信息
* @param {string} [hint] 显式门店名称
* @returns {string} 4S 店名称
*/
function resolveShopMerchantName(userInfo = {}, hint) {
if (hint != null && hint !== '') {
return hint
}
return (
userInfo.shopMerchantName ||
userInfo.default4SStoreInfo?.merchantName ||
userInfo.default4SStoreInfo_crowdFunding?.merchantName ||
userInfo.default4SStoreInfo_usedCar?.merchantName ||
''
)
}
/** 园区店 ID:下拉 storeStaffList 等;勿用于 dynamic.save 的 merchantId */
function resolveYqMerchantId(userInfo = {}, shopMerchantId = '') {
return userInfo.yqMerchantId || userInfo.merchantId || shopMerchantId || ''
}
/** 园区店名称:保存 yqMerchantName */
function resolveYqMerchantName(userInfo = {}, hint) {
if (hint != null && hint !== '') {
return hint
}
return userInfo.yqMerchantName || userInfo.merchantName || ''
}
/** 业务场景:0 会员权益/升级,1 精品升级,7 二手车 */
function resolveSceneType(userInfo = {}, hint) {
if (hint != null && hint !== '') {
return hint
}
if (userInfo.sceneType != null && userInfo.sceneType !== '') {
return userInfo.sceneType
}
return 0
}
/**
* 从单份上下文解析 4S merchantId(已 normalize 的 merchantId 可作为兜底)
* @param {Object} [ctx={}]
* @returns {string|number}
*/
function pick4sMerchantIdFromContext(ctx = {}) {
const fromShop = resolveShopMerchantId(ctx)
if (fromShop) {
return fromShop
}
if (ctx.shopMerchantId != null && ctx.shopMerchantId !== '') {
return ctx.merchantId || ctx.shopMerchantId
}
if (ctx.merchantId && ctx.yqMerchantId && ctx.merchantId !== ctx.yqMerchantId) {
return ctx.merchantId
}
if (ctx.merchantId && (ctx.yqMerchantId == null || ctx.yqMerchantId === '')) {
return ctx.merchantId
}
return ''
}
/**
* 保存/详情/周历请求用的 merchantId(4S 店),忽略 pageContext 中误写的园区 merchantId
* @param {Object} [userContext={}]
* @param {Object} [pageContext={}]
* @returns {string|number}
*/
function resolveSaveMerchantId(userContext = {}, pageContext = {}) {
return pick4sMerchantIdFromContext(userContext) || pick4sMerchantIdFromContext(pageContext) || ''
}
/**
* 将不同业务登录态统一为动态日报用户上下文,二手车优先使用默认二手车 4S 店。
* @param {Object} [userInfo={}] 原始登录用户信息
* @returns {Object} 动态日报用户上下文
*/
function normalizeDailyReportUserInfo(userInfo = {}) {
const merchantId = resolveShopMerchantId(userInfo)
const shopMerchantId = userInfo.shopMerchantId || merchantId || ''
const shopMerchantName = resolveShopMerchantName(userInfo) || userInfo.shopMerchantName || ''
return {
merchantId,
shopMerchantId,
shopMerchantName,
yqMerchantId: resolveYqMerchantId(userInfo, merchantId),
yqMerchantName: resolveYqMerchantName(userInfo),
sceneType: resolveSceneType(userInfo),
staffUuid: userInfo.uuid || userInfo.staffUuid || '',
phone: userInfo.phone || '',
baseSceneCode: userInfo.baseSceneCode,
merchantName: shopMerchantName,
staffName: userInfo.name || userInfo.staffName || ''
}
}
module.exports = {
resolveShopMerchantId,
resolveShopMerchantName,
resolveYqMerchantId,
resolveYqMerchantName,
resolveSceneType,
resolveSaveMerchantId,
normalizeDailyReportUserInfo
}