<?php

	/***************************************************************\
	|																|
	|	开单大师（专业的房产ERP管理系统）								|
	|																|
	|	© 2019 http://www.kaidandashi.com All rights reserved.		|
	|																|
	|	本系统由淮南市银泰软件科技有限公司提供技术支持					|
	|																|
	|	QQ号：984784483												|
	|																|
	\***************************************************************/

	namespace Admin\Controller;
	use Think\Controller;
	class DlrizhiController extends CommonController {

		// 登录日志
		public function index(){
			$is_rbac = _rbac_node_show(337);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if (I('is_ajax')) {
				$condition = "a.gongsiid=".session('gongsiid');
				$sousuo = I('sousuo');
				$shijian = I('shijian');
				if ($sousuo) {
					$condition .= " and (e.ygmingcheng like '%$sousuo%' or e.pinyinjs like '%$sousuo%' or e.dianhua like '%$sousuo%')";
				}
				if ($shijian) {
					$time_s = explode(' - ',$shijian);
					$condition .= " and a.shijian>=".strtotime($time_s[0])." and a.shijian<".strtotime($time_s[0])+86400;
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$dlpx = "order by a.".$field." ".$order;
				} else {
					$dlpx = "order by a.shijian desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __DLRIZHI__ a left join __YONGHU__ e on a.uid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.*,e.ygmingcheng,e.bumen from __DLRIZHI__ a left join __YONGHU__ e on a.uid=e.id where {$condition} ".$dlpx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					$data[$key]['bmming'] = $value['uid'] ? yhbm($value['uid'],3) : "——";
					$data[$key]['shijian'] = $value['shijian'] ? date('Y-m-d H:i:s',$value['shijian']) : "——";
					$data[$key]['zdbianhao'] = $value['zdbianhao'] ? $value['zdbianhao'] : "——";
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->display();
			}
		}
	}