214 lines
5.7 KiB
TypeScript
214 lines
5.7 KiB
TypeScript
import { BaseResponse, Pageable } from '@/shared/model-components';
|
|
import { unwrap } from '@u/asyncs';
|
|
import { ajaxEngine } from './axios_instance';
|
|
import { BaseUserInfo, UserInfo, UserType } from '@/shared/model-user';
|
|
|
|
/**
|
|
* 用户请求重设密码。
|
|
* @param username 要重设密码的用户账号。
|
|
* @param verify 用于验证重设操作的验证码。
|
|
* @param password 要设置成的新密码。
|
|
* @returns 服务端进行重设密码操作以后的操作结果。
|
|
*/
|
|
export async function repassword(username: string, verify: string, password: string): Promise<BaseResponse> {
|
|
const response = await ajaxEngine(true).put(`/password`, {
|
|
uname: username,
|
|
verifyCode: verify,
|
|
newPass: password
|
|
});
|
|
return unwrap(response);
|
|
}
|
|
|
|
export interface AccountsResponse extends BaseResponse, Pageable {
|
|
accounts: BaseUserInfo[];
|
|
}
|
|
|
|
/**
|
|
* 请求系统账号列表
|
|
* @param page 页码
|
|
* @param query
|
|
* @param query.keyword 查询用户账号、用户名的关键字
|
|
* @param query.type 查询用户账号、用户名的关键字
|
|
* @param query.state 账号是否启用
|
|
* @returns 系统账号列表
|
|
*/
|
|
export async function userAccounts(
|
|
page: number,
|
|
query?: { keyword?: string; type?: UserType; state?: boolean }
|
|
): Promise<AccountsResponse> {
|
|
const response = await ajaxEngine().get<AccountsResponse>(`/account`, { params: { page, ...query } });
|
|
return unwrap(response);
|
|
}
|
|
|
|
/**
|
|
* 更改用户可用性状态
|
|
* @param uid 账号Id
|
|
* @param enabled 是否启用
|
|
*/
|
|
export async function changeAccountStatus(uid: string, enabled: boolean): Promise<BaseResponse> {
|
|
const response = await ajaxEngine().put(`/account/enabled/state`, {
|
|
uid,
|
|
enabled
|
|
});
|
|
return unwrap(response);
|
|
}
|
|
|
|
/**
|
|
* 重置密码
|
|
* @param uid 账号Id
|
|
* @return 验证码
|
|
*/
|
|
export async function resetPassword(uid: string) {
|
|
const response = await ajaxEngine().delete<BaseResponse & { verify: string }>(`/password/${uid}`);
|
|
return unwrap(response);
|
|
}
|
|
|
|
export interface ChangeUserInfoParams {
|
|
address?: string;
|
|
contact?: string;
|
|
name?: string;
|
|
phone?: string;
|
|
region?: string;
|
|
unitServiceFee?: number;
|
|
}
|
|
|
|
/**
|
|
* 修改用户信息。
|
|
* @param uid
|
|
* @param data 修改后的用户信息
|
|
*/
|
|
export async function changeUserInfo(uid: string, data: ChangeUserInfoParams): Promise<BaseResponse> {
|
|
const response = await ajaxEngine().put(`/account/${uid}`, data);
|
|
return unwrap(response);
|
|
}
|
|
|
|
/**
|
|
* 创建非企业账号。
|
|
* @param data 创建的用户信息
|
|
*/
|
|
export async function createUser(data: BaseUserInfo): Promise<BaseResponse & { verify: string }> {
|
|
const response = await ajaxEngine().post(`/account`, data);
|
|
return unwrap(response);
|
|
}
|
|
|
|
/**
|
|
* 创建企业账号。
|
|
* @param data 创建的企业信息
|
|
*/
|
|
export async function createEnterprise(
|
|
data: Required<ChangeUserInfoParams> & { username: string }
|
|
): Promise<BaseResponse & { verify: string }> {
|
|
const response = await ajaxEngine().post(`/enterprise`, data);
|
|
return unwrap(response);
|
|
}
|
|
|
|
/**
|
|
* 获取用户的完整信息。
|
|
* @param uid 用户Id
|
|
*/
|
|
export async function userDetail(uid: string): Promise<BaseResponse & { user: UserInfo }> {
|
|
const response = await ajaxEngine().get(`/account/${uid}`);
|
|
return unwrap(response);
|
|
}
|
|
|
|
export interface ChargeListResponse extends BaseResponse, Pageable {
|
|
records: ChargeRecord[];
|
|
}
|
|
|
|
/**
|
|
* 计费记录
|
|
*/
|
|
export interface ChargeRecord {
|
|
/** 记录索引号,可用来排序 */
|
|
seq: number;
|
|
/** 最终合计费用 */
|
|
amount: null | number;
|
|
/** 计费时间,不是收到费用的时间,是费用可以维持服务到达的时间。格式 yyyy-MM-ddTHH:mm:ss.SSSSSSZ */
|
|
chargeTo: string;
|
|
/** 条目创建时间 */
|
|
createdAt: string;
|
|
/** 折扣,即减掉的百分比 */
|
|
discount: number;
|
|
/** 基本费用 */
|
|
fee: number;
|
|
/** 是否起效 */
|
|
settled: boolean;
|
|
/** 起效时间 */
|
|
settledAt: null | string;
|
|
/** 是否已取消 */
|
|
cancelled: boolean;
|
|
/** 取消时间 */
|
|
cancelledAt: null | string;
|
|
/** 所属用户ID */
|
|
userId: string;
|
|
/** 所属用户名称 */
|
|
name: string;
|
|
/** 所属用户账号 */
|
|
username: string;
|
|
}
|
|
|
|
/**
|
|
* 请求计费记录
|
|
* @param page 页码
|
|
* @param query
|
|
* @param query.keyword 查询用户账号、用户名的关键字
|
|
* @param query.begin 起始时间
|
|
* @param query.end 截止时间
|
|
* @returns 计费记录列表
|
|
*/
|
|
export async function chargeList(
|
|
page: number,
|
|
query?: { keyword?: string; begin: string; end: string }
|
|
): Promise<ChargeListResponse> {
|
|
const response = await ajaxEngine().get<ChargeListResponse>(`/charge`, { params: { page, ...query } });
|
|
return unwrap(response);
|
|
}
|
|
|
|
/**
|
|
* 撤销计费记录
|
|
* @param uid 账号Id
|
|
* @param seq 记录索引
|
|
*/
|
|
export async function cancelRecord(uid: string, seq: number): Promise<BaseResponse> {
|
|
const response = await ajaxEngine().put(`/charge/${uid}/${seq}`, { cancelled: true });
|
|
return unwrap(response);
|
|
}
|
|
|
|
export interface ChargeListResponse extends BaseResponse, Pageable {
|
|
records: ChargeRecord[];
|
|
}
|
|
|
|
/**
|
|
* 搜索企业
|
|
* @param keyword 关键词
|
|
* @returns 企业列表
|
|
*/
|
|
export async function searchEnterprise(keyword: string): Promise<BaseResponse & { users: UserInfo[] }> {
|
|
const response = await ajaxEngine().get(`/enterprise/quick/search`, {
|
|
params: { keyword }
|
|
});
|
|
return unwrap(response);
|
|
}
|
|
|
|
export interface CreateRecord {
|
|
// 关联的企业用户Id
|
|
userId: string;
|
|
// 计费日期至
|
|
chargeTo: string;
|
|
// 应计金额
|
|
fee: null | string;
|
|
// 应收金额
|
|
amount: null | string;
|
|
// 折扣
|
|
discount: null | string;
|
|
}
|
|
|
|
/**
|
|
* 创建计费记录
|
|
* @param data 计费信息
|
|
*/
|
|
export async function createRecord(data: CreateRecord): Promise<BaseResponse> {
|
|
const response = await ajaxEngine().post(`/charge`, data);
|
|
return unwrap(response);
|
|
}
|