import http from '@/utils/request'
import { getPosPayChannel } from '@/utils/choosePay'

// 订单类通用接口，需手动指定url
export function apiOrder (url, { data: params }) {
  return http.post(`/admin/statistics/${url}`, { data: params })
}
// 获取订单列表
export function apiOrderList (params) {
  // 只显示用户绑定景点
  return http.post('/admin/order/list', { data: params })
}
export function getLastThreeOrderList (params) {
  return http.post('order/getLastThreeOrderList', { data: params })
}
// 获取订单列表（改签页面）
export function getOrderListForChange (params) {
  return http.post('order/getOrderListForChange', { data: params })
}
// 获取订单列表（退票页面）
export function getOrderListForRefund (params) {
  return http.post('order/getOrderListForRefund', { data: params })
}

// 获取检票列表
export function apiCheckList (params) {
  return http.post('/admin/statistics/orderCheckStatistics', { data: params })
}

// 获取免票列表
export function apiFreeList (params) {
  return http.post('/admin/freeLog/list', { data: params })
}
// 删除免票记录
export function deleteFreeRecord (id) {
  return http.post('/admin/freeLog/delete', { data: { idList: [id] } })
}
// 获取游客列表
export function apiVisitorList (params) {
  return http.post('/admin/customer', { data: params })
}
// 删除游客记录
export function deleteVisitorRecord (id) {
  return http.post('/admin/customer/delete', { data: { idList: [id] } })
}

// 免票统计
export function getFreeTicketStatistics (params) {
  return http.post('/admin/statistics/freeLogStatistics', { data: params })
}
// 获取按销售渠道的订单统计
export function getOrderStatisticsBySaleChannel (params) {
  return http.post('/order/getOrderStatisticsBySaleChannel', { data: params })
}

// 根据售票渠道获取检票列表
export function getCheckStatisticsByOtaName (params) {
  return http.post('order/getCheckStatisticsByOtaName', { data: params })
}
// 通行人数统计
export function getCheckStatisticsInTicketCount (params) {
  return http.post('order/getCheckStatisticsInTicketCount', { data: params })
}

// 创建订单
export function createOrder (params) {
  if (params.bocTradeNo) {
    params.payChannel = getPosPayChannel(params.bocTradeNo)
  }

  params.ticketList = params.tickets
  delete params.tickets
  // console.log(params)
  return http.post('/admin/order/createOrder', { data: params })
}

// 获取单个订单详情
export function getSingleOrder (id) {
  return http.post('/admin/order/getById', { data: { id } })
}

// 取消订单
export function cancelOrder (params) {
  return http.post('/admin/order/cancelOrder', { data: params })
}

// 门票补打
export function reprintTicket (params) {
  return http.post('/admin/order/secondPrintTicket', { data: params })
}

// 人工检票
export function checkTickets (params) {
  return http.post('/admin/order/manualCheck', { data: params })
}

// 修改订单
export function updateOrder (params) {
  return http.post('/admin/order/orderUpdate', { data: params })
}

// 获取所有订单统计
export function getOrderStatistics (params) {
  return http.post('/admin/statistics/orderSaleStatistics', { data: params })
}

// 获取妈祖日历票订单统计
export function getBatchAndAreaStatistics (params) {
  return http.post('/orderStatistics/getBatchAndAreaStatistics', { data: params })
}

// 获取按售票员的订单统计
export function getOrderStatisticsByManager (params) {
  return http.post('/order/getOrderStatisticsByManager', { data: params })
}
// 退票统计
export function getCancelOrderStatistics (params) {
  return http.post('/order/getCancelOrderStatistics', { data: params })
}
// 取消单张票
export function cancelPartTicket (params) {
  return http.post('/order/cancelPartTicket', { data: params })
}

// 预订订单出票
export function createAgencyPreorderTickets (params) {
  return http.post('/order/travelAgencyPreorderGetTickets', { data: params })
}

// 已开发票
export function pickInvoice (
  params,
  ticketIdList,
  type,
  buyer,
  tax_num,
  email,
  phone,
  invoiceBuyerAddress,
  invoiceBuyerBankAccount,
  remark
) {
  return http.post('/order/pickInvoice', {
    orderIdList: params,
    ticketIdList,
    invoiceType: type,
    invoiceBuyer: buyer,
    invoiceBuyerTaxNum: tax_num,
    invoiceBuyerEmail: email,
    invoiceBuyerPhone: phone,
    invoiceBuyerAddress,
    invoiceBuyerBankAccount,
    remark
  })
}

// 获取发票
export function getInvoice (params) {
  return http.post('/order/getInvoice', {
    orderIdList: params
  })
}

// 售票累计统计
export function getOrderGrandTotalStatistics (params) {
  return http.post('/orderStatistics/getOrderGrandTotalStatistics', { data: params })
}

// 获取销售渠道列表
export function getSaleChannelList () {
  return http.post('/admin/order/otaSourceNameList')
}

// 补打记录
export function getTicketSecondPrintLog (params) {
  return http.post('/orderStatistics/getTicketSecondPrintLog', { data: params })
}

// 查询门票同比分析表
export function getComparedAnalysis (params) {
  return http.post('/order/getComparedAnalysis', { data: params })
}
// 导出门票同比分析表
export function exportOrderComparedAnalysis (params) {
  return http.post('/exportMission/exportOrderComparedAnalysis', { data: params })
}

// 景点售票统计
export function getOrderScenicSaleStatistics (params) {
  return http.post('/orderStatistics/getOrderScenicSaleStatistics', { data: params })
}
// 景点售票统计导出
export function exportOrderScenicSaleStatistics (params) {
  return http.post('/exportMission/exportOrderScenicSaleStatistics', { data: params })
}

// 处理门票
export function ticketHandle (params) {
  return http.post('/order/ticketHandle', { data: params })
}

// 处理历史
export function getTicketHandleLogs (params) {
  return http.post('/order/getTicketHandleLogs', { data: params })
}

// 预订单列表
export function preorderList (params) {
  return http.post('/preorder/list', { data: params })
}

// 预订单导出
export function preorderListExport (params) {
  return http.post('/preorder/export', { data: params })
}

// 修改预订单
export function preorderUpdate (params) {
  return http.post('/preorder/update', { data: params })
}

// 预订单审核
export function preorderAudit (params) {
  return http.post('/preorder/audit', { data: params })
}

// 预订单出票
export function preorderCreateOrder (params) {
  return http.post('/preorder/createOrder', { data: params })
}

// 预订单删除
export function preorderDelete (params) {
  return http.post('/preorder/delete', { data: params })
}

// 预订单详情
export function preorderDetail (id) {
  return http.post(`/preorder/${id}`)
}

// 预订单游客详情
export function preorderDetailTravellerFace (id) {
  return http.post(`/preorder/traveller/${id}`)
}

// 预订单游客详情
export function getKeys () {
  return http.post('http://175.44.31.47:3000/impression-mazu-ms/open/loginApp/getKeys?loginName=browse&password=Aaqw2@2024')
}

export function printTickets (ids) {
  return http.post('/admin/order/printTicket', { data: { ticketIdList: ids } })
}

export function getReportList (params) {
  return http.post('/admin/reportMission', { data: params })
}

export function deleteReport (ids) {
  return http.post('/admin/reportMission/delete', { data: { idList: ids } })
}
