HomeLease/api/user/user.js
2025-09-15 09:25:26 +08:00

228 lines
5.1 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 request from '@/utils/request'
import { uploadFile } from '@/utils/request.js'
import { exp } from 'qrcode/lib/core/galois-field'
/**
* 获取用户信息
* @returns {Promise} 返回用户信息
*/
export function getUserInfo() {
return request({
url: '/app/user/getUser',
method: 'GET',
showLoading: false,
})
.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
})
}
/**
* 获取用户财务数据
* @returns {Promise} 返回财务数据
*/
export function getUserFinancialData() {
return request({
url: '/app/user/getBill',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('财务数据API调用失败:', error)
return null
})
}
/**
* 获取用户统计信息
* @returns {Promise} 返回用户统计信息
*/
export function getUserStats() {
return request({
url: '/app/user/stats',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('用户统计API调用失败:', error)
return null
})
}
/**
* 获取代理统计数据
* @returns {Promise} 返回代理统计信息
*/
export function getAgentCount() {
return request({
url: '/app/order/agentCount',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('代理统计API调用失败:', error)
return null
})
}
/**
* 获取代理用户列表
* @param {Object} params - 查询参数
* @param {string} params.beginTime - 开始时间
* @param {string} params.endTime - 结束时间
* @param {string} params.name - 用户昵称搜索
* @returns {Promise}
*/
export function getAgentList(params = {}) {
return request({
url: '/app/order/agentList',
method: 'GET',
params,
showLoading: false,
}).catch(error => {
console.warn('代理用户列表API调用失败:', error)
return null
})
}
/**
* 获取用户列表 (使用代理列表接口)
* @param {Object} params - 查询参数
* @returns {Promise}
*/
export function getUserList(params = {}) {
return getAgentList(params)
}
/**
* 更新用户信息
* @param {Object} data - 用户信息数据
* @returns {Promise} 返回更新结果
*/
export function updateUserInfo(data) {
return request({
url: '/app/user/update',
method: 'POST',
data,
})
}
/**
* 更新用户昵称
* @param {string} nickName - 新的昵称
* @returns {Promise} 返回更新结果
*/
export function updateNickName(nickName) {
return request({
url: '/app/user/updateNickName',
method: 'PUT',
params: { nickName },
showLoading: true,
// 强制将params作为查询参数发送
useQueryParams: true,
}).catch(error => {
console.warn('更新昵称API调用失败:', error)
throw error
})
}
/**
* 获取提现信息
* @returns {Promise} 返回提现相关信息
*/
export function getWithdrawInfo() {
return request({
url: '/app/withdraw',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('提现信息API调用失败使用模拟数据:', error)
return createMockResponse(mockWithdrawInfo)
})
}
/**
* 获取服务费用明细
* @returns {Promise} 返回服务费用明细
*/
export function computedServiceAmount(amount) {
return request({
url: '/app/withdraw/serviceAmount',
method: 'GET',
showLoading: false,
params: { amount },
}).catch(error => {
console.warn('服务费用API调用失败:', error)
return null
})
}
/**
* 提交提现申请
* @param {Object} data 提现数据
* @param {number} data.amount 提现金额
* @param {string} data.accountId 账号id
* @param {string} data.serviceType 服务类型
* @param {string} data.serviceCharge 服务费
* @param {string} data.arrivalAmount 实际到达金额
* @returns {Promise} 返回提现申请结果
*/
export function submitWithdraw(data) {
return request({
url: '/app/withdraw',
method: 'POST',
data,
showLoading: true,
}).catch(error => {
console.warn('提现申请API调用失败:', error)
throw error
})
}
/**
* 上传头像
* @param {string} avatarUrl - 文件路径
* @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',
},
})
}
/**
* 获取本地存储的用户ID
* @returns {string|null} 返回用户ID如果不存在则返回null
*/
export function getLocalUserId() {
return uni.getStorageSync('userId') || null
}
/**
* 清除本地存储的用户ID
*/
export function clearLocalUserId() {
uni.removeStorageSync('userId')
console.log('本地用户ID已清除')
}
export function getIsRealName() {
return request({
url: '/app/user/isReal',
})
}