Files
uniapp_ycc/src/api/agent.js
2026-02-11 15:16:52 +08:00

165 lines
4.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import useApiFetch from '@/composables/useApiFetch'
function buildQueryString(params) {
const parts = []
Object.keys(params || {}).forEach((key) => {
const v = params[key]
if (v !== undefined && v !== null && v !== '')
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`)
})
const s = parts.join('&')
return s ? `?${s}` : ''
}
export function getAgentInfo() {
return useApiFetch('/agent/info').get().json()
}
export function getTeamStatistics() {
return useApiFetch('/agent/team/statistics').get().json()
}
export function getConversionRate() {
return useApiFetch('/agent/conversion/rate').get().json()
}
export function getRevenueInfo() {
return useApiFetch('/agent/revenue').get().json()
}
/**
* 我的推广收益明细(佣金列表)
* @param {object} params - { page, page_size }
*/
export function getCommissionList(params) {
return useApiFetch(`/agent/commission/list${buildQueryString(params)}`).get().json()
}
/**
* 下级推广收益明细(返佣列表)
* @param {object} params - { page, page_size, rebate_type? }
*/
export function getRebateList(params) {
return useApiFetch(`/agent/rebate/list${buildQueryString(params)}`).get().json()
}
export function getProductConfig() {
return useApiFetch('/agent/product_config').get().json()
}
/**
* 获取推广链接数据
* @param {string} linkIdentifier - 推广链接标识
*/
export function getLinkData(linkIdentifier) {
return useApiFetch(
`/agent/link?link_identifier=${encodeURIComponent(linkIdentifier)}`,
)
.get()
.json()
}
/**
* 生成推广链接
* @param {object} params - 生成参数
* @param {number} params.product_id - 产品ID
* @param {number} params.set_price - 设定价格
* @param {string} [params.target_path] - 目标路径模板(如 /agent/promotionInquire/
*/
export function generateLink(params) {
return useApiFetch('/agent/generating_link').post(params).json()
}
export function getTeamList(params) {
return useApiFetch(`/agent/team/list${buildQueryString(params)}`).get().json()
}
/**
* 获取下级贡献详情(订单/邀请列表)
* @param {object} params - { subordinate_id, page, page_size, tab_type: 'order'|'invite' }
*/
export function getSubordinateContributionDetail(params) {
return useApiFetch(`/agent/subordinate/contribution/detail${buildQueryString(params)}`).get().json()
}
export function getSubordinateList(params) {
return useApiFetch(`/agent/subordinate/list${buildQueryString(params)}`).get().json()
}
export function applyForAgent(params) {
return useApiFetch('/agent/apply').post(params).json()
}
export function registerByInviteCode(params) {
return useApiFetch('/agent/register/invite').post(params).json()
}
export function applyWithdrawal(params) {
return useApiFetch('/agent/withdrawal/apply').post(params).json()
}
export function getWithdrawalList(params) {
return useApiFetch(`/agent/withdrawal/list${buildQueryString(params)}`).get().json()
}
export function realNameAuth(params) {
return useApiFetch('/agent/real_name').post(params).json()
}
export function generateInviteCode(params) {
return useApiFetch('/agent/invite_code/generate').post(params).json()
}
export function getInviteCodeList(params) {
return useApiFetch(`/agent/invite_code/list${buildQueryString(params)}`).get().json()
}
/**
* 删除邀请码
* @param {object} params - { id: 邀请码ID }
*/
export function deleteInviteCode(params) {
return useApiFetch('/agent/invite_code/delete').post(params).json()
}
/**
* 获取邀请链接(短链)
* @param {object} params - { invite_code: 邀请码, target_path?: 目标路径 }
*/
export function getInviteLink(params) {
const queryString = buildQueryString(params || {})
return useApiFetch(`/agent/invite_link${queryString}`).get().json()
}
/**
* 生成邀请海报(带二维码的图片)
* @param {object} params - { invite_link: 邀请链接 }
*/
export function generateInvitePoster(params) {
const queryString = buildQueryString(params || {})
return useApiFetch(`/agent/invite/poster${queryString}`).get().json()
}
/**
* 推广查询记录列表(代理推广产生的订单/报告)
* @param {object} params - { page, page_size }
*/
export function getPromotionQueryList(params) {
return useApiFetch(`/agent/promotion/query/list${buildQueryString(params)}`).get().json()
}
/**
* 获取等级权益与升级费用
*/
export function getLevelPrivilege() {
return useApiFetch('/agent/level/privilege').get().json()
}
export function applyUpgrade(params) {
return useApiFetch('/agent/upgrade/apply').post(params).json()
}
export function upgradeSubordinate(params) {
return useApiFetch('/agent/upgrade/subordinate').post(params).json()
}