<?php

	/***************************************************************\
	|																|
	|	开单大师（专业的房产ERP管理系统）							|
	|																|
	|	© 2017-2022 淮南市银泰软件科技有限公司 All rights reserved	|
	|																|
	|	http://www.kaidandashi.com									|
	|																|
	|	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 = "a.".$field." ".$order;
				} else {
					$dlpx = "a.shijian desc";
				}
				$count = M('dlrizhi')->alias('a')->join('jjrxt_yonghu e on a.uid=e.id','LEFT')->where($condition)->count();
				$Page = I('p');
				$data = M('dlrizhi')->alias('a')->join('jjrxt_yonghu e on a.uid=e.id','LEFT')->field('a.*,e.ygmingcheng,e.bumen')->where($condition)->order($dlpx)->page($Page,$limit)->select();
				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,
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->display();
			}
		}
	}