From 276e7dfee0b3132b57ea539f9f170a4eb1ea8632 Mon Sep 17 00:00:00 2001 From: Ultrame <1019265060@qq.com> Date: Mon, 29 Sep 2025 22:43:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E7=8E=B0=E9=94=99=E8=AF=AF=E5=BC=B9?= =?UTF-8?q?=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/api.ts | 2 +- src/services/httpService.ts | 22 ++- .../setTransactionPassword/index.tsx | 45 ++--- src/user_pages/wallet/index.tsx | 2 +- src/user_pages/withdrawal/index.tsx | 177 +++++++++--------- 5 files changed, 121 insertions(+), 127 deletions(-) diff --git a/src/config/api.ts b/src/config/api.ts index 489dd2d..763f263 100644 --- a/src/config/api.ts +++ b/src/config/api.ts @@ -31,7 +31,7 @@ export const API_CONFIG = { LEAVE: '/game/leave' }, PROFESSIONS: '/professions/tree', - CITIS: '/admin/wch_cities/page' + CITIS: '/cities/tree' }; // 请求拦截器配置 diff --git a/src/services/httpService.ts b/src/services/httpService.ts index 19c1c4a..225635a 100644 --- a/src/services/httpService.ts +++ b/src/services/httpService.ts @@ -105,7 +105,7 @@ class HttpService { } // 处理响应 - private handleResponse(response: any): Promise> { + private handleResponse(response: any, showToast: boolean): Promise> { return new Promise((resolve, reject) => { const { statusCode, data } = response @@ -121,8 +121,12 @@ class HttpService { // 业务状态码检查 if (data && typeof data === 'object') { if (data.success === false || (data.code && data.code !== 0 && data.code !== 200)) { - this.handleBusinessError(data) - reject(new Error(data.message || '请求失败')) + if (showToast) { + this.handleBusinessError(data) + reject(new Error(data.message || '请求失败')) + } else { + reject(response.data) + } return } } @@ -191,7 +195,8 @@ class HttpService { data, params, showLoading = false, - loadingText = '请求中...' + loadingText = '请求中...', + showToast = true, } = config let fullUrl = this.buildUrl(url, method === 'GET' ? params : undefined) @@ -238,11 +243,12 @@ class HttpService { method: method, data: method !== 'GET' ? data : undefined, header: reqHeader, - timeout: this.timeout + timeout: this.timeout, + showToast, } const response = await Taro.request(requestConfig) - return this.handleResponse(response) + return this.handleResponse(response, showToast) } catch (error) { this.log('error', '请求失败', error) @@ -304,9 +310,9 @@ class HttpService { } - uploadFile(){ + uploadFile() { + - } // PUT请求 diff --git a/src/user_pages/setTransactionPassword/index.tsx b/src/user_pages/setTransactionPassword/index.tsx index 15656f0..cd8cb78 100644 --- a/src/user_pages/setTransactionPassword/index.tsx +++ b/src/user_pages/setTransactionPassword/index.tsx @@ -43,38 +43,19 @@ const SetTransactionPassword: React.FC = () => { }); return; } - if (handleType === "set") { - const { sms_code } = formData; - try { - await httpService.post("/wallet/set_payment_password", { password: new_password, sms_code }); - Taro.showToast({ - title: "设置交易密码成功", - icon: "success", - }); - Taro.navigateBack(); - } catch (error) { - Taro.showToast({ - title: "设置交易密码失败", - icon: "none", - }); - return; - } - } else if (handleType === "reset") { - // const { old_password } = formData; - try { - await httpService.post("/wallet/reset_payment_password", { phone, new_password, sms_code }); - Taro.showToast({ - title: "修改交易密码成功", - icon: "success", - }); - Taro.navigateBack(); - } catch (error) { - Taro.showToast({ - title: "修改交易密码失败", - icon: "none", - }); - return; - } + try { + await httpService.post("/wallet/set_payment_password", { password: new_password }); + Taro.showToast({ + title: "设置交易密码成功", + icon: "success", + }); + Taro.navigateBack(); + } catch (error) { + Taro.showToast({ + title: "设置交易密码失败", + icon: "none", + }); + return; } }; diff --git a/src/user_pages/wallet/index.tsx b/src/user_pages/wallet/index.tsx index 17bde07..2da38cb 100644 --- a/src/user_pages/wallet/index.tsx +++ b/src/user_pages/wallet/index.tsx @@ -267,7 +267,7 @@ const WalletPage: React.FC = () => { // 处理提现 const handle_withdraw = () => { - if (password_status) { + if (!password_status) { navigateToSetTransactionPassword("set"); return; } diff --git a/src/user_pages/withdrawal/index.tsx b/src/user_pages/withdrawal/index.tsx index 114430a..712c8fa 100644 --- a/src/user_pages/withdrawal/index.tsx +++ b/src/user_pages/withdrawal/index.tsx @@ -27,19 +27,11 @@ const Withdrawal: React.FC = () => { const [password, setPassword] = useState(new Array(6).fill("")); - const toastConfig = { - aa: { - title: "已超单日限额", - content: "您今日提现已超过支付通道2000元单日限额;建议您明日再发起提现,资金仍安全存放在钱包余额中。" - }, - bb: { - title: "已超单日限额", - content: "今日提现通道额度已用完,暂时无法提现;您的余额安全存放在钱包中,我们会在 次日0点恢复 提现服务;如有紧急情况,请联系客服。" - } - } + const [mapErrorCodes, setMapErrorCodes] = useState({}); useDidShow(() => { load_wallet_data(); + getWithdrawErrorCodes(); }); useEffect(() => { @@ -112,66 +104,102 @@ const Withdrawal: React.FC = () => { }); } }; + const getWithdrawErrorCodes = async () => { + try { + const response = await httpService.post("/wallet/error_codes"); + if (response.code === 0) { + const { withdraw_errors: { WEIXIN_ERRORS } } = response.data; + const mapErrorCodes = {}; + for (const key in WEIXIN_ERRORS) { + const { code } = WEIXIN_ERRORS[key]; + mapErrorCodes[code] = WEIXIN_ERRORS[key]; + } + setMapErrorCodes(mapErrorCodes); + } + } catch (error: any) { + console.error("获取提现错误码失败:", error); + } + } const handleWithdraw = async () => { - // TODO 校验提现状态 - // if (true) { - // Taro.showToast({ - // title: "您今日已累计提现 10次,达到每日次数上限", - // icon: "none", - // }); - // } - // const { aa, bb } = toastConfig; - // Taro.showModal({ - // title: aa.title, - // content: aa.content, - // showCancel: false, - // confirmColor: "#000", - // }); - // Taro.showModal({ - // title: bb.title, - // content: bb.content, - // showCancel: false, - // confirmColor: "#000", - // }); set_show_withdraw_popup(true); }; - const submit_withdraw = async () => { - // 先调用后端接口获取提现参数 - const response = await httpService.post("/wallet/withdraw", { - amount: parseFloat(inputValue), - transfer_remark: "用户申请提现", - }); + const submit_withdraw = async (payment_password: string) => { + try { + // 先调用后端接口获取提现参数 + const response = await httpService.post("/wallet/withdraw", { + amount: parseFloat(inputValue), + transfer_remark: "用户申请提现", + payment_password, + }, { showToast: false }); + const { data } = response; + // 根据后端返回的数据结构解析参数 + const { mch_id, app_id, package_info, open_id } = data; - // 根据后端返回的数据结构解析参数 - const { mch_id, app_id, package_info, open_id } = response.data; + console.log("/wallet/withdraw:", data); + set_show_withdraw_popup(false); - console.log("/wallet/withdraw:", response.data); - set_show_withdraw_popup(false); + // 调用微信商户转账接口 + (Taro as any).requestMerchantTransfer({ + mchId: mch_id, + appId: app_id, + package: package_info, + openId: open_id, + success: (res) => { + console.log("微信转账成功:", res); + Taro.showToast({ + title: "提现成功", + icon: "success", + duration: 2000, + }); - // 调用微信商户转账接口 - (Taro as any).requestMerchantTransfer({ - mchId: mch_id, - appId: app_id, - package: package_info, - openId: open_id, - success: (res) => { - console.log("微信转账成功:", res); + // 关闭弹窗并重置状态 + set_show_withdraw_popup(false); + setInputValue("0.00"); + // 重新加载数据 + load_wallet_data(); + }, + fail: (res) => { + console.log("微信转账失败:", res); + }, + }); + } catch (error: any) { + const { code, message } = error; + if (message === "支付密码错误") { + set_show_withdraw_popup(false); + Taro.showModal({ + content: "支付密码错误,请重试", + cancelText: "忘记密码", + confirmText: "重试", + cancelColor: "#000", + confirmColor: "#fff", + }).then((res) => { + if (res.confirm) { + set_show_withdraw_popup(true); + } else if (res.cancel) { + Taro.navigateTo({ + url: "/user_pages/validPhone/index" + }); + } + }); + return; + } else if (mapErrorCodes[code]) { + const { message, description } = mapErrorCodes[code]; + Taro.showModal({ + title: description, + content: message, + showCancel: false, + confirmText: "确认", + confirmColor: "#fff", + }); + return; + } else { Taro.showToast({ - title: "提现成功", - icon: "success", + title: message, + icon: "none", duration: 2000, }); - - // 关闭弹窗并重置状态 - set_show_withdraw_popup(false); - setInputValue("0.00"); - // 重新加载数据 - load_wallet_data(); - }, - fail: (res) => { - console.log("微信转账失败:", res); - }, - }); + } + } } const handlePasswordInput = (e: any) => { const value = e.detail.value; @@ -179,29 +207,8 @@ const Withdrawal: React.FC = () => { setPassword([one, two, three, four, five, six]); if (value.length === 6) { const timer = setTimeout(() => { - // TODO 校验密码 - if (false) { - set_show_withdraw_popup(false); - Taro.showModal({ - content: "支付密码错误,请重试", - cancelText: "忘记密码", - confirmText: "重试", - cancelColor: "#000", - confirmColor: "#fff", - }).then((res) => { - if (res.confirm) { - set_show_withdraw_popup(true); - } else if (res.cancel) { - Taro.navigateTo({ - url: "/user_pages/validPhone/index" - }); - } - }).finally(() => { - clearTimeout(timer); - }); - } else { - submit_withdraw(); - } + submit_withdraw(value); + clearTimeout(timer); }, 100); } } @@ -253,7 +260,7 @@ const Withdrawal: React.FC = () => { 4. 用户在使用提现服务前,应充分了解并同意上述规则。 - + {/* 提现输入密码弹窗 */}