feat(withdraw): 添加分销商提现领取功能

- 新增 receiveShopDealerWithdraw 接口用于用户领取提现
- 新增 receiveSuccessShopDealerWithdraw 接口用于领取成功回调
- 添加 ShopDealerWithdrawReceiveResult 类型定义
- 实现提取 package_info 的 extractPackageInfo 函数
- 更新提现列表页面的领取按钮样式
- 完善领取流程的状态处理和错误提示机制
This commit is contained in:
2026-01-31 22:24:51 +08:00
parent 3b98dfa150
commit 47d2eee486
2 changed files with 44 additions and 18 deletions

View File

@@ -14,6 +14,9 @@ export type ShopDealerWithdrawCreateResult =
| null | null
| undefined; | 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<S
return Promise.reject(new Error(res.message)); return Promise.reject(new Error(res.message));
} }
/**
* 用户领取(仅当 applyStatus=20 时)- 后台返回 package_info 供小程序调起确认收款页
*/
export async function receiveShopDealerWithdraw(id: number): Promise<ShopDealerWithdrawReceiveResult> {
const res = await request.post<ApiResult<any>>(
'/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<ApiResult<unknown>>(
'/shop/shop-dealer-withdraw/receive-success/' + id,
{}
);
if (res.code === 0) {
return res.message;
}
return Promise.reject(new Error(res.message));
}
/** /**
* 修改分销商提现明细表 * 修改分销商提现明细表
*/ */

View File

@@ -19,8 +19,8 @@ import {useDealerUser} from '@/hooks/useDealerUser'
import { import {
pageShopDealerWithdraw, pageShopDealerWithdraw,
addShopDealerWithdraw, addShopDealerWithdraw,
getShopDealerWithdraw, receiveShopDealerWithdraw,
updateShopDealerWithdraw receiveSuccessShopDealerWithdraw
} from '@/api/shop/shopDealerWithdraw' } from '@/api/shop/shopDealerWithdraw'
import type {ShopDealerWithdraw} from '@/api/shop/shopDealerWithdraw/model' import type {ShopDealerWithdraw} from '@/api/shop/shopDealerWithdraw/model'
@@ -33,6 +33,7 @@ interface WithdrawRecordWithDetails extends ShopDealerWithdraw {
} }
const extractPackageInfo = (result: unknown): string | null => { const extractPackageInfo = (result: unknown): string | null => {
if (typeof result === 'string') return result
if (!result || typeof result !== 'object') return null if (!result || typeof result !== 'object') return null
const r = result as any const r = result as any
return ( return (
@@ -315,13 +316,8 @@ const DealerWithdraw: React.FC = () => {
throw new Error('当前环境不支持微信收款确认,请在微信小程序内操作') throw new Error('当前环境不支持微信收款确认,请在微信小程序内操作')
} }
// Prefer getting package from the list record; if missing, query detail. const receiveResult = await receiveShopDealerWithdraw(record.id)
let packageInfo = extractPackageInfo(record as any) const packageInfo = extractPackageInfo(receiveResult)
if (!packageInfo) {
const detail = await getShopDealerWithdraw(record.id)
packageInfo = extractPackageInfo(detail as any)
}
if (!packageInfo) { if (!packageInfo) {
throw new Error('后台未返回 package_info无法领取请联系管理员') throw new Error('后台未返回 package_info无法领取请联系管理员')
} }
@@ -337,16 +333,15 @@ const DealerWithdraw: React.FC = () => {
throw new Error(msg || '领取失败,请稍后重试') throw new Error(msg || '领取失败,请稍后重试')
} }
// Best-effort: ask backend to mark as "已到账".
try { try {
await updateShopDealerWithdraw({id: record.id, applyStatus: 40} as any) await receiveSuccessShopDealerWithdraw(record.id)
} catch (e) { Taro.showToast({title: '领取成功', icon: 'success'})
// Backend may enforce state transitions; still refresh to reflect backend truth. } catch (e: any) {
console.warn('更新提现状态失败:', e) console.warn('领取成功,但状态同步失败:', e)
Taro.showToast({title: '已收款,状态更新失败,请稍后刷新', icon: 'none'})
} finally {
await handleRefresh()
} }
Taro.showToast({title: '领取成功', icon: 'success'})
await handleRefresh()
} catch (e: any) { } catch (e: any) {
console.error('领取失败:', e) console.error('领取失败:', e)
Taro.showToast({title: e?.message || '领取失败', icon: 'error'}) Taro.showToast({title: e?.message || '领取失败', icon: 'error'})
@@ -496,7 +491,7 @@ const DealerWithdraw: React.FC = () => {
{record.applyStatus === 20 && record.payType === 10 && ( {record.applyStatus === 20 && record.payType === 10 && (
<View className="flex justify-center"> <View className="flex mb-5 justify-center">
<Button <Button
size="small" size="small"
type="primary" type="primary"