Compare commits
2 Commits
8f8def3a87
...
27e694ee0d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27e694ee0d | ||
|
|
74d53c619d |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lanhu-web",
|
"name": "lanhu-web",
|
||||||
"version": "1.7.0",
|
"version": "1.8.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",
|
||||||
|
|||||||
@@ -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>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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处理方式检查支付状态
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export default function Purchase() {
|
|||||||
const res = profile
|
const res = profile
|
||||||
? await listProduct({})
|
? await listProduct({})
|
||||||
: await listProductHome({})
|
: await listProductHome({})
|
||||||
|
console.log(res, 'res')
|
||||||
|
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
setProductList(res.data)
|
setProductList(res.data)
|
||||||
|
|||||||
@@ -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,6 +26,27 @@ 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'
|
||||||
|
return getPurchaseSkuCountMin(skuData, {mode: type, live, expire: expireValue})
|
||||||
|
}, [type, live, expire, skuData])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (type === '1') {
|
||||||
|
const current = getValues('daily_limit')
|
||||||
|
if (current < currentCountMin) {
|
||||||
|
setValue('daily_limit', currentCountMin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const current = getValues('quota')
|
||||||
|
if (current < currentCountMin) {
|
||||||
|
setValue('quota', currentCountMin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [currentCountMin, type, setValue, getValues])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const nextType = modeList.includes(type) ? type : modeList[0]
|
const nextType = modeList.includes(type) ? type : modeList[0]
|
||||||
|
|
||||||
@@ -146,14 +167,14 @@ export default function Center({skuData}: {
|
|||||||
<NumberStepperField
|
<NumberStepperField
|
||||||
name="daily_limit"
|
name="daily_limit"
|
||||||
label="每日提取上限"
|
label="每日提取上限"
|
||||||
min={100}
|
min={currentCountMin || 100}
|
||||||
step={100}
|
step={100}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<NumberStepperField
|
<NumberStepperField
|
||||||
name="quota"
|
name="quota"
|
||||||
label="IP 购买数量"
|
label="IP 购买数量"
|
||||||
min={500}
|
min={currentCountMin || 500}
|
||||||
step={100}
|
step={100}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ 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({
|
||||||
@@ -25,6 +25,11 @@ export default function LongForm({skuList}: {skuList: ProductItem['skus']}) {
|
|||||||
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: defaultMode === '2' ? Math.max(defaultCountMin, 500) : 500,
|
||||||
daily_limit: 100,
|
daily_limit: defaultMode === '1' ? Math.max(defaultCountMin, 100) : 100,
|
||||||
pay_type: 'balance', // 余额支付
|
pay_type: 'balance', // 余额支付
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -49,6 +49,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)
|
||||||
|
|||||||
@@ -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,15 +108,30 @@ 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}/>
|
<>
|
||||||
<Pay
|
<FieldPayment balance={profile.balance}/>
|
||||||
method={method}
|
<Pay
|
||||||
balance={profile.balance}
|
method={method}
|
||||||
amount={discountedPrice}
|
balance={profile.balance}
|
||||||
resource={resource}
|
amount={discountedPrice}
|
||||||
/>
|
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()}>
|
||||||
登录后支付
|
登录后支付
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,21 +2,22 @@
|
|||||||
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} = 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 +29,25 @@ 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 (type === '1') {
|
||||||
|
const current = getValues('daily_limit')
|
||||||
|
if (current < currentCountMin) {
|
||||||
|
setValue('daily_limit', currentCountMin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const current = getValues('quota')
|
||||||
|
if (current < currentCountMin) {
|
||||||
|
setValue('quota', currentCountMin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [currentCountMin, type, setValue, getValues])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const nextType = modeList.includes(type) ? type : modeList[0]
|
const nextType = modeList.includes(type) ? type : modeList[0]
|
||||||
|
|
||||||
@@ -151,14 +171,14 @@ export default function Center({
|
|||||||
<NumberStepperField
|
<NumberStepperField
|
||||||
name="daily_limit"
|
name="daily_limit"
|
||||||
label="每日提取上限"
|
label="每日提取上限"
|
||||||
min={2000}
|
min={currentCountMin || 2000}
|
||||||
step={1000}
|
step={1000}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<NumberStepperField
|
<NumberStepperField
|
||||||
name="quota"
|
name="quota"
|
||||||
label="IP 购买数量"
|
label="IP 购买数量"
|
||||||
min={10000}
|
min={currentCountMin || 10000}
|
||||||
step={5000}
|
step={5000}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ 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({
|
||||||
@@ -25,15 +25,19 @@ export default function ShortForm({skuList}: {skuList: ProductItem['skus']}) {
|
|||||||
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),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
type: defaultMode,
|
type: defaultMode,
|
||||||
live: defaultLive,
|
live: defaultLive,
|
||||||
expire: defaultExpire,
|
expire: defaultExpire,
|
||||||
quota: 10_000, // >= 10000,
|
quota: defaultMode === '2' ? defaultCountMin || 10000 : 10000,
|
||||||
daily_limit: 2_000, // >= 2000
|
daily_limit: defaultMode === '1' ? defaultCountMin || 2000 : 2000,
|
||||||
pay_type: 'balance', // 余额支付
|
pay_type: 'balance', // 余额支付
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user