From 47d2eee486e770a4b5b1202e1a94172b0de9f7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sat, 31 Jan 2026 22:24:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(withdraw):=20=E6=B7=BB=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E9=94=80=E5=95=86=E6=8F=90=E7=8E=B0=E9=A2=86=E5=8F=96=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 receiveShopDealerWithdraw 接口用于用户领取提现 - 新增 receiveSuccessShopDealerWithdraw 接口用于领取成功回调 - 添加 ShopDealerWithdrawReceiveResult 类型定义 - 实现提取 package_info 的 extractPackageInfo 函数 - 更新提现列表页面的领取按钮样式 - 完善领取流程的状态处理和错误提示机制 --- src/api/shop/shopDealerWithdraw/index.ts | 31 ++++++++++++++++++++++++ src/dealer/withdraw/index.tsx | 31 ++++++++++-------------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/api/shop/shopDealerWithdraw/index.ts b/src/api/shop/shopDealerWithdraw/index.ts index 70ebfdb..398b9be 100644 --- a/src/api/shop/shopDealerWithdraw/index.ts +++ b/src/api/shop/shopDealerWithdraw/index.ts @@ -14,6 +14,9 @@ export type ShopDealerWithdrawCreateResult = | null | undefined; +// When applyStatus=20, user can "receive" (WeChat confirm receipt flow). +export type ShopDealerWithdrawReceiveResult = ShopDealerWithdrawCreateResult; + /** * 分页查询分销商提现明细表 */ @@ -57,6 +60,34 @@ export async function addShopDealerWithdraw(data: ShopDealerWithdraw): Promise { + const res = await request.post>( + '/shop/shop-dealer-withdraw/receive/' + id, + {} + ); + if (res.code === 0) { + return res.data ?? res.message; + } + return Promise.reject(new Error(res.message)); +} + +/** + * 领取成功回调:前端确认收款后通知后台把状态置为 applyStatus=40 + */ +export async function receiveSuccessShopDealerWithdraw(id: number) { + const res = await request.post>( + '/shop/shop-dealer-withdraw/receive-success/' + id, + {} + ); + if (res.code === 0) { + return res.message; + } + return Promise.reject(new Error(res.message)); +} + /** * 修改分销商提现明细表 */ diff --git a/src/dealer/withdraw/index.tsx b/src/dealer/withdraw/index.tsx index 1a08079..84f5e14 100644 --- a/src/dealer/withdraw/index.tsx +++ b/src/dealer/withdraw/index.tsx @@ -19,8 +19,8 @@ import {useDealerUser} from '@/hooks/useDealerUser' import { pageShopDealerWithdraw, addShopDealerWithdraw, - getShopDealerWithdraw, - updateShopDealerWithdraw + receiveShopDealerWithdraw, + receiveSuccessShopDealerWithdraw } from '@/api/shop/shopDealerWithdraw' import type {ShopDealerWithdraw} from '@/api/shop/shopDealerWithdraw/model' @@ -33,6 +33,7 @@ interface WithdrawRecordWithDetails extends ShopDealerWithdraw { } const extractPackageInfo = (result: unknown): string | null => { + if (typeof result === 'string') return result if (!result || typeof result !== 'object') return null const r = result as any return ( @@ -315,13 +316,8 @@ const DealerWithdraw: React.FC = () => { throw new Error('当前环境不支持微信收款确认,请在微信小程序内操作') } - // Prefer getting package from the list record; if missing, query detail. - let packageInfo = extractPackageInfo(record as any) - if (!packageInfo) { - const detail = await getShopDealerWithdraw(record.id) - packageInfo = extractPackageInfo(detail as any) - } - + const receiveResult = await receiveShopDealerWithdraw(record.id) + const packageInfo = extractPackageInfo(receiveResult) if (!packageInfo) { throw new Error('后台未返回 package_info,无法领取,请联系管理员') } @@ -337,16 +333,15 @@ const DealerWithdraw: React.FC = () => { throw new Error(msg || '领取失败,请稍后重试') } - // Best-effort: ask backend to mark as "已到账". try { - await updateShopDealerWithdraw({id: record.id, applyStatus: 40} as any) - } catch (e) { - // Backend may enforce state transitions; still refresh to reflect backend truth. - console.warn('更新提现状态失败:', e) + await receiveSuccessShopDealerWithdraw(record.id) + Taro.showToast({title: '领取成功', icon: 'success'}) + } catch (e: any) { + console.warn('领取成功,但状态同步失败:', e) + Taro.showToast({title: '已收款,状态更新失败,请稍后刷新', icon: 'none'}) + } finally { + await handleRefresh() } - - Taro.showToast({title: '领取成功', icon: 'success'}) - await handleRefresh() } catch (e: any) { console.error('领取失败:', e) Taro.showToast({title: e?.message || '领取失败', icon: 'error'}) @@ -496,7 +491,7 @@ const DealerWithdraw: React.FC = () => { {record.applyStatus === 20 && record.payType === 10 && ( - +