提现错误弹窗

This commit is contained in:
2025-09-29 22:43:17 +08:00
parent 9b6e3e15d0
commit 276e7dfee0
5 changed files with 121 additions and 127 deletions

View File

@@ -31,7 +31,7 @@ export const API_CONFIG = {
LEAVE: '/game/leave' LEAVE: '/game/leave'
}, },
PROFESSIONS: '/professions/tree', PROFESSIONS: '/professions/tree',
CITIS: '/admin/wch_cities/page' CITIS: '/cities/tree'
}; };
// 请求拦截器配置 // 请求拦截器配置

View File

@@ -105,7 +105,7 @@ class HttpService {
} }
// 处理响应 // 处理响应
private handleResponse<T>(response: any): Promise<ApiResponse<T>> { private handleResponse<T>(response: any, showToast: boolean): Promise<ApiResponse<T>> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const { statusCode, data } = response const { statusCode, data } = response
@@ -121,8 +121,12 @@ class HttpService {
// 业务状态码检查 // 业务状态码检查
if (data && typeof data === 'object') { if (data && typeof data === 'object') {
if (data.success === false || (data.code && data.code !== 0 && data.code !== 200)) { if (data.success === false || (data.code && data.code !== 0 && data.code !== 200)) {
this.handleBusinessError(data) if (showToast) {
reject(new Error(data.message || '请求失败')) this.handleBusinessError(data)
reject(new Error(data.message || '请求失败'))
} else {
reject(response.data)
}
return return
} }
} }
@@ -191,7 +195,8 @@ class HttpService {
data, data,
params, params,
showLoading = false, showLoading = false,
loadingText = '请求中...' loadingText = '请求中...',
showToast = true,
} = config } = config
let fullUrl = this.buildUrl(url, method === 'GET' ? params : undefined) let fullUrl = this.buildUrl(url, method === 'GET' ? params : undefined)
@@ -238,11 +243,12 @@ class HttpService {
method: method, method: method,
data: method !== 'GET' ? data : undefined, data: method !== 'GET' ? data : undefined,
header: reqHeader, header: reqHeader,
timeout: this.timeout timeout: this.timeout,
showToast,
} }
const response = await Taro.request(requestConfig) const response = await Taro.request(requestConfig)
return this.handleResponse<T>(response) return this.handleResponse<T>(response, showToast)
} catch (error) { } catch (error) {
this.log('error', '请求失败', error) this.log('error', '请求失败', error)
@@ -304,9 +310,9 @@ class HttpService {
} }
uploadFile(){ uploadFile() {
} }
// PUT请求 // PUT请求

View File

@@ -43,38 +43,19 @@ const SetTransactionPassword: React.FC = () => {
}); });
return; return;
} }
if (handleType === "set") { try {
const { sms_code } = formData; await httpService.post("/wallet/set_payment_password", { password: new_password });
try { Taro.showToast({
await httpService.post("/wallet/set_payment_password", { password: new_password, sms_code }); title: "设置交易密码成功",
Taro.showToast({ icon: "success",
title: "设置交易密码成功", });
icon: "success", Taro.navigateBack();
}); } catch (error) {
Taro.navigateBack(); Taro.showToast({
} catch (error) { title: "设置交易密码失败",
Taro.showToast({ icon: "none",
title: "设置交易密码失败", });
icon: "none", return;
});
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;
}
} }
}; };

View File

@@ -267,7 +267,7 @@ const WalletPage: React.FC = () => {
// 处理提现 // 处理提现
const handle_withdraw = () => { const handle_withdraw = () => {
if (password_status) { if (!password_status) {
navigateToSetTransactionPassword("set"); navigateToSetTransactionPassword("set");
return; return;
} }

View File

@@ -27,19 +27,11 @@ const Withdrawal: React.FC = () => {
const [password, setPassword] = useState<string[]>(new Array(6).fill("")); const [password, setPassword] = useState<string[]>(new Array(6).fill(""));
const toastConfig = { const [mapErrorCodes, setMapErrorCodes] = useState({});
aa: {
title: "已超单日限额",
content: "您今日提现已超过支付通道2000元单日限额建议您明日再发起提现资金仍安全存放在钱包余额中。"
},
bb: {
title: "已超单日限额",
content: "今日提现通道额度已用完,暂时无法提现;您的余额安全存放在钱包中,我们会在 次日0点恢复 提现服务;如有紧急情况,请联系客服。"
}
}
useDidShow(() => { useDidShow(() => {
load_wallet_data(); load_wallet_data();
getWithdrawErrorCodes();
}); });
useEffect(() => { 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 () => { 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); set_show_withdraw_popup(true);
}; };
const submit_withdraw = async () => { const submit_withdraw = async (payment_password: string) => {
// 先调用后端接口获取提现参数 try {
const response = await httpService.post("/wallet/withdraw", { // 先调用后端接口获取提现参数
amount: parseFloat(inputValue), const response = await httpService.post("/wallet/withdraw", {
transfer_remark: "用户申请提现", amount: parseFloat(inputValue),
}); transfer_remark: "用户申请提现",
payment_password,
}, { showToast: false });
const { data } = response;
// 根据后端返回的数据结构解析参数
const { mch_id, app_id, package_info, open_id } = data;
// 根据后端返回的数据结构解析参数 console.log("/wallet/withdraw:", data);
const { mch_id, app_id, package_info, open_id } = response.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({ set_show_withdraw_popup(false);
mchId: mch_id, setInputValue("0.00");
appId: app_id, // 重新加载数据
package: package_info, load_wallet_data();
openId: open_id, },
success: (res) => { fail: (res) => {
console.log("微信转账成功:", 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({ Taro.showToast({
title: "提现成功", title: message,
icon: "success", icon: "none",
duration: 2000, duration: 2000,
}); });
}
// 关闭弹窗并重置状态 }
set_show_withdraw_popup(false);
setInputValue("0.00");
// 重新加载数据
load_wallet_data();
},
fail: (res) => {
console.log("微信转账失败:", res);
},
});
} }
const handlePasswordInput = (e: any) => { const handlePasswordInput = (e: any) => {
const value = e.detail.value; const value = e.detail.value;
@@ -179,29 +207,8 @@ const Withdrawal: React.FC = () => {
setPassword([one, two, three, four, five, six]); setPassword([one, two, three, four, five, six]);
if (value.length === 6) { if (value.length === 6) {
const timer = setTimeout(() => { const timer = setTimeout(() => {
// TODO 校验密码 submit_withdraw(value);
if (false) { clearTimeout(timer);
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();
}
}, 100); }, 100);
} }
} }
@@ -253,7 +260,7 @@ const Withdrawal: React.FC = () => {
<Text>4. 使</Text> <Text>4. 使</Text>
</View> </View>
</View> </View>
{/* 提现输入密码弹窗 */} {/* 提现输入密码弹窗 */}
<CommonPopup <CommonPopup
visible={show_withdraw_popup} visible={show_withdraw_popup}