2025-06-07 11:28:36 +08:00
|
|
|
'use server'
|
|
|
|
|
|
2025-06-23 18:59:31 +08:00
|
|
|
import {ApiResponse, ExtraResp} from '@/lib/api'
|
2025-06-07 11:28:36 +08:00
|
|
|
import {callByUser} from './base'
|
2025-06-23 18:59:31 +08:00
|
|
|
import {listAnnouncements} from './announcement'
|
2025-06-07 11:28:36 +08:00
|
|
|
|
|
|
|
|
type listAccountReq = {
|
2025-06-23 18:59:31 +08:00
|
|
|
resource_no?: string
|
2025-06-30 16:08:08 +08:00
|
|
|
create_after?: Date
|
|
|
|
|
create_before?: Date
|
2025-06-07 11:28:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type listAccountResp = {
|
2025-06-30 16:08:08 +08:00
|
|
|
date: string
|
2025-06-07 11:28:36 +08:00
|
|
|
count: number
|
|
|
|
|
}[]
|
|
|
|
|
|
|
|
|
|
export async function listAccount(props: listAccountReq) {
|
2025-06-23 18:59:31 +08:00
|
|
|
return await callByUser<listAccountResp>('/api/resource/statistics/usage', props)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function statisticsResourceFree() {
|
|
|
|
|
return await callByUser<{
|
|
|
|
|
long: {
|
|
|
|
|
ResourceCount: number
|
|
|
|
|
ResourceDailyFreeSum: number
|
|
|
|
|
ResourceQuotaSum: number
|
|
|
|
|
}
|
|
|
|
|
short: {
|
|
|
|
|
ResourceCount: number
|
|
|
|
|
ResourceDailyFreeSum: number
|
|
|
|
|
ResourceQuotaSum: number
|
|
|
|
|
}
|
|
|
|
|
}>('/api/resource/statistics/free')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type listInitializationResp = {
|
|
|
|
|
anno: ExtraResp<typeof listAnnouncements>
|
|
|
|
|
free: ExtraResp<typeof statisticsResourceFree>
|
|
|
|
|
usage: ExtraResp<typeof listAccount>
|
|
|
|
|
}
|
|
|
|
|
export async function listInitialization(): Promise<ApiResponse<listInitializationResp>> {
|
|
|
|
|
const free = await statisticsResourceFree()
|
|
|
|
|
if (!free.success) {
|
|
|
|
|
return {
|
|
|
|
|
success: false,
|
|
|
|
|
status: 500,
|
|
|
|
|
message: '套餐剩余数据获取失败',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const anno = await listAnnouncements({
|
|
|
|
|
page: 1,
|
|
|
|
|
size: 5,
|
|
|
|
|
})
|
|
|
|
|
if (!anno.success) {
|
|
|
|
|
return {
|
|
|
|
|
success: false,
|
|
|
|
|
status: 500,
|
|
|
|
|
message: '公告数据获取失败',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const usage = await listAccount({
|
|
|
|
|
create_after: new Date(),
|
|
|
|
|
create_before: new Date(),
|
|
|
|
|
})
|
|
|
|
|
if (!usage.success) {
|
|
|
|
|
return {
|
|
|
|
|
success: false,
|
|
|
|
|
status: 500,
|
|
|
|
|
message: '套餐用量数据获取失败',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const data = {
|
|
|
|
|
anno: anno.data,
|
|
|
|
|
free: free.data,
|
|
|
|
|
usage: usage.data,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
data: data,
|
|
|
|
|
}
|
2025-06-07 11:28:36 +08:00
|
|
|
}
|