AdminDataController.php 3.0 KB
<?php
/**
 * 数据统计
 * Author : xiaojie
 * DateTime: 2018/12/04 13:11
 */
namespace app\portal\controller;

use app\portal\model\StatisticsModel;
use cmf\controller\AdminBaseController;

/**
 * Class AdminDataController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'数据统计',
 *     'action' =>'default',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 30,
 *     'icon'   =>'th',
 *     'remark' =>'数据统计'
 * )
 */

class AdminDataController extends AdminBaseController
{

    /**
     * 数据统计
     * @adminMenu(
     *     'name'   => '数据统计',
     *     'parent' => 'portal/AdminData/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '数据统计',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        $param = $this->request->param();
        $statisticsModel = new StatisticsModel();
        $map = $this->search2($param);
        $total_num = $statisticsModel->getTotalNum();
        $today_num = $statisticsModel->getTodayNum();
        $data = $statisticsModel->getBrokenData($map);
        $list3 = $statisticsModel->getCakeData($map);
        $list1 = empty($data)?'':json_encode($data['list1']);
        $list2 = empty($data)?'':json_encode($data['list2']);
        $list3 = empty($list3)?'':json_encode($list3);

        $this->assign('total_num',$total_num);
        $this->assign('today_num',$today_num);
        $this->assign('list1',$list1);
        $this->assign('list2',$list2);
        $this->assign('list3',$list3);
        return $this->fetch();
    }

    /**
     * 统计查询
     * Author:xieJie
     * @param $param 所接收数据
     * @return array
     */
    public function search2($param)
    {
        $map['status'] = 1;
        if(isset($param['time']) && !empty($param['time'])){
            if($param['time'] == 7){
                $param['start_time'] = date('Y-m-d H:i',time() - 86400*7);
                $param['end_time'] = date('Y-m-d H:i',time());
                $this->assign('time',7);
            }elseif ($param['time'] == 30){
                $param['start_time'] = date('Y-m-d H:i',time() - 86400*30);
                $param['end_time'] = date('Y-m-d H:i',time());
                $this->assign('time',30);
            }else{
                return false;
            }
        }else{
            $this->assign('time','');
        }
        if(isset($param['start_time']) && !empty($param['start_time']) && isset($param['end_time']) && !empty($param['end_time'])){
            $start_date = isset($param['start_time'])?strtotime($param['start_time']):'';
            $end_date = isset($param['end_time'])?strtotime($param['end_time']):'';
            $map['create_time'] = ['between',[$start_date,$end_date]];
            $this->assign('start_time',$param['start_time']);
            $this->assign('end_time',$param['end_time']);
        }
        return $map;
    }



}