123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\Admin;
- use app\admin\model\User;
- 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', -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;
- }
- }
- $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'),
- ]);
- $this->assignconfig('column', array_keys($userlist));
- $this->assignconfig('userdata', array_values($userlist));
- return $this->view->fetch();
- }
- /**
- * 订单统计笔数
- */
- public function order(){
- $starttime = strtotime(date('Y-m-d',strtotime("-30 day"))); //默认30天前
- $endtime = strtotime(date('Y-m-d')) - 1;
- //接收
- $choicedatetime = input('choicedatetime','');
- if(!empty($choicedatetime)){
- $choicedatetime = explode(' - ',$choicedatetime);
- $starttime = strtotime($choicedatetime[0]);
- $endtime = strtotime($choicedatetime[1]) + 86399;
- }
- $this->view->assign('defaultdatetime',date('Y-m-d',$starttime).' - '.date('Y-m-d',$endtime));
- //dump($starttime);
- //dump($endtime);
- //过去30天
- $ec_date = [];
- $ec_ordernum = [];
- // $ec_orderfee = [];
- $whereop = $this->whereop('company_id');
- $whereop['status'] = 3;
- for($i=$starttime;$i<$endtime;$i+=86400){
- $starttime_i = $i;
- $endtime_i = $i + 86399;
- //dump($starttime);
- //日历
- $ec_date[] = date('Y-m-d',$starttime_i);
- //下单人数
- $whereop['finish_time'] = ['between',[$starttime_i,$endtime_i]];
- $ec_ordernum[] = Db::name('order')->where($whereop)->count('id');
- //下单金额
- // $ec_orderfee[] = Db::name('order')->where(['createtime'=>['between',[$starttime_i,$endtime_i]]])->sum('pay_fee');
- }
- $this->assignconfig('ec_date', $ec_date);
- $this->assignconfig('ec_ordernum', $ec_ordernum);
- // $this->assignconfig('ec_orderfee', $ec_orderfee);
- return $this->view->fetch();
- }
- /**
- * 订单统计各类型
- */
- public function orderservicetype(){
- $starttime = strtotime(date('Y-m-d',strtotime("-30 day"))); //默认30天前
- $endtime = strtotime(date('Y-m-d')) - 1;
- //接收
- $choicedatetime = input('choicedatetime','');
- if(!empty($choicedatetime)){
- $choicedatetime = explode(' - ',$choicedatetime);
- $starttime = strtotime($choicedatetime[0]);
- $endtime = strtotime($choicedatetime[1]) + 86399;
- }
- $this->view->assign('defaultdatetime',date('Y-m-d',$starttime).' - '.date('Y-m-d',$endtime));
- //饼图
- $whereop = $this->whereop('company_id');
- $whereop['status'] = 3;
- $whereop['finish_time'] = ['between',[$starttime,$endtime]];
- $servicetype = Db::name('servicetype')->field('id,title as name')->select();
- $all_count = Db::name('order')->where($whereop)->count('id');
- foreach($servicetype as $key => &$val){
- $whereop['servicetype_id'] = $val['id'];
- $val['value'] = Db::name('order')->where($whereop)->count('id');
- $val['name'] = $val['name'] . bcdiv($val['value'],$all_count,4)*100 . '%';
- unset($val['id']);
- }
- $this->assignconfig('servicetype', $servicetype);
- return $this->view->fetch();
- }
- /**
- * 客户统计
- */
- public function datacentertwo(){
- $whereop = $this->whereop('company_id');
- $usernumber = Db::name('user_wallet')->where($whereop)->count();//充卡客户数量
- $summoney = Db::name('user_wallet')->where($whereop)->sum('money');//充卡余额
- //客户类别
- $comefrom_config = ['线下新客','老带新','平台引流','自然进店'];
- $comefrom_array = [];
- foreach($comefrom_config as $key => $val){
- $number = Db::name('user_wallet')->where($whereop)->where('comefrom',$val)->count();
- $comefrom_array[] = ['name'=>$val . bcdiv($number,$usernumber,4)*100 . '%','value'=>$number];
- }
- //
- $this->assign('usernumber', $usernumber);
- $this->assign('summoney', $summoney);
- $this->assignconfig('comefrom_array', $comefrom_array);
- return $this->view->fetch();
- }
- }
|