@conecli/cone-render 0.10.1-shop3.6 → 0.10.1-shop3.8
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/common/index.h5.ts +1 -1
- package/dist/components/base/CustomScrollView/index.tsx +1 -1
- package/dist/open/api/util.ts +1 -1
- package/dist/service/http/const.ts +1 -1
- package/dist/service/requestServer.ts +1 -1
- package/dist/service/requestServer.weapp.ts +1 -0
- package/dist/utils/h5Utils.ts +1 -1
- package/dist/utils/index.h5.ts +1 -1
- package/dist/utils/jumpExtMapUtil.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
2
1
|
APPID,
|
|
3
2
|
JshopxColorFunctionIdList,
|
|
4
3
|
PagesColorFunctionIdList,
|
|
5
4
|
PAGES_DOMAIN,
|
|
6
5
|
B2BColorFunctionIdList,
|
|
7
6
|
MobileVerifyColorList,
|
|
8
7
|
AppVerifyColorList,
|
|
9
8
|
JshopxVerifyColorList,
|
|
10
9
|
BMallVerifyColorList,
|
|
11
10
|
shopMemberColorFunctionIdList,
|
|
12
11
|
isLanguageForEn,
|
|
13
12
|
isJdApp,
|
|
14
13
|
isIosDevice,
|
|
15
14
|
isAndroidDevice,
|
|
16
15
|
showSuccessToast,
|
|
17
16
|
showFailToast,
|
|
18
17
|
isH5,
|
|
19
18
|
isWxMinAndWxapp,
|
|
20
19
|
isMin,
|
|
21
20
|
isPc,
|
|
22
21
|
sgmCustomReport,
|
|
23
22
|
getSgmCustomCode,
|
|
24
23
|
draInterfaceCustomReport,
|
|
25
24
|
callRouterIOS,
|
|
26
25
|
callRouterAndroid,
|
|
27
26
|
cookiesStr: '',
|
|
28
27
|
requestHeaderContentType: {
|
|
29
28
|
jsonHeader: {
|
|
30
29
|
'content-type': 'application/json;charset=utf-8',
|
|
31
30
|
},
|
|
32
31
|
formDataHeader: {
|
|
33
32
|
'content-type': 'application/x-www-form-urlencoded',
|
|
34
33
|
},
|
|
35
34
|
},
|
|
36
35
|
requestBaseParam: {
|
|
37
36
|
data: null,
|
|
38
37
|
header: {
|
|
39
38
|
'content-type': 'application/json;charset=utf-8',
|
|
40
39
|
},
|
|
41
40
|
},
|
|
42
41
|
timeOut: 7000,
|
|
43
42
|
apiClientParams: {
|
|
44
43
|
clientVersion: '11.0.0',
|
|
45
44
|
client: 'wh5',
|
|
46
45
|
area: '1_72_2799_0',
|
|
47
46
|
screen: `${Math.ceil(
|
|
48
47
|
getSystemInfo?.screenWidth * devicePixelRatio,
|
|
49
48
|
)}*${Math.ceil(getSystemInfo?.screenHeight * devicePixelRatio)}`,
|
|
50
49
|
uuid: UUID,
|
|
51
50
|
},
|
|
52
51
|
public addressFetchInfo: {
|
|
53
52
|
reqState: boolean
|
|
54
53
|
promiseInstance: null | Promise<any>
|
|
55
54
|
}
|
|
56
55
|
public getPromotionConfig: {
|
|
57
56
|
projectId: null | string | number
|
|
58
57
|
pageId: null | string | number
|
|
59
58
|
}
|
|
60
59
|
public resInfo: ServiceInterFace.HttpRequestInfo
|
|
61
60
|
public api: ServiceInterFace.HttpApi
|
|
62
61
|
public isPageDomain: boolean
|
|
63
62
|
public verifyColorList: string[]
|
|
64
63
|
constructor(opt) {
|
|
65
64
|
this._init()
|
|
66
65
|
this.addressFetchInfo = {
|
|
67
66
|
reqState: false,
|
|
68
67
|
promiseInstance: null,
|
|
69
68
|
}
|
|
70
69
|
this.getPromotionConfig = {
|
|
71
70
|
projectId: null,
|
|
72
71
|
pageId: null,
|
|
73
72
|
}
|
|
74
73
|
this._userAreaUpdateListen()
|
|
75
74
|
this.resInfo = this._getResConfig(opt)
|
|
76
75
|
this.api = api
|
|
77
76
|
this.isPageDomain = isH5
|
|
78
77
|
? window?.location?.hostname === PAGES_DOMAIN
|
|
79
78
|
: false
|
|
80
79
|
this.verifyColorList = [
|
|
81
80
|
...MobileVerifyColorList,
|
|
82
81
|
...AppVerifyColorList,
|
|
83
82
|
...JshopxVerifyColorList,
|
|
84
83
|
...BMallVerifyColorList,
|
|
85
84
|
]
|
|
86
85
|
}
|
|
87
86
|
_init(): void {
|
|
88
87
|
httpInterceptors.forEach((item) => {
|
|
89
88
|
Taro.addInterceptor((chain) => item(chain))
|
|
90
89
|
})
|
|
91
90
|
}
|
|
92
91
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
93
92
|
return Object.assign({}, DefaultConfig, opt)
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
_userAreaUpdateListen() {
|
|
97
96
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
|
|
98
97
|
this.updateApiClientParamsResInfo({
|
|
99
98
|
area,
|
|
100
99
|
})
|
|
101
100
|
})
|
|
102
101
|
}
|
|
103
102
|
updateApiClientParamsResInfo(opt = {}) {
|
|
104
103
|
this.resInfo.apiClientParams = {
|
|
105
104
|
...this.resInfo.apiClientParams,
|
|
106
105
|
...opt,
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
checkFunctionIdToReturnAppId(functionId) {
|
|
111
110
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
112
111
|
return APPID.JSHOPX_COLOR_APPID
|
|
113
112
|
} else if (
|
|
114
113
|
this.isPageDomain &&
|
|
115
114
|
PagesColorFunctionIdList.includes(functionId)
|
|
116
115
|
) {
|
|
117
116
|
return APPID.PAGES_COLOR_APPID
|
|
118
117
|
} else if (shopMemberColorFunctionIdList.includes(functionId)) {
|
|
119
118
|
return APPID.SHOP_MEMBER_COLOR_APPID
|
|
120
119
|
} else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
121
120
|
return APPID.B2B_COLOR_APPID
|
|
122
121
|
} else if (isPc) {
|
|
123
122
|
return APPID.MALL_COLOR_APPID
|
|
124
123
|
} else {
|
|
125
124
|
return APPID.SHOP_COLOR_APPID
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
gatewayReq(
|
|
130
129
|
functionId: string,
|
|
131
130
|
bodyParams = {},
|
|
132
131
|
clientParams = {},
|
|
133
132
|
): Promise<any> {
|
|
134
133
|
if (
|
|
135
134
|
functionId === 'receiveShopCoupon' &&
|
|
136
135
|
((isH5 &&
|
|
137
136
|
(window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
|
|
138
137
|
isWxMinAndWxapp)
|
|
139
138
|
) {
|
|
140
139
|
clientParams = Object.assign(
|
|
141
140
|
{},
|
|
142
141
|
{
|
|
143
142
|
loginType: '1',
|
|
144
143
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
145
144
|
},
|
|
146
145
|
clientParams,
|
|
147
146
|
)
|
|
148
147
|
}
|
|
149
148
|
const apiClientParams = Object.assign(
|
|
150
149
|
{},
|
|
151
150
|
this.resInfo.apiClientParams,
|
|
152
151
|
clientParams,
|
|
153
152
|
)
|
|
154
153
|
typeof apiClientParams.appid === 'undefined' &&
|
|
155
154
|
(apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId))
|
|
156
155
|
const isColorVerify = this.verifyColorList.includes(functionId)
|
|
157
156
|
const getReqData = {
|
|
158
157
|
functionId: functionId,
|
|
159
158
|
body: JSON.stringify(bodyParams),
|
|
160
159
|
t: Date.now(),
|
|
161
160
|
...apiClientParams,
|
|
162
161
|
}
|
|
163
162
|
const requestParams = {
|
|
164
163
|
functionId: getReqData?.functionId,
|
|
165
164
|
body: getReqData?.body,
|
|
166
165
|
appid: getReqData?.appid,
|
|
167
166
|
client: getReqData?.client,
|
|
168
167
|
clientVersion: getReqData?.clientVersion,
|
|
169
168
|
area: getReqData?.area,
|
|
170
169
|
requestTimeStamp: getReqData?.t,
|
|
171
170
|
}
|
|
172
171
|
return http
|
|
173
172
|
.request({
|
|
174
173
|
url: this.api.apiFunc,
|
|
175
174
|
data: getReqData,
|
|
176
175
|
isColorVerify,
|
|
177
176
|
})
|
|
178
177
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
179
178
|
const { statusCode, data, status, msg } = res
|
|
180
179
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
181
180
|
ok: true,
|
|
182
181
|
}
|
|
183
182
|
if ((statusCode === 200 || status === '0') && data) {
|
|
184
183
|
changeRes = this.dealResponseFormatRes(data, getReqData)
|
|
185
184
|
return changeRes
|
|
186
185
|
} else {
|
|
187
186
|
sgmCustomReport({
|
|
188
187
|
code: getSgmCustomCode('interface_data_error'),
|
|
189
188
|
msg: {
|
|
190
189
|
subMsg: '接口请求异常',
|
|
191
190
|
functionId,
|
|
192
191
|
statusCode,
|
|
193
192
|
source: 'remote',
|
|
194
193
|
status,
|
|
195
194
|
msg,
|
|
196
195
|
requestParams,
|
|
197
196
|
},
|
|
198
197
|
})
|
|
199
198
|
draInterfaceCustomReport({
|
|
200
199
|
...getReqData,
|
|
201
200
|
...res,
|
|
202
201
|
source: 'remote',
|
|
203
202
|
})
|
|
204
203
|
changeRes = {
|
|
205
204
|
...data,
|
|
206
205
|
statusCode,
|
|
207
206
|
status,
|
|
208
207
|
msg,
|
|
209
208
|
ok: false,
|
|
210
209
|
}
|
|
211
210
|
return changeRes
|
|
212
211
|
}
|
|
213
212
|
})
|
|
214
213
|
.catch((res) => {
|
|
215
214
|
const propertyNames = Object.getOwnPropertyNames(res)
|
|
216
215
|
const resObject = {}
|
|
217
216
|
propertyNames.forEach((propertyName) => {
|
|
218
217
|
resObject[propertyName] = res[propertyName]
|
|
219
218
|
})
|
|
220
219
|
sgmCustomReport({
|
|
221
220
|
code: getSgmCustomCode('interface_data_error'),
|
|
222
221
|
msg: {
|
|
223
222
|
subMsg: '接口请求错误',
|
|
224
223
|
functionId,
|
|
225
224
|
source: 'remote',
|
|
226
225
|
requestParams,
|
|
227
226
|
catchError: resObject,
|
|
228
227
|
},
|
|
229
228
|
})
|
|
230
229
|
draInterfaceCustomReport({
|
|
231
230
|
...getReqData,
|
|
232
231
|
...resObject,
|
|
233
232
|
source: 'remote',
|
|
234
233
|
})
|
|
235
234
|
return {
|
|
236
235
|
...resObject,
|
|
237
236
|
ok: false,
|
|
238
237
|
} as ServiceInterFace.RequestResponseFormatRes
|
|
239
238
|
})
|
|
240
239
|
}
|
|
241
240
|
|
|
242
241
|
dealResponseFormatRes(data, reqData) {
|
|
243
242
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
244
243
|
ok: true,
|
|
245
244
|
}
|
|
246
245
|
const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
|
|
247
246
|
? Number(data.code)
|
|
248
247
|
: -1
|
|
249
248
|
const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
|
|
250
249
|
? Number(data.subCode)
|
|
251
250
|
: -1
|
|
252
251
|
if (
|
|
253
252
|
data.success === true ||
|
|
254
253
|
data.isSuccess ||
|
|
255
254
|
resCode === 0 ||
|
|
256
255
|
resCode === 200 ||
|
|
257
256
|
subCode === 0
|
|
258
257
|
) {
|
|
259
258
|
changeRes = {
|
|
260
259
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
261
260
|
? data.result
|
|
262
261
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
263
262
|
? data.data
|
|
264
263
|
: data,
|
|
265
264
|
code: data.code ?? 200,
|
|
266
265
|
ok: true,
|
|
267
266
|
source: data,
|
|
268
267
|
}
|
|
269
268
|
return changeRes
|
|
270
269
|
} else {
|
|
271
270
|
changeRes = {
|
|
272
271
|
...data,
|
|
273
272
|
ok: false,
|
|
274
273
|
}
|
|
275
274
|
if (reqData && resCode !== 3) {
|
|
276
275
|
const getReportMsgData = reqData['hybridId']
|
|
277
276
|
? {
|
|
278
277
|
subMsg: '预加载接口请求数据异常',
|
|
279
278
|
hybridId: reqData?.hybridId,
|
|
280
279
|
requestId: reqData?.requestId,
|
|
281
280
|
param: reqData?.param,
|
|
282
281
|
source: 'remote',
|
|
283
282
|
}
|
|
284
283
|
: {
|
|
285
284
|
subMsg: '接口请求返回数据异常',
|
|
286
285
|
functionId: reqData?.functionId,
|
|
287
286
|
code: resCode,
|
|
288
287
|
source: 'remote',
|
|
289
288
|
requestParams: {
|
|
290
289
|
functionId: reqData?.functionId,
|
|
291
290
|
body: reqData?.body,
|
|
292
291
|
appid: reqData?.appid,
|
|
293
292
|
client: reqData?.client,
|
|
294
293
|
clientVersion: reqData?.clientVersion,
|
|
295
294
|
area: reqData?.area,
|
|
296
295
|
requestTimeStamp: reqData?.t,
|
|
297
296
|
},
|
|
298
297
|
resData: data,
|
|
299
298
|
}
|
|
300
299
|
sgmCustomReport({
|
|
301
300
|
code: getSgmCustomCode('interface_data_error'),
|
|
302
301
|
msg: getReportMsgData,
|
|
303
302
|
})
|
|
304
303
|
draInterfaceCustomReport({
|
|
305
304
|
...reqData,
|
|
306
305
|
...data,
|
|
307
306
|
source: 'remote',
|
|
308
307
|
})
|
|
309
308
|
}
|
|
310
309
|
return changeRes
|
|
311
310
|
}
|
|
312
311
|
}
|
|
313
312
|
|
|
314
313
|
async receiveCoupon(param = {}, clientParams) {
|
|
315
314
|
const loginType = isPc ? { loginType: 3 } : {}
|
|
316
315
|
return await this.gatewayReq(
|
|
317
316
|
'receiveShopCoupon',
|
|
318
317
|
{
|
|
319
318
|
operation: '3',
|
|
320
319
|
...param,
|
|
321
320
|
},
|
|
322
321
|
{ ...loginType, ...clientParams },
|
|
323
322
|
)
|
|
324
323
|
}
|
|
325
324
|
|
|
326
325
|
getCustomerCenterDispatch(params = {}) {
|
|
327
326
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
328
327
|
clientVersion: '9.2.0',
|
|
329
328
|
client: 'H5',
|
|
330
329
|
uuid: 88888,
|
|
331
330
|
appid: 'shopmember_m_jd_com',
|
|
332
331
|
})
|
|
333
332
|
}
|
|
334
333
|
|
|
335
334
|
batchAddCart(...args) {
|
|
336
335
|
let skuIds, num, showToast, giftCard
|
|
337
336
|
if (['number', 'string'].includes(typeof args[0])) {
|
|
338
337
|
;[skuIds, num = 1, showToast = true, giftCard = false] = args
|
|
339
338
|
} else if (typeof args[0] === 'object' && args[0] !== null) {
|
|
340
339
|
const params = args[0]
|
|
341
340
|
skuIds = params.skuIds
|
|
342
341
|
num = params.num || 1
|
|
343
342
|
showToast = params.showToast !== undefined ? params.showToast : true
|
|
344
343
|
giftCard = params.giftCard !== undefined ? params.giftCard : false
|
|
345
344
|
} else {
|
|
346
345
|
console.error('batchAddCart() Invalid arguments!', args)
|
|
347
346
|
const msg = isLanguageForEn
|
|
348
347
|
? 'Please retry later'
|
|
349
348
|
: '加入购物车失败,请稍后重试!'
|
|
350
349
|
showFailToast({
|
|
351
350
|
title: msg,
|
|
352
351
|
})
|
|
353
352
|
return Promise.resolve({
|
|
354
353
|
ok: false,
|
|
355
354
|
msg,
|
|
356
355
|
})
|
|
357
356
|
}
|
|
358
357
|
const addToWhereText = giftCard ? '购物清单' : '购物车'
|
|
359
358
|
const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`
|
|
360
359
|
const failMsg = isLanguageForEn
|
|
361
360
|
? 'Please retry later'
|
|
362
361
|
: `加入${addToWhereText}失败,请稍后重试!`
|
|
363
362
|
if (skuIds) {
|
|
364
363
|
return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
|
|
365
364
|
.then((res: ServiceInterFace.SkuToCartDataRes) => {
|
|
366
365
|
if (res?.ok) {
|
|
367
366
|
if (showToast && !res?.isOpenApp)
|
|
368
367
|
showSuccessToast({
|
|
369
368
|
title: successMsg,
|
|
370
369
|
})
|
|
371
370
|
} else {
|
|
372
371
|
showToast &&
|
|
373
372
|
showFailToast({
|
|
374
373
|
title: res?.errMsg || failMsg,
|
|
375
374
|
})
|
|
376
375
|
}
|
|
377
376
|
return Promise.resolve(res)
|
|
378
377
|
})
|
|
379
378
|
.catch((e) => {
|
|
380
379
|
console.log('调用加购方法异常=======>', e)
|
|
381
380
|
return Promise.resolve({
|
|
382
381
|
ok: false,
|
|
383
382
|
msg: failMsg,
|
|
384
383
|
})
|
|
385
384
|
})
|
|
386
385
|
} else {
|
|
387
386
|
return Promise.resolve({
|
|
388
387
|
ok: false,
|
|
389
388
|
msg: failMsg,
|
|
390
389
|
})
|
|
391
390
|
}
|
|
392
391
|
}
|
|
393
392
|
|
|
394
393
|
async giftCardAddCart(skuList, num) {
|
|
395
394
|
const loginType = isPc ? { loginType: 3 } : {}
|
|
396
395
|
return this.gatewayReq(
|
|
397
396
|
'giftCardAddCart',
|
|
398
397
|
{
|
|
399
398
|
skuList,
|
|
400
399
|
num: Number(num),
|
|
401
400
|
},
|
|
402
401
|
{ ...loginType },
|
|
403
402
|
)
|
|
404
403
|
}
|
|
405
404
|
|
|
406
405
|
_addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
|
|
407
406
|
return new Promise((resolve) => {
|
|
408
407
|
const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
|
|
409
408
|
if (productIdsArr.length > 0) {
|
|
410
409
|
if (giftCard) {
|
|
411
410
|
this.giftCardAddCart(productIdsArr, addCardNum)
|
|
412
411
|
.then((res) => {
|
|
413
412
|
if (res?.code === '0' && res?.result?.value) {
|
|
414
413
|
resolve({
|
|
415
414
|
ok: true,
|
|
416
415
|
})
|
|
417
416
|
} else {
|
|
418
417
|
resolve({
|
|
419
418
|
ok: false,
|
|
420
419
|
msg: '加购失败,请稍后重试',
|
|
421
420
|
})
|
|
422
421
|
}
|
|
423
422
|
})
|
|
424
423
|
.catch((e) => {
|
|
425
424
|
console.error('礼品卡加车失败: ', e)
|
|
426
425
|
resolve({
|
|
427
426
|
ok: false,
|
|
428
427
|
msg: '加购失败,请稍后重试',
|
|
429
428
|
})
|
|
430
429
|
})
|
|
431
430
|
} else if (isJdApp) {
|
|
432
431
|
const nativeAddCartCallBack = `nativeBatchAddCart${
|
|
433
432
|
Date.now() + Number(productIdsArr[0]) + Number(addCardNum)
|
|
434
433
|
}`
|
|
435
434
|
console.log(
|
|
436
435
|
'==========>',
|
|
437
436
|
'原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
|
|
438
437
|
nativeAddCartCallBack,
|
|
439
438
|
)
|
|
440
439
|
if (!window[nativeAddCartCallBack]) {
|
|
441
440
|
window[nativeAddCartCallBack] = (res) => {
|
|
442
441
|
const getMessageJsonData =
|
|
443
442
|
typeof res === 'string' ? JSON.parse(res) : res
|
|
444
443
|
console.info(
|
|
445
444
|
'获取批量加车原始数据',
|
|
446
445
|
res,
|
|
447
446
|
'====转换后的json数据为===',
|
|
448
447
|
getMessageJsonData,
|
|
449
448
|
)
|
|
450
449
|
try {
|
|
451
450
|
if (isAndroidDevice) {
|
|
452
451
|
getMessageJsonData?.status === '0'
|
|
453
452
|
? resolve({
|
|
454
453
|
ok: true,
|
|
455
454
|
msg: '已加入购物车!',
|
|
456
455
|
})
|
|
457
456
|
: resolve({
|
|
458
457
|
ok: false,
|
|
459
458
|
msg: '加购失败,请稍后重试',
|
|
460
459
|
})
|
|
461
460
|
} else if (isIosDevice) {
|
|
462
461
|
getMessageJsonData?.status === '0' &&
|
|
463
462
|
getMessageJsonData?.data?.code === 0
|
|
464
463
|
? resolve({
|
|
465
464
|
ok: true,
|
|
466
465
|
msg: '已加入购物车!',
|
|
467
466
|
})
|
|
468
467
|
: resolve({
|
|
469
468
|
ok: false,
|
|
470
469
|
msg: '批量加车失败,请稍后重试',
|
|
471
470
|
})
|
|
472
471
|
} else {
|
|
473
472
|
resolve({
|
|
474
473
|
ok: false,
|
|
475
474
|
msg: '加购失败,请稍后重试',
|
|
476
475
|
})
|
|
477
476
|
}
|
|
478
477
|
} catch (e) {
|
|
479
478
|
resolve({
|
|
480
479
|
ok: false,
|
|
481
480
|
msg: '加购失败,请稍后重试',
|
|
482
481
|
})
|
|
483
482
|
console.warn('批量加车转换数据异常', e)
|
|
484
483
|
}
|
|
485
484
|
window[nativeAddCartCallBack] = null
|
|
486
485
|
}
|
|
487
486
|
}
|
|
488
487
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
489
488
|
return isAndroidDevice
|
|
490
489
|
? {
|
|
491
490
|
sku: skuItem,
|
|
492
491
|
num: addCardNum,
|
|
493
492
|
}
|
|
494
493
|
: {
|
|
495
494
|
productCode: skuItem,
|
|
496
495
|
buyCount: addCardNum,
|
|
497
496
|
}
|
|
498
497
|
})
|
|
499
498
|
if (isAndroidDevice) {
|
|
500
499
|
const androidProductsStr = JSON.stringify(productsAddCartList)
|
|
501
500
|
callRouterAndroid({
|
|
502
501
|
routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
|
|
503
502
|
routerParam: {
|
|
504
503
|
wareList: productsAddCartList,
|
|
505
504
|
},
|
|
506
505
|
callBackName: nativeAddCartCallBack,
|
|
507
506
|
})
|
|
508
507
|
} else if (isIosDevice) {
|
|
509
508
|
if (isLowAppVer) {
|
|
510
509
|
const lowVersionAppList = productIdsArr.map((skuItem) => {
|
|
511
510
|
return {
|
|
512
511
|
sku: skuItem,
|
|
513
512
|
num: addCardNum,
|
|
514
513
|
}
|
|
515
514
|
})
|
|
516
515
|
const lowVersionAppListStr = JSON.stringify(lowVersionAppList)
|
|
517
516
|
const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`
|
|
518
517
|
jump.side.jdJumpToWeb(url, {})
|
|
519
518
|
resolve({
|
|
520
519
|
ok: true,
|
|
521
520
|
isOpenApp: true,
|
|
522
521
|
msg: '加购完成, 加购结果请点击购物车确认',
|
|
523
522
|
})
|
|
524
523
|
} else {
|
|
525
524
|
callRouterIOS({
|
|
526
525
|
routerURL: 'router://JDCartModule/batchAddService',
|
|
527
526
|
routerParam: {
|
|
528
527
|
sourceType: 'h5',
|
|
529
528
|
sourceValue: '店铺批量加购',
|
|
530
529
|
businessName: 'storeModel',
|
|
531
530
|
isNewMode: '1',
|
|
532
531
|
NotPassWebview: '1',
|
|
533
532
|
products: productsAddCartList,
|
|
534
533
|
},
|
|
535
534
|
callBackName: nativeAddCartCallBack,
|
|
536
535
|
})
|
|
537
536
|
}
|
|
538
537
|
}
|
|
539
538
|
} else if (isMin) {
|
|
540
539
|
console.log('==========>', '京购批量加车!')
|
|
541
540
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
542
541
|
return {
|
|
543
542
|
skuId: skuItem,
|
|
544
543
|
buyNum: addCardNum,
|
|
545
544
|
}
|
|
546
545
|
})
|
|
547
546
|
global.wxAppBizInstance
|
|
548
547
|
.addCart({ commArr: productsAddCartList })
|
|
549
548
|
.then((res) => {
|
|
550
549
|
console.log('dealCartSuccess: ', res)
|
|
551
550
|
resolve({
|
|
552
551
|
ok: true,
|
|
553
552
|
msg: '已加入购物车!',
|
|
554
553
|
data: res,
|
|
555
554
|
})
|
|
556
555
|
})
|
|
557
556
|
.catch((e) => {
|
|
558
557
|
console.log('京购小程序批量加车失败dealCartFail: ', e)
|
|
559
558
|
resolve({
|
|
560
559
|
ok: false,
|
|
561
560
|
msg: '加购失败,请稍后重试',
|
|
562
561
|
})
|
|
563
562
|
})
|
|
564
563
|
} else {
|
|
565
564
|
console.log('==========>', 'M站批量加车!')
|
|
566
565
|
return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
|
|
567
566
|
resolve(res),
|
|
568
567
|
)
|
|
569
568
|
}
|
|
570
569
|
} else {
|
|
571
570
|
resolve({
|
|
572
571
|
ok: false,
|
|
573
572
|
msg: '加购sku不能为空',
|
|
574
573
|
})
|
|
575
574
|
}
|
|
576
575
|
})
|
|
577
576
|
}
|
|
578
577
|
|
|
579
578
|
productAddToCart(skuIdsStr, num) {
|
|
580
579
|
return new Promise((resolve) => {
|
|
581
580
|
if (window.AddcartToolObj) {
|
|
582
581
|
window.AddcartToolObj.addCart({
|
|
583
582
|
skuId: skuIdsStr,
|
|
584
583
|
num,
|
|
585
584
|
source: 'sjdpyw',
|
|
586
585
|
actId: '1',
|
|
587
586
|
loginType: window?.isJingGouMiniViewState ? '11' : '2',
|
|
588
587
|
sucFun(res) {
|
|
589
588
|
console.log(
|
|
590
589
|
'ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0',
|
|
591
590
|
res,
|
|
592
591
|
)
|
|
593
592
|
if (res.errId === '0' && res.cartJson) {
|
|
594
593
|
resolve({
|
|
595
594
|
ok: true,
|
|
596
595
|
msg: '已加入购物车!',
|
|
597
596
|
...res,
|
|
598
597
|
})
|
|
599
598
|
} else {
|
|
600
599
|
if (res.errId === '13') {
|
|
601
600
|
global.doLogin()
|
|
602
601
|
} else {
|
|
603
602
|
resolve({
|
|
604
603
|
ok: false,
|
|
605
604
|
msg: '加购失败,请稍后重试',
|
|
606
605
|
...res,
|
|
607
606
|
})
|
|
608
607
|
}
|
|
609
608
|
}
|
|
610
609
|
},
|
|
611
610
|
failFun(err) {
|
|
612
611
|
console.log('fail', err)
|
|
613
612
|
resolve({
|
|
614
613
|
ok: false,
|
|
615
614
|
msg: '加购失败,请稍后重试',
|
|
616
615
|
...err,
|
|
617
616
|
})
|
|
618
617
|
},
|
|
619
618
|
})
|
|
620
619
|
} else {
|
|
621
620
|
resolve({
|
|
622
621
|
ok: false,
|
|
623
622
|
msg: '购物车方法检查异常',
|
|
624
623
|
})
|
|
625
624
|
}
|
|
626
625
|
})
|
|
627
626
|
}
|
|
628
627
|
bMallGetUserInfo = () => {
|
|
629
628
|
return getBMallUserInfo()
|
|
630
629
|
}
|
|
631
630
|
async bMallAddCart(params = {}) {
|
|
632
631
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
633
632
|
client: 'H5',
|
|
634
633
|
clientVersion: '5.5.0',
|
|
635
634
|
})
|
|
636
635
|
}
|
|
637
636
|
async bMallChangeCart(params = {}) {
|
|
638
637
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
639
638
|
client: 'H5',
|
|
640
639
|
clientVersion: '5.5.0',
|
|
641
640
|
})
|
|
642
641
|
}
|
|
643
642
|
async bMallRemoveCart(params = {}) {
|
|
644
643
|
return await this.gatewayReq(
|
|
645
644
|
'bmall_cartRemove',
|
|
646
645
|
params,
|
|
647
646
|
{
|
|
648
647
|
client: 'H5',
|
|
649
648
|
clientVersion: '5.5.0',
|
|
650
649
|
},
|
|
651
650
|
)
|
|
652
651
|
}
|
|
653
652
|
async bMallGetOmittedProduct(params = {}) {
|
|
654
653
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
655
654
|
client: 'H5',
|
|
656
655
|
clientVersion: '5.5.0',
|
|
657
656
|
})
|
|
658
657
|
}
|
|
659
658
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
660
659
|
const params = await getParams({ ...data, skuId, bMallTag, num })
|
|
661
660
|
return await this.bMallAddCart(params)
|
|
662
661
|
}
|
|
663
662
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
664
663
|
const params = await getParams({ bMallTag })
|
|
665
664
|
delete params.operations
|
|
666
665
|
return await this.bMallGetOmittedProduct(params)
|
|
667
666
|
}
|
|
668
667
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
669
668
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
|
|
670
669
|
return await this.bMallRemoveCart(params)
|
|
671
670
|
}
|
|
672
671
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
673
672
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
|
|
674
673
|
return await this.bMallChangeCart(params)
|
|
675
674
|
}
|
|
676
675
|
|
|
677
676
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
678
677
|
if (!needRequest && isH5 && window?.bMallCartData) {
|
|
679
678
|
return window?.bMallCartData
|
|
680
679
|
}
|
|
681
680
|
const cartData = await this.bMallGetSkuNumService(bMallTag)
|
|
682
681
|
let items
|
|
683
682
|
if (cartData.ok && cartData.result) {
|
|
684
683
|
items = cartData?.result?.items || {}
|
|
685
684
|
}
|
|
686
685
|
if (isH5) {
|
|
687
686
|
window.bMallCartData = items
|
|
688
687
|
}
|
|
689
688
|
return items
|
|
690
689
|
}
|
|
691
690
|
|
|
692
691
|
async bMallCartHandle(goodItem, num) {
|
|
693
692
|
try {
|
|
694
693
|
const {
|
|
695
694
|
skuUuid,
|
|
696
695
|
limitUpper,
|
|
697
696
|
limitLower,
|
|
698
697
|
} = goodItem
|
|
699
698
|
let cartNum = Number(num)
|
|
700
699
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
701
700
|
cartNum = limitLower
|
|
702
701
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
703
702
|
cartNum = limitUpper
|
|
704
703
|
}
|
|
705
704
|
if (skuUuid && cartNum > 0) {
|
|
706
705
|
return this.bMallChangeCartService({
|
|
707
706
|
...goodItem,
|
|
708
707
|
skuUuid,
|
|
709
708
|
num: cartNum,
|
|
710
709
|
})
|
|
711
710
|
} else if (!skuUuid && cartNum > 0) {
|
|
712
711
|
return this.bMallAddCartService({ ...goodItem, num: cartNum })
|
|
713
712
|
} else if (skuUuid && !cartNum) {
|
|
714
713
|
return this.bMallRemoveCartService({
|
|
715
714
|
...goodItem,
|
|
716
715
|
skuUuid,
|
|
717
716
|
num: cartNum,
|
|
718
717
|
})
|
|
719
718
|
} else {
|
|
720
719
|
console.error('参数不全')
|
|
721
720
|
return false
|
|
722
721
|
}
|
|
723
722
|
} catch (e) {
|
|
724
723
|
console.error(e)
|
|
725
724
|
}
|
|
726
725
|
}
|
|
726
|
+
import Taro from '@tarojs/taro';
|
|
727
727
|
APPID,
|
|
728
728
|
JshopxColorFunctionIdList,
|
|
729
729
|
PagesColorFunctionIdList,
|
|
730
730
|
PAGES_DOMAIN,
|
|
731
731
|
B2BColorFunctionIdList,
|
|
732
732
|
MobileVerifyColorList,
|
|
733
733
|
AppVerifyColorList,
|
|
734
734
|
JshopxVerifyColorList,
|
|
735
735
|
BMallVerifyColorList,
|
|
736
736
|
shopMemberColorFunctionIdList,
|
|
737
737
|
isLanguageForEn,
|
|
738
738
|
isJdApp,
|
|
739
739
|
isIosDevice,
|
|
740
740
|
isAndroidDevice,
|
|
741
741
|
showSuccessToast,
|
|
742
742
|
showFailToast,
|
|
743
743
|
isH5,
|
|
744
744
|
isWxMinAndWxapp,
|
|
745
745
|
isMin,
|
|
746
746
|
isPc,
|
|
747
747
|
cookiesStr: '',
|
|
748
748
|
requestHeaderContentType: {
|
|
749
749
|
jsonHeader: {
|
|
750
750
|
'content-type': 'application/json;charset=utf-8',
|
|
751
751
|
},
|
|
752
752
|
formDataHeader: {
|
|
753
753
|
'content-type': 'application/x-www-form-urlencoded',
|
|
754
754
|
},
|
|
755
755
|
},
|
|
756
756
|
requestBaseParam: {
|
|
757
757
|
data: null,
|
|
758
758
|
header: {
|
|
759
759
|
'content-type': 'application/json;charset=utf-8',
|
|
760
760
|
},
|
|
761
761
|
},
|
|
762
762
|
timeOut: 7000,
|
|
763
763
|
apiClientParams: {
|
|
764
764
|
appid: 'wx_mini_app',
|
|
765
765
|
clientVersion: '11.0.0',
|
|
766
766
|
client: 'wh5',
|
|
767
767
|
area: '1_72_2799_0',
|
|
768
768
|
screen: `${Math.ceil(
|
|
769
769
|
getSystemInfo?.screenWidth * devicePixelRatio,
|
|
770
770
|
)}*${Math.ceil(getSystemInfo?.screenHeight * devicePixelRatio)}`,
|
|
771
771
|
uuid: UUID,
|
|
772
772
|
loginType: '11',
|
|
773
773
|
},
|
|
774
774
|
public addressFetchInfo: {
|
|
775
775
|
reqState: boolean
|
|
776
776
|
promiseInstance: null | Promise<any>
|
|
777
777
|
}
|
|
778
778
|
public getPromotionConfig: {
|
|
779
779
|
projectId: null | string | number
|
|
780
780
|
pageId: null | string | number
|
|
781
781
|
}
|
|
782
782
|
public resInfo: ServiceInterFace.HttpRequestInfo
|
|
783
783
|
public api: ServiceInterFace.HttpApi
|
|
784
784
|
public isPageDomain: boolean
|
|
785
785
|
public verifyColorList: string[]
|
|
786
786
|
constructor(opt) {
|
|
787
787
|
this._init()
|
|
788
788
|
this.addressFetchInfo = {
|
|
789
789
|
reqState: false,
|
|
790
790
|
promiseInstance: null,
|
|
791
791
|
}
|
|
792
792
|
this.getPromotionConfig = {
|
|
793
793
|
projectId: null,
|
|
794
794
|
pageId: null,
|
|
795
795
|
}
|
|
796
796
|
this._userAreaUpdateListen()
|
|
797
797
|
this.resInfo = this._getResConfig(opt)
|
|
798
798
|
this.api = api
|
|
799
799
|
this.isPageDomain = isH5
|
|
800
800
|
? window?.location?.hostname === PAGES_DOMAIN
|
|
801
801
|
: false
|
|
802
802
|
this.verifyColorList = [
|
|
803
803
|
...MobileVerifyColorList,
|
|
804
804
|
...AppVerifyColorList,
|
|
805
805
|
...JshopxVerifyColorList,
|
|
806
806
|
...BMallVerifyColorList,
|
|
807
807
|
]
|
|
808
808
|
}
|
|
809
809
|
_init(): void {
|
|
810
810
|
httpInterceptors.forEach((item) => {
|
|
811
811
|
Taro.addInterceptor((chain) => item(chain))
|
|
812
812
|
})
|
|
813
813
|
}
|
|
814
814
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
815
815
|
return Object.assign({}, DefaultConfig, opt)
|
|
816
816
|
}
|
|
817
817
|
|
|
818
818
|
_userAreaUpdateListen() {
|
|
819
819
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
|
|
820
820
|
this.updateApiClientParamsResInfo({
|
|
821
821
|
area,
|
|
822
822
|
})
|
|
823
823
|
})
|
|
824
824
|
}
|
|
825
825
|
updateApiClientParamsResInfo(opt = {}) {
|
|
826
826
|
this.resInfo.apiClientParams = {
|
|
827
827
|
...this.resInfo.apiClientParams,
|
|
828
828
|
...opt,
|
|
829
829
|
}
|
|
830
830
|
}
|
|
831
831
|
|
|
832
832
|
checkFunctionIdToReturnAppId(functionId) {
|
|
833
833
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
834
834
|
return APPID.JSHOPX_COLOR_APPID
|
|
835
835
|
} else if (
|
|
836
836
|
this.isPageDomain &&
|
|
837
837
|
PagesColorFunctionIdList.includes(functionId)
|
|
838
838
|
) {
|
|
839
839
|
return APPID.PAGES_COLOR_APPID
|
|
840
840
|
} else if (shopMemberColorFunctionIdList.includes(functionId)) {
|
|
841
841
|
return APPID.SHOP_MEMBER_COLOR_APPID
|
|
842
842
|
} else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
843
843
|
return APPID.B2B_COLOR_APPID
|
|
844
844
|
} else if (isPc) {
|
|
845
845
|
return APPID.MALL_COLOR_APPID
|
|
846
846
|
} else {
|
|
847
847
|
return APPID.SHOP_COLOR_APPID
|
|
848
848
|
}
|
|
849
849
|
}
|
|
850
850
|
|
|
851
851
|
gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
|
|
852
852
|
if (functionId === 'receiveShopCoupon') {
|
|
853
853
|
clientParams = Object.assign(
|
|
854
854
|
{},
|
|
855
855
|
{
|
|
856
856
|
loginType: '1',
|
|
857
857
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
858
858
|
},
|
|
859
859
|
clientParams,
|
|
860
860
|
)
|
|
861
861
|
}
|
|
862
862
|
const apiClientParams = Object.assign(
|
|
863
863
|
{},
|
|
864
864
|
this.resInfo.apiClientParams,
|
|
865
865
|
clientParams,
|
|
866
866
|
)
|
|
867
867
|
const isColorVerify = this.verifyColorList.includes(functionId);
|
|
868
868
|
const getReqData = {
|
|
869
869
|
functionId: functionId,
|
|
870
870
|
body: JSON.stringify(bodyParams),
|
|
871
871
|
t: Date.now(),
|
|
872
872
|
...apiClientParams,
|
|
873
873
|
}
|
|
874
874
|
const requestParams = {
|
|
875
875
|
functionId: getReqData?.functionId,
|
|
876
876
|
body: getReqData?.body,
|
|
877
877
|
appid: getReqData?.appid,
|
|
878
878
|
client: getReqData?.client,
|
|
879
879
|
clientVersion: getReqData?.clientVersion,
|
|
880
880
|
area: getReqData?.area,
|
|
881
881
|
requestTimeStamp: getReqData?.t,
|
|
882
882
|
}
|
|
883
883
|
return http
|
|
884
884
|
.request({
|
|
885
885
|
url: this.api.apiFunc,
|
|
886
886
|
data: getReqData,
|
|
887
887
|
isColorVerify,
|
|
888
888
|
})
|
|
889
889
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
890
890
|
const { statusCode, data, status, msg } = res
|
|
891
891
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
892
892
|
ok: true,
|
|
893
893
|
}
|
|
894
894
|
if ((statusCode === 200 || status === '0') && data) {
|
|
895
895
|
changeRes = this.dealResponseFormatRes(data, getReqData)
|
|
896
896
|
return changeRes
|
|
897
897
|
} else {
|
|
898
898
|
sgmCustomReport({
|
|
899
899
|
code: getSgmCustomCode('interface_data_error'),
|
|
900
900
|
msg: {
|
|
901
901
|
subMsg: '接口请求异常',
|
|
902
902
|
functionId,
|
|
903
903
|
statusCode,
|
|
904
904
|
source: 'remote',
|
|
905
905
|
status,
|
|
906
906
|
msg,
|
|
907
907
|
requestParams,
|
|
908
908
|
},
|
|
909
909
|
})
|
|
910
910
|
draInterfaceCustomReport({
|
|
911
911
|
...getReqData,
|
|
912
912
|
...res,
|
|
913
913
|
source: 'remote',
|
|
914
914
|
})
|
|
915
915
|
changeRes = {
|
|
916
916
|
...data,
|
|
917
917
|
statusCode,
|
|
918
918
|
status,
|
|
919
919
|
msg,
|
|
920
920
|
ok: false,
|
|
921
921
|
}
|
|
922
922
|
return changeRes
|
|
923
923
|
}
|
|
924
924
|
})
|
|
925
925
|
.catch((res) => {
|
|
926
926
|
const propertyNames = Object.getOwnPropertyNames(res)
|
|
927
927
|
const resObject = {}
|
|
928
928
|
propertyNames.forEach((propertyName) => {
|
|
929
929
|
resObject[propertyName] = res[propertyName]
|
|
930
930
|
})
|
|
931
931
|
sgmCustomReport({
|
|
932
932
|
code: getSgmCustomCode('interface_data_error'),
|
|
933
933
|
msg: {
|
|
934
934
|
subMsg: '接口请求错误',
|
|
935
935
|
functionId,
|
|
936
936
|
source: 'remote',
|
|
937
937
|
requestParams,
|
|
938
938
|
catchError: resObject,
|
|
939
939
|
},
|
|
940
940
|
})
|
|
941
941
|
draInterfaceCustomReport({
|
|
942
942
|
...getReqData,
|
|
943
943
|
...resObject,
|
|
944
944
|
source: 'remote',
|
|
945
945
|
})
|
|
946
946
|
return {
|
|
947
947
|
...resObject,
|
|
948
948
|
ok: false,
|
|
949
949
|
} as ServiceInterFace.RequestResponseFormatRes
|
|
950
950
|
})
|
|
951
951
|
}
|
|
952
952
|
|
|
953
953
|
dealResponseFormatRes(data, reqData) {
|
|
954
954
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
955
955
|
ok: true,
|
|
956
956
|
}
|
|
957
957
|
const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
|
|
958
958
|
? Number(data.code)
|
|
959
959
|
: -1
|
|
960
960
|
const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
|
|
961
961
|
? Number(data.subCode)
|
|
962
962
|
: -1
|
|
963
963
|
if (
|
|
964
964
|
data.success === true ||
|
|
965
965
|
data.isSuccess ||
|
|
966
966
|
resCode === 0 ||
|
|
967
967
|
resCode === 200 ||
|
|
968
968
|
subCode === 0
|
|
969
969
|
) {
|
|
970
970
|
changeRes = {
|
|
971
971
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
972
972
|
? data.result
|
|
973
973
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
974
974
|
? data.data
|
|
975
975
|
: data,
|
|
976
976
|
code: data.code ?? 200,
|
|
977
977
|
ok: true,
|
|
978
978
|
source: data,
|
|
979
979
|
}
|
|
980
980
|
return changeRes
|
|
981
981
|
} else {
|
|
982
982
|
changeRes = {
|
|
983
983
|
...data,
|
|
984
984
|
ok: false,
|
|
985
985
|
}
|
|
986
986
|
if (reqData && resCode !== 3) {
|
|
987
987
|
const getReportMsgData = reqData['hybridId']
|
|
988
988
|
? {
|
|
989
989
|
subMsg: '预加载接口请求数据异常',
|
|
990
990
|
hybridId: reqData?.hybridId,
|
|
991
991
|
requestId: reqData?.requestId,
|
|
992
992
|
param: reqData?.param,
|
|
993
993
|
source: 'remote',
|
|
994
994
|
}
|
|
995
995
|
: {
|
|
996
996
|
subMsg: '接口请求返回数据异常',
|
|
997
997
|
functionId: reqData?.functionId,
|
|
998
998
|
code: resCode,
|
|
999
999
|
source: 'remote',
|
|
1000
1000
|
requestParams: {
|
|
1001
1001
|
functionId: reqData?.functionId,
|
|
1002
1002
|
body: reqData?.body,
|
|
1003
1003
|
appid: reqData?.appid,
|
|
1004
1004
|
client: reqData?.client,
|
|
1005
1005
|
clientVersion: reqData?.clientVersion,
|
|
1006
1006
|
area: reqData?.area,
|
|
1007
1007
|
requestTimeStamp: reqData?.t,
|
|
1008
1008
|
},
|
|
1009
1009
|
resData: data,
|
|
1010
1010
|
}
|
|
1011
1011
|
sgmCustomReport({
|
|
1012
1012
|
code: getSgmCustomCode('interface_data_error'),
|
|
1013
1013
|
msg: getReportMsgData,
|
|
1014
1014
|
})
|
|
1015
1015
|
draInterfaceCustomReport({
|
|
1016
1016
|
...reqData,
|
|
1017
1017
|
...data,
|
|
1018
1018
|
source: 'remote',
|
|
1019
1019
|
})
|
|
1020
1020
|
}
|
|
1021
1021
|
return changeRes
|
|
1022
1022
|
}
|
|
1023
1023
|
}
|
|
1024
1024
|
|
|
1025
1025
|
async receiveCoupon(param = {}, clientParams) {
|
|
1026
1026
|
console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
1027
1027
|
return await this.gatewayReq(
|
|
1028
1028
|
'receiveShopCoupon',
|
|
1029
1029
|
{
|
|
1030
1030
|
operation: '3',
|
|
1031
1031
|
...param,
|
|
1032
1032
|
},
|
|
1033
1033
|
{ ...clientParams },
|
|
1034
1034
|
);
|
|
1035
1035
|
}
|
|
1036
1036
|
|
|
1037
1037
|
getCustomerCenterDispatch(params = {}) {
|
|
1038
1038
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
1039
1039
|
clientVersion: '9.2.0',
|
|
1040
1040
|
client: 'H5',
|
|
1041
1041
|
uuid: 88888,
|
|
1042
1042
|
appid: 'shopmember_m_jd_com',
|
|
1043
1043
|
})
|
|
1044
1044
|
}
|
|
1045
1045
|
|
|
1046
1046
|
batchAddCart(...args) {
|
|
1047
1047
|
let skuIds, num, showToast, giftCard;
|
|
1048
1048
|
if (['number', 'string'].includes(typeof args[0])) {
|
|
1049
1049
|
[skuIds, num = 1, showToast = true, giftCard = false] = args;
|
|
1050
1050
|
} else if (typeof args[0] === 'object' && args[0] !== null) {
|
|
1051
1051
|
const params = args[0];
|
|
1052
1052
|
skuIds = params.skuIds;
|
|
1053
1053
|
num = params.num || 1;
|
|
1054
1054
|
showToast = params.showToast !== undefined ? params.showToast : true;
|
|
1055
1055
|
giftCard = params.giftCard !== undefined ? params.giftCard : false;
|
|
1056
1056
|
} else {
|
|
1057
1057
|
console.error('batchAddCart() Invalid arguments!', args);
|
|
1058
1058
|
const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
|
|
1059
1059
|
showFailToast({
|
|
1060
1060
|
title: msg,
|
|
1061
1061
|
});
|
|
1062
1062
|
return Promise.resolve({
|
|
1063
1063
|
ok: false,
|
|
1064
1064
|
msg,
|
|
1065
1065
|
});
|
|
1066
1066
|
}
|
|
1067
1067
|
const addToWhereText = giftCard ? '购物清单' : '购物车';
|
|
1068
1068
|
const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
|
|
1069
1069
|
const failMsg = isLanguageForEn
|
|
1070
1070
|
? 'Please retry later'
|
|
1071
1071
|
: `加入${addToWhereText}失败,请稍后重试!`;
|
|
1072
1072
|
if (skuIds) {
|
|
1073
1073
|
return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
|
|
1074
1074
|
.then((res: ServiceInterFace.SkuToCartDataRes) => {
|
|
1075
1075
|
if (res?.ok) {
|
|
1076
1076
|
if (showToast && !res?.isOpenApp)
|
|
1077
1077
|
showSuccessToast({
|
|
1078
1078
|
title: successMsg,
|
|
1079
1079
|
})
|
|
1080
1080
|
} else {
|
|
1081
1081
|
showToast &&
|
|
1082
1082
|
showFailToast({
|
|
1083
1083
|
title: res?.errMsg || failMsg,
|
|
1084
1084
|
})
|
|
1085
1085
|
}
|
|
1086
1086
|
return Promise.resolve(res)
|
|
1087
1087
|
})
|
|
1088
1088
|
.catch((e) => {
|
|
1089
1089
|
console.log('调用加购方法异常=======>', e)
|
|
1090
1090
|
return Promise.resolve({
|
|
1091
1091
|
ok: false,
|
|
1092
1092
|
msg: failMsg,
|
|
1093
1093
|
})
|
|
1094
1094
|
})
|
|
1095
1095
|
} else {
|
|
1096
1096
|
return Promise.resolve({
|
|
1097
1097
|
ok: false,
|
|
1098
1098
|
msg: failMsg,
|
|
1099
1099
|
})
|
|
1100
1100
|
}
|
|
1101
1101
|
}
|
|
1102
1102
|
|
|
1103
1103
|
async giftCardAddCart(skuList, num) {
|
|
1104
1104
|
return this.gatewayReq('giftCardAddCart', {
|
|
1105
1105
|
skuList,
|
|
1106
1106
|
num: Number(num),
|
|
1107
1107
|
});
|
|
1108
1108
|
}
|
|
1109
1109
|
|
|
1110
1110
|
_addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
|
|
1111
1111
|
return new Promise((resolve) => {
|
|
1112
1112
|
const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
|
|
1113
1113
|
if (productIdsArr.length > 0) {
|
|
1114
1114
|
if (giftCard) {
|
|
1115
1115
|
this.giftCardAddCart(productIdsArr, addCardNum)
|
|
1116
1116
|
.then((res) => {
|
|
1117
1117
|
if (res?.code === '0' && res?.result?.value) {
|
|
1118
1118
|
resolve({
|
|
1119
1119
|
ok: true,
|
|
1120
1120
|
})
|
|
1121
1121
|
} else {
|
|
1122
1122
|
resolve({
|
|
1123
1123
|
ok: false,
|
|
1124
1124
|
msg: '加购失败,请稍后重试',
|
|
1125
1125
|
})
|
|
1126
1126
|
}
|
|
1127
1127
|
})
|
|
1128
1128
|
.catch((e) => {
|
|
1129
1129
|
console.error('礼品卡加车失败: ', e)
|
|
1130
1130
|
resolve({
|
|
1131
1131
|
ok: false,
|
|
1132
1132
|
msg: '加购失败,请稍后重试',
|
|
1133
1133
|
});
|
|
1134
1134
|
});
|
|
1135
1135
|
} else if (isJdApp) {
|
|
1136
1136
|
console.log('==========>', 'app原生批量加车!,小程序端暂不涉及');
|
|
1137
1137
|
} else if (isMin) {
|
|
1138
1138
|
console.log('==========>', '京购批量加车!')
|
|
1139
1139
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
1140
1140
|
return {
|
|
1141
1141
|
skuId: skuItem,
|
|
1142
1142
|
buyNum: addCardNum,
|
|
1143
1143
|
}
|
|
1144
1144
|
})
|
|
1145
1145
|
global.wxAppBizInstance
|
|
1146
1146
|
.addCart({ commArr: productsAddCartList })
|
|
1147
1147
|
.then((res) => {
|
|
1148
1148
|
console.log('dealCartSuccess: ', res)
|
|
1149
1149
|
resolve({
|
|
1150
1150
|
ok: true,
|
|
1151
1151
|
msg: '已加入购物车!',
|
|
1152
1152
|
data: res,
|
|
1153
1153
|
})
|
|
1154
1154
|
})
|
|
1155
1155
|
.catch((e) => {
|
|
1156
1156
|
console.log('京购小程序批量加车失败dealCartFail: ', e)
|
|
1157
1157
|
resolve({
|
|
1158
1158
|
ok: false,
|
|
1159
1159
|
msg: '加购失败,请稍后重试',
|
|
1160
1160
|
})
|
|
1161
1161
|
})
|
|
1162
1162
|
} else {
|
|
1163
1163
|
console.log('==========>', 'M站批量加车!')
|
|
1164
1164
|
return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
|
|
1165
1165
|
resolve(res),
|
|
1166
1166
|
)
|
|
1167
1167
|
}
|
|
1168
1168
|
} else {
|
|
1169
1169
|
resolve({
|
|
1170
1170
|
ok: false,
|
|
1171
1171
|
msg: '加购sku不能为空',
|
|
1172
1172
|
})
|
|
1173
1173
|
}
|
|
1174
1174
|
})
|
|
1175
1175
|
}
|
|
1176
1176
|
|
|
1177
1177
|
productAddToCart() {
|
|
1178
1178
|
return Promise.resolve({
|
|
1179
1179
|
ok: false,
|
|
1180
1180
|
msg: 'productAddToCart暂不支持小程序',
|
|
1181
1181
|
});
|
|
1182
1182
|
}
|
|
1183
1183
|
bMallGetUserInfo = () => {
|
|
1184
1184
|
return getBMallUserInfo()
|
|
1185
1185
|
}
|
|
1186
1186
|
async bMallAddCart(params = {}) {
|
|
1187
1187
|
console.warn('bMallAddCart 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
1188
1188
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
1189
1189
|
client: 'H5',
|
|
1190
1190
|
clientVersion: '5.5.0',
|
|
1191
1191
|
})
|
|
1192
1192
|
}
|
|
1193
1193
|
async bMallChangeCart(params = {}) {
|
|
1194
1194
|
console.warn('bMallChangeCart 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
1195
1195
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
1196
1196
|
client: 'H5',
|
|
1197
1197
|
clientVersion: '5.5.0',
|
|
1198
1198
|
})
|
|
1199
1199
|
}
|
|
1200
1200
|
async bMallRemoveCart(params = {}) {
|
|
1201
1201
|
console.warn('bMallRemoveCart 方法在微信京购小程序环境未经验证,请不要使用!');
|
|
1202
1202
|
return await this.gatewayReq(
|
|
1203
1203
|
'bmall_cartRemove',
|
|
1204
1204
|
params,
|
|
1205
1205
|
{
|
|
1206
1206
|
client: 'H5',
|
|
1207
1207
|
clientVersion: '5.5.0',
|
|
1208
1208
|
},
|
|
1209
1209
|
)
|
|
1210
1210
|
}
|
|
1211
1211
|
async bMallGetOmittedProduct(params = {}) {
|
|
1212
1212
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
1213
1213
|
client: 'H5',
|
|
1214
1214
|
clientVersion: '5.5.0',
|
|
1215
1215
|
})
|
|
1216
1216
|
}
|
|
1217
1217
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
1218
1218
|
const params = await getParams({ ...data, skuId, bMallTag, num })
|
|
1219
1219
|
return await this.bMallAddCart(params)
|
|
1220
1220
|
}
|
|
1221
1221
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
1222
1222
|
const params = await getParams({ bMallTag })
|
|
1223
1223
|
delete params.operations
|
|
1224
1224
|
return await this.bMallGetOmittedProduct(params)
|
|
1225
1225
|
}
|
|
1226
1226
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
1227
1227
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
|
|
1228
1228
|
return await this.bMallRemoveCart(params)
|
|
1229
1229
|
}
|
|
1230
1230
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
1231
1231
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
|
|
1232
1232
|
return await this.bMallChangeCart(params)
|
|
1233
1233
|
}
|
|
1234
1234
|
|
|
1235
1235
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
1236
1236
|
if (!needRequest && isH5 && window?.bMallCartData) {
|
|
1237
1237
|
return window?.bMallCartData
|
|
1238
1238
|
}
|
|
1239
1239
|
const cartData = await this.bMallGetSkuNumService(bMallTag)
|
|
1240
1240
|
let items
|
|
1241
1241
|
if (cartData.ok && cartData.result) {
|
|
1242
1242
|
items = cartData?.result?.items || {}
|
|
1243
1243
|
}
|
|
1244
1244
|
if (isH5) {
|
|
1245
1245
|
window.bMallCartData = items
|
|
1246
1246
|
}
|
|
1247
1247
|
return items
|
|
1248
1248
|
}
|
|
1249
1249
|
|
|
1250
1250
|
async bMallCartHandle(goodItem, num) {
|
|
1251
1251
|
try {
|
|
1252
1252
|
const {
|
|
1253
1253
|
skuUuid,
|
|
1254
1254
|
limitUpper,
|
|
1255
1255
|
limitLower,
|
|
1256
1256
|
} = goodItem
|
|
1257
1257
|
let cartNum = Number(num)
|
|
1258
1258
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
1259
1259
|
cartNum = limitLower
|
|
1260
1260
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
1261
1261
|
cartNum = limitUpper
|
|
1262
1262
|
}
|
|
1263
1263
|
if (skuUuid && cartNum > 0) {
|
|
1264
1264
|
return this.bMallChangeCartService({
|
|
1265
1265
|
...goodItem,
|
|
1266
1266
|
skuUuid,
|
|
1267
1267
|
num: cartNum,
|
|
1268
1268
|
})
|
|
1269
1269
|
} else if (!skuUuid && cartNum > 0) {
|
|
1270
1270
|
return this.bMallAddCartService({ ...goodItem, num: cartNum })
|
|
1271
1271
|
} else if (skuUuid && !cartNum) {
|
|
1272
1272
|
return this.bMallRemoveCartService({
|
|
1273
1273
|
...goodItem,
|
|
1274
1274
|
skuUuid,
|
|
1275
1275
|
num: cartNum,
|
|
1276
1276
|
})
|
|
1277
1277
|
} else {
|
|
1278
1278
|
console.error('参数不全')
|
|
1279
1279
|
return false
|
|
1280
1280
|
}
|
|
1281
1281
|
} catch (e) {
|
|
1282
1282
|
console.error(e)
|
|
1283
1283
|
}
|
|
1284
1284
|
}
|