1. 计费核心改动 (relay/helper/price.go): - applyDistributorMarkup 新增自定义价格支持 - 自定义价格转 USD 后与平台底价对比,计算等效加价倍率 - 保底机制:自定义价格不得低于平台底价,防止平台亏损 - 优先级:全站加价 > 自定义价格 > 单模型加价比例 2. 分站价格显示修复 (controller/dist_site.go): - 自定义价格跟随商家币种(CNY),发送前需转 USD - 修复 ¥6.8 显示为 ¥46.24 的翻倍问题 3. 管理页面改进 (DistributorModels.jsx): - 全站加价模式下展示含加价的价格 - 自定义价格输入框显示正确的币种单位 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
import{u as Oe,a as $e,d as Me,r as n,g as Ee,o as Le,j as e,Q as ae,e as Ue,z as d,p as He,q as Re,t as Fe,v as De,w as ze,x as Be,y as We}from"./index-DZXnuqaY.js";import{C as H}from"./CountUp-DtJMqT_7.js";import{u as Qe}from"./useTranslation-C6aAveL4.js";function Xe(){var ee;const{t:s}=Qe(),{user:i,refreshUser:R}=Oe(),{site:r}=$e(),{symbol:S,rate:$}=Me(),[m,le]=n.useState(null),[l,ne]=n.useState(null),[re,F]=n.useState(!0),[M,D]=n.useState(""),[z,B]=n.useState(!1),[h,E]=n.useState(""),[ce,L]=n.useState(null),[W,Q]=n.useState(null),[oe,J]=n.useState(!1),[b,y]=n.useState(!1),[U,f]=n.useState(""),[C,k]=n.useState(null),[de,j]=n.useState(!1),[p,V]=n.useState(""),[P,ie]=n.useState("usdt"),[N,me]=n.useState(null),[A,pe]=n.useState(!1),[G,ue]=n.useState([]),[xe,K]=n.useState(!1);r!=null&&r.enable_topup,r==null||r.topup_config;const q=n.useCallback(async()=>{var t;F(!0);try{const[a,c]=await Promise.all([Ee(),r!=null&&r.enable_topup?Le().catch(()=>null):Promise.resolve(null)]);a.data.success&&le(a.data.data),(t=c==null?void 0:c.data)!=null&&t.data&&ne(c.data.data)}catch{}F(!1)},[r==null?void 0:r.enable_topup]);n.useEffect(()=>{q()},[q]);const X=(m==null?void 0:m.quota)??(i==null?void 0:i.quota)??0,ge=(m==null?void 0:m.used_quota)??(i==null?void 0:i.used_quota)??0,he=(m==null?void 0:m.request_count)??(i==null?void 0:i.request_count)??0,be=X/ae*$,ye=async t=>{if(t.preventDefault(),!!M.trim()){B(!0);try{(await Ue(M.trim())).data.success&&(d.success(s("topup.redeemSuccess")),D(""),await Promise.all([q(),R()]))}catch{}B(!1)}},Y=async t=>{if(!t||t<=0){Q(null);return}J(!0);try{const a=await He({amount:parseInt(t)});a.data.message==="success"&&Q(a.data.data)}catch{}J(!1)},fe=t=>{L(t),E(t),Y(t)},je=t=>["stripe","alipay","wxpay"].includes(t)&&!t.startsWith("epay_"),Ne=async t=>{var c;const a=parseInt(h);if(!a||a<=0){d.error(s("topup.enterAmount"));return}y(!0),f(t);try{const u=window.location.origin+"/topup",_={amount:a,payment_method:t,return_url:u};if(je(t)){const o=await Re(_);if(o.data.message==="success"&&((c=o.data.data)!=null&&c.pay_link))window.open(o.data.data.pay_link,"_blank");else if(o.data.message!=="success"){const x=typeof o.data.data=="string"?o.data.data:o.data.message;d.error(x||s("common.requestFailed"))}}else{const o=await Fe(_);if(o.data.message==="success"){const x=o.data.data,te=o.data.url;if(te&&x){const g=document.createElement("form");g.action=te,g.method="POST",navigator.userAgent.indexOf("Safari")>-1&&navigator.userAgent.indexOf("Chrome")<1||(g.target="_blank");for(const se in x){const O=document.createElement("input");O.type="hidden",O.name=se,O.value=x[se],g.appendChild(O)}document.body.appendChild(g),g.submit(),document.body.removeChild(g)}}else{const x=typeof o.data.data=="string"?o.data.data:o.data.message;d.error(x||s("common.requestFailed"))}}}catch{}y(!1),f("")},ve=async t=>{var a;y(!0),f("creem");try{const c=await De({product_id:t.productId,payment_method:"creem"});if(c.data.message==="success"&&((a=c.data.data)!=null&&a.checkout_url))window.open(c.data.data.checkout_url,"_blank");else if(c.data.message!=="success"){const u=typeof c.data.data=="string"?c.data.data:c.data.message;d.error(u||s("common.requestFailed"))}}catch{}y(!1),f("")},we=async()=>{const t=parseInt(h);if(!t||t<=0){d.error(s("topup.enterAmount"));return}if(!p){d.error(s("topup.selectChain"));return}if(!P){d.error(s("topup.selectToken"));return}y(!0),f("crypto");try{const a=await ze({amount:t,chain:p,token:P});if(a.data.message==="success"&&a.data.data)k(a.data.data),Ce(a.data.data.trade_no);else if(a.data.message!=="success"){const c=typeof a.data.data=="string"?a.data.data:a.data.message;d.error(c||s("common.requestFailed"))}}catch{}y(!1),f("")},Ce=t=>{j(!0);const a=setInterval(async()=>{var u,_;try{const o=await Be(t);((u=o.data.data)==null?void 0:u.status)==="success"?(clearInterval(a),j(!1),k(null),d.success(s("topup.paymentSuccess")),await Promise.all([q(),R()])):((_=o.data.data)==null?void 0:_.status)==="expired"&&(clearInterval(a),j(!1),d.error(s("topup.orderExpired")))}catch{clearInterval(a),j(!1)}},5e3),c=((l==null?void 0:l.crypto_expiry_minutes)||30)*60*1e3;setTimeout(()=>{clearInterval(a),j(!1)},c)},v=(l==null?void 0:l.crypto_wallets)||{},w=n.useMemo(()=>{const t=[];return v.tron&&t.push({key:"tron",label:"TRON (TRC20)"}),v.eth&&t.push({key:"eth",label:"Ethereum (ERC20)"}),v.bsc&&t.push({key:"bsc",label:"BSC (BEP20)"}),t},[v.tron,v.eth,v.bsc]);n.useEffect(()=>{w.length>0&&!p&&V(w[0].key)},[w,p]);const Z=n.useMemo(()=>{if(!(l!=null&&l.creem_products))return[];try{const t=typeof l.creem_products=="string"?JSON.parse(l.creem_products):l.creem_products;return Array.isArray(t)?t:[]}catch{return[]}},[l==null?void 0:l.creem_products]),_e=async()=>{var t;K(!0);try{const a=await We({page:1,page_size:20});(t=a.data.data)!=null&&t.items&&ue(a.data.data.items)}catch{}K(!1)},Se=(l==null?void 0:l.amount_options)||[1,5,10,20,50,100],T=(l==null?void 0:l.min_topup)||1,ke=(l==null?void 0:l.pay_methods)||[],Pe=l==null?void 0:l.enable_online_topup,Ae=l==null?void 0:l.enable_stripe_topup,qe=l==null?void 0:l.enable_creem_topup,Te=l==null?void 0:l.enable_crypto_topup,I=ke.filter(t=>t.type!=="creem"&&t.type!=="crypto");return re?e.jsx("div",{className:"flex items-center justify-center min-h-[60vh]",children:e.jsx("div",{className:"w-8 h-8 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin"})}):e.jsxs("div",{className:"max-w-4xl mx-auto px-6 py-10",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-2xl font-heading font-bold text-page mb-1",children:s("topup.title")}),e.jsx("p",{className:"text-sm text-page-secondary",children:s("topup.subtitle")})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-10",children:[e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("p",{className:"text-sm text-page-secondary mb-2",children:s("dashboard.balance")}),e.jsxs("div",{className:"text-3xl font-bold text-page",children:[S,e.jsx(H,{from:0,to:be,duration:1.5})]}),e.jsx("p",{className:"text-xs text-page-muted mt-1",children:s("dashboard.quotaUnits",{count:X.toLocaleString()})})]}),e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("p",{className:"text-sm text-page-secondary mb-2",children:s("dashboard.used")}),e.jsxs("div",{className:"text-3xl font-bold text-page",children:[S,e.jsx(H,{from:0,to:ge/ae*$,duration:1.5})]})]}),e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("p",{className:"text-sm text-page-secondary mb-2",children:s("dashboard.totalRequests")}),e.jsx("div",{className:"text-3xl font-bold text-page",children:e.jsx(H,{from:0,to:he,duration:1.5})})]})]}),(r==null?void 0:r.enable_topup)&&(Pe||Ae)&&I.length>0&&e.jsxs("div",{className:"glass rounded-2xl p-6 mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page",children:s("topup.onlineTopup")}),e.jsx("button",{onClick:()=>{pe(!A),A||_e()},className:"text-sm text-page-secondary hover:text-page transition-colors",children:s(A?"topup.hideHistory":"topup.viewHistory")})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-3",children:s("topup.selectAmount")}),e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2",children:Se.map(t=>e.jsxs("button",{onClick:()=>fe(t),className:`py-2.5 px-3 rounded-xl text-sm font-medium transition-all ${ce===t?"bg-brand-500 text-white shadow-lg shadow-brand-500/25":"glass-sm text-page-label hover:text-page hover:bg-page-surface-hover"}`,children:[S,t]},t))})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-2",children:s("topup.customAmount")}),e.jsx("div",{className:"flex gap-3",children:e.jsx("input",{type:"number",value:h,onChange:t=>{E(t.target.value),L(null)},onBlur:t=>Y(t.target.value),min:T,placeholder:s("topup.amountPlaceholder",{min:T}),className:"input flex-1"})}),oe?e.jsx("p",{className:"text-xs text-page-muted mt-2",children:s("topup.calculating")}):W?e.jsxs("p",{className:"text-xs text-page-secondary mt-2",children:[s("topup.payAmountLabel"),": ",e.jsxs("span",{className:"text-page-success font-medium",children:["¥",W]})]}):null]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-3",children:s("topup.paymentMethod")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:I.map(t=>{const a=b&&U===t.type;return e.jsx("button",{onClick:()=>Ne(t.type),disabled:b||!h,className:"px-4 py-2.5 rounded-xl text-sm font-medium glass-sm text-page-label hover:text-page hover:bg-page-surface-hover disabled:opacity-40 disabled:cursor-not-allowed transition-all",children:a?s("topup.processing"):t.name},t.type)})})]})]}),(r==null?void 0:r.enable_topup)&&qe&&Z.length>0&&e.jsxs("div",{className:"glass rounded-2xl p-6 mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("topup.creemPayment")||"Creem Payment"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:Z.map(t=>e.jsxs("div",{className:`glass-sm rounded-xl p-4 cursor-pointer transition-all ${(N==null?void 0:N.productId)===t.productId?"ring-2 ring-brand-500 bg-brand-500/10":"hover:bg-page-surface"}`,onClick:()=>me(t),children:[e.jsx("h3",{className:"text-sm font-semibold text-page mb-1",children:t.name}),e.jsxs("p",{className:"text-xl font-bold text-page-success mb-1",children:["$",t.price," ",e.jsx("span",{className:"text-xs text-page-muted font-normal",children:t.currency||"USD"})]}),t.quota&&e.jsx("p",{className:"text-xs text-page-secondary",children:s("topup.quotaIncluded")||`${t.quota} quota`})]},t.productId))}),N&&e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx("button",{onClick:()=>ve(N),disabled:b,className:"btn-primary px-6",children:b&&U==="creem"?s("topup.processing"):`${s("topup.payNow")||"Pay"} $${N.price}`})})]}),(r==null?void 0:r.enable_topup)&&Te&&w.length>0&&e.jsxs("div",{className:"glass rounded-2xl p-6 mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("topup.cryptoPayment")}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-2",children:s("topup.amount")}),e.jsx("input",{type:"number",value:h,onChange:t=>{E(t.target.value),L(null)},min:T,placeholder:s("topup.amountPlaceholder",{min:T}),className:"input w-full"})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-2",children:s("topup.chain")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:w.map(t=>e.jsx("button",{onClick:()=>V(t.key),className:`px-4 py-2 rounded-xl text-sm font-medium transition-all ${p===t.key?"bg-brand-500 text-white shadow-lg shadow-brand-500/25":"glass-sm text-page-label hover:text-page hover:bg-page-surface-hover"}`,children:t.label},t.key))})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-2",children:s("topup.token")||"Token"}),e.jsx("div",{className:"flex gap-2",children:["usdt","usdc"].map(t=>e.jsx("button",{onClick:()=>ie(t),className:`px-4 py-2 rounded-xl text-sm font-medium transition-all ${P===t?"bg-brand-500 text-white shadow-lg shadow-brand-500/25":"glass-sm text-page-label hover:text-page hover:bg-page-surface-hover"}`,children:t.toUpperCase()},t))})]}),e.jsx("button",{onClick:we,disabled:b||!h,className:"btn-primary w-full",children:b&&U==="crypto"?s("topup.processing"):`${s("topup.payWith")||"Pay with"} ${P.toUpperCase()} (${((ee=w.find(t=>t.key===p))==null?void 0:ee.label)||p})`})]}),C&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>k(null),children:e.jsxs("div",{className:"glass rounded-2xl p-6 max-w-md w-full mx-4",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{className:"text-lg font-semibold text-page mb-4",children:s("topup.cryptoPayment")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"glass-sm rounded-xl p-4",children:[e.jsx("p",{className:"text-xs text-page-secondary mb-1",children:s("topup.walletAddress")}),e.jsx("p",{className:"text-sm text-page font-mono break-all",children:C.wallet})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"glass-sm rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-page-secondary mb-1",children:s("topup.amount")}),e.jsxs("p",{className:"text-sm text-page font-medium",children:[C.amount," ",C.token]})]}),e.jsxs("div",{className:"glass-sm rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-page-secondary mb-1",children:s("topup.chain")}),e.jsx("p",{className:"text-sm text-page font-medium",children:C.chain})]})]}),de&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-page-secondary",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin"}),s("topup.waitingPayment")]}),e.jsx("button",{onClick:()=>{k(null),j(!1)},className:"w-full py-2 rounded-xl text-sm glass-sm text-page-secondary hover:text-page transition-colors",children:s("topup.close")})]})]})}),A&&e.jsxs("div",{className:"glass rounded-2xl p-6 mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("topup.history")}),xe?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"w-6 h-6 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin"})}):G.length===0?e.jsx("p",{className:"text-sm text-page-muted text-center py-8",children:s("topup.noHistory")}):e.jsx("div",{className:"space-y-2",children:G.map((t,a)=>e.jsxs("div",{className:"flex items-center justify-between glass-sm rounded-xl px-4 py-3",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-page",children:[S,(Number(t.amount)*$).toFixed(2)]}),e.jsxs("p",{className:"text-xs text-page-muted",children:[new Date(t.create_time*1e3).toLocaleString()," · ",t.payment_method||s("topup.redeemCode")]})]}),e.jsx("span",{className:`text-xs px-2 py-1 rounded-full ${t.status==="success"?"bg-green-500/10 text-page-success":t.status==="pending"?"bg-yellow-500/10 text-page-warning":"bg-red-500/10 text-page-danger"}`,children:t.status==="success"?s("topup.statusSuccess"):t.status==="pending"?s("topup.statusPending"):s("topup.statusFailed")})]},a))})]}),e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("topup.redeemTitle")}),e.jsxs("form",{onSubmit:ye,className:"flex gap-3",children:[e.jsx("input",{type:"text",value:M,onChange:t=>D(t.target.value),className:"input flex-1",placeholder:s("topup.enterRedeemCode")}),e.jsx("button",{type:"submit",disabled:z,className:"btn-primary whitespace-nowrap",children:s(z?"topup.redeeming":"topup.redeem")})]})]})]})}export{Xe as default};
|