car4s/application/admin/controller/Dashboard.php
孟凡懂 ebc7f2be88
Some checks failed
continuous-integration/drone/push Build is failing
新功能更新 fix #1 fix #2 fix #3 fix #4 fix #5
2022-07-09 04:16:14 +08:00

155 lines
6.7 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;
use think\Config;
use car\Sms;
/**
* 控制台
*
* @icon fa fa-dashboard
* @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
*/
class Dashboard extends Backend
{
/**
* 查看
*/
public function index()
{
try {
\think\Db::execute("SET @@sql_mode='';");
} catch (\Exception $e) {
}
$user_ids=[1,2];
// $list = User::where('id', 'in', $user_ids)->select();
// $list = collection($list)->toarray();
// $list = array_column($list, null, 'id');
// var_dump($list);
// $sms = new Sms(['userid' => 5838, 'account' => '盛世鑫鼎比亚迪', 'password' => '123456']);
// $prefix = Config::get('database.prefix');
// $fieldArr = [];
// $table = $prefix . 'user4s_user';
// $database = Config::get('database.database');
// $pk = Db::getTableInfo($table, 'pk');
// $list = db()->query(
// "SELECT COLUMN_NAME,COLUMN_COMMENT,COLUMN_TYPE,IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?",
// [$table, $database]
// );
// foreach ($list as $k => $v) {
// if ($v['COLUMN_NAME'] !== $pk) {
// $fieldArr[$v['COLUMN_COMMENT']] = $v; //['COLUMN_NAME']
// }
// }
// var_dump($fieldArr);
//$sms->sendsms('15264925507','测试短信啊');
//$sms->getStatus();
// print_r($sms->send($user_ids,'【比亚迪汽车】如果搜[姓名]-将返回[联系方式]-要对数[余额]-进行[积分]-找且[性别]-要[车牌号码],退订回T'));
// $sms->getStatus();
$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(function ($query) {
for ($y = 1; $y <= 20; $y++) {
$start_date = strtotime("-" . $y . " 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)]]
);
$query->whereOr($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();
}
}