adminAction.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. class adminClassAction extends Action
  3. {
  4. public function loadadminAjax()
  5. {
  6. $id = (int)$this->get('id',0);
  7. $data = m('admin')->getone($id);
  8. if($data){
  9. $data['pass']='';
  10. }
  11. $arr['data'] = $data;
  12. $dbs = m('sjoin');
  13. $arr['grouparr'] = $dbs->getgrouparr();
  14. $arr['groupid'] = $dbs->getgroupid($id);
  15. $this->returnjson($arr);
  16. }
  17. public function beforeshow($table)
  18. {
  19. $fields = 'id,name,`user`,deptname,`type`,`num`,status,tel,workdate,ranking,superman,loginci,sex,sort,face';
  20. $s = '';
  21. $key = $this->post('key');
  22. if($key!=''){
  23. $s = m('admin')->getkeywhere($key);
  24. }
  25. //这句是bug修改
  26. $sql1 = 'alter table `[Q]admin` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;';
  27. $opts = $this->option->getval('adminbug1');
  28. if(isempt($opts)){
  29. $this->db->query($sql1);
  30. $this->option->setval('adminbug1',$this->now, '用户bug1');
  31. }
  32. return array(
  33. 'fields'=> $fields,
  34. 'where' => $s
  35. );
  36. }
  37. public function fieldsafters($table, $fid, $val, $id)
  38. {
  39. $fields = 'sex,ranking,tel,mobile,workdate,email,quitdt';
  40. if(contain($fields, $fid))m('userinfo')->update("`$fid`='$val'", $id);
  41. }
  42. public function publicbeforesave($table, $cans, $id)
  43. {
  44. $user = strtolower(trimstr($cans['user']));
  45. $name = trimstr($cans['name']);
  46. $num = trimstr($cans['num']);
  47. $email= trimstr($cans['email']);
  48. $check= c('check');
  49. $mobile = $cans['mobile'];
  50. $weixinid = $cans['weixinid'];
  51. $pingyin = $cans['pingyin'];
  52. $msg = '';
  53. if($check->isincn($user))return '用户名不能有中文';
  54. if(strlen($user)<2)return '用户名必须2位字符以上';
  55. if(!isempt($email) && !$check->isemail($email))return '邮箱格式有误';
  56. if(!isempt($pingyin) && $check->isincn($pingyin))return '名字拼音不能有中文';
  57. if(!isempt($num) && $check->isincn($num))return '编号不能有中文';
  58. if(!isempt($mobile)){
  59. if(!$check->ismobile($mobile))return '手机格式有误';
  60. }
  61. if(isempt($mobile) && isempt($email))return '邮箱/手机号不能同时为空';
  62. if(!isempt($weixinid)){
  63. if(is_numeric($weixinid))return '微信号不能是数字';
  64. if($check->isincn($weixinid))return '微信号不能有中文';
  65. }
  66. $db = m($table);
  67. if($msg=='' && $num!='')if($db->rows("`num`='$num' and `id`<>'$id'")>0)$msg ='编号['.$num.']已存在';
  68. if($msg=='')if($db->rows("`user`='$user' and `id`<>'$id'")>0)$msg ='用户名['.$user.']已存在';
  69. if($msg=='')if($db->rows("`name`='$name' and `id`<>'$id'")>0)$msg ='姓名['.$name.']已存在';
  70. $rows = array();
  71. if($msg == ''){
  72. $did = $cans['deptid'];
  73. $sup = $cans['superid'];
  74. $rows = $db->getpath($did, $sup);
  75. }
  76. if(isempt($pingyin))$pingyin = c('pingyin')->get($name,1);
  77. $rows['pingyin'] = $pingyin;
  78. $rows['user'] = $user;
  79. $rows['name'] = $name;
  80. $rows['email'] = $email;
  81. $arr = array('msg'=>$msg, 'rows'=>$rows);
  82. return $arr;
  83. }
  84. public function publicaftersave($table, $cans, $id)
  85. {
  86. m($table)->record(array('superman'=>$cans['name']), "`superid`='$id'");
  87. if(getconfig('systype')=='demo'){
  88. m('weixin:user')->optuserwx($id);
  89. }
  90. $mygroup = $this->post('mygroup');
  91. m('sjoin')->addgroupuid($id, $mygroup);
  92. $this->updatess('and a.id='.$id.'');
  93. }
  94. public function updatedataAjax()
  95. {
  96. c('cache')->del('deptuserjson');
  97. $a = $this->updatess();
  98. m('imgroup')->updategall();
  99. echo '总'.$a[0].'条记录,更新了'.$a[1].'条';
  100. }
  101. public function updatess($whe='')
  102. {
  103. return m('admin')->updateinfo($whe);
  104. }
  105. //批量导入
  106. public function saveadminplAjax()
  107. {
  108. $rows = c('html')->importdata('user,name,sex,ranking,deptname,mobile,email,tel,superman','name');
  109. $oi = 0;
  110. $db = m('admin');
  111. $sort = (int)$db->getmou('max(`sort`)', '`id`>0');
  112. $dbs = m('dept');
  113. $py = c('pingyin');
  114. $inarr = array();
  115. foreach($rows as $k=>$rs){
  116. $user = $rs['user'];
  117. $name = $rs['name'];
  118. $arr = array();
  119. $arr['pingyin'] = $py->get($name,1);
  120. if($db->rows("`name`='$name'")>0)$name = $name.'1';
  121. if(isempt($user))$user = $arr['pingyin'];
  122. if($db->rows("`user`='$user'")>0)$user = $user.'1'; //相同用户名?
  123. $arr['user'] = strtolower($user);
  124. $arr['name'] = $name;
  125. $arr['sex'] = $rs['sex'];
  126. $arr['ranking'] = $rs['ranking'];
  127. $arr['deptname'] = $rs['deptname'];
  128. $arr['mobile'] = $rs['mobile'];
  129. $arr['email'] = $rs['email'];
  130. $arr['tel'] = $rs['tel'];
  131. $arr['superman'] = $rs['superman'];
  132. $arr['pass'] = md5('123456');
  133. $arr['sort'] = $sort+$oi;
  134. $arr['workdate'] = $this->date;
  135. $arr['adddt'] = $this->now;
  136. $arr['companyid'] = 1; //默认公司Id为1
  137. //读取上级主管Id
  138. $superid = (int)$db->getmou('id', "`name`='".$arr['superman']."'");
  139. if($superid==0)$arr['superman'] = '';
  140. $arr['superid'] = $superid;
  141. //读取部门Id
  142. $deptarr = $this->getdeptid($rs['deptname'], $dbs);
  143. if($deptarr['deptid']==0)return returnerror('行'.($k+1).'找不到对应顶级部门['.$rs['deptname'].']');
  144. foreach($deptarr as $k1=>$v1)$arr[$k1]=$v1;
  145. $inarr[] = $arr;
  146. }
  147. foreach($inarr as $k=>$rs){
  148. $bo = $db->insert($rs);
  149. if($bo)$oi++;
  150. }
  151. if($oi>0)$this->updatess();
  152. return returnsuccess('成功导入'.$oi.'个用户');
  153. }
  154. private function getdeptid($str,$dobj)
  155. {
  156. $deptid = '0';
  157. if(isempt($str))return $deptid;
  158. $stra = explode(',', $str);
  159. $depad = $this->getdeptids($stra[0],$dobj);
  160. $deptids= '';
  161. $deptnames= '';
  162. for($i=1;$i<count($stra);$i++){
  163. $depads = $this->getdeptids($stra[$i],$dobj);
  164. if($depads[0]>0){
  165. $deptids.=','.$depads[0].'';
  166. $deptnames.=','.$depads[1].'';
  167. }
  168. }
  169. if($deptids!='')$deptids = substr($deptids, 1);
  170. if($deptnames!='')$deptnames = substr($deptnames, 1);
  171. return array(
  172. 'deptid' => $depad[0],
  173. 'deptname' => $depad[1],
  174. 'deptallname' => $stra[0],
  175. 'deptids' => $deptids,
  176. 'deptnames' => $deptnames,
  177. );
  178. }
  179. private function getdeptids($str,$dobj)
  180. {
  181. $stra = explode('/', $str);
  182. $pid = 0;
  183. $id = 1;//默认顶级ID
  184. $deptname = '';
  185. for($i=0;$i<count($stra);$i++){
  186. $name = $stra[$i];
  187. $deptname = $name;
  188. $id = (int)$dobj->getmou('id',"`pid`='$pid' and `name`='$name'");
  189. //不存在就创建部门
  190. if($id==0){
  191. if($pid==0)return array(0, $deptname);
  192. $cjbm['name'] = $deptname;
  193. $cjbm['pid'] = $pid;
  194. $id = $dobj->insert($cjbm);
  195. $pid = $id;
  196. }else{
  197. $pid = $id;
  198. }
  199. }
  200. return array($id, $deptname);
  201. }
  202. //修改头像
  203. public function editfaceAjax()
  204. {
  205. $fid = (int)$this->post('fid');
  206. $uid = (int)$this->post('uid');
  207. echo m('admin')->changeface($uid, $fid);
  208. }
  209. //获取职位
  210. public function getrankAjax()
  211. {
  212. $arr = array();
  213. $rows = $this->db->getall('select `ranking` from `[Q]admin` group by `ranking`');
  214. foreach($rows as $k=>$rs)$arr[] = array('name'=>$rs['ranking'],'value'=>'');
  215. return $arr;
  216. }
  217. }
粤ICP备19079148号