/*
 *  全系列 restful api格式, 定义通用req对象
 *
 *  @author terrfly
 *  @site https://www.jeepay.vip
 *  @date 2021/5/8 07:18
 */

import request from '@/http/request'
import { Base64 } from 'js-base64'
import $infoBox from '@/utils/infoBox'


export const req = {

  // 通用列表查询接口
  list: (url, params) => {
    return request.request({ url: url, method: 'GET', params: params }, true, true, false)
  },

  // 通用新增接口
  add: (url, data) => {
    return request.request({ url: url, method: 'POST', data: data }, true, true, false)
  },

  // 通用查询单条数据接口
  getById: (url, bizId, params = {}) => {
    return request.request({ url: url + '/' + bizId, method: 'GET', params: params }, true, true, false)
  },

  // 通用修改接口
  updateById: (url, bizId, data) => {
    return request.request({ url: url + '/' + bizId, method: 'PUT', data: data }, true, true, false)
  },

  // 通用删除接口
  delById: (url, bizId) => {
    return request.request({ url: url + '/' + bizId, method: 'DELETE' }, true, true, false)
  },

  // 通用 新增 or 更新
  addOrUpdate: (bizId, url, data, showMessage = true) => {

    //包含bizId 请求的是修改接口
    if (bizId) {
      return req.updateById(url, bizId, data).then(res => {
        if (showMessage) $infoBox.message.success('更新成功')
        return Promise.resolve(res)
      })

    } else {

      return req.add(url, data).then(res => {
        if (showMessage) $infoBox.message.success('新增成功')
        return Promise.resolve(res)
      })

    }

  }
}

// 全系列 restful api格式 (全局loading方式)
export const reqLoad = {

  // 通用列表查询接口
  list: (url, params) => {
    return request.request({ url: url, method: 'GET', params: params }, true, true, true)
  },

  // 通用新增接口
  add: (url, data) => {
    return request.request({ url: url, method: 'POST', data: data }, true, true, true)
  },

  // 通用查询单条数据接口
  getById: (url, bizId, params = {}) => {
    return request.request({ url: url + '/' + bizId, method: 'GET', params: params }, true, true, true)
  },

  // 通用修改接口
  updateById: (url, bizId, data) => {
    return request.request({ url: url + '/' + bizId, method: 'PUT', data: data }, true, true, true)
  },

  // 通用删除接口
  delById: (url, bizId) => {
    return request.request({ url: url + '/' + bizId, method: 'DELETE' }, true, true, true)
  }
}

/** 角色管理页面 **/
export const API_URL_ENT_LIST = '/api/sysEnts'
export const API_URL_ROLE_LIST = '/api/sysRoles'
export const API_URL_ROLE_ENT_RELA_LIST = '/api/sysRoleEntRelas'
export const API_URL_SYS_USER_LIST = '/api/sysUsers'
export const API_URL_SYS_USER_TEAM_LIST = '/api/userTeams'
export const API_URL_SYS_USER_TEAM_USER_LIST = 'api/userTeams/userList'
export const API_URL_USER_ROLE_RELA_LIST = '/api/sysUserRoleRelas'
/** 首页统计 **/
export const API_URL_MAIN_STATISTIC = '/api/mainChart'
/** 下级代理 **/
export const API_URL_AGENT_LIST = '/api/subAgents'
/** 服务商 **/
export const API_URL_ISV_LIST = '/api/isvInfo'
/** 商户App管理 **/
export const API_URL_MCH_APP = '/api/mchApps'
/** 支付订单管理 **/
export const API_URL_PAY_ORDER_LIST = '/api/payOrder'
/** 提现记录列表 **/
export const API_URL_WITHDRAWALS_RECORD_LIST = '/api/cashout'
/** 钱包流水列表 **/
export const API_URL_WALLET_HISTORY_LIST = '/api/accountHistory'
/** 退款订单管理 **/
export const API_URL_REFUND_ORDER_LIST = '/api/refundOrder'
/** 支付方式列表 **/
export const API_URL_PAYWAYS_LIST = '/api/payWays'
/** 商户支付通道配置 **/
export const API_URL_MCH_PAYPASSAGE_LIST = '/api/mch/payPassages'
/** 转账订单管理 **/
export const API_URL_TRANSFER_ORDER_LIST = '/api/transferOrders'

/** 分账组管理 **/
export const API_URL_DIVISION_RECEIVER_GROUP = '/api/divisionReceiverGroups'

/** 分账账号管理 **/
export const API_URL_DIVISION_RECEIVER = '/api/divisionReceivers'
/** 码牌管理 */
export const API_URL_QRC_SHELL_LIST = '/api/mchQrcShells'
/** 分账记录管理 **/
export const API_URL_PAY_ORDER_DIVISION_RECORD_LIST = '/api/division/records'

/** 三方账号信息 **/
export const API_URL_CHANNEL_ACCOUNT_INFO = '/api/channelAccountInfo'

/** 商户静态码管理 **/
export const API_URL_MCH_QR_CODE_LIST = '/api/mchQrCodes'

/** 商户门店管理 **/
export const API_URL_MCH_STORE_LIST = '/api/mchStore'

/** 微信公众号消息接收者管理 **/
export const API_URL_MCH_WXMP_UESR = '/api/wxmp'

/** 设备厂商配置 **/
export const API_URL_DEVICE_PROVIDER = '/api/device/provider'

/** 门店设备配置 **/
export const API_URL_STORE_DEVICE = '/api/store/device'

/** 进件管理 **/
export const API_URL_MCH_APPLYMENT_LIST = '/api/mchApplyments'

/** 支付接口定义页面 **/
export const API_URL_IFDEFINES_LIST = '/api/payIfDefines'

/** 商户配置 **/
export const API_URL_MCH_CONFIG = '/api/mchConfig'

/** 兼容组件包  **/
export const API_URL_MCH_LIST = '/api/mchInfo'


export const API_URL_MCH_TERMINAL = '/api/mchTerminals'

/** 统计接口 **/
export const API_URL_STATISTIC = '/api/statistic'

/** 公告*/
export const API_URL_NOTICELIST = '/api/sysArticles'

/** 广告 **/
export const API_URL_ADVERT = '/api/advert'

/** 代理商配置 **/
export const API_URL_AGENT_CONFIG = '/api/agentConfig'

export const API_URL_UPLOAD_SINGLE_FILE_URL = process.env.VITE_API_BASE_URL + '/api/ossFiles/singleFile'

export const API_URL_ISV_INFO_LIST = '/api/isvInfo/isvInfoList'

//商户资质模板信息分页查询
export const API_URL_APTITUDE = '/api/qualificationDefine/page'

//商户资质模板信息保存
export const API_URL_APTITUDE_SAVE = '/api/qualificationDefine/save'


//渠道通道配置
export const API_URL_PAY_CONFIG_ALTERNATIVE_LIST = '/api/payConfig/configAlternativeList'

export const API_MCH_PAY_DEFINESPAGE = '/api/payIfDefines/listPage'

//资金明细
export const API_MCH_ACCOUNT_CHANGE_LOG_LIST = '/api/accountChange'

//申请单接口
export const API_URL_MCH_MODIFY_APPLYMENT_LIST = '/api/mchModifyApplyment'
//申请单审核接口
export const API_URL_MCH_MODIFY_APPLYMENT_AUDIT = '/api/mchModifyApplyment/audit'
// 方案分类
export const API_URL_PACKAGE_TYPE_LIST = '/api/packageInfo/getPackageTypeList'
export const API_URL_PACKAGE_TYPE_Add = '/api/packageType/add'
export const API_URL_QUALIFICATIONDEFINE_PAGE = '/api/qualificationDefine/page'
export const API_URL_MCH_APPS = '/api/mchApps'//新增应用
export const API_URL_PACKAGE_TYPE_UPDATE = '/api/packageType/updatePackage'
export const API_URL_PACKAGE_TYPE_DEL = '/api/packageType/deletePackage'

/** 产品中心 */
export const API_URL_PRODUCT_LIST = '/api/product/getProductList' //产品列表
export const API_URL_PRODUCT_TYPE_LIST = '/api/product/getProductTypeList'//分类列表
export const API_URL_PRODUCT_DETAIL_LIST = '/api/product/getProductById'//详情
export const API_URL_PRODUCT_START_LIST = '/api/product/startProduct'//开通

export const API_URL_PACKAGE_LIST = '/api/packageInfo/getPackageList'//方案中心

export const API_URL_PACKAGE_DETAIL_LIST = '/api/packageInfo/getPackageById'//方案分类
export const API_URL_PACKAGE_ORDER = '/api/packageInfo/getPackageOder'//开通记录


export const API_MCH_APPLYMENT_REMARK = '/api/mchApplyments/remark'//商户备注修改
export const API_MCH_PAY_DEFINES = '/api/payIfDefines'//通道


//视频列表数据
export const API_URL_MCH_VIDEO_DATA_LIST = '/api/mchVideo/dataList'
export const API_MCH_PAY_SETTLE_LOG = '/api/settle'//结算记录查询



//代付
export const API_URL_PAY_TRANSFERDEFINE_LIST = '/api/transferDefine/definePage'

export const API_URL_PAY_TRANSFERDEFINE_DEL = '/api/transferDefine/define'
export const API_URL_PAY_TRANSFERDEFINE_ADD = '/api/transferDefine/define'



/** 安全发 开始 **/
//代付
//新增
export const API_URL_PAY_AQF_ADD = '/api/aqf/add'
//查询详情
export const API_URL_PAY_AQF_QUERY = '/api/aqf'
//付款账号列表
export const API_URL_PAY_AQF_LIST = '/api/aqf/getPageList'
//删除
export const API_URL_PAY_AQF_DEL = '/api/aqf/'
//修改
export const API_URL_PAY_AQF_SAVE = '/api/aqf'
//获取签约连接
export const API_URL_PAY_AQF_SIGN_URL = '/api/aqfApi/signUrl'

//安全发解约
export const API_URL_PAY_AQF_AGREEMENT_UNSIGN = '/api/aqfApi/userAgreementUnsign'
//记账本查询
export const API_URL_PAY_AQF_ACCOUNT_BOOK_QUERY = '/api/aqfApi/alipayFundAccountbookQuery'




//任务发布
//新增
export const API_URL_PAY_TASK_ADD = '/api/taskList/add'
//查询详情
export const API_URL_PAY_TASK_QUERY = '/api/taskList'
//付款账号列表
export const API_URL_PAY_TASK_LIST = '/api/taskList/getPageList'
//删除
export const API_URL_PAY_TASK_DEL = '/api/taskList/'
//修改
export const API_URL_PAY_TASK_SAVE = '/api/taskList'



/** 安全发 结束 **/

/** 上传图片/文件地址 **/
export const upload = {
  avatar: request.baseUrl + '/api/ossFiles/avatar',
  cert: request.baseUrl + '/api/ossFiles/cert',
  applyment: request.baseUrl + '/api/ossFiles/applyment',

}

const api = {
  user: '/user',
  role_list: '/role',
  service: '/service',
  permission: '/permission',
  permissionNoPager: '/permission/no-pager',
  orgTree: '/org/tree'
}

export default api

/** 导出文件地址 **/
export const exportExcelUrl = {
  payOrder: '/api/payOrder/exportExcel',
  settleOrder: '/api/settle/exportExcel',
  refundOrder: '/api/refundOrder/exportExcel',
  transferOrder: '/api/transferOrders/exportExcel',
  qrCodes: '/api/mchQrCodes/exportExcel',
  statistic: '/api/statistic/export',
}

/** 获取权限树状结构图 **/
export function $getEntTree() {
  return request.request({ url: '/api/sysEnts/showTree', method: 'GET' })
}

/** 更新用户角色信息 */
export function $uSysUserRoleRela(sysUserId, roleIdList) {
  return request.request({
    url: 'api/sysUserRoleRelas/relas/' + sysUserId,
    method: 'POST',
    data: { roleIdListStr: JSON.stringify(roleIdList) }
  })
}

export function $getRoleList(parameter) {
  return request({
    url: '/api/sysRoles',
    method: 'get',
    params: parameter
  })
}

/** 发起提现 **/
export function $withdrawalApply(parameter) {
  return request.request({
    url: '/api/cashout/sett',
    method: 'POST',
    data: parameter
  })
}

/** 查询提现费率规则 **/
export function $withdrawalFee() {
  return request.request({
    url: '/api/cashout/paywayFee',
    method: 'GET'
  })
}

/** 支付体验配置 **/
export function $payTest(appId) {
  return request.request({
    url: 'api/paytest/payways/' + appId,
    method: 'GET'
  })
}

/** 支付体验下单配置 **/
export function $payTestOrder(parameter) {
  return request.request({
    url: '/api/paytest/payOrders',
    method: 'POST',
    data: parameter
  })
}


export function $getPayAmountWeek() {
  return request.request({
    url: API_URL_MAIN_STATISTIC + '/payAmountWeek',
    method: 'GET'
  })
}

export function $getNumCount(data) {
  return request.request({
    url: API_URL_MAIN_STATISTIC + '/payDayCount',
    method: 'GET',
    params: data
  })
}

export function $getPayCount(parameter) {
  return request.request({
    url: API_URL_MAIN_STATISTIC + '/payCount',
    method: 'GET',
    params: { queryDateRange: parameter }
  })
}

export function $getPayType(parameter) {
  return request.request({
    url: API_URL_MAIN_STATISTIC + '/payTypeCount',
    method: 'GET',
    params: { queryDateRange: parameter }
  })
}

export function $getMainUserInfo() {
  return request.request({
    url: API_URL_MAIN_STATISTIC,
    method: 'GET'
  })
}

export function $getStatistics(queryDateRange, countType = '', agentNo = '') {
  return request.request({
    url: '/api/stat/index',
    method: 'GET',
    params: { queryDateRange, countType, agentNo }
  })
}

export function $updateUserPass(parameter) {
  return request.request({
    url: '/api/current/modifyPwd',
    method: 'put',
    data: parameter
  })
}

export function $getPayTrendCount(date) {
  return request.request({
    url: API_URL_MAIN_STATISTIC + '/payTrendCount',
    method: 'GET',
    params: { recentDay: date }
  })
}

export function $updateUserInfo(parameter) {
  return request.request({
    url: '/api/current/user',
    method: 'put',
    data: parameter
  })
}

export function $getUserInfo() {
  return request.request({
    url: '/api/current/user',
    method: 'get'
  })
}

/** MFA认证信息 **/
export function $getMFAInfo() {
  return request.request({
    url: '/api/current/mfaInfo',
    method: 'get'
  })
}

/** MFA认证绑定 **/
export function $mfaBind(parameter) {
  return request.request({
    url: '/api/current/mfaBind',
    method: 'put',
    data: parameter
  })
}

/** MFA认证解绑 **/
export function $mfaRelieve(parameter) {
  return request.request({
    url: '/api/current/mfaRelieve',
    method: 'put',
    data: parameter
  })
}

export function $getPasswordRules() {
  return request.request({
    url: '/api/anon/cipher/pwdRulesRegexp',
    method: 'get'
  })
}

export function $getTeamUserList(recordId, parameter) {
  return request.request({
    url: API_URL_SYS_USER_TEAM_USER_LIST + '/' + recordId,
    method: 'GET',
    params: parameter
  })
}

export function $getWithdrawalDetails(infoId) {
  return request.request({
    url: API_URL_WITHDRAWALS_RECORD_LIST + '/' + infoId,
    method: 'GET'
  })
}

/** 获取到webSocket的前缀 （ws://localhost） **/
export function $getWebSocketPrefix() {
  // 获取网站域名 +  端口号
  let domain = document.location.protocol + '//' + document.location.host

  // 判断api_base_url 是否设置
  if (process.env.VUE_APP_API_BASE_URL && process.env.VUE_APP_API_BASE_URL !== '/') {
    domain = process.env.VUE_APP_API_BASE_URL
  }

  if (domain.startsWith('https:')) {
    return 'wss://' + domain.replace('https://', '')
  } else {
    return 'ws://' + domain.replace('http://', '')
  }
}

/** 查询支付宝授权地址URL **/
export function $queryAlipayIsvsubMchAuthUrl(mchAppId) {
  return request.request({
    url: '/api/mch/payConfigs/alipayIsvsubMchAuthUrls/' + mchAppId,
    method: 'GET'
  })
}

/** 查询商户转账支出的接口 **/
export function $queryMchTransferIfCode(appId) {
  return request.request({
    url: 'api/mchTransfers/ifCodes/' + appId,
    method: 'GET'
  })
}

/** 获取渠道用户ID二维码地址 **/
export function $getChannelUserQrImgUrl(ifCode, appId, extParam) {
  return request.request({
    url: '/api/mchTransfers/channelUserId',
    method: 'GET',
    params: { ifCode, appId, extParam }
  })
}

/** 转账 **/
export function $doTransfer(parameter) {
  return request.request({
    url: '/api/mchTransfers/doTransfer',
    method: 'POST',
    data: parameter
  }, true, true, true)
}

/** 查询当前应用支持的支付接口 **/
export function $getIfCodeByAppId(appId) {
  return request.request({
    url: '/api/mch/payConfigs/ifCodes/' + appId,
    method: 'GET'
  }, true, true, true)
}

/** 退款接口 */
export function $payOrderRefund(payOrderId, refundAmount, refundReason, refundPassword) {
  return request.request({
    url: '/api/payOrder/refunds/' + payOrderId,
    method: 'POST',
    data: { refundAmount, refundReason, refundPassword: Base64.encode(refundPassword) }
  })
}

/* 查询接口配置参数 */
export function $queryInterfaceConfig(applyId, applyIdConvertMchAppId, convertMchAppIfCode) {
  return request.request({
    url: '/api/mchApplyments/interfaceConfig/' + applyId,
    method: 'get',
    params: { applyIdConvertMchAppId, convertMchAppIfCode } // applyId 转换为 商户应用ID
  })
}

/* 配置 */
export function $configInterfaceConfig(applyId, mchAppId, configType, configVal, appConfigModeAndIfCode) {
  return request.request({
    url: '/api/mchApplyments/interfaceConfig/' + applyId + '/' + mchAppId,
    method: 'post',
    data: { configType, configVal, appConfigModeAndIfCode }
  })
}

/* 获取请求参数 */
export function $applymentAppConfig(applyId, mchAppId) {
  return request.request({
    url: '/api/mchApplyments/appConfig/' + applyId + '/' + mchAppId,
    method: 'post',
  })
}

/** 获取公众号授权信息接口 */
export function $getWxmpInfo() {
  return request.request({
    url: '/api/wxmp/getWxmpInfo',
    method: 'GET'
  })
}

/* 配置 */
export function $qrcShellView(styleCode, configModel) {
  return request.request({
    url: '/api/mchQrcShells/view',
    method: 'post',
    data: {
      configModelStr: JSON.stringify(configModel),
      styleCode: styleCode
    }
  })
}

/** 测试云喇叭播报接口 */
export function $speakTest(deviceId, amount) {
  return request.request({
    url: '/api/store/device/speak/' + deviceId,
    method: 'POST',
    data: { amount }
  })
}

/** 测试云打印接口 */
export function $printTest(deviceId, amount) {
  return request.request({
    url: '/api/store/device/print/' + deviceId,
    method: 'POST',
    data: { amount }
  })
}

/** 清空打印队列接口 */
export function $clearPrint(deviceId) {
  return request.request({
    url: '/api/store/device/clear/' + deviceId,
    method: 'POST'
  })
}


/* 查询进件接口的最新状态 */
export function $getMchApplymentChannelState(applyId) {
  return request.request({
    url: '/api/mchApplyments/channelState/' + applyId,
    method: 'get'
  })
}

/* 获取合并的进件信息（智能读取） */
export function $getMergeApplyDetailInfos(mchNo, fixApplyId, currentPageIfCode) {
  return request.request({
    url: '/api/mchApplyments/mergeApplyDetailInfos/' + mchNo,
    method: 'get',
    params: { fixApplyId, currentPageIfCode }
  })
}


/* 二维码下载 */
export function $qrcShellViewByQrc(qrcId) {
  return request.request({
    url: '/api/mchQrcShells/viewByQrc/' + qrcId,
    method: 'get',
  })
}


/* 获取请求参数 */
export function $getUploadFormParams(file, bizType) {
  return request.request({
    url: '/api/ossFiles/form',
    method: 'post',
    data: { bizType: bizType, sourceFileName: file.name, sourceFileSize: file.size }
  })
}


/* orc识别 */
export function $orcScan(imgUrl, type) {
  return request.request({
    url: '/api/imgInfo/detail/',
    method: 'post',
    data: { imgUrl, type }
  })
}

/** 导出功能 **/
export function $exportExcel(url, params) {
  return request.exportExcel(url, params)
}

/* 支付订单数据统计 */
export function $payOrderCount(parameter) {
  return request.request({
    url: '/api/payOrder/count',
    method: 'get',
    params: parameter
  })
}

/* 退款订单数据统计 */
export function $refundOrderCount (parameter) {
  return request.request({
    url: '/api/refundOrder/count',
    method: 'get',
    params: parameter
  })
}

/** 分账重试 */
export function $resendDivision(recordId) {
  return request.request({
    url: '/api/division/records/resend/' + recordId,
    method: 'POST'
  })
}


// 更新商户级别
export function $updateMchLevel(mchLevel) {
  return request.request({
    url: '/api/mchConfig/mchLevel',
    method: 'PUT',
    data: { mchLevel }
  })
}

/** 查询网站配置信息 */
export function $getSiteInfos() {
  return request.request({
    url: '/api/anon/siteInfos',
    method: 'GET',
    params: { queryConfig: 1 }
  })
}


/** 预先检查 */
export function $applyPreCheck(mchNo, ifCode, isvNo) {
  return request.request({
    url: '/api/mchApplyments/applyPreCheck/' + mchNo + '/' + ifCode,
    method: 'GET',
    params: {isvNo: isvNo}
  })
}

/** 查询地图配置 */
export function $getMapConfig() {
  return request.request({
    url: '/api/mchStore/mapConfig',
    method: 'get'
  })
}


/* 查询合同信息 */
export function $getMchApplymentChannelSignInfo(applyId) {
  return request.request({
    url: '/api/mchApplyments/channelSignInfo/' + applyId,
    method: 'get'
  })
}

/* 合同信息(重签等) */
export function $getMchApplyReSign (applyId, extSignInfo) {
  return request.request({
    url: '/api/mchApplyments/channelSignInfo/' + applyId,
    method: 'get',
    params: { extSignInfo }
  })
}

/* 开户意愿查询 */
export function $getMchApplymentWxOpenInfo(applyId) {
  return request.request({
    url: '/api/mchApplyments/channelWxOpenInfo/' + applyId,
    method: 'get'
  })
}

/* 开户意愿查询*/
export function $getMchApplymentAlipayOpenInfo(applyId) {
  return request.request({
    url: '/api/mchApplyments/channelAlipayOpenInfo/' + applyId,
    method: 'get'
  })
}


/** 费率配置： 获取全部接口 */
export function $getRateConfigIfcodes(infoId, configMode, ifName) {
  return request.request({
    url: '/api/rateConfig/ifCodes',
    params: { infoId, configMode, ifName },
    method: 'GET'
  })
}


/** 拓展员商户统计数据 */
export function $userChart(sysUserId, queryDateRange) {
  return request.request({
    url: '/api/stat/userChart',
    method: 'GET',
    params: { sysUserId, queryDateRange },
  })
}


// -- 支付接口参数 & 费率配置组件 接口 --

/** 费率配置： 获取全部接口 */
export function $getPayConfigIfcodes(infoId, configMode, ifName) {
  return request.request({
    url: '/api/payConfig/ifCodes',
    params: { infoId, configMode, ifName },
    method: 'GET'
  })
}

/**查询商户应用支付参数、费率是否配置 */
export function $getMchPayParamsExist (infoId, ifCode) {
  return request.request({
    url: '/api/payConfig/existPayParams/' + infoId + '/' + ifCode,
    method: 'get'
  })
}

/**查询某一进件记录下，商户应用支付通道是否已配置 */
export function $getMchPayPassageExist (applyId, appId) {
  return request.request({
    url: '/api/mch/payPassages/exist/' + applyId + '/' + appId,
    method: 'get'
  })
}

/** 进件成功，一键配置应用支付信息 */
export function $autoConfigMchPayInfo (applyId, appId, data) {
  return request.request({
    url: '/api/mch/payPassages/applyment/' + applyId + '/' + appId,
    method: 'post',
    data: data
  })
}

/**查询已经配置的参数  */
export function $getInterfaceSavedConfigs(infoId, ifCode, configMode, qcreals = 0) {
  return request.request({
    url: '/api/payConfig/interfaceSavedConfigs',
    method: 'get',
    params: { infoId, ifCode, configMode }
  })
}

/**更新支付参数配置的参数  */
export function $saveInterfaceParams(data) {
  return request.request({
    url: '/api/payConfig/interfaceParams',
    method: 'post',
    data: data
  })
}

/** 费率配置：获取 支付方式 */
export function $getRateConfigPayways(infoId, configMode, ifCode, range = 0, mccCode = '', isvNo = '', appId = '') {
  return request.request({
    url: '/api/rateConfig/payways',
    params: {infoId, configMode, ifCode, range, mccCode, isvNo, appId},
    method: 'GET'
  })
}

/** 费率配置：获取 支付方式 */
export function $getRateConfigSavedMapData(infoId, configMode, ifCode, range = 0, mccCode = '', isvNo = '', appId = '') {
  return request.request({
    url: '/api/rateConfig/savedMapData',
    params: {infoId, configMode, ifCode, range, mccCode, isvNo, appId},
    method: 'GET'
  })
}

/** 费率配置： 保存 */
export function $saveRateConfig(reqData) {
  return request.request({
    url: '/api/rateConfig',
    data: reqData,
    method: 'POST'
  })
}


/** 商户支付通道配置 （ 左侧列表  ）  **/
// export const API_URL_MCH_PAYPASSAGE_LIST = '/api/mch/payPassages'


/** 商户通道选中： 右侧列表 */
export function $getAvailablePayInterfaceList(mchNo, wayCode) {
  return request.request({
    url: '/api/mch/payPassages/availablePayInterface/' + mchNo + '/' + wayCode,
    method: 'GET'
  })
}


/** 更新商户的通道状态 */
export function $updateMchPassageState(appId, wayCode, ifCode, state) {
  return request.request({
    url: '/api/mch/payPassages/mchPassage',
    method: 'POST',
    params: { appId, wayCode, ifCode, state },
  })
}

/** 绑定码牌 */
export function $bindQrc(recordId, bindObject) {
  return request.request({
    url: '/api/mchQrCodes/bind/' + recordId,
    data: bindObject,
    method: 'PUT'
  })
}

/** 解绑码牌 */
export function $unbindQrc(recordId) {
  return request.request({
    url: '/api/mchQrCodes/unbind/' + recordId,
    method: 'POST'
  })
}

/** 划拨码牌 */
export function $allotQrc(allotObject) {
  return request.request({
    url: '/api/mchQrCodes/allotQrc',
    data: allotObject,
    method: 'POST'
  })
}

/** 码牌受支持设备列表 */
export function $bindDeviceList(recordId, params) {
  return request.request({
    url: '/api/mchQrCodes/bindDevice/' + recordId,
    data: params,
    method: 'GET'
  })
}

/** 绑定设备 */
export function $bindDevice(recordId, bindObject) {
  return request.request({
    url: '/api/store/device/bind/' + recordId,
    data: bindObject,
    method: 'PUT'
  })
}

/** 解绑设备 */
export function $unbindDevice(recordId) {
  return request.request({
    url: '/api/store/device/unbind/' + recordId,
    method: 'POST'
  })
}

/** 划拨设备 */
export function $allotDevice(allotObject) {
  return request.request({
    url: '/api/store/device/allotDevice',
    data: allotObject,
    method: 'POST'
  })
}

/** 收付通进件  动态获取银行支行列表 */
export function $bankBranchList(mchNo, ifCode, params,isvNo='') {
  return request.request({
    url: '/api/mchApplyments/bankList/' + mchNo + '/' + ifCode + '/' +isvNo,
    params: params,
    method: 'GET'
  })
}

// -- 支付接口参数 & 费率配置组件 接口 --


/** 更新默认设备 */
export function $updateMchTermDefault(trmId, defaultFlag) {
  return request.request({
    url: '/api/mchTerminals/trmDefaults',
    data: { trmId, defaultFlag },
    method: 'PUT'
  })
}

/** 报备信息集合 */
export function $getMchTermChannelBindInfos(trmId) {
  return request.request({
    url: '/api/mchTerminals/channelBindInfos/' + trmId,
    method: 'GET'
  })
}

/** 接口报备 */
export function $mchTermChannelSendup(trmId, ifCode, state) {
  return request.request({
    url: '/api/mchTerminals/channelSendup/' + trmId,
    data: { ifCode, state },
    method: 'POST'
  })
}


/** 更新信息 */
export function $updMchTermChannelBindInfos(trmId, data) {
  return request.request({
    url: '/api/mchTerminals/channelBindInfos/' + trmId,
    data: data,
    method: 'POST'
  })
}

/* 富友电子协议生成 */
export function $elecContractGenerate(applyId) {
  return request.request({
    url: '/api/mchApplyments/elecContractGenerate/' + applyId,
    method: 'post'
  })
}

/* 富友电子协议签署 */
export function $elecContractSign(applyId) {
  return request.request({
    url: '/api/mchApplyments/elecContractSign/' + applyId,
    method: 'post'
  })
}

/* 富友  上传图片 */
export function $fuiouUpload(applyId) {
  return request.request({
    url: '/api/mchApplyments/fuiouUpload/' + applyId,
    method: 'post'
  })
}

/* 富友  提交审核 */
export function $fuiouConfirm(applyId) {
  return request.request({
    url: '/api/mchApplyments/fuiouConfirm/' + applyId,
    method: 'post'
  })
}

/* 富友微信参数配置 */
export function $fuiouWxSet(applyId, data) {
  return request.request({
    url: '/api/mchApplyments/fuiouWxConfigSet/' + applyId,
    method: 'post',
    data: data,
  })
}

/* 富友微信参数查询 */
export function $fuiouWxGet(applyId) {
  return request.request({
    url: '/api/mchApplyments/fuiouWxConfigGet/' + applyId,
    method: 'post'
  })
}

/* 应用： 查询系统公钥 */
export function $getSysRSA2PublicKey() {
  return request.request({
    url: '/api/mchApps/sysRSA2PublicKey',
    method: 'GET'
  })
}

/** 解除登录限制 **/
export function $deleteLoginLimit(recordId) {
  return request.request({
    url: '/api/sysUsers/loginLimit/' + recordId,
    method: 'delete'
  })
}

// 更新支付密码
export function $updateAgentSipw(originalPwd, confirmPwd) {
  return request.request({
    url: '/api/agentConfig/agentSipw',
    method: 'PUT',
    data: { originalPwd: Base64.encode(originalPwd), confirmPwd: Base64.encode(confirmPwd) }
  })
}

/* 斗拱分账配置 */
export function $dgpayConfigOpen (applyId, reqParams) {
  return request.request({
    url: '/api/mchApplyments/dgpayConfigOpen/' + applyId,
    data: reqParams,
    method: 'post'
  })
}

/* 斗拱分账配置查询 */
export function $dgpayConfigOpenQuery (applyId) {
  return request.request({
    url: '/api/mchApplyments/dgpayConfigOpenQuery/' + applyId,
    method: 'get'
  })
}

/* 乐刷业务开通 */
export function $leshuapayConfigOpen (applyId, reqParams) {
  return request.request({
    url: '/api/mchApplyments/leshuapayConfigOpen/' + applyId,
    data: reqParams,
    method: 'post'
  })
}

/* 斗拱微信参数配置 */
export function $dgWxSet(applyId, data) {
  return request.request({
    url: '/api/mchApplyments/dgWxConfigSet/' + applyId,
    method: 'post',
    data: data,
  })
}

/* 斗拱微信实名认证 */
export function $dgpayWxRealName(applyId, reqParams) {
  return request.request({
    url: '/api/mchApplyments/dgpayWxRealName/' + applyId,
    data: reqParams,
    method: 'post'
  })
}

/* 获取请求参数 */
export function $lklApplymentAppConfig(applyId, mchAppId, reqParams) {
  return request.request({
    url: '/api/mchApplyments/lklAppConfig/' + applyId + '/' + mchAppId,
    data: reqParams,
    method: 'post',
  })
}

/* 获取终端记过参数 */
export function $sqbActivationConfig(reqParams) {
  return request.request({
    url: '/api/mchConfig/activation',
    data: reqParams,
    method: 'post',
  })
}

/* 银联前置  新增支付类型 */
export function $payConfAdd(applyId, reqParams) {
  return request.request({
    url: '/api/mchApplyments/payConf/' + applyId,
    data: reqParams,
    method: 'post'
  })
}

/* 银联前置  查询第三方交易识别码 */
export function $getMchPartner (applyId, mchAppId, appConfigModeAndIfCode) {
  return request.request({
    url: '/api/mchApplyments/mchPartner/' + applyId + '/' + mchAppId,
    method: 'post',
    data: { appConfigModeAndIfCode }
  })
}

/* 快钱 发起合同签约 */
export function $kqSignApply(applyId, params) {
  return request.request({
    url: '/api/mchApplyments/kqSignApply/' + applyId,
    data: params,
    method: 'post'
  })
}

/* 银盛  上传图片 */
export function $yspayUpload(applyId, reqParams) {
  return request.request({
    url: '/api/mchApplyments/yspayUpload/' + applyId,
    data: reqParams,
    method: 'post'
  })
}

/* 银盛  资料确认 */
export function $yspayConfirm (applyId, reqParams) {
  return request.request({
    url: '/api/mchApplyments/yspayConfirm/' + applyId,
    data: reqParams,
    method: 'post'
  })
}

/* 银盛  签约通知重发 */
export function $ysSignSendAgain (applyId) {
  return request.request({
    url: '/api/mchApplyments/ysSignSendAgain/' + applyId,
    method: 'post'
  })
}

/* 银盛  发起合同签约 */
export function $ysSignApply (applyId, params) {
  return request.request({
    url: '/api/mchApplyments/ysSignApply/' + applyId,
    method: 'post',
    data: params
  })
}

/* 银盛  签约结果查询 */
export function $ysSignQuery (applyId) {
  return request.request({
    url: '/api/mchApplyments/ysSignQuery/' + applyId,
    method: 'post'
  })
}

/* 银盛  新增支付类型 */
export function $ysPayRateConfig(applyId, reqParams) {
  return request.request({
    url: '/api/mchApplyments/ysPayRateConfig/' + applyId,
    data: reqParams,
    method: 'post'
  })
}

/* 银盛微信配置 */
export function $yspayConfigInterfaceConfig(applyId, mchAppId, configType, configVal) {
  return request.request({
    url: '/api/mchApplyments/yspayInterfaceConfig/' + applyId + '/' + mchAppId,
    method: 'post',
    data: { configType, configVal }
  })
}

/* 拉卡拉saas支行列表 */
export function $lklGetBankList(areaCode, branchName) {
  return request.request({
    url: '/api/mchApplyments/getLklBankList/' + areaCode + '/' + branchName,
    method: 'get'
  })
}

export function $auditInfo(parameter) {
  return request.request({
    url: API_URL_SYS_USER_LIST + '/audit',
    method: 'put',
    data: parameter
  })
}

/* 瑞银信获取银行开户支行信息列表 */
export function $ruipayGetBankList(ifCode, headBankNo, mchNo, queryData) {
  return request.request({
    url: '/api/mchApplyments/bankCode/' + ifCode,
    method: 'get',
    params: { headBankNo, mchNo, queryData },
  })
}
// 验证是否有密码
export function $isSipw() {
  return request.request({
    url: '/api/agentConfig/hasSipwValidate',
    method: 'get'
  })
}

/* 星驿付获取银行开户支行信息列表 */
export function $terpayGetBankList (ifCode, queryBankData) {
  return request.request({
    url: '/api/mchApplyments/bankCode/' + ifCode,
    method: 'get',
    params: queryBankData,
  })
}


/* 星驿付发送短信验证码 */
export function $terpayAnSignMsg (ifCode, mchNo, applyId, terpayApplymjsonStrentInfo) {
  return request.request({
    url: '/api/mchApplyments/iApplyRes/sendPubRequst/' + ifCode,
    method: 'post',
    data: { mchNo, applyId, jsonStr: JSON.stringify(terpayApplymjsonStrentInfo) }
  })
}

/**查询已经配置的oauth2参数 */
export function $getOauth2SavedConfigs (infoId, ifCode, configMode) {
  return request.request({
    url: '/api/payOauth2Config/savedConfigs',
    method: 'get',
    params: { infoId, ifCode, configMode }
  })
}

/**更新oauth2配置的参数 */
export function $saveOauth2ConfigParams (data) {
  return request.request({
    url: '/api/payOauth2Config/configParams',
    method: 'post',
    data: data
  })
}

// 隐私政策与服务协议
export function $getTreaty () {
  return request.request({
    url: '/api/anon/treaty',
    method: 'GET'
  })
}


/** 查询出diy列表  */
export function $getOauth2DiyList (infoId, configMode) {
  return request.request({
    url: '/api/payOauth2Config/diyList',
    method: 'get',
    params: { infoId, configMode }
  })
}

/** 新增 diy列表  */
export function $addOauth2DiyList (infoId, configMode, remark, copySourceInfoId) {
  return request.request({
    url: '/api/payOauth2Config/diyList',
    method: 'POST',
    data: { infoId, configMode, remark }
  })
}

/** 获取App下载链接*/
export  function  $getAppDownloadUrl (){
  return  request.request({
    url:'/api/anon/clientVersion/downloadUrl',
    method:'GET'
  })
}

/** 批量删除广告 */
export function $batchDelAdvert(advertIds) {
  return request.request({
    url: '/api/advert',
    data: { delAdvertIds : advertIds },
    method: 'DELETE'
  })
}

/** 支付宝安全发授权 **/
export function $alipayAgreementPageSign (mchAppId) {
  return request.request({
    url: '/api/mch/payConfigs/alipayAgreementPageSign/' + mchAppId,
    method: 'GET'
  })
}

/** 查询支付宝安全发授权结果 **/
export function $queryUserAgreementPageSign (mchAppId) {
  return request.request({
    url: '/api/mch/payConfigs/queryUserAgreementPageSign/' + mchAppId,
    method: 'GET'
  })
}

/* 进件api */
export function $applymentNextBiz (applyId, parameter) {
  return request.request({
    url: '/api/mchApplyments/applymentNextBiz/' + applyId,
    method: 'post',
    data: parameter
  })
}

/* 提现数据统计 */
export function $cashoutCount (parameter) {
  return request.request({
    url: '/api/cashout/count',
    method: 'get',
    params: parameter
  })
}

/** 服务商渠道参数配置*/
export function $getIsvChannelConfig (mchNo, ifCode, isvNo) {
  return request.request({
    url: '/api/mchApplyments/getIsvChannelConfig/' + mchNo + '/' + ifCode + "/" + isvNo,
    method: 'GET'
  })
}

/* 河马付后续流程 */
export function $hmpayAfterOperate (ifCode, mchNo, applyId, operationType, hmApplyData) {
  return request.request({
    url: '/api/mchApplyments/iApplyRes/sendPubRequst/' + ifCode,
    method: 'post',
    data: { mchNo: mchNo, applyId: applyId, operationType: operationType, jsonStr: JSON.stringify(hmApplyData) }
  })
}

/* 门店入驻申请 */
export function $applymentStore (storeId, state, applyId, params) {
  return request.request({
    url: '/api/mchApplyments/storeApplyment/' + storeId + '/' + state + '/' + applyId,
    method: 'post',
    data: { applyId, state, storeId, params }
  })
}

/* 河马查询商户门店信息 */
export function $hmpayQueryStoreInfo (applyId) {
  return request.request({
    url: '/api/mchApplyments/storeApplyment/' + applyId,
    method: 'get'
  })
}

/** 代理商配置 */
export function $getAgentConfig(configKey) {
  return request.request({
    url: API_URL_AGENT_CONFIG + '/' + configKey,
    method: 'GET'
  })
}

/** 支付宝直付通商户作废接口 */
export function $zftMchDelete(appId, smId) {
  return request.request({
    url: API_URL_MCH_APPLYMENT_LIST + '/zftMchDelete/' + appId + '/' + smId,
    method: 'POST'
  })
}

export function $addMchOauth2Config(data) {
  return request.request({
    url: '/api/mchApplyments/addConfig',
    method: 'POST',
    data: data
  })
}

export function $getMchOauth2Config(mchNo) {
  return request.request({
    url: 'api/mchApplyments/getConfig?mchNo='+mchNo,
    method: 'GET'
  })
}

//渠道下指定通道参数配置
export function $getPayConfigChosenConfigAlternative(data) {
  return request.request({
    url: '/api/payConfig/chosenConfigAlternative',
    method: 'post',
    data: data
  })
}

//保存通道参数配置实例
export function $getPaySaveConfigAlternative(data) {
  return request.request({
    url: '/api/payConfig/saveConfigAlternative',
    method: 'post',
    data: data
  })
}

//设置默认isv
export function $getMchInfoIsv(data) {
  return request.request({
    url: '/api/mchInfo/defIsv',
    method: 'post',
    data
  })
}

//新增关联渠道
export function $getIsvInfoConn(data) {
  return request.request({
    url: '/api/isvInfo/isvConn',
    method: 'post',
    data: data
  })
}
export function $getMerchantInformation(mchApplyId, modifyApplyType) {
  return request.request({
    url: '/api/mchApplyments/modifyApplyment?mchApplyId=' + mchApplyId + "&modifyApplyType=" + modifyApplyType,
    method: 'GET'
  })
}

//商户进件信息变更
export function $getMchIncomingRefresh($data) {
  return request.request({
    url: '/api/mchApplyments/modifyApplyment',
    method: 'POST',
    data: $data
  })
}
export function $getMchAutoBindIsvConn(data) {
  return request.request({
    url: '/api/isvInfo/autoBindIsvConn',
    method: 'post',
    data
  })
}

//进件获取结算类型
export function $getSettType(yspay,infoId) {
  return request.request({
    url:'/api/isvInfo/getSettType?ifCode='+yspay+'&infoId='+infoId,
    method: 'get',
  })
}
//商户进件信息详情变更回显
export function $getMerchantChangeModifyApply(data) {
  return request.request({
    url: '/api/mchApplyments/modifyApplyment?'+data,
    method: 'GET'
  })
}
//配置列表
export function $getMchConfigConfig(data) {
  return request.request({
    url: 'api/mchConfig/config',
    method: 'post',
    data
  })
}

//进件状态标记
export function $getMchApplymentsState(data) {
  return request.request({
    url: 'api/mchApplyments/state',
    method: 'post',
    data
  })
}
export function $getMchApplymentsScanPayFlag(data) {
  return request.request({
    url: '/api/mchApplyments/scanPayFlag',
    method: 'post',
    data
  })
}

/* 结算订单数据统计 */
export function $settleOrderCount(parameter) {
  return request.request({
    url: '/api/settle/count',
    method: 'get',
    params: parameter
  })
}


//同步结算状态
export function $getSettTypeSync(Id) {
  return request.request({
    url:'/api/settle/sync/'+Id,
    method: 'get',
  })
}

//更新订单
export function $getPayOrderRefresh(ordeSn) {
  return request.request({
    url: 'api/payOrder/refresh/'+ordeSn,
    method: 'POST'
  })
}

//商户变更状态刷新
export function $getMchApplymentsModifyApplyId(modifyApplyId) {
  return request.request({
    url: '/api/mchModifyApplyment/result/'+modifyApplyId,
    method: 'get',
  })
}


//创建授权任务
export function $getMchSphVideoTask(data) {
  return request.request({
    url: '/api/mchVideo/authTask',
    method: 'post',
    data,
  })
}

//查询授权任务状态
export function $getMchSphVideoAuthTask(taskId) {
  return request.request({
    url: '/api/mchVideo/authTask?taskId='+taskId,
    method: 'get',
  })
}
//视频号数据标记
export function $getMchChoiceFlag(id,data) {
  return request.request({
    url: '/api/mchVideo/choiceFlag/'+id,
    method: 'post',
    data,
  })
}

/** 视频号数据删除 **/
export function $deleteMchVideo(videoId) {
  return request.request({
    url: '/api/mchVideo/' + videoId,
    method: 'delete'
  })
}

//服务商修改渠道关联关系
export function $getMchIsvEditStatus(data) {
  return request.request({
    url: '/api/isvInfo/editStatus',
    method: 'post',
    data
  })
}

/* 配置 */
export function $getWaitOperationNumber(data={}) {
  return request.request({
    url: '/api/mainChart/getWaitOperationNumber',
    method: 'GET',
    data,
  })
}
/**更新代付参数配置的参数 */
export function $getAqfApisignUrl(subId) {
  return request.request({
    url: '/api/aqfApi/signUrl?infoId=V1698312342&subId='+subId,
    method: 'GET'
  })
}

/**获取代付参数配置的参数 */
export function $getPayTransferDefineDefinePage(infoId, configMode, ifName) {
  return request.request({
    url: '/api/transferDefine/definePage',
    params: {infoId, configMode, ifName},
    method: 'GET'
  })
}
/**获取代付参数配置的参数 */
export function $getTransferDefineInstanceCode(code) {
  return request.request({
    url: '/api/transferDefine/instance/code/'+code,
    method: 'get',
  })
}
/**更新代付参数配置的参数 */
export function $saveTransferDefineInstance(data) {
  return request.request({
    url: '/api/transferDefine/instance',
    method: 'post',
    data: data
  })
}

/**获取代付参数配置的参数 */
export function $getPayTransferConfigIfCodePage(infoId, configMode, ifName) {
  return request.request({
      url: '/api/transferConfig/ifCodes',
      params: {infoId, configMode, ifName},
      method: 'GET'
  })
}

//费率数据集合数据
export function $getRateConfigTateInfoDetail(isvNo, ifCode, infoId, infoType) {
  return request.request({
      url: '/api/rateConfig/rateInfoDetail?isvNo=' + isvNo + '&ifCode=' + ifCode + '&infoType=' + infoType + '&infoId=' + infoId,
      method: 'GET',
  })
}

//新版费率配置接口
export function $savetRateConfigResetV2(data) {
  return request.request({
      url: '/api/rateConfig/resetV2',
      method: 'POST',
      data
  })
}
//业务变更状态刷新
export function $getMchModifyApplyments(modifyApplyId) {
  return request.request({
    url: '/api/mchModifyApplyment/'+modifyApplyId,
    method: 'get',
  })
}