2025-04-08 11:21:58 +08:00
|
|
|
'use server'
|
2025-12-16 17:10:30 +08:00
|
|
|
import {callByDevice, callByUser} from '@/actions/base'
|
2025-04-11 17:34:42 +08:00
|
|
|
import {Resource} from '@/lib/models'
|
2025-12-16 17:10:30 +08:00
|
|
|
import {PageRecord} from '@/lib/api'
|
|
|
|
|
|
|
|
|
|
export type CreateResourceReq = {
|
|
|
|
|
type: number
|
|
|
|
|
short?: {
|
|
|
|
|
live: number
|
|
|
|
|
mode: number
|
|
|
|
|
quota: number
|
|
|
|
|
expire?: number
|
|
|
|
|
}
|
|
|
|
|
long?: {
|
|
|
|
|
live: number
|
|
|
|
|
mode: number
|
|
|
|
|
quota: number
|
|
|
|
|
expire?: number
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-09 17:17:39 +08:00
|
|
|
|
2025-05-22 14:59:22 +08:00
|
|
|
export async function listResourceShort(props: {
|
2025-04-09 17:17:39 +08:00
|
|
|
page: number
|
|
|
|
|
size: number
|
2025-04-11 17:34:42 +08:00
|
|
|
resource_no?: string
|
2025-04-09 17:17:39 +08:00
|
|
|
type?: number
|
2025-04-10 17:49:02 +08:00
|
|
|
create_after?: Date
|
|
|
|
|
create_before?: Date
|
|
|
|
|
expire_after?: Date
|
|
|
|
|
expire_before?: Date
|
2025-04-11 17:34:42 +08:00
|
|
|
}) {
|
2025-05-22 14:59:22 +08:00
|
|
|
return await callByUser<PageRecord<Resource<1>>>('/api/resource/list/short', props)
|
2025-04-09 17:17:39 +08:00
|
|
|
}
|
2025-04-08 11:21:58 +08:00
|
|
|
|
2025-05-22 14:59:22 +08:00
|
|
|
export async function listResourceLong(props: {
|
|
|
|
|
page: number
|
|
|
|
|
size: number
|
|
|
|
|
resource_no?: string
|
|
|
|
|
type?: number
|
|
|
|
|
create_after?: Date
|
|
|
|
|
create_before?: Date
|
|
|
|
|
expire_after?: Date
|
|
|
|
|
expire_before?: Date
|
|
|
|
|
}) {
|
|
|
|
|
return await callByUser<PageRecord<Resource<2>>>('/api/resource/list/long', props)
|
2025-04-16 18:51:17 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-22 14:59:22 +08:00
|
|
|
export async function allResource() {
|
|
|
|
|
return callByUser<Resource<1 | 2>[]>('/api/resource/all')
|
2025-04-08 11:21:58 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-16 17:10:30 +08:00
|
|
|
export async function createResource(props: CreateResourceReq) {
|
2025-05-22 14:59:22 +08:00
|
|
|
return await callByUser('/api/resource/create', props)
|
2025-04-16 18:51:17 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-22 14:59:22 +08:00
|
|
|
export async function prepareResource(props: {
|
2025-06-18 19:05:38 +08:00
|
|
|
payment_method: number
|
|
|
|
|
payment_platform: number
|
2025-12-16 17:10:30 +08:00
|
|
|
} & CreateResourceReq) {
|
2025-05-22 14:59:22 +08:00
|
|
|
return await callByUser<{
|
|
|
|
|
trade_no: string
|
|
|
|
|
pay_url: string
|
2025-06-27 10:57:50 +08:00
|
|
|
}>('/api/trade/create', {
|
|
|
|
|
platform: props.payment_platform,
|
|
|
|
|
method: props.payment_method,
|
|
|
|
|
type: 1,
|
|
|
|
|
resource: {
|
|
|
|
|
type: props.type,
|
|
|
|
|
short: props.short,
|
|
|
|
|
long: props.long,
|
|
|
|
|
},
|
|
|
|
|
})
|
2025-04-16 18:51:17 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-22 14:59:22 +08:00
|
|
|
export async function completeResource(props: {
|
2025-04-17 18:30:16 +08:00
|
|
|
trade_no: string
|
2025-06-27 10:57:50 +08:00
|
|
|
method: number
|
2025-05-22 14:59:22 +08:00
|
|
|
}) {
|
2025-06-27 10:57:50 +08:00
|
|
|
return callByUser('/api/trade/complete', props)
|
2025-04-08 11:21:58 +08:00
|
|
|
}
|
2025-08-16 11:41:07 +08:00
|
|
|
|
|
|
|
|
export async function payClose(props: {
|
|
|
|
|
trade_no: string
|
|
|
|
|
method: number
|
|
|
|
|
}) {
|
|
|
|
|
return callByUser('/api/trade/cancel', props)
|
|
|
|
|
}
|
2025-12-16 17:10:30 +08:00
|
|
|
|
|
|
|
|
export async function getPrice(props: CreateResourceReq) {
|
2025-12-20 15:08:12 +08:00
|
|
|
return callByDevice<{
|
|
|
|
|
price: string
|
|
|
|
|
discounted_price?: string
|
|
|
|
|
discounted?: number
|
|
|
|
|
}>('/api/resource/price', props)
|
2025-12-16 17:10:30 +08:00
|
|
|
}
|