add assistant_performance

新增医助个人业绩
执行:add_assistant_performance_menu.sql
This commit is contained in:
2026-05-19 14:41:14 +08:00
parent 9208e7eaaa
commit 1cb00e9fbe
5 changed files with 421 additions and 0 deletions
+9
View File
@@ -179,3 +179,12 @@ export function commissionSettlementConfirmFinalize(params: Record<string, any>)
export function commissionSettlementConfirmRevoke(params: Record<string, any>) {
return request.post({ url: '/stats.commissionSettlement/confirmRevoke', params })
}
/** 医助个人业绩概览 */
export function assistantPerformanceOverview(params: {
time_type?: string
start_date?: string
end_date?: string
}) {
return request.get({ url: '/stats.assistantPerformance/overview', params })
}
@@ -0,0 +1,273 @@
<template>
<div class="assistant-performance-page">
<el-card class="!border-none" shadow="never">
<el-form :inline="true" class="stats-filter-form">
<el-form-item label="时间范围">
<el-radio-group v-model="queryParams.time_type" @change="handleTimeTypeChange">
<el-radio-button label="today">今天</el-radio-button>
<el-radio-button label="yesterday">昨天</el-radio-button>
<el-radio-button label="week">最近7天</el-radio-button>
<el-radio-button label="month">最近30天</el-radio-button>
<el-radio-button label="custom">自定义</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-if="queryParams.time_type === 'custom'">
<el-date-picker
v-model="dateRange"
type="daterange"
value-format="YYYY-MM-DD"
range-separator=""
start-placeholder="开始日期"
end-placeholder="结束日期"
style="width: 260px"
@change="handleCustomDateChange"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" :loading="loading" @click="fetchData">查询</el-button>
<el-button @click="handleReset">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<div class="stats-kpi-grid">
<div v-for="card in summaryCards" :key="card.key" class="stats-kpi-card" :class="card.cardClass">
<div class="stats-kpi-label">{{ card.label }}</div>
<div class="stats-kpi-value" :class="{ 'is-money': card.type === 'money' }">
{{ formatValue(card.key, card.type) }}
</div>
</div>
</div>
<el-card class="!border-none mt-4" shadow="never">
<template #header>
<div class="card-header">
<span class="card-title">业绩趋势</span>
<span class="card-hint">{{ dateRangeText }} · 履约完成业绩</span>
</div>
</template>
<v-charts
v-if="chartHasData"
class="stats-chart"
:option="chartOption"
autoresize
/>
<el-empty v-else description="暂无数据" />
</el-card>
</div>
</template>
<script setup lang="ts" name="assistantPerformancePage">
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import vCharts from 'vue-echarts'
import { assistantPerformanceOverview } from '@/api/stats'
const loading = ref(false)
const dateRange = ref<string[]>([])
const queryParams = reactive({
time_type: 'month',
start_date: '',
end_date: ''
})
const overview = reactive<Record<string, any>>({
date_range: [],
summary: {
total_amount: 0,
total_count: 0
},
chart: {
dates: [],
amounts: [],
counts: []
}
})
const summaryCards = [
{ key: 'total_amount', label: '业绩', type: 'money', cardClass: '' },
{ key: 'total_count', label: '有效订单数', type: 'count', cardClass: '' }
]
const dateRangeText = computed(() => {
if (!overview.date_range?.length) return '未选择'
return `${overview.date_range[0]}${overview.date_range[1]}`
})
const chartHasData = computed(() => {
return overview.chart.dates.length > 0 && overview.chart.amounts.some((v: number) => v > 0)
})
const chartOption = computed(() => ({
tooltip: {
trigger: 'axis',
formatter: (params: any) => {
const p = params[0]
return `${p.axisValue}<br/>${p.marker}${p.seriesName}: ¥${Number(p.value).toFixed(2)}`
}
},
grid: { left: 60, right: 24, top: 36, bottom: 36 },
xAxis: {
type: 'category',
data: overview.chart.dates,
axisLabel: {
interval: overview.chart.dates.length > 15 ? 'auto' : 0,
rotate: overview.chart.dates.length > 10 ? 30 : 0
}
},
yAxis: {
type: 'value',
name: '金额(元)',
axisLabel: {
formatter: (val: number) => val >= 10000 ? (val / 10000).toFixed(1) + '万' : String(val)
}
},
series: [
{
name: '业绩',
type: 'line',
smooth: true,
showSymbol: true,
symbolSize: 6,
lineStyle: { width: 3, color: '#4a78ff' },
itemStyle: { color: '#4a78ff' },
areaStyle: {
color: {
type: 'linear',
x: 0, y: 0, x2: 0, y2: 1,
colorStops: [
{ offset: 0, color: 'rgba(74, 120, 255, 0.25)' },
{ offset: 1, color: 'rgba(74, 120, 255, 0.02)' }
]
}
},
data: overview.chart.amounts
}
]
}))
const formatValue = (key: string, type: string) => {
const value = overview.summary?.[key] ?? 0
if (type === 'money') return `¥${Number(value).toFixed(2)}`
return String(value)
}
const fetchData = async () => {
loading.value = true
try {
const params: Record<string, any> = { time_type: queryParams.time_type }
if (queryParams.time_type === 'custom') {
params.start_date = dateRange.value[0] || ''
params.end_date = dateRange.value[1] || ''
}
const res = await assistantPerformanceOverview(params)
Object.assign(overview, res || {})
} catch (error: any) {
console.error('获取业绩数据失败:', error)
ElMessage.error(error?.msg || '获取业绩数据失败')
} finally {
loading.value = false
}
}
const handleTimeTypeChange = () => {
if (queryParams.time_type !== 'custom') {
dateRange.value = []
fetchData()
}
}
const handleCustomDateChange = () => {
if (dateRange.value?.length === 2) {
fetchData()
}
}
const handleReset = () => {
queryParams.time_type = 'month'
dateRange.value = []
fetchData()
}
onMounted(() => {
fetchData()
})
</script>
<style scoped lang="scss">
.assistant-performance-page {
padding: 20px;
}
.stats-filter-form {
:deep(.el-form-item) {
margin-bottom: 0;
}
}
.stats-kpi-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 16px;
margin-top: 16px;
}
.stats-kpi-card {
background: linear-gradient(145deg, #ffffff, #f5f8ff);
border: 1px solid #ebf1ff;
border-radius: 14px;
padding: 20px;
box-shadow: 0 10px 24px rgba(74, 120, 255, 0.08);
}
.stats-kpi-card.is-cancelled {
background: linear-gradient(145deg, #ffffff, #fff5f5);
border-color: #ffe0e0;
box-shadow: 0 10px 24px rgba(239, 68, 68, 0.06);
}
.stats-kpi-label {
color: #6b7280;
font-size: 13px;
}
.stats-kpi-value {
margin-top: 12px;
font-size: 28px;
line-height: 1.1;
font-weight: 700;
color: #1f2937;
}
.stats-kpi-value.is-money {
font-size: 24px;
}
.stats-kpi-card.is-cancelled .stats-kpi-value {
color: #ef4444;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
}
.card-title {
font-size: 15px;
font-weight: 600;
color: #1f2937;
}
.card-hint {
color: #909399;
font-size: 12px;
}
.stats-chart {
height: 360px;
}
</style>
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace app\adminapi\controller\stats;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\logic\stats\AssistantPerformanceLogic;
/**
* 医助个人业绩
*
* - GET stats.assistantPerformance/overview 个人业绩概览
*/
class AssistantPerformanceController extends BaseAdminController
{
public function overview()
{
$params = $this->request->get();
return $this->data(AssistantPerformanceLogic::overview($params, $this->adminId, $this->adminInfo));
}
}
@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
namespace app\adminapi\logic\stats;
use think\facade\Db;
class AssistantPerformanceLogic
{
/** 履约完成 */
private const FULFILLMENT_COMPLETED = 3;
public static function overview(array $params, int $adminId, array $adminInfo): array
{
// 时间范围解析
$timeType = $params['time_type'] ?? 'month';
$today = date('Y-m-d');
switch ($timeType) {
case 'today':
$startDate = $today;
$endDate = $today;
break;
case 'yesterday':
$startDate = date('Y-m-d', strtotime('-1 day'));
$endDate = $startDate;
break;
case 'week':
$startDate = date('Y-m-d', strtotime('-6 days'));
$endDate = $today;
break;
case 'month':
$startDate = date('Y-m-d', strtotime('-29 days'));
$endDate = $today;
break;
case 'custom':
$startDate = $params['start_date'] ?? $today;
$endDate = $params['end_date'] ?? $today;
break;
default:
$startDate = date('Y-m-d', strtotime('-29 days'));
$endDate = $today;
}
$startTs = strtotime($startDate . ' 00:00:00');
$endTs = strtotime($endDate . ' 23:59:59');
// 查询当前医助创建的、履约已完成的处方业务订单
$baseQuery = Db::name('tcm_prescription_order')
->where('delete_time IS NULL')
->where('diagnosis_id', '>', 0)
->where('creator_id', $adminId)
->where('fulfillment_status', self::FULFILLMENT_COMPLETED)
->where('create_time', '>=', $startTs)
->where('create_time', '<=', $endTs);
// 业绩总额
$totalAmount = (clone $baseQuery)->sum('amount');
// 有效订单数
$totalCount = (clone $baseQuery)->count();
// 按日期分组的折线图数据
$dailyData = (clone $baseQuery)
->field("FROM_UNIXTIME(create_time, '%Y-%m-%d') as date_label, SUM(amount) as daily_amount, COUNT(*) as daily_count")
->group('date_label')
->order('date_label', 'asc')
->select()
->toArray();
// 补全日期范围内的空日期
$dateMap = [];
foreach ($dailyData as $row) {
$dateMap[$row['date_label']] = [
'amount' => round((float)$row['daily_amount'], 2),
'count' => (int)$row['daily_count'],
];
}
$dates = [];
$amounts = [];
$counts = [];
$cursor = strtotime($startDate);
$endCursor = strtotime($endDate);
while ($cursor <= $endCursor) {
$d = date('Y-m-d', $cursor);
$dates[] = substr($d, 5); // MM-DD
$amounts[] = $dateMap[$d]['amount'] ?? 0;
$counts[] = $dateMap[$d]['count'] ?? 0;
$cursor = strtotime('+1 day', $cursor);
}
return [
'date_range' => [$startDate, $endDate],
'summary' => [
'total_amount' => round((float)$totalAmount, 2),
'total_count' => (int)$totalCount,
],
'chart' => [
'dates' => $dates,
'amounts' => $amounts,
'counts' => $counts,
],
];
}
}
@@ -0,0 +1,12 @@
-- 医助个人业绩菜单
-- 页面路径: /stats/assistant_performance
-- 前端组件: /stats/assistant-performance/index
-- 查询权限: stats.assistantPerformance/overview
-- 获取「数据统计」目录的 id(假设已经存在)
SET @stats_root_id = (SELECT id FROM zyt_system_menu WHERE name = '数据统计' AND type = 'M' LIMIT 1);
INSERT INTO `zyt_system_menu`
(`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
VALUES
(@stats_root_id, 'C', '个人业绩', '', 10, 'stats.assistantPerformance/overview', '/stats/assistant_performance', '/stats/assistant-performance/index', '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());