fix(分润管理):前端功能实现,统计功能实现

This commit is contained in:
2025-04-15 11:40:49 +08:00
parent 10b35d21f9
commit 87a8778ce2
17 changed files with 743 additions and 25 deletions
@@ -9,43 +9,43 @@
export default {
dev: {
'/api-uaa/': {
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-user/': {
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-log/': {
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-search/': {
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-generator/': {
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-file/': {
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-order/': {
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-device/': {
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
},
@@ -103,7 +103,15 @@
{
path: '/orders/statistics.html',
component: './orders/statistics',
}
},
{
path: '/orders/profitSharing.html',
component: './orders/ProfitSharing',
},
{
path: '/orders/profit-sharing/statistics.html',
component: './orders/ProfitSharing/Statistics',
},
],
},
{
@@ -0,0 +1,106 @@
import { PageContainer, ProDescriptions } from '@ant-design/pro-components';
import { Card, Divider, Button, message } from 'antd';
import React, { useEffect, useState } from 'react';
import { useParams, history } from 'umi';
import { getProfitSharingDetail, executeProfitSharing } from '@/services/orders/api';
const ProfitSharingDetail: React.FC = () => {
const { orderNo } = useParams<{ orderNo: string }>();
const [loading, setLoading] = useState(false);
const [detail, setDetail] = useState<ORDERS.ProfitSharing>();
const fetchDetail = async () => {
setLoading(true);
try {
const result = await getProfitSharingDetail(orderNo);
if (result.resp_code === 0) {
setDetail(result.data);
}
} catch (error) {
message.error('获取详情失败');
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchDetail();
}, [orderNo]);
const handleExecute = async () => {
try {
const result = await executeProfitSharing(orderNo);
if (result.resp_code === 0) {
message.success('分账执行成功');
fetchDetail();
} else {
message.error(result.resp_msg || '分账执行失败');
}
} catch (error) {
message.error('分账执行失败');
}
};
return (
<PageContainer
onBack={() => history.goBack()}
extra={
detail?.status === 3 && detail?.retryTimes < 3 && (
<Button type="primary" onClick={handleExecute}>
重试分账
</Button>
)
}
>
<Card loading={loading}>
<ProDescriptions
column={2}
title="订单信息"
>
<ProDescriptions.Item label="订单编号">{detail?.orderNo}</ProDescriptions.Item>
<ProDescriptions.Item label="微信支付订单号">{detail?.transactionId}</ProDescriptions.Item>
<ProDescriptions.Item label="订单总额">
¥{detail?.totalAmount ? (detail.totalAmount / 100).toFixed(2) : '-'}
</ProDescriptions.Item>
<ProDescriptions.Item label="创建时间">{detail?.createTime}</ProDescriptions.Item>
</ProDescriptions>
<Divider />
<ProDescriptions
column={2}
title="分账信息"
>
<ProDescriptions.Item label="分账状态">
{STATUS_MAP[detail?.status]?.text}
</ProDescriptions.Item>
<ProDescriptions.Item label="分账单号">{detail?.profitSharingId}</ProDescriptions.Item>
<ProDescriptions.Item label="平台分账金额">
¥{detail?.platformAmount ? (detail.platformAmount / 100).toFixed(2) : '-'}
</ProDescriptions.Item>
<ProDescriptions.Item label="二维码分账金额">
¥{detail?.qrCodeAmount ? (detail.qrCodeAmount / 100).toFixed(2) : '-'}
</ProDescriptions.Item>
<ProDescriptions.Item label="实际分账金额">
¥{detail?.receiverAmount ? (detail.receiverAmount / 100).toFixed(2) : '-'}
</ProDescriptions.Item>
<ProDescriptions.Item label="分账完成时间">{detail?.finishTime}</ProDescriptions.Item>
<ProDescriptions.Item label="分账账号">{detail?.payeeAccount}</ProDescriptions.Item>
<ProDescriptions.Item label="账号类型">
{detail?.payeeType === 'MERCHANT_ID' ? '商户ID' : '个人openid'}
</ProDescriptions.Item>
<ProDescriptions.Item label="分账描述">{detail?.description}</ProDescriptions.Item>
{detail?.status === 3 && (
<ProDescriptions.Item label="失败原因" span={2}>
{detail?.failReason}
</ProDescriptions.Item>
)}
<ProDescriptions.Item label="重试次数">{detail?.retryTimes || 0}</ProDescriptions.Item>
<ProDescriptions.Item label="最后重试时间">{detail?.lastRetryTime}</ProDescriptions.Item>
</ProDescriptions>
</Card>
</PageContainer>
);
};
export default ProfitSharingDetail;
@@ -0,0 +1,35 @@
.chartCard {
margin-top: 24px;
}
.secondRow {
margin-top: 24px;
}
.iconTotal {
color: #1890ff;
font-size: 24px;
}
.iconSuccess {
color: #52c41a;
font-size: 24px;
}
.iconFail {
color: #ff4d4f;
font-size: 24px;
}
.iconAmount {
color: #faad14;
font-size: 24px;
}
:global {
.ant-card {
.ant-card-head {
border-bottom: none;
}
}
}
@@ -0,0 +1,175 @@
import { PageContainer, StatisticCard } from '@ant-design/pro-components';
import { Card, Row, Col, Tabs, DatePicker } from 'antd';
import { Area, Column } from '@ant-design/plots';
import React, { useState, useEffect } from 'react';
import { getProfitSharingStatistics } from '@/services/orders/api';
import styles from './Statistics.less';
import {
TransactionOutlined,
CheckCircleOutlined,
CloseCircleOutlined,
PayCircleOutlined,
} from '@ant-design/icons';
const { Divider } = StatisticCard;
const { RangePicker } = DatePicker;
const Statistics: React.FC = () => {
const [loading, setLoading] = useState(false);
const [timeRange, setTimeRange] = useState<[string, string]>(['', '']);
const [statistics, setStatistics] = useState<any>({});
const [activeTab, setActiveTab] = useState<string>('day');
// 获取统计数据
const fetchStatistics = async () => {
setLoading(true);
try {
const result = await getProfitSharingStatistics({
startTime: timeRange[0],
endTime: timeRange[1],
type: activeTab,
});
if (result.resp_code === 0) {
setStatistics(result.data);
}
} catch (error) {
console.error('获取统计数据失败:', error);
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchStatistics();
}, [timeRange, activeTab]);
// 金额趋势图配置
const amountTrendConfig = {
data: statistics.amountTrend || [],
xField: 'date',
yField: 'amount',
seriesField: 'type',
smooth: true,
animation: true,
legend: {
position: 'top',
},
yAxis: {
label: {
formatter: (val: string) => `¥${(Number(val) / 100).toFixed(2)}`,
},
},
tooltip: {
formatter: (datum: any) => {
return {
name: datum.type,
value: `¥${(datum.amount / 100).toFixed(2)}`,
};
},
},
};
// 成功率统计图配置
const successRateConfig = {
data: statistics.successRate || [],
xField: 'date',
yField: 'value',
seriesField: 'type',
isGroup: true,
columnStyle: {
radius: [4, 4, 0, 0],
},
label: {
position: 'middle',
style: {
fill: '#FFFFFF',
},
},
};
return (
<PageContainer>
{/* 总体统计卡片 */}
<StatisticCard.Group direction="row">
<StatisticCard
statistic={{
title: '总分账笔数',
value: statistics.totalCount || 0,
icon: <TransactionOutlined className={styles.iconTotal} />,
}}
/>
<Divider type="vertical" />
<StatisticCard
statistic={{
title: '成功笔数',
value: statistics.successCount || 0,
icon: <CheckCircleOutlined className={styles.iconSuccess} />,
}}
/>
<Divider type="vertical" />
<StatisticCard
statistic={{
title: '失败笔数',
value: statistics.failCount || 0,
icon: <CloseCircleOutlined className={styles.iconFail} />,
}}
/>
<Divider type="vertical" />
<StatisticCard
statistic={{
title: '总分账金额',
value: statistics.totalAmount ? (statistics.totalAmount / 100).toFixed(2) : '0.00',
prefix: '¥',
icon: <PayCircleOutlined className={styles.iconAmount} />,
}}
/>
</StatisticCard.Group>
{/* 时间维度统计 */}
<Card
className={styles.chartCard}
title="分账统计"
extra={
<RangePicker
onChange={(dates) => {
if (dates) {
setTimeRange([
dates[0]?.format('YYYY-MM-DD') || '',
dates[1]?.format('YYYY-MM-DD') || '',
]);
}
}}
/>
}
>
<Tabs
activeKey={activeTab}
onChange={setActiveTab}
items={[
{ key: 'day', label: '日统计' },
{ key: 'week', label: '周统计' },
{ key: 'month', label: '月统计' },
]}
/>
<Row gutter={24}>
<Col span={24}>
<Card title="分账金额趋势" loading={loading}>
<Area {...amountTrendConfig} height={300} />
</Card>
</Col>
</Row>
<Row gutter={24} className={styles.secondRow}>
<Col span={24}>
<Card title="分账成功率统计" loading={loading}>
<Column {...successRateConfig} height={300} />
</Card>
</Col>
</Row>
</Card>
</PageContainer>
);
};
export default Statistics;
@@ -3,9 +3,10 @@ import {
ProForm,
ProFormSelect,
ProFormText,
ProFormDigit,
} from '@ant-design/pro-components';
import React, { useEffect } from 'react';
import { STATUS_OPTIONS } from '../index';
import { STATUS_OPTIONS, PAYEE_TYPE_OPTIONS } from '../index';
export type UpdateFormProps = {
onSubmit: (values: ORDERS.Qrcode) => Promise<void>;
@@ -105,6 +106,46 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
rules={[{ required: true, message: '请选择状态' }]}
/>
</ProForm.Group>
<ProForm.Group title="分账配置">
<ProFormText
width="md"
name="payeeAccount"
label="分账账号"
placeholder="请输入分账接收账号"
rules={[{ required: true, message: '请输入分账账号' }]}
/>
<ProFormSelect
width="md"
name="payeeType"
label="账号类型"
options={PAYEE_TYPE_OPTIONS}
rules={[{ required: true, message: '请选择账号类型' }]}
/>
<ProFormDigit
width="md"
name="profitRate"
label="分账比例"
min={0}
max={100}
fieldProps={{
precision: 2,
suffix: '%',
}}
rules={[
{ required: true, message: '请输入分账比例' },
{ type: 'number', min: 0, max: 100, message: '比例必须在0-100之间' },
]}
/>
{values?.payeeStatus === 2 && (
<ProFormText
width="md"
name="payeeFailReason"
label="验证失败原因"
disabled
/>
)}
</ProForm.Group>
</ModalForm>
);
};
@@ -20,3 +20,26 @@
.query-filter {
margin-bottom: 16px;
}
.ant-form {
.ant-form-item-group-title {
font-weight: 500;
font-size: 16px;
margin-bottom: 16px;
color: rgba(0, 0, 0, 0.85);
border-bottom: 1px solid #f0f0f0;
padding-bottom: 8px;
}
}
.payee-status {
&-0 {
color: #d9d9d9;
}
&-1 {
color: #52c41a;
}
&-2 {
color: #ff4d4f;
}
}
@@ -7,8 +7,10 @@ import {
ProForm,
ProFormSelect,
ProFormText,
ProFormDigit,
ProTable,
QueryFilter,
Tooltip,
} from '@ant-design/pro-components';
import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd';
import React, { useRef, useState, useCallback, useEffect } from 'react';
@@ -28,6 +30,19 @@ export const DEVICE_OPTIONS = [
{ label: '5YSZMBS0030BJ8', value: '5YSZMBS0030BJ8' },
] as const;
// 添加账号类型常量
export const PAYEE_TYPE_OPTIONS = [
{ label: '商户ID', value: 'MERCHANT_ID' },
{ label: '个人openid', value: 'PERSONAL_OPENID' },
] as const;
// 添加账号状态常量
export const PAYEE_STATUS_OPTIONS = [
{ label: '未验证', value: 0 },
{ label: '已验证', value: 1 },
{ label: '验证失败', value: 2 },
] as const;
const handleApiRequest = async (
apiCall: () => Promise<any>,
loadingMessage: string,
@@ -267,6 +282,47 @@ const TableList: React.FC = () => {
width: 80,
render: (status) => renderStatus(status),
},
{
title: '分账账号',
dataIndex: 'payeeAccount',
width: 140,
ellipsis: true,
},
{
title: '账号类型',
dataIndex: 'payeeType',
width: 100,
valueEnum: {
'MERCHANT_ID': { text: '商户ID' },
'PERSONAL_OPENID': { text: '个人openid' },
},
},
{
title: '分账比例',
dataIndex: 'profitRate',
width: 100,
render: (val) => val ? `${val}%` : '-',
},
{
title: '验证状态',
dataIndex: 'payeeStatus',
width: 100,
render: (status, record) => {
const statusMap = {
0: { color: 'default', text: '未验证' },
1: { color: 'success', text: '已验证' },
2: { color: 'error', text: '验证失败' },
};
const { color, text } = statusMap[status] || statusMap[0];
return record.payeeFailReason ? (
<Tooltip title={record.payeeFailReason}>
<Tag color={color}>{text}</Tag>
</Tooltip>
) : (
<Tag color={color}>{text}</Tag>
);
},
},
{
title: '创建时间',
dataIndex: 'createTime',
@@ -447,6 +503,38 @@ const TableList: React.FC = () => {
rules={[{ required: true, message: '请选择状态' }]}
/>
</ProForm.Group>
<ProForm.Group title="分账配置">
<ProFormText
width="md"
name="payeeAccount"
label="分账账号"
placeholder="请输入分账接收账号"
rules={[{ required: true, message: '请输入分账账号' }]}
/>
<ProFormSelect
width="md"
name="payeeType"
label="账号类型"
options={PAYEE_TYPE_OPTIONS}
rules={[{ required: true, message: '请选择账号类型' }]}
/>
<ProFormDigit
width="md"
name="profitRate"
label="分账比例"
min={0}
max={100}
fieldProps={{
precision: 2,
suffix: '%',
}}
rules={[
{ required: true, message: '请输入分账比例' },
{ type: 'number', min: 0, max: 100, message: '比例必须在0-100之间' },
]}
/>
</ProForm.Group>
</ModalForm>
<UpdateForm
onSubmit={async (values) => {
@@ -179,3 +179,41 @@ export async function dashboard() {
});
}
/** 分页查询分账记录 */
export async function profitSharingList(params: {
page: number;
limit: number;
[key: string]: any;
}) {
return request('/api-order/profitSharing/list', {
method: 'GET',
params,
});
}
/** 获取分账记录详情 */
export async function getProfitSharingDetail(orderNo: string) {
return request(`/api-order/profitSharing/${orderNo}`, {
method: 'GET',
});
}
/** 执行分账 */
export async function executeProfitSharing(orderNo: string) {
return request(`/api-order/profitSharing/execute/${orderNo}`, {
method: 'POST',
});
}
/** 获取分账统计数据 */
export async function getProfitSharingStatistics(params: {
startTime?: string;
endTime?: string;
type: 'day' | 'week' | 'month';
}) {
return request('/api-order/profitSharing/statistics', {
method: 'GET',
params,
});
}
@@ -64,6 +64,11 @@ declare namespace ORDERS {
status: number;
tenantId?: string;
updateTime?: string;
payeeAccount?: string;
payeeType?: 'MERCHANT_ID' | 'PERSONAL_OPENID';
profitRate?: number;
payeeStatus?: number;
payeeFailReason?: string;
}
type HomeCarousel = {
@@ -138,6 +143,30 @@ declare namespace ORDERS {
value: number;
}>;
}
interface ProfitSharing {
id: number;
orderId: string;
orderNo: string;
transactionId: string;
profitSharingId: string;
totalAmount: number;
platformAmount: number;
qrCodeAmount: number;
status: number;
codeId: string;
payeeAccount: string;
payeeType: string;
description: string;
failReason: string;
receiverAmount: number;
finishTime: string;
outOrderNo: string;
retryTimes: number;
lastRetryTime: string;
createTime: string;
updateTime: string;
}
}
declare namespace API {