deptModel.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. class reimplat_deptClassModel extends reimplatModel
  3. {
  4. public function initReimplat()
  5. {
  6. $this->settable('zreim_user');
  7. }
  8. //获取部门
  9. public function getdeptlist()
  10. {
  11. $url = $this->geturl('opendept','deptlist');
  12. $result = c('curl')->getcurl($url);
  13. $barr = $this->recordchu($result);
  14. if(!$barr['success'])return $barr;
  15. return returnsuccess($barr['data']['deptlist']);
  16. }
  17. //获取所有用户
  18. public function getuserlist()
  19. {
  20. $url = $this->geturl('opendept','useralllist');
  21. $result = c('curl')->getcurl($url);
  22. $barr = $this->recordchu($result);
  23. if($barr['success']){
  24. $userarr = $barr['data']['userlist'];
  25. $ids = '0';
  26. foreach($userarr as $k=>$rs){
  27. $id1 = $this->userupdates($rs);
  28. $ids.=','.$id1.'';
  29. }
  30. $this->delete('`id` not in('.$ids.')');
  31. }
  32. return returnsuccess();
  33. }
  34. public function getuinfo($user)
  35. {
  36. return $this->getone("`user`='$user'");
  37. }
  38. public function userupdates($rs)
  39. {
  40. $where = "`user`='".$rs['user']."'";
  41. $uars = $this->getone($where);
  42. if($uars){
  43. $id1 = $uars['id'];
  44. }else{
  45. $id1 = 0;
  46. $where='';
  47. }
  48. $uarr = array(
  49. 'user' => $rs['user'],
  50. 'name' => $rs['name'],
  51. 'position' => $rs['position'],
  52. 'mobile' => $rs['mobile'],
  53. 'email' => $rs['email'],
  54. 'tel' => $rs['tel'],
  55. 'status' => $rs['status'],
  56. 'deptid' => $rs['deptid'],
  57. );
  58. if(isset($rs['face']))$uarr['face'] = $rs['face'];
  59. $this->record($uarr, $where);
  60. if($id1==0)$id1 = $this->db->insert_id();
  61. return $id1;
  62. }
  63. //用户信息
  64. public function getuserinfo($user)
  65. {
  66. $url = $this->geturl('opendept','userinfo', array('user'=>$user));
  67. $result = c('curl')->getcurl($url);
  68. $barr = $this->recordchu($result);
  69. if(!$barr['success'])return $barr;
  70. $rs = $barr['data']['userinfo'];
  71. $this->userupdates($rs);
  72. return returnsuccess($rs);
  73. }
  74. //更新用户
  75. public function userupdate($urs)
  76. {
  77. $urs['position'] = $urs['ranking'];
  78. $urs['istxl'] = $urs['isvcard'];
  79. $urs['gender'] = ($urs['sex']=='女')?2:1;
  80. unset($urs['ranking']);
  81. unset($urs['sex']);
  82. unset($urs['isvcard']);
  83. $url = $this->geturl('opendept','userupdate');
  84. $result = c('curl')->postcurl($url, json_encode($urs));
  85. $barr = $this->recordchu($result);
  86. if($barr['success'])$this->getuserinfo($urs['user']);
  87. return $barr;
  88. }
  89. //更新全部部门
  90. public function deptallupdate()
  91. {
  92. $rows = m('dept')->getall('1=1','`id`,`name`,`num`,`pid`,`sort`,`headman`');
  93. $arr['deptalldata'] = $rows;
  94. $url = $this->geturl('opendept','deptallupdate');
  95. $result = c('curl')->postcurl($url, json_encode($arr));
  96. $barr = $this->recordchu($result);
  97. return $barr;
  98. }
  99. public function notinadmin($ids='')
  100. {
  101. $sql = "select a.`user` from `[Q]zreim_user` a left join `[Q]admin` b on a.`user`=b.`user` where";
  102. if($ids!=''){
  103. $sql.= " b.id in($ids)";
  104. }else{
  105. $sql.= ' b.id is null';
  106. }
  107. $rows= $this->db->getall($sql);
  108. $arr = array();
  109. foreach($rows as $k=>$rs){
  110. $arr[] = $rs['user'];
  111. }
  112. return $arr;
  113. }
  114. //删除用户
  115. public function deleteuserall($ids='')
  116. {
  117. $arr = $this->notinadmin($ids);
  118. if(!$arr){
  119. return returnerror('没有可删除用户');
  120. }
  121. return $this->userdelete(join(',', $arr));
  122. }
  123. public function userdelete($user)
  124. {
  125. $url = $this->geturl('opendept','userdelete');
  126. $body = '{"userlist":"'.$user.'"}';
  127. $result = c('curl')->postcurl($url, $body);
  128. $barr = $this->recordchu($result);
  129. if($barr['success'])$this->getuserlist();
  130. return $barr;
  131. }
  132. }
粤ICP备19079148号