闫增涛
2024-02-23 fdfb3ca757ecd6c396632ed276ff354671d3a7e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
import request from "../../../request/index";
import { tokenKey, goodsStore } from '../../config'
import { handleQueryResourceListData, handleDetailQueryRequestData } from '../tool'
const storeApi = {
  /*
    **获取商品列表**
    path: 数据路径
    storeInfo: 仓储
    channelInfo: 频道
    subAccess: 
    queryType: 检索类型
    paging: 分页
    sort: 排序
    fields: 自定义字段
  */
  getProductList: ({
    path = '',
    storeInfo = goodsStore,
    storeEventIdOrRefCode = '',
    favoriteTypes = '',
    queryType,
    linkType,
    subAccess = [],
    paging = {},
    sort,
    fields,
    filterList,
    coverSize,
    mainProductId,
    handelEBooK
  }) => {
    const query = {
      AccessControl: {
        Path: path,
        StoreRefCode: storeInfo + '',
        Type: queryType || '\\',
        LinkType: linkType || ''
      },
      FavoriteTypes: favoriteTypes ? [favoriteTypes] : [],
      SubAccess: subAccess.length > 0 ? subAccess : [],
      PageQuery: {
        Start: paging.start || '0',
        Size: paging.size || '10'
      },
      SortQuery:
        sort?.length == 0
          ? []
          : sort
            ? [sort]
            : [
                {
                  LinkOrder: 'Desc'
                }
              ],
      CreateDate: [],
      Description: [],
      Name: [],
      Icon: [],
      RefCode: [],
      TypeId: [],
      SysType: [],
      State: [],
      Tag: [],
      BeginDate: [],
      EndDate: [],
      ProductLinkInfo: [],
      AllowDonate: [],
      // DonatePriceList: [],
      StoreEvent: [],
      SubProductCount: [],
      SaleMethod: [],
      SaleMethodValid: [],
      StoreEventIdOrRefCode: storeEventIdOrRefCode,
      ...fields,
      ...filterList
    }
    if (mainProductId) {
      query.AccessControl.MainProductId = mainProductId
    }
    if (handelEBooK) {
      query.ProductCmsQuery = [
        {
          QueryCms: {
            Path: '*',
            Type: '\\',
            Name: [],
            Icon: [],
            TypeId: [],
            RefCode: [],
            ChildrenCount: [],
            ChildrenFolderCount: [],
            CreateDate: [],
            SysType: [],
            SaleMethod: [],
            PageQuery: {
              Start: 0,
              Size: 9999
            },
            ProductLinkInfo: []
          }
        }
      ]
    }
    const body = {
      query: JSON.stringify({
        Query: [
          {
            Q1: query
          }
        ]
      })
    }
    let token = localStorage.getItem(tokenKey)
    let url = token ? '/store/api/ApiQueryProductByAppUser' : '/store/api/ApiQueryProduct'
    return request({
      url: url,
      method: 'post',
      data: body
    }).then((resp) => {
      if (resp.length > 0) {
        const data = resp[0]
        const datas = handleQueryResourceListData({
          datas: data.datas,
          fields,
          path,
          storeInfo,
          coverSize,
          handelEBooK
        })
        return {
          datas,
          total: data.totalCount,
          extraInfos: data.extraInfos?.StoreEvent
        }
      }
      return {
        datas: [],
        total: 0
      }
    })
  },
  /*
    **获取商品详情**
    path: 数据路径
    storeInfo: 仓储
    channelInfo: 频道
    subAccess: 
    fields: 自定义字段
    productId: 商品ID
    cmsPath:cmsPath
  */
  getProductDetail: ({
    path = '',
    storeInfo = goodsStore,
    channelInfo = '',
    favoriteTypes = '',
    queryType,
    subAccess = [],
    fields,
    productId,
    cmsPath,
    cmsType,
    coverSize,
    itemId,
    itemIds,
    itemFields,
    linkTypes,
    filterList,
    handelEBooK,
    sort,
    cmsSort,
    source
  }) => {
    const subQuery = {}
    if (cmsPath) {
      subQuery['QueryCms'] = {
        Path: cmsPath + '',
        Type: cmsType || '\\',
        Name: [],
        Icon: [],
        TypeId: [],
        RefCode: [],
        ChildrenCount: [],
        ChildrenFolderCount: [],
        CreateDate: [],
        SysType: [],
        SaleMethod: [],
        PageQuery: {
          Start: 0,
          Size: 9999
        },
        SortQuery: cmsSort
          ? [cmsSort]
          : [
              {
                ProductLinkOrder: 'Asc'
              }
            ],
        ProductLinkInfo: [],
        ...itemFields
      }
      if (itemId) subQuery['QueryCms']['Id='] = [`${itemId}`]
      if (itemIds) subQuery['QueryCms']['Id='] = itemIds
    } else {
      subQuery['QueryCms'] = {
        Path: '*',
        Type: '\\',
        Name: [],
        Icon: [],
        TypeId: [],
        RefCode: [],
        ChildrenCount: [],
        ChildrenFolderCount: [],
        CreateDate: [],
        SysType: [],
        SaleMethod: [],
        PageQuery: {
          Start: 0,
          Size: 9999
        },
        ProductLinkInfo: []
      }
    }
    // 获取关联资源
    let linkFields = {}
    if (linkTypes && linkTypes.length) {
      for (let i = 0; i < linkTypes.length; i++) {
        const linkType = linkTypes[i]
        subQuery['QueryLink_' + linkType.linkType] = {
          Path: cmsPath + '',
          Type: '\\',
          Name: [],
          Icon: [],
          TypeId: [],
          RefCode: [],
          LinkTypes: [linkType.linkType],
          PageQuery: {
            Start: 0,
            Size: 100
          },
          ProductLinkInfo: [],
          ...linkType.fields
        }
        linkFields = {
          ...linkFields,
          ...linkType.fields
        }
      }
    }
    const query = {
      AccessControl: {
        Path: path,
        StoreRefCode: storeInfo + '',
        ChannelRefCode: channelInfo + '',
        Type: queryType || '\\'
      },
      FavoriteTypes: favoriteTypes ? [favoriteTypes] : [],
      SubAccess: subAccess.length > 0 ? subAccess : [],
      PageQuery: {
        Start: '0',
        Size: '1'
      },
      'Id=': [`${productId}`],
      SortQuery: sort
        ? [sort]
        : [
            {
              LinkOrder: 'Desc'
            }
          ],
      CreateDate: [],
      Description: [],
      Name: [],
      Icon: [],
      RefCode: [],
      TypeId: [],
      SysType: [],
      State: [],
      Tag: [],
      BeginDate: [],
      EndDate: [],
      ProductLinkInfo: [],
      AllowDonate: [],
      DonatePriceList: [],
      StoreEvent: [],
      SaleMethod: [],
      SaleMethodValid: [],
      CmsItemValid: [],
      ProductCmsQuery: [subQuery],
      ...fields,
      ...filterList
    }
    if (productId) query['Id='] = [`${productId}`]
 
    const body = {
      query: JSON.stringify({
        Query: [
          {
            Q1: query
          }
        ]
      })
    }
    let token = localStorage.getItem(tokenKey)
    let url = token ? '/store/api/ApiQueryProductByAppUser' : '/store/api/ApiQueryProduct'
    return request({
      url: url,
      method: 'post',
      data: body,
      cancelToken: source?.token
    })
      .then((resp) => {
        if (resp.length > 0) {
          const data = resp[0]
          if (data.datas.length) {
            data.datas[0].subDatas = data.datas[0].cmsDatas
            const datas = handleDetailQueryRequestData({
              item: data.datas[0],
              fields,
              itemFields: {
                ...itemFields,
                ...linkFields
              },
              path,
              coverSize,
              handelEBooK
            })
            return {
              datas,
              total: data.totalCount
            }
          } else {
            return {
              datas: [],
              total: 0
            }
          }
        }
        return {
          datas: [],
          total: 0
        }
      })
  },
 
  // 获取优惠券列表
  getChannelPromoteCodeList(data) {
    return request({
      url: '/store/api/ApiGetChannelPromoteCodeList',
      method: 'post',
      data
    })
  },
 
  // 获取用户已领取的优惠券列表
  getPromoteCodeList(data) {
    return request({
      url: '/store/api/ApiGetPromoteCodeList',
      method: 'post',
      data
    })
  },
 
  // 获取用户浏览排行
  getProductViewRank(data) {
    return request({
      url: '/store/api/ApiGetProductViewRank',
      method: 'post',
      data
    })
  },
 
  // 获取用户销售排行
  getProductSaleRank(data) {
    return request({
      url: '/store/api/ApiGetProductSaleRank',
      method: 'post',
      data
    })
  },
 
  // 获取商品可用优惠券
  getProductPromoteCodeList(data) {
    return request({
      url: '/store/api/ApiGetProductPromoteCodeList',
      method: 'post',
      data
    })
  },
 
  // 获取订单可用优惠券
  getOrderPromoteCodeList(data) {
    return request({
      url: '/store/api/GetOrderPromoteCodeList',
      method: 'post',
      data
    })
  },
 
  // 获取销售方式可用优惠券
  getSaleMethodPromoteCodeList(data) {
    return request({
      url: '/store/api/GetSaleMethodPromoteCodeList',
      method: 'post',
      data
    })
  },
 
  // 领取优惠卷
  getPromoteCode(data) {
    return request({
      url: '/store/api/ApiGetPromoteCode',
      method: 'post',
      data
    })
  },
 
  // 为订单使用优惠券
  updateOrderPromoteCode(data) {
    return request({
      url: '/store/api/UpdateOrderPromoteCode',
      method: 'post',
      data
    })
  },
 
  // 为销售方式使用优惠券
  updateSaleMethodPromoteCode(data) {
    return request({
      url: '/store/api/UpdateSaleMethodPromoteCode',
      method: 'post',
      data
    })
  },
 
  // 通过订单号获取订单
  getOrderByOrderNum(data) {
    return request({
      url: '/store/api/GetOrderByOrderNum',
      method: 'post',
      data
    })
  },
 
  // 创建订单
  initOrder(data) {
    return request({
      url: '/store/api/InitOrder',
      method: 'post',
      data
    })
  },
 
  // 确认订单
  confirmOrder(data) {
    return request({
      url: '/store/api/ConfirmOrder',
      method: 'post',
      data
    })
  },
 
  // 取消订单
  cancelOrder(data) {
    return request({
      url: '/store/api/CancelOrder',
      method: 'post',
      data
    })
  },
 
  // 赞赏
  CreateDonateOrder(data) {
    return request({
      url: '/store/api/CreateDonateOrder',
      method: 'post',
      data
    })
  },
 
  //获取用户订单列表
  getUserOrderList(data) {
    return request({
      url: '/store/api/GetUserOrderList',
      method: 'post',
      data
    })
  },
 
  //获取频道下的列表
  getStoreChannelList(data) {
    return request({
      url: '/store/api/ApiGetStoreChannelList',
      method: 'post',
      data
    })
  },
 
  //获取购物车
  getShoppingCartProductList(data) {
    return request({
      url: '/store/api/ApiGetShoppingCartProductList',
      method: 'post',
      data
    })
  },
 
  //添加到购物车
  addShoppingCart(data) {
    return request({
      url: '/store/api/ApiAddShoppingCart',
      method: 'post',
      data
    })
  },
 
  //购物车删除商品
  delShoppingCart(data) {
    return request({
      url: '/store/api/ApiDelShoppingCart',
      method: 'post',
      data
    })
  },
 
  //从购物车创建订单
  shoppingCartCreateOrder(data) {
    return request({
      url: '/store/api/ApiShoppingCartCreateOrder',
      method: 'post',
      data
    })
  },
 
  //获取已购买的商品列表
  getPurchasedProductList(data) {
    return request({
      url: '/store/api/ApiGetPurchasedProductList',
      method: 'post',
      data
    })
  },
 
  //调取微信支付
  makeWeChatPay(data) {
    return request({
      url: '/store/api/MakeWeChatPay',
      method: 'post',
      data
    })
  },
 
  //调取微信二维码支付
  makeWeChatQrPay(data) {
    return request({
      url: '/store/api/MakeWeChatQrPay',
      method: 'post',
      data
    })
  },
 
  // 获取激活码详情
  getActiveCode(data) {
    return request({
      url: '/store/api/ApiGetActiveCode',
      method: 'post',
      data
    })
  },
 
  // 使用激活码
  userActiveCode(data) {
    return request({
      url: '/store/api/ApiUseActiveCode',
      method: 'post',
      data
    })
  },
  // 使用激活码使用记录
  userActiveCodeList(data) {
    return request({
      url: '/store/api/ApiGetUsedActiveCodeList',
      method: 'post',
      data
    })
  },
 
  // 商品查询类型字段接口
  getProductTypeField(data) {
    return request({
      url: '/store/api/ApiGetProductTypeField',
      method: 'post',
      data
    })
  },
 
  // 收藏或加入书架
  addProductLink(data) {
    return request({
      url: '/store/api/ApiAddProductLink',
      method: 'post',
      data
    })
  },
 
  // 取消收藏或移除书架
  delProductLink(data) {
    return request({
      url: '/store/api/ApiDelProductLink',
      method: 'post',
      data
    })
  },
 
  //购买免费商品
  MakeFreeOrderPay(data) {
    return request({
      url: '/store/api/MakeFreeOrderPay',
      method: 'post',
      data
    })
  },
 
  // 申请订单开票
  requestOrderInvoice(data) {
    return request({
      url: '/store/api/RequestOrderInvoice',
      method: 'post',
      data
    })
  },
 
  // 获取用户钱包
  getUserWallet(data) {
    return request({
      url: '/store/api/GetWallet',
      method: 'post',
      data
    })
  },
  // 获取用户钱包记录
  getWalletHistory(data) {
    return request({
      url: '/store/api/GetWalletHistory',
      method: 'post',
      data
    })
  },
  // 通过钱包自动购买
  autoPayWithWallet(data) {
    return request({
      url: '/store/api/AutoPayWithWallet',
      method: 'post',
      data
    })
  },
  // 查询商品所在Store
  getProductStore(data) {
    return request({
      url: '/store/api/ApiGetProductStore',
      method: 'post',
      data
    })
  }
}
 
export default storeApi