<?php
namespace Erpadmin\Controller;
use Think\Controller;
class IndexController extends ErpadminbaseController {
    public function index(){
        //$group = M('jjr_mianyang')->where()->group('xingming')->field('max(id) as max')->select();
        //$this->show('123');
        $this->display();
    }

    public function welcome()
    {

    	//$this->show(StrOrderOne());
    	$this->display('welcome');
    }



    public function getLoginCountLine()
    {
        
        $Model = new \Think\Model();
        $ThisWeek = $this->getThisWeekOf(date());
        $start_time = strtotime($ThisWeek[0]);
        $end_time = strtotime($ThisWeek[6])+3600*24;
        $sql = "SELECT FROM_UNIXTIME(shijian,'%Y-%m-%d') as create_date,count(id) as value 
                from __DLRIZHI__ WHERE shijian >= {$start_time} and shijian < {$end_time}   GROUP BY create_date";
        $sql = "select a.create_date,
    SUM(CASE a.dlleibie WHEN 'pc' THEN a.value ELSE 0 END ) z1,
    SUM(CASE a.dlleibie WHEN 'mobile' THEN a.value ELSE 0 END ) z2
     from (select FROM_UNIXTIME(shijian, '%Y-%m-%d') as create_date,dlleibie,count(id) as value from __DLRIZHI__ 
     WHERE  shijian >= {$start_time} and shijian < {$end_time}  
     group by create_date,dlleibie) a
     GROUP BY a.create_date;";
        $all = $Model->query($sql);
        //p($all);die;
        $arr = array();
        $arr2 = array();
        foreach ($all as $key => $value) {
            $arr[$value['create_date']] = $value;
        }
        foreach ($ThisWeek as $k => $v) {
            $arr2[] = $v;
            $series1[] = $arr[$v]['z1']?$arr[$v]['z1']:'';
            $series2[] = $arr[$v]['z2']?$arr[$v]['z2']:'';
        }

        $return_data = array(
            'status'=>1,
            'info'=>'',
            'data'=>array(
                'xAxis'=>$arr2,
                'series1'=>$series1,
                'series2'=>$series2
            )
        );

        $this->ajaxReturn($return_data);
    }


    public function getLoginCountPie()
    {
        $Model = new \Think\Model();
        $ThisWeek = $this->getThisWeekOf(date());
        $start_time = strtotime($ThisWeek[0]);
        $end_time = strtotime($ThisWeek[6])+3600*24;

        $sql1 = "SELECT (case dlleibie when 'pc' THEN '电脑端' when 'mobile' then '移动端' ELSE '' END) as name,count(id) as value 
                from __DLRIZHI__ WHERE shijian >= {$start_time} and shijian < {$end_time}   GROUP BY dlleibie";
        $data1 = $Model->query($sql1);
        

        $return_data = array(
            'status'=>1,
            'info'=>'',
            'data'=>array(
                'legend'=>$legend,
                'data1'=>$data1
            )
        );

        $this->ajaxReturn($return_data);
    }

}