@conecli/cone-render 0.10.1-shop-beta.60 → 0.10.1-shop-beta.61

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