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