杨磊
3 天以前 87d2fac9c381de99f75ce6c6c39b7d638b980d7e
src/assets/js/middleGround/api/store.js
@@ -1,10 +1,6 @@
import request from "@/plugin/axios";
import { tokenKey, goodsStore } from "@/assets/js/config";
import toolClass from "@/assets/js/toolClass";
import {
  handleQueryResourceListData,
  handleDetailQueryRequestData
} from "../tool";
import request from '@/plugin/axios/index.ts'
import { tokenKey, goodsStore } from '@/assets/js/config'
import { handleQueryResourceListData, handleDetailQueryRequestData } from '../tool'
const storeApi = {
  /*
    **获取商品列表**
@@ -18,9 +14,10 @@
    fields: 自定义字段
  */
  getProductList: ({
    path = "",
    path = '',
    storeInfo = goodsStore,
    storeEventIdOrRefCode = "",
    storeEventIdOrRefCode = '',
    favoriteTypes = '',
    queryType,
    linkType,
    subAccess = [],
@@ -29,30 +26,32 @@
    fields,
    filterList,
    coverSize,
    mainProductId
    mainProductId,
    handelEBooK
  }) => {
    const query = {
      AccessControl: {
        Path: path,
        StoreRefCode: storeInfo + "",
        Type: queryType || "\\",
        LinkType: linkType || ""
        StoreRefCode: storeInfo + '',
        Type: queryType || '\\',
        LinkType: linkType || ''
      },
      FavoriteTypes: favoriteTypes ? [favoriteTypes] : [],
      SubAccess: subAccess.length > 0 ? subAccess : [],
      PageQuery: {
        Start: paging.start || "0",
        Size: paging.size || "10"
        Start: paging.start || '0',
        Size: paging.size || '10'
      },
      SortQuery:
        sort?.length == 0
          ? []
          : sort
          ? [sort]
          : [
              {
                LinkOrder: "Desc"
              }
            ],
            ? [sort]
            : [
                {
                  LinkOrder: 'Desc'
                }
              ],
      CreateDate: [],
      Description: [],
      Name: [],
@@ -74,9 +73,33 @@
      StoreEventIdOrRefCode: storeEventIdOrRefCode,
      ...fields,
      ...filterList
    };
    }
    if (mainProductId) {
      query.AccessControl.MainProductId = 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({
@@ -86,36 +109,35 @@
          }
        ]
      })
    };
    let token = toolClass.getCookie(tokenKey);
    let url = token
      ? "/store/api/ApiQueryProductByAppUser"
      : "/store/api/ApiQueryProduct";
    }
    let token = localStorage.getItem(tokenKey)
    let url = token ? '/store/api/ApiQueryProductByAppUser' : '/store/api/ApiQueryProduct'
    return request({
      url: url,
      method: "post",
      method: 'post',
      data: body
    }).then((resp) => {
      if (resp.length > 0) {
        const data = resp[0];
        const data = resp[0]
        const datas = handleQueryResourceListData({
          datas: data.datas,
          fields,
          path,
          storeInfo,
          coverSize
        });
          coverSize,
          handelEBooK
        })
        return {
          datas,
          total: data.totalCount,
          extraInfos: data.extraInfos?.StoreEvent
        };
        }
      }
      return {
        datas: [],
        total: 0
      };
    });
      }
    })
  },
  /*
    **获取商品详情**
@@ -128,47 +150,92 @@
    cmsPath:cmsPath
  */
  getProductDetail: ({
    path = "",
    path = '',
    storeInfo = goodsStore,
    channelInfo = "",
    channelInfo = '',
    favoriteTypes = '',
    queryType,
    subAccess = [],
    fields,
    productId,
    cmsPath,
    cmsType,
    coverSize,
    itemId,
    itemIds,
    itemFields,
    linkTypes
    linkTypes,
    filterList,
    handelEBooK,
    sort,
    cmsSort,
    source
  }) => {
    const subQuery = {};
    const subQuery = {}
    if (cmsPath) {
      subQuery["QueryCms"] = {
        Path: cmsPath + "",
        Type: "\\",
      subQuery['QueryCms'] = {
        Path: cmsPath + '',
        Type: cmsType || '\\',
        Name: [],
        Icon: [],
        TypeId: [],
        RefCode: [],
        Description:[],
        ChildrenCount: [],
        ChildrenFolderCount: [],
        CreateDate: [],
        SysType: [],
        SaleMethod: [],
        PageQuery: {
          Start: 0,
          Size: 100
          Size: 9999
        },
        SortQuery: cmsSort
          ? [cmsSort]
          : [
              {
                ProductLinkOrder: 'Asc'
              }
            ],
        ProductLinkInfo: [],
        ...itemFields
      };
      if (itemId) subQuery["QueryCms"]["Id="] = [`${itemId}`];
      }
      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 = {};
    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: "\\",
        const linkType = linkTypes[i]
        subQuery['QueryLink_' + linkType.linkType] = {
          Path: cmsPath + '',
          Type: '\\',
          Name: [],
          Icon: [],
          TypeId: [],
          RefCode: [],
          Description:[],
          LinkTypes: [linkType.linkType],
          PageQuery: {
            Start: 0,
@@ -176,32 +243,40 @@
          },
          ProductLinkInfo: [],
          ...linkType.fields
        };
        }
        linkFields = {
          ...linkFields,
          ...linkType.fields
        };
        }
      }
    }
    const query = {
      AccessControl: {
        Path: path,
        StoreRefCode: storeInfo + "",
        ChannelRefCode: channelInfo + "",
        Type: queryType || "\\"
        StoreRefCode: storeInfo + '',
        ChannelRefCode: channelInfo + '',
        Type: queryType || '\\'
      },
      FavoriteTypes: favoriteTypes ? [favoriteTypes] : [],
      SubAccess: subAccess.length > 0 ? subAccess : [],
      PageQuery: {
        Start: "0",
        Size: "1"
        Start: '0',
        Size: '1'
      },
      "Id=": [`${productId}`],
      SortQuery: [],
      'Id=': [`${productId}`],
      SortQuery: sort
        ? [sort]
        : [
            {
              LinkOrder: 'Desc'
            }
          ],
      CreateDate: [],
      Description: [],
      Name: [],
      Icon: [],
      RefCode: [],
      Description:[],
      TypeId: [],
      SysType: [],
      State: [],
@@ -214,10 +289,12 @@
      StoreEvent: [],
      SaleMethod: [],
      SaleMethodValid: [],
      CmsItemValid: [],
      ProductCmsQuery: [subQuery],
      ...fields
    };
    if (productId) query["Id="] = [`${productId}`];
      ...fields,
      ...filterList
    }
    if (productId) query['Id='] = [`${productId}`]
    const body = {
      query: JSON.stringify({
@@ -227,308 +304,576 @@
          }
        ]
      })
    };
    let token = toolClass.getCookie(tokenKey);
    let url = token
      ? "/store/api/ApiQueryProductByAppUser"
      : "/store/api/ApiQueryProduct";
    }
    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];
        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
          });
          return {
            datas,
            total: data.totalCount
          };
        } else {
          return {
            datas: [],
            total: 0
          };
      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
        }
      }
      return {
        datas: [],
        total: 0
      };
    });
  },
    }
    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",
      url: '/store/api/ApiGetChannelPromoteCodeList',
      method: 'post',
      data
    });
    })
  },
  // 获取用户已领取的优惠券列表
  getPromoteCodeList(data) {
    return request({
      url: "/store/api/ApiGetPromoteCodeList",
      method: "post",
      url: '/store/api/ApiGetPromoteCodeList',
      method: 'post',
      data
    });
    })
  },
  // 获取用户浏览排行
  getProductViewRank(data) {
    return request({
      url: "/store/api/ApiGetProductViewRank",
      method: "post",
      url: '/store/api/ApiGetProductViewRank',
      method: 'post',
      data
    });
    })
  },
  // 获取用户销售排行
  getProductSaleRank(data) {
    return request({
      url: "/store/api/ApiGetProductSaleRank",
      method: "post",
      url: '/store/api/ApiGetProductSaleRank',
      method: 'post',
      data
    });
    })
  },
  // 获取商品可用优惠券
  getProductPromoteCodeList(data) {
    return request({
      url: "/store/api/ApiGetProductPromoteCodeList",
      method: "post",
      url: '/store/api/ApiGetProductPromoteCodeList',
      method: 'post',
      data
    });
    })
  },
  // 获取订单可用优惠券
  getOrderPromoteCodeList(data) {
    return request({
      url: "/store/api/GetOrderPromoteCodeList",
      method: "post",
      url: '/store/api/GetOrderPromoteCodeList',
      method: 'post',
      data
    });
    })
  },
  // 获取销售方式可用优惠券
  getSaleMethodPromoteCodeList(data) {
    return request({
      url: "/store/api/GetSaleMethodPromoteCodeList",
      method: "post",
      url: '/store/api/GetSaleMethodPromoteCodeList',
      method: 'post',
      data
    });
    })
  },
  // 领取优惠卷
  getPromoteCode(data) {
    return request({
      url: "/store/api/ApiGetPromoteCode",
      method: "post",
      url: '/store/api/ApiGetPromoteCode',
      method: 'post',
      data
    });
    })
  },
  // 为订单使用优惠券
  updateOrderPromoteCode(data) {
    return request({
      url: "/store/api/UpdateOrderPromoteCode",
      method: "post",
      url: '/store/api/UpdateOrderPromoteCode',
      method: 'post',
      data
    });
    })
  },
  // 为销售方式使用优惠券
  updateSaleMethodPromoteCode(data) {
    return request({
      url: "/store/api/UpdateSaleMethodPromoteCode",
      method: "post",
      url: '/store/api/UpdateSaleMethodPromoteCode',
      method: 'post',
      data
    });
    })
  },
  // 通过订单号获取订单
  getOrderByOrderNum(data) {
    return request({
      url: "/store/api/GetOrderByOrderNum",
      method: "post",
      url: '/store/api/GetOrderByOrderNum',
      method: 'post',
      data
    });
    })
  },
  // 创建订单
  initOrder(data) {
    return request({
      url: "/store/api/InitOrder",
      method: "post",
      url: '/store/api/InitOrder',
      method: 'post',
      data
    });
    })
  },
  // 确认订单
  confirmOrder(data) {
    return request({
      url: "/store/api/ConfirmOrder",
      method: "post",
      url: '/store/api/ConfirmOrder',
      method: 'post',
      data
    });
    })
  },
  // 取消订单
  cancelOrder(data) {
    return request({
      url: "/store/api/CancelOrder",
      method: "post",
      url: '/store/api/CancelOrder',
      method: 'post',
      data
    });
    })
  },
  // 赞赏
  CreateDonateOrder(data) {
    return request({
      url: "/store/api/CreateDonateOrder",
      method: "post",
      url: '/store/api/CreateDonateOrder',
      method: 'post',
      data
    });
    })
  },
  //获取用户订单列表
  getUserOrderList(data) {
    return request({
      url: "/store/api/GetUserOrderList",
      method: "post",
      url: '/store/api/GetUserOrderList',
      method: 'post',
      data
    });
    })
  },
  //获取频道下的列表
  getStoreChannelList(data) {
    return request({
      url: "/store/api/ApiGetStoreChannelList",
      method: "post",
      url: '/store/api/ApiGetStoreChannelList',
      method: 'post',
      data
    });
    })
  },
  //获取购物车
  getShoppingCartProductList(data) {
    return request({
      url: "/store/api/ApiGetShoppingCartProductList",
      method: "post",
      url: '/store/api/ApiGetShoppingCartProductList',
      method: 'post',
      data
    });
    })
  },
  //添加到购物车
  addShoppingCart(data) {
    return request({
      url: "/store/api/ApiAddShoppingCart",
      method: "post",
      url: '/store/api/ApiAddShoppingCart',
      method: 'post',
      data
    });
    })
  },
  //购物车删除商品
  delShoppingCart(data) {
    return request({
      url: "/store/api/ApiDelShoppingCart",
      method: "post",
      url: '/store/api/ApiDelShoppingCart',
      method: 'post',
      data
    });
    })
  },
  //从购物车创建订单
  shoppingCartCreateOrder(data) {
    return request({
      url: "/store/api/ApiShoppingCartCreateOrder",
      method: "post",
      url: '/store/api/ApiShoppingCartCreateOrder',
      method: 'post',
      data
    });
    })
  },
  //获取已购买的商品列表
  getPurchasedProductList(data) {
    return request({
      url: "/store/api/ApiGetPurchasedProductList",
      method: "post",
      url: '/store/api/ApiGetPurchasedProductList',
      method: 'post',
      data
    });
    })
  },
  //调取微信支付
  makeWeChatPay(data) {
    return request({
      url: "/store/api/MakeWeChatPay",
      method: "post",
      url: '/store/api/MakeWeChatPay',
      method: 'post',
      data
    });
    })
  },
  //调取微信二维码支付
  makeWeChatQrPay(data) {
    return request({
      url: "/store/api/MakeWeChatQrPay",
      method: "post",
      url: '/store/api/MakeWeChatQrPay',
      method: 'post',
      data
    });
    })
  },
  // 获取激活码详情
  getActiveCode(data) {
    return request({
      url: "/store/api/ApiGetActiveCode",
      method: "post",
      url: '/store/api/ApiGetActiveCode',
      method: 'post',
      data
    });
    })
  },
  // 使用激活码
  userActiveCode(data) {
    return request({
      url: "/store/api/ApiUseActiveCode",
      method: "post",
      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",
      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",
      url: '/store/api/ApiDelProductLink',
      method: 'post',
      data
    });
    })
  },
  //收藏商品
  productLink(data) {
  //购买免费商品
  MakeFreeOrderPay(data) {
    return request({
      url: "/store/api/ApiAddProductLink",
      method: "post",
      url: '/store/api/MakeFreeOrderPay',
      method: 'post',
      data
    });
  }
};
    })
  },
export default storeApi;
  // 申请订单开票
  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