import request from "@/utils/request";

/**
 * 分析概览
 * @param param
 * @returns {AxiosPromise}
 */
export function analysisPreview(param) {
  const safeParam = JSON.parse(JSON.stringify(param));

  if (safeParam.startTime) {
    const startDate = new Date(safeParam.startTime);
    if (!isNaN(startDate.getTime())) {
      safeParam.startTime = `${safeParam.startTime.trim()} 00:00:00`;
    }
  }

  if (safeParam.endTime) {
    const endDate = new Date(safeParam.endTime);
    if (!isNaN(endDate.getTime())) {
      safeParam.endTime = `${safeParam.endTime.trim()} 23:59:59`;
    }
  }
  return request({
    url: '/index/statistics/analysisPreview',
    method: 'post',
    data: safeParam
  })
}

/**
 * 数据概览
 * @param query
 * @returns {AxiosPromise}
 */
export function dealerAggregated() {
  return request({
    url: '/index/statistics/dealerAggregated',
    method: 'get',
    params: {}
  })
}

/**
 * 消费余额
 * @returns {AxiosPromise}
 */
export function rechargeComsumption(){
  return request({
    url: '/index/statistics/rechargeComsumption',
    method: 'get',
    params: {}
  })
}
/**
 * 获取统计流量
 * @returns {AxiosPromise}
 */
export function trafficLog(){
  return request({
    url: '/index/statistics/trafficLog',
    method: 'get',
    params: {}
  })
}



/**
 * 数据概览
 * @param query
 * @returns {AxiosPromise}
 */
export function smsBalance() {
  return request({
    url: '/index/statistics/smsBalance',
    method: 'get',
    params: {}
  })
}

/**
 * 授权信息
 * @returns {*}
 */
export function authorizationInfo() {
  return request({
    url: '/index/statistics/authorizationInfo',
    method: 'get',
    params: {}
  })
}

/**
 * 课程观看top10
 * @returns {*}
 */
// export function watchCourseTopTen(param){
//   const safeParam = JSON.parse(JSON.stringify(param));
//
//   if (safeParam.startTime) {
//     const startDate = new Date(safeParam.startTime);
//     if (!isNaN(startDate.getTime())) {
//       safeParam.startTime = `${safeParam.startTime.trim()} 00:00:00`;
//     }
//   }
//
//   if (safeParam.endTime) {
//     const endDate = new Date(safeParam.endTime);
//     if (!isNaN(endDate.getTime())) {
//       safeParam.endTime = `${safeParam.endTime.trim()} 23:59:59`;
//     }
//   }
//   return request({
//     url: '/index/statistics/watchCourseTopTen',
//     method: 'post',
//     data: safeParam
//   })
// }

/**
 * 课程观看趋势
 * @returns {*}
 */
export function watchCourseTrend(param){
  const safeParam = JSON.parse(JSON.stringify(param));

  if (safeParam.startTime) {
    const startDate = new Date(safeParam.startTime);
    if (!isNaN(startDate.getTime())) {
      safeParam.startTime = `${safeParam.startTime.trim()} 00:00:00`;
    }
  }

  if (safeParam.endTime) {
    const endDate = new Date(safeParam.endTime);
    if (!isNaN(endDate.getTime())) {
      safeParam.endTime = `${safeParam.endTime.trim()} 23:59:59`;
    }
  }
  return request({
    url: '/index/statistics/watchCourseTrend',
    method: 'post',
    data: safeParam
  })
}

/**
 * 课程观看趋势
 * @returns {*}
 */
export function watchEndPlayTrend(param){
  const safeParam = JSON.parse(JSON.stringify(param));

  if (safeParam.startTime) {
    const startDate = new Date(safeParam.startTime);
    if (!isNaN(startDate.getTime())) {
      safeParam.startTime = `${safeParam.startTime.trim()} 00:00:00`;
    }
  }

  if (safeParam.endTime) {
    const endDate = new Date(safeParam.endTime);
    if (!isNaN(endDate.getTime())) {
      safeParam.endTime = `${safeParam.endTime.trim()} 23:59:59`;
    }
  }
  return request({
    url: '/index/statistics/watchEndPlayTrend',
    method: 'post',
    data: safeParam
  })
}

/**
 * 经销商会员观看
 * @param param
 * @returns {*}
 */
export function deaMemberTopTen(param){
  const safeParam = JSON.parse(JSON.stringify(param));

  if (safeParam.startTime) {
    const startDate = new Date(safeParam.startTime);
    if (!isNaN(startDate.getTime())) {
      safeParam.startTime = `${safeParam.startTime.trim()} 00:00:00`;
    }
  }

  if (safeParam.endTime) {
    const endDate = new Date(safeParam.endTime);
    if (!isNaN(endDate.getTime())) {
      safeParam.endTime = `${safeParam.endTime.trim()} 23:59:59`;
    }
  }
  return request({
    url: '/index/statistics/deaMemberTopTen',
    method: 'post',
    data: safeParam
  })
}

/**
 * 课程观看TOP10
 * @param param
 * @returns {AxiosPromise}
 */
export function watchCourseTopTen(param){
  const safeParam = JSON.parse(JSON.stringify(param));

  if (safeParam.startTime) {
    const startDate = new Date(safeParam.startTime);
    if (!isNaN(startDate.getTime())) {
      safeParam.startTime = `${safeParam.startTime.trim()} 00:00:00`;
    }
  }

  if (safeParam.endTime) {
    const endDate = new Date(safeParam.endTime);
    if (!isNaN(endDate.getTime())) {
      safeParam.endTime = `${safeParam.endTime.trim()} 23:59:59`;
    }
  }
  return request({
    url: '/index/statistics/watchCourseTopTen',
    method: 'post',
    data: safeParam
  })
}


/**
 * 答题红包金额TOP10
 * @returns {*}
 */
export function rewardMoneyTopTen(param){
  const safeParam = JSON.parse(JSON.stringify(param));

  if (safeParam.startTime) {
    const startDate = new Date(safeParam.startTime);
    if (!isNaN(startDate.getTime())) {
      safeParam.startTime = `${safeParam.startTime.trim()} 00:00:00`;
    }
  }

  if (safeParam.endTime) {
    const endDate = new Date(safeParam.endTime);
    if (!isNaN(endDate.getTime())) {
      safeParam.endTime = `${safeParam.endTime.trim()} 23:59:59`;
    }
  }
  return request({
    url: '/index/statistics/rewardMoneyTopTen',
    method: 'post',
    data: safeParam
  })
}

/**
 * 答题红包金额趋势
 * @returns {*}
 * @param param
 * @returns {*}
 */
export function rewardMoneyTrend(param){
  const safeParam = JSON.parse(JSON.stringify(param));

  if (safeParam.startTime) {
    const startDate = new Date(safeParam.startTime);
    if (!isNaN(startDate.getTime())) {
      safeParam.startTime = `${safeParam.startTime.trim()} 00:00:00`;
    }
  }

  if (safeParam.endTime) {
    const endDate = new Date(safeParam.endTime);
    if (!isNaN(endDate.getTime())) {
      safeParam.endTime = `${safeParam.endTime.trim()} 23:59:59`;
    }
  }
  return request({
    url: '/index/statistics/rewardMoneyTrend',
    method: 'post',
    data: safeParam
  })
}


/**
 * 获取当月订单数
 * @returns {*}
 */
export function thisMonthOrderCount(){
  return request({
    url: '/index/statistics/thisMonthOrderCount',
    method: 'get',
    params: {}
  })
}

/**
 * 获取当月收款数
 * @returns {*}
 */
export function thisMonthRecvCount(){
  return request({
    url: '/index/statistics/thisMonthRecvCount',
    method: 'get',
    params: {}
  })
}
