294 lines
10 KiB
PHP
Executable File
294 lines
10 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\admin\controller\statistics\Kpidispatcher;
|
|
use app\admin\model\Admin;
|
|
use app\admin\model\kpi\Template;
|
|
use app\admin\model\oa\Task;
|
|
use app\admin\model\User;
|
|
use app\common\controller\Backend;
|
|
use app\common\model\Attachment;
|
|
use Carbon\Carbon;
|
|
use fast\Date;
|
|
use think\Db;
|
|
use function Symfony\Component\Clock\now;
|
|
|
|
/**
|
|
* 控制台
|
|
*
|
|
* @icon fa fa-dashboard
|
|
* @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
|
|
*/
|
|
class Dashboard extends Backend
|
|
{
|
|
|
|
/**
|
|
* 查看
|
|
*/
|
|
public function index()
|
|
{
|
|
try {
|
|
\think\Db::execute("SET @@sql_mode='';");
|
|
} catch (\Exception $e) {
|
|
|
|
}
|
|
$column = [];
|
|
$starttime = Date::unixtime('day', -6);
|
|
$endtime = Date::unixtime('day', 0, 'end');
|
|
$joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime])
|
|
->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date')
|
|
->group('join_date')
|
|
->select();
|
|
for ($time = $starttime; $time <= $endtime;) {
|
|
$column[] = date("Y-m-d", $time);
|
|
$time += 86400;
|
|
}
|
|
$userlist = array_fill_keys($column, 0);
|
|
foreach ($joinlist as $k => $v) {
|
|
$userlist[$v['join_date']] = $v['nums'];
|
|
}
|
|
|
|
$dbTableList = Db::query("SHOW TABLE STATUS");
|
|
$addonList = get_addon_list();
|
|
$totalworkingaddon = 0;
|
|
$totaladdon = count($addonList);
|
|
foreach ($addonList as $index => $item) {
|
|
if ($item['state']) {
|
|
$totalworkingaddon += 1;
|
|
}
|
|
}
|
|
|
|
$today = [
|
|
(new Carbon())->now()->startOfDay(),
|
|
(new Carbon())->now()->endOfDay(),
|
|
];
|
|
|
|
$this->view->assign([
|
|
'totaluser' => User::count(),
|
|
'totaladdon' => $totaladdon,
|
|
'totaladmin' => Admin::count(),
|
|
// 'totalcategory' => \app\common\model\Category::count(),
|
|
'todayusersignup' => User::whereTime('jointime', 'today')->count(),
|
|
'todayuserlogin' => User::whereTime('logintime', 'today')->count(),
|
|
'sevendau' => User::whereTime('jointime|logintime|prevtime', '-7 days')->count(),
|
|
'thirtydau' => User::whereTime('jointime|logintime|prevtime', '-30 days')->count(),
|
|
'threednu' => User::whereTime('jointime', '-3 days')->count(),
|
|
'sevendnu' => User::whereTime('jointime', '-7 days')->count(),
|
|
'dbtablenums' => count($dbTableList),
|
|
'dbsize' => array_sum(array_map(function ($item) {
|
|
return $item['Data_length'] + $item['Index_length'];
|
|
}, $dbTableList)),
|
|
'totalworkingaddon' => $totalworkingaddon,
|
|
'attachmentnums' => Attachment::count(),
|
|
'attachmentsize' => Attachment::sum('filesize'),
|
|
'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(),
|
|
'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'),
|
|
|
|
'new_order_count' => model('order')
|
|
->whereBetween('create_time',$today)
|
|
->where('admin_id',$this->auth->id)->count(),
|
|
'dispatch_order_count' => model('order_dispatch')
|
|
->whereBetween('create_time',$today)
|
|
->where('admin_id',$this->auth->id)
|
|
->count(),
|
|
'doing_order_count' => model('order_dispatch')
|
|
->whereBetween('create_time',$today)
|
|
->where('status','>=',\app\admin\model\Order::STATUS_DRAFT)
|
|
->where('admin_id',$this->auth->id)->count(),
|
|
'ending_order_count' => model('order_dispatch')
|
|
->whereBetween('create_time',$today)
|
|
->where('status','=',\app\admin\model\Order::STATUS_FINISHED)
|
|
->where('admin_id',$this->auth->id)->count(),
|
|
|
|
]);
|
|
$this->assignconfig('column', array_keys($userlist));
|
|
$this->assignconfig('userdata', array_values($userlist));
|
|
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
public function task()
|
|
{
|
|
|
|
$dateTime = \date('Y-m-d H:i:s');
|
|
|
|
$dayTasks = (new Task())
|
|
->where('exec_admin_id','=',$this->auth->id)
|
|
->where('type','=',1)
|
|
->where('expire_end_time','>=', $dateTime)
|
|
->select();
|
|
|
|
$weekTasks = (new Task())
|
|
->where('exec_admin_id','=',$this->auth->id)
|
|
->where('type','=',2)
|
|
->where('expire_end_time','>=', $dateTime)
|
|
->select();
|
|
|
|
$monthTasks = (new Task())
|
|
->where('exec_admin_id','=',$this->auth->id)
|
|
->where('type','=',3)
|
|
->where('expire_end_time','>=', $dateTime)
|
|
->select();
|
|
|
|
$this->view->assign('day', $dayTasks);
|
|
$this->view->assign('week', $weekTasks);
|
|
$this->view->assign('month', $monthTasks);
|
|
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
public function kpi()
|
|
{
|
|
|
|
$groupIds = $this->auth->getGroupIds();
|
|
$groupId = $groupIds[0] ?? 0;
|
|
|
|
if ($groupId == 6) {
|
|
$kpiTemplate = (new Template())
|
|
->where('group_id','=', 6)
|
|
->with('kpiitem')
|
|
->find();
|
|
|
|
if (!$kpiTemplate) {
|
|
$this->error('kpi模板未找到');
|
|
}
|
|
|
|
$filter['group_id'] = 6;
|
|
$filter['admin_user_ids'] = 3;
|
|
$filter['start_time'] = date('Y-m-01 00:00:00');
|
|
$filter['end_time'] = date('Y-m-t 23:59:59');
|
|
$chart = (new Kpidispatcher())->chart($filter);
|
|
$chart = $chart[0] ?? [];
|
|
|
|
$datalist = [
|
|
//转化率 = 完单数 / 总订单数
|
|
'trans_rate' => $chart['trans_rate'] ?? 0,
|
|
'finish_num' => $chart['finish_num'] ?? 0,
|
|
'count_num' => $chart['count_num'] ?? 0,
|
|
//利润率 = 总业绩/总成效额
|
|
'performance_rate' => $chart['performance_rate'] ?? 0,
|
|
'performance' => $chart['performance'] ?? 0,
|
|
'total' => $chart['total'] ?? 0,
|
|
//派单时效
|
|
'avg_time_diff' => $chart['avg_time_diff'] ?? 0,
|
|
//派单成功率
|
|
'succ_rate' => $chart['succ_rate'] ?? 0,
|
|
'finish_num' => $chart['finish_num'] ?? 0,
|
|
'count_num' => $chart['count_num'] ?? 0,
|
|
|
|
//录入师傅数
|
|
'worker_num' => $chart['worker_num'] ?? 0,
|
|
];
|
|
|
|
$kpiItems = $kpiTemplate['kpiitem'];
|
|
|
|
foreach ($kpiItems as &$kpiItem) {
|
|
if ($kpiItem['unit'] == 1) {
|
|
$kpiItem['target_value'] .= '%';
|
|
}
|
|
if ($kpiItem['attr'] == 'ZHL') {
|
|
$kpiItem['complete_value'] = $datalist['trans_rate'] . '%';
|
|
$kpiItem['detail'] = $datalist['finish_num'] . '/' . $datalist['count_num'];
|
|
}
|
|
if ($kpiItem['attr'] == 'LRL') {
|
|
$kpiItem['complete_value'] = $datalist['performance_rate'] . '%';
|
|
$kpiItem['detail'] = $datalist['performance'] . '/' . $datalist['total'];
|
|
}
|
|
if ($kpiItem['attr'] == 'PDSX') {
|
|
$kpiItem['complete_value'] = $datalist['avg_time_diff'];
|
|
$kpiItem['detail'] = $datalist['avg_time_diff'];
|
|
}
|
|
if ($kpiItem['attr'] == 'PCCGL') {
|
|
$kpiItem['complete_value'] = $datalist['succ_rate'] . '%';
|
|
$kpiItem['detail'] = $datalist['finish_num'] . '/' . $datalist['count_num'];
|
|
}
|
|
if ($kpiItem['attr'] == 'GDJSL') {
|
|
$kpiItem['complete_value'] = 0;
|
|
$kpiItem['detail'] = 0;
|
|
}
|
|
if ($kpiItem['attr'] == 'LRSFS') {
|
|
$kpiItem['complete_value'] = $datalist['worker_num'];
|
|
$kpiItem['detail'] = $datalist['worker_num'];
|
|
}
|
|
}
|
|
|
|
$this->view->assign('kpi_template', $kpiTemplate);
|
|
$this->view->assign('kpi_items', $kpiItems);
|
|
|
|
return $this->view->fetch('kpi_dispatch');
|
|
}
|
|
|
|
if ($groupId == 2) {
|
|
|
|
$build = new \app\admin\model\Order();
|
|
|
|
$start = date('Y-m-01 00:00:00');
|
|
$end_at = date('Y-m-t 23:59:59');
|
|
|
|
$build->whereBetween('create_time', [$start, $end_at]);
|
|
|
|
$data = $build->field([
|
|
'admin_id',
|
|
'count(id) total',
|
|
'count(if(status=60,1,null)) finish',
|
|
'sum(if(status=60,performance,null)) money',
|
|
])->group('admin_id')
|
|
->where('admin_id', $this->auth->id)
|
|
->find();
|
|
|
|
//total 派单数
|
|
//money 利润
|
|
|
|
$assignData = [
|
|
'total' => $data['total'] ?? 0,
|
|
'finish' => $data['finish'] ?? 0,
|
|
'money' => $data['money'] ?? 0,
|
|
];
|
|
|
|
$admin = Admin::get($this->auth->id);
|
|
|
|
$this->view->assign('adminname', $admin['nickname']);
|
|
$this->view->assign('data', $assignData);
|
|
|
|
return $this->view->fetch('kpi_presale');
|
|
}
|
|
|
|
return $this->view->fetch('kpi_admin');
|
|
|
|
}
|
|
|
|
public function task_complete($ids = null)
|
|
{
|
|
|
|
$row = (new Task())->get($ids);
|
|
if (!$row) {
|
|
$this->error(__('No Results were found'));
|
|
}
|
|
if (false === $this->request->isPost()) {
|
|
$this->view->assign('row', $row);
|
|
return $this->view->fetch();
|
|
}
|
|
$params = $this->request->post('row/a');
|
|
|
|
$task = (new Task())->where('id', '=', $ids)->whereIn('status', [1, 5])->find();
|
|
|
|
if (!$task) {
|
|
$this->error('任务状态已变更,请刷新后操作');
|
|
}
|
|
|
|
$dateTime = \date('Y-m-d H:i:s');
|
|
|
|
$task->save([
|
|
'status' => 3,
|
|
'prove_desc' => $params['prove_desc'],
|
|
'prove_file_path' => $params['prove_file_path'],
|
|
'complete_time' => $dateTime,
|
|
]);
|
|
|
|
$this->success();
|
|
}
|
|
|
|
|
|
}
|