HomeLease/api/user/user.js

228 lines
5.1 KiB
JavaScript
Raw Normal View History

2025-08-19 11:54:07 +08:00
import request from '@/utils/request'
import { uploadFile } from '@/utils/request.js'
2025-09-12 15:17:47 +08:00
import { exp } from 'qrcode/lib/core/galois-field'
2025-08-19 11:54:07 +08:00
/**
* 获取用户信息
* @returns {Promise} 返回用户信息
*/
export function getUserInfo() {
return request({
url: '/app/user/getUser',
method: 'GET',
showLoading: false,
})
2025-08-22 16:51:58 +08:00
.then(response => {
// 如果API调用成功将用户ID存入本地存储
if (response.code === 200 && response.data && response.data.userId) {
uni.setStorageSync('userId', response.data.userId)
console.log('用户ID已存入本地存储:', response.data.userId)
}
return response
})
.catch(error => {
console.warn('用户信息API调用失败:', error)
return null
2025-08-22 16:51:58 +08:00
})
2025-08-19 11:54:07 +08:00
}
/**
* 获取用户财务数据
* @returns {Promise} 返回财务数据
*/
export function getUserFinancialData() {
return request({
url: '/app/user/getBill',
2025-08-19 11:54:07 +08:00
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('财务数据API调用失败:', error)
return null
2025-08-19 11:54:07 +08:00
})
}
/**
* 获取用户统计信息
* @returns {Promise} 返回用户统计信息
*/
export function getUserStats() {
return request({
url: '/app/user/stats',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('用户统计API调用失败:', error)
return null
2025-08-19 12:01:17 +08:00
})
}
/**
* 获取代理统计数据
* @returns {Promise} 返回代理统计信息
*/
export function getAgentCount() {
return request({
url: '/app/order/agentCount',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('代理统计API调用失败:', error)
return null
2025-08-19 12:01:17 +08:00
})
}
/**
2025-08-19 14:01:32 +08:00
* 获取代理用户列表
2025-08-19 12:01:17 +08:00
* @param {Object} params - 查询参数
2025-08-19 14:01:32 +08:00
* @param {string} params.beginTime - 开始时间
2025-08-22 16:51:58 +08:00
* @param {string} params.endTime - 结束时间
2025-08-19 14:01:32 +08:00
* @param {string} params.name - 用户昵称搜索
* @returns {Promise}
2025-08-19 12:01:17 +08:00
*/
2025-08-19 14:01:32 +08:00
export function getAgentList(params = {}) {
2025-08-19 12:01:17 +08:00
return request({
2025-08-19 14:01:32 +08:00
url: '/app/order/agentList',
2025-08-19 12:01:17 +08:00
method: 'GET',
params,
showLoading: false,
}).catch(error => {
console.warn('代理用户列表API调用失败:', error)
return null
2025-08-19 11:54:07 +08:00
})
}
2025-08-19 14:01:32 +08:00
/**
* 获取用户列表 (使用代理列表接口)
* @param {Object} params - 查询参数
* @returns {Promise}
*/
export function getUserList(params = {}) {
return getAgentList(params)
}
2025-08-19 11:54:07 +08:00
/**
* 更新用户信息
* @param {Object} data - 用户信息数据
* @returns {Promise} 返回更新结果
*/
export function updateUserInfo(data) {
return request({
url: '/app/user/update',
method: 'POST',
data,
})
}
2025-08-20 10:03:06 +08:00
/**
* 更新用户昵称
* @param {string} nickName - 新的昵称
* @returns {Promise} 返回更新结果
*/
export function updateNickName(nickName) {
return request({
url: '/app/user/updateNickName',
method: 'PUT',
params: { nickName },
showLoading: true,
// 强制将params作为查询参数发送
useQueryParams: true,
2025-08-20 10:03:06 +08:00
}).catch(error => {
console.warn('更新昵称API调用失败:', error)
throw error
})
}
2025-08-19 14:22:25 +08:00
/**
* 获取提现信息
* @returns {Promise} 返回提现相关信息
*/
export function getWithdrawInfo() {
return request({
url: '/app/withdraw',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('提现信息API调用失败使用模拟数据:', error)
return createMockResponse(mockWithdrawInfo)
})
}
2025-08-22 16:51:58 +08:00
/**
* 获取服务费用明细
* @returns {Promise} 返回服务费用明细
*/
2025-08-25 10:11:25 +08:00
export function computedServiceAmount(amount) {
2025-08-22 16:51:58 +08:00
return request({
url: '/app/withdraw/serviceAmount',
method: 'GET',
showLoading: false,
2025-08-25 10:11:25 +08:00
params: { amount },
2025-08-22 16:51:58 +08:00
}).catch(error => {
console.warn('服务费用API调用失败:', error)
return null
2025-08-22 16:51:58 +08:00
})
}
2025-08-19 14:22:25 +08:00
/**
* 提交提现申请
* @param {Object} data 提现数据
* @param {number} data.amount 提现金额
2025-08-25 11:40:20 +08:00
* @param {string} data.accountId 账号id
* @param {string} data.serviceType 服务类型
* @param {string} data.serviceCharge 服务费
* @param {string} data.arrivalAmount 实际到达金额
2025-08-19 14:22:25 +08:00
* @returns {Promise} 返回提现申请结果
*/
export function submitWithdraw(data) {
return request({
url: '/app/withdraw',
method: 'POST',
data,
showLoading: true,
}).catch(error => {
console.warn('提现申请API调用失败:', error)
throw error
})
2025-08-22 16:51:58 +08:00
}
2025-08-20 11:45:42 +08:00
/**
* 上传头像
* @param {string} avatarUrl - 文件路径
2025-08-20 11:45:42 +08:00
* @returns {Promise} 返回上传结果
*/
export function uploadAvatar(avatarUrl) {
return request({
url: '/app/user/avatar',
method: 'PUT',
data: {
avatarUrl: avatarUrl,
},
header: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
2025-08-22 16:51:58 +08:00
}
2025-08-20 16:59:06 +08:00
/**
* 获取本地存储的用户ID
* @returns {string|null} 返回用户ID如果不存在则返回null
*/
export function getLocalUserId() {
return uni.getStorageSync('userId') || null
}
/**
* 清除本地存储的用户ID
*/
export function clearLocalUserId() {
uni.removeStorageSync('userId')
console.log('本地用户ID已清除')
2025-08-22 16:51:58 +08:00
}
2025-09-12 15:17:47 +08:00
export function getIsRealName() {
return request({
url: '/app/user/isReal',
})
}