123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- class InspuserController extends ComController {
-
- public function _initialize() {
- parent::_initialize();
- $this->dbname ='inspuser_info';
- $this->regx_db='xj_';
- }
- public function index(){
- $Data=I();
- if(isset($Data['list'])){
- $UserVIew=M($this->dbname,$this->regx_db);
- $GetPage=$Data['pageCurrent'];//第几页
- $GetSize=$Data['pageSize'];//每页条数
- $Page=($GetPage-1)*$GetSize;
- $Map=array();
- if(!empty($Data['name'])){
- $Map['name']=$Data['name'];
- }
- if(!empty($Data['phone'])){
- $Map['phone']=$Data['phone'];
- }
- $permdata=$this->permdata();
- if (!empty($permdata))
- {
- $Map['add_user']=$permdata;
- }
- $Count= $UserVIew->where($Map)->count();// 查询满足要求的总记录数
- $List = $UserVIew->field("id,name,phone,add_data,add_user,is_enable")->where($Map)->order('add_data desc')
- ->limit($Page,$GetSize)->select();
- $Info = array(
- 'totalRow' => $Count,
- //'pageSize' => $count,//分页时不传
- 'list' => $List,
- );
- echo json_encode($Info);
- }
- else
- {
- $this->display();
- }
-
- }
-
- public function add(){
- if (IS_POST) {
- $Tab=M($this->dbname,$this->regx_db);
- $rules = array(
- array('phone','','电话号码重复!',0,'unique'),
- );
- if (!$Tab->validate($rules)->create())
- {
- // echo json_encode(array('statusCode'=>'300','message'=> $menu->getError()));
- $this->mtReturn(300,$Tab->getError());
- }
- else
- {
- /*$PhoneRes=M('')->query('SELECT openid FROM ztcrm.sp_customuser where phone='.$Data['phone']);
- if (empty($PhoneRes)) {
- $this->mtReturn(300,'该号码未关注公众号,请先关注公众号注册信息才能录入');
- }*/
- $Data=I();
- $Data['add_data']=date('Y-m-d H:i:s');
- $Data['add_user']=session('zt_username');
- $res = $Tab->add($Data);
- if($res)
- $this->mtReturn(200,'巡检员新增成功');
- else
- $this->mtReturn(300,'巡检员新增失败');
- }
-
- }
- else
- {
- $this->assign('action','/home/Inspuser/add');
- $this->display();
- }
-
- }
- public function edit(){
- $Data=I();
- $Tab=M($this->dbname,$this->regx_db);
- if(IS_POST)
- {
- $this->logcs(print_r($Data,ture));
- $res=$Tab->save($Data);
- if($res)
- $this->mtReturn(200,'编辑成功');
- else
- $this->mtReturn(300,'编辑失败');
-
- }
- else
- {
- $ResData = $Tab->field("id,name,phone,add_data,add_user,is_enable")->where(array('id'=>$Data['id']))->select();
- $this->assign('ResData',$ResData[0]);
- $this->assign('action','/home/Inspuser/edit');
- $this->display();
- }
- }
- public function downdata(){//导出Excel
- $Data=I();
- $UserVIew=M("v_user");
- $Map['status']=1;
- if(!empty($Data['username'])){
- $Map['username']=$Data['username'];
- }
- if(!empty($Data['truename'])){
- $Map['truename']=$Data['truename'];
- }
- if(!empty($Data['depname'])){
- $Map['depname']=$Data['depname'];
- }
- if(!empty($Data['posname'])){
- $Map['posname']=$Data['posname'];
- }
- $expTableData =$UserVIew->field("username,truename,extension,agentid,depname,posname,phone,email,address")->where($Map)->select();
- $expCellName=array('登录名','姓名','分机号','座席号','所在部门','担任角色','联系电话','电子邮箱','地址');
- $expTitle='用户信息';
- $this->exportExcel($expTitle,$expCellName,$expTableData);
- // echo json_encode($expTableData);
- }
-
-
- }
|