<?php

	/*******************************************************************\
	|																	|
	|	房哨（多中介管理运营平台系统）									|
	|																	|
	|	© 2018-2023 http://www.kaidandashi.com/ All rights reserved.	|
	|																	|
	|	本系统由淮南市银泰软件科技有限公司提供技术支持					|
	|																	|
	|	QQ号：984784483													|
	|																	|
	\*******************************************************************/

	namespace Erpadmin\Controller;
	use Think\Controller;
	class IndexController extends ErpadminbaseController {

		public function index(){
			$this->display();
		}

		public function welcome() {
			$this->display('welcome');
		}

		public function updatepass(){
			if (IS_POST) {
				$ymima=I('ymima');
				$xmima=I('xmima');
				$qrmima=I('qrmima');
				$erp_user = session('erp_user');
				$uid = $erp_user['id'];
				$yymima=M('admin_user')->where(array('id'=>$uid))->getField('password');
				if ($yymima!=admin_pass_salt($ymima)) {
					$this->error('原密码错误!');
				}
				if ($xmima!=$qrmima) {
					$this->error('两次密码不匹配!');
				}
				$passwd = admin_pass_salt($xmima);
				$r = M('admin_user')->where(array('id'=>$uid))->setField(array('password'=>$passwd));
				if ($r) {
					$this->success('成功');
				}else{
					$this->error('失败');
				}
			}else{
				$this->display();
			}
		}

		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);
			$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);
		}

	}