InspuserController.class.php.bak.20200601 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class InspuserController extends ComController {
  5. public function _initialize() {
  6. parent::_initialize();
  7. $this->dbname ='inspuser_info';
  8. $this->regx_db='xj_';
  9. }
  10. public function index(){
  11. $Data=I();
  12. if(isset($Data['list'])){
  13. $UserVIew=M($this->dbname,$this->regx_db);
  14. $GetPage=$Data['pageCurrent'];//第几页
  15. $GetSize=$Data['pageSize'];//每页条数
  16. $Page=($GetPage-1)*$GetSize;
  17. $Map=array();
  18. if(!empty($Data['name'])){
  19. $Map['name']=$Data['name'];
  20. }
  21. if(!empty($Data['phone'])){
  22. $Map['phone']=$Data['phone'];
  23. }
  24. $permdata=$this->permdata();
  25. if (!empty($permdata))
  26. {
  27. $Map['add_user']=$permdata;
  28. }
  29. $Count= $UserVIew->where($Map)->count();// 查询满足要求的总记录数
  30. $List = $UserVIew->field("id,name,phone,add_data,add_user,is_enable")->where($Map)->order('add_data desc')
  31. ->limit($Page,$GetSize)->select();
  32. $Info = array(
  33. 'totalRow' => $Count,
  34. //'pageSize' => $count,//分页时不传
  35. 'list' => $List,
  36. );
  37. echo json_encode($Info);
  38. }
  39. else
  40. {
  41. $this->display();
  42. }
  43. }
  44. public function add(){
  45. if (IS_POST) {
  46. $Tab=M($this->dbname,$this->regx_db);
  47. $rules = array(
  48. array('phone','','电话号码重复!',0,'unique'),
  49. );
  50. if (!$Tab->validate($rules)->create())
  51. {
  52. // echo json_encode(array('statusCode'=>'300','message'=> $menu->getError()));
  53. $this->mtReturn(300,$Tab->getError());
  54. }
  55. else
  56. {
  57. /*$PhoneRes=M('')->query('SELECT openid FROM ztcrm.sp_customuser where phone='.$Data['phone']);
  58. if (empty($PhoneRes)) {
  59. $this->mtReturn(300,'该号码未关注公众号,请先关注公众号注册信息才能录入');
  60. }*/
  61. $Data=I();
  62. $Data['add_data']=date('Y-m-d H:i:s');
  63. $Data['add_user']=session('zt_username');
  64. $res = $Tab->add($Data);
  65. if($res)
  66. $this->mtReturn(200,'巡检员新增成功');
  67. else
  68. $this->mtReturn(300,'巡检员新增失败');
  69. }
  70. }
  71. else
  72. {
  73. $this->assign('action','/home/Inspuser/add');
  74. $this->display();
  75. }
  76. }
  77. public function edit(){
  78. $Data=I();
  79. $Tab=M($this->dbname,$this->regx_db);
  80. if(IS_POST)
  81. {
  82. $this->logcs(print_r($Data,ture));
  83. $res=$Tab->save($Data);
  84. if($res)
  85. $this->mtReturn(200,'编辑成功');
  86. else
  87. $this->mtReturn(300,'编辑失败');
  88. }
  89. else
  90. {
  91. $ResData = $Tab->field("id,name,phone,add_data,add_user,is_enable")->where(array('id'=>$Data['id']))->select();
  92. $this->assign('ResData',$ResData[0]);
  93. $this->assign('action','/home/Inspuser/edit');
  94. $this->display();
  95. }
  96. }
  97. public function downdata(){//导出Excel
  98. $Data=I();
  99. $UserVIew=M("v_user");
  100. $Map['status']=1;
  101. if(!empty($Data['username'])){
  102. $Map['username']=$Data['username'];
  103. }
  104. if(!empty($Data['truename'])){
  105. $Map['truename']=$Data['truename'];
  106. }
  107. if(!empty($Data['depname'])){
  108. $Map['depname']=$Data['depname'];
  109. }
  110. if(!empty($Data['posname'])){
  111. $Map['posname']=$Data['posname'];
  112. }
  113. $expTableData =$UserVIew->field("username,truename,extension,agentid,depname,posname,phone,email,address")->where($Map)->select();
  114. $expCellName=array('登录名','姓名','分机号','座席号','所在部门','担任角色','联系电话','电子邮箱','地址');
  115. $expTitle='用户信息';
  116. $this->exportExcel($expTitle,$expCellName,$expTableData);
  117. // echo json_encode($expTableData);
  118. }
  119. }