2 lines
33 KiB
JavaScript
2 lines
33 KiB
JavaScript
import{j as e,g as ut,M as ge,T as U,i as Te,k as At,S as mt,l as ht,c as Ut,m as _e,n as Yt,o as pt,p as Se,B as R,q as ae,D as Bt,C as Ee,r as Vt}from"./semi-ui-fcB3D8nU.js";import{r as a,d as Ht}from"./react-core-C8o2IdY8.js";import{A as F,s as w,bf as Ie,aO as Ue,bg as P,bh as ft,bi as Kt,bj as Qt,aM as xe,az as Gt,ay as Zt,bk as te,bl as Oe,aL as at,aF as Jt,bm as Xt,b1 as es,bn as ts,bo as ss,bp as as,bq as rs,br as ns,bs as ls}from"./index-DApEyau7.js";import{r as rt,a as is,P as os,W as ze,b as Ye,E as nt,w as cs,p as ds,v as us,c as ms}from"./withdrawProfileUtils-BeheHjO7.js";import{u as Be}from"./i18n-DJWjvQyM.js";import{D as hs}from"./DistributorApplyFileUpload-Byp4JYxD.js";import"./tools-qobPTha0.js";import"./react-components-KaTRN41W.js";const{Text:lt}=U;function ps({visible:t,onCancel:n,inviteeId:i,inviteeLabel:d,commissionMode:u="topup"}){const{t:h}=Be(),[y,l]=a.useState(!1),[S,_]=a.useState([]),[M,j]=a.useState(0),[C,z]=a.useState(1),[E,T]=a.useState(10),r=u==="profit_share",p=a.useCallback(async(m,O)=>{if(i){l(!0);try{const B=r?`/api/distributor/invitee/${i}/profit-shares?p=${m}&page_size=${O}`:`/api/distributor/invitee/${i}/commissions?p=${m}&page_size=${O}`,Z=await F.get(B),{success:J,message:ce,data:L}=Z.data;if(!J){w(ce||h("加载失败"));return}_((L==null?void 0:L.items)||[]),j((L==null?void 0:L.total)??0),z(m)}catch{w(h("加载失败"))}finally{l(!1)}}},[i,r,h]);a.useEffect(()=>{!t||!i||(z(1),T(10),p(1,10))},[t,i,p]);const o=a.useMemo(()=>r?[{title:h("时间"),dataIndex:"created_at",width:170,render:m=>m?Ie.unix(Number(m)).format("YYYY-MM-DD HH:mm:ss"):"—"},{title:h("模型"),dataIndex:"model_name",width:200,render:m=>m?String(m):"—"},{title:h("渠道路由后缀"),dataIndex:"route_slug",width:120,render:m=>String(m??"").trim()||"—"},{title:h("用户消耗额度"),dataIndex:"user_quota_charged",width:130,render:m=>rt(m)},{title:e.jsx(ut,{content:h("加价切片额度说明"),children:e.jsx("span",{className:"cursor-help border-b border-dotted border-gray-400",children:h("加价切片额度")})}),dataIndex:"markup_slice_quota",width:130,render:m=>rt(m)},{title:h("当时分成比例"),dataIndex:"commission_bps",width:110,render:m=>typeof m=="number"&&m>0?Ue(m):"—"},{title:e.jsx(os,{t:h}),dataIndex:"reward_quota",width:120,render:(m,O)=>is(O,h)}]:[{title:h("时间"),dataIndex:"created_at",width:170,render:m=>m?Ie.unix(Number(m)).format("YYYY-MM-DD HH:mm:ss"):"—"},{title:h("充值入账额度"),dataIndex:"invitee_quota_added",render:m=>P(m||0)},{title:h("当时分成比例"),dataIndex:"commission_bps",width:120,render:m=>Ue(m)},{title:h("收益额度"),dataIndex:"reward_quota",render:m=>P(m||0)}],[r,h]),$=h(r?"利润分成明细":"分成明细"),Y=h(r?"利润分成明细说明":"每次被邀请用户充值入账后,按当时适用的分成比例计算一条记录。");return e.jsxs(ge,{title:e.jsxs("span",{children:[$,d?e.jsx(lt,{type:"tertiary",size:"small",className:"ml-2 font-normal",children:d}):null]}),visible:t,onCancel:n,footer:null,width:r?1180:880,bodyStyle:r?{overflow:"visible"}:void 0,children:[e.jsx(lt,{type:"tertiary",size:"small",className:"block mb-3",children:Y}),e.jsx(Te,{loading:y,rowKey:"id",columns:o,dataSource:S,pagination:{currentPage:C,pageSize:E,total:M,onPageChange:m=>p(m,E),onPageSizeChange:m=>{T(m),p(1,m)}}})]})}const{Text:We}=U,{Option:fs}=pt,$e=10,pe=t=>`${t.channel_id||0}:${t.model_name||""}`,it=(t,n)=>Math.round(Number(t??0)*100)===Math.round(Number(n??0)*100);function ot(t){const n=String(t||"").trim();if(!n)return"—";const i=ft.find(d=>d.value===n);return i?i.label:n}const xs=({visible:t,onCancel:n,inviteeId:i,inviteeLabel:d,t:u})=>{const[h,y]=a.useState(!1),[l,S]=a.useState(!1),[_,M]=a.useState([]),[j,C]=a.useState(""),[z,E]=a.useState(null),[T,r]=a.useState(1),[p,o]=a.useState({}),[$,Y]=a.useState({}),m=a.useCallback(async(f={})=>{var g,N,k,V;const{silent:x=!1}=f;if(!(!i||!t)){x||y(!0);try{const H=await F.get(`/api/distributor/invitee-model-discounts?invitee_id=${i}`);if(!((g=H.data)!=null&&g.success)){w(((N=H.data)==null?void 0:N.message)||u("加载失败"));return}const re=((V=(k=H.data)==null?void 0:k.data)==null?void 0:V.items)||[];M(re);const K={};re.forEach(Q=>{K[pe(Q)]=Q.current_markup_discount_rate}),o(K),Y(K)}catch{w(u("加载失败"))}finally{x||y(!1)}}},[i,t,u]);a.useEffect(()=>{t?m():(C(""),E(null),r(1),o({}),Y({}))},[t,m]);const O=a.useMemo(()=>{const f=new Set,x=[];return ft.forEach(g=>{_.some(k=>String(k.supplier_type||"").trim()===g.value)&&x.push({value:g.value,label:g.label}),f.add(g.value)}),_.forEach(g=>{const N=String(g.supplier_type||"").trim();N&&!f.has(N)&&(f.add(N),x.push({value:N,label:N}))}),x},[_]),B=a.useMemo(()=>{let f=_;z!=null&&z!==""&&(f=f.filter(g=>String(g.supplier_type||"").trim()===z));const x=j.toLowerCase().trim();return x?f.filter(g=>{const N=`${g.channel_path||""} ${g.model_name||""} ${g.channel_id||""}`.toLowerCase(),k=String(g.supplier_type||"").trim().toLowerCase(),V=ot(g.supplier_type).toLowerCase();return N.includes(x)||k.includes(x)||V.includes(x)}):f},[_,j,z]),Z=z!=null&&z!==""||!!j.trim(),J=a.useMemo(()=>_.length?_.reduce((f,x)=>{const g=pe(x),N=p[g],k=$[g]??N;return it(k,N)?f:f+1},0):0,[_,p,$]);a.useEffect(()=>{r(1)},[j,z,_.length]);const ce=(f,x)=>{const g=x==null?0:Number(x),N=Math.max(0,Math.min(100,g));Y(k=>({...k,[f]:N}))},L=async()=>{var f,x;if(J===0)return Qt(u("暂无修改")),!1;S(!0);try{const g=_.map(k=>({model_name:k.model_name,channel_id:k.channel_id,markup_discount_rate:$[pe(k)]??k.current_markup_discount_rate})),N=await F.put("/api/distributor/invitee-model-discounts",{invitee_id:i,discounts:g});return(f=N.data)!=null&&f.success?(xe(u("保存成功")),await m({silent:!0}),!0):(w(((x=N.data)==null?void 0:x.message)||u("保存失败")),!1)}catch{return w(u("保存失败")),!1}finally{S(!1)}},be=async()=>{await L()},we=async()=>{await L()&&n()},de=()=>{n()},je=[{title:u("模型 / 通道路径"),dataIndex:"model_name",width:380,render:(f,x)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(U.Text,{strong:!0,copyable:!0,children:f}),e.jsx(U.Text,{type:"secondary",size:"small",copyable:!0,children:x.channel_path||"—"}),e.jsx(U.Text,{type:"tertiary",size:"small",children:ot(x.supplier_type)})]})},{title:u("系统折扣率"),dataIndex:"default_markup_discount_rate",width:140,render:f=>e.jsxs(We,{type:"secondary",children:[Number(f||0).toFixed(2),"%"]})},{title:u("模型折扣率"),dataIndex:"current_markup_discount_rate",width:200,render:(f,x)=>{const g=pe(x),N=$[g]??x.current_markup_discount_rate,k=p[g]??x.current_markup_discount_rate,V=!it(N,k),H=Number(x.default_markup_discount_rate??0),re=N>H+1e-6,K=u("您当前设置的折扣率高于系统默认折扣率,会导致用户使用价格高于正常价。");return e.jsxs("div",{className:"flex items-center gap-1.5 w-full min-w-0",children:[re?e.jsx(ut,{content:K,position:"top",children:e.jsx("span",{className:"inline-flex shrink-0 cursor-help text-amber-500 dark:text-amber-400",role:"img","aria-label":K,children:e.jsx(Kt,{size:18,strokeWidth:2.25})})}):e.jsx("span",{className:"inline-flex w-[18px] shrink-0 justify-center","aria-hidden":!0}),e.jsx(At,{value:N,onChange:Q=>ce(g,Q),min:0,max:100,precision:2,suffix:"%",className:`min-w-0 flex-1 ${V?"border-semi-color-primary":""}`})]})}}],ue=(()=>{const f=(T-1)*$e,x=f+$e;return B.slice(f,x)})();return e.jsx(ge,{title:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U.Text,{strong:!0,className:"!text-base",children:u("模型折扣率设置")}),d&&e.jsxs(U.Text,{type:"tertiary",size:"small",children:["(",d,")"]})]}),visible:t,onCancel:n,width:760,footer:e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.jsx(R,{type:"primary",theme:"solid",loading:l,onClick:be,children:u("保存")}),e.jsx(R,{type:"primary",loading:l,onClick:we,children:u("保存并关闭")}),e.jsx(R,{type:"tertiary",disabled:l,onClick:de,children:u("关闭")})]}),children:e.jsx(mt,{spinning:h,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(ht,{type:"info",closeIcon:null,icon:e.jsx(Ut,{}),className:"!rounded-lg",description:u("说明:本功能用于为被邀请用户配置各模型的折扣率(在官方定价基础上的加价比例)。当设置的折扣率高于系统折扣率时,用户侧模型价格会高于系统默认;低于系统折扣率时则会低于系统默认(即减价)。未修改时与渠道系统折扣率一致,修改后仅对该用户生效。")}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(_e,{placeholder:u("搜索模型、通道路径或供应商类型..."),value:j,onChange:C,className:"flex-1 min-w-0",prefix:e.jsx(Yt,{}),showClear:!0}),e.jsx(pt,{placeholder:u("筛选供应商类型"),value:z,onChange:E,showClear:!0,filter:!0,className:"w-full sm:w-[220px] flex-shrink-0",children:O.map(f=>e.jsx(fs,{value:f.value,children:f.label},f.value))})]}),e.jsxs(Se,{className:"text-sm",children:[e.jsx(We,{type:"tertiary",children:Z?u("显示 ${shown} / 共 ${total} 个模型渠道").replace("${shown}",String(B.length)).replace("${total}",String(_.length)):u("共 ${count} 个模型渠道").replace("${count}",String(_.length))}),J>0&&e.jsx(We,{type:"primary",children:u("已修改 ${count} 个").replace("${count}",String(J))})]}),e.jsx(Te,{columns:je,dataSource:ue,pagination:{currentPage:T,pageSize:$e,total:B.length,showSizeChanger:!1,onPageChange:f=>r(f)},rowKey:pe})]})})})};function gs({label:t,required:n,url:i,onUrlChange:d,onPreview:u,compact:h=!1,imagesOnly:y=!1,allowPdf:l=!1,hint:S}){return e.jsx(hs,{label:t,required:n,url:i,onUrlChange:d,maxCount:1,onPreview:u,compact:h,imagesOnly:y,allowPdf:l,hint:S})}const{Text:Ce}=U,_s=a.forwardRef(function({value:n,onChange:i,min:d,max:u,placeholder:h},y){const[l,S]=a.useState(""),_=a.useRef(!1);a.useEffect(()=>{_.current||(n==null||n===""?S(""):S(String(n)))},[n]);const M=()=>{const j=String(l).trim();if(j===""){i(void 0),S("");return}let C=Math.round(parseFloat(j)*100)/100;if(Number.isNaN(C)||C<=0){i(void 0),S("");return}return d!=null&&C<d&&(C=d),u!=null&&C>u&&(C=u),i(C),S(String(C)),C};return a.useImperativeHandle(y,()=>({commit:M}),[l,d,u,i]),e.jsx(_e,{style:{width:"100%"},value:l,onFocus:()=>{_.current=!0},onChange:j=>S(j==null?"":String(j)),onBlur:()=>{_.current=!1,M()},onEnterPress:M,placeholder:h})});function xt({required:t,children:n}){return e.jsxs(Ce,{size:"small",className:"block mb-1.5 text-[var(--semi-color-text-0)]",children:[t?e.jsx("span",{className:"text-[var(--semi-color-danger)] mr-1","aria-hidden":!0,children:"*"}):null,n]})}function gt({children:t}){return e.jsx("div",{className:"min-w-0",children:t})}function G({title:t,children:n}){return e.jsxs(e.Fragment,{children:[e.jsx(Bt,{margin:"16px",align:"left",children:t}),e.jsx("div",{className:"space-y-4",children:n})]})}function D({label:t,required:n,value:i,onChange:d,placeholder:u}){return e.jsxs(gt,{children:[e.jsx(xt,{required:n,children:t}),e.jsx(_e,{value:i,onChange:h=>d(String(h??"")),placeholder:u})]})}function se({label:t,url:n,onUrlChange:i,onPreview:d,imagesOnly:u=!1,allowPdf:h=!1}){return e.jsx(gt,{children:e.jsx(gs,{label:t,required:!0,url:n,onUrlChange:i,onPreview:d,compact:!0,imagesOnly:u,allowPdf:h,hint:u?"":void 0})})}function bs({accountType:t,form:n,onFieldChange:i,onPreview:d,fiatCommitRef:u,isQuotaTokensMode:h,quotaInput:y,onQuotaInputChange:l,fiatAmount:S,onFiatAmountChange:_,fiatMin:M,fiatMax:j,affQuotaFloor:C,minQInternal:z,affQuota:E,renderQuota:T}){const{t:r}=Be(),p=i;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ce,{size:"small",className:"text-[var(--semi-color-text-0)]",children:r("账户类型")}),e.jsx(ae,{color:t===ze?"blue":"green",type:"solid",size:"large",children:r(t===ze?"企业":"个人")})]}),t===Ye?e.jsxs(e.Fragment,{children:[e.jsxs(G,{title:r("基本信息"),children:[e.jsx(D,{label:r("姓名"),required:!0,value:n.real_name,onChange:o=>p("real_name",o),placeholder:r("姓名(必填)")}),e.jsx(D,{label:r("身份证号"),required:!0,value:n.id_card_no,onChange:o=>p("id_card_no",o),placeholder:r("身份证号(必填)")}),e.jsx(D,{label:r("身份证有效期"),required:!0,value:n.id_card_expiry,onChange:o=>p("id_card_expiry",o),placeholder:r("如 2030-12-31 或 长期")}),e.jsx(D,{label:r("手机号"),required:!0,value:n.mobile,onChange:o=>p("mobile",o),placeholder:r("手机号(必填)")})]}),e.jsxs(G,{title:r("银行信息"),children:[e.jsx(D,{label:r("银行卡号"),required:!0,value:n.bank_account,onChange:o=>p("bank_account",o),placeholder:r("银行卡号(必填)")}),e.jsx(D,{label:r("开户行"),required:!0,value:n.bank_name,onChange:o=>p("bank_name",o),placeholder:r("开户行(必填)")}),e.jsx(D,{label:r("银行预留手机号"),required:!0,value:n.bank_reserved_phone,onChange:o=>p("bank_reserved_phone",o),placeholder:r("银行预留手机号(必填)")})]}),e.jsxs(G,{title:r("证件照片"),children:[e.jsx(se,{label:r("身份证正面"),url:n.id_card_front_url,onUrlChange:o=>p("id_card_front_url",o),onPreview:d,imagesOnly:!0}),e.jsx(se,{label:r("身份证反面"),url:n.id_card_back_url,onUrlChange:o=>p("id_card_back_url",o),onPreview:d,imagesOnly:!0}),e.jsx(se,{label:r("银行卡照"),url:n.bank_card_photo_url,onUrlChange:o=>p("bank_card_photo_url",o),onPreview:d,imagesOnly:!0})]}),e.jsx(G,{title:r("发票"),children:e.jsx(se,{label:r("发票"),url:n.invoice_url,onUrlChange:o=>p("invoice_url",o),onPreview:d,allowPdf:!0})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(G,{title:r("企业信息"),children:[e.jsx(D,{label:r("企业名称"),required:!0,value:n.real_name,onChange:o=>p("real_name",o),placeholder:r("企业名称(必填)")}),e.jsx(D,{label:r("统一社会信用代码"),required:!0,value:n.credit_code,onChange:o=>p("credit_code",o),placeholder:r("统一社会信用代码(必填)")}),e.jsx(D,{label:r("法人姓名"),required:!0,value:n.legal_person_name,onChange:o=>p("legal_person_name",o),placeholder:r("法人姓名(必填)")}),e.jsx(D,{label:r("法人手机号"),required:!0,value:n.legal_person_phone,onChange:o=>p("legal_person_phone",o),placeholder:r("法人手机号(必填)")}),e.jsx(D,{label:r("对公卡号"),required:!0,value:n.bank_account,onChange:o=>p("bank_account",o),placeholder:r("对公卡号(必填)")}),e.jsx(D,{label:r("开户行"),required:!0,value:n.bank_name,onChange:o=>p("bank_name",o),placeholder:r("开户行(必填)")}),e.jsx(D,{label:r("联行号"),required:!0,value:n.bank_branch_code,onChange:o=>p("bank_branch_code",o),placeholder:r("联行号(必填)")}),e.jsx(D,{label:r("联系人"),required:!0,value:n.contact_person,onChange:o=>p("contact_person",o),placeholder:r("联系人(必填)")})]}),e.jsxs(G,{title:r("企业附件"),children:[e.jsx(se,{label:r("营业执照"),url:n.business_license_url,onUrlChange:o=>p("business_license_url",o),onPreview:d,imagesOnly:!0}),e.jsx(se,{label:r("对公账户证明"),url:n.corporate_account_proof_url,onUrlChange:o=>p("corporate_account_proof_url",o),onPreview:d,imagesOnly:!0})]}),e.jsx(G,{title:r("发票"),children:e.jsx(se,{label:r("发票"),url:n.invoice_url,onUrlChange:o=>p("invoice_url",o),onPreview:d,allowPdf:!0})})]}),e.jsxs(G,{title:r("提现金额"),children:[e.jsx(xt,{required:!0,children:r("提现余额")}),h?e.jsxs(e.Fragment,{children:[e.jsx(Ce,{type:"tertiary",size:"small",className:"block mb-2",children:r("TOKENS 模式:与上方「待使用收益」数字一致,填写系统内部点数(正整数)")}),e.jsx(_e,{value:y,onChange:o=>l(o==null?"":String(o)),placeholder:r("请输入内部点数")})]}):e.jsx(_s,{ref:u,value:S,onChange:_,min:M,max:j,placeholder:r("填写收益金额")}),e.jsx(Ce,{type:"tertiary",size:"small",className:"block mt-1",children:C>=z?e.jsxs(e.Fragment,{children:[r("单笔最低"),": ",T(z)," · ",r("当前待使用余额"),":"," ",T(E||0)]}):e.jsxs(e.Fragment,{children:[r("单笔最低"),": ",T(z)," ·"," ",C>0?e.jsxs(e.Fragment,{children:[r("当前余额低于系统最低门槛时,可提范围"),": ",T(1),"~",T(C)," ·"," "]}):null,r("当前待使用余额"),": ",T(E||0)]})})]})]})}function ws(t){return/\.pdf(\?|$)/i.test(t||"")}const{Text:q,Title:js}=U,ke=168,Ae=20,fe=2,ct=14;function dt(t,n,i,d,u,h){const y=Math.min(h,d/2,u/2);t.beginPath(),t.moveTo(n+y,i),t.lineTo(n+d-y,i),t.quadraticCurveTo(n+d,i,n+d,i+y),t.lineTo(n+d,i+u-y),t.quadraticCurveTo(n+d,i+u,n+d-y,i+u),t.lineTo(n+y,i+u),t.quadraticCurveTo(n,i+u,n,i+u-y),t.lineTo(n,i+y),t.quadraticCurveTo(n,i,n+y,i),t.closePath()}function ys(t,n){const i=URL.createObjectURL(t),d=document.createElement("a");d.href=i,d.download=n,d.click(),URL.revokeObjectURL(i)}function vs(t,n){return new Promise((i,d)=>{const u=new XMLSerializer().serializeToString(t),h=new Blob([u],{type:"image/svg+xml;charset=utf-8"}),y=URL.createObjectURL(h),l=new Image;l.onload=()=>{try{const S=document.createElement("canvas"),_=ke+Ae*2,M=Math.max(window.devicePixelRatio||1,1);S.width=_*M,S.height=_*M;const j=S.getContext("2d");if(!j){d(new Error("canvas context unavailable"));return}j.scale(M,M),j.fillStyle="#ffffff",dt(j,0,0,_,_,ct),j.fill(),j.strokeStyle="#d9d9d9",j.lineWidth=fe,dt(j,fe/2,fe/2,_-fe,_-fe,ct),j.stroke(),j.drawImage(l,Ae,Ae,ke,ke),S.toBlob(C=>{if(!C){d(new Error("png export failed"));return}ys(C,n),i()},"image/png")}catch(S){d(S)}finally{URL.revokeObjectURL(y)}},l.onerror=()=>{URL.revokeObjectURL(y),d(new Error("qr image load failed"))},l.src=y})}function Ds(){var tt,st;const{t}=Be(),n=Ht(),[i]=a.useContext(Gt),[d,u]=a.useContext(Zt),[h,y]=a.useState(!0),[l,S]=a.useState(null),[_,M]=a.useState([]),[j,C]=a.useState(0),[z,E]=a.useState(1),[T,r]=a.useState(10),[p,o]=a.useState(!1),[$,Y]=a.useState(!1),[m,O]=a.useState(""),[B,Z]=a.useState(!1),[J,ce]=a.useState(Ye),[L,be]=a.useState({...nt}),[we,de]=a.useState(""),[je,ue]=a.useState(void 0),[f,x]=a.useState(!1),g=a.useRef(null),[N,k]=a.useState(!1),[V,H]=a.useState([]),[re,K]=a.useState(0),[Q,_t]=a.useState(1),[ne,bt]=a.useState(10),[ye,Me]=a.useState(null),[wt,Ve]=a.useState(!1),[jt,He]=a.useState(null),[yt,Ke]=a.useState(""),[vt,Qe]=a.useState(!1),[Nt,Ge]=a.useState(null),[St,Ze]=a.useState(""),[Ct,De]=a.useState(!1),[qe,Le]=a.useState(()=>te()),Je=(((tt=i==null?void 0:i.status)==null?void 0:tt.distributor_withdraw_cs_image_url)||"").trim(),Xe=(()=>{var b,v;const s=Number((b=i==null?void 0:i.status)==null?void 0:b.distributor_min_withdraw_quota);if(Number.isFinite(s)&&s>0)return Math.floor(s);let c=te();return(!Number.isFinite(c)||c<=0)&&(c=Number((v=i==null?void 0:i.status)==null?void 0:v.quota_per_unit)),(!Number.isFinite(c)||c<=0)&&(c=parseFloat(localStorage.getItem("quota_per_unit")||"")||5e5),c})(),le=a.useMemo(()=>typeof window>"u"?!1:(localStorage.getItem("quota_display_type")||"USD")==="TOKENS",[p]),X=Math.floor(Number(l==null?void 0:l.aff_quota)||0),ve=Xe,ie=a.useMemo(()=>{var s;return String(((s=i==null?void 0:i.status)==null?void 0:s.distributor_commission_mode)||"topup")==="profit_share"},[(st=i==null?void 0:i.status)==null?void 0:st.distributor_commission_mode]),kt=a.useMemo(()=>{if(!(le||X<=0))return X>=ve?Oe(ve):Oe(1)},[le,X,ve]),Tt=a.useMemo(()=>{if(!(le||X<=0))return Oe(X)},[le,X]),Re=a.useMemo(()=>{const s=d==null?void 0:d.user;if(s)return at(s);try{const c=localStorage.getItem("user");if(c)return at(JSON.parse(c))}catch{}return!1},[d==null?void 0:d.user]);a.useEffect(()=>{if(!p)return;let s=!1;return(async()=>{Y(!0),O("");try{const c=await F.get("/api/status"),{success:b,data:v,message:W}=c.data||{};if(!b){s||w(W||t("加载失败"));return}const I=String((v==null?void 0:v.distributor_withdraw_notice)??"").trim();s||O(I)}catch{s||w(t("加载失败"))}finally{s||Y(!1)}})(),()=>{s=!0}},[p,t]);const Ne=async()=>{const s=await F.get("/api/distributor/center"),{success:c,message:b,data:v}=s.data;if(!c){w(b),n("/console/topup");return}S(v)},oe=a.useCallback(async()=>{const s=await F.get("/api/user/self"),{success:c,message:b,data:v}=s.data;return c&&v?(u({type:"login",payload:v}),v):(b&&w(b),null)},[u]),Pe=a.useCallback(async(s=1,c=T)=>{const b=await F.get(`/api/user/aff_invitees?p=${s}&page_size=${c}`),{success:v,message:W,data:I}=b.data;if(!v){w(W);return}M((I==null?void 0:I.items)||[]),C((I==null?void 0:I.total)??0),E(s)},[T]);a.useEffect(()=>{if(!Re){n("/console/topup");return}(async()=>{y(!0);try{await Ne(),await Pe(1,T),await oe()}finally{y(!1)}})()},[Re]),a.useEffect(()=>{Le(te())},[]);const It=(s,c)=>{be(b=>({...b,[s]:c}))},Fe=a.useMemo(()=>Number(l==null?void 0:l.apply_type)===ze?ze:Ye,[l==null?void 0:l.apply_type]),et=()=>{ce(Fe),be({...nt,real_name:String((l==null?void 0:l.application_real_name)||"").trim()})},zt=async()=>{var W,I;const s=us(t,Fe,L);if(s){w(s);return}const c=Math.floor(Number(l==null?void 0:l.aff_quota)||0),b=Xe;let v;if(le){const A=String(we).trim();if(A===""){w(t("请填写提现额度"));return}if(!/^\d+$/.test(A)){w(t("提现额度须为正整数"));return}if(v=parseInt(A,10),v<=0){w(t("提现额度须为正整数"));return}}else{const A=(I=(W=g.current)==null?void 0:W.commit)==null?void 0:I.call(W),ee=A!=null&&!Number.isNaN(Number(A))?A:je;if(ee==null||Number.isNaN(Number(ee))||Number(ee)<=0){w(t("请填写与上方待使用收益一致的提现金额"));return}const $t=Math.round(Number(ee)*100)/100;if(v=ls($t),v<=0){w(t("提现金额过小或无效"));return}}if(c>=b){if(v<b){w(t("提现额度不能低于")+" "+P(b));return}}else if(v<1||v>c){w(t("提现额度须在 1 与当前待使用余额之间"));return}if(v>c){w(t("提现额度不能大于当前可提现额度")+"("+P(c)+")");return}x(!0);try{const A=ms(Fe,L,v),ee=await F.post("/api/distributor/withdrawal",A);ee.data.success?(xe(t("已提交,请等待审核")),o(!1),et(),de(""),ue(void 0),await Ne(),await oe(),B&&await me(Q,ne)):w(ee.data.message)}catch{w(t("提交失败"))}finally{x(!1)}},me=async(s=1,c=ne)=>{k(!0);try{const b=await F.get(`/api/distributor/withdrawals?p=${s}&page_size=${c}`),{success:v,message:W,data:I}=b.data;if(!v){w(W);return}H((I==null?void 0:I.items)||[]),K((I==null?void 0:I.total)??0),_t(s)}catch{w(t("加载失败"))}finally{k(!1)}},Mt=async s=>{try{const c=await F.post(`/api/distributor/withdrawals/${s}/cancel`);c.data.success?(xe(t("已取消")),await Ne(),await oe(),await me(Q,ne)):w(c.data.message)}catch{w(t("操作失败"))}},Dt=s=>s===1?t("提现中"):s===2?t("提现成功"):s===3?t("提现失败"):s===4?t("已取消"):"—",qt=s=>{const c=Dt(s);return s===1?e.jsx(ae,{color:"blue",type:"light",size:"small",children:c}):s===2?e.jsx(ae,{color:"green",type:"light",size:"small",children:c}):s===3?e.jsx(ae,{color:"red",type:"light",size:"small",children:c}):s===4?e.jsx(ae,{color:"grey",type:"light",size:"small",children:c}):e.jsx(ae,{size:"small",type:"light",children:c})},Lt=a.useCallback(async()=>{await oe(),Le(te()),De(!0)},[oe]),Rt=async()=>{if(qe<te()){w(t("划转金额最低为")+" "+P(te()));return}const s=await F.post("/api/user/aff_transfer",{quota:qe}),{success:c,message:b}=s.data;c?(xe(b),De(!1),await oe(),await Ne()):w(b)},Pt=()=>De(!1),he=(l==null?void 0:l.aff_code)&&`${window.location.origin}/r/${l.aff_code}`,Ft=a.useCallback(async()=>{var c;const s=(c=document.getElementById("dist-qr-wrap"))==null?void 0:c.querySelector("svg");if(s)try{await vs(s,`invite-${(l==null?void 0:l.aff_code)||"qrcode"}.png`)}catch{w(t("下载失败"))}},[l==null?void 0:l.aff_code,t]),Et=s=>{He(s.invitee_id),Ke(String(s.display_name||s.username||`#${s.invitee_id}`).trim()),Ve(!0)},Ot=s=>{Ge(s.invitee_id),Ze(String(s.display_name||s.username||`#${s.invitee_id}`).trim()),Qe(!0)},Wt=a.useMemo(()=>[{title:t("被邀请用户"),dataIndex:"username",render:(s,c)=>c.display_name||c.username||c.invitee_id},{title:t("邀请时间"),dataIndex:"created_at",width:180,render:s=>s?Ie.unix(Number(s)).format("YYYY-MM-DD HH:mm"):"—"},{title:t(ie?"累计利润分成额度":"累计分成额度"),dataIndex:ie?"profit_share_earned_quota":"commission_earned_quota",render:s=>P(s||0)},{title:t("操作"),width:160,render:(s,c)=>e.jsxs(Se,{children:[e.jsx(R,{size:"small",type:"tertiary",onClick:()=>Et(c),children:t("详情")}),ie?e.jsx(R,{size:"small",type:"tertiary",onClick:()=>Ot(c),children:t("模型折扣率")}):null]})}],[ie,t]);return Re?e.jsxs("div",{className:"mt-14 px-4 pb-16 max-w-7xl mx-auto",children:[e.jsx(js,{heading:3,className:"mb-8",children:t("代理分销")}),e.jsx(ht,{type:"info",className:"mt-2 !rounded-xl",description:t(ie?"邀请用户用量产生的加价部分将计入您的待使用收益,可在详情中按笔查看。":"邀请的用户充值后,您将获得对应比例的分销额度(待使用收益)。分成比例以您账号当前设置为准;可在「详情」中查看每笔充值的入账额度、当时比例与收益。")}),e.jsxs("div",{className:"mt-2 flex flex-col xl:flex-row gap-8 xl:gap-10 items-start",children:[e.jsxs("aside",{className:"flex w-full flex-col gap-[10px] xl:w-[520px] flex-shrink-0 order-1 xl:order-2",children:[e.jsx(Ee,{className:"!rounded-xl w-full shadow-sm border-0",cover:e.jsx("div",{className:"relative min-h-[10.5rem]",style:{"--palette-primary-darkerChannel":"0 75 80",backgroundImage:"linear-gradient(0deg, rgba(var(--palette-primary-darkerChannel) / 80%), rgba(var(--palette-primary-darkerChannel) / 80%)), url('/cover-4.webp')",backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat"},children:e.jsxs("div",{className:"relative z-10 h-full flex flex-col justify-between p-4",children:[e.jsxs("div",{className:"flex justify-between items-start gap-2",children:[e.jsxs("div",{children:[e.jsx(q,{strong:!0,style:{color:"white",fontSize:"16px"},children:t("收益统计")}),e.jsxs(q,{style:{color:"rgba(255,255,255,0.88)",fontSize:"12px",display:"block",marginTop:6},children:[t("当前分销比例"),":",Ue((l==null?void 0:l.effective_commission_bps)??0)]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 flex-shrink-0",children:[e.jsx(R,{type:"primary",theme:"solid",size:"small",onClick:()=>{et(),de(""),ue(void 0),Me(null),o(!0)},className:"!rounded-lg !border-0 !bg-emerald-600 hover:!bg-emerald-700 active:!bg-emerald-800 !text-white",children:t("提现")}),e.jsx(R,{type:"tertiary",theme:"solid",size:"small",onClick:async()=>{Z(!0),await me(1,ne)},className:"!rounded-lg",children:t("提现记录")}),e.jsxs(R,{type:"primary",theme:"solid",size:"small",disabled:!(l!=null&&l.aff_quota)||l.aff_quota<=0,onClick:()=>Lt(),className:"!rounded-lg",children:[e.jsx(es,{size:12,className:"mr-1"}),t("划转到余额")]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 sm:gap-6 mt-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base sm:text-2xl font-bold mb-2",style:{color:"white"},children:P((l==null?void 0:l.aff_quota)||0)}),e.jsxs("div",{className:"flex items-center justify-center text-sm",children:[e.jsx(ts,{size:14,className:"mr-1",style:{color:"rgba(255,255,255,0.8)"}}),e.jsx(q,{style:{color:"rgba(255,255,255,0.8)",fontSize:"12px"},children:t("待使用收益")})]})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base sm:text-2xl font-bold mb-2",style:{color:"white"},children:P((l==null?void 0:l.aff_history_quota)||0)}),e.jsxs("div",{className:"flex items-center justify-center text-sm",children:[e.jsx(ss,{size:14,className:"mr-1",style:{color:"rgba(255,255,255,0.8)"}}),e.jsx(q,{style:{color:"rgba(255,255,255,0.8)",fontSize:"12px"},children:t("总收益")})]})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base sm:text-2xl font-bold mb-2",style:{color:"white"},children:(l==null?void 0:l.aff_count)??0}),e.jsxs("div",{className:"flex items-center justify-center text-sm",children:[e.jsx(as,{size:14,className:"mr-1",style:{color:"rgba(255,255,255,0.8)"}}),e.jsx(q,{style:{color:"rgba(255,255,255,0.8)",fontSize:"12px"},children:t("邀请人数")})]})]})]})]})}),children:e.jsx(Se,{vertical:!0,style:{width:"100%"},className:"!gap-3",children:e.jsx(_e,{value:he||"",readonly:!0,className:"!rounded-lg",prefix:t("邀请链接"),suffix:e.jsx(R,{type:"primary",theme:"solid",onClick:async()=>{he&&await Xt(he)&&xe(t("邀请链接已复制到剪切板"))},icon:e.jsx(Jt,{size:14}),className:"!rounded-lg",children:t("复制")})})})}),e.jsx(Ee,{className:"!rounded-2xl",title:t("注册二维码"),bodyStyle:{paddingTop:20,paddingBottom:24},children:e.jsx("div",{className:"w-full flex flex-col items-center",children:he?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"inline-flex rounded-xl bg-[var(--semi-color-fill-0)] p-2 ring-1 ring-[var(--semi-color-border)]",children:e.jsx("div",{className:"rounded-lg bg-semi-color-white p-2 shadow-[0_2px_8px_rgba(0,0,0,0.08)] dark:shadow-[0_4px_16px_rgba(0,0,0,0.55)] ring-1 ring-black/[0.06] dark:ring-white/[0.12]",id:"dist-qr-wrap",children:e.jsx(rs,{value:he,size:ke,level:"M",bgColor:"#ffffff",fgColor:"#000000"})})}),e.jsx(R,{className:"mt-2",size:"small",onClick:Ft,children:t("下载二维码")})]}):e.jsx(q,{type:"tertiary",children:"—"})})})]}),e.jsx("div",{className:"flex-1 min-w-0 w-full order-2 xl:order-1 mt-2 sm:mt-4 xl:mt-0",children:e.jsx(Ee,{className:"!rounded-2xl",title:t("邀请用户列表"),loading:h,children:e.jsx(Te,{rowKey:"invitee_id",columns:Wt,dataSource:_,pagination:{currentPage:z,pageSize:T,total:j,onPageChange:s=>Pe(s,T),onPageSizeChange:s=>{r(s),Pe(1,s)}}})})})]}),e.jsx(ps,{visible:wt,onCancel:()=>{Ve(!1),He(null),Ke("")},inviteeId:jt,inviteeLabel:yt,commissionMode:ie?"profit_share":"topup"}),e.jsx(xs,{visible:vt,onCancel:()=>{Qe(!1),Ge(null),Ze("")},inviteeId:Nt,inviteeLabel:St,t}),e.jsx(ns,{t,openTransfer:Ct,transfer:Rt,handleTransferCancel:Pt,userState:d,renderQuota:P,getQuotaPerUnit:te,transferAmount:qe,setTransferAmount:Le}),e.jsxs(ge,{title:t("提现"),visible:p,onCancel:()=>o(!1),footer:e.jsxs(Se,{children:[e.jsx(R,{onClick:()=>o(!1),children:t("关闭")}),e.jsx(R,{type:"primary",theme:"solid",loading:f,onClick:zt,children:t("提交申请")})]}),width:Math.min(960,typeof window<"u"?window.innerWidth-48:960),children:[e.jsx("div",{className:"mb-4",children:e.jsx(q,{type:"tertiary",size:"small",className:"block",children:t("提交后将暂扣对应待使用收益,审核通过即完成提现;驳回或取消将退回额度。")})}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 items-start",children:[e.jsxs("div",{className:"flex-1 min-w-0 w-full space-y-5",children:[e.jsx(bs,{accountType:J,form:L,onFieldChange:It,onPreview:Me,fiatCommitRef:g,isQuotaTokensMode:le,quotaInput:we,onQuotaInputChange:de,fiatAmount:je,onFiatAmountChange:ue,fiatMin:kt,fiatMax:Tt,affQuotaFloor:X,minQInternal:ve,affQuota:l==null?void 0:l.aff_quota,renderQuota:P}),e.jsxs("div",{className:"mt-4",children:[e.jsx(q,{size:"small",strong:!0,className:"block mb-2",children:t("提现说明")}),e.jsx(mt,{spinning:$,children:m?e.jsx(q,{type:"secondary",size:"small",className:"block whitespace-pre-wrap break-words",children:m}):!$&&e.jsx(q,{type:"tertiary",size:"small",children:t("管理员未配置提现说明")})})]})]}),e.jsxs("div",{className:"w-full lg:w-[280px] flex-shrink-0",children:[e.jsx(q,{strong:!0,className:"block mb-2",children:t("联系客服")}),Je?e.jsx("div",{className:"rounded-lg border border-[var(--semi-color-border)] bg-[var(--semi-color-fill-0)] p-2 overflow-auto max-h-[min(420px,50vh)]",children:e.jsx("img",{src:Je,alt:"",className:"w-full object-contain"})}):e.jsx(q,{type:"tertiary",size:"small",children:t("管理员可在运营设置中配置右侧客服图片")})]})]})]}),e.jsx(ge,{title:t("提现记录"),visible:B,onCancel:()=>Z(!1),footer:e.jsx(R,{onClick:()=>Z(!1),children:t("关闭")}),width:960,children:e.jsx(Te,{loading:N,size:"small",rowKey:"id",scroll:{x:1100},columns:[{title:t("额度"),dataIndex:"quota_amount",width:120,render:s=>P(s||0)},{title:t("状态"),dataIndex:"status",width:112,render:s=>qt(s)},{title:t("提现月份"),dataIndex:"withdraw_month",width:100},{title:t("类型"),dataIndex:"account_type",width:72,render:s=>cs(t,s)},{title:t("收款信息"),render:(s,c)=>{const b=ds(c);return e.jsxs("div",{className:"text-xs space-y-0.5",children:[e.jsx("div",{children:b.real_name}),e.jsxs("div",{className:"text-[var(--semi-color-text-2)]",children:[b.bank_name," ",b.bank_account]})]})}},{title:t("时间"),dataIndex:"created_at",width:158,render:s=>s?Ie.unix(Number(s)).format("YYYY-MM-DD HH:mm"):"—"},{title:t("反馈原因"),width:200,render:(s,c)=>{const b=String(c.reject_reason||"").trim();return b?e.jsx(q,{size:"small",className:"break-all text-[var(--semi-color-text-0)]",children:b}):e.jsx(q,{type:"tertiary",size:"small",children:"—"})}},{title:t("操作"),width:100,fixed:"right",align:"center",render:(s,c)=>c.status===1?e.jsx(Vt,{title:t("确认取消该笔提现?额度将退回"),onConfirm:()=>Mt(c.id),children:e.jsx(ae,{color:"red",type:"light",size:"small",className:"cursor-pointer",children:t("取消")})}):e.jsx(q,{type:"tertiary",size:"small",children:"—"})}],dataSource:V,pagination:{currentPage:Q,pageSize:ne,total:re,onPageChange:s=>me(s,ne),onPageSizeChange:s=>{bt(s),me(1,s)}}})}),e.jsx(ge,{title:t("预览"),visible:!!ye,onCancel:()=>Me(null),footer:null,width:Math.min(900,typeof window<"u"?window.innerWidth-48:900),children:ye&&!ws(ye)?e.jsx("div",{className:"flex max-h-[85vh] justify-center overflow-auto p-2",children:e.jsx("img",{src:ye,alt:"",className:"max-h-[85vh] max-w-full object-contain"})}):null})]}):null}export{Ds as default};
|