1
This commit is contained in:
@@ -293,7 +293,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { listOrderrows, getOrderrows, delOrderrows, addOrderrows, updateOrderrows, getValidCodeSelectData } from "@/api/system/orderrows";
|
import { listOrderrows, getOrderrows, delOrderrows, addOrderrows, updateOrderrows, getValidCodeSelectData, getOrderStatistics } from "@/api/system/orderrows";
|
||||||
import { getAdminSelectData } from "@/api/system/superadmin";
|
import { getAdminSelectData } from "@/api/system/superadmin";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -382,14 +382,106 @@ export default {
|
|||||||
this.orderrowsList = response.rows;
|
this.orderrowsList = response.rows;
|
||||||
this.total = response.total;
|
this.total = response.total;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
// 计算统计数据
|
// 调用后端统计接口计算统计数据
|
||||||
this.calculateStatistics();
|
this.loadStatistics();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('获取订单列表失败:', error);
|
console.error('获取订单列表失败:', error);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.$message.error('获取订单列表失败');
|
this.$message.error('获取订单列表失败');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/** 加载统计数据(从后端获取) */
|
||||||
|
loadStatistics() {
|
||||||
|
// 构建统计查询参数,使用与列表查询相同的条件
|
||||||
|
const statParams = {
|
||||||
|
...this.queryParams,
|
||||||
|
beginTime: this.dateRange && this.dateRange.length > 0 ? this.dateRange[0] : null,
|
||||||
|
endTime: this.dateRange && this.dateRange.length > 1 ? this.dateRange[1] : null
|
||||||
|
};
|
||||||
|
|
||||||
|
getOrderStatistics(statParams).then(response => {
|
||||||
|
const data = response.data || {};
|
||||||
|
const groupStats = data.groupStats || {};
|
||||||
|
|
||||||
|
// 转换后端返回的统计格式为前端需要的格式
|
||||||
|
this.statistics = {
|
||||||
|
totalOrders: data.totalOrders || 0,
|
||||||
|
totalCosPrice: 0, // 后端没有返回此字段,如果需要可以前端计算或后端添加
|
||||||
|
totalEstimateFee: data.totalCommission || 0,
|
||||||
|
totalActualFee: data.totalActualFee || 0,
|
||||||
|
statusStats: {
|
||||||
|
cancel: this.convertGroupStat(groupStats.cancel),
|
||||||
|
invalid: this.convertGroupStat(groupStats.invalid),
|
||||||
|
pending: this.convertGroupStat(groupStats.pending),
|
||||||
|
paid: this.convertGroupStat(groupStats.paid),
|
||||||
|
finished: this.convertGroupStat(groupStats.finished),
|
||||||
|
deposit: this.convertGroupStat(groupStats.deposit),
|
||||||
|
illegal: this.convertGroupStat(groupStats.illegal)
|
||||||
|
},
|
||||||
|
accountStats: {} // 后端没有按账号统计,保留为空或后续添加
|
||||||
|
};
|
||||||
|
|
||||||
|
// 如果有订单列表,计算总计佣金额和按账号统计(这些前端计算更快)
|
||||||
|
if (this.orderrowsList.length > 0) {
|
||||||
|
let totalCosPrice = 0;
|
||||||
|
const accountStats = {};
|
||||||
|
|
||||||
|
this.orderrowsList.forEach(order => {
|
||||||
|
// 总计佣金额
|
||||||
|
if (order.estimateCosPrice) {
|
||||||
|
totalCosPrice += parseFloat(order.estimateCosPrice) || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按账号统计
|
||||||
|
const unionId = order.unionId;
|
||||||
|
if (!accountStats[unionId]) {
|
||||||
|
accountStats[unionId] = {
|
||||||
|
count: 0,
|
||||||
|
amount: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
accountStats[unionId].count++;
|
||||||
|
|
||||||
|
// 计算账号佣金金额(使用与后端相同的逻辑)
|
||||||
|
const validCode = String(order.validCode);
|
||||||
|
const isCancel = validCode === '3';
|
||||||
|
const isIllegal = ['25', '26', '27', '28'].includes(validCode);
|
||||||
|
|
||||||
|
let commissionAmount = parseFloat(order.actualFee) || 0;
|
||||||
|
if (isIllegal && order.estimateCosPrice && order.commissionRate) {
|
||||||
|
commissionAmount = parseFloat(order.estimateCosPrice) * parseFloat(order.commissionRate) / 100;
|
||||||
|
} else if (isCancel && (!order.actualFee || parseFloat(order.actualFee) === 0)
|
||||||
|
&& order.estimateCosPrice && order.commissionRate) {
|
||||||
|
commissionAmount = parseFloat(order.estimateCosPrice) * parseFloat(order.commissionRate) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
accountStats[unionId].amount += commissionAmount;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.statistics.totalCosPrice = totalCosPrice;
|
||||||
|
this.statistics.accountStats = accountStats;
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('获取统计数据失败:', error);
|
||||||
|
// 如果后端统计失败,回退到前端计算
|
||||||
|
this.calculateStatistics();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/** 转换后端分组统计格式 */
|
||||||
|
convertGroupStat(groupStat) {
|
||||||
|
if (!groupStat) {
|
||||||
|
return {
|
||||||
|
label: '',
|
||||||
|
count: 0,
|
||||||
|
amount: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
label: groupStat.label || '',
|
||||||
|
count: groupStat.count || 0,
|
||||||
|
amount: groupStat.actualFee || 0 // 使用actualFee作为金额
|
||||||
|
};
|
||||||
|
},
|
||||||
/** 获取管理员列表 */
|
/** 获取管理员列表 */
|
||||||
getAdminList() {
|
getAdminList() {
|
||||||
getAdminSelectData().then(response => {
|
getAdminSelectData().then(response => {
|
||||||
@@ -686,13 +778,31 @@ export default {
|
|||||||
if (order.estimateFee) {
|
if (order.estimateFee) {
|
||||||
stats.totalEstimateFee += parseFloat(order.estimateFee) || 0;
|
stats.totalEstimateFee += parseFloat(order.estimateFee) || 0;
|
||||||
}
|
}
|
||||||
// 实际佣金
|
|
||||||
if (order.actualFee) {
|
// 计算实际佣金或预估佣金
|
||||||
stats.totalActualFee += parseFloat(order.actualFee) || 0;
|
// 对于违规订单(25,26,27,28),始终使用 estimateCosPrice * commissionRate / 100 计算
|
||||||
|
// 对于取消订单(3),如果actualFee为空或0,则通过公式计算
|
||||||
|
const validCode = String(order.validCode);
|
||||||
|
const isCancel = validCode === '3'; // 取消订单
|
||||||
|
const isIllegal = ['25', '26', '27', '28'].includes(validCode); // 违规订单
|
||||||
|
|
||||||
|
let commissionAmount = parseFloat(order.actualFee) || 0;
|
||||||
|
const estimateCosPrice = parseFloat(order.estimateCosPrice) || 0;
|
||||||
|
const commissionRate = parseFloat(order.commissionRate) || 0;
|
||||||
|
|
||||||
|
// 违规订单始终使用公式计算佣金
|
||||||
|
if (isIllegal && estimateCosPrice > 0 && commissionRate > 0) {
|
||||||
|
commissionAmount = estimateCosPrice * commissionRate / 100;
|
||||||
}
|
}
|
||||||
|
// 取消订单:如果actualFee为空或0,则通过公式计算
|
||||||
|
else if (isCancel && (!order.actualFee || parseFloat(order.actualFee) === 0) && estimateCosPrice > 0 && commissionRate > 0) {
|
||||||
|
commissionAmount = estimateCosPrice * commissionRate / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 实际佣金累计(包含计算出的违规和取消订单佣金)
|
||||||
|
stats.totalActualFee += commissionAmount;
|
||||||
|
|
||||||
// 按状态统计
|
// 按状态统计
|
||||||
const validCode = String(order.validCode);
|
|
||||||
let statusKey = 'invalid'; // 默认无效
|
let statusKey = 'invalid'; // 默认无效
|
||||||
for (const [key, group] of Object.entries(statusGroups)) {
|
for (const [key, group] of Object.entries(statusGroups)) {
|
||||||
if (group.codes.includes(validCode)) {
|
if (group.codes.includes(validCode)) {
|
||||||
@@ -701,7 +811,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stats.statusStats[statusKey].count++;
|
stats.statusStats[statusKey].count++;
|
||||||
stats.statusStats[statusKey].amount += parseFloat(order.actualFee) || 0;
|
stats.statusStats[statusKey].amount += commissionAmount;
|
||||||
|
|
||||||
// 按账号统计
|
// 按账号统计
|
||||||
const unionId = order.unionId;
|
const unionId = order.unionId;
|
||||||
@@ -712,7 +822,7 @@ export default {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
stats.accountStats[unionId].count++;
|
stats.accountStats[unionId].count++;
|
||||||
stats.accountStats[unionId].amount += parseFloat(order.actualFee) || 0;
|
stats.accountStats[unionId].amount += commissionAmount;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.statistics = stats;
|
this.statistics = stats;
|
||||||
|
|||||||
Reference in New Issue
Block a user