/**
 * api接口管理， 全部以$开头
 * @author terrfly
 * @site https://www.jeequan.com
 * @date 2021/12/17 09:57
 */

import http from './http.js';
import { Base64 } from 'js-base64';

export const req = {
  list: (uri, params) => {
    return http.req(uri, params, 'GET', false);
  },

  add: (uri, data) => {
    return http.req(uri, data, 'POST', false);
  },

  getById: (uri, bizId) => {
    return http.req(`${uri}/${bizId}`, {}, 'GET', false);
  },

  updateById: (uri, bizId, data) => {
    return http.req(`${uri}/${bizId}`, data, 'PUT', false);
  },

  delById: (uri, bizId) => {
    return http.req(`${uri}/${bizId}`, {}, 'DELETE', false);
  },
};
// 登录
export const $login = (v) => {
  // 登录类型
  let lt = '';

  // #ifdef H5 || MP-WEIXIN || MP-ALIPAY
  lt = Base64.encode('FACEAPP');
  // #endif

  let data = {
    ia: Base64.encode(v.username),
    ip: Base64.encode(v.pwd),
    lt: lt,
  };
  return http.req('/api/anon/auth/validate', data, 'POST');
};
/** 支付订单列表 */
export const API_URL_PAY_ORDER_LIST = '/api/payOrder';
/* 订单退款 */
export function $payOrderRefund(vdata) {
  return http.req(
    '/api/payOrder/refunds/' + vdata.payOrderId,
    {
      refundAmount: vdata.refundAmountNum,
      refundReason: vdata.refundReason,
      refundPassword: Base64.encode(vdata.refundPassword),
    },
    'POST'
  );
}
/* 获取个人信息 */
export function $userInfo(cid1, cid2) {
  return http.req('/api/current/user', { cid1, cid2 }, 'GET');
}
// 首页 交易数据
export const $indexPayment = () => {
  return http.req(
    '/api/mainChart/payDayCount',
    { queryDateRange: 'today' },
    'GET'
  );
};
// 上下班 打卡接口
export const $workRecords = (workState) => {
  return http.req('/api/user/workRecords', { workState: workState }, 'POST');
};
// 获取交班列表
export const $handover = () => {
  return http.req('/api/user/workRecords/stats', {}, 'GET');
};
/* 支付接口*/
export function $appPay(amount, authCode) {
  let data = { amount, wayCode: 'AUTO_BAR', authCode };
  return http.req('/api/pay/app', data, 'POST');
}
// 支付方式统计
export const $payTypeStat = (data) => {
  return http.req('/api/statistic', data, 'GET');
};
// 总支付方式统计
export const $payTypeStatAll = (data) => {
  return http.req('/api/statistic/total', data, 'GET');
};
// 交班列表
export const $handoverList = (params) => {
  return http.req('/api/user/workRecords', params, 'GET');
};
// 交班详情
export const $getHandoverById = (id) => {
  return req.getById('/api/user/workRecords', id);
};
// 获取公司信息 技术支持电话
export const $getCompanyInfos = () => {
  return http.req('/api/anon/siteInfos?queryConfig=1', {}, 'GET');
};
// 获取刷脸设备广告
export const $adBannerList = (params) => {
  return http.req('/api/advert/faceDevice',params,'GET')
};
