杨磊
3 天以前 87d2fac9c381de99f75ce6c6c39b7d638b980d7e
src/assets/js/middleGround/api/store.js
New file
@@ -0,0 +1,879 @@
import request from '@/plugin/axios/index.ts'
import { tokenKey, goodsStore } from '@/assets/js/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: [],
        Description:[],
        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: [],
        Description:[],
        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: [],
          Description:[],
          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: [],
      Description:[],
      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
        }
      })
  },
  // 获取商品详情,不返回 ChildrenCount,ChildrenFolderCount
  // (此接口为了满足不返回 ChildrenCount,ChildrenFolderCount而后续添加的) 不是中台原有的
  getProductDetailNoChildren:({
    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: [],
        Description:[],
        // 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: [],
        Description:[],
        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: [],
          Description:[],
          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: [],
      Description:[],
      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
    })
  },
  //根据销售方式查询商品信息
  getProductBySaleMethod(data) {
    return request({
      url: '/store/api/ApiGetProductBySaleMethod',
      method: 'post',
      data
    })
  }
}
export default storeApi