import http from '@/utils/request'
import moment from 'moment'
export const getRealtime = () => {
  return http.post(`order/getOrderStatistics`, {
    startDate: new Date(moment().format('YYYY-MM-DD') + ' 00:00:00'),
    endDate: new Date(moment().format('YYYY-MM-DD') + ' 23:59:59'),
    keyWords2: '', // 票种id
    keyWords3: '', // 售票员id
    keyWords4: '' // 景点
  }).then(res => {
    let sumInfo = res.data[res.data.length - 1]
    if (sumInfo) {
      return {
        price: sumInfo.actual_price || 0,
        count: sumInfo.actual_count || 0,
        cancel: sumInfo.sum_cancel || 0,
        checkNum: sumInfo.actual_people || 0,
        cancelRate: (((sumInfo.sum_cancel || 0) / (sumInfo.sum_count || 1)) * 100).toFixed(2)
      }
    } else {
      return {
        price: 0,
        count: 0,
        cancel: 0,
        checkNum: 0,
        cancelRate: 0
      }
    }
  })
}
export const getMonthSales = () => {
  let params = {
    startDate: new Date(moment().subtract(30, 'days').format('YYYY-MM-DD') + ' 00:00:00'),
    endDate: new Date(moment().subtract(1, 'days').format('YYYY-MM-DD') + ' 23:59:59')
  }
  return http.post('order/getOrderStatisticsByDate', params).then(res => {
    return res.data
  })
}
