18 Commits

Author SHA1 Message Date
Eamon-meng
84a5e27c05 提取IP添加主机格式选项功能 2026-05-09 13:34:36 +08:00
Eamon-meng
9dea370a87 更改白名单上限 2026-05-06 15:14:33 +08:00
Eamon-meng
602372e58d 套餐页面添加标题字段 2026-04-30 16:57:00 +08:00
Eamon-meng
574ad0e662 购买页面 & IP提取页面样式调整 2026-04-28 18:02:26 +08:00
Eamon-meng
78d916ade1 购买页面调间隙高度 2026-04-28 18:02:25 +08:00
Eamon-meng
6a9e7289b5 购买套餐页面更改字段和添加小字提示 & 添加余额管理页面
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 18:02:23 +08:00
6adcd33943 放开提取接口权限 2026-04-28 18:01:57 +08:00
Eamon-meng
165151b9d2 解决构建报错问题 2026-04-23 14:09:38 +08:00
Eamon-meng
1e76275f04 套餐添加操作列 & 登录后已实名的更新状态显示 &更新脚本的远程仓库地址 2026-04-23 13:43:06 +08:00
Eamon-meng
d9cd5eb41b 发布v1.9.0版本 2026-04-22 13:18:40 +08:00
Eamon-meng
7ff42861f1 套餐管理添加IP检查状态字段 &修复套餐提取和购买的数量显示问题 2026-04-22 10:27:19 +08:00
Eamon-meng
eb4c2d2d5f 暂无可用套餐时取消加载中 & 登录页加返回首页 & 加联系专属客服 & 修改白名单上限10个 2026-04-21 16:51:30 +08:00
a0b0956677 免费与菜单提示文字 2026-04-21 16:19:11 +08:00
Eamon-meng
27e694ee0d 取消关闭支付弹窗调用关闭订单接口 & 添加未实名去支付时的拦截 2026-04-20 16:22:49 +08:00
Eamon-meng
74d53c619d 购买套餐添加count_min字段 2026-04-20 15:36:50 +08:00
8f8def3a87 完善异常跳转 2026-04-20 15:34:49 +08:00
Eamon-meng
ed73d8579f 更新发布v1.7.0 2026-04-18 17:36:22 +08:00
Eamon-meng
e3c61a77e6 修复未登录时提取ip时的套餐显示和不调用获取套餐接口 2026-04-18 17:13:26 +08:00
32 changed files with 923 additions and 369 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "lanhu-web", "name": "lanhu-web",
"version": "1.6.0", "version": "1.12.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -H 0.0.0.0 --turbopack", "dev": "next dev -H 0.0.0.0 --turbopack",

View File

@@ -9,8 +9,8 @@ if ($confrim -ne "y") {
exit 0 exit 0
} }
docker build -t repo.lanhuip.com:8554/lanhu/web:latest . docker build -t repo.lanhuip.com/lanhu/web:latest .
docker build -t repo.lanhuip.com:8554/lanhu/web:$($args[0]) . docker build -t repo.lanhuip.com/lanhu/web:$($args[0]) .
docker push repo.lanhuip.com:8554/lanhu/web:latest docker push repo.lanhuip.com/lanhu/web:latest
docker push repo.lanhuip.com:8554/lanhu/web:$($args[0]) docker push repo.lanhuip.com/lanhu/web:$($args[0])

14
src/actions/balance.ts Normal file
View File

@@ -0,0 +1,14 @@
'use server'
import {Balance} from '@/lib/models'
import {callByUser} from '@/actions/base'
import {PageRecord} from '@/lib/api'
export async function listBalances(params: {
page?: number
size?: number
bill_no?: string
created_at_start?: Date
created_at_end?: Date
}) {
return await callByUser<PageRecord<Balance>>('/api/balance/page', params)
}

View File

@@ -2,6 +2,7 @@
import {API_BASE_URL, ApiResponse, CLIENT_ID, CLIENT_SECRET} from '@/lib/api' import {API_BASE_URL, ApiResponse, CLIENT_ID, CLIENT_SECRET} from '@/lib/api'
import {add, isBefore} from 'date-fns' import {add, isBefore} from 'date-fns'
import {cookies, headers} from 'next/headers' import {cookies, headers} from 'next/headers'
import {redirect} from 'next/navigation'
import {cache} from 'react' import {cache} from 'react'
export type TokenResp = { export type TokenResp = {
@@ -106,7 +107,6 @@ const _callByUser = cache(async <R = undefined>(
// ====================== // ======================
async function call<R = undefined>(url: string, body: RequestInit['body'], auth?: string): Promise<ApiResponse<R>> { async function call<R = undefined>(url: string, body: RequestInit['body'], auth?: string): Promise<ApiResponse<R>> {
let response: Response
try { try {
const reqHeaders = await headers() const reqHeaders = await headers()
const reqIP = reqHeaders.get('x-forwarded-for') const reqIP = reqHeaders.get('x-forwarded-for')
@@ -118,15 +118,14 @@ async function call<R = undefined>(url: string, body: RequestInit['body'], auth?
if (reqIP) callHeaders['X-Forwarded-For'] = reqIP if (reqIP) callHeaders['X-Forwarded-For'] = reqIP
if (reqUA) callHeaders['User-Agent'] = reqUA if (reqUA) callHeaders['User-Agent'] = reqUA
response = await fetch(url, { const response = await fetch(url, {
method: 'POST', method: 'POST',
headers: callHeaders, headers: callHeaders,
body, body,
}) })
}
catch (e) { if (response.status === 401) {
console.error('后端请求失败', url, (e as Error).message) return redirect('/login?redirect=' + encodeURIComponent(url.replace(API_BASE_URL, '')))
throw new Error(`请求失败,网络错误`)
} }
const type = response.headers.get('Content-Type') ?? 'text/plain' const type = response.headers.get('Content-Type') ?? 'text/plain'
@@ -168,6 +167,11 @@ async function call<R = undefined>(url: string, body: RequestInit['body'], auth?
throw new Error(`无法解析响应数据,未处理的 Content-Type: ${type}`) throw new Error(`无法解析响应数据,未处理的 Content-Type: ${type}`)
} }
catch (e) {
console.error('后端请求失败', url, (e as Error).message)
throw new Error(`请求失败,网络错误`)
}
}
// 导出 // 导出
export { export {

View File

@@ -17,6 +17,7 @@ export async function listChannels(props: {
} }
type CreateChannelsResp = { type CreateChannelsResp = {
ip: string
host: string host: string
port: string port: string
username?: string username?: string
@@ -31,6 +32,7 @@ export async function createChannels(params: {
prov?: string prov?: string
city?: string city?: string
isp?: number isp?: number
host_format?: number
}) { }) {
return callByUser<CreateChannelsResp[]>('/api/channel/create', params) return callPublic<CreateChannelsResp[]>('/api/channel/create', params)
} }

View File

@@ -103,3 +103,10 @@ export async function getPriceHome(props: CreateResourceReq) {
discounted?: string discounted?: string
}>('/api/resource/price', props) }>('/api/resource/price', props)
} }
export async function updateCheckip(props: {
id: number
checkip: boolean
}) {
return callByUser('/api/resource/update/checkip', props)
}

View File

@@ -23,6 +23,7 @@ export async function GET(req: NextRequest) {
const prov = params.get('a') || undefined const prov = params.get('a') || undefined
const city = params.get('b') || undefined const city = params.get('b') || undefined
const isp = params.get('s') || undefined const isp = params.get('s') || undefined
const hostFormat = params.get('rh') || 'domain'
const result = await createChannels({ const result = await createChannels({
resource_id: Number(resource_id), resource_id: Number(resource_id),
@@ -32,7 +33,9 @@ export async function GET(req: NextRequest) {
prov, prov,
city, city,
isp: Number(isp), isp: Number(isp),
host_format: hostFormat === 'domain' ? 1 : 2,
}) })
if (!result.success) { if (!result.success) {
throw new Error(result.message) throw new Error(result.message)
} }
@@ -46,10 +49,32 @@ export async function GET(req: NextRequest) {
switch (format) { switch (format) {
case 'json': case 'json':
return NextResponse.json(result.data) if (hostFormat === 'domain') {
const domainFormatData = result.data.map(item => ({
host: item.host,
port: item.port,
...(item.username && item.password ? {username: item.username, password: item.password} : {}),
}))
return NextResponse.json(domainFormatData)
}
else {
const ipFormatData = result.data.map(item => ({
ip: item.ip,
port: item.port,
...(item.username && item.password ? {username: item.username, password: item.password} : {}),
}))
return NextResponse.json(ipFormatData)
}
case 'text': case 'text':
const text = result.data.map((item) => { const text = result.data.map((item) => {
const list = [item.host, item.port] let hostValue: string
if (hostFormat === 'domain') {
hostValue = item.host
}
else {
hostValue = item.ip
}
const list = [hostValue, String(item.port)]
if (item.username && item.password) { if (item.username && item.password) {
list.push(item.username) list.push(item.username)
list.push(item.password) list.push(item.password)

View File

@@ -6,7 +6,7 @@ import {Card, CardContent} from '@/components/ui/card'
import {Form, FormField} from '@/components/ui/form' import {Form, FormField} from '@/components/ui/form'
import {Label} from '@/components/ui/label' import {Label} from '@/components/ui/label'
import {Tabs, TabsList, TabsTrigger} from '@/components/ui/tabs' import {Tabs, TabsList, TabsTrigger} from '@/components/ui/tabs'
import {EyeClosedIcon, EyeIcon} from 'lucide-react' import {EyeClosedIcon, EyeIcon, HomeIcon} from 'lucide-react'
import {useState, ReactNode, useEffect, Suspense} from 'react' import {useState, ReactNode, useEffect, Suspense} from 'react'
import zod from 'zod' import zod from 'zod'
import {useForm, useFormContext, useWatch} from 'react-hook-form' import {useForm, useFormContext, useWatch} from 'react-hook-form'
@@ -16,6 +16,7 @@ import {useRouter} from 'next/navigation'
import {login, LoginMode} from '@/actions/auth' import {login, LoginMode} from '@/actions/auth'
import {useProfileStore} from '@/components/stores/profile' import {useProfileStore} from '@/components/stores/profile'
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
import Link from 'next/link'
const smsSchema = zod.object({ const smsSchema = zod.object({
username: zod.string().length(11, '请输入正确的手机号码'), username: zod.string().length(11, '请输入正确的手机号码'),
@@ -88,6 +89,16 @@ export default function LoginCard() {
const [showPwd, setShowPwd] = useState(false) const [showPwd, setShowPwd] = useState(false)
return ( return (
<div className="relative flex flex-col items-center">
<div className="relative w-96 mx-4">
<Link
href="/"
className="absolute -top-8 right-0 inline-flex items-center text-sm transition-colors px-10"
>
<HomeIcon size={18} className="mr-1"/>
</Link>
</div>
<Card className="w-96 mx-4 shadow-lg relative z-20 py-8"> <Card className="w-96 mx-4 shadow-lg relative z-20 py-8">
<CardContent className="px-8"> <CardContent className="px-8">
{/* 登录方式切换 */} {/* 登录方式切换 */}
@@ -193,6 +204,7 @@ export default function LoginCard() {
</Form> </Form>
</CardContent> </CardContent>
</Card> </Card>
</div>
) )
} }

View File

@@ -237,7 +237,7 @@ export default function CustomPage() {
<section className="relative rounded-lg overflow-hidden h-48 lg:h-56"> <section className="relative rounded-lg overflow-hidden h-48 lg:h-56">
<Image <Image
src={group} src={group}
alt="免费试用背景" alt="立即试用背景"
fill fill
className="object-cover" className="object-cover"
priority priority
@@ -251,9 +251,9 @@ export default function CustomPage() {
className={merge( className={merge(
'bg-blue-600 hover:bg-blue-700 text-white px-8 py-3 rounded-md whitespace-nowrap', 'bg-blue-600 hover:bg-blue-700 text-white px-8 py-3 rounded-md whitespace-nowrap',
)} )}
onClick={() => router.push('/login')} onClick={() => router.push('/product')}
> >
</Button> </Button>
</div> </div>
</div> </div>

View File

@@ -14,7 +14,8 @@
| b | string | 否 | 归属地城市。默认全局随机 | | b | string | 否 | 归属地城市。默认全局随机 |
| s | string | 否 | 归属地运营商。默认全局随机 | | s | string | 否 | 归属地运营商。默认全局随机 |
| d | string | 否 | 是否去重1 - 是0 - 否。默认为是 | | d | string | 否 | 是否去重1 - 是0 - 否。默认为是 |
| rt | string | 否 | 返回类型1 - TXT2 - JSON。默认 TXT | | rt | string | 否 | 返回类型1 - TXT2 - JSON。默认 TXT
| rh | string | 否 | 返回时主机字段的格式1 - 域名2 - IP。默认为域名 |
| rs | number[] | 否 | 返回时要使用的分隔符,值为该字符的 ascii 编码,可以有多个字符,多个字符用半角逗号连接。默认为 13,10即回车 + 换行(\r\n | | rs | number[] | 否 | 返回时要使用的分隔符,值为该字符的 ascii 编码,可以有多个字符,多个字符用半角逗号连接。默认为 13,10即回车 + 换行(\r\n |
| rb | number[] | 否 | 返回时要使用的换行符,值为该字符的 ascii 编码,可以有多个字符,多个字符用半角逗号连接。默认为 124即垂直线 \| | | rb | number[] | 否 | 返回时要使用的换行符,值为该字符的 ascii 编码,可以有多个字符,多个字符用半角逗号连接。默认为 124即垂直线 \| |
| n | number | 否 | 提取数量。默认为 1 | | n | number | 否 | 提取数量。默认为 1 |
@@ -33,7 +34,7 @@
| password | string | 代理服务器密码(仅在认证类型为密码时返回) | | password | string | 代理服务器密码(仅在认证类型为密码时返回) |
## 示例 ## 示例1
### 请求示例 ### 请求示例
@@ -65,3 +66,36 @@ GET https://lanhuip.com/api/extract?i=1&t=2&a=广东省&b=广州市&s=移动&d=1
} }
] ]
``` ```
## 示例2
### 请求示例
```http
GET https://lanhuip.com/api/extract?i=24&t=1&a=广东省&b=广州市&d=1&rt=text&rh=ip&rs=124&rb=13%2C10&n=1
```
### 响应示例
```json
[
{
"ip": "127.0.0.1",
"port": 20000,
"username": "user1",
"password": "pass1"
},
{
"ip": "127.0.0.1",
"port": 20001,
"username": "user2",
"password": "pass2"
},
{
"ip": "127.0.0.1",
"port": 20002,
"username": "user3",
"password": "pass3"
}
]
```

View File

@@ -10,13 +10,13 @@ export default function Addr({channel}: {
const expired = isBefore(channel.expired_at, new Date()) const expired = isBefore(channel.expired_at, new Date())
return ( return (
<div className={`${expired ? 'text-weak' : ''}`}> <>
<span>{ip}:{port}</span> <span>{ip}:{port}</span>
{expired && ( {expired && (
<Badge variant="secondary"> <Badge className="ml-2 bg-orange-100 text-orange-700 hover:bg-orange-100 dark:bg-orange-900/30 dark:text-orange-400">
</Badge> </Badge>
)} )}
</div> </>
) )
} }

View File

@@ -0,0 +1,16 @@
import {ReactNode} from 'react'
import {Metadata} from 'next'
export async function generateMetadata(): Promise<Metadata> {
return {
title: '余额管理 - 蓝狐代理',
}
}
export type PurchaseLayoutProps = {
children: ReactNode
}
export default async function PurchaseLayout(props: PurchaseLayoutProps) {
return props.children
}

View File

@@ -0,0 +1,235 @@
'use client'
import {useCallback, useEffect, useState} from 'react'
import {PageRecord} from '@/lib/api'
import {Balance} from '@/lib/models'
import {useStatus} from '@/lib/states'
import {Search, Eraser} from 'lucide-react'
import {Button} from '@/components/ui/button'
import DataTable from '@/components/data-table'
import {format} from 'date-fns'
import DatePicker from '@/components/date-picker'
import {Form, FormField} from '@/components/ui/form'
import {useForm} from 'react-hook-form'
import zod from 'zod'
import {zodResolver} from '@hookform/resolvers/zod'
import {Label} from '@/components/ui/label'
import Page from '@/components/page'
import {CheckCircle, AlertCircle} from 'lucide-react'
import {Input} from '@/components/ui/input'
import {listBalances} from '@/actions/balance'
const filterSchema = zod.object({
created_at_start: zod.date().optional(),
created_at_end: zod.date().optional(),
bill_no: zod.string().optional(),
})
type FilterSchema = zod.infer<typeof filterSchema>
export type BalancePageProps = {}
export default function BalancePage(props: BalancePageProps) {
const [status, setStatus] = useStatus()
const [data, setData] = useState<PageRecord<Balance>>({
page: 1,
size: 10,
total: 0,
list: [],
})
const form = useForm<FilterSchema>({
resolver: zodResolver(filterSchema),
defaultValues: {
bill_no: '',
created_at_start: undefined,
created_at_end: undefined,
},
})
const onSubmit = async (value: FilterSchema) => {
await refresh(1, data.size)
}
const refresh = useCallback(async (page: number, size: number) => {
setStatus('load')
try {
const created_at_start = form.getValues('created_at_start')
const created_at_end = form.getValues('created_at_end')
const bill_no = form.getValues('bill_no')
const res = await listBalances({
page, size,
created_at_start,
created_at_end,
bill_no: bill_no || undefined,
})
if (res.success) {
setData(res.data)
setStatus('done')
}
else {
throw new Error('Failed to load bills')
}
}
catch (e) {
setStatus('fail')
}
}, [form, setStatus])
useEffect(() => {
refresh(1, 10).then()
}, [refresh])
return (
<Page>
<section className="flex justify-between flex-wrap">
<Form form={form} handler={form.handleSubmit(onSubmit)} className="flex-auto flex flex-wrap gap-4 items-end">
<FormField name="bill_no" label={<span className="text-sm"></span>}>
{({id, field}) => {
return <Input {...field} id={id} className="h-9"/>
}}
</FormField>
<div className="flex flex-col gap-2">
<Label className="text-sm"></Label>
<div className="flex items-center">
<FormField name="created_at_start">
{({field}) => {
const dateValue = typeof field.value === 'string' && field.value ? new Date(field.value) : undefined
return (
<DatePicker
placeholder="选择开始时间"
{...field}
format="yyyy-MM-dd"
/>
)
}
}
</FormField>
<span className="px-1">-</span>
<FormField name="created_at_end">
{({field}) => (
<DatePicker
placeholder="选择结束时间"
{...field}
format="yyyy-MM-dd"
/>
)
}
</FormField>
</div>
</div>
<Button className="h-9" type="submit">
<Search/>
<span></span>
</Button>
<Button
theme="outline"
className="h-9"
type="button"
onClick={() => {
form.reset()
refresh(1, data.size)
}}
>
<Eraser/>
<span></span>
</Button>
</Form>
</section>
<DataTable
data={data.list}
status={status}
pagination={{
total: data.total,
page: data.page,
size: data.size,
onPageChange: async (page: number) => {
await refresh(page, data.size)
},
onSizeChange: async (size: number) => {
await refresh(data.page, size)
},
}}
columns={[
{accessorKey: 'bill_no', header: `账单编号`,
accessorFn: row => row.bill?.bill_no || '',
},
{
accessorKey: 'status',
header: `状态`,
cell: ({row}) => {
const trade = row.original.trade
if (![1, 2, 3, 4, 5].includes(trade?.method)) {
return (
<div className="flex items-center gap-2">
<CheckCircle size={16} className="text-done"/>
<span></span>
</div>
)
}
if (!trade) return <span>-</span>
return (
<div className="flex items-center gap-2">
{trade?.status === 1 ? (
<CheckCircle size={16} className="text-done"/>
) : trade?.status === 2 ? (
<AlertCircle size={16} className="text-weak"/>
) : trade?.status === 3 ? (
<AlertCircle size={16} className="text-fail"/>
) : null}
<span>
{trade?.status === 1 ? '已完成'
: trade?.status === 2 ? '已取消'
: trade?.status === 3 ? '已退款' : '-'}
</span>
</div>
)
},
},
{
accessorKey: 'amount',
header: '变动金额',
cell: ({row}) => {
const amount = row.original.amount
const isPositive = Number(amount) > 0
return (
<div className="flex items-center gap-1">
<span
className={`font-semibold ${
isPositive ? 'text-green-600' : 'text-red-600'
}`}
>
{isPositive ? '+' : ''}
{Number(amount).toFixed(2)}
</span>
</div>
)
},
},
{
header: '余额变化',
accessorKey: 'balance_prev',
cell: ({row}) => (
<div className="flex items-center gap-2">
<span className="text-gray-500 text-sm">¥{Number(row.original.balance_prev).toFixed(2)}</span>
<span className="text-muted-foreground"></span>
<span>¥{Number(row.original.balance_curr).toFixed(2)}</span>
</div>
),
},
{
header: '备注',
accessorKey: 'remark',
},
{
header: '创建时间',
accessorKey: 'created_at',
cell: ({row}) =>
format(new Date(row.original.created_at), 'yyyy-MM-dd HH:mm'),
},
]}
/>
</Page>
)
}

View File

@@ -192,7 +192,7 @@ export default function ChannelsPage(props: ChannelsPageProps) {
<span ></span> <span ></span>
<div className="flex flex-wrap gap-1 max-w-[200px]"> <div className="flex flex-wrap gap-1 max-w-[200px]">
{channel.whitelists.split(',').map((ip, index) => ( {channel.whitelists.split(',').map((ip, index) => (
<Badge key={index} variant="secondary"> <Badge key={index} className="bg-green-100 text-green-700 hover:bg-green-100 dark:bg-green-900/30 dark:text-green-400">
{ip.trim()} {ip.trim()}
</Badge > </Badge >
))} ))}
@@ -201,7 +201,7 @@ export default function ChannelsPage(props: ChannelsPageProps) {
) : hasAuth ? ( ) : hasAuth ? (
<div className="flex flex-col"> <div className="flex flex-col">
<span></span> <span></span>
<Badge variant="secondary"> <Badge className="bg-blue-100 text-blue-700 hover:bg-blue-100 dark:bg-blue-900/30 dark:text-blue-400">
{channel.username}:{channel.password} {channel.username}:{channel.password}
</Badge > </Badge >
</div> </div>

View File

@@ -6,7 +6,7 @@ import {RealnameAuthDialog} from '@/components/composites/dialogs/realname-auth-
import UserCenter from '@/components/composites/user-center' import UserCenter from '@/components/composites/user-center'
import {Button} from '@/components/ui/button' import {Button} from '@/components/ui/button'
import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from '@/components/ui/tooltip' import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from '@/components/ui/tooltip'
import {Archive, ArchiveRestore, Eye, HardDriveUpload, IdCard, LockKeyhole, Package, PanelLeftCloseIcon, PanelLeftOpenIcon, ShoppingCart, UserRound, UserRoundPen, Wallet} from 'lucide-react' import {Archive, ArchiveRestore, CircleDollarSign, Eye, HardDriveUpload, IdCard, LockKeyhole, MessageCircleMoreIcon, Package, PanelLeftCloseIcon, PanelLeftOpenIcon, ShoppingCart, UserRound, UserRoundPen, Wallet} from 'lucide-react'
import {merge} from '@/lib/utils' import {merge} from '@/lib/utils'
import logoAvatar from '@/assets/logo-avatar.svg' import logoAvatar from '@/assets/logo-avatar.svg'
import logoText from '@/assets/logo-text.svg' import logoText from '@/assets/logo-text.svg'
@@ -93,7 +93,8 @@ function ContentResolved() {
export function Header() { export function Header() {
const navbar = useLayoutStore(store => store.navbar) const navbar = useLayoutStore(store => store.navbar)
const toggleNavbar = useLayoutStore(store => store.toggleNavbar) const toggleNavbar = useLayoutStore(store => store.toggleNavbar)
const profile = use(useProfileStore(store => store.profile))
const showRealnameAuth = profile?.id_type === 0
return ( return (
<header className={merge( <header className={merge(
`flex-none h-16 overflow-hidden`, `flex-none h-16 overflow-hidden`,
@@ -103,25 +104,53 @@ export function Header() {
<div className="flex-auto flex items-center gap-2"> <div className="flex-auto flex items-center gap-2">
<Button <Button
theme="ghost" theme="ghost"
className="w-9 h-9 ml-4 md:ml-0" className="h-9 ml-4 md:ml-0"
onClick={toggleNavbar}> onClick={toggleNavbar}>
{navbar {navbar ? (
? <PanelLeftCloseIcon/> <>
: <PanelLeftOpenIcon/> <PanelLeftCloseIcon/>
} <span className="text-foreground/90"></span>
</>
) : (
<>
<PanelLeftOpenIcon/>
<span className="text-foreground/90"></span>
</>
)}
</Button> </Button>
<span className="max-md:hidden"> <span className="max-md:hidden"></span>
<div className="max-md:hidden h-5 w-px bg-gray-300 mx-2"/>
</span> {showRealnameAuth ? (
<Link
href="/admin/identify"
className="max-md:hidden flex items-center gap-1.5 text-sm text-blue-600 hover:text-blue-800 transition-colors"
>
<IdCard size={16}/>
<span></span>
</Link>
) : (
<Link
href=""
className="max-md:hidden flex items-center gap-1.5 text-sm text-green-400 hover:text-green-400 transition-colors"
>
<IdCard size={16}/>
<span></span>
</Link>
)}
<div className="max-md:hidden h-5 w-px bg-gray-300 mx-2"/>
<a
href="https://wpa1.qq.com/K0s0cvwf?_type=wpa&qidian=true"
target="_blank"
rel="noopener noreferrer"
className="max-md:hidden flex items-center gap-1.5 text-sm text-blue-600 hover:text-blue-800 transition-colors mr-2"
>
<MessageCircleMoreIcon size={16}/>
<span></span>
</a>
</div> </div>
{/* right */} <div className="flex-none flex items-center justify-end pr-4 max-md:hidden gap-3">
<div className="flex-none flex items-center justify-end pr-4 max-md:hidden gap-2"> <Link href="/" className="flex-none h-16 flex items-center justify-center text-sm">
<Link
href="/"
className={merge(
`flex-none h-16 flex items-center justify-center`,
)}>
</Link> </Link>
<Suspense> <Suspense>
@@ -176,12 +205,13 @@ export function Navbar() {
<TooltipProvider> <TooltipProvider>
<NavItem href="/admin" icon={<UserRound size={20}/>} label="账户总览" expand={navbar}/> <NavItem href="/admin" icon={<UserRound size={20}/>} label="账户总览" expand={navbar}/>
<NavTitle label="快速开始"/> <NavTitle label="快速开始"/>
<NavItem href="/admin/identify" icon={<IdCard size={20}/>} label="实名认证" expand={navbar}/> {/* <NavItem href="/admin/identify" icon={<IdCard size={20}/>} label="实名认证" expand={navbar}/> */}
<NavItem href="/admin/whitelist" icon={<LockKeyhole size={20}/>} label="白名单" expand={navbar}/> <NavItem href="/admin/whitelist" icon={<LockKeyhole size={20}/>} label="白名单" expand={navbar}/>
<NavItem href="/admin/purchase" icon={<ShoppingCart size={20}/>} label="购买套餐" expand={navbar}/> <NavItem href="/admin/purchase" icon={<ShoppingCart size={20}/>} label="购买套餐" expand={navbar}/>
<NavItem href="/admin/extract" icon={<HardDriveUpload size={20}/>} label="提取 IP" expand={navbar}/> <NavItem href="/admin/extract" icon={<HardDriveUpload size={20}/>} label="提取 IP" expand={navbar}/>
<NavTitle label="个人中心"/> <NavTitle label="个人中心"/>
<NavItem href="/admin/profile" icon={<UserRoundPen size={20}/>} label="基本信息" expand={navbar}/> <NavItem href="/admin/profile" icon={<UserRoundPen size={20}/>} label="基本信息" expand={navbar}/>
<NavItem href="/admin/balance" icon={<CircleDollarSign size={20}/>} label="余额管理" expand={navbar}/>
<NavItem href="/admin/bills" icon={<Wallet size={20}/>} label="我的账单" expand={navbar}/> <NavItem href="/admin/bills" icon={<Wallet size={20}/>} label="我的账单" expand={navbar}/>
<NavTitle label="资源管理"/> <NavTitle label="资源管理"/>
<NavItem href="/admin/resources" icon={<Package size={20}/>} label="我的套餐" expand={navbar}/> <NavItem href="/admin/resources" icon={<Package size={20}/>} label="我的套餐" expand={navbar}/>

View File

@@ -1,4 +1,4 @@
import {ReactNode} from 'react' import {ReactNode, Suspense} from 'react'
import {Shell, Content, Header, Navbar, Mask} from './clients' import {Shell, Content, Header, Navbar, Mask} from './clients'
export default function Template(props: { export default function Template(props: {
@@ -13,7 +13,9 @@ export default function Template(props: {
</div> </div>
<div className="col-start-2 row-start-1 bg-card overflow-hidden relative z-20"> <div className="col-start-2 row-start-1 bg-card overflow-hidden relative z-20">
<Suspense>
<Header/> <Header/>
</Suspense>
</div> </div>
<svg className="col-start-2 row-start-2 w-full h-full z-20 pointer-events-none" preserveAspectRatio="none"> <svg className="col-start-2 row-start-2 w-full h-full z-20 pointer-events-none" preserveAspectRatio="none">

View File

@@ -8,7 +8,7 @@ import zod from 'zod'
import {toast} from 'sonner' import {toast} from 'sonner'
import {useStatus} from '@/lib/states' import {useStatus} from '@/lib/states'
import {ExtraResp} from '@/lib/api' import {ExtraResp} from '@/lib/api'
import {listResourceLong, listResourceShort} from '@/actions/resource' import {listResourceLong, listResourceShort, updateCheckip} from '@/actions/resource'
import DataTable from '@/components/data-table' import DataTable from '@/components/data-table'
import {ColumnDef} from '@tanstack/react-table' import {ColumnDef} from '@tanstack/react-table'
import {Resource} from '@/lib/models/resource' import {Resource} from '@/lib/models/resource'
@@ -21,6 +21,7 @@ import {
isValidResourceType, isValidResourceType,
ResourceTypeBadge, ResourceTypeBadge,
} from './utils' } from './utils'
import {Button} from '@/components/ui/button'
const filterSchema = zod.object({ const filterSchema = zod.object({
resource_no: zod.string().optional().default(''), resource_no: zod.string().optional().default(''),
@@ -130,11 +131,31 @@ export default function ResourceList({resourceType}: ResourceListProps) {
}) })
} }
const handleCheckipChange = async (id: number, currentCheckip: boolean) => {
try {
const result = await updateCheckip({
id: id,
checkip: !currentCheckip,
})
if (result.success) {
toast.success(`IP检查已${!currentCheckip ? '启用' : '停用'}`)
await refresh(data.page, data.size)
}
else {
throw new Error(result.message || '操作失败')
}
}
catch (e) {
toast.error(e instanceof Error ? e.message : '更新IP检查状态失败')
}
}
// 表格列定义 // 表格列定义
const columns = useMemo<ColumnDef<Resource<1> | Resource<2>>[]>(() => { const columns = useMemo<ColumnDef<Resource<1> | Resource<2>>[]>(() => {
const resourceKey = isLong ? 'long' : 'short' const resourceKey = isLong ? 'long' : 'short'
const baseColumns: ColumnDef<Resource<1> | Resource<2>>[] = [ const baseColumns = ([
{ {
header: '套餐编号', header: '套餐编号',
cell: ({row}) => { cell: ({row}) => {
@@ -218,7 +239,11 @@ export default function ResourceList({resourceType}: ResourceListProps) {
{ {
header: '开通时间', header: '开通时间',
cell: ({row}) => formatDateTime(row.original.created_at), cell: ({row}) => formatDateTime(row.original.created_at),
}, }, // 短效资源增加到期时间列
!isLong ? {
header: '到期时间',
cell: ({row}) => formatDateTime((row.original as Resource<1>).short.expire_at),
} : undefined,
{ {
header: '状态', header: '状态',
cell: ({row}) => { cell: ({row}) => {
@@ -230,15 +255,22 @@ export default function ResourceList({resourceType}: ResourceListProps) {
) )
}, },
}, },
] {
header: '操作',
// 短效资源增加到期时间列 cell: ({row}) => {
if (!isLong) { const checkip = row.original.checkip
baseColumns.push({ return (
header: '到期时间', <Button
cell: ({row}) => formatDateTime((row.original as Resource<1>).short.expire_at), theme={checkip ? 'fail' : 'default'}
}) className="h-7 px-3 text-sm"
} onClick={() => handleCheckipChange(row.original.id, row.original.checkip)}
>
{checkip ? '停用IP检查' : '启用IP检查'}
</Button>
)
},
},
] satisfies ((ColumnDef<Resource<1> | Resource<2>> | undefined)[])).filter(Boolean) as ColumnDef<Resource<1> | Resource<2>>[]
return baseColumns return baseColumns
}, [isLong]) }, [isLong])

View File

@@ -9,7 +9,7 @@ import {Button} from '@/components/ui/button'
import {useForm, useFormContext, useWatch} from 'react-hook-form' import {useForm, useFormContext, useWatch} from 'react-hook-form'
import {Alert, AlertTitle} from '@/components/ui/alert' import {Alert, AlertTitle} from '@/components/ui/alert'
import {ArrowRight, Box, CircleAlert, CopyIcon, ExternalLinkIcon, LinkIcon, Loader, Plus, Timer} from 'lucide-react' import {ArrowRight, Box, CircleAlert, CopyIcon, ExternalLinkIcon, LinkIcon, Loader, Plus, Timer} from 'lucide-react'
import {memo, ReactNode, useEffect, useRef, useState} from 'react' import {memo, ReactNode, Suspense, use, useEffect, useRef, useState} from 'react'
import {useStatus} from '@/lib/states' import {useStatus} from '@/lib/states'
import {allResource} from '@/actions/resource' import {allResource} from '@/actions/resource'
import {Resource} from '@/lib/models' import {Resource} from '@/lib/models'
@@ -28,10 +28,11 @@ const schema = z.object({
city: z.string().optional(), city: z.string().optional(),
regionType: z.enum(['unlimited', 'specific']).default('unlimited'), regionType: z.enum(['unlimited', 'specific']).default('unlimited'),
isp: z.enum(['all', '1', '2', '3'], {required_error: '请选择运营商'}), isp: z.enum(['all', '1', '2', '3'], {required_error: '请选择运营商'}),
proto: z.enum(['all', '1', '2', '3'], {required_error: '请选择协议'}), proto: z.enum(['all', '1', '2'], {required_error: '请选择协议'}),
authType: z.enum(['1', '2'], {required_error: '请选择认证方式'}), authType: z.enum(['1', '2'], {required_error: '请选择认证方式'}),
distinct: z.enum(['1', '0'], {required_error: '请选择去重选项'}), distinct: z.enum(['1', '0'], {required_error: '请选择去重选项'}),
format: z.enum(['text', 'json'], {required_error: '请选择导出格式'}), format: z.enum(['text', 'json'], {required_error: '请选择导出格式'}),
hostFormat: z.enum(['domain', 'ip'], {required_error: '请选择主机格式'}),
separator: z.string({required_error: '请选择分隔符'}), separator: z.string({required_error: '请选择分隔符'}),
breaker: z.string({required_error: '请选择换行符'}), breaker: z.string({required_error: '请选择换行符'}),
count: z.number({required_error: '请输入有效的数量'}).min(1), count: z.number({required_error: '请输入有效的数量'}).min(1),
@@ -53,6 +54,7 @@ export default function Extract(props: ExtractProps) {
authType: '1', authType: '1',
count: 1, count: 1,
distinct: '1', distinct: '1',
hostFormat: 'domain',
format: 'text', format: 'text',
breaker: '13,10', breaker: '13,10',
separator: '124', separator: '124',
@@ -71,7 +73,7 @@ export default function Extract(props: ExtractProps) {
)} )}
> >
<CardSection> <CardSection>
<Alert variant="warn" className="flex items-center justify-between"> {/* <Alert variant="warn" className="flex items-center justify-between">
<span className="flex items-center gap-2"> <span className="flex items-center gap-2">
<CircleAlert/> <CircleAlert/>
<AlertTitle className="flex text-gray-900">提取IP前需要将本机IP添加到白名单后才可使用</AlertTitle> <AlertTitle className="flex text-gray-900">提取IP前需要将本机IP添加到白名单后才可使用</AlertTitle>
@@ -83,7 +85,7 @@ export default function Extract(props: ExtractProps) {
<span>添加白名单</span> <span>添加白名单</span>
<ArrowRight className="size-4"/> <ArrowRight className="size-4"/>
</Link> </Link>
</Alert> </Alert> */}
<FormFields/> <FormFields/>
</CardSection> </CardSection>
@@ -113,7 +115,9 @@ const FormFields = memo(() => {
return ( return (
<div className="flex flex-col gap-6 items-stretch max-w-[calc(160px*4+1rem*3)]"> <div className="flex flex-col gap-6 items-stretch max-w-[calc(160px*4+1rem*3)]">
{/* 选择套餐 */} {/* 选择套餐 */}
<Suspense>
<SelectResource/> <SelectResource/>
</Suspense>
{/* 地区筛选 */} {/* 地区筛选 */}
<SelectRegion/> <SelectRegion/>
@@ -161,12 +165,12 @@ const FormFields = memo(() => {
<RadioGroupItem value="1" id={`${id}-v-http`} className="mr-2"/> <RadioGroupItem value="1" id={`${id}-v-http`} className="mr-2"/>
<span>HTTP</span> <span>HTTP</span>
</FormLabel> </FormLabel>
<FormLabel htmlFor={`${id}-v-https`} className="px-3 h-10 border rounded-md flex items-center text-sm"> {/* <FormLabel htmlFor={`${id}-v-https`} className="px-3 h-10 border rounded-md flex items-center text-sm">
<RadioGroupItem value="2" id={`${id}-v-https`} className="mr-2"/> <RadioGroupItem value="2" id={`${id}-v-https`} className="mr-2"/>
<span>HTTPS</span> <span>HTTPS</span>
</FormLabel> </FormLabel> */}
<FormLabel htmlFor={`${id}-v-socks5`} className="px-3 h-10 border rounded-md flex items-center text-sm"> <FormLabel htmlFor={`${id}-v-socks5`} className="px-3 h-10 border rounded-md flex items-center text-sm">
<RadioGroupItem value="3" id={`${id}-v-socks5`} className="mr-2"/> <RadioGroupItem value="2" id={`${id}-v-socks5`} className="mr-2"/>
<span>SOCKS5</span> <span>SOCKS5</span>
</FormLabel> </FormLabel>
</RadioGroup> </RadioGroup>
@@ -231,6 +235,26 @@ const FormFields = memo(() => {
)} )}
</FormField> </FormField>
{/* 主机格式 */}
<FormField name="hostFormat" className="md:max-w-[calc(160px*2+1rem)]" label="主机格式" classNames={{label: 'max-md:text-sm'}}>
{({id, field}) => (
<RadioGroup
onValueChange={field.onChange}
defaultValue={field.value}
className="flex gap-4"
>
<FormLabel htmlFor={`${id}-v-domain`} className="px-3 h-10 flex-1 border rounded-md flex items-center text-sm">
<RadioGroupItem value="domain" id={`${id}-v-domain`} className="mr-2"/>
<span></span>
</FormLabel>
<FormLabel htmlFor={`${id}-v-ip`} className="px-3 h-10 flex-1 border rounded-md flex items-center text-sm">
<RadioGroupItem value="ip" id={`${id}-v-ip`} className="mr-2"/>
<span>IP</span>
</FormLabel>
</RadioGroup>
)}
</FormField>
{/* 分隔符 */} {/* 分隔符 */}
<FormField name="separator" className="md:max-w-[calc(160px*3+1rem*2)]" label="分隔符" classNames={{label: 'max-md:text-sm'}}> <FormField name="separator" className="md:max-w-[calc(160px*3+1rem*2)]" label="分隔符" classNames={{label: 'max-md:text-sm'}}>
{({id, field}) => ( {({id, field}) => (
@@ -332,8 +356,13 @@ FormFields.displayName = 'FormFields'
function SelectResource() { function SelectResource() {
const [resources, setResources] = useState<Resource[]>([]) const [resources, setResources] = useState<Resource[]>([])
const [status, setStatus] = useStatus() const [status, setStatus] = useStatus()
const profile = useProfileStore(state => state.profile) const profile = use(useProfileStore(store => store.profile))
const getResources = async () => { const getResources = async () => {
if (!profile) {
setStatus('done')
setResources([])
return
}
setStatus('load') setStatus('load')
try { try {
const resp = await allResource() const resp = await allResource()
@@ -352,7 +381,7 @@ function SelectResource() {
useEffect(() => { useEffect(() => {
getResources().then() getResources().then()
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [profile])
return ( return (
<FormField name="resource" className="md:max-w-[calc(160px*2+1rem)]" label="选择套餐" classNames={{label: 'max-md:text-sm'}}> <FormField name="resource" className="md:max-w-[calc(160px*2+1rem)]" label="选择套餐" classNames={{label: 'max-md:text-sm'}}>
@@ -372,12 +401,10 @@ function SelectResource() {
</div> </div>
) : !profile ? ( ) : !profile ? (
<div className="p-4 flex gap-1 items-center"> <div className="p-4 flex gap-1 items-center">
<Loader className="animate-spin" size={20}/> <span className="text-gray-600"><Link href="/login" className="text-blue-600 hover:text-blue-700 font-medium"></Link></span>
<span><Link href="/login" className="text-blue-600 hover:underline"></Link></span>
</div> </div>
) : resources.length === 0 ? ( ) : resources.length === 0 ? (
<div className="p-4 flex gap-1 items-center"> <div className="p-4 flex gap-1 items-center">
<Loader className="animate-spin" size={20}/>
<span></span> <span></span>
</div> </div>
) : ( ) : (
@@ -489,6 +516,8 @@ function SelectRegion() {
const regionType = useWatch({control, name: 'regionType'}) const regionType = useWatch({control, name: 'regionType'})
const prov = useWatch({control, name: 'prov'}) const prov = useWatch({control, name: 'prov'})
const city = useWatch({control, name: 'city'}) const city = useWatch({control, name: 'city'})
console.log(regionType, 'regionType')
console.log(prov, 'prov', city, 'city')
return ( return (
<div className="flex flex-col gap-4 md:max-w-[calc(160px*2+1rem)]"> <div className="flex flex-col gap-4 md:max-w-[calc(160px*2+1rem)]">
@@ -599,25 +628,40 @@ function ApplyLink() {
} }
return ( return (
<div className={merge( <div className="flex flex-col gap-3 rounded-lg">
`flex flex-col gap-4`, <Alert variant="warn" className="flex items-center justify-between">
`rounded-lg`, <div className="flex items-center gap-2">
)}> <CircleAlert className="size-4 shrink-0"/>
<h4>API </h4> <AlertTitle className="text-orange-600">
IP IP 使
</AlertTitle>
</div>
<Link href="/admin/whitelist" className="flex-none text-orange-600 font-medium flex items-center gap-1">
<span></span>
<ArrowRight className="size-4"/>
</Link>
</Alert>
{/* 展示链接地址 */} <Alert className="flex items-center justify-between">
<div className="bg-secondary p-4 rounded-md break-all"> <div className="flex items-center gap-2">
<CircleAlert className="size-4 shrink-0"/>
<AlertTitle> socks5 http </AlertTitle>
</div>
<div className="w-[88px]"/>
</Alert>
<h4 className="text-base font-medium">API </h4>
<div className="bg-gray-100 rounded-md p-4 break-all font-mono text-sm">
{link(form.getValues())} {link(form.getValues())}
</div> </div>
{/* 操作 */} <div className="flex gap-3">
<div className="flex gap-4"> <Button type="button" onClick={() => submit('copy')} className="gap-1">
<Button type="button" onClick={() => submit('copy')}> <CopyIcon className="size-4"/>
<CopyIcon/>
<span></span> <span></span>
</Button> </Button>
<Button type="button" onClick={() => submit('open')}> <Button type="button" onClick={() => submit('open')} className="gap-1">
<ExternalLinkIcon/> <ExternalLinkIcon className="size-4"/>
<span></span> <span></span>
</Button> </Button>
</div> </div>
@@ -626,7 +670,7 @@ function ApplyLink() {
} }
function link(values: Schema) { function link(values: Schema) {
const {resource, prov, city, isp, proto, authType, distinct, format: formatType, separator, breaker, count} = values const {resource, prov, city, isp, proto, authType, distinct, format: formatType, hostFormat, separator, breaker, count} = values
const sp = new URLSearchParams() const sp = new URLSearchParams()
if (resource) sp.set('i', String(resource)) if (resource) sp.set('i', String(resource))
@@ -638,6 +682,7 @@ function link(values: Schema) {
if (isp != 'all') sp.set('s', isp) if (isp != 'all') sp.set('s', isp)
sp.set('d', distinct) sp.set('d', distinct)
sp.set('rt', formatType) sp.set('rt', formatType)
sp.set('rh', hostFormat)
sp.set('rs', separator) sp.set('rs', separator)
sp.set('rb', breaker) sp.set('rb', breaker)
sp.set('n', String(count)) sp.set('n', String(count))

View File

@@ -17,21 +17,21 @@ export type PaymentModalProps = {
export function PaymentModal(props: PaymentModalProps) { export function PaymentModal(props: PaymentModalProps) {
// 手动关闭时的处理 // 手动关闭时的处理
const handleClose = async () => { const handleClose = async () => {
try { // try {
const res = await payClose({ // const res = await payClose({
trade_no: props.inner_no, // trade_no: props.inner_no,
method: props.method, // method: props.method,
}) // })
if (!res.success) { // if (!res.success) {
throw new Error(res.message) // throw new Error(res.message)
} // }
} // }
catch (error) { // catch (error) {
console.error('关闭订单失败:', error) // console.error('关闭订单失败:', error)
} // }
finally { // finally {
props.onClose?.() props.onClose?.()
} // }
} }
// SSE处理方式检查支付状态 // SSE处理方式检查支付状态

View File

@@ -3,18 +3,18 @@ import {FormField} from '@/components/ui/form'
import {RadioGroup} from '@/components/ui/radio-group' import {RadioGroup} from '@/components/ui/radio-group'
import FormOption from '@/components/composites/purchase/option' import FormOption from '@/components/composites/purchase/option'
import {Schema} from '@/components/composites/purchase/long/form' import {Schema} from '@/components/composites/purchase/long/form'
import {useEffect} from 'react' import {useEffect, useMemo} from 'react'
import {useFormContext, useWatch} from 'react-hook-form' import {useFormContext, useWatch} from 'react-hook-form'
import {Card} from '@/components/ui/card' import {Card} from '@/components/ui/card'
import {BillingMethodField} from '../shared/billing-method-field' import {BillingMethodField} from '../shared/billing-method-field'
import {FeatureList} from '../shared/feature-list' import {FeatureList} from '../shared/feature-list'
import {NumberStepperField} from '../shared/number-stepper-field' import {NumberStepperField} from '../shared/number-stepper-field'
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuPrice, hasPurchaseSku, PurchaseSkuData} from '../shared/sku' import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuCountMin, getPurchaseSkuPrice, hasPurchaseSku, PurchaseSkuData} from '../shared/sku'
export default function Center({skuData}: { export default function Center({skuData}: {
skuData: PurchaseSkuData skuData: PurchaseSkuData
}) { }) {
const {setValue} = useFormContext<Schema>() const {setValue, getValues} = useFormContext<Schema>()
const type = useWatch<Schema>({name: 'type'}) as Schema['type'] const type = useWatch<Schema>({name: 'type'}) as Schema['type']
const live = useWatch<Schema>({name: 'live'}) as Schema['live'] const live = useWatch<Schema>({name: 'live'}) as Schema['live']
const expire = useWatch<Schema>({name: 'expire'}) as Schema['expire'] const expire = useWatch<Schema>({name: 'expire'}) as Schema['expire']
@@ -26,18 +26,35 @@ export default function Center({skuData}: {
? getAvailablePurchaseExpires(skuData, {mode: type, live}) ? getAvailablePurchaseExpires(skuData, {mode: type, live})
: [] : []
const currentCountMin = useMemo(() => {
if (!type || !live) return 0
const expireValue = type === '1' ? expire : '0'
const countMin = getPurchaseSkuCountMin(skuData, {
mode: type,
live,
expire: expireValue,
})
return countMin
}, [type, live, expire, skuData])
useEffect(() => {
if (currentCountMin <= 0) return
const targetField = type === '1' ? 'daily_limit' : 'quota'
const currentValue = getValues(targetField)
if (currentValue !== currentCountMin) {
setValue(targetField, currentCountMin, {shouldValidate: true})
}
}, [currentCountMin, type, setValue, getValues])
useEffect(() => { useEffect(() => {
const nextType = modeList.includes(type) ? type : modeList[0] const nextType = modeList.includes(type) ? type : modeList[0]
if (!nextType) { if (!nextType) {
return return
} }
if (nextType !== type) { if (nextType !== type) {
setValue('type', nextType) setValue('type', nextType)
return return
} }
const nextLiveList = nextType === '1' const nextLiveList = nextType === '1'
? getAvailablePurchaseLives(skuData, {mode: nextType, expire}) ? getAvailablePurchaseLives(skuData, {mode: nextType, expire})
: getAvailablePurchaseLives(skuData, {mode: nextType}) : getAvailablePurchaseLives(skuData, {mode: nextType})
@@ -62,14 +79,45 @@ export default function Center({skuData}: {
}, [expire, live, modeList, setValue, skuData, type]) }, [expire, live, modeList, setValue, skuData, type])
return ( return (
<Card className="flex-auto p-6 flex flex-col gap-6 relative"> <Card className="flex-auto p-6 flex flex-col gap-10 relative">
<div className="text-center -mb-10"> HTTPsocks5 </div>
<BillingMethodField modeList={modeList} timeDailyLimit={100}/> <BillingMethodField modeList={modeList} timeDailyLimit={100}/>
{/* 套餐时效 */}
{type === '1' && (
<FormField name="expire" label="套餐有效时间" description="有效时间内可用于提取 IP">
{({id, field}) => (
<RadioGroup
id={id}
value={field.value}
onValueChange={(value) => {
field.onChange(value)
const nextLiveList = getAvailablePurchaseLives(skuData, {mode: type, expire: value})
if (!nextLiveList.includes(live) && nextLiveList[0]) {
setValue('live', nextLiveList[0])
}
}}
className="flex gap-4 flex-wrap">
{expireList.map(day => (
<FormOption
key={day}
id={`${id}-${day}`}
value={day}
label={`${day}`}
compare={field.value}
/>
))}
</RadioGroup>
)}
</FormField>
)}
{/* IP 时效 */} {/* IP 时效 */}
<FormField<Schema, 'live'> <FormField<Schema, 'live'>
className="space-y-4"
name="live" name="live"
label="IP 时效"> label="IP 有效时间"
description="提取出的 IP 可用时间"
>
{({id, field}) => ( {({id, field}) => (
<RadioGroup <RadioGroup
id={id} id={id}
@@ -111,49 +159,21 @@ export default function Center({skuData}: {
)} )}
</FormField> </FormField>
{/* 套餐时效 */}
{type === '1' && (
<FormField className="space-y-4" name="expire" label="套餐时效">
{({id, field}) => (
<RadioGroup
id={id}
value={field.value}
onValueChange={(value) => {
field.onChange(value)
const nextLiveList = getAvailablePurchaseLives(skuData, {mode: type, expire: value})
if (!nextLiveList.includes(live) && nextLiveList[0]) {
setValue('live', nextLiveList[0])
}
}}
className="flex gap-4 flex-wrap">
{expireList.map(day => (
<FormOption
key={day}
id={`${id}-${day}`}
value={day}
label={`${day}`}
compare={field.value}
/>
))}
</RadioGroup>
)}
</FormField>
)}
{/* 每日提取上限/购买数量 */} {/* 每日提取上限/购买数量 */}
{type === '1' ? ( {type === '1' ? (
<NumberStepperField <NumberStepperField
name="daily_limit" name="daily_limit"
label="每日提取上限" label="IP 每日提取上限"
min={100} description="本套餐每日可提取 IP 的最大数量"
min={currentCountMin}
step={100} step={100}
/> />
) : ( ) : (
<NumberStepperField <NumberStepperField
name="quota" name="quota"
label="IP 购买数量" label="IP 总提取上限"
min={500} description="本套餐总计可提取 IP 的最大数量"
min={currentCountMin}
step={100} step={100}
/> />
)} )}

View File

@@ -5,26 +5,31 @@ import {Form} from '@/components/ui/form'
import * as z from 'zod' import * as z from 'zod'
import {zodResolver} from '@hookform/resolvers/zod' import {zodResolver} from '@hookform/resolvers/zod'
import {ProductItem} from '@/actions/product' import {ProductItem} from '@/actions/product'
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, parsePurchaseSkuList} from '../shared/sku' import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuCountMin, parsePurchaseSkuList} from '../shared/sku'
import {PurchaseSidePanel} from '../shared/side-panel' import {PurchaseSidePanel} from '../shared/side-panel'
const schema = z.object({ const schema = z.object({
type: z.enum(['1', '2']).default('2'), type: z.enum(['1', '2']).default('2'),
live: z.string(), live: z.string(),
quota: z.number().min(500, '购买数量不能少于 500 个'), quota: z.number().min(1, '购买数量不能少于 1 个'),
expire: z.string(), expire: z.string(),
daily_limit: z.number().min(100, '每日限额不能少于 100 个'), daily_limit: z.number().min(1, '每日限额不能少于 1 个'),
pay_type: z.enum(['wechat', 'alipay', 'balance']), pay_type: z.enum(['wechat', 'alipay', 'balance']),
}) })
export type Schema = z.infer<typeof schema> export type Schema = z.infer<typeof schema>
export default function LongForm({skuList}: {skuList: ProductItem['skus']}) { export default function LongForm({skuList}: {skuList: ProductItem['skus']}) {
const skuData = parsePurchaseSkuList('long', skuList) const skuData = parsePurchaseSkuList('long', skuList)
const defaultMode = skuData.modeList.includes('2') ? '2' : '1' const defaultMode = skuData.modeList.includes('1') ? '1' : '2'
const defaultLive = getAvailablePurchaseLives(skuData, {mode: defaultMode})[0] || '' const defaultLive = getAvailablePurchaseLives(skuData, {mode: defaultMode})[0] || ''
const defaultExpire = defaultMode === '1' const defaultExpire = defaultMode === '1'
? getAvailablePurchaseExpires(skuData, {mode: defaultMode, live: defaultLive})[0] || '0' ? getAvailablePurchaseExpires(skuData, {mode: defaultMode, live: defaultLive})[0] || '0'
: '0' : '0'
const defaultCountMin = getPurchaseSkuCountMin(skuData, {
mode: defaultMode,
live: defaultLive,
expire: defaultExpire,
})
const form = useForm<Schema>({ const form = useForm<Schema>({
resolver: zodResolver(schema), resolver: zodResolver(schema),
@@ -32,8 +37,8 @@ export default function LongForm({skuList}: {skuList: ProductItem['skus']}) {
type: defaultMode, type: defaultMode,
live: defaultLive, live: defaultLive,
expire: defaultExpire, expire: defaultExpire,
quota: 500, quota: defaultCountMin,
daily_limit: 100, daily_limit: defaultCountMin,
pay_type: 'balance', // 余额支付 pay_type: 'balance', // 余额支付
}, },
}) })

View File

@@ -11,7 +11,7 @@ export function BillingMethodField(props: {
modeList: PurchaseMode[] modeList: PurchaseMode[]
timeDailyLimit: number timeDailyLimit: number
}) { }) {
const {setValue} = useFormContext<PurchaseFormValues>() const {setValue, getValues} = useFormContext<PurchaseFormValues>()
return ( return (
<FormField<PurchaseFormValues, 'type'> <FormField<PurchaseFormValues, 'type'>
@@ -30,20 +30,10 @@ export function BillingMethodField(props: {
setValue('expire', '0') setValue('expire', '0')
return return
} }
setValue('expire', getValues('expire') || '0')
setValue('daily_limit', props.timeDailyLimit)
}} }}
className="flex gap-4 max-md:flex-col" className="flex gap-4 max-md:flex-col"
> >
{props.modeList.includes('2') && (
<FormOption
id={`${id}-2`}
value="2"
label="包量套餐"
description="适用于短期或不定期高提取业务场景"
compare={field.value}
/>
)}
{props.modeList.includes('1') && ( {props.modeList.includes('1') && (
<FormOption <FormOption
@@ -54,6 +44,15 @@ export function BillingMethodField(props: {
compare={field.value} compare={field.value}
/> />
)} )}
{props.modeList.includes('2') && (
<FormOption
id={`${id}-2`}
value="2"
label="包量套餐"
description="适用于短期或不定期高提取业务场景"
compare={field.value}
/>
)}
</RadioGroup> </RadioGroup>
)} )}
</FormField> </FormField>

View File

@@ -12,6 +12,7 @@ type PurchaseStepperFieldName = 'quota' | 'daily_limit'
type NumberStepperFieldProps = { type NumberStepperFieldProps = {
name: PurchaseStepperFieldName name: PurchaseStepperFieldName
label: string label: string
description?: string
min: number min: number
step: number step: number
} }
@@ -25,7 +26,7 @@ export function NumberStepperField(props: NumberStepperFieldProps) {
return ( return (
<FormField<PurchaseFormValues, PurchaseStepperFieldName> <FormField<PurchaseFormValues, PurchaseStepperFieldName>
className="space-y-4" description={props.description}
name={props.name} name={props.name}
label={props.label} label={props.label}
> >
@@ -49,6 +50,9 @@ export function NumberStepperField(props: NumberStepperFieldProps) {
className="w-40 h-10 border border-gray-200 rounded-sm text-center" className="w-40 h-10 border border-gray-200 rounded-sm text-center"
min={props.min} min={props.min}
step={props.step} step={props.step}
onInvalid={(e) => {
e.preventDefault()
}}
onBlur={(event) => { onBlur={(event) => {
field.onBlur() field.onBlur()
const nextValue = Number(event.target.value) const nextValue = Number(event.target.value)

View File

@@ -14,6 +14,7 @@ import {ExtraResp} from '@/lib/api'
import {formatPurchaseLiveLabel} from './sku' import {formatPurchaseLiveLabel} from './sku'
import {User} from '@/lib/models' import {User} from '@/lib/models'
import {PurchaseFormValues} from './form-values' import {PurchaseFormValues} from './form-values'
import {IdCard} from 'lucide-react'
const emptyPrice: ExtraResp<typeof getPrice> = { const emptyPrice: ExtraResp<typeof getPrice> = {
price: '0.00', price: '0.00',
@@ -107,6 +108,7 @@ export function PurchaseSidePanel(props: PurchaseSidePanelProps) {
<span className="text-xl text-orange-500">{discountedPrice}</span> <span className="text-xl text-orange-500">{discountedPrice}</span>
</p> </p>
{profile ? ( {profile ? (
profile.id_type !== 0 ? (
<> <>
<FieldPayment balance={profile.balance}/> <FieldPayment balance={profile.balance}/>
<Pay <Pay
@@ -116,9 +118,23 @@ export function PurchaseSidePanel(props: PurchaseSidePanelProps) {
resource={resource} resource={resource}
/> />
</> </>
) : (
<div className="flex flex-col gap-3">
<p className="text-sm text-gray-500">
</p>
<Link
href="/admin/identify"
className={buttonVariants()}
>
<IdCard size={16} className="mr-1"/>
</Link>
</div>
)
) : ( ) : (
<Link href="/login" className={buttonVariants()}> <Link href="/login" className={buttonVariants()}>
</Link> </Link>
)} )}
</Card> </Card>

View File

@@ -7,11 +7,13 @@ export type PurchaseSkuItem = {
live: string live: string
expire: string expire: string
price: string price: string
count_min: number
} }
export type PurchaseSkuData = { export type PurchaseSkuData = {
items: PurchaseSkuItem[] items: PurchaseSkuItem[]
priceMap: Map<string, string> priceMap: Map<string, string>
countMinMap: Map<string, number>
modeList: PurchaseMode[] modeList: PurchaseMode[]
liveList: string[] liveList: string[]
expireList: string[] expireList: string[]
@@ -24,6 +26,7 @@ export function parsePurchaseSkuList(kind: PurchaseKind, skuList: ProductItem['s
const items: PurchaseSkuItem[] = [] const items: PurchaseSkuItem[] = []
const priceMap = new Map<string, string>() const priceMap = new Map<string, string>()
const countMinMap = new Map<string, number>()
const modeSet = new Set<PurchaseMode>() const modeSet = new Set<PurchaseMode>()
const liveSet = new Set<number>() const liveSet = new Set<number>()
const expireSet = new Set<number>() const expireSet = new Set<number>()
@@ -45,6 +48,8 @@ export function parsePurchaseSkuList(kind: PurchaseKind, skuList: ProductItem['s
live: liveValue, live: liveValue,
expire: expireValue, expire: expireValue,
}) })
const countMin = typeof sku.count_min === 'number' ? sku.count_min : Number(sku.count_min) || 0
countMinMap.set(code, countMin)
items.push({ items.push({
code, code,
@@ -52,6 +57,7 @@ export function parsePurchaseSkuList(kind: PurchaseKind, skuList: ProductItem['s
live: liveValue, live: liveValue,
expire: expireValue, expire: expireValue,
price: sku.price, price: sku.price,
count_min: countMin,
}) })
priceMap.set(code, sku.price) priceMap.set(code, sku.price)
modeSet.add(mode) modeSet.add(mode)
@@ -75,6 +81,7 @@ export function parsePurchaseSkuList(kind: PurchaseKind, skuList: ProductItem['s
return { return {
items, items,
priceMap, priceMap,
countMinMap,
modeList: (['2', '1'] as const).filter(mode => modeSet.has(mode)), modeList: (['2', '1'] as const).filter(mode => modeSet.has(mode)),
liveList: sortNumericValues(liveSet), liveList: sortNumericValues(liveSet),
expireList: sortNumericValues(expireSet), expireList: sortNumericValues(expireSet),
@@ -163,3 +170,11 @@ export function formatPurchaseLiveLabel(live: string, kind: PurchaseKind) {
return `${minutes} 分钟` return `${minutes} 分钟`
} }
export function getPurchaseSkuCountMin(
skuData: PurchaseSkuData,
props: {mode: PurchaseMode, live: string, expire: string},
): number {
const key = getPurchaseSkuKey(props)
return skuData.countMinMap.get(key) ?? 0
}

View File

@@ -2,21 +2,21 @@
import {FormField} from '@/components/ui/form' import {FormField} from '@/components/ui/form'
import {RadioGroup} from '@/components/ui/radio-group' import {RadioGroup} from '@/components/ui/radio-group'
import FormOption from '@/components/composites/purchase/option' import FormOption from '@/components/composites/purchase/option'
import {useEffect} from 'react' import {useEffect, useMemo} from 'react'
import {useFormContext, useWatch} from 'react-hook-form' import {useFormContext, useWatch} from 'react-hook-form'
import {Schema} from '@/components/composites/purchase/short/form' import {Schema} from '@/components/composites/purchase/short/form'
import {Card} from '@/components/ui/card' import {Card} from '@/components/ui/card'
import {BillingMethodField} from '../shared/billing-method-field' import {BillingMethodField} from '../shared/billing-method-field'
import {FeatureList} from '../shared/feature-list' import {FeatureList} from '../shared/feature-list'
import {NumberStepperField} from '../shared/number-stepper-field' import {NumberStepperField} from '../shared/number-stepper-field'
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuPrice, hasPurchaseSku, PurchaseSkuData} from '../shared/sku' import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuCountMin, getPurchaseSkuPrice, hasPurchaseSku, PurchaseSkuData} from '../shared/sku'
export default function Center({ export default function Center({
skuData, skuData,
}: { }: {
skuData: PurchaseSkuData skuData: PurchaseSkuData
}) { }) {
const {setValue} = useFormContext<Schema>() const {setValue, getValues} = useFormContext<Schema>()
const type = useWatch<Schema>({name: 'type'}) as Schema['type'] const type = useWatch<Schema>({name: 'type'}) as Schema['type']
const live = useWatch<Schema>({name: 'live'}) as Schema['live'] const live = useWatch<Schema>({name: 'live'}) as Schema['live']
const expire = useWatch<Schema>({name: 'expire'}) as Schema['expire'] const expire = useWatch<Schema>({name: 'expire'}) as Schema['expire']
@@ -28,6 +28,22 @@ export default function Center({
? getAvailablePurchaseExpires(skuData, {mode: type, live}) ? getAvailablePurchaseExpires(skuData, {mode: type, live})
: [] : []
const currentCountMin = useMemo(() => {
if (!type || !live) return 0
const expireValue = type === '1' ? expire : '0'
return getPurchaseSkuCountMin(skuData, {mode: type, live, expire: expireValue})
}, [type, live, expire, skuData])
useEffect(() => {
if (currentCountMin <= 0) return
const targetField = type === '1' ? 'daily_limit' : 'quota'
const currentValue = getValues(targetField)
if (currentValue !== currentCountMin) {
setValue(targetField, currentCountMin, {shouldValidate: true})
}
}, [currentCountMin, type, setValue, getValues])
useEffect(() => { useEffect(() => {
const nextType = modeList.includes(type) ? type : modeList[0] const nextType = modeList.includes(type) ? type : modeList[0]
@@ -64,14 +80,45 @@ export default function Center({
}, [expire, live, modeList, setValue, skuData, type]) }, [expire, live, modeList, setValue, skuData, type])
return ( return (
<Card className="flex-auto p-6 flex flex-col gap-6 relative"> <Card className="flex-auto p-6 flex flex-col gap-10 relative">
<div className="text-center -mb-10"> HTTPsocks5 </div>
<BillingMethodField modeList={modeList} timeDailyLimit={2000}/> <BillingMethodField modeList={modeList} timeDailyLimit={2000}/>
{/* 套餐时效 */}
{type === '1' && (
<FormField name="expire" label="套餐有效时间" description="有效时间内可用于提取 IP">
{({id, field}) => (
<RadioGroup
id={id}
value={field.value}
onValueChange={(value) => {
field.onChange(value)
const nextLiveList = getAvailablePurchaseLives(skuData, {mode: type, expire: value})
if (!nextLiveList.includes(live) && nextLiveList[0]) {
setValue('live', nextLiveList[0])
}
}}
className="flex gap-4 flex-wrap">
{expireList.map(day => (
<FormOption
key={day}
id={`${id}-${day}`}
value={day}
label={`${day}`}
compare={field.value}
/>
))}
</RadioGroup>
)}
</FormField>
)}
{/* IP 时效 */} {/* IP 时效 */}
<FormField<Schema, 'live'> <FormField<Schema, 'live'>
className="space-y-4"
name="live" name="live"
label="IP 时效"> label="IP 有效时间"
description="提取出的 IP 可用时间"
>
{({id, field}) => ( {({id, field}) => (
<RadioGroup <RadioGroup
id={id} id={id}
@@ -116,49 +163,21 @@ export default function Center({
)} )}
</FormField> </FormField>
{/* 套餐时效 */}
{type === '1' && (
<FormField className="space-y-4" name="expire" label="套餐时效">
{({id, field}) => (
<RadioGroup
id={id}
value={field.value}
onValueChange={(value) => {
field.onChange(value)
const nextLiveList = getAvailablePurchaseLives(skuData, {mode: type, expire: value})
if (!nextLiveList.includes(live) && nextLiveList[0]) {
setValue('live', nextLiveList[0])
}
}}
className="flex gap-4 flex-wrap">
{expireList.map(day => (
<FormOption
key={day}
id={`${id}-${day}`}
value={day}
label={`${day}`}
compare={field.value}
/>
))}
</RadioGroup>
)}
</FormField>
)}
{/* 每日提取上限/购买数量 */} {/* 每日提取上限/购买数量 */}
{type === '1' ? ( {type === '1' ? (
<NumberStepperField <NumberStepperField
name="daily_limit" name="daily_limit"
label="每日提取上限" label="IP 每日提取上限"
min={2000} description="本套餐每日可提取 IP 的最大数量"
min={currentCountMin}
step={1000} step={1000}
/> />
) : ( ) : (
<NumberStepperField <NumberStepperField
name="quota" name="quota"
label="IP 购买数量" label="IP 总提取上限"
min={10000} description="本套餐总计可提取 IP 的最大数量"
min={currentCountMin}
step={5000} step={5000}
/> />
)} )}

View File

@@ -5,26 +5,31 @@ import {Form} from '@/components/ui/form'
import * as z from 'zod' import * as z from 'zod'
import {zodResolver} from '@hookform/resolvers/zod' import {zodResolver} from '@hookform/resolvers/zod'
import {ProductItem} from '@/actions/product' import {ProductItem} from '@/actions/product'
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, parsePurchaseSkuList} from '../shared/sku' import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuCountMin, parsePurchaseSkuList} from '../shared/sku'
import {PurchaseSidePanel} from '../shared/side-panel' import {PurchaseSidePanel} from '../shared/side-panel'
const schema = z.object({ const schema = z.object({
type: z.enum(['1', '2']).default('2'), type: z.enum(['1', '2']).default('2'),
live: z.string(), live: z.string(),
quota: z.number().min(10000, '购买数量不能少于 10000 个'), quota: z.number(),
expire: z.string(), expire: z.string(),
daily_limit: z.number().min(2000, '每日限额不能少于 2000 个'), daily_limit: z.number(),
pay_type: z.enum(['wechat', 'alipay', 'balance']).default('balance'), pay_type: z.enum(['wechat', 'alipay', 'balance']).default('balance'),
}) })
export type Schema = z.infer<typeof schema> export type Schema = z.infer<typeof schema>
export default function ShortForm({skuList}: {skuList: ProductItem['skus']}) { export default function ShortForm({skuList}: {skuList: ProductItem['skus']}) {
const skuData = parsePurchaseSkuList('short', skuList) const skuData = parsePurchaseSkuList('short', skuList)
const defaultMode = skuData.modeList.includes('2') ? '2' : '1' const defaultMode = skuData.modeList.includes('1') ? '1' : '2'
const defaultLive = getAvailablePurchaseLives(skuData, {mode: defaultMode})[0] || '' const defaultLive = getAvailablePurchaseLives(skuData, {mode: defaultMode})[0] || ''
const defaultExpire = defaultMode === '1' const defaultExpire = defaultMode === '1'
? getAvailablePurchaseExpires(skuData, {mode: defaultMode, live: defaultLive})[0] || '0' ? getAvailablePurchaseExpires(skuData, {mode: defaultMode, live: defaultLive})[0] || '0'
: '0' : '0'
const defaultCountMin = getPurchaseSkuCountMin(skuData, {
mode: defaultMode,
live: defaultLive,
expire: defaultExpire,
})
const form = useForm<Schema>({ const form = useForm<Schema>({
resolver: zodResolver(schema), resolver: zodResolver(schema),
@@ -32,8 +37,8 @@ export default function ShortForm({skuList}: {skuList: ProductItem['skus']}) {
type: defaultMode, type: defaultMode,
live: defaultLive, live: defaultLive,
expire: defaultExpire, expire: defaultExpire,
quota: 10_000, // >= 10000, quota: defaultCountMin,
daily_limit: 2_000, // >= 2000 daily_limit: defaultCountMin,
pay_type: 'balance', // 余额支付 pay_type: 'balance', // 余额支付
}, },
}) })

View File

@@ -26,7 +26,7 @@ function Resolved(props: {
router.push(profile ? '/admin/purchase' : '/product') router.push(profile ? '/admin/purchase' : '/product')
}} }}
> >
</button> </button>
) )
} }
@@ -42,7 +42,7 @@ function Pending(props: {
router.push('/product') router.push('/product')
}} }}
> >
</button> </button>
) )
} }

View File

@@ -80,18 +80,6 @@ function FormField<
) )
} }
{/* control */}
<Slot
data-slot="form-control"
aria-invalid={!!fieldState.error}
aria-describedby={
!!fieldState.error
? `${id}-description`
: `${id}-description ${id}-message`
}>
{props.children({id, field, fieldState, formState})}
</Slot>
{/* description */} {/* description */}
{!!props.description && ( {!!props.description && (
<FormDescription <FormDescription
@@ -105,6 +93,18 @@ function FormField<
</FormDescription> </FormDescription>
)} )}
{/* control */}
<Slot
data-slot="form-control"
aria-invalid={!!fieldState.error}
aria-describedby={
!!fieldState.error
? `${id}-description`
: `${id}-description ${id}-message`
}>
{props.children({id, field, fieldState, formState})}
</Slot>
{/* message */} {/* message */}
{!fieldState.error ? null : ( {!fieldState.error ? null : (
<FormMessage id={`${id}-message`} error={fieldState.error} className={props.classNames?.message}/> <FormMessage id={`${id}-message`} error={fieldState.error} className={props.classNames?.message}/>

View File

@@ -39,6 +39,17 @@ export type Bill = {
refund: Refund refund: Refund
resource: Resource resource: Resource
} }
export type Balance = {
id: number
resource_id: number
bill_no: string
amount: number
created_at: Date
trade: Trade
balance_prev: number
balance_curr: number
bill: Bill
}
export type Trade = { export type Trade = {
id: number id: number

View File

@@ -1,6 +1,7 @@
export type ProductSku = { export type ProductSku = {
id: number id: number
code: string code: string
count_min: number
name: string name: string
price: string price: string
price_min: string price_min: string

View File

@@ -29,6 +29,7 @@ export type Resource<T extends 1 | 2 = 1 | 2> = {
active: boolean active: boolean
created_at: Date created_at: Date
updated_at: Date updated_at: Date
checkip: boolean
} & ( } & (
T extends 1 ? { T extends 1 ? {
type: 1 type: 1