117 lines
5.0 KiB
PHP
117 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\admin\model\Admin;
|
|
use app\common\model\user4s\User;
|
|
use app\common\model\user4s\Log;
|
|
use app\common\model\user4s\Levellog;
|
|
use app\common\model\user4s\Visit;
|
|
use app\common\controller\Backend;
|
|
use app\common\model\Attachment;
|
|
use fast\Date;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 控制台
|
|
*
|
|
* @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', -10);
|
|
$endtime = Date::unixtime('day', 0, 'end');
|
|
$joinlist = User::where('createtime', 'between time', [$starttime, $endtime])
|
|
->field('createtime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(createtime), "%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'];
|
|
}
|
|
$this->assignconfig('column', array_keys($userlist));
|
|
$this->assignconfig('userdata', array_values($userlist));
|
|
//var_dump(Log::getlastsql());
|
|
$joinlist = Log::where('state','=','0')
|
|
->where('createtime', 'between time', [$starttime, $endtime])
|
|
->where('end','exp',' > start')
|
|
->field('createtime, SUM(end-start) AS price, DATE_FORMAT(FROM_UNIXTIME(createtime), "%Y-%m-%d") AS join_date')
|
|
->group('join_date')
|
|
->select();
|
|
|
|
// for ($time = $starttime; $time <= $endtime;) {
|
|
// $column[] = date("Y-m-d", $time);
|
|
// $time += 86400;
|
|
// }
|
|
$pricelist = array_fill_keys($column, 0);
|
|
foreach ($joinlist as $k => $v) {
|
|
$pricelist[$v['join_date']] = $v['price'];
|
|
}
|
|
$this->assignconfig('pricedata', array_values($pricelist));
|
|
|
|
//保险临期
|
|
$start_date = strtotime("-1 year");
|
|
$end_date = strtotime("+2 month",$start_date);
|
|
$ins_where = array(
|
|
'insdate'=>['between',[date('Y-m-d',$start_date),date('Y-m-d',$end_date)]]
|
|
);
|
|
$ins_end = User::where($ins_where)->count();
|
|
$visit_where = array(
|
|
'visittime'=>['<=',Date::unixtime('day', 0,'end')]
|
|
);
|
|
$visit = Visit::where($visit_where)->where('status',0)->count();
|
|
//今日生日
|
|
$birthday_users = Db::query("select count(*) as num from car_user4s_user where MONTH(birthday) = MONTH(NOW()) and DAY(birthday) = DAY(NOW())");
|
|
//var_dump(Db::getlastsql(), $birthday_users);
|
|
$index_data = [
|
|
'totaluser' => User::count(),
|
|
'totalvipuser' => User::where('level_id','>','1')->count(),
|
|
'todayprice' => Log::where('state','=','0')->whereTime('createtime', 'today')->where('end','exp',' > start')->sum('end-start'),
|
|
'sumprice' =>Log::where('state','=','0')->where('end','exp',' > start')->sum('end-start'),
|
|
'totaladmin' => Admin::count(),
|
|
'totalcategory' => \app\common\model\Category::count(),
|
|
'todayusersignup' => User::whereTime('createtime', 'today')->count(),
|
|
'todayusertovip' => Levellog::whereTime('createtime', 'today')->where('end','exp',' > start')->count(),
|
|
'day7user' => User::whereTime('createtime', '-7 days')->count(),
|
|
'day7price' => Log::where('state','=','0')->whereTime('createtime', '-7 days')->where('end','exp',' > start')->sum('end-start'),
|
|
'day3user' => User::whereTime('createtime', '-3 days')->count(),
|
|
'day3price' => Log::where('state','=','0')->whereTime('createtime', '-3 days')->where('end','exp',' > start')->sum('end-start'),
|
|
// 'dbtablenums' => count($dbTableList),
|
|
// 'dbsize' => array_sum(array_map(function ($item) {
|
|
// return $item['Data_length'] + $item['Index_length'];
|
|
// }, $dbTableList)),
|
|
// 'totalworkingaddon' => $totalworkingaddon,
|
|
'birthday_num' => isset($birthday_users[0]['num']) ? $birthday_users[0]['num'] : 0,
|
|
'ins_end' => $ins_end,
|
|
'visit' => $visit,
|
|
'all_visit' => Visit::count(),
|
|
'attachmentsize' => Attachment::sum('filesize'),
|
|
'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(),
|
|
'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'),
|
|
];
|
|
|
|
|
|
$this->assignconfig('index_data', $index_data);
|
|
$this->view->assign($index_data);
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
}
|