@tgbotpress/plugin-premium 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -2
- package/migrations/postgres/000-premium-core.sql +82 -0
- package/migrations/postgres/014-premium-payment.sql +11 -0
- package/migrations/postgres/023-telegram-purchase.sql +22 -0
- package/migrations/postgres/038-telegram-stars.sql +35 -0
- package/package.json +106 -4
- package/scripts/build.mjs +22 -0
- package/src/admin-api.d.ts +30 -0
- package/src/admin-api.js +486 -0
- package/src/admin-api.source.ts +330 -0
- package/src/admin-pages.d.ts +6 -0
- package/src/admin-pages.js +5 -0
- package/src/admin-pages.orders.d.ts +1 -0
- package/src/admin-pages.orders.js +26 -0
- package/src/admin-pages.orders.tsx +33 -0
- package/src/admin-pages.packages.d.ts +1 -0
- package/src/admin-pages.packages.js +39 -0
- package/src/admin-pages.packages.tsx +51 -0
- package/src/admin-pages.platforms.d.ts +1 -0
- package/src/admin-pages.platforms.js +33 -0
- package/src/admin-pages.platforms.tsx +52 -0
- package/src/admin-pages.trades.d.ts +1 -0
- package/src/admin-pages.trades.js +27 -0
- package/src/admin-pages.trades.tsx +32 -0
- package/src/admin-pages.ts +6 -0
- package/src/admin-ui-runtime.d.ts +63 -0
- package/src/admin-ui-runtime.js +11 -0
- package/src/admin-ui-runtime.ts +44 -0
- package/src/fulfillment.d.ts +24 -0
- package/src/fulfillment.js +417 -0
- package/src/fulfillment.source.ts +311 -0
- package/src/host-types.d.ts +31 -0
- package/src/index.d.ts +26 -0
- package/src/index.js +47 -0
- package/src/notifications.d.ts +39 -0
- package/src/notifications.js +96 -0
- package/src/notifications.source.ts +60 -0
- package/src/purchases.d.ts +51 -0
- package/src/purchases.js +627 -0
- package/src/purchases.source.ts +568 -0
- package/src/server.d.ts +41 -0
- package/src/server.js +44 -0
- package/src/server.source.ts +60 -0
- package/src/tasks.d.ts +24 -0
- package/src/tasks.js +46 -0
- package/src/tasks.source.ts +69 -0
- package/src/wallet-poll.d.ts +21 -0
- package/src/wallet-poll.js +139 -0
- package/src/wallet-poll.source.ts +120 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { usePremiumAdminRuntime } from './admin-ui-runtime.js'
|
|
2
|
+
import {useState} from 'react'
|
|
3
|
+
import {useMutation,useQuery,useQueryClient} from '@tanstack/react-query'
|
|
4
|
+
import {ChevronLeft,ChevronRight,Copy,ImagePlus,Pencil,Plus,RefreshCw,Search,Trash2,Package} from 'lucide-react'
|
|
5
|
+
import {telegramPremiumStarPrice} from './index.js'
|
|
6
|
+
type Bot={rid:number;bot_firstname:string|null;bot_username:string|null}
|
|
7
|
+
type Platform={rid:number;bot_rid:number;platform_name:number;bot_firstname:string|null;bot_username:string|null;status:number}
|
|
8
|
+
type Row={rid:number;bot_rid:number;bot_firstname:string|null;bot_username:string|null;premium_platform_rid:number;platform_name:number;package_name:string;package_month:number;usdt_price:string;seq_sn:number;status:number;show_notes:string|null;package_pic:string|null;comments:string|null;create_time:string;update_time:string|null}
|
|
9
|
+
type Data={rows:Row[];total:number;page:number;pageSize:number;canAdd:boolean;canEdit:boolean;canDelete:boolean;canStatus:boolean;canCopy:boolean}
|
|
10
|
+
type Options={bots:Bot[];platforms:Platform[]}
|
|
11
|
+
type Form={premium_platform_rid:string;package_name:string;package_month:string;usdt_price:string;seq_sn:string;show_notes:string}
|
|
12
|
+
const blank:Form={premium_platform_rid:'',package_name:'',package_month:'3',usdt_price:'',seq_sn:'0',show_notes:''}
|
|
13
|
+
export function PremiumPackagesPage(){
|
|
14
|
+
const {AdminShell, Button, Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, Textarea, api, ApiError}=usePremiumAdminRuntime()
|
|
15
|
+
const client=useQueryClient(),me=useQuery({queryKey:['me'],queryFn:()=>api<Record<string, unknown>>('/api/me'),retry:false,staleTime:60000})
|
|
16
|
+
const logout=useMutation({mutationFn:()=>api('/api/auth/logout',{method:'POST',headers:{'Content-Type':'application/json'},body:'{}'}),onSuccess:()=>{client.clear();location.assign('/console/home')}})
|
|
17
|
+
const [draft,setDraft]=useState(''),[search,setSearch]=useState(''),[bot,setBot]=useState('all'),[page,setPage]=useState(1),[pageSize,setPageSize]=useState(15),[editor,setEditor]=useState<'create'|Row|null>(null),[form,setForm]=useState<Form>(blank),[image,setImage]=useState<File|null>(null),[remove,setRemove]=useState<Row|null>(null),[copy,setCopy]=useState(false),[sourceRid,setSourceRid]=useState(''),[targetRid,setTargetRid]=useState(''),[feedback,setFeedback]=useState(''),[failure,setFailure]=useState('')
|
|
18
|
+
const query=useQuery({queryKey:['premium-packages',page,pageSize,search,bot],queryFn:()=>api<Data>('/api/premium-packages?'+new URLSearchParams({page:String(page),pageSize:String(pageSize),search,botRid:bot})),enabled:!!me.data,retry:false})
|
|
19
|
+
const options=useQuery({queryKey:['premium-packages','options'],queryFn:()=>api<Options>('/api/premium-packages?action=options'),enabled:!!me.data,retry:false,staleTime:60000})
|
|
20
|
+
const mutation=useMutation({mutationFn:(args:{body:Record<string,unknown>;file?:File})=>{if(args.file){const fd=new FormData();fd.set('payload',JSON.stringify(args.body));fd.set('thumb',args.file);return api<{message:string}>('/api/premium-packages',{method:'POST',body:fd})}return api<{message:string}>('/api/premium-packages',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(args.body)})},onSuccess:async r=>{setFeedback(r.message);setFailure('');setEditor(null);setRemove(null);setCopy(false);setImage(null);await client.invalidateQueries({queryKey:['premium-packages']})},onError:e=>setFailure(e instanceof ApiError?e.message:'操作失败,请重试')})
|
|
21
|
+
if(me.isPending)return <div className="flex min-h-screen items-center justify-center"><RefreshCw className="size-4 animate-spin" aria-label="加载中"/></div>
|
|
22
|
+
if(!me.data)return <main className="flex min-h-screen items-center justify-center p-4"><section className="w-full max-w-sm space-y-4 rounded-xl bg-card p-6"><h1 className="font-semibold">登录管理后台</h1><Button asChild className="w-full"><a href="/api/auth/start?destination=premiumPackages">管理员登录</a></Button></section></main>
|
|
23
|
+
const total=query.data?.total||0,pages=Math.max(1,Math.ceil(total/pageSize)),botName=(id:number)=>{const b=options.data?.bots.find(x=>x.rid===id);return b?.bot_firstname||b?.bot_username||'机器人 #'+id}
|
|
24
|
+
const open=(row?:Row)=>{mutation.reset();setFailure('');setImage(null);setForm(row?{premium_platform_rid:String(row.premium_platform_rid),package_name:row.package_name,package_month:String(row.package_month),usdt_price:row.usdt_price,seq_sn:String(row.seq_sn),show_notes:row.show_notes||''}:{...blank});setEditor(row||'create')}
|
|
25
|
+
const activePlatforms=options.data?.platforms||[]
|
|
26
|
+
const selectedPlatform=activePlatforms.find(p=>p.rid===Number(form.premium_platform_rid)),starsMode=selectedPlatform?.platform_name===3,starsPrice=telegramPremiumStarPrice(Number(form.package_month))
|
|
27
|
+
const priceLabel=(platformName:number,months:number,price:string)=>platformName===3?`${price} USDT · Bot 开通消耗 ${telegramPremiumStarPrice(months)??'—'} Stars`:`${price} USDT`
|
|
28
|
+
const save=()=>{if(!editor)return;const body={action:editor==='create'?'create':'update',...(editor==='create'?{}:{rid:editor.rid}),premium_platform_rid:Number(form.premium_platform_rid),package_name:form.package_name.trim(),package_month:Number(form.package_month),usdt_price:form.usdt_price.trim(),seq_sn:Number(form.seq_sn||0),show_notes:form.show_notes.trim()};mutation.mutate({body,file:image||undefined})}
|
|
29
|
+
return <AdminShell user={me.data} title="会员套餐" activeRoute="admin.premium.package.index" onRefresh={()=>query.refetch()} onLogout={()=>logout.mutate()}><main className="space-y-3 p-3 sm:p-4">
|
|
30
|
+
<form className="flex flex-wrap items-center gap-2 rounded-xl bg-card p-3" onSubmit={e=>{e.preventDefault();setSearch(draft.trim());setPage(1)}}><div className="relative min-w-40 flex-1"><Search className="absolute left-2.5 top-2.5 size-3.5 text-muted-foreground"/><Input value={draft} maxLength={50} onChange={e=>setDraft(e.target.value)} placeholder="搜索套餐名称" className="h-9 pl-8 text-xs"/></div><Select value={bot} onValueChange={v=>{setBot(v);setPage(1)}}><SelectTrigger className="h-9 w-full text-xs sm:w-48"><SelectValue placeholder="全部机器人"/></SelectTrigger><SelectContent><SelectItem value="all">全部机器人</SelectItem>{options.data?.bots.map(b=><SelectItem key={b.rid} value={String(b.rid)}>{botName(b.rid)}{b.bot_username?' (@'+b.bot_username+')':''}</SelectItem>)}</SelectContent></Select><Button size="sm" className="h-9">搜索</Button><Button type="button" size="icon" variant="outline" className="size-9" aria-label="刷新" disabled={query.isFetching} onClick={()=>query.refetch()}><RefreshCw className={query.isFetching?'size-3.5 animate-spin':'size-3.5'}/></Button>{query.data?.canAdd&&<Button type="button" size="sm" className="h-9" onClick={()=>open()}><Plus className="mr-1 size-3.5"/>添加套餐</Button>}{query.data?.canCopy&&<Button type="button" size="sm" variant="outline" className="h-9" onClick={()=>{setFailure('');setSourceRid('');setTargetRid('');setCopy(true)}}><Copy className="mr-1 size-3.5"/>复制套餐</Button>}</form>
|
|
31
|
+
{(query.error||failure)&&<div role="alert" className="rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive">{failure||(query.error instanceof ApiError?query.error.message:'加载失败')}</div>}
|
|
32
|
+
<section className="overflow-hidden rounded-xl bg-card"><header className="flex h-11 items-center justify-between border-b px-3"><h1 className="flex items-center gap-2 text-sm font-semibold"><Package className="size-4 text-muted-foreground"/>会员套餐</h1><span className="text-xs text-muted-foreground">共 {total} 条</span></header>
|
|
33
|
+
<div className="hidden overflow-x-auto md:block"><Table className="min-w-[1120px]"><TableHeader><TableRow>{['ID','机器人','平台','套餐名称','月份','USDT 售价 / Stars 开通成本','排序','状态','创建时间','修改时间','操作'].map(x=><TableHead key={x} className="h-9 px-3">{x}</TableHead>)}</TableRow></TableHeader><TableBody>{query.isPending?<TableRow><TableCell colSpan={11} className="h-20 text-center text-xs text-muted-foreground">加载中…</TableCell></TableRow>:query.data?.rows.length?query.data.rows.map(r=><TableRow key={r.rid}><TableCell className="px-3 py-2 font-mono text-xs">#{r.rid}</TableCell><TableCell className="px-3 py-2 text-xs">{botName(r.bot_rid)}<span className="block text-muted-foreground">{r.bot_username?'@'+r.bot_username:''}</span></TableCell><TableCell className="px-3 py-2 font-mono text-xs">#{r.premium_platform_rid}</TableCell><TableCell className="px-3 py-2 text-xs"><div className="font-medium">{r.package_name}</div><div className="max-w-48 truncate text-muted-foreground">{r.show_notes||''}</div></TableCell><TableCell className="px-3 py-2 text-xs">{r.package_month} 个月</TableCell><TableCell className="px-3 py-2 font-mono text-xs">{priceLabel(r.platform_name,r.package_month,r.usdt_price)}</TableCell><TableCell className="px-3 py-2 text-xs">{r.seq_sn}</TableCell><TableCell className="px-3 py-2"><Switch checked={r.status===0} disabled={!query.data?.canStatus||mutation.isPending} onCheckedChange={enabled=>mutation.mutate({body:{action:'status',rid:r.rid,enabled}})}/></TableCell><TableCell className="whitespace-nowrap px-3 py-2 text-xs">{r.create_time||'—'}</TableCell><TableCell className="whitespace-nowrap px-3 py-2 text-xs">{r.update_time||'—'}</TableCell><TableCell className="px-3 py-2">{query.data?.canEdit||query.data?.canDelete?<div className="flex items-center gap-1">{query.data.canEdit&&<Button variant="ghost" size="icon" className="size-7" aria-label="编辑" onClick={()=>open(r)}><Pencil className="size-3.5"/></Button>}{query.data.canDelete&&<Button variant="ghost" size="icon" className="size-7 text-destructive" aria-label="删除" onClick={()=>{setRemove(r);setFailure('')}}><Trash2 className="size-3.5"/></Button>}</div>:'—'}</TableCell></TableRow>):<TableRow><TableCell colSpan={11} className="h-20 text-center text-xs text-muted-foreground">暂无记录</TableCell></TableRow>}</TableBody></Table></div>
|
|
34
|
+
<div className="divide-y md:hidden">{query.data?.rows.map(r=><article key={r.rid} className="space-y-2 p-3"><div className="flex items-start justify-between gap-3"><div><p className="text-sm font-medium">{r.package_name}</p><p className="text-[10px] text-muted-foreground">{botName(r.bot_rid)} · 平台 #{r.premium_platform_rid} · #{r.rid}</p></div><Switch checked={r.status===0} disabled={!query.data?.canStatus||mutation.isPending} onCheckedChange={enabled=>mutation.mutate({body:{action:'status',rid:r.rid,enabled}})}/></div><div className="grid grid-cols-3 gap-2 text-xs"><div><span className="text-muted-foreground">期限</span><p>{r.package_month} 个月</p></div><div><span className="text-muted-foreground">价格</span><p className="font-mono">{priceLabel(r.platform_name,r.package_month,r.usdt_price)}</p></div><div><span className="text-muted-foreground">排序</span><p>{r.seq_sn}</p></div><div className="col-span-3"><span className="text-muted-foreground">说明</span><p className="whitespace-pre-wrap">{r.show_notes||'—'}</p></div><div><span className="text-muted-foreground">创建</span><p>{r.create_time||'—'}</p></div><div><span className="text-muted-foreground">修改</span><p>{r.update_time||'—'}</p></div>{r.package_pic&&<a href={r.package_pic} target="_blank" rel="noreferrer" className="text-primary underline">查看套餐图片</a>}</div><div className="flex gap-1">{query.data?.canEdit&&<Button size="sm" variant="outline" className="h-7 text-xs" onClick={()=>open(r)}><Pencil className="mr-1 size-3"/>编辑</Button>}{query.data?.canDelete&&<Button size="sm" variant="outline" className="h-7 text-xs text-destructive" onClick={()=>setRemove(r)}><Trash2 className="mr-1 size-3"/>删除</Button>}</div></article>)}</div>
|
|
35
|
+
<footer className="flex flex-wrap items-center justify-between gap-2 border-t px-3 py-2"><span className="text-xs text-muted-foreground">第 {page}/{pages} 页</span><div className="flex items-center gap-1.5"><Select value={String(pageSize)} onValueChange={v=>{setPageSize(Number(v));setPage(1)}}><SelectTrigger className="h-8 w-24 text-xs"><SelectValue/></SelectTrigger><SelectContent>{[10,15,20,30,50,100].map(n=><SelectItem key={n} value={String(n)}>{n} 条/页</SelectItem>)}</SelectContent></Select><Button variant="outline" size="icon" className="size-8" aria-label="上一页" disabled={page<=1||query.isFetching} onClick={()=>setPage(v=>v-1)}><ChevronLeft className="size-3.5"/></Button><Button variant="outline" size="icon" className="size-8" aria-label="下一页" disabled={page>=pages||query.isFetching} onClick={()=>setPage(v=>v+1)}><ChevronRight className="size-3.5"/></Button></div></footer>
|
|
36
|
+
</section>
|
|
37
|
+
</main>
|
|
38
|
+
<Dialog open={!!editor} onOpenChange={v=>{if(!v){setEditor(null);setImage(null)}}}><DialogContent className="max-h-[90vh] max-w-xl overflow-y-auto"><DialogHeader><DialogTitle>{editor==='create'?'添加会员套餐':'编辑会员套餐'}</DialogTitle></DialogHeader><form id="premium-package-form" className="grid gap-3 sm:grid-cols-2" onSubmit={e=>{e.preventDefault();save()}}>
|
|
39
|
+
<label className="space-y-1 text-xs sm:col-span-2"><span>会员平台</span><Select disabled={editor!=='create'} value={form.premium_platform_rid} onValueChange={v=>setForm({...form,premium_platform_rid:v})}><SelectTrigger className="h-9 text-xs"><SelectValue placeholder="选择会员平台"/></SelectTrigger><SelectContent>{activePlatforms.map(p=><SelectItem key={p.rid} value={String(p.rid)}>平台 #{p.rid} · {botName(p.bot_rid)}{p.status===1?' · 已停用':''}{p.platform_name===3?' · Telegram Stars':' · USDT'}</SelectItem>)}</SelectContent></Select></label>
|
|
40
|
+
<label className="space-y-1 text-xs sm:col-span-2"><span>套餐名称</span><Input maxLength={50} value={form.package_name} onChange={e=>setForm({...form,package_name:e.target.value})} className="h-9 text-xs"/></label>
|
|
41
|
+
<label className="space-y-1 text-xs"><span>套餐月份</span><Select value={form.package_month} onValueChange={v=>setForm({...form,package_month:v})}><SelectTrigger className="h-9 text-xs"><SelectValue/></SelectTrigger><SelectContent>{[3,6,12].map(n=><SelectItem key={n} value={String(n)}>{n} 个月</SelectItem>)}</SelectContent></Select></label>
|
|
42
|
+
<label className="space-y-1 text-xs"><span>USDT 售价</span><Input type="number" min="0.01" max="999999999999.99" step="0.01" value={form.usdt_price} onChange={e=>setForm({...form,usdt_price:e.target.value})} className="h-9 font-mono text-xs"/>{starsMode&&<span className="block text-muted-foreground">机器人开通消耗 {starsPrice??'—'} Stars(Telegram 固定费率)</span>}</label>
|
|
43
|
+
<label className="space-y-1 text-xs"><span>排序</span><Input type="number" min="0" step="1" value={form.seq_sn} onChange={e=>setForm({...form,seq_sn:e.target.value})} className="h-9 text-xs"/></label>
|
|
44
|
+
<label className="space-y-1 text-xs sm:col-span-2"><span>显示说明</span><Textarea maxLength={1000} value={form.show_notes} onChange={e=>setForm({...form,show_notes:e.target.value})} className="min-h-20 text-xs"/></label>
|
|
45
|
+
{editor&&editor!=='create'&&<div className="space-y-2 text-xs sm:col-span-2"><span className="block">套餐图片</span>{editor.package_pic&&<a href={editor.package_pic} target="_blank" rel="noreferrer" className="text-primary underline">查看当前图片</a>}<label className="flex h-9 cursor-pointer items-center gap-2 rounded-md border px-3"><ImagePlus className="size-3.5"/><span className="truncate">{image?.name||'选择 PNG、JPG、GIF 或 WebP'}</span><input type="file" accept="image/png,image/jpeg,image/gif,image/webp" className="sr-only" onChange={e=>setImage(e.target.files?.[0]||null)}/></label>{image&&<span className="text-muted-foreground">{(image.size/1024/1024).toFixed(1)} MB</span>}</div>}</form>
|
|
46
|
+
{failure&&editor&&<p role="alert" className="text-xs text-destructive">{failure}</p>}<DialogFooter><Button size="sm" variant="outline" onClick={()=>setEditor(null)}>取消</Button><Button size="sm" form="premium-package-form" disabled={mutation.isPending||!form.premium_platform_rid||!form.package_name.trim()||!form.usdt_price}>{mutation.isPending?'保存中…':'保存'}</Button></DialogFooter></DialogContent></Dialog>
|
|
47
|
+
<Dialog open={!!remove} onOpenChange={v=>{if(!v)setRemove(null)}}><DialogContent className="max-w-sm"><DialogHeader><DialogTitle>删除此会员套餐?</DialogTitle></DialogHeader><p className="text-xs text-muted-foreground">{remove?.package_name} · {remove?.package_month} 个月 · {remove&&priceLabel(remove.platform_name,remove.package_month,remove.usdt_price)}</p>{failure&&remove&&<p role="alert" className="text-xs text-destructive">{failure}</p>}<DialogFooter><Button size="sm" variant="outline" onClick={()=>setRemove(null)}>取消</Button><Button size="sm" variant="destructive" disabled={mutation.isPending} onClick={()=>remove&&mutation.mutate({body:{action:'delete',rid:remove.rid}})}>确认删除</Button></DialogFooter></DialogContent></Dialog>
|
|
48
|
+
<Dialog open={copy} onOpenChange={v=>{if(!v)setCopy(false)}}><DialogContent className="max-w-md"><DialogHeader><DialogTitle>复制会员套餐</DialogTitle></DialogHeader><label className="block space-y-1 text-xs"><span>来源平台</span><Select value={sourceRid} onValueChange={setSourceRid}><SelectTrigger className="h-9 text-xs"><SelectValue placeholder="选择套餐来源"/></SelectTrigger><SelectContent>{activePlatforms.map(p=><SelectItem key={p.rid} value={String(p.rid)}>平台 #{p.rid} · {botName(p.bot_rid)}</SelectItem>)}</SelectContent></Select></label><label className="block space-y-1 text-xs"><span>覆盖平台</span><Select value={targetRid} onValueChange={setTargetRid}><SelectTrigger className="h-9 text-xs"><SelectValue placeholder="选择目标平台"/></SelectTrigger><SelectContent>{activePlatforms.map(p=><SelectItem key={p.rid} value={String(p.rid)}>平台 #{p.rid} · {botName(p.bot_rid)}</SelectItem>)}</SelectContent></Select></label><p className="rounded-md border border-destructive/30 bg-destructive/5 p-2 text-xs text-destructive">确认后会先删除目标平台当前全部套餐,再复制来源平台的套餐。</p>{failure&©&&<p role="alert" className="text-xs text-destructive">{failure}</p>}<DialogFooter><Button size="sm" variant="outline" onClick={()=>setCopy(false)}>取消</Button><Button size="sm" variant="destructive" disabled={!sourceRid||!targetRid||sourceRid===targetRid||mutation.isPending} onClick={()=>mutation.mutate({body:{action:'copy',sourcePlatformRid:Number(sourceRid),targetPlatformRid:Number(targetRid)}})}>确认覆盖并复制</Button></DialogFooter></DialogContent></Dialog>
|
|
49
|
+
<Dialog open={!!feedback} onOpenChange={v=>{if(!v)setFeedback('')}}><DialogContent className="max-w-sm"><DialogHeader><DialogTitle>{feedback}</DialogTitle></DialogHeader><DialogFooter><Button size="sm" onClick={()=>setFeedback('')}>确定</Button></DialogFooter></DialogContent></Dialog>
|
|
50
|
+
</AdminShell>
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function PremiumPlatformsPage(): import("react").JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { usePremiumAdminRuntime } from './admin-ui-runtime.js';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
5
|
+
import { ChevronLeft, ChevronRight, KeyRound, Pencil, Plus, RefreshCw, Search, ShieldCheck, Trash2 } from 'lucide-react';
|
|
6
|
+
const empty = { bot_rid: '', platform_name: '1', tg_admin_uid: '', platform_hash: '', platform_cookie: '', receive_wallet: '', get_tx_time: '', tg_notice_obj_receive: '', tg_notice_obj_send: '', comments: '' };
|
|
7
|
+
const platformLabel = (name) => name === 1 ? '自己搭建' : name === 2 ? 'API 平台调用' : 'Telegram Stars 官方接口';
|
|
8
|
+
export function PremiumPlatformsPage() {
|
|
9
|
+
const { AdminShell, Button, Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, Textarea, api, ApiError } = usePremiumAdminRuntime();
|
|
10
|
+
const client = useQueryClient(), me = useQuery({ queryKey: ['me'], queryFn: () => api('/api/me'), retry: false, staleTime: 60000 });
|
|
11
|
+
const logout = useMutation({ mutationFn: () => api('/api/auth/logout', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' }), onSuccess: () => { client.clear(); location.assign('/console/home'); } });
|
|
12
|
+
const [draft, setDraft] = useState(''), [search, setSearch] = useState(''), [page, setPage] = useState(1), [pageSize, setPageSize] = useState(15), [editor, setEditor] = useState(null), [form, setForm] = useState(empty), [secret, setSecret] = useState(null), [secretValue, setSecretValue] = useState(''), [remove, setRemove] = useState(null), [feedback, setFeedback] = useState(''), [failure, setFailure] = useState(''), [starsBalance, setStarsBalance] = useState(null);
|
|
13
|
+
const data = useQuery({ queryKey: ['premium-platforms', page, pageSize, search], queryFn: () => api('/api/premium-platforms?' + new URLSearchParams({ page: String(page), pageSize: String(pageSize), search })), enabled: !!me.data, retry: false });
|
|
14
|
+
const options = useQuery({ queryKey: ['premium-platforms', 'options'], queryFn: () => api('/api/premium-platforms?action=options'), enabled: !!me.data, retry: false, staleTime: 60000 });
|
|
15
|
+
const mutation = useMutation({ mutationFn: (body) => api('/api/premium-platforms', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }), onSuccess: async (result) => { setFeedback(result.message); setEditor(null); setSecret(null); setSecretValue(''); setRemove(null); setFailure(''); await client.invalidateQueries({ queryKey: ['premium-platforms'] }); }, onError: e => setFailure(e instanceof ApiError ? e.message : '操作失败,请重试') });
|
|
16
|
+
const balanceQuery = useMutation({ mutationFn: (botRid) => api('/api/premium-platforms?action=starsBalance&botRid=' + botRid), onSuccess: (result, botRid) => { setStarsBalance({ botRid, amount: result.stars }); setFailure(''); }, onError: e => setFailure(e instanceof ApiError ? e.message : '读取机器人 Stars 余额失败') });
|
|
17
|
+
if (me.isPending)
|
|
18
|
+
return _jsx("div", { className: "flex min-h-screen items-center justify-center", children: _jsx(RefreshCw, { className: "size-4 animate-spin", "aria-label": "\u52A0\u8F7D\u4E2D" }) });
|
|
19
|
+
if (!me.data)
|
|
20
|
+
return _jsx("main", { className: "flex min-h-screen items-center justify-center p-4", children: _jsxs("section", { className: "w-full max-w-sm space-y-4 rounded-xl bg-card p-6", children: [_jsx("h1", { className: "font-semibold", children: "\u767B\u5F55\u7BA1\u7406\u540E\u53F0" }), _jsx(Button, { asChild: true, className: "w-full", children: _jsx("a", { href: "/api/auth/start?destination=premiumPlatforms", children: "\u7BA1\u7406\u5458\u767B\u5F55" }) })] }) });
|
|
21
|
+
const total = data.data?.total || 0, pages = Math.max(1, Math.ceil(total / pageSize)), botName = (b) => b.bot_firstname || b.bot_username || '机器人 #' + b.rid;
|
|
22
|
+
const open = (row) => { mutation.reset(); balanceQuery.reset(); setStarsBalance(null); setFailure(''); setForm(row ? { bot_rid: String(row.bot_rid), platform_name: String(row.platform_name), tg_admin_uid: row.tg_admin_uid || '', platform_hash: row.platform_hash || '', platform_cookie: '', receive_wallet: row.receive_wallet || '', get_tx_time: row.get_tx_time || '', tg_notice_obj_receive: row.tg_notice_obj_receive || '', tg_notice_obj_send: row.tg_notice_obj_send || '', comments: row.comments || '' } : { ...empty }); setEditor(row || 'create'); };
|
|
23
|
+
const save = () => { if (!editor)
|
|
24
|
+
return; const body = { action: editor === 'create' ? 'create' : 'update', ...(editor === 'create' ? {} : { rid: editor.rid }), bot_rid: Number(form.bot_rid), platform_name: Number(form.platform_name), tg_admin_uid: form.tg_admin_uid.trim(), platform_hash: form.platform_hash.trim(), ...(editor === 'create' ? { platform_cookie: form.platform_cookie.trim() } : {}), receive_wallet: form.receive_wallet.trim(), get_tx_time: form.get_tx_time.trim(), tg_notice_obj_receive: form.tg_notice_obj_receive.trim(), tg_notice_obj_send: form.tg_notice_obj_send.trim(), comments: form.comments.trim() }; mutation.mutate(body); };
|
|
25
|
+
const botLabel = (id) => { const b = options.data?.bots.find(x => x.rid === id); return b ? botName(b) : '机器人 #' + id; };
|
|
26
|
+
return _jsxs(AdminShell, { user: me.data, title: "\u4F1A\u5458\u5E73\u53F0", activeRoute: "admin.premium.platform.index", onRefresh: () => data.refetch(), onLogout: () => logout.mutate(), children: [_jsxs("main", { className: "space-y-3 p-3 sm:p-4", children: [_jsxs("form", { className: "flex flex-wrap items-center gap-2 rounded-xl bg-card p-3", onSubmit: e => { e.preventDefault(); setSearch(draft.trim()); setPage(1); }, children: [_jsxs("div", { className: "relative min-w-40 flex-1", children: [_jsx(Search, { className: "absolute left-2.5 top-2.5 size-3.5 text-muted-foreground" }), _jsx(Input, { value: draft, maxLength: 100, onChange: e => setDraft(e.target.value), placeholder: "\u641C\u7D22\u5E73\u53F0 Hash\u3001\u7BA1\u7406\u5458 ID \u6216\u5907\u6CE8", className: "h-9 pl-8 text-xs" })] }), _jsx(Button, { size: "sm", className: "h-9", children: "\u641C\u7D22" }), _jsx(Button, { type: "button", variant: "outline", size: "icon", className: "size-9", "aria-label": "\u5237\u65B0", disabled: data.isFetching, onClick: () => data.refetch(), children: _jsx(RefreshCw, { className: data.isFetching ? 'size-3.5 animate-spin' : 'size-3.5' }) }), data.data?.canAdd && _jsxs(Button, { type: "button", size: "sm", className: "h-9", onClick: () => open(), children: [_jsx(Plus, { className: "mr-1 size-3.5" }), "\u6DFB\u52A0\u5E73\u53F0"] })] }), (data.error || failure) && _jsx("div", { role: "alert", className: "rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive", children: failure || (data.error instanceof ApiError ? data.error.message : '加载失败') }), _jsxs("section", { className: "overflow-hidden rounded-xl bg-card", children: [_jsxs("header", { className: "flex h-11 items-center justify-between border-b px-3", children: [_jsxs("h1", { className: "flex items-center gap-2 text-sm font-semibold", children: [_jsx(ShieldCheck, { className: "size-4 text-muted-foreground" }), "\u4F1A\u5458\u5E73\u53F0"] }), _jsxs("span", { className: "text-xs text-muted-foreground", children: ["\u5171 ", total, " \u6761"] })] }), _jsx("div", { className: "hidden overflow-x-auto md:block", children: _jsxs(Table, { className: "min-w-[1300px]", children: [_jsx(TableHeader, { children: _jsx(TableRow, { children: ['ID', '机器人', '会员平台', '管理员 ID', '平台 Hash', 'Cookie', '助记词', '状态', '收款钱包', '拉取时间', '通知对象', '创建时间', '备注', '操作'].map(x => _jsx(TableHead, { className: "h-9 px-3", children: x }, x)) }) }), _jsx(TableBody, { children: data.isPending ? _jsx(TableRow, { children: _jsx(TableCell, { colSpan: 14, className: "h-20 text-center text-xs text-muted-foreground", children: "\u52A0\u8F7D\u4E2D\u2026" }) }) : data.data?.rows.length ? data.data.rows.map(r => _jsxs(TableRow, { children: [_jsxs(TableCell, { className: "px-3 py-2 font-mono text-xs", children: ["#", r.rid] }), _jsxs(TableCell, { className: "px-3 py-2 text-xs", children: [botLabel(r.bot_rid), _jsx("span", { className: "block text-muted-foreground", children: r.bot_username ? '@' + r.bot_username : '' })] }), _jsx(TableCell, { className: "px-3 py-2 text-xs", children: platformLabel(r.platform_name) }), _jsx(TableCell, { className: "px-3 py-2 font-mono text-xs", children: r.tg_admin_uid || '—' }), _jsx(TableCell, { className: "max-w-40 truncate px-3 py-2 font-mono text-xs", title: r.platform_hash || '', children: r.platform_name === 3 ? '—' : r.platform_hash || '—' }), _jsx(TableCell, { className: "px-3 py-2 text-xs", children: r.platform_name === 3 ? '—' : r.cookie_configured ? '已加密设置' : '未设置' }), _jsx(TableCell, { className: "px-3 py-2 text-xs", children: r.platform_name === 3 ? '—' : r.phrase_configured ? '已加密设置' : '未设置' }), _jsx(TableCell, { className: "px-3 py-2", children: _jsx(Switch, { checked: r.status === 0, disabled: !data.data?.canStatus || mutation.isPending, onCheckedChange: enabled => mutation.mutate({ action: 'status', rid: r.rid, enabled }) }) }), _jsx(TableCell, { className: "max-w-44 truncate px-3 py-2 font-mono text-xs", title: r.receive_wallet || '', children: r.receive_wallet || '—' }), _jsx(TableCell, { className: "whitespace-nowrap px-3 py-2 text-xs", children: r.get_tx_time || '—' }), _jsxs(TableCell, { className: "max-w-44 px-3 py-2 text-xs", children: [_jsxs("div", { className: "truncate", children: ["\u6536\u6B3E\uFF1A", r.tg_notice_obj_receive || '—'] }), _jsxs("div", { className: "truncate", children: ["\u6210\u529F\uFF1A", r.tg_notice_obj_send || '—'] })] }), _jsx(TableCell, { className: "whitespace-nowrap px-3 py-2 text-xs", children: r.create_time || '—' }), _jsx(TableCell, { className: "max-w-36 truncate px-3 py-2 text-xs", title: r.comments || '', children: r.comments || '—' }), _jsx(TableCell, { className: "px-3 py-2", children: _jsxs("div", { className: "flex items-center gap-1", children: [data.data?.canEdit && _jsx(Button, { size: "icon", variant: "ghost", className: "size-7", "aria-label": "\u7F16\u8F91", onClick: () => open(r), children: _jsx(Pencil, { className: "size-3.5" }) }), r.platform_name !== 3 && data.data?.canCookie && _jsx(Button, { size: "icon", variant: "ghost", className: "size-7", "aria-label": "\u66F4\u65B0 Cookie", onClick: () => { setSecret({ row: r, kind: 'cookie' }); setSecretValue(''); setFailure(''); }, children: _jsx(KeyRound, { className: "size-3.5" }) }), r.platform_name !== 3 && data.data?.canPhrase && _jsx(Button, { size: "sm", variant: "ghost", className: "h-7 px-2 text-xs", onClick: () => { setSecret({ row: r, kind: 'phrase' }); setSecretValue(''); setFailure(''); }, children: "\u52A9\u8BB0\u8BCD" }), data.data?.canDelete && _jsx(Button, { size: "icon", variant: "ghost", className: "size-7 text-destructive", "aria-label": "\u5220\u9664", onClick: () => { setRemove(r); setFailure(''); }, children: _jsx(Trash2, { className: "size-3.5" }) })] }) })] }, r.rid)) : _jsx(TableRow, { children: _jsx(TableCell, { colSpan: 14, className: "h-20 text-center text-xs text-muted-foreground", children: "\u6682\u65E0\u8BB0\u5F55" }) }) })] }) }), _jsx("div", { className: "divide-y md:hidden", children: data.data?.rows.map(r => _jsxs("article", { className: "space-y-2 p-3", children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium", children: botLabel(r.bot_rid) }), _jsxs("div", { className: "font-mono text-[10px] text-muted-foreground", children: ["#", r.rid, " \u00B7 ", platformLabel(r.platform_name), " \u00B7 ", r.tg_admin_uid || '无管理员 ID'] })] }), _jsx(Switch, { checked: r.status === 0, disabled: !data.data?.canStatus || mutation.isPending, onCheckedChange: enabled => mutation.mutate({ action: 'status', rid: r.rid, enabled }) })] }), r.platform_name === 3 ? _jsxs("div", { className: "rounded-md bg-muted/50 p-2 text-xs text-muted-foreground", children: ["\u4F7F\u7528 Telegram Stars \u5B98\u65B9\u63A5\u53E3\u5F00\u901A\uFF0CBot \u9700\u6709\u8DB3\u591F Stars\u3002", _jsxs("p", { className: "mt-1 truncate font-mono", children: ["USDT \u6536\u6B3E\uFF1A", r.receive_wallet || '—'] }), _jsxs("p", { children: ["\u5F00\u59CB\u62C9\u53D6\uFF1A", r.get_tx_time || '—'] })] }) : _jsxs("div", { className: "grid grid-cols-2 gap-2 text-xs", children: [_jsxs("div", { children: [_jsx("span", { className: "text-muted-foreground", children: "\u5E73\u53F0 Hash" }), _jsx("p", { className: "truncate font-mono", children: r.platform_hash || '—' })] }), _jsxs("div", { children: [_jsx("span", { className: "text-muted-foreground", children: "\u5BC6\u94A5\u72B6\u6001" }), _jsxs("p", { children: ["Cookie ", r.cookie_configured ? '已设置' : '未设置', " \u00B7 \u52A9\u8BB0\u8BCD ", r.phrase_configured ? '已设置' : '未设置'] })] }), _jsxs("div", { className: "col-span-2", children: [_jsx("span", { className: "text-muted-foreground", children: "\u6536\u6B3E\u94B1\u5305" }), _jsx("p", { className: "truncate font-mono", children: r.receive_wallet || '—' })] }), _jsxs("div", { children: [_jsx("span", { className: "text-muted-foreground", children: "\u62C9\u53D6\u65F6\u95F4" }), _jsx("p", { children: r.get_tx_time || '—' })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-2 text-xs", children: [_jsxs("div", { children: [_jsx("span", { className: "text-muted-foreground", children: "\u521B\u5EFA\u65F6\u95F4" }), _jsx("p", { children: r.create_time || '—' })] }), _jsxs("div", { children: [_jsx("span", { className: "text-muted-foreground", children: "\u901A\u77E5\u5BF9\u8C61" }), _jsx("p", { className: "truncate", children: r.tg_notice_obj_send || '—' })] }), _jsxs("div", { className: "col-span-2", children: [_jsx("span", { className: "text-muted-foreground", children: "\u5907\u6CE8" }), _jsx("p", { className: "truncate", children: r.comments || '—' })] })] }), _jsxs("div", { className: "flex flex-wrap gap-1", children: [data.data?.canEdit && _jsxs(Button, { size: "sm", variant: "outline", className: "h-7 text-xs", onClick: () => open(r), children: [_jsx(Pencil, { className: "mr-1 size-3" }), "\u7F16\u8F91"] }), r.platform_name !== 3 && data.data?.canCookie && _jsx(Button, { size: "sm", variant: "outline", className: "h-7 text-xs", onClick: () => { setSecret({ row: r, kind: 'cookie' }); setSecretValue(''); }, children: "Cookie" }), r.platform_name !== 3 && data.data?.canPhrase && _jsx(Button, { size: "sm", variant: "outline", className: "h-7 text-xs", onClick: () => { setSecret({ row: r, kind: 'phrase' }); setSecretValue(''); }, children: "\u52A9\u8BB0\u8BCD" }), data.data?.canDelete && _jsxs(Button, { size: "sm", variant: "outline", className: "h-7 text-xs text-destructive", onClick: () => setRemove(r), children: [_jsx(Trash2, { className: "mr-1 size-3" }), "\u5220\u9664"] })] })] }, r.rid)) }), _jsxs("footer", { className: "flex flex-wrap items-center justify-between gap-2 border-t px-3 py-2", children: [_jsxs("span", { className: "text-xs text-muted-foreground", children: ["\u7B2C ", page, "/", pages, " \u9875"] }), _jsxs("div", { className: "flex items-center gap-1.5", children: [_jsxs(Select, { value: String(pageSize), onValueChange: v => { setPageSize(Number(v)); setPage(1); }, children: [_jsx(SelectTrigger, { className: "h-8 w-24 text-xs", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: [10, 15, 20, 30, 50, 100].map(n => _jsxs(SelectItem, { value: String(n), children: [n, " \u6761/\u9875"] }, n)) })] }), _jsx(Button, { variant: "outline", size: "icon", className: "size-8", "aria-label": "\u4E0A\u4E00\u9875", disabled: page <= 1 || data.isFetching, onClick: () => setPage(v => v - 1), children: _jsx(ChevronLeft, { className: "size-3.5" }) }), _jsx(Button, { variant: "outline", size: "icon", className: "size-8", "aria-label": "\u4E0B\u4E00\u9875", disabled: page >= pages || data.isFetching, onClick: () => setPage(v => v + 1), children: _jsx(ChevronRight, { className: "size-3.5" }) })] })] })] })] }), _jsx(Dialog, { open: !!editor, onOpenChange: v => { if (!v)
|
|
27
|
+
setEditor(null); }, children: _jsxs(DialogContent, { className: "max-h-[90vh] max-w-2xl overflow-y-auto", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: editor === 'create' ? '添加会员平台' : '编辑会员平台' }) }), _jsxs("form", { id: "premium-platform-form", className: "grid gap-3 sm:grid-cols-2", onSubmit: e => { e.preventDefault(); save(); }, children: [_jsxs("label", { className: "space-y-1 text-xs", children: [_jsx("span", { children: "\u673A\u5668\u4EBA" }), _jsxs(Select, { value: form.bot_rid, onValueChange: v => { setForm({ ...form, bot_rid: v }); setStarsBalance(null); }, children: [_jsx(SelectTrigger, { className: "h-9 text-xs", children: _jsx(SelectValue, { placeholder: "\u9009\u62E9\u673A\u5668\u4EBA" }) }), _jsx(SelectContent, { children: options.data?.bots.map(b => _jsxs(SelectItem, { value: String(b.rid), children: [botName(b), b.bot_username ? ' (@' + b.bot_username + ')' : ''] }, b.rid)) })] })] }), _jsxs("label", { className: "space-y-1 text-xs", children: [_jsx("span", { children: "\u4F1A\u5458\u5E73\u53F0" }), _jsxs(Select, { value: form.platform_name, onValueChange: v => { setForm({ ...form, platform_name: v }); setStarsBalance(null); }, children: [_jsx(SelectTrigger, { className: "h-9 text-xs", children: _jsx(SelectValue, {}) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "1", children: "\u81EA\u5DF1\u642D\u5EFA" }), _jsx(SelectItem, { value: "2", children: "API \u5E73\u53F0\u8C03\u7528" }), _jsx(SelectItem, { value: "3", children: "Telegram Stars \u5B98\u65B9\u63A5\u53E3" })] })] })] }), form.platform_name === '3' && _jsxs("div", { className: "rounded-md border bg-muted/30 p-3 text-xs text-muted-foreground sm:col-span-2", children: [_jsx("p", { className: "mb-1 font-medium text-foreground", children: "Telegram Stars \u5F00\u901A\u8BF4\u660E" }), _jsxs("ul", { className: "list-disc space-y-1 pl-4", children: [_jsxs("li", { children: ["\u9002\u5408 Telegram Stars \u652F\u4ED8\uFF0C\u4F7F\u7528\u5B98\u65B9\u63A5\u53E3 ", _jsx("code", { children: "giftPremiumSubscription" }), "\u3002"] }), _jsx("li", { children: "\u65E0\u9700 Fragment Cookie\uFF0C\u4E5F\u65E0\u9700\u81EA\u884C\u7BA1\u7406 TON \u94B1\u5305\uFF1B\u8D2D\u4E70\u8005\u4ECD\u6309\u5957\u9910\u652F\u4ED8 USDT \u5230\u4E0A\u65B9\u6536\u6B3E\u94B1\u5305\u3002" }), _jsx("li", { children: "\u7531\u673A\u5668\u4EBA\u4F59\u989D\u652F\u4ED8\uFF0C\u5F00\u901A\u524D\u4F1A\u68C0\u67E5 Bot \u662F\u5426\u6709\u8DB3\u591F Stars\u3002" }), _jsx("li", { children: "\u63A5\u53E3\u9700\u8981\u76EE\u6807\u7528\u6237\u7684 Telegram \u6570\u5B57 ID\uFF1B\u5DF2\u88AB\u673A\u5668\u4EBA\u8BB0\u5F55\u7684\u7528\u6237\u540D\u4F1A\u81EA\u52A8\u89E3\u6790\uFF0C\u8D2D\u4E70\u65F6\u4E5F\u53EF\u76F4\u63A5\u53D1\u9001\u6570\u503C ID\u3002" })] }), _jsxs("div", { className: "mt-2 flex flex-wrap items-center gap-2", children: [_jsx(Button, { type: "button", variant: "outline", size: "sm", className: "h-7 text-xs", disabled: !form.bot_rid || balanceQuery.isPending, onClick: () => balanceQuery.mutate(Number(form.bot_rid)), children: balanceQuery.isPending ? '查询中…' : '查询机器人 Stars 余额' }), starsBalance?.botRid === Number(form.bot_rid) && _jsxs("span", { children: ["\u5F53\u524D\u4F59\u989D\uFF1A", _jsxs("strong", { className: "text-foreground", children: [starsBalance.amount, " Stars"] })] })] })] }), _jsxs("label", { className: "space-y-1 text-xs", children: [_jsx("span", { children: "TG \u7BA1\u7406\u5458\u7528\u6237 ID" }), _jsx(Input, { maxLength: 500, value: form.tg_admin_uid, onChange: e => setForm({ ...form, tg_admin_uid: e.target.value }), className: "h-9 text-xs" })] }), form.platform_name !== '3' && _jsxs(_Fragment, { children: [_jsxs("label", { className: "space-y-1 text-xs sm:col-span-2", children: [_jsxs("span", { className: "flex items-center gap-2", children: [_jsx("span", { children: "\u5E73\u53F0 Hash" }), _jsx("a", { href: "https://fragment.com/", target: "_blank", rel: "noopener noreferrer", className: "text-primary underline underline-offset-2", children: "Fragment \u2197" })] }), _jsx(Input, { maxLength: 500, value: form.platform_hash, onChange: e => setForm({ ...form, platform_hash: e.target.value }), className: "h-9 font-mono text-xs" })] }), editor === 'create' && _jsxs("label", { className: "space-y-1 text-xs sm:col-span-2", children: [_jsx("span", { children: "\u5E73\u53F0 Cookie\uFF08\u53EF\u540E\u7EED\u5355\u72EC\u66F4\u65B0\uFF09" }), _jsx(Input, { type: "password", autoComplete: "new-password", maxLength: 2500, value: form.platform_cookie, onChange: e => setForm({ ...form, platform_cookie: e.target.value }), className: "h-9 font-mono text-xs" })] })] }), _jsxs("label", { className: "space-y-1 text-xs sm:col-span-2", children: [_jsx("span", { children: "USDT \u6536\u6B3E\u94B1\u5305" }), _jsx(Input, { maxLength: 100, value: form.receive_wallet, onChange: e => setForm({ ...form, receive_wallet: e.target.value }), className: "h-9 font-mono text-xs" })] }), _jsxs("label", { className: "space-y-1 text-xs", children: [_jsx("span", { children: "\u5F00\u59CB\u62C9\u53D6\u4EA4\u6613\u65F6\u95F4" }), _jsx(Input, { type: "datetime-local", value: form.get_tx_time ? form.get_tx_time.replace(' ', 'T').slice(0, 16) : '', onChange: e => setForm({ ...form, get_tx_time: e.target.value ? e.target.value.replace('T', ' ') + ':00' : '' }), className: "h-9 text-xs" })] }), _jsxs("label", { className: "space-y-1 text-xs", children: [_jsx("span", { children: "\u6536\u6B3E\u901A\u77E5\u5BF9\u8C61\uFF08\u9017\u53F7\u5206\u9694\uFF09" }), _jsx(Input, { maxLength: 200, value: form.tg_notice_obj_receive, onChange: e => setForm({ ...form, tg_notice_obj_receive: e.target.value }), className: "h-9 text-xs" })] }), _jsxs("label", { className: "space-y-1 text-xs", children: [_jsx("span", { children: "\u6210\u529F\u901A\u77E5\u5BF9\u8C61\uFF08\u9017\u53F7\u5206\u9694\uFF09" }), _jsx(Input, { maxLength: 200, value: form.tg_notice_obj_send, onChange: e => setForm({ ...form, tg_notice_obj_send: e.target.value }), className: "h-9 text-xs" })] }), _jsxs("label", { className: "space-y-1 text-xs sm:col-span-2", children: [_jsx("span", { children: "\u5907\u6CE8" }), _jsx(Textarea, { maxLength: 255, value: form.comments, onChange: e => setForm({ ...form, comments: e.target.value }), className: "min-h-16 text-xs" })] })] }), failure && editor && _jsx("p", { role: "alert", className: "text-xs text-destructive", children: failure }), _jsxs(DialogFooter, { children: [_jsx(Button, { size: "sm", variant: "outline", onClick: () => setEditor(null), children: "\u53D6\u6D88" }), _jsx(Button, { size: "sm", form: "premium-platform-form", disabled: mutation.isPending || !form.bot_rid, children: mutation.isPending ? '保存中…' : '保存' })] })] }) }), _jsx(Dialog, { open: !!secret, onOpenChange: v => { if (!v) {
|
|
28
|
+
setSecret(null);
|
|
29
|
+
setSecretValue('');
|
|
30
|
+
} }, children: _jsxs(DialogContent, { className: "max-w-md", children: [_jsx(DialogHeader, { children: _jsxs(DialogTitle, { children: ["\u66F4\u65B0", secret?.kind === 'cookie' ? '平台 Cookie' : '钱包助记词'] }) }), _jsx("p", { className: "text-xs text-muted-foreground", children: "\u5185\u5BB9\u4F1A\u4F7F\u7528\u670D\u52A1\u5668 RSA \u516C\u94A5\u52A0\u5BC6\u540E\u4FDD\u5B58\uFF0C\u4E0D\u4F1A\u518D\u6B21\u663E\u793A\u3002" }), _jsx(Textarea, { autoComplete: "off", value: secretValue, onChange: e => setSecretValue(e.target.value), className: "min-h-28 font-mono text-xs" }), failure && secret && _jsx("p", { role: "alert", className: "text-xs text-destructive", children: failure }), _jsxs(DialogFooter, { children: [_jsx(Button, { size: "sm", variant: "outline", onClick: () => setSecret(null), children: "\u53D6\u6D88" }), _jsx(Button, { size: "sm", disabled: !secretValue.trim() || mutation.isPending, onClick: () => secret && mutation.mutate({ action: secret.kind, rid: secret.row.rid, value: secretValue }), children: "\u52A0\u5BC6\u4FDD\u5B58" })] })] }) }), _jsx(Dialog, { open: !!remove, onOpenChange: v => { if (!v)
|
|
31
|
+
setRemove(null); }, children: _jsxs(DialogContent, { className: "max-w-sm", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: "\u5220\u9664\u4F1A\u5458\u5E73\u53F0\uFF1F" }) }), _jsxs("p", { className: "text-xs text-muted-foreground", children: [remove && botLabel(remove.bot_rid), " \u00B7 #", remove?.rid] }), failure && remove && _jsx("p", { role: "alert", className: "text-xs text-destructive", children: failure }), _jsxs(DialogFooter, { children: [_jsx(Button, { size: "sm", variant: "outline", onClick: () => setRemove(null), children: "\u53D6\u6D88" }), _jsx(Button, { size: "sm", variant: "destructive", disabled: mutation.isPending, onClick: () => remove && mutation.mutate({ action: 'delete', rid: remove.rid }), children: "\u786E\u8BA4\u5220\u9664" })] })] }) }), _jsx(Dialog, { open: !!feedback, onOpenChange: v => { if (!v)
|
|
32
|
+
setFeedback(''); }, children: _jsxs(DialogContent, { className: "max-w-sm", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: feedback }) }), _jsx(DialogFooter, { children: _jsx(Button, { size: "sm", onClick: () => setFeedback(''), children: "\u786E\u5B9A" }) })] }) })] });
|
|
33
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { usePremiumAdminRuntime } from './admin-ui-runtime.js'
|
|
2
|
+
import {useState} from 'react'
|
|
3
|
+
import {useMutation,useQuery,useQueryClient} from '@tanstack/react-query'
|
|
4
|
+
import {ChevronLeft,ChevronRight,KeyRound,Pencil,Plus,RefreshCw,Search,ShieldCheck,Trash2} from 'lucide-react'
|
|
5
|
+
type Bot={rid:number;bot_firstname:string|null;bot_username:string|null}
|
|
6
|
+
type Row={rid:number;bot_rid:number;bot_firstname:string|null;bot_username:string|null;platform_name:number;tg_admin_uid:string|null;platform_hash:string|null;cookie_configured:boolean;phrase_configured:boolean;status:number;receive_wallet:string|null;get_tx_time:string|null;tg_notice_obj_receive:string|null;tg_notice_obj_send:string|null;comments:string|null;create_time:string}
|
|
7
|
+
type Data={rows:Row[];total:number;page:number;pageSize:number;canAdd:boolean;canEdit:boolean;canDelete:boolean;canStatus:boolean;canCookie:boolean;canPhrase:boolean}
|
|
8
|
+
type Form={bot_rid:string;platform_name:string;tg_admin_uid:string;platform_hash:string;platform_cookie:string;receive_wallet:string;get_tx_time:string;tg_notice_obj_receive:string;tg_notice_obj_send:string;comments:string}
|
|
9
|
+
const empty:Form={bot_rid:'',platform_name:'1',tg_admin_uid:'',platform_hash:'',platform_cookie:'',receive_wallet:'',get_tx_time:'',tg_notice_obj_receive:'',tg_notice_obj_send:'',comments:''}
|
|
10
|
+
type Action=Record<string,unknown>
|
|
11
|
+
const platformLabel=(name:number)=>name===1?'自己搭建':name===2?'API 平台调用':'Telegram Stars 官方接口'
|
|
12
|
+
export function PremiumPlatformsPage(){
|
|
13
|
+
const {AdminShell, Button, Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, Textarea, api, ApiError}=usePremiumAdminRuntime()
|
|
14
|
+
const client=useQueryClient(),me=useQuery({queryKey:['me'],queryFn:()=>api<Record<string, unknown>>('/api/me'),retry:false,staleTime:60000})
|
|
15
|
+
const logout=useMutation({mutationFn:()=>api('/api/auth/logout',{method:'POST',headers:{'Content-Type':'application/json'},body:'{}'}),onSuccess:()=>{client.clear();location.assign('/console/home')}})
|
|
16
|
+
const [draft,setDraft]=useState(''),[search,setSearch]=useState(''),[page,setPage]=useState(1),[pageSize,setPageSize]=useState(15),[editor,setEditor]=useState<'create'|Row|null>(null),[form,setForm]=useState<Form>(empty),[secret,setSecret]=useState<{row:Row;kind:'cookie'|'phrase'}|null>(null),[secretValue,setSecretValue]=useState(''),[remove,setRemove]=useState<Row|null>(null),[feedback,setFeedback]=useState(''),[failure,setFailure]=useState(''),[starsBalance,setStarsBalance]=useState<{botRid:number;amount:number}|null>(null)
|
|
17
|
+
const data=useQuery({queryKey:['premium-platforms',page,pageSize,search],queryFn:()=>api<Data>('/api/premium-platforms?'+new URLSearchParams({page:String(page),pageSize:String(pageSize),search})),enabled:!!me.data,retry:false})
|
|
18
|
+
const options=useQuery({queryKey:['premium-platforms','options'],queryFn:()=>api<{bots:Bot[]}>('/api/premium-platforms?action=options'),enabled:!!me.data,retry:false,staleTime:60000})
|
|
19
|
+
const mutation=useMutation({mutationFn:(body:Action)=>api<{message:string}>('/api/premium-platforms',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)}),onSuccess:async result=>{setFeedback(result.message);setEditor(null);setSecret(null);setSecretValue('');setRemove(null);setFailure('');await client.invalidateQueries({queryKey:['premium-platforms']})},onError:e=>setFailure(e instanceof ApiError?e.message:'操作失败,请重试')})
|
|
20
|
+
const balanceQuery=useMutation({mutationFn:(botRid:number)=>api<{stars:number}>('/api/premium-platforms?action=starsBalance&botRid='+botRid),onSuccess:(result,botRid)=>{setStarsBalance({botRid,amount:result.stars});setFailure('')},onError:e=>setFailure(e instanceof ApiError?e.message:'读取机器人 Stars 余额失败')})
|
|
21
|
+
if(me.isPending)return <div className="flex min-h-screen items-center justify-center"><RefreshCw className="size-4 animate-spin" aria-label="加载中"/></div>
|
|
22
|
+
if(!me.data)return <main className="flex min-h-screen items-center justify-center p-4"><section className="w-full max-w-sm space-y-4 rounded-xl bg-card p-6"><h1 className="font-semibold">登录管理后台</h1><Button asChild className="w-full"><a href="/api/auth/start?destination=premiumPlatforms">管理员登录</a></Button></section></main>
|
|
23
|
+
const total=data.data?.total||0,pages=Math.max(1,Math.ceil(total/pageSize)),botName=(b:Bot)=>b.bot_firstname||b.bot_username||'机器人 #'+b.rid
|
|
24
|
+
const open=(row?:Row)=>{mutation.reset();balanceQuery.reset();setStarsBalance(null);setFailure('');setForm(row?{bot_rid:String(row.bot_rid),platform_name:String(row.platform_name),tg_admin_uid:row.tg_admin_uid||'',platform_hash:row.platform_hash||'',platform_cookie:'',receive_wallet:row.receive_wallet||'',get_tx_time:row.get_tx_time||'',tg_notice_obj_receive:row.tg_notice_obj_receive||'',tg_notice_obj_send:row.tg_notice_obj_send||'',comments:row.comments||''}:{...empty});setEditor(row||'create')}
|
|
25
|
+
const save=()=>{if(!editor)return;const body={action:editor==='create'?'create':'update',...(editor==='create'?{}:{rid:editor.rid}),bot_rid:Number(form.bot_rid),platform_name:Number(form.platform_name),tg_admin_uid:form.tg_admin_uid.trim(),platform_hash:form.platform_hash.trim(),...(editor==='create'?{platform_cookie:form.platform_cookie.trim()}:{}),receive_wallet:form.receive_wallet.trim(),get_tx_time:form.get_tx_time.trim(),tg_notice_obj_receive:form.tg_notice_obj_receive.trim(),tg_notice_obj_send:form.tg_notice_obj_send.trim(),comments:form.comments.trim()};mutation.mutate(body)}
|
|
26
|
+
const botLabel=(id:number)=>{const b=options.data?.bots.find(x=>x.rid===id);return b?botName(b):'机器人 #'+id}
|
|
27
|
+
return <AdminShell user={me.data} title="会员平台" activeRoute="admin.premium.platform.index" onRefresh={()=>data.refetch()} onLogout={()=>logout.mutate()}><main className="space-y-3 p-3 sm:p-4">
|
|
28
|
+
<form className="flex flex-wrap items-center gap-2 rounded-xl bg-card p-3" onSubmit={e=>{e.preventDefault();setSearch(draft.trim());setPage(1)}}><div className="relative min-w-40 flex-1"><Search className="absolute left-2.5 top-2.5 size-3.5 text-muted-foreground"/><Input value={draft} maxLength={100} onChange={e=>setDraft(e.target.value)} placeholder="搜索平台 Hash、管理员 ID 或备注" className="h-9 pl-8 text-xs"/></div><Button size="sm" className="h-9">搜索</Button><Button type="button" variant="outline" size="icon" className="size-9" aria-label="刷新" disabled={data.isFetching} onClick={()=>data.refetch()}><RefreshCw className={data.isFetching?'size-3.5 animate-spin':'size-3.5'}/></Button>{data.data?.canAdd&&<Button type="button" size="sm" className="h-9" onClick={()=>open()}><Plus className="mr-1 size-3.5"/>添加平台</Button>}</form>
|
|
29
|
+
{(data.error||failure)&&<div role="alert" className="rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive">{failure||(data.error instanceof ApiError?data.error.message:'加载失败')}</div>}
|
|
30
|
+
<section className="overflow-hidden rounded-xl bg-card"><header className="flex h-11 items-center justify-between border-b px-3"><h1 className="flex items-center gap-2 text-sm font-semibold"><ShieldCheck className="size-4 text-muted-foreground"/>会员平台</h1><span className="text-xs text-muted-foreground">共 {total} 条</span></header>
|
|
31
|
+
<div className="hidden overflow-x-auto md:block"><Table className="min-w-[1300px]"><TableHeader><TableRow>{['ID','机器人','会员平台','管理员 ID','平台 Hash','Cookie','助记词','状态','收款钱包','拉取时间','通知对象','创建时间','备注','操作'].map(x=><TableHead key={x} className="h-9 px-3">{x}</TableHead>)}</TableRow></TableHeader><TableBody>{data.isPending?<TableRow><TableCell colSpan={14} className="h-20 text-center text-xs text-muted-foreground">加载中…</TableCell></TableRow>:data.data?.rows.length?data.data.rows.map(r=><TableRow key={r.rid}><TableCell className="px-3 py-2 font-mono text-xs">#{r.rid}</TableCell><TableCell className="px-3 py-2 text-xs">{botLabel(r.bot_rid)}<span className="block text-muted-foreground">{r.bot_username?'@'+r.bot_username:''}</span></TableCell><TableCell className="px-3 py-2 text-xs">{platformLabel(r.platform_name)}</TableCell><TableCell className="px-3 py-2 font-mono text-xs">{r.tg_admin_uid||'—'}</TableCell><TableCell className="max-w-40 truncate px-3 py-2 font-mono text-xs" title={r.platform_hash||''}>{r.platform_name===3?'—':r.platform_hash||'—'}</TableCell><TableCell className="px-3 py-2 text-xs">{r.platform_name===3?'—':r.cookie_configured?'已加密设置':'未设置'}</TableCell><TableCell className="px-3 py-2 text-xs">{r.platform_name===3?'—':r.phrase_configured?'已加密设置':'未设置'}</TableCell><TableCell className="px-3 py-2"><Switch checked={r.status===0} disabled={!data.data?.canStatus||mutation.isPending} onCheckedChange={enabled=>mutation.mutate({action:'status',rid:r.rid,enabled})}/></TableCell><TableCell className="max-w-44 truncate px-3 py-2 font-mono text-xs" title={r.receive_wallet||''}>{r.receive_wallet||'—'}</TableCell><TableCell className="whitespace-nowrap px-3 py-2 text-xs">{r.get_tx_time||'—'}</TableCell><TableCell className="max-w-44 px-3 py-2 text-xs"><div className="truncate">收款:{r.tg_notice_obj_receive||'—'}</div><div className="truncate">成功:{r.tg_notice_obj_send||'—'}</div></TableCell><TableCell className="whitespace-nowrap px-3 py-2 text-xs">{r.create_time||'—'}</TableCell><TableCell className="max-w-36 truncate px-3 py-2 text-xs" title={r.comments||''}>{r.comments||'—'}</TableCell><TableCell className="px-3 py-2"><div className="flex items-center gap-1">{data.data?.canEdit&&<Button size="icon" variant="ghost" className="size-7" aria-label="编辑" onClick={()=>open(r)}><Pencil className="size-3.5"/></Button>}{r.platform_name!==3&&data.data?.canCookie&&<Button size="icon" variant="ghost" className="size-7" aria-label="更新 Cookie" onClick={()=>{setSecret({row:r,kind:'cookie'});setSecretValue('');setFailure('')}}><KeyRound className="size-3.5"/></Button>}{r.platform_name!==3&&data.data?.canPhrase&&<Button size="sm" variant="ghost" className="h-7 px-2 text-xs" onClick={()=>{setSecret({row:r,kind:'phrase'});setSecretValue('');setFailure('')}}>助记词</Button>}{data.data?.canDelete&&<Button size="icon" variant="ghost" className="size-7 text-destructive" aria-label="删除" onClick={()=>{setRemove(r);setFailure('')}}><Trash2 className="size-3.5"/></Button>}</div></TableCell></TableRow>):<TableRow><TableCell colSpan={14} className="h-20 text-center text-xs text-muted-foreground">暂无记录</TableCell></TableRow>}</TableBody></Table></div>
|
|
32
|
+
<div className="divide-y md:hidden">{data.data?.rows.map(r=><article key={r.rid} className="space-y-2 p-3"><div className="flex items-center justify-between gap-2"><div><div className="text-sm font-medium">{botLabel(r.bot_rid)}</div><div className="font-mono text-[10px] text-muted-foreground">#{r.rid} · {platformLabel(r.platform_name)} · {r.tg_admin_uid||'无管理员 ID'}</div></div><Switch checked={r.status===0} disabled={!data.data?.canStatus||mutation.isPending} onCheckedChange={enabled=>mutation.mutate({action:'status',rid:r.rid,enabled})}/></div>{r.platform_name===3?<div className="rounded-md bg-muted/50 p-2 text-xs text-muted-foreground">使用 Telegram Stars 官方接口开通,Bot 需有足够 Stars。<p className="mt-1 truncate font-mono">USDT 收款:{r.receive_wallet||'—'}</p><p>开始拉取:{r.get_tx_time||'—'}</p></div>:<div className="grid grid-cols-2 gap-2 text-xs"><div><span className="text-muted-foreground">平台 Hash</span><p className="truncate font-mono">{r.platform_hash||'—'}</p></div><div><span className="text-muted-foreground">密钥状态</span><p>Cookie {r.cookie_configured?'已设置':'未设置'} · 助记词 {r.phrase_configured?'已设置':'未设置'}</p></div><div className="col-span-2"><span className="text-muted-foreground">收款钱包</span><p className="truncate font-mono">{r.receive_wallet||'—'}</p></div><div><span className="text-muted-foreground">拉取时间</span><p>{r.get_tx_time||'—'}</p></div></div>}<div className="grid grid-cols-2 gap-2 text-xs"><div><span className="text-muted-foreground">创建时间</span><p>{r.create_time||'—'}</p></div><div><span className="text-muted-foreground">通知对象</span><p className="truncate">{r.tg_notice_obj_send||'—'}</p></div><div className="col-span-2"><span className="text-muted-foreground">备注</span><p className="truncate">{r.comments||'—'}</p></div></div><div className="flex flex-wrap gap-1">{data.data?.canEdit&&<Button size="sm" variant="outline" className="h-7 text-xs" onClick={()=>open(r)}><Pencil className="mr-1 size-3"/>编辑</Button>}{r.platform_name!==3&&data.data?.canCookie&&<Button size="sm" variant="outline" className="h-7 text-xs" onClick={()=>{setSecret({row:r,kind:'cookie'});setSecretValue('')}}>Cookie</Button>}{r.platform_name!==3&&data.data?.canPhrase&&<Button size="sm" variant="outline" className="h-7 text-xs" onClick={()=>{setSecret({row:r,kind:'phrase'});setSecretValue('')}}>助记词</Button>}{data.data?.canDelete&&<Button size="sm" variant="outline" className="h-7 text-xs text-destructive" onClick={()=>setRemove(r)}><Trash2 className="mr-1 size-3"/>删除</Button>}</div></article>)}</div>
|
|
33
|
+
<footer className="flex flex-wrap items-center justify-between gap-2 border-t px-3 py-2"><span className="text-xs text-muted-foreground">第 {page}/{pages} 页</span><div className="flex items-center gap-1.5"><Select value={String(pageSize)} onValueChange={v=>{setPageSize(Number(v));setPage(1)}}><SelectTrigger className="h-8 w-24 text-xs"><SelectValue/></SelectTrigger><SelectContent>{[10,15,20,30,50,100].map(n=><SelectItem key={n} value={String(n)}>{n} 条/页</SelectItem>)}</SelectContent></Select><Button variant="outline" size="icon" className="size-8" aria-label="上一页" disabled={page<=1||data.isFetching} onClick={()=>setPage(v=>v-1)}><ChevronLeft className="size-3.5"/></Button><Button variant="outline" size="icon" className="size-8" aria-label="下一页" disabled={page>=pages||data.isFetching} onClick={()=>setPage(v=>v+1)}><ChevronRight className="size-3.5"/></Button></div></footer>
|
|
34
|
+
</section>
|
|
35
|
+
</main>
|
|
36
|
+
<Dialog open={!!editor} onOpenChange={v=>{if(!v)setEditor(null)}}><DialogContent className="max-h-[90vh] max-w-2xl overflow-y-auto"><DialogHeader><DialogTitle>{editor==='create'?'添加会员平台':'编辑会员平台'}</DialogTitle></DialogHeader><form id="premium-platform-form" className="grid gap-3 sm:grid-cols-2" onSubmit={e=>{e.preventDefault();save()}}>
|
|
37
|
+
<label className="space-y-1 text-xs"><span>机器人</span><Select value={form.bot_rid} onValueChange={v=>{setForm({...form,bot_rid:v});setStarsBalance(null)}}><SelectTrigger className="h-9 text-xs"><SelectValue placeholder="选择机器人"/></SelectTrigger><SelectContent>{options.data?.bots.map(b=><SelectItem key={b.rid} value={String(b.rid)}>{botName(b)}{b.bot_username?' (@'+b.bot_username+')':''}</SelectItem>)}</SelectContent></Select></label>
|
|
38
|
+
<label className="space-y-1 text-xs"><span>会员平台</span><Select value={form.platform_name} onValueChange={v=>{setForm({...form,platform_name:v});setStarsBalance(null)}}><SelectTrigger className="h-9 text-xs"><SelectValue/></SelectTrigger><SelectContent><SelectItem value="1">自己搭建</SelectItem><SelectItem value="2">API 平台调用</SelectItem><SelectItem value="3">Telegram Stars 官方接口</SelectItem></SelectContent></Select></label>
|
|
39
|
+
{form.platform_name==='3'&&<div className="rounded-md border bg-muted/30 p-3 text-xs text-muted-foreground sm:col-span-2"><p className="mb-1 font-medium text-foreground">Telegram Stars 开通说明</p><ul className="list-disc space-y-1 pl-4"><li>适合 Telegram Stars 支付,使用官方接口 <code>giftPremiumSubscription</code>。</li><li>无需 Fragment Cookie,也无需自行管理 TON 钱包;购买者仍按套餐支付 USDT 到上方收款钱包。</li><li>由机器人余额支付,开通前会检查 Bot 是否有足够 Stars。</li><li>接口需要目标用户的 Telegram 数字 ID;已被机器人记录的用户名会自动解析,购买时也可直接发送数值 ID。</li></ul><div className="mt-2 flex flex-wrap items-center gap-2"><Button type="button" variant="outline" size="sm" className="h-7 text-xs" disabled={!form.bot_rid||balanceQuery.isPending} onClick={()=>balanceQuery.mutate(Number(form.bot_rid))}>{balanceQuery.isPending?'查询中…':'查询机器人 Stars 余额'}</Button>{starsBalance?.botRid===Number(form.bot_rid)&&<span>当前余额:<strong className="text-foreground">{starsBalance.amount} Stars</strong></span>}</div></div>}
|
|
40
|
+
<label className="space-y-1 text-xs"><span>TG 管理员用户 ID</span><Input maxLength={500} value={form.tg_admin_uid} onChange={e=>setForm({...form,tg_admin_uid:e.target.value})} className="h-9 text-xs"/></label>
|
|
41
|
+
{form.platform_name!=='3'&&<><label className="space-y-1 text-xs sm:col-span-2"><span className="flex items-center gap-2"><span>平台 Hash</span><a href="https://fragment.com/" target="_blank" rel="noopener noreferrer" className="text-primary underline underline-offset-2">Fragment ↗</a></span><Input maxLength={500} value={form.platform_hash} onChange={e=>setForm({...form,platform_hash:e.target.value})} className="h-9 font-mono text-xs"/></label>
|
|
42
|
+
{editor==='create'&&<label className="space-y-1 text-xs sm:col-span-2"><span>平台 Cookie(可后续单独更新)</span><Input type="password" autoComplete="new-password" maxLength={2500} value={form.platform_cookie} onChange={e=>setForm({...form,platform_cookie:e.target.value})} className="h-9 font-mono text-xs"/></label>}</>}
|
|
43
|
+
<label className="space-y-1 text-xs sm:col-span-2"><span>USDT 收款钱包</span><Input maxLength={100} value={form.receive_wallet} onChange={e=>setForm({...form,receive_wallet:e.target.value})} className="h-9 font-mono text-xs"/></label>
|
|
44
|
+
<label className="space-y-1 text-xs"><span>开始拉取交易时间</span><Input type="datetime-local" value={form.get_tx_time?form.get_tx_time.replace(' ','T').slice(0,16):''} onChange={e=>setForm({...form,get_tx_time:e.target.value?e.target.value.replace('T',' ')+':00':''})} className="h-9 text-xs"/></label>
|
|
45
|
+
<label className="space-y-1 text-xs"><span>收款通知对象(逗号分隔)</span><Input maxLength={200} value={form.tg_notice_obj_receive} onChange={e=>setForm({...form,tg_notice_obj_receive:e.target.value})} className="h-9 text-xs"/></label>
|
|
46
|
+
<label className="space-y-1 text-xs"><span>成功通知对象(逗号分隔)</span><Input maxLength={200} value={form.tg_notice_obj_send} onChange={e=>setForm({...form,tg_notice_obj_send:e.target.value})} className="h-9 text-xs"/></label>
|
|
47
|
+
<label className="space-y-1 text-xs sm:col-span-2"><span>备注</span><Textarea maxLength={255} value={form.comments} onChange={e=>setForm({...form,comments:e.target.value})} className="min-h-16 text-xs"/></label></form>{failure&&editor&&<p role="alert" className="text-xs text-destructive">{failure}</p>}<DialogFooter><Button size="sm" variant="outline" onClick={()=>setEditor(null)}>取消</Button><Button size="sm" form="premium-platform-form" disabled={mutation.isPending||!form.bot_rid}>{mutation.isPending?'保存中…':'保存'}</Button></DialogFooter></DialogContent></Dialog>
|
|
48
|
+
<Dialog open={!!secret} onOpenChange={v=>{if(!v){setSecret(null);setSecretValue('')}}}><DialogContent className="max-w-md"><DialogHeader><DialogTitle>更新{secret?.kind==='cookie'?'平台 Cookie':'钱包助记词'}</DialogTitle></DialogHeader><p className="text-xs text-muted-foreground">内容会使用服务器 RSA 公钥加密后保存,不会再次显示。</p><Textarea autoComplete="off" value={secretValue} onChange={e=>setSecretValue(e.target.value)} className="min-h-28 font-mono text-xs"/>{failure&&secret&&<p role="alert" className="text-xs text-destructive">{failure}</p>}<DialogFooter><Button size="sm" variant="outline" onClick={()=>setSecret(null)}>取消</Button><Button size="sm" disabled={!secretValue.trim()||mutation.isPending} onClick={()=>secret&&mutation.mutate({action:secret.kind,rid:secret.row.rid,value:secretValue})}>加密保存</Button></DialogFooter></DialogContent></Dialog>
|
|
49
|
+
<Dialog open={!!remove} onOpenChange={v=>{if(!v)setRemove(null)}}><DialogContent className="max-w-sm"><DialogHeader><DialogTitle>删除会员平台?</DialogTitle></DialogHeader><p className="text-xs text-muted-foreground">{remove&&botLabel(remove.bot_rid)} · #{remove?.rid}</p>{failure&&remove&&<p role="alert" className="text-xs text-destructive">{failure}</p>}<DialogFooter><Button size="sm" variant="outline" onClick={()=>setRemove(null)}>取消</Button><Button size="sm" variant="destructive" disabled={mutation.isPending} onClick={()=>remove&&mutation.mutate({action:'delete',rid:remove.rid})}>确认删除</Button></DialogFooter></DialogContent></Dialog>
|
|
50
|
+
<Dialog open={!!feedback} onOpenChange={v=>{if(!v)setFeedback('')}}><DialogContent className="max-w-sm"><DialogHeader><DialogTitle>{feedback}</DialogTitle></DialogHeader><DialogFooter><Button size="sm" onClick={()=>setFeedback('')}>确定</Button></DialogFooter></DialogContent></Dialog>
|
|
51
|
+
</AdminShell>
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function PremiumTradesPage(): import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { usePremiumAdminRuntime } from './admin-ui-runtime.js';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
5
|
+
import { Ban, ChevronLeft, ChevronRight, KeyRound, RefreshCw, RotateCcw, Search, WalletCards } from 'lucide-react';
|
|
6
|
+
export function PremiumTradesPage() {
|
|
7
|
+
const { AdminShell, Button, Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, Textarea, api, ApiError } = usePremiumAdminRuntime();
|
|
8
|
+
const client = useQueryClient(), me = useQuery({ queryKey: ['me'], queryFn: () => api('/api/me'), retry: false, staleTime: 60_000 });
|
|
9
|
+
const logout = useMutation({ mutationFn: () => api('/api/auth/logout', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' }), onSuccess: () => { client.clear(); window.location.assign('/console/home'); } });
|
|
10
|
+
const [draft, setDraft] = useState({ tx_hash: '', transferfrom_address: '', transferto_address: '' }), [filter, setFilter] = useState(draft), [page, setPage] = useState(1), [pageSize, setPageSize] = useState(15), [selected, setSelected] = useState(null), [action, setAction] = useState(null);
|
|
11
|
+
const query = useQuery({ queryKey: ['premium-trades', page, pageSize, filter], queryFn: () => api(`/api/premium-trades?${new URLSearchParams({ page: String(page), pageSize: String(pageSize), ...filter })}`), enabled: !!me.data, retry: false });
|
|
12
|
+
const mutation = useMutation({ mutationFn: () => api('/api/premium-trades', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action, rid: selected?.rid }) }), onSuccess: async () => { setSelected(null); setAction(null); await client.invalidateQueries({ queryKey: ['premium-trades'] }); } });
|
|
13
|
+
if (me.isPending)
|
|
14
|
+
return _jsx("div", { className: "flex min-h-screen items-center justify-center", children: _jsx(RefreshCw, { className: "size-4 animate-spin text-muted-foreground", "aria-label": "\u6B63\u5728\u52A0\u8F7D" }) });
|
|
15
|
+
if (!me.data)
|
|
16
|
+
return _jsx("main", { className: "flex min-h-screen items-center justify-center p-4", children: _jsxs("section", { className: "w-full max-w-sm space-y-4 rounded-xl bg-card p-6 shadow-sm", children: [_jsxs("div", { className: "flex items-center gap-2 text-sm font-semibold", children: [_jsx(WalletCards, { className: "size-4" }), "TGBotPress"] }), _jsx("h1", { className: "text-base font-semibold", children: "\u767B\u5F55\u7BA1\u7406\u540E\u53F0" }), _jsx(Button, { asChild: true, className: "w-full", children: _jsxs("a", { href: "/api/auth/start?destination=premiumTrades", children: [_jsx(KeyRound, { className: "size-4" }), "\u7BA1\u7406\u5458\u767B\u5F55"] }) })] }) });
|
|
17
|
+
const total = query.data?.total || 0, pages = Math.max(1, Math.ceil(total / pageSize));
|
|
18
|
+
return _jsxs(AdminShell, { user: me.data, title: "\u4F1A\u5458\u4EA4\u6613", activeRoute: "admin.premium.trade.index", onRefresh: () => query.refetch(), onLogout: () => logout.mutate(), children: [_jsxs("main", { className: "space-y-3 p-3 sm:p-4", children: [_jsxs("form", { className: "flex flex-wrap items-center gap-2 rounded-xl bg-card p-3", onSubmit: e => { e.preventDefault(); setFilter(draft); setPage(1); }, children: [['tx_hash', 'transferfrom_address', 'transferto_address'].map((key, i) => _jsx(Input, { value: draft[key], maxLength: i ? 200 : 100, onChange: e => setDraft({ ...draft, [key]: e.target.value }), placeholder: ['交易 Hash', '发送钱包地址', '接收钱包地址'][i], className: "h-9 min-w-44 flex-1 text-xs" }, key)), _jsxs(Button, { size: "sm", className: "h-9", children: [_jsx(Search, { className: "mr-1 size-3.5" }), "\u641C\u7D22"] }), _jsx(Button, { type: "button", variant: "outline", size: "icon", className: "size-9", "aria-label": "\u5237\u65B0", disabled: query.isFetching, onClick: () => query.refetch(), children: _jsx(RefreshCw, { className: `size-3.5 ${query.isFetching ? 'animate-spin' : ''}` }) })] }), _jsxs("section", { className: "overflow-hidden rounded-xl bg-card", children: [_jsxs("header", { className: "flex h-11 items-center justify-between border-b px-3", children: [_jsxs("h1", { className: "flex items-center gap-2 text-sm font-semibold", children: [_jsx(WalletCards, { className: "size-4 text-muted-foreground" }), "\u4F1A\u5458\u4EA4\u6613"] }), _jsxs("span", { className: "text-xs text-muted-foreground", children: ["\u5171 ", total, " \u6761"] })] }), query.error && _jsx("div", { role: "alert", className: "px-3 py-3 text-xs text-destructive", children: query.error instanceof ApiError ? query.error.message : '加载失败,请重试' }), _jsx("div", { className: "hidden overflow-x-auto md:block", children: _jsxs(Table, { className: "min-w-[1500px]", children: [_jsx(TableHeader, { children: _jsx(TableRow, { children: ['ID', '交易 Hash', '发送钱包地址', '接收钱包地址', '币种', '转入金额', '交易时间', '拉取时间', '处理状态', '处理时间', '处理备注', '操作'].map(x => _jsx(TableHead, { className: "h-9 px-3", children: x }, x)) }) }), _jsx(TableBody, { children: query.isPending ? _jsx(TableRow, { children: _jsx(TableCell, { colSpan: 12, className: "h-20 text-center text-xs text-muted-foreground", children: "\u52A0\u8F7D\u4E2D\u2026" }) }) : query.data?.rows.length ? query.data.rows.map(row => _jsxs(TableRow, { children: [_jsxs(TableCell, { className: "px-3 py-2 font-mono text-xs", children: ["#", row.rid] }), _jsx(TableCell, { className: "max-w-52 truncate px-3 py-2 font-mono text-[10px]", title: row.tx_hash, children: row.tx_hash }), _jsx(TableCell, { className: "max-w-48 truncate px-3 py-2 font-mono text-[10px]", title: row.transferfrom_address, children: row.transferfrom_address }), _jsx(TableCell, { className: "max-w-48 truncate px-3 py-2 font-mono text-[10px]", title: row.transferto_address, children: row.transferto_address }), _jsx(TableCell, { className: "px-3 py-2 text-xs", children: row.coin_name }), _jsx(TableCell, { className: "px-3 py-2 font-mono text-xs", children: row.amount }), _jsx(TableCell, { className: "whitespace-nowrap px-3 py-2 text-xs", children: row.transaction_time }), _jsx(TableCell, { className: "whitespace-nowrap px-3 py-2 text-xs", children: row.get_time || '—' }), _jsx(TableCell, { className: "px-3 py-2", children: _jsx("span", { className: `rounded-full px-2 py-1 text-[10px] ${row.process_status === 9 ? 'bg-emerald-50 text-emerald-700' : row.process_status === 1 ? 'bg-amber-50 text-amber-700' : row.process_status === 2 ? 'bg-muted text-muted-foreground' : 'bg-muted text-foreground'}`, children: row.process_status_label }) }), _jsx(TableCell, { className: "whitespace-nowrap px-3 py-2 text-xs", children: row.process_time || '—' }), _jsx(TableCell, { className: "max-w-48 truncate px-3 py-2 text-xs", title: row.process_comments || '', children: row.process_comments || '—' }), _jsx(TableCell, { className: "px-3 py-2", children: _jsxs("div", { className: "flex items-center gap-1", children: [query.data.canReissue && _jsxs(Button, { size: "sm", variant: "outline", className: "h-7 px-2 text-[11px]", disabled: !row.can_reissue || !query.data.telegramEnabled, title: !query.data.telegramEnabled ? '开发环境未启用外部机器人操作' : undefined, onClick: () => { setSelected(row); setAction('reissue'); }, children: [_jsx(RotateCcw, { className: "mr-1 size-3" }), "\u8865\u53D1"] }), query.data.canStop && _jsxs(Button, { size: "sm", variant: "outline", className: "h-7 border-destructive/30 px-2 text-[11px] text-destructive hover:bg-destructive/10", disabled: !row.can_stop, onClick: () => { setSelected(row); setAction('stop'); }, children: [_jsx(Ban, { className: "mr-1 size-3" }), "\u7981\u6B62"] })] }) })] }, row.rid)) : _jsx(TableRow, { children: _jsx(TableCell, { colSpan: 12, className: "h-20 text-center text-xs text-muted-foreground", children: "\u6682\u65E0\u8BB0\u5F55" }) }) })] }) }), _jsx("div", { className: "divide-y md:hidden", children: query.isPending ? _jsx("p", { className: "py-8 text-center text-xs text-muted-foreground", children: "\u52A0\u8F7D\u4E2D\u2026" }) : query.data?.rows.length ? query.data.rows.map(row => _jsx(PremiumTradeMobileCard, { row: row, canReissue: !!query.data?.canReissue, canStop: !!query.data?.canStop, telegramEnabled: !!query.data?.telegramEnabled, onReissue: () => { setSelected(row); setAction('reissue'); }, onStop: () => { setSelected(row); setAction('stop'); } }, row.rid)) : _jsx("p", { className: "py-8 text-center text-xs text-muted-foreground", children: "\u6682\u65E0\u8BB0\u5F55" }) }), _jsxs("footer", { className: "flex flex-wrap items-center justify-between gap-2 border-t px-3 py-2", children: [_jsxs("span", { className: "text-xs text-muted-foreground", children: ["\u7B2C ", page, " / ", pages, " \u9875"] }), _jsxs("div", { className: "flex items-center gap-1.5", children: [_jsxs(Select, { value: String(pageSize), onValueChange: v => { setPageSize(Number(v)); setPage(1); }, children: [_jsx(SelectTrigger, { className: "h-8 w-24 text-xs", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: [10, 15, 20, 30, 50, 100].map(n => _jsxs(SelectItem, { value: String(n), className: "text-xs", children: [n, " \u6761/\u9875"] }, n)) })] }), _jsx(Button, { variant: "outline", size: "icon", className: "size-8", "aria-label": "\u4E0A\u4E00\u9875", disabled: page <= 1 || query.isFetching, onClick: () => setPage(p => p - 1), children: _jsx(ChevronLeft, { className: "size-3.5" }) }), _jsx(Button, { variant: "outline", size: "icon", className: "size-8", "aria-label": "\u4E0B\u4E00\u9875", disabled: page >= pages || query.isFetching, onClick: () => setPage(p => p + 1), children: _jsx(ChevronRight, { className: "size-3.5" }) })] })] })] })] }), _jsx(Dialog, { open: !!action, onOpenChange: open => { if (!open) {
|
|
19
|
+
setAction(null);
|
|
20
|
+
setSelected(null);
|
|
21
|
+
mutation.reset();
|
|
22
|
+
} }, children: _jsxs(DialogContent, { "aria-describedby": undefined, className: "max-w-md gap-4", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { className: "text-base", children: action === 'reissue' ? '确认补发会员订单' : '确认禁止兑换' }) }), selected && _jsxs("div", { className: "space-y-1 rounded-lg bg-muted px-3 py-2 text-xs", children: [_jsxs("p", { children: ["\u4EA4\u6613 #", selected.rid, " \u00B7 ", selected.coin_name, " ", selected.amount] }), _jsx("p", { className: "truncate font-mono text-[10px]", children: selected.tx_hash }), _jsxs("p", { children: ["\u5F53\u524D\u72B6\u6001\uFF1A", selected.process_status_label] })] }), action === 'reissue' && _jsx("p", { className: "text-xs text-muted-foreground", children: "\u63D0\u4EA4\u540E\u4F1A\u91CD\u65B0\u8FDB\u5165\u4F1A\u5458\u5F00\u901A\u5904\u7406\u961F\u5217\u3002" }), action === 'stop' && _jsx("p", { className: "text-xs text-muted-foreground", children: "\u6B64\u4EA4\u6613\u5C06\u6807\u8BB0\u4E3A\u4EBA\u5DE5\u7981\u6B62\uFF0C\u540E\u7EED\u4E0D\u4F1A\u7EE7\u7EED\u5151\u6362\u3002" }), mutation.error && _jsx("p", { role: "alert", className: "text-xs text-destructive", children: mutation.error instanceof ApiError ? mutation.error.message : '操作失败,请重试' }), _jsxs(DialogFooter, { children: [_jsx(Button, { size: "sm", variant: "outline", disabled: mutation.isPending, onClick: () => { setAction(null); setSelected(null); mutation.reset(); }, children: "\u53D6\u6D88" }), _jsx(Button, { size: "sm", variant: action === 'stop' ? 'destructive' : 'default', disabled: mutation.isPending || !selected, onClick: () => mutation.mutate(), children: mutation.isPending ? '处理中' : action === 'reissue' ? '提交补发' : '确认禁止' })] })] }) })] });
|
|
23
|
+
}
|
|
24
|
+
function PremiumTradeMobileCard({ row, canReissue, canStop, telegramEnabled, onReissue, onStop }) {
|
|
25
|
+
const { Button } = usePremiumAdminRuntime();
|
|
26
|
+
return _jsxs("article", { className: "space-y-3 p-3", children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { children: [_jsxs("p", { className: "text-sm font-medium", children: ["\u4EA4\u6613 #", row.rid, " \u00B7 ", row.coin_name, " ", row.amount] }), _jsxs("p", { className: "text-xs text-muted-foreground", children: ["\u4EA4\u6613\u65F6\u95F4 ", row.transaction_time] })] }), _jsx("span", { className: `rounded-full px-2 py-1 text-[10px] ${row.process_status === 9 ? 'bg-emerald-50 text-emerald-700' : row.process_status === 1 ? 'bg-amber-50 text-amber-700' : row.process_status === 2 ? 'bg-muted text-muted-foreground' : 'bg-destructive/10 text-destructive'}`, children: row.process_status_label })] }), _jsxs("dl", { className: "space-y-2 text-xs", children: [_jsxs("div", { children: [_jsx("dt", { className: "text-muted-foreground", children: "\u4EA4\u6613 Hash" }), _jsx("dd", { className: "mt-0.5 break-all font-mono text-[10px]", children: row.tx_hash })] }), _jsxs("div", { children: [_jsx("dt", { className: "text-muted-foreground", children: "\u53D1\u9001\u5730\u5740" }), _jsx("dd", { className: "mt-0.5 break-all font-mono text-[10px]", children: row.transferfrom_address })] }), _jsxs("div", { children: [_jsx("dt", { className: "text-muted-foreground", children: "\u63A5\u6536\u5730\u5740" }), _jsx("dd", { className: "mt-0.5 break-all font-mono text-[10px]", children: row.transferto_address })] }), _jsxs("div", { className: "grid grid-cols-2 gap-2", children: [_jsxs("div", { children: [_jsx("dt", { className: "text-muted-foreground", children: "\u62C9\u53D6\u65F6\u95F4" }), _jsx("dd", { className: "mt-0.5", children: row.get_time || '—' })] }), _jsxs("div", { children: [_jsx("dt", { className: "text-muted-foreground", children: "\u5904\u7406\u65F6\u95F4" }), _jsx("dd", { className: "mt-0.5", children: row.process_time || '—' })] })] }), _jsxs("div", { children: [_jsx("dt", { className: "text-muted-foreground", children: "\u5904\u7406\u5907\u6CE8" }), _jsx("dd", { className: "mt-0.5", children: row.process_comments || '—' })] })] }), (canReissue || canStop) && _jsxs("div", { className: "flex gap-2 border-t pt-2", children: [canReissue && _jsxs(Button, { size: "sm", variant: "outline", className: "h-8 flex-1", disabled: !row.can_reissue || !telegramEnabled, title: !telegramEnabled ? '开发环境未启用外部机器人操作' : undefined, onClick: onReissue, children: [_jsx(RotateCcw, { className: "mr-1 size-3.5" }), "\u8865\u53D1"] }), canStop && _jsxs(Button, { size: "sm", variant: "outline", className: "h-8 flex-1 text-destructive", disabled: !row.can_stop, onClick: onStop, children: [_jsx(Ban, { className: "mr-1 size-3.5" }), "\u7981\u6B62"] })] })] });
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { usePremiumAdminRuntime } from './admin-ui-runtime.js'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { useMutation,useQuery,useQueryClient } from '@tanstack/react-query'
|
|
4
|
+
import { Ban,ChevronLeft,ChevronRight,KeyRound,RefreshCw,RotateCcw,Search,WalletCards } from 'lucide-react'
|
|
5
|
+
type Row={rid:number;tx_hash:string;transferfrom_address:string;transferto_address:string;coin_name:string;amount:string;transaction_time:string;process_status:number;process_status_label:string;process_time:string|null;process_comments:string|null;get_time:string|null;can_reissue:boolean;can_stop:boolean}
|
|
6
|
+
type Data={rows:Row[];total:number;page:number;pageSize:number;canReissue:boolean;canStop:boolean;telegramEnabled:boolean}
|
|
7
|
+
type Action='reissue'|'stop'
|
|
8
|
+
export function PremiumTradesPage(){
|
|
9
|
+
const {AdminShell, Button, Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, Textarea, api, ApiError}=usePremiumAdminRuntime()
|
|
10
|
+
const client=useQueryClient(),me=useQuery({queryKey:['me'],queryFn:()=>api<Record<string, unknown>>('/api/me'),retry:false,staleTime:60_000})
|
|
11
|
+
const logout=useMutation({mutationFn:()=>api('/api/auth/logout',{method:'POST',headers:{'Content-Type':'application/json'},body:'{}'}),onSuccess:()=>{client.clear();window.location.assign('/console/home')}})
|
|
12
|
+
const [draft,setDraft]=useState({tx_hash:'',transferfrom_address:'',transferto_address:''}),[filter,setFilter]=useState(draft),[page,setPage]=useState(1),[pageSize,setPageSize]=useState(15),[selected,setSelected]=useState<Row|null>(null),[action,setAction]=useState<Action|null>(null)
|
|
13
|
+
const query=useQuery({queryKey:['premium-trades',page,pageSize,filter],queryFn:()=>api<Data>(`/api/premium-trades?${new URLSearchParams({page:String(page),pageSize:String(pageSize),...filter})}`),enabled:!!me.data,retry:false})
|
|
14
|
+
const mutation=useMutation({mutationFn:()=>api('/api/premium-trades',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({action,rid:selected?.rid})}),onSuccess:async()=>{setSelected(null);setAction(null);await client.invalidateQueries({queryKey:['premium-trades']})}})
|
|
15
|
+
if(me.isPending)return <div className="flex min-h-screen items-center justify-center"><RefreshCw className="size-4 animate-spin text-muted-foreground" aria-label="正在加载"/></div>
|
|
16
|
+
if(!me.data)return <main className="flex min-h-screen items-center justify-center p-4"><section className="w-full max-w-sm space-y-4 rounded-xl bg-card p-6 shadow-sm"><div className="flex items-center gap-2 text-sm font-semibold"><WalletCards className="size-4"/>TGBotPress</div><h1 className="text-base font-semibold">登录管理后台</h1><Button asChild className="w-full"><a href="/api/auth/start?destination=premiumTrades"><KeyRound className="size-4"/>管理员登录</a></Button></section></main>
|
|
17
|
+
const total=query.data?.total||0,pages=Math.max(1,Math.ceil(total/pageSize))
|
|
18
|
+
return <AdminShell user={me.data} title="会员交易" activeRoute="admin.premium.trade.index" onRefresh={()=>query.refetch()} onLogout={()=>logout.mutate()}><main className="space-y-3 p-3 sm:p-4">
|
|
19
|
+
<form className="flex flex-wrap items-center gap-2 rounded-xl bg-card p-3" onSubmit={e=>{e.preventDefault();setFilter(draft);setPage(1)}}>{(['tx_hash','transferfrom_address','transferto_address'] as const).map((key,i)=><Input key={key} value={draft[key]} maxLength={i?200:100} onChange={e=>setDraft({...draft,[key]:e.target.value})} placeholder={['交易 Hash','发送钱包地址','接收钱包地址'][i]} className="h-9 min-w-44 flex-1 text-xs"/>)}<Button size="sm" className="h-9"><Search className="mr-1 size-3.5"/>搜索</Button><Button type="button" variant="outline" size="icon" className="size-9" aria-label="刷新" disabled={query.isFetching} onClick={()=>query.refetch()}><RefreshCw className={`size-3.5 ${query.isFetching?'animate-spin':''}`}/></Button></form>
|
|
20
|
+
<section className="overflow-hidden rounded-xl bg-card"><header className="flex h-11 items-center justify-between border-b px-3"><h1 className="flex items-center gap-2 text-sm font-semibold"><WalletCards className="size-4 text-muted-foreground"/>会员交易</h1><span className="text-xs text-muted-foreground">共 {total} 条</span></header>{query.error&&<div role="alert" className="px-3 py-3 text-xs text-destructive">{query.error instanceof ApiError?query.error.message:'加载失败,请重试'}</div>}
|
|
21
|
+
<div className="hidden overflow-x-auto md:block"><Table className="min-w-[1500px]"><TableHeader><TableRow>{['ID','交易 Hash','发送钱包地址','接收钱包地址','币种','转入金额','交易时间','拉取时间','处理状态','处理时间','处理备注','操作'].map(x=><TableHead key={x} className="h-9 px-3">{x}</TableHead>)}</TableRow></TableHeader><TableBody>{query.isPending?<TableRow><TableCell colSpan={12} className="h-20 text-center text-xs text-muted-foreground">加载中…</TableCell></TableRow>:query.data?.rows.length?query.data.rows.map(row=><TableRow key={row.rid}><TableCell className="px-3 py-2 font-mono text-xs">#{row.rid}</TableCell><TableCell className="max-w-52 truncate px-3 py-2 font-mono text-[10px]" title={row.tx_hash}>{row.tx_hash}</TableCell><TableCell className="max-w-48 truncate px-3 py-2 font-mono text-[10px]" title={row.transferfrom_address}>{row.transferfrom_address}</TableCell><TableCell className="max-w-48 truncate px-3 py-2 font-mono text-[10px]" title={row.transferto_address}>{row.transferto_address}</TableCell><TableCell className="px-3 py-2 text-xs">{row.coin_name}</TableCell><TableCell className="px-3 py-2 font-mono text-xs">{row.amount}</TableCell><TableCell className="whitespace-nowrap px-3 py-2 text-xs">{row.transaction_time}</TableCell><TableCell className="whitespace-nowrap px-3 py-2 text-xs">{row.get_time||'—'}</TableCell><TableCell className="px-3 py-2"><span className={`rounded-full px-2 py-1 text-[10px] ${row.process_status===9?'bg-emerald-50 text-emerald-700':row.process_status===1?'bg-amber-50 text-amber-700':row.process_status===2?'bg-muted text-muted-foreground':'bg-muted text-foreground'}`}>{row.process_status_label}</span></TableCell><TableCell className="whitespace-nowrap px-3 py-2 text-xs">{row.process_time||'—'}</TableCell><TableCell className="max-w-48 truncate px-3 py-2 text-xs" title={row.process_comments||''}>{row.process_comments||'—'}</TableCell><TableCell className="px-3 py-2"><div className="flex items-center gap-1">{query.data.canReissue&&<Button size="sm" variant="outline" className="h-7 px-2 text-[11px]" disabled={!row.can_reissue||!query.data.telegramEnabled} title={!query.data.telegramEnabled?'开发环境未启用外部机器人操作':undefined} onClick={()=>{setSelected(row);setAction('reissue')}}><RotateCcw className="mr-1 size-3"/>补发</Button>}{query.data.canStop&&<Button size="sm" variant="outline" className="h-7 border-destructive/30 px-2 text-[11px] text-destructive hover:bg-destructive/10" disabled={!row.can_stop} onClick={()=>{setSelected(row);setAction('stop')}}><Ban className="mr-1 size-3"/>禁止</Button>}</div></TableCell></TableRow>):<TableRow><TableCell colSpan={12} className="h-20 text-center text-xs text-muted-foreground">暂无记录</TableCell></TableRow>}</TableBody></Table></div>
|
|
22
|
+
<div className="divide-y md:hidden">{query.isPending?<p className="py-8 text-center text-xs text-muted-foreground">加载中…</p>:query.data?.rows.length?query.data.rows.map(row=><PremiumTradeMobileCard key={row.rid} row={row} canReissue={!!query.data?.canReissue} canStop={!!query.data?.canStop} telegramEnabled={!!query.data?.telegramEnabled} onReissue={()=>{setSelected(row);setAction('reissue')}} onStop={()=>{setSelected(row);setAction('stop')}}/>):<p className="py-8 text-center text-xs text-muted-foreground">暂无记录</p>}</div>
|
|
23
|
+
<footer className="flex flex-wrap items-center justify-between gap-2 border-t px-3 py-2"><span className="text-xs text-muted-foreground">第 {page} / {pages} 页</span><div className="flex items-center gap-1.5"><Select value={String(pageSize)} onValueChange={v=>{setPageSize(Number(v));setPage(1)}}><SelectTrigger className="h-8 w-24 text-xs"><SelectValue/></SelectTrigger><SelectContent>{[10,15,20,30,50,100].map(n=><SelectItem key={n} value={String(n)} className="text-xs">{n} 条/页</SelectItem>)}</SelectContent></Select><Button variant="outline" size="icon" className="size-8" aria-label="上一页" disabled={page<=1||query.isFetching} onClick={()=>setPage(p=>p-1)}><ChevronLeft className="size-3.5"/></Button><Button variant="outline" size="icon" className="size-8" aria-label="下一页" disabled={page>=pages||query.isFetching} onClick={()=>setPage(p=>p+1)}><ChevronRight className="size-3.5"/></Button></div></footer>
|
|
24
|
+
</section></main>
|
|
25
|
+
<Dialog open={!!action} onOpenChange={open=>{if(!open){setAction(null);setSelected(null);mutation.reset()}}}><DialogContent aria-describedby={undefined} className="max-w-md gap-4"><DialogHeader><DialogTitle className="text-base">{action==='reissue'?'确认补发会员订单':'确认禁止兑换'}</DialogTitle></DialogHeader>{selected&&<div className="space-y-1 rounded-lg bg-muted px-3 py-2 text-xs"><p>交易 #{selected.rid} · {selected.coin_name} {selected.amount}</p><p className="truncate font-mono text-[10px]">{selected.tx_hash}</p><p>当前状态:{selected.process_status_label}</p></div>}{action==='reissue'&&<p className="text-xs text-muted-foreground">提交后会重新进入会员开通处理队列。</p>}{action==='stop'&&<p className="text-xs text-muted-foreground">此交易将标记为人工禁止,后续不会继续兑换。</p>}{mutation.error&&<p role="alert" className="text-xs text-destructive">{mutation.error instanceof ApiError?mutation.error.message:'操作失败,请重试'}</p>}<DialogFooter><Button size="sm" variant="outline" disabled={mutation.isPending} onClick={()=>{setAction(null);setSelected(null);mutation.reset()}}>取消</Button><Button size="sm" variant={action==='stop'?'destructive':'default'} disabled={mutation.isPending||!selected} onClick={()=>mutation.mutate()}>{mutation.isPending?'处理中':action==='reissue'?'提交补发':'确认禁止'}</Button></DialogFooter></DialogContent></Dialog>
|
|
26
|
+
</AdminShell>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function PremiumTradeMobileCard({row,canReissue,canStop,telegramEnabled,onReissue,onStop}:{row:Row;canReissue:boolean;canStop:boolean;telegramEnabled:boolean;onReissue:()=>void;onStop:()=>void}) {
|
|
30
|
+
const {Button}=usePremiumAdminRuntime()
|
|
31
|
+
return <article className="space-y-3 p-3"><div className="flex items-start justify-between gap-2"><div><p className="text-sm font-medium">交易 #{row.rid} · {row.coin_name} {row.amount}</p><p className="text-xs text-muted-foreground">交易时间 {row.transaction_time}</p></div><span className={`rounded-full px-2 py-1 text-[10px] ${row.process_status===9?'bg-emerald-50 text-emerald-700':row.process_status===1?'bg-amber-50 text-amber-700':row.process_status===2?'bg-muted text-muted-foreground':'bg-destructive/10 text-destructive'}`}>{row.process_status_label}</span></div><dl className="space-y-2 text-xs"><div><dt className="text-muted-foreground">交易 Hash</dt><dd className="mt-0.5 break-all font-mono text-[10px]">{row.tx_hash}</dd></div><div><dt className="text-muted-foreground">发送地址</dt><dd className="mt-0.5 break-all font-mono text-[10px]">{row.transferfrom_address}</dd></div><div><dt className="text-muted-foreground">接收地址</dt><dd className="mt-0.5 break-all font-mono text-[10px]">{row.transferto_address}</dd></div><div className="grid grid-cols-2 gap-2"><div><dt className="text-muted-foreground">拉取时间</dt><dd className="mt-0.5">{row.get_time||'—'}</dd></div><div><dt className="text-muted-foreground">处理时间</dt><dd className="mt-0.5">{row.process_time||'—'}</dd></div></div><div><dt className="text-muted-foreground">处理备注</dt><dd className="mt-0.5">{row.process_comments||'—'}</dd></div></dl>{(canReissue||canStop)&&<div className="flex gap-2 border-t pt-2">{canReissue&&<Button size="sm" variant="outline" className="h-8 flex-1" disabled={!row.can_reissue||!telegramEnabled} title={!telegramEnabled?'开发环境未启用外部机器人操作':undefined} onClick={onReissue}><RotateCcw className="mr-1 size-3.5"/>补发</Button>}{canStop&&<Button size="sm" variant="outline" className="h-8 flex-1 text-destructive" disabled={!row.can_stop} onClick={onStop}><Ban className="mr-1 size-3.5"/>禁止</Button>}</div>}</article>
|
|
32
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { PremiumPlatformsPage } from './admin-pages.platforms.js'
|
|
2
|
+
export { PremiumPackagesPage } from './admin-pages.packages.js'
|
|
3
|
+
export { PremiumOrdersPage } from './admin-pages.orders.js'
|
|
4
|
+
export { PremiumTradesPage } from './admin-pages.trades.js'
|
|
5
|
+
export { PremiumAdminProvider, usePremiumAdminRuntime } from './admin-ui-runtime.js'
|
|
6
|
+
export type { PremiumAdminRuntime } from './admin-ui-runtime.js'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type ComponentType, type HTMLAttributes, type InputHTMLAttributes, type ReactNode, type TableHTMLAttributes, type TextareaHTMLAttributes, type TdHTMLAttributes, type ThHTMLAttributes } from 'react';
|
|
2
|
+
type ApiErrorConstructor = abstract new (...args: any[]) => Error;
|
|
3
|
+
type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
4
|
+
variant?: string;
|
|
5
|
+
size?: string;
|
|
6
|
+
asChild?: boolean;
|
|
7
|
+
};
|
|
8
|
+
type SelectProps = {
|
|
9
|
+
value?: string;
|
|
10
|
+
defaultValue?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
onValueChange?: (value: string) => void;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
type SwitchProps = {
|
|
16
|
+
checked?: boolean;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
19
|
+
id?: string;
|
|
20
|
+
className?: string;
|
|
21
|
+
};
|
|
22
|
+
type DialogProps = {
|
|
23
|
+
open?: boolean;
|
|
24
|
+
onOpenChange?: (open: boolean) => void;
|
|
25
|
+
children?: ReactNode;
|
|
26
|
+
};
|
|
27
|
+
export type PremiumAdminRuntime = {
|
|
28
|
+
api: <T = unknown>(url: string, init?: RequestInit) => Promise<T>;
|
|
29
|
+
ApiError: ApiErrorConstructor;
|
|
30
|
+
AdminShell: ComponentType<any>;
|
|
31
|
+
Button: ComponentType<ButtonProps>;
|
|
32
|
+
Input: ComponentType<InputHTMLAttributes<HTMLInputElement>>;
|
|
33
|
+
Select: ComponentType<SelectProps>;
|
|
34
|
+
SelectContent: ComponentType<HTMLAttributes<HTMLDivElement>>;
|
|
35
|
+
SelectItem: ComponentType<HTMLAttributes<HTMLDivElement> & {
|
|
36
|
+
value: string;
|
|
37
|
+
}>;
|
|
38
|
+
SelectTrigger: ComponentType<ButtonProps>;
|
|
39
|
+
SelectValue: ComponentType<HTMLAttributes<HTMLSpanElement> & {
|
|
40
|
+
placeholder?: string;
|
|
41
|
+
}>;
|
|
42
|
+
Switch: ComponentType<SwitchProps>;
|
|
43
|
+
Table: ComponentType<TableHTMLAttributes<HTMLTableElement>>;
|
|
44
|
+
TableBody: ComponentType<HTMLAttributes<HTMLTableSectionElement>>;
|
|
45
|
+
TableCell: ComponentType<TdHTMLAttributes<HTMLTableCellElement>>;
|
|
46
|
+
TableHead: ComponentType<ThHTMLAttributes<HTMLTableCellElement>>;
|
|
47
|
+
TableHeader: ComponentType<HTMLAttributes<HTMLTableSectionElement>>;
|
|
48
|
+
TableRow: ComponentType<HTMLAttributes<HTMLTableRowElement>>;
|
|
49
|
+
Dialog: ComponentType<DialogProps>;
|
|
50
|
+
DialogContent: ComponentType<HTMLAttributes<HTMLDivElement> & {
|
|
51
|
+
'aria-describedby'?: string;
|
|
52
|
+
}>;
|
|
53
|
+
DialogFooter: ComponentType<HTMLAttributes<HTMLDivElement>>;
|
|
54
|
+
DialogHeader: ComponentType<HTMLAttributes<HTMLDivElement>>;
|
|
55
|
+
DialogTitle: ComponentType<HTMLAttributes<HTMLHeadingElement>>;
|
|
56
|
+
Textarea: ComponentType<TextareaHTMLAttributes<HTMLTextAreaElement>>;
|
|
57
|
+
};
|
|
58
|
+
export declare function PremiumAdminProvider(props: {
|
|
59
|
+
runtime: PremiumAdminRuntime;
|
|
60
|
+
children?: ReactNode;
|
|
61
|
+
}): import("react").FunctionComponentElement<import("react").ProviderProps<PremiumAdminRuntime | null>>;
|
|
62
|
+
export declare function usePremiumAdminRuntime(): PremiumAdminRuntime;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createContext, createElement, useContext } from 'react';
|
|
2
|
+
const runtimeContext = createContext(null);
|
|
3
|
+
export function PremiumAdminProvider(props) {
|
|
4
|
+
return createElement(runtimeContext.Provider, { value: props.runtime }, props.children);
|
|
5
|
+
}
|
|
6
|
+
export function usePremiumAdminRuntime() {
|
|
7
|
+
const runtime = useContext(runtimeContext);
|
|
8
|
+
if (!runtime)
|
|
9
|
+
throw new Error('PremiumAdminProvider is missing');
|
|
10
|
+
return runtime;
|
|
11
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createContext, createElement, useContext, type ButtonHTMLAttributes, type ComponentType, type HTMLAttributes, type InputHTMLAttributes, type ReactNode, type SelectHTMLAttributes, type TableHTMLAttributes, type TextareaHTMLAttributes, type TdHTMLAttributes, type ThHTMLAttributes } from 'react'
|
|
2
|
+
|
|
3
|
+
type ApiErrorConstructor = abstract new (...args: any[]) => Error
|
|
4
|
+
type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & { variant?: string; size?: string; asChild?: boolean }
|
|
5
|
+
type SelectProps = { value?: string; defaultValue?: string; disabled?: boolean; onValueChange?: (value: string) => void; children?: ReactNode }
|
|
6
|
+
type SwitchProps = { checked?: boolean; disabled?: boolean; onCheckedChange?: (checked: boolean) => void; id?: string; className?: string }
|
|
7
|
+
type DialogProps = { open?: boolean; onOpenChange?: (open: boolean) => void; children?: ReactNode }
|
|
8
|
+
export type PremiumAdminRuntime = {
|
|
9
|
+
api: <T = unknown>(url: string, init?: RequestInit) => Promise<T>
|
|
10
|
+
ApiError: ApiErrorConstructor
|
|
11
|
+
AdminShell: ComponentType<any>
|
|
12
|
+
Button: ComponentType<ButtonProps>
|
|
13
|
+
Input: ComponentType<InputHTMLAttributes<HTMLInputElement>>
|
|
14
|
+
Select: ComponentType<SelectProps>
|
|
15
|
+
SelectContent: ComponentType<HTMLAttributes<HTMLDivElement>>
|
|
16
|
+
SelectItem: ComponentType<HTMLAttributes<HTMLDivElement> & { value: string }>
|
|
17
|
+
SelectTrigger: ComponentType<ButtonProps>
|
|
18
|
+
SelectValue: ComponentType<HTMLAttributes<HTMLSpanElement> & { placeholder?: string }>
|
|
19
|
+
Switch: ComponentType<SwitchProps>
|
|
20
|
+
Table: ComponentType<TableHTMLAttributes<HTMLTableElement>>
|
|
21
|
+
TableBody: ComponentType<HTMLAttributes<HTMLTableSectionElement>>
|
|
22
|
+
TableCell: ComponentType<TdHTMLAttributes<HTMLTableCellElement>>
|
|
23
|
+
TableHead: ComponentType<ThHTMLAttributes<HTMLTableCellElement>>
|
|
24
|
+
TableHeader: ComponentType<HTMLAttributes<HTMLTableSectionElement>>
|
|
25
|
+
TableRow: ComponentType<HTMLAttributes<HTMLTableRowElement>>
|
|
26
|
+
Dialog: ComponentType<DialogProps>
|
|
27
|
+
DialogContent: ComponentType<HTMLAttributes<HTMLDivElement> & { 'aria-describedby'?: string }>
|
|
28
|
+
DialogFooter: ComponentType<HTMLAttributes<HTMLDivElement>>
|
|
29
|
+
DialogHeader: ComponentType<HTMLAttributes<HTMLDivElement>>
|
|
30
|
+
DialogTitle: ComponentType<HTMLAttributes<HTMLHeadingElement>>
|
|
31
|
+
Textarea: ComponentType<TextareaHTMLAttributes<HTMLTextAreaElement>>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const runtimeContext = createContext<PremiumAdminRuntime | null>(null)
|
|
35
|
+
|
|
36
|
+
export function PremiumAdminProvider(props: { runtime: PremiumAdminRuntime; children?: ReactNode }) {
|
|
37
|
+
return createElement(runtimeContext.Provider, { value: props.runtime }, props.children)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function usePremiumAdminRuntime() {
|
|
41
|
+
const runtime = useContext(runtimeContext)
|
|
42
|
+
if (!runtime) throw new Error('PremiumAdminProvider is missing')
|
|
43
|
+
return runtime
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DatabaseConnection } from './host-types.js';
|
|
2
|
+
export type PremiumFulfillmentDatabase = Pick<DatabaseConnection, 'query' | 'connect'>;
|
|
3
|
+
export type PremiumFulfillmentLogger = Pick<Console, 'info' | 'error'>;
|
|
4
|
+
export type PremiumRunPayment = (amount: string, ref: string, months: number, mnemonic: string) => Promise<string>;
|
|
5
|
+
export type PremiumFulfillmentOptions = {
|
|
6
|
+
pool: PremiumFulfillmentDatabase;
|
|
7
|
+
decryptSecret: (value: string | null) => string;
|
|
8
|
+
runPayment: PremiumRunPayment;
|
|
9
|
+
preflight: (mnemonic: string) => Promise<boolean>;
|
|
10
|
+
fetcher?: typeof fetch;
|
|
11
|
+
logger?: PremiumFulfillmentLogger;
|
|
12
|
+
shouldContinue?: () => boolean;
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
allowTelegramStars?: boolean;
|
|
15
|
+
batchSize?: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function syncPremiumFulfillment(options: PremiumFulfillmentOptions): Promise<{
|
|
18
|
+
skipped: boolean;
|
|
19
|
+
scanned: number;
|
|
20
|
+
matched: number;
|
|
21
|
+
succeeded: number;
|
|
22
|
+
failed: number;
|
|
23
|
+
manual: number;
|
|
24
|
+
}>;
|