forked from gxwebsoft/mp-10550
feat(withdraw): 添加分销商提现领取功能
- 新增 receiveShopDealerWithdraw 接口用于用户领取提现 - 新增 receiveSuccessShopDealerWithdraw 接口用于领取成功回调 - 添加 ShopDealerWithdrawReceiveResult 类型定义 - 实现提取 package_info 的 extractPackageInfo 函数 - 更新提现列表页面的领取按钮样式 - 完善领取流程的状态处理和错误提示机制
This commit is contained in:
@@ -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<S
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分销商提现明细表
|
||||
*/
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
} 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 && (
|
||||
<View className="flex justify-center">
|
||||
<View className="flex mb-5 justify-center">
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
|
||||
Reference in New Issue
Block a user