@conecli/cone-render 0.10.1-shop3.138 → 0.10.1-shop3.139

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.
@@ -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
  draBusinessCustomReport,
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
  draInterfaceCustomReport,
23
22
  isHarmonyDevice,
24
23
  isAscfApp,
25
24
  callRouterIOS,
26
25
  callRouterAndroid,
27
26
  callRouterHarmony,
28
27
  sendNativePageToShowCartFloatBtn,
29
28
  cookiesStr: '',
30
29
  requestHeaderContentType: {
31
30
  jsonHeader: {
32
31
  'content-type': 'application/json;charset=utf-8',
33
32
  },
34
33
  formDataHeader: {
35
34
  'content-type': 'application/x-www-form-urlencoded',
36
35
  },
37
36
  },
38
37
  requestBaseParam: {
39
38
  data: null,
40
39
  header: {
41
40
  'content-type': 'application/json;charset=utf-8',
42
41
  },
43
42
  },
44
43
  timeOut: 7000,
45
44
  apiClientParams: {
46
45
  clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
47
46
  client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
48
47
  area: '1_72_2799_0',
49
48
  screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
50
49
  window.screen?.height * devicePixelRatio,
51
50
  )}`,
52
51
  uuid: UUID,
53
52
  },
54
53
  window.shopGlobalSwitch?.useNativeHarmonyAddCartJdAppVersion;
55
54
  nativeHarmonyAddCartJdAppVersion && jdAppVersionCompare(nativeHarmonyAddCartJdAppVersion) >= 0;
56
55
  public addressFetchInfo: {
57
56
  reqState: boolean;
58
57
  promiseInstance: null | Promise<any>;
59
58
  };
60
59
  public getPromotionConfig: {
61
60
  projectId: null | string | number;
62
61
  pageId: null | string | number;
63
62
  };
64
63
  public resInfo: ServiceInterFace.HttpRequestInfo;
65
64
  public api: ServiceInterFace.HttpApi;
66
65
  public isPageDomain: boolean;
67
66
  public verifyColorList: string[];
68
67
  private isShowJdShopCartFloatBtn: boolean;
69
68
  constructor(opt) {
70
69
  this._init();
71
70
  this.addressFetchInfo = {
72
71
  reqState: false,
73
72
  promiseInstance: null,
74
73
  };
75
74
  this.getPromotionConfig = {
76
75
  projectId: null,
77
76
  pageId: null,
78
77
  };
79
78
  this._userAreaUpdateListen();
80
79
  this.resInfo = this._getResConfig(opt);
81
80
  this.api = api;
82
81
  this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
83
82
  this.verifyColorList = [
84
83
  ...MobileVerifyColorList,
85
84
  ...AppVerifyColorList,
86
85
  ...JshopxVerifyColorList,
87
86
  ...BMallVerifyColorList,
88
87
  ];
89
88
  this.isShowJdShopCartFloatBtn =
90
89
  jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
91
90
  }
92
91
  _init(): void {
93
92
  httpInterceptors.forEach((item) => {
94
93
  Taro.addInterceptor((chain) => item(chain));
95
94
  });
96
95
  }
97
96
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
98
97
  return Object.assign({}, DefaultConfig, opt);
99
98
  }
100
99
 
101
100
  _userAreaUpdateListen() {
102
101
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
103
102
  this.updateApiClientParamsResInfo(areaInfo);
104
103
  console.log(
105
104
  'cone-render收到原生端获取传来的四级地址信息',
106
105
  areaInfo,
107
106
  '更新后的接口底层信息',
108
107
  this.resInfo.apiClientParams,
109
108
  );
110
109
  });
111
110
  }
112
111
  updateApiClientParamsResInfo(opt = {}) {
113
112
  const { area, realTimeArea, ...others } = opt;
114
113
  this.resInfo.apiClientParams = {
115
114
  ...this.resInfo.apiClientParams,
116
115
  ...others,
117
116
  };
118
117
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
119
118
  realTimeArea &&
120
119
  realTimeArea !== '' &&
121
120
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
122
121
  }
123
122
 
124
123
  checkFunctionIdToReturnAppId(functionId) {
125
124
  if (JshopxColorFunctionIdList.includes(functionId)) {
126
125
  return APPID.JSHOPX_COLOR_APPID;
127
126
  } else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
128
127
  return APPID.PAGES_COLOR_APPID;
129
128
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
130
129
  return APPID.SHOP_MEMBER_COLOR_APPID;
131
130
  } else if (B2BColorFunctionIdList.includes(functionId)) {
132
131
  return APPID.B2B_COLOR_APPID;
133
132
  } else if (isPc) {
134
133
  return APPID.MALL_COLOR_APPID;
135
134
  } else {
136
135
  return APPID.SHOP_COLOR_APPID;
137
136
  }
138
137
  }
139
138
 
140
139
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
141
140
  if (
142
141
  functionId === 'receiveShopCoupon' &&
143
142
  ((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
144
143
  isWxMinAndWxapp)
145
144
  ) {
146
145
  clientParams = Object.assign(
147
146
  {},
148
147
  {
149
148
  loginType: isAscfApp ? '2' : '1',
150
149
  loginWQBiz: WXAPP_BIZ_KEY,
151
150
  },
152
151
  clientParams,
153
152
  );
154
153
  }
155
154
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
156
155
  typeof apiClientParams.appid === 'undefined' &&
157
156
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
158
157
  const isColorVerify = this.verifyColorList.includes(functionId);
159
158
  const getReqData = {
160
159
  functionId: functionId,
161
160
  body: JSON.stringify(bodyParams),
162
161
  t: Date.now(),
163
162
  ...apiClientParams,
164
163
  };
165
164
  return http
166
165
  .request({
167
166
  url: this.api.apiFunc,
168
167
  data: getReqData,
169
168
  isColorVerify,
170
169
  })
171
170
  .then((res: ServiceInterFace.RequestPromiseRes) => {
172
171
  const { statusCode, data, status, msg } = res;
173
172
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
174
173
  ok: true,
175
174
  };
176
175
  if ((statusCode === 200 || status === '0') && data) {
177
176
  changeRes = this.dealResponseFormatRes(data);
178
177
  return changeRes;
179
178
  } else {
180
179
  changeRes = {
181
180
  ...data,
182
181
  statusCode,
183
182
  status,
184
183
  msg,
185
184
  ok: false,
186
185
  };
187
186
  return changeRes;
188
187
  }
189
188
  })
190
189
  .catch((res) => {
191
190
  const propertyNames = Object.getOwnPropertyNames(res);
192
191
  const resObject = {};
193
192
  propertyNames.forEach((propertyName) => {
194
193
  resObject[propertyName] = res[propertyName];
195
194
  });
196
195
  draInterfaceCustomReport({
197
196
  eventName: 'apiStatusCode',
198
197
  errorName: `shop_${functionId}_error`,
199
198
  errorMessage: `接口返回statusCode为${res?.statusCode || res?.status}`,
200
199
  url: this.api.apiFunc,
201
200
  source: 'remote',
202
201
  requestType: res?.requestType,
203
202
  functionId: getReqData?.functionId,
204
203
  appid: getReqData?.appid,
205
204
  client: getReqData?.client,
206
205
  clientVersion: getReqData?.clientVersion,
207
206
  statusCode: res?.statusCode,
208
207
  status: res?.status,
209
208
  statusText: res?.statusText,
210
209
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
211
210
  originReqDataStr: JSON.stringify(getReqData),
212
211
  });
213
212
  return {
214
213
  ...resObject,
215
214
  ok: false,
216
215
  } as ServiceInterFace.RequestResponseFormatRes;
217
216
  });
218
217
  }
219
218
 
220
219
  dealResponseFormatRes(data) {
221
220
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
222
221
  ok: true,
223
222
  };
224
223
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
225
224
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
226
225
  ? Number(data.subCode)
227
226
  : -1;
228
227
  if (
229
228
  data.success === true ||
230
229
  data.isSuccess ||
231
230
  resCode === 0 ||
232
231
  resCode === 200 ||
233
232
  subCode === 0
234
233
  ) {
235
234
  changeRes = {
236
235
  result: Object.prototype.hasOwnProperty.call(data, 'result')
237
236
  ? data.result
238
237
  : Object.prototype.hasOwnProperty.call(data, 'data')
239
238
  ? data.data
240
239
  : data,
241
240
  code: data.code ?? 200,
242
241
  ok: true,
243
242
  source: data,
244
243
  };
245
244
  return changeRes;
246
245
  } else {
247
246
  changeRes = {
248
247
  ...data,
249
248
  ok: false,
250
249
  };
251
250
  return changeRes;
252
251
  }
253
252
  }
254
253
 
255
254
  async receiveCoupon(param = {}, clientParams) {
256
255
  const loginType = isPc ? { loginType: 3 } : {};
257
256
  return await this.gatewayReq(
258
257
  'receiveShopCoupon',
259
258
  {
260
259
  operation: '3',
261
260
  ...param,
262
261
  },
263
262
  { ...loginType, ...clientParams },
264
263
  );
265
264
  }
266
265
 
267
266
  getCustomerCenterDispatch(params = {}) {
268
267
  return this.gatewayReq('customerCenterDispatch', params, {
269
268
  clientVersion: '9.2.0',
270
269
  client: 'H5',
271
270
  uuid: 88888,
272
271
  appid: 'shopmember_m_jd_com',
273
272
  });
274
273
  }
275
274
 
276
275
  batchAddCart(...args) {
277
276
  let skuIds, num, showToast, giftCard, extFlag, extQuery;
278
277
  if (['number', 'string'].includes(typeof args[0])) {
279
278
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
280
279
  } else if (typeof args[0] === 'object' && args[0] !== null) {
281
280
  const params = args[0];
282
281
  skuIds = params.skuIds;
283
282
  num = params.num || 1;
284
283
  showToast = params.showToast !== undefined ? params.showToast : true;
285
284
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
286
285
  extFlag = params.extFlag !== undefined ? params.extFlag : null;
287
286
  extQuery = params.extQuery !== undefined ? params.extQuery : null;
288
287
  } else {
289
288
  try {
290
289
  const data = {
291
290
  eventName: 'business',
292
291
  errorName: 'shop_batchAddCart_error',
293
292
  errorMessage: '入参不合法',
294
293
  extraData: JSON.stringify(args),
295
294
  };
296
295
  draBusinessCustomReport(data);
297
296
  } catch (e) {
298
297
  console.error('draBusinessCustomReport error:', e);
299
298
  }
300
299
  const msg = global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
301
300
  showFailToast({
302
301
  title: msg,
303
302
  });
304
303
  return Promise.resolve({
305
304
  ok: false,
306
305
  msg,
307
306
  });
308
307
  }
309
308
  const successMsg = giftCard
310
309
  ? global?.languageJsonData?.successAddShopList || '加入购物清单成功'
311
310
  : global?.languageJsonData?.successAddCart || '加入购物车成功';
312
311
  const failMsg = giftCard
313
312
  ? global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试'
314
313
  : global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
315
314
  if (skuIds) {
316
315
  return this._addShopGoodCart(`${skuIds}`, `${num}`, {
317
316
  giftCard,
318
317
  extFlag,
319
318
  extQuery,
320
319
  })
321
320
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
322
321
  if (res?.ok) {
323
322
  showToast &&
324
323
  !res?.isOpenApp &&
325
324
  showSuccessToast({
326
325
  title: successMsg,
327
326
  });
328
327
  this.isShowJdShopCartFloatBtn &&
329
328
  sendNativePageToShowCartFloatBtn({
330
329
  isShow: true,
331
330
  });
332
331
  } else {
333
332
  showToast &&
334
333
  showFailToast({
335
334
  title: res?.errMsg || failMsg,
336
335
  });
337
336
  }
338
337
  return Promise.resolve(res);
339
338
  })
340
339
  .catch((e) => {
341
340
  console.log('调用加购方法异常=======>', e);
342
341
  return Promise.resolve({
343
342
  ok: false,
344
343
  msg: failMsg,
345
344
  });
346
345
  });
347
346
  } else {
348
347
  try {
349
348
  const data = {
350
349
  eventName: 'business',
351
350
  errorName: 'shop_batchAddCart_error',
352
351
  errorMessage: '没有传入合法的skuIds',
353
352
  };
354
353
  draBusinessCustomReport(data);
355
354
  } catch (e) {
356
355
  console.error('draBusinessCustomReport error:', e);
357
356
  }
358
357
  return Promise.resolve({
359
358
  ok: false,
360
359
  msg: failMsg,
361
360
  });
362
361
  }
363
362
  }
364
363
 
365
364
  async giftCardAddCart(skuList, num) {
366
365
  const loginType = isPc ? { loginType: 3 } : {};
367
366
  return this.gatewayReq(
368
367
  'giftCardAddCart',
369
368
  {
370
369
  skuList,
371
370
  num: Number(num),
372
371
  },
373
372
  { ...loginType },
374
373
  );
375
374
  }
376
375
 
377
376
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard, extFlag, extQuery }) {
378
377
  return new Promise((resolve) => {
379
378
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
380
379
  if (productIdsArr.length > 0) {
381
380
  if (giftCard) {
382
381
  this.giftCardAddCart(productIdsArr, addCardNum)
383
382
  .then((res) => {
384
383
  if (res?.code === '0' && res?.result?.value) {
385
384
  resolve({
386
385
  ok: true,
387
386
  });
388
387
  } else {
389
388
  try {
390
389
  const data = {
391
390
  eventName: 'business',
392
391
  errorName: 'shop_batchAddCart_error',
393
392
  errorMessage: '礼品卡加车接口返回加车失败标识',
394
393
  };
395
394
  draBusinessCustomReport(data);
396
395
  } catch (e) {
397
396
  console.error('draBusinessCustomReport error:', e);
398
397
  }
399
398
  resolve({
400
399
  ok: false,
401
400
  msg: '加购失败,请稍后重试',
402
401
  });
403
402
  }
404
403
  })
405
404
  .catch((e) => {
406
405
  console.error('礼品卡加车失败: ', e);
407
406
  resolve({
408
407
  ok: false,
409
408
  msg: '加购失败,请稍后重试',
410
409
  });
411
410
  });
412
411
  } else if (
413
412
  isJdApp &&
414
413
  (!isHarmonyDevice || (isHarmonyDevice && useNativeHarmonyAddCartJd))
415
414
  ) {
416
415
  const nativeAddCartCallBack = `nativeBatchAddCart${
417
416
  Date.now() + Number(productIdsArr[0]) + Number(addCardNum)
418
417
  }`;
419
418
  console.log(
420
419
  '==========>',
421
420
  '使用原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
422
421
  nativeAddCartCallBack,
423
422
  );
424
423
  if (!window[nativeAddCartCallBack]) {
425
424
  window[nativeAddCartCallBack] = (res) => {
426
425
  const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
427
426
  console.info(
428
427
  '获取批量加车原始数据',
429
428
  res,
430
429
  '====转换后的json数据为===',
431
430
  getMessageJsonData,
432
431
  );
433
432
  try {
434
433
  if (isAndroidDevice) {
435
434
  const isOk = getMessageJsonData?.status === '0';
436
435
  isOk
437
436
  ? resolve({
438
437
  ok: true,
439
438
  msg: '已加入购物车!',
440
439
  cartNum: getMessageJsonData?.data?.response?.cartNum || 0,
441
440
  })
442
441
  : resolve({
443
442
  ok: false,
444
443
  msg: '加购失败,请稍后重试',
445
444
  errMsg: getMessageJsonData?.data?.message ?? '',
446
445
  });
447
446
  if (!isOk) {
448
447
  const data = {
449
448
  eventName: 'business',
450
449
  errorName: 'shop_batchAddCart_error',
451
450
  errorMessage: 'H5调用Android原生加车失败',
452
451
  };
453
452
  draBusinessCustomReport(data);
454
453
  }
455
454
  } else if (isIosDevice) {
456
455
  const isOk =
457
456
  getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
458
457
  isOk
459
458
  ? resolve({
460
459
  ok: true,
461
460
  msg: '已加入购物车!',
462
461
  cartNum: getMessageJsonData?.data?.response?.cartNum || 0,
463
462
  })
464
463
  : resolve({
465
464
  ok: false,
466
465
  msg: '批量加车失败,请稍后重试',
467
466
  errMsg: getMessageJsonData?.data?.message ?? '',
468
467
  });
469
468
  if (!isOk) {
470
469
  const data = {
471
470
  eventName: 'business',
472
471
  errorName: 'shop_batchAddCart_error',
473
472
  errorMessage: 'H5调用IOS原生加车失败',
474
473
  };
475
474
  draBusinessCustomReport(data);
476
475
  }
477
476
  } else if (isHarmonyDevice) {
478
477
  const isOk =
479
478
  getMessageJsonData?.data?.code === 0 &&
480
479
  getMessageJsonData?.data?.response?.resultCode === 0;
481
480
  isOk
482
481
  ? resolve({
483
482
  ok: true,
484
483
  msg: '已加入购物车!',
485
484
  cartNum: getMessageJsonData?.data?.response?.cartNum || 0,
486
485
  })
487
486
  : resolve({
488
487
  ok: false,
489
488
  msg: '加购失败,请稍后重试',
490
489
  errMsg: getMessageJsonData?.data?.message ?? '',
491
490
  });
492
491
  if (!isOk) {
493
492
  const data = {
494
493
  eventName: 'business',
495
494
  errorName: 'shop_batchAddCart_error',
496
495
  errorMessage: 'H5调用Harmony原生加车失败',
497
496
  };
498
497
  draBusinessCustomReport(data);
499
498
  }
500
499
  } else {
501
500
  resolve({
502
501
  ok: false,
503
502
  msg: '加购失败,请稍后重试',
504
503
  });
505
504
  const data = {
506
505
  eventName: 'business',
507
506
  errorName: 'shop_batchAddCart_error',
508
507
  errorMessage: 'H5调用未知原生加车失败',
509
508
  };
510
509
  draBusinessCustomReport(data);
511
510
  }
512
511
  } catch (e) {
513
512
  resolve({
514
513
  ok: false,
515
514
  msg: '加购失败,请稍后重试',
516
515
  });
517
516
  console.warn('批量加车转换数据异常', e);
518
517
  const data = {
519
518
  eventName: 'business',
520
519
  errorName: 'shop_batchAddCart_error',
521
520
  errorMessage: '批量加车转换数据异常',
522
521
  };
523
522
  draBusinessCustomReport(data);
524
523
  }
525
524
  window[nativeAddCartCallBack] = null;
526
525
  };
527
526
  }
528
527
  const productsAddCartList = productIdsArr.map((skuItem) => {
529
528
  const adInfos = getAdInfoBySkuId(skuItem);
530
529
  let allExtFlag = typeof extFlag === 'object' ? extFlag : {};
531
530
  if (adInfos) {
532
531
  allExtFlag = Object.assign({}, allExtFlag, { adInfos });
533
532
  }
534
533
  let item: any = null;
535
534
  if (isAndroidDevice) {
536
535
  item = {
537
536
  sku: skuItem,
538
537
  num: addCardNum,
539
538
  extFlag: allExtFlag,
540
539
  };
541
540
  } else if (isIosDevice) {
542
541
  item = {
543
542
  productCode: skuItem,
544
543
  buyCount: addCardNum,
545
544
  extFlag: allExtFlag,
546
545
  };
547
546
  } else if (isHarmonyDevice) {
548
547
  item = {
549
548
  sourceType: 'native',
550
549
  sourceValue: 'shop',
551
550
  productCode: skuItem,
552
551
  buyCount: addCardNum,
553
552
  extFlag: allExtFlag,
554
553
  };
555
554
  }
556
555
  return item;
557
556
  });
558
557
  if (isAndroidDevice) {
559
558
  const androidProductsStr = JSON.stringify(productsAddCartList);
560
559
  let routerURL = `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`;
561
560
  if (extQuery) {
562
561
  routerURL += `&${extQuery}`;
563
562
  }
564
563
  callRouterAndroid({
565
564
  routerURL,
566
565
  routerParam: {
567
566
  wareList: productsAddCartList,
568
567
  },
569
568
  callBackName: nativeAddCartCallBack,
570
569
  });
571
570
  } else if (isIosDevice) {
572
571
  if (isLowAppVer) {
573
572
  const lowVersionAppList = productIdsArr.map((skuItem) => {
574
573
  return {
575
574
  sku: skuItem,
576
575
  num: addCardNum,
577
576
  };
578
577
  });
579
578
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
580
579
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
581
580
  jump.side.jdJumpToWeb(url, {});
582
581
  resolve({
583
582
  ok: true,
584
583
  isOpenApp: true,
585
584
  msg: '加购完成, 加购结果请点击购物车确认',
586
585
  });
587
586
  } else {
588
587
  callRouterIOS({
589
588
  routerURL: 'router://JDCartModule/batchAddService',
590
589
  routerParam: {
591
590
  sourceType: 'h5',
592
591
  sourceValue: '店铺批量加购',
593
592
  businessName: 'storeModel',
594
593
  isNewMode: '1',
595
594
  NotPassWebview: '1',
596
595
  products: productsAddCartList,
597
596
  },
598
597
  callBackName: nativeAddCartCallBack,
599
598
  });
600
599
  }
601
600
  } else if (isHarmonyDevice) {
602
601
  callRouterHarmony({
603
602
  routerURL: 'router://JDCartModule/batchAddService',
604
603
  routerParam: {
605
604
  sourceType: 'native',
606
605
  sourceValue: 'shop',
607
606
  products: productsAddCartList,
608
607
  },
609
608
  callBackName: nativeAddCartCallBack,
610
609
  });
611
610
  }
612
611
  } else if (isMin) {
613
612
  console.log('==========>', '京购批量加车!');
614
613
  const productsAddCartList = productIdsArr.map((skuItem) => {
615
614
  return {
616
615
  skuId: skuItem,
617
616
  buyNum: addCardNum,
618
617
  };
619
618
  });
620
619
  global.wxAppBizInstance
621
620
  .addCart({ commArr: productsAddCartList })
622
621
  .then((res) => {
623
622
  console.log('dealCartSuccess: ', res);
624
623
  resolve({
625
624
  ok: true,
626
625
  msg: '已加入购物车!',
627
626
  data: res,
628
627
  });
629
628
  })
630
629
  .catch((e) => {
631
630
  console.log('京购小程序批量加车失败dealCartFail: ', e);
632
631
  resolve({
633
632
  ok: false,
634
633
  msg: '加购失败,请稍后重试',
635
634
  });
636
635
  const data = {
637
636
  eventName: 'business',
638
637
  errorName: 'shop_batchAddCart_error',
639
638
  errorMessage: 'H5调用小程序加车失败',
640
639
  };
641
640
  draBusinessCustomReport(data);
642
641
  });
643
642
  } else {
644
643
  console.log('==========>', '使用M站批量加车!');
645
644
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
646
645
  }
647
646
  } else {
648
647
  resolve({
649
648
  ok: false,
650
649
  msg: '加购sku不能为空',
651
650
  });
652
651
  const data = {
653
652
  eventName: 'business',
654
653
  errorName: 'shop_batchAddCart_error',
655
654
  errorMessage: '加购sku不能为空',
656
655
  };
657
656
  draBusinessCustomReport(data);
658
657
  }
659
658
  });
660
659
  }
661
660
 
662
661
  productAddToCart(skuIdsStr, num) {
663
662
  return new Promise((resolve) => {
664
663
  if (window.AddcartToolObj) {
665
664
  window.AddcartToolObj.addCart({
666
665
  skuId: skuIdsStr,
667
666
  num,
668
667
  source: 'sjdpyw',
669
668
  actId: '1',
670
669
  loginType: isAscfApp ? '2' : window?.isJingGouMiniViewState ? '11' : isPc ? '3' : '2',
671
670
  sucFun(res) {
672
671
  console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
673
672
  if (res.errId === '0' && res.cartJson) {
674
673
  resolve({
675
674
  ok: true,
676
675
  msg: '已加入购物车!',
677
676
  ...res,
678
677
  });
679
678
  } else {
680
679
  if (res.errId === '13') {
681
680
  global.doLogin();
682
681
  } else {
683
682
  resolve({
684
683
  ok: false,
685
684
  msg: '加购失败,请稍后重试',
686
685
  ...res,
687
686
  });
688
687
  const data = {
689
688
  eventName: 'business',
690
689
  errorName: 'shop_batchAddCart_error',
691
690
  errorMessage: 'H5调用M站加车失败',
692
691
  };
693
692
  draBusinessCustomReport(data);
694
693
  }
695
694
  }
696
695
  },
697
696
  failFun(err) {
698
697
  console.log('fail', err);
699
698
  resolve({
700
699
  ok: false,
701
700
  msg: '加购失败,请稍后重试',
702
701
  ...err,
703
702
  });
704
703
  const data = {
705
704
  eventName: 'business',
706
705
  errorName: 'shop_batchAddCart_error',
707
706
  errorMessage: 'H5调用M站加车失败',
708
707
  };
709
708
  draBusinessCustomReport(data);
710
709
  },
711
710
  });
712
711
  } else {
713
712
  resolve({
714
713
  ok: false,
715
714
  msg: '购物车方法检查异常',
716
715
  });
717
716
  const data = {
718
717
  eventName: 'business',
719
718
  errorName: 'shop_batchAddCart_error',
720
719
  errorMessage: 'H5调用M站加车检查依赖方法异常',
721
720
  };
722
721
  draBusinessCustomReport(data);
723
722
  }
724
723
  });
725
724
  }
726
725
  bMallGetUserInfo = () => {
727
726
  return getBMallUserInfo();
728
727
  };
729
728
  async bMallAddCart(params = {}) {
730
729
  return await this.gatewayReq('bmall_cartAdd', params, {
731
730
  client: 'H5',
732
731
  clientVersion: '5.5.0',
733
732
  });
734
733
  }
735
734
  async bMallChangeCart(params = {}) {
736
735
  return await this.gatewayReq('bmall_cartChange', params, {
737
736
  client: 'H5',
738
737
  clientVersion: '5.5.0',
739
738
  });
740
739
  }
741
740
  async bMallRemoveCart(params = {}) {
742
741
  return await this.gatewayReq(
743
742
  'bmall_cartRemove',
744
743
  params,
745
744
  {
746
745
  client: 'H5',
747
746
  clientVersion: '5.5.0',
748
747
  },
749
748
  );
750
749
  }
751
750
  async bMallGetOmittedProduct(params = {}) {
752
751
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
753
752
  client: 'H5',
754
753
  clientVersion: '5.5.0',
755
754
  });
756
755
  }
757
756
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
758
757
  const params = await getParams({ ...data, skuId, bMallTag, num });
759
758
  return await this.bMallAddCart(params);
760
759
  }
761
760
  async bMallGetSkuNumService(bMallTag = 1) {
762
761
  const params = await getParams({ bMallTag });
763
762
  delete params.operations;
764
763
  return await this.bMallGetOmittedProduct(params);
765
764
  }
766
765
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
767
766
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
768
767
  return await this.bMallRemoveCart(params);
769
768
  }
770
769
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
771
770
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
772
771
  return await this.bMallChangeCart(params);
773
772
  }
774
773
 
775
774
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
776
775
  if (!needRequest && isH5 && window?.bMallCartData) {
777
776
  return window?.bMallCartData;
778
777
  }
779
778
  const cartData = await this.bMallGetSkuNumService(bMallTag);
780
779
  let items;
781
780
  if (cartData.ok && cartData.result) {
782
781
  items = cartData?.result?.items || {};
783
782
  }
784
783
  if (isH5) {
785
784
  window.bMallCartData = items;
786
785
  }
787
786
  return items;
788
787
  }
789
788
 
790
789
  async bMallCartHandle(goodItem, num) {
791
790
  try {
792
791
  const {
793
792
  skuUuid,
794
793
  limitUpper,
795
794
  limitLower,
796
795
  } = goodItem;
797
796
  let cartNum = Number(num);
798
797
  if (limitLower && cartNum && cartNum < limitLower) {
799
798
  cartNum = limitLower;
800
799
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
801
800
  cartNum = limitUpper;
802
801
  }
803
802
  if (skuUuid && cartNum > 0) {
804
803
  return this.bMallChangeCartService({
805
804
  ...goodItem,
806
805
  skuUuid,
807
806
  num: cartNum,
808
807
  });
809
808
  } else if (!skuUuid && cartNum > 0) {
810
809
  return this.bMallAddCartService({ ...goodItem, num: cartNum });
811
810
  } else if (skuUuid && !cartNum) {
812
811
  return this.bMallRemoveCartService({
813
812
  ...goodItem,
814
813
  skuUuid,
815
814
  num: cartNum,
816
815
  });
817
816
  } else {
818
817
  console.error('参数不全');
819
818
  return false;
820
819
  }
821
820
  } catch (e) {
822
821
  console.error(e);
823
822
  }
824
823
  }
824
+ import Taro from '@tarojs/taro';
825
825
  APPID,
826
826
  JshopxColorFunctionIdList,
827
827
  PagesColorFunctionIdList,
828
828
  PAGES_DOMAIN,
829
829
  B2BColorFunctionIdList,
830
830
  MobileVerifyColorList,
831
831
  AppVerifyColorList,
832
832
  JshopxVerifyColorList,
833
833
  BMallVerifyColorList,
834
834
  shopMemberColorFunctionIdList,
835
835
  draBusinessCustomReport,
836
836
  isJdApp,
837
837
  isIosDevice,
838
838
  isAndroidDevice,
839
839
  showSuccessToast,
840
840
  showFailToast,
841
841
  isH5,
842
842
  isWxMinAndWxapp,
843
843
  isMin,
844
844
  isPc,
845
845
  draInterfaceCustomReport,
846
846
  isHarmonyDevice,
847
847
  isAscfApp,
848
848
  callRouterIOS,
849
849
  callRouterAndroid,
850
850
  callRouterHarmony,
851
851
  sendNativePageToShowCartFloatBtn,
852
852
  cookiesStr: '',
853
853
  requestHeaderContentType: {
854
854
  jsonHeader: {
855
855
  'content-type': 'application/json;charset=utf-8',
856
856
  },
857
857
  formDataHeader: {
858
858
  'content-type': 'application/x-www-form-urlencoded',
859
859
  },
860
860
  },
861
861
  requestBaseParam: {
862
862
  data: null,
863
863
  header: {
864
864
  'content-type': 'application/json;charset=utf-8',
865
865
  },
866
866
  },
867
867
  timeOut: 7000,
868
868
  apiClientParams: {
869
869
  clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
870
870
  client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
871
871
  area: '1_72_2799_0',
872
872
  screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
873
873
  window.screen?.height * devicePixelRatio,
874
874
  )}`,
875
875
  uuid: UUID,
876
876
  },
877
877
  window.shopGlobalSwitch?.useNativeHarmonyAddCartJdAppVersion;
878
878
  nativeHarmonyAddCartJdAppVersion && jdAppVersionCompare(nativeHarmonyAddCartJdAppVersion) >= 0;
879
879
  public addressFetchInfo: {
880
880
  reqState: boolean;
881
881
  promiseInstance: null | Promise<any>;
882
882
  };
883
883
  public getPromotionConfig: {
884
884
  projectId: null | string | number;
885
885
  pageId: null | string | number;
886
886
  };
887
887
  public resInfo: ServiceInterFace.HttpRequestInfo;
888
888
  public api: ServiceInterFace.HttpApi;
889
889
  public isPageDomain: boolean;
890
890
  public verifyColorList: string[];
891
891
  private isShowJdShopCartFloatBtn: boolean;
892
892
  constructor(opt) {
893
893
  this._init();
894
894
  this.addressFetchInfo = {
895
895
  reqState: false,
896
896
  promiseInstance: null,
897
897
  };
898
898
  this.getPromotionConfig = {
899
899
  projectId: null,
900
900
  pageId: null,
901
901
  };
902
902
  this._userAreaUpdateListen();
903
903
  this.resInfo = this._getResConfig(opt);
904
904
  this.api = api;
905
905
  this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
906
906
  this.verifyColorList = [
907
907
  ...MobileVerifyColorList,
908
908
  ...AppVerifyColorList,
909
909
  ...JshopxVerifyColorList,
910
910
  ...BMallVerifyColorList,
911
911
  ];
912
912
  this.isShowJdShopCartFloatBtn =
913
913
  jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
914
914
  }
915
915
  _init(): void {
916
916
  httpInterceptors.forEach((item) => {
917
917
  Taro.addInterceptor((chain) => item(chain));
918
918
  });
919
919
  }
920
920
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
921
921
  return Object.assign({}, DefaultConfig, opt);
922
922
  }
923
923
 
924
924
  _userAreaUpdateListen() {
925
925
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
926
926
  this.updateApiClientParamsResInfo(areaInfo);
927
927
  console.log(
928
928
  'cone-render收到原生端获取传来的四级地址信息',
929
929
  areaInfo,
930
930
  '更新后的接口底层信息',
931
931
  this.resInfo.apiClientParams,
932
932
  );
933
933
  });
934
934
  }
935
935
  updateApiClientParamsResInfo(opt = {}) {
936
936
  const { area, realTimeArea, ...others } = opt;
937
937
  this.resInfo.apiClientParams = {
938
938
  ...this.resInfo.apiClientParams,
939
939
  ...others,
940
940
  };
941
941
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
942
942
  realTimeArea &&
943
943
  realTimeArea !== '' &&
944
944
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
945
945
  }
946
946
 
947
947
  checkFunctionIdToReturnAppId(functionId) {
948
948
  if (JshopxColorFunctionIdList.includes(functionId)) {
949
949
  return APPID.JSHOPX_COLOR_APPID;
950
950
  } else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
951
951
  return APPID.PAGES_COLOR_APPID;
952
952
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
953
953
  return APPID.SHOP_MEMBER_COLOR_APPID;
954
954
  } else if (B2BColorFunctionIdList.includes(functionId)) {
955
955
  return APPID.B2B_COLOR_APPID;
956
956
  } else if (isPc) {
957
957
  return APPID.MALL_COLOR_APPID;
958
958
  } else {
959
959
  return APPID.SHOP_COLOR_APPID;
960
960
  }
961
961
  }
962
962
 
963
963
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
964
964
  if (
965
965
  functionId === 'receiveShopCoupon' &&
966
966
  ((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
967
967
  isWxMinAndWxapp)
968
968
  ) {
969
969
  clientParams = Object.assign(
970
970
  {},
971
971
  {
972
972
  loginType: isAscfApp ? '2' : '1',
973
973
  loginWQBiz: WXAPP_BIZ_KEY,
974
974
  },
975
975
  clientParams,
976
976
  );
977
977
  }
978
978
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
979
979
  typeof apiClientParams.appid === 'undefined' &&
980
980
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
981
981
  const isColorVerify = this.verifyColorList.includes(functionId);
982
982
  const getReqData = {
983
983
  functionId: functionId,
984
984
  body: JSON.stringify(bodyParams),
985
985
  t: Date.now(),
986
986
  ...apiClientParams,
987
987
  };
988
988
  return http
989
989
  .request({
990
990
  url: this.api.apiFunc,
991
991
  data: getReqData,
992
992
  isColorVerify,
993
993
  })
994
994
  .then((res: ServiceInterFace.RequestPromiseRes) => {
995
995
  const { statusCode, data, status, msg } = res;
996
996
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
997
997
  ok: true,
998
998
  };
999
999
  if ((statusCode === 200 || status === '0') && data) {
1000
1000
  changeRes = this.dealResponseFormatRes(data);
1001
1001
  return changeRes;
1002
1002
  } else {
1003
1003
  changeRes = {
1004
1004
  ...data,
1005
1005
  statusCode,
1006
1006
  status,
1007
1007
  msg,
1008
1008
  ok: false,
1009
1009
  };
1010
1010
  return changeRes;
1011
1011
  }
1012
1012
  })
1013
1013
  .catch((res) => {
1014
1014
  const propertyNames = Object.getOwnPropertyNames(res);
1015
1015
  const resObject = {};
1016
1016
  propertyNames.forEach((propertyName) => {
1017
1017
  resObject[propertyName] = res[propertyName];
1018
1018
  });
1019
1019
  draInterfaceCustomReport({
1020
1020
  eventName: 'apiStatusCode',
1021
1021
  errorName: `shop_${functionId}_error`,
1022
1022
  errorMessage: `接口返回statusCode为${res?.statusCode || res?.status}`,
1023
1023
  url: this.api.apiFunc,
1024
1024
  source: 'remote',
1025
1025
  requestType: res?.requestType,
1026
1026
  functionId: getReqData?.functionId,
1027
1027
  appid: getReqData?.appid,
1028
1028
  client: getReqData?.client,
1029
1029
  clientVersion: getReqData?.clientVersion,
1030
1030
  statusCode: res?.statusCode,
1031
1031
  status: res?.status,
1032
1032
  statusText: res?.statusText,
1033
1033
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
1034
1034
  originReqDataStr: JSON.stringify(getReqData),
1035
1035
  });
1036
1036
  return {
1037
1037
  ...resObject,
1038
1038
  ok: false,
1039
1039
  } as ServiceInterFace.RequestResponseFormatRes;
1040
1040
  });
1041
1041
  }
1042
1042
 
1043
1043
  dealResponseFormatRes(data) {
1044
1044
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
1045
1045
  ok: true,
1046
1046
  };
1047
1047
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
1048
1048
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
1049
1049
  ? Number(data.subCode)
1050
1050
  : -1;
1051
1051
  if (
1052
1052
  data.success === true ||
1053
1053
  data.isSuccess ||
1054
1054
  resCode === 0 ||
1055
1055
  resCode === 200 ||
1056
1056
  subCode === 0
1057
1057
  ) {
1058
1058
  changeRes = {
1059
1059
  result: Object.prototype.hasOwnProperty.call(data, 'result')
1060
1060
  ? data.result
1061
1061
  : Object.prototype.hasOwnProperty.call(data, 'data')
1062
1062
  ? data.data
1063
1063
  : data,
1064
1064
  code: data.code ?? 200,
1065
1065
  ok: true,
1066
1066
  source: data,
1067
1067
  };
1068
1068
  return changeRes;
1069
1069
  } else {
1070
1070
  changeRes = {
1071
1071
  ...data,
1072
1072
  ok: false,
1073
1073
  };
1074
1074
  return changeRes;
1075
1075
  }
1076
1076
  }
1077
1077
 
1078
1078
  async receiveCoupon(param = {}, clientParams) {
1079
1079
  const loginType = isPc ? { loginType: 3 } : {};
1080
1080
  return await this.gatewayReq(
1081
1081
  'receiveShopCoupon',
1082
1082
  {
1083
1083
  operation: '3',
1084
1084
  ...param,
1085
1085
  },
1086
1086
  { ...loginType, ...clientParams },
1087
1087
  );
1088
1088
  }
1089
1089
 
1090
1090
  getCustomerCenterDispatch(params = {}) {
1091
1091
  return this.gatewayReq('customerCenterDispatch', params, {
1092
1092
  clientVersion: '9.2.0',
1093
1093
  client: 'H5',
1094
1094
  uuid: 88888,
1095
1095
  appid: 'shopmember_m_jd_com',
1096
1096
  });
1097
1097
  }
1098
1098
 
1099
1099
  batchAddCart(...args) {
1100
1100
  let skuIds, num, showToast, giftCard, extFlag, extQuery;
1101
1101
  let skipNativeCartFloatBtn = false;
1102
1102
  if (['number', 'string'].includes(typeof args[0])) {
1103
1103
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
1104
1104
  } else if (typeof args[0] === 'object' && args[0] !== null) {
1105
1105
  const params = args[0];
1106
1106
  skuIds = params.skuIds;
1107
1107
  num = params.num || 1;
1108
1108
  showToast = params.showToast !== undefined ? params.showToast : true;
1109
1109
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
1110
1110
  extFlag = params.extFlag !== undefined ? params.extFlag : null;
1111
1111
  extQuery = params.extQuery !== undefined ? params.extQuery : null;
1112
1112
  skipNativeCartFloatBtn = params.skipNativeCartFloatBtn === true;
1113
1113
  } else {
1114
1114
  try {
1115
1115
  const data = {
1116
1116
  eventName: 'business',
1117
1117
  errorName: 'shop_batchAddCart_error',
1118
1118
  errorMessage: '入参不合法',
1119
1119
  extraData: JSON.stringify(args),
1120
1120
  };
1121
1121
  draBusinessCustomReport(data);
1122
1122
  } catch (e) {
1123
1123
  console.error('draBusinessCustomReport error:', e);
1124
1124
  }
1125
1125
  const msg = global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
1126
1126
  showFailToast({
1127
1127
  title: msg,
1128
1128
  });
1129
1129
  return Promise.resolve({
1130
1130
  ok: false,
1131
1131
  msg,
1132
1132
  });
1133
1133
  }
1134
1134
  const successMsg = giftCard
1135
1135
  ? global?.languageJsonData?.successAddShopList || '加入购物清单成功'
1136
1136
  : global?.languageJsonData?.successAddCart || '加入购物车成功';
1137
1137
  const failMsg = giftCard
1138
1138
  ? global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试'
1139
1139
  : global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
1140
1140
  if (skuIds) {
1141
1141
  return this._addShopGoodCart(`${skuIds}`, `${num}`, {
1142
1142
  giftCard,
1143
1143
  extFlag,
1144
1144
  extQuery,
1145
1145
  })
1146
1146
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
1147
1147
  if (res?.ok) {
1148
1148
  showToast &&
1149
1149
  !res?.isOpenApp &&
1150
1150
  showSuccessToast({
1151
1151
  title: successMsg,
1152
1152
  });
1153
1153
  !skipNativeCartFloatBtn &&
1154
1154
  this.isShowJdShopCartFloatBtn &&
1155
1155
  sendNativePageToShowCartFloatBtn({
1156
1156
  isShow: true,
1157
1157
  });
1158
1158
  } else {
1159
1159
  showToast &&
1160
1160
  showFailToast({
1161
1161
  title: res?.errMsg || failMsg,
1162
1162
  });
1163
1163
  }
1164
1164
  return Promise.resolve(res);
1165
1165
  })
1166
1166
  .catch((e) => {
1167
1167
  console.log('调用加购方法异常=======>', e);
1168
1168
  return Promise.resolve({
1169
1169
  ok: false,
1170
1170
  msg: failMsg,
1171
1171
  });
1172
1172
  });
1173
1173
  } else {
1174
1174
  try {
1175
1175
  const data = {
1176
1176
  eventName: 'business',
1177
1177
  errorName: 'shop_batchAddCart_error',
1178
1178
  errorMessage: '没有传入合法的skuIds',
1179
1179
  };
1180
1180
  draBusinessCustomReport(data);
1181
1181
  } catch (e) {
1182
1182
  console.error('draBusinessCustomReport error:', e);
1183
1183
  }
1184
1184
  return Promise.resolve({
1185
1185
  ok: false,
1186
1186
  msg: failMsg,
1187
1187
  });
1188
1188
  }
1189
1189
  }
1190
1190
 
1191
1191
  async giftCardAddCart(skuList, num) {
1192
1192
  const loginType = isPc ? { loginType: 3 } : {};
1193
1193
  return this.gatewayReq(
1194
1194
  'giftCardAddCart',
1195
1195
  {
1196
1196
  skuList,
1197
1197
  num: Number(num),
1198
1198
  },
1199
1199
  { ...loginType },
1200
1200
  );
1201
1201
  }
1202
1202
 
1203
1203
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard, extFlag, extQuery }) {
1204
1204
  return new Promise((resolve) => {
1205
1205
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
1206
1206
  if (productIdsArr.length > 0) {
1207
1207
  if (giftCard) {
1208
1208
  this.giftCardAddCart(productIdsArr, addCardNum)
1209
1209
  .then((res) => {
1210
1210
  if (res?.code === '0' && res?.result?.value) {
1211
1211
  resolve({
1212
1212
  ok: true,
1213
1213
  });
1214
1214
  } else {
1215
1215
  try {
1216
1216
  const data = {
1217
1217
  eventName: 'business',
1218
1218
  errorName: 'shop_batchAddCart_error',
1219
1219
  errorMessage: '礼品卡加车接口返回加车失败标识',
1220
1220
  };
1221
1221
  draBusinessCustomReport(data);
1222
1222
  } catch (e) {
1223
1223
  console.error('draBusinessCustomReport error:', e);
1224
1224
  }
1225
1225
  resolve({
1226
1226
  ok: false,
1227
1227
  msg: '加购失败,请稍后重试',
1228
1228
  });
1229
1229
  }
1230
1230
  })
1231
1231
  .catch((e) => {
1232
1232
  console.error('礼品卡加车失败: ', e);
1233
1233
  resolve({
1234
1234
  ok: false,
1235
1235
  msg: '加购失败,请稍后重试',
1236
1236
  });
1237
1237
  });
1238
1238
  } else if (
1239
1239
  isJdApp &&
1240
1240
  (!isHarmonyDevice || (isHarmonyDevice && useNativeHarmonyAddCartJd))
1241
1241
  ) {
1242
1242
  const nativeAddCartCallBack = `nativeBatchAddCart${
1243
1243
  Date.now() + Number(productIdsArr[0]) + Number(addCardNum)
1244
1244
  }`;
1245
1245
  console.log(
1246
1246
  '==========>',
1247
1247
  '使用原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
1248
1248
  nativeAddCartCallBack,
1249
1249
  );
1250
1250
  if (!window[nativeAddCartCallBack]) {
1251
1251
  window[nativeAddCartCallBack] = (res) => {
1252
1252
  const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
1253
1253
  console.info(
1254
1254
  '获取批量加车原始数据',
1255
1255
  res,
1256
1256
  '====转换后的json数据为===',
1257
1257
  getMessageJsonData,
1258
1258
  );
1259
1259
  try {
1260
1260
  if (isAndroidDevice) {
1261
1261
  const isOk = getMessageJsonData?.status === '0';
1262
1262
  isOk
1263
1263
  ? resolve({
1264
1264
  ok: true,
1265
1265
  msg: '已加入购物车!',
1266
1266
  cartNum: getMessageJsonData?.data?.response?.cartNum || 0,
1267
1267
  })
1268
1268
  : resolve({
1269
1269
  ok: false,
1270
1270
  msg: '加购失败,请稍后重试',
1271
1271
  errMsg: getMessageJsonData?.data?.message ?? '',
1272
1272
  });
1273
1273
  if (!isOk) {
1274
1274
  const data = {
1275
1275
  eventName: 'business',
1276
1276
  errorName: 'shop_batchAddCart_error',
1277
1277
  errorMessage: 'H5调用Android原生加车失败',
1278
1278
  };
1279
1279
  draBusinessCustomReport(data);
1280
1280
  }
1281
1281
  } else if (isIosDevice) {
1282
1282
  const isOk =
1283
1283
  getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
1284
1284
  isOk
1285
1285
  ? resolve({
1286
1286
  ok: true,
1287
1287
  msg: '已加入购物车!',
1288
1288
  cartNum: getMessageJsonData?.data?.response?.cartNum || 0,
1289
1289
  })
1290
1290
  : resolve({
1291
1291
  ok: false,
1292
1292
  msg: '批量加车失败,请稍后重试',
1293
1293
  errMsg: getMessageJsonData?.data?.message ?? '',
1294
1294
  });
1295
1295
  if (!isOk) {
1296
1296
  const data = {
1297
1297
  eventName: 'business',
1298
1298
  errorName: 'shop_batchAddCart_error',
1299
1299
  errorMessage: 'H5调用IOS原生加车失败',
1300
1300
  };
1301
1301
  draBusinessCustomReport(data);
1302
1302
  }
1303
1303
  } else if (isHarmonyDevice) {
1304
1304
  const isOk =
1305
1305
  getMessageJsonData?.data?.code === 0 &&
1306
1306
  getMessageJsonData?.data?.response?.resultCode === 0;
1307
1307
  isOk
1308
1308
  ? resolve({
1309
1309
  ok: true,
1310
1310
  msg: '已加入购物车!',
1311
1311
  cartNum: getMessageJsonData?.data?.response?.cartNum || 0,
1312
1312
  })
1313
1313
  : resolve({
1314
1314
  ok: false,
1315
1315
  msg: '加购失败,请稍后重试',
1316
1316
  errMsg: getMessageJsonData?.data?.message ?? '',
1317
1317
  });
1318
1318
  if (!isOk) {
1319
1319
  const data = {
1320
1320
  eventName: 'business',
1321
1321
  errorName: 'shop_batchAddCart_error',
1322
1322
  errorMessage: 'H5调用Harmony原生加车失败',
1323
1323
  };
1324
1324
  draBusinessCustomReport(data);
1325
1325
  }
1326
1326
  } else {
1327
1327
  resolve({
1328
1328
  ok: false,
1329
1329
  msg: '加购失败,请稍后重试',
1330
1330
  });
1331
1331
  const data = {
1332
1332
  eventName: 'business',
1333
1333
  errorName: 'shop_batchAddCart_error',
1334
1334
  errorMessage: 'H5调用未知原生加车失败',
1335
1335
  };
1336
1336
  draBusinessCustomReport(data);
1337
1337
  }
1338
1338
  } catch (e) {
1339
1339
  resolve({
1340
1340
  ok: false,
1341
1341
  msg: '加购失败,请稍后重试',
1342
1342
  });
1343
1343
  console.warn('批量加车转换数据异常', e);
1344
1344
  const data = {
1345
1345
  eventName: 'business',
1346
1346
  errorName: 'shop_batchAddCart_error',
1347
1347
  errorMessage: '批量加车转换数据异常',
1348
1348
  };
1349
1349
  draBusinessCustomReport(data);
1350
1350
  }
1351
1351
  window[nativeAddCartCallBack] = null;
1352
1352
  };
1353
1353
  }
1354
1354
  const productsAddCartList = productIdsArr.map((skuItem) => {
1355
1355
  const adInfos = getAdInfoBySkuId(skuItem);
1356
1356
  let allExtFlag = typeof extFlag === 'object' ? extFlag : {};
1357
1357
  if (adInfos) {
1358
1358
  allExtFlag = Object.assign({}, allExtFlag, { adInfos });
1359
1359
  }
1360
1360
  let item: any = null;
1361
1361
  if (isAndroidDevice) {
1362
1362
  item = {
1363
1363
  sku: skuItem,
1364
1364
  num: addCardNum,
1365
1365
  extFlag: allExtFlag,
1366
1366
  };
1367
1367
  } else if (isIosDevice) {
1368
1368
  item = {
1369
1369
  productCode: skuItem,
1370
1370
  buyCount: addCardNum,
1371
1371
  extFlag: allExtFlag,
1372
1372
  };
1373
1373
  } else if (isHarmonyDevice) {
1374
1374
  item = {
1375
1375
  sourceType: 'native',
1376
1376
  sourceValue: 'shop',
1377
1377
  productCode: skuItem,
1378
1378
  buyCount: addCardNum,
1379
1379
  extFlag: allExtFlag,
1380
1380
  };
1381
1381
  }
1382
1382
  return item;
1383
1383
  });
1384
1384
  if (isAndroidDevice) {
1385
1385
  const androidProductsStr = JSON.stringify(productsAddCartList);
1386
1386
  let routerURL = `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`;
1387
1387
  if (extQuery) {
1388
1388
  routerURL += `&${extQuery}`;
1389
1389
  }
1390
1390
  callRouterAndroid({
1391
1391
  routerURL,
1392
1392
  routerParam: {
1393
1393
  wareList: productsAddCartList,
1394
1394
  },
1395
1395
  callBackName: nativeAddCartCallBack,
1396
1396
  });
1397
1397
  } else if (isIosDevice) {
1398
1398
  if (isLowAppVer) {
1399
1399
  const lowVersionAppList = productIdsArr.map((skuItem) => {
1400
1400
  return {
1401
1401
  sku: skuItem,
1402
1402
  num: addCardNum,
1403
1403
  };
1404
1404
  });
1405
1405
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
1406
1406
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
1407
1407
  jump.side.jdJumpToWeb(url, {});
1408
1408
  resolve({
1409
1409
  ok: true,
1410
1410
  isOpenApp: true,
1411
1411
  msg: '加购完成, 加购结果请点击购物车确认',
1412
1412
  });
1413
1413
  } else {
1414
1414
  callRouterIOS({
1415
1415
  routerURL: 'router://JDCartModule/batchAddService',
1416
1416
  routerParam: {
1417
1417
  sourceType: 'h5',
1418
1418
  sourceValue: '店铺批量加购',
1419
1419
  businessName: 'storeModel',
1420
1420
  isNewMode: '1',
1421
1421
  NotPassWebview: '1',
1422
1422
  products: productsAddCartList,
1423
1423
  },
1424
1424
  callBackName: nativeAddCartCallBack,
1425
1425
  });
1426
1426
  }
1427
1427
  } else if (isHarmonyDevice) {
1428
1428
  callRouterHarmony({
1429
1429
  routerURL: 'router://JDCartModule/batchAddService',
1430
1430
  routerParam: {
1431
1431
  sourceType: 'native',
1432
1432
  sourceValue: 'shop',
1433
1433
  products: productsAddCartList,
1434
1434
  },
1435
1435
  callBackName: nativeAddCartCallBack,
1436
1436
  });
1437
1437
  }
1438
1438
  } else if (isMin) {
1439
1439
  console.log('==========>', '京购批量加车!');
1440
1440
  const productsAddCartList = productIdsArr.map((skuItem) => {
1441
1441
  return {
1442
1442
  skuId: skuItem,
1443
1443
  buyNum: addCardNum,
1444
1444
  };
1445
1445
  });
1446
1446
  global.wxAppBizInstance
1447
1447
  .addCart({ commArr: productsAddCartList })
1448
1448
  .then((res) => {
1449
1449
  console.log('dealCartSuccess: ', res);
1450
1450
  resolve({
1451
1451
  ok: true,
1452
1452
  msg: '已加入购物车!',
1453
1453
  data: res,
1454
1454
  });
1455
1455
  })
1456
1456
  .catch((e) => {
1457
1457
  console.log('京购小程序批量加车失败dealCartFail: ', e);
1458
1458
  resolve({
1459
1459
  ok: false,
1460
1460
  msg: '加购失败,请稍后重试',
1461
1461
  });
1462
1462
  const data = {
1463
1463
  eventName: 'business',
1464
1464
  errorName: 'shop_batchAddCart_error',
1465
1465
  errorMessage: 'H5调用小程序加车失败',
1466
1466
  };
1467
1467
  draBusinessCustomReport(data);
1468
1468
  });
1469
1469
  } else {
1470
1470
  console.log('==========>', '使用M站批量加车!');
1471
1471
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
1472
1472
  }
1473
1473
  } else {
1474
1474
  resolve({
1475
1475
  ok: false,
1476
1476
  msg: '加购sku不能为空',
1477
1477
  });
1478
1478
  const data = {
1479
1479
  eventName: 'business',
1480
1480
  errorName: 'shop_batchAddCart_error',
1481
1481
  errorMessage: '加购sku不能为空',
1482
1482
  };
1483
1483
  draBusinessCustomReport(data);
1484
1484
  }
1485
1485
  });
1486
1486
  }
1487
1487
 
1488
1488
  productAddToCart(skuIdsStr, num) {
1489
1489
  return new Promise((resolve) => {
1490
1490
  if (window.AddcartToolObj) {
1491
1491
  window.AddcartToolObj.addCart({
1492
1492
  skuId: skuIdsStr,
1493
1493
  num,
1494
1494
  source: 'sjdpyw',
1495
1495
  actId: '1',
1496
1496
  loginType: isAscfApp ? '2' : window?.isJingGouMiniViewState ? '11' : isPc ? '3' : '2',
1497
1497
  sucFun(res) {
1498
1498
  console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
1499
1499
  if (res.errId === '0' && res.cartJson) {
1500
1500
  resolve({
1501
1501
  ok: true,
1502
1502
  msg: '已加入购物车!',
1503
1503
  ...res,
1504
1504
  });
1505
1505
  } else {
1506
1506
  if (res.errId === '13') {
1507
1507
  global.doLogin();
1508
1508
  } else {
1509
1509
  resolve({
1510
1510
  ok: false,
1511
1511
  msg: '加购失败,请稍后重试',
1512
1512
  ...res,
1513
1513
  });
1514
1514
  const data = {
1515
1515
  eventName: 'business',
1516
1516
  errorName: 'shop_batchAddCart_error',
1517
1517
  errorMessage: 'H5调用M站加车失败',
1518
1518
  };
1519
1519
  draBusinessCustomReport(data);
1520
1520
  }
1521
1521
  }
1522
1522
  },
1523
1523
  failFun(err) {
1524
1524
  console.log('fail', err);
1525
1525
  resolve({
1526
1526
  ok: false,
1527
1527
  msg: '加购失败,请稍后重试',
1528
1528
  ...err,
1529
1529
  });
1530
1530
  const data = {
1531
1531
  eventName: 'business',
1532
1532
  errorName: 'shop_batchAddCart_error',
1533
1533
  errorMessage: 'H5调用M站加车失败',
1534
1534
  };
1535
1535
  draBusinessCustomReport(data);
1536
1536
  },
1537
1537
  });
1538
1538
  } else {
1539
1539
  resolve({
1540
1540
  ok: false,
1541
1541
  msg: '购物车方法检查异常',
1542
1542
  });
1543
1543
  const data = {
1544
1544
  eventName: 'business',
1545
1545
  errorName: 'shop_batchAddCart_error',
1546
1546
  errorMessage: 'H5调用M站加车检查依赖方法异常',
1547
1547
  };
1548
1548
  draBusinessCustomReport(data);
1549
1549
  }
1550
1550
  });
1551
1551
  }
1552
1552
  bMallGetUserInfo = () => {
1553
1553
  return getBMallUserInfo();
1554
1554
  };
1555
1555
  async bMallAddCart(params = {}) {
1556
1556
  return await this.gatewayReq('bmall_cartAdd', params, {
1557
1557
  client: 'H5',
1558
1558
  clientVersion: '5.5.0',
1559
1559
  });
1560
1560
  }
1561
1561
  async bMallChangeCart(params = {}) {
1562
1562
  return await this.gatewayReq('bmall_cartChange', params, {
1563
1563
  client: 'H5',
1564
1564
  clientVersion: '5.5.0',
1565
1565
  });
1566
1566
  }
1567
1567
  async bMallRemoveCart(params = {}) {
1568
1568
  return await this.gatewayReq(
1569
1569
  'bmall_cartRemove',
1570
1570
  params,
1571
1571
  {
1572
1572
  client: 'H5',
1573
1573
  clientVersion: '5.5.0',
1574
1574
  },
1575
1575
  );
1576
1576
  }
1577
1577
  async bMallGetOmittedProduct(params = {}) {
1578
1578
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
1579
1579
  client: 'H5',
1580
1580
  clientVersion: '5.5.0',
1581
1581
  });
1582
1582
  }
1583
1583
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
1584
1584
  const params = await getParams({ ...data, skuId, bMallTag, num });
1585
1585
  return await this.bMallAddCart(params);
1586
1586
  }
1587
1587
  async bMallGetSkuNumService(bMallTag = 1) {
1588
1588
  const params = await getParams({ bMallTag });
1589
1589
  delete params.operations;
1590
1590
  return await this.bMallGetOmittedProduct(params);
1591
1591
  }
1592
1592
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1593
1593
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1594
1594
  return await this.bMallRemoveCart(params);
1595
1595
  }
1596
1596
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1597
1597
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1598
1598
  return await this.bMallChangeCart(params);
1599
1599
  }
1600
1600
 
1601
1601
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
1602
1602
  if (!needRequest && isH5 && window?.bMallCartData) {
1603
1603
  return window?.bMallCartData;
1604
1604
  }
1605
1605
  const cartData = await this.bMallGetSkuNumService(bMallTag);
1606
1606
  let items;
1607
1607
  if (cartData.ok && cartData.result) {
1608
1608
  items = cartData?.result?.items || {};
1609
1609
  }
1610
1610
  if (isH5) {
1611
1611
  window.bMallCartData = items;
1612
1612
  }
1613
1613
  return items;
1614
1614
  }
1615
1615
 
1616
1616
  async bMallCartHandle(goodItem, num) {
1617
1617
  try {
1618
1618
  const {
1619
1619
  skuUuid,
1620
1620
  limitUpper,
1621
1621
  limitLower,
1622
1622
  } = goodItem;
1623
1623
  let cartNum = Number(num);
1624
1624
  if (limitLower && cartNum && cartNum < limitLower) {
1625
1625
  cartNum = limitLower;
1626
1626
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
1627
1627
  cartNum = limitUpper;
1628
1628
  }
1629
1629
  if (skuUuid && cartNum > 0) {
1630
1630
  return this.bMallChangeCartService({
1631
1631
  ...goodItem,
1632
1632
  skuUuid,
1633
1633
  num: cartNum,
1634
1634
  });
1635
1635
  } else if (!skuUuid && cartNum > 0) {
1636
1636
  return this.bMallAddCartService({ ...goodItem, num: cartNum });
1637
1637
  } else if (skuUuid && !cartNum) {
1638
1638
  return this.bMallRemoveCartService({
1639
1639
  ...goodItem,
1640
1640
  skuUuid,
1641
1641
  num: cartNum,
1642
1642
  });
1643
1643
  } else {
1644
1644
  console.error('参数不全');
1645
1645
  return false;
1646
1646
  }
1647
1647
  } catch (e) {
1648
1648
  console.error(e);
1649
1649
  }
1650
1650
  }