You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
202 lines
6.5 KiB
202 lines
6.5 KiB
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\service\api\member\MemberService;
|
|
use core\base\BaseApiController;
|
|
use think\facade\View;
|
|
|
|
/**
|
|
* Dashboard WebView 控制器
|
|
*/
|
|
class Dashboard extends BaseApiController
|
|
{
|
|
/**
|
|
* WebView 页面渲染
|
|
*/
|
|
public function webview()
|
|
{
|
|
$type = $this->request->get('type', 'my_data'); // 页面类型
|
|
$token = $this->request->get('token', ''); // 用户token
|
|
$platform = $this->request->get('platform', 'web'); // 平台标识
|
|
|
|
// 验证token和获取用户信息
|
|
if (empty($token)) {
|
|
return $this->renderErrorPage('缺少用户认证信息');
|
|
}
|
|
|
|
try {
|
|
// 这里应该验证token,暂时跳过验证用于测试
|
|
$userInfo = $this->getMockUserInfo($type);
|
|
|
|
// 根据页面类型渲染不同内容
|
|
$htmlContent = $this->renderDashboardPage($type, $userInfo, $platform);
|
|
|
|
// 输出HTML内容
|
|
return response($htmlContent)->header([
|
|
'Content-Type' => 'text/html; charset=utf-8',
|
|
'Cache-Control' => 'no-cache, no-store, must-revalidate',
|
|
'Pragma' => 'no-cache',
|
|
'Expires' => '0'
|
|
]);
|
|
|
|
} catch (\Exception $e) {
|
|
return $this->renderErrorPage('页面加载失败: ' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 渲染Dashboard页面
|
|
*/
|
|
private function renderDashboardPage($type, $userInfo, $platform)
|
|
{
|
|
// 获取页面数据
|
|
$pageData = $this->getPageData($type, $userInfo);
|
|
|
|
// 页面标题映射
|
|
$titleMap = [
|
|
'my_data' => '我的数据',
|
|
'dept_data' => '部门数据',
|
|
'campus_data' => '校区数据'
|
|
];
|
|
|
|
$pageTitle = $titleMap[$type] ?? '数据统计';
|
|
|
|
// 使用视图模板渲染页面
|
|
return View::fetch('dashboard/main', [
|
|
'pageTitle' => $pageTitle,
|
|
'pageData' => $pageData,
|
|
'platform' => $platform,
|
|
'userInfo' => $userInfo
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 获取页面数据
|
|
*/
|
|
private function getPageData($type, $userInfo)
|
|
{
|
|
switch ($type) {
|
|
case 'my_data':
|
|
return $this->getMyData($userInfo);
|
|
case 'dept_data':
|
|
return $this->getDeptData($userInfo);
|
|
case 'campus_data':
|
|
return $this->getCampusData($userInfo);
|
|
default:
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取我的数据
|
|
*/
|
|
private function getMyData($userInfo)
|
|
{
|
|
return [
|
|
'stats' => [
|
|
['label' => '本月签约客户', 'value' => 12, 'unit' => '人', 'trend' => '+15%'],
|
|
['label' => '本月完成业绩', 'value' => 85000, 'unit' => '元', 'trend' => '+8%'],
|
|
['label' => '跟进客户数', 'value' => 45, 'unit' => '人', 'trend' => '+5%'],
|
|
['label' => '转化率', 'value' => 26.7, 'unit' => '%', 'trend' => '+2.3%']
|
|
],
|
|
'charts' => [
|
|
'monthly_trend' => [
|
|
'title' => '月度业绩趋势',
|
|
'data' => [65000, 72000, 68000, 75000, 82000, 85000]
|
|
],
|
|
'customer_source' => [
|
|
'title' => '客户来源分布',
|
|
'data' => [
|
|
['name' => '线上推广', 'value' => 35],
|
|
['name' => '转介绍', 'value' => 28],
|
|
['name' => '电话营销', 'value' => 22],
|
|
['name' => '其他', 'value' => 15]
|
|
]
|
|
]
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取部门数据
|
|
*/
|
|
private function getDeptData($userInfo)
|
|
{
|
|
return [
|
|
'stats' => [
|
|
['label' => '部门总业绩', 'value' => 520000, 'unit' => '元', 'trend' => '+12%'],
|
|
['label' => '团队人数', 'value' => 8, 'unit' => '人', 'trend' => '0%'],
|
|
['label' => '平均业绩', 'value' => 65000, 'unit' => '元', 'trend' => '+12%'],
|
|
['label' => '部门排名', 'value' => 2, 'unit' => '名', 'trend' => '+1']
|
|
],
|
|
'charts' => [
|
|
'team_performance' => [
|
|
'title' => '团队成员业绩排行',
|
|
'data' => [
|
|
['name' => '张三', 'value' => 85000],
|
|
['name' => '李四', 'value' => 72000],
|
|
['name' => '王五', 'value' => 68000],
|
|
['name' => '赵六', 'value' => 65000]
|
|
]
|
|
]
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取校区数据
|
|
*/
|
|
private function getCampusData($userInfo)
|
|
{
|
|
return [
|
|
'stats' => [
|
|
['label' => '校区总业绩', 'value' => 1200000, 'unit' => '元', 'trend' => '+18%'],
|
|
['label' => '部门数量', 'value' => 5, 'unit' => '个', 'trend' => '0%'],
|
|
['label' => '员工总数', 'value' => 32, 'unit' => '人', 'trend' => '+3'],
|
|
['label' => '客户总数', 'value' => 245, 'unit' => '人', 'trend' => '+25']
|
|
],
|
|
'charts' => [
|
|
'dept_performance' => [
|
|
'title' => '部门业绩对比',
|
|
'data' => [
|
|
['name' => '销售一部', 'value' => 320000],
|
|
['name' => '销售二部', 'value' => 280000],
|
|
['name' => '销售三部', 'value' => 260000],
|
|
['name' => '客服部', 'value' => 180000],
|
|
['name' => '行政部', 'value' => 160000]
|
|
]
|
|
]
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取模拟用户信息
|
|
*/
|
|
private function getMockUserInfo($type)
|
|
{
|
|
return [
|
|
'id' => 1,
|
|
'name' => '测试员工',
|
|
'department' => '销售部',
|
|
'campus' => '总校区',
|
|
'role' => 'staff'
|
|
];
|
|
}
|
|
|
|
|
|
/**
|
|
* 渲染错误页面
|
|
*/
|
|
private function renderErrorPage($message)
|
|
{
|
|
$errorHtml = View::fetch('dashboard/error', [
|
|
'message' => $message
|
|
]);
|
|
|
|
return response($errorHtml)->header([
|
|
'Content-Type' => 'text/html; charset=utf-8'
|
|
]);
|
|
}
|
|
}
|