123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- <?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();
- }
- /**
- * 七日销售金额数据统计
- */
- public function datacenterthree(){
- $servicetype = Db::name('servicetype')->field('id,title as name')->select();
- $servicename = array_column($servicetype,'name');
- $this->assignconfig('servicename',$servicename);
- //七日
- $starttime = strtotime(date('Y-m-d')) - 518400;
- $endtime = strtotime(date('Y-m-d')) + 86399;
- $ec_date = [];
- $map = [
- 'company_id' => $this->auth->company_id,
- 'status' => 3,
- ];
- /*if($this->auth->type == 2){
- $map['staff_id'] = $this->auth->id;
- }*/
- for($i=$starttime;$i<$endtime;$i+=86400){
- $starttime_i = $i;
- $endtime_i = $i + 86399;
- //日历
- $ec_date[] = date('d',$starttime_i).'日';
- }
- $this->assignconfig('ec_date',$ec_date);
- foreach($servicetype as $key => &$val){
- $val['type'] = 'bar';
- if($key == 0){
- $val['barGap'] = 0;
- }
- $val['emphasis'] = ['focus'=>'series'];
- $val['data'] = [];
- $map['servicetype_id'] = $val['id'];
- for($i=$starttime;$i<$endtime;$i+=86400){
- $starttime_i = $i;
- $endtime_i = $i + 86399;
- //销售金额
- $map['finish_time'] = ['between',[$starttime_i,$endtime_i]];
- $val['data'][] = Db::name('order')->where($map)->sum('total_fee');
- }
- unset($val['id']);
- }
- $this->assignconfig('servicetype',$servicetype);
- return $this->view->fetch();
- }
- /**
- * 半年销售金额数据统计
- */
- public function datacenterthree2(){
- $servicetype = Db::name('servicetype')->field('id,title as name')->select();
- $servicename = array_column($servicetype,'name');
- $this->assignconfig('servicename',$servicename);
- $thismonth = strtotime(date('Y-m-01'));
- $ec_date = [];
- $map = [
- 'company_id' => $this->auth->company_id,
- 'status' => 3,
- ];
- /*if($this->auth->type == 2){
- $map['staff_id'] = $this->auth->id;
- }*/
- for($i=5;$i>=0;$i--){
- $starttime_i = strtotime("-".$i." month",$thismonth);
- $endtime_i = strtotime("-".($i-1) ." month",$thismonth) - 1;
- //日历
- $ec_date[] = date('m',$starttime_i).'月';
- //dump(date('Y-m-d H:i:s',$starttime_i));
- //dump(date('Y-m-d H:i:s',$endtime_i));
- }
- $this->assignconfig('ec_date',$ec_date);
- foreach($servicetype as $key => &$val){
- $val['type'] = 'bar';
- if($key == 0){
- $val['barGap'] = 0;
- }
- $val['emphasis'] = ['focus'=>'series'];
- $val['data'] = [];
- $map['servicetype_id'] = $val['id'];
- for($i=5;$i>=0;$i-=1){
- $starttime_i = strtotime("-".$i." month",$thismonth);
- $endtime_i = strtotime("-".($i-1) ." month",$thismonth) - 1;
- //销售金额
- $map['finish_time'] = ['between',[$starttime_i,$endtime_i]];
- $val['data'][] = Db::name('order')->where($map)->sum('total_fee');
- }
- unset($val['id']);
- }
- $this->assignconfig('servicetype',$servicetype);
- return $this->view->fetch();
- }
- /**
- * 业绩统计笔数
- */
- public function datacenterfour(){
- $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));
- $staff = Db::name('company_staff')->field('id,truename')->where('type',2)->where('company_id',$this->auth->company_id)->select();
- //柱状图
- $ec_date = [];
- $ec_ordernum = [];
- $map = [
- 'company_id' => $this->auth->company_id,
- 'status' => 3,
- 'finish_time' => ['between',[$starttime,$endtime]],
- ];
- foreach($staff as $key => $val){
- //日历
- $ec_date[] = $val['truename'];
- //下单人数
- $map['staff_id'] = $val['id'];
- $ec_ordernum[] = Db::name('order')->where($map)->count('id');
- }
- $this->assignconfig('ec_date', $ec_date);
- $this->assignconfig('ec_ordernum', $ec_ordernum);
- return $this->view->fetch();
- }
- /**
- * 业绩统计金额
- */
- public function datacenterfive(){
- $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));
- $staff = Db::name('company_staff')->field('id,truename')->where('type',2)->where('company_id',$this->auth->company_id)->select();
- //柱状图
- $ec_date = [];
- $ec_ordernum = [];
- $map = [
- 'company_id' => $this->auth->company_id,
- 'status' => 3,
- 'finish_time' => ['between',[$starttime,$endtime]],
- ];
- foreach($staff as $key => $val){
- //日历
- $ec_date[] = $val['truename'];
- //下单人数
- $map['staff_id'] = $val['id'];
- $ec_ordernum[] = Db::name('order')->where($map)->sum('total_fee');
- }
- $this->assignconfig('ec_date', $ec_date);
- $this->assignconfig('ec_ordernum', $ec_ordernum);
- return $this->view->fetch();
- }
- }
|