adminAction.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. $a = $this->updatess();
  97. m('imgroup')->updategall();
  98. echo '总'.$a[0].'条记录,更新了'.$a[1].'条';
  99. }
  100. public function updatess($whe='')
  101. {
  102. return m('admin')->updateinfo($whe);
  103. }
  104. //批量导入
  105. public function saveadminplAjax()
  106. {
  107. $rows = c('html')->importdata('user,name,sex,ranking,deptname,mobile,email,tel,superman','name');
  108. $oi = 0;
  109. $db = m('admin');
  110. $sort = (int)$db->getmou('max(`sort`)', '`id`>0');
  111. $dbs = m('dept');
  112. $py = c('pingyin');
  113. $inarr = array();
  114. foreach($rows as $k=>$rs){
  115. $user = $rs['user'];
  116. $name = $rs['name'];
  117. $arr = array();
  118. $arr['pingyin'] = $py->get($name,1);
  119. if($db->rows("`name`='$name'")>0)$name = $name.'1';
  120. if(isempt($user))$user = $arr['pingyin'];
  121. if($db->rows("`user`='$user'")>0)$user = $user.'1'; //相同用户名?
  122. $arr['user'] = strtolower($user);
  123. $arr['name'] = $name;
  124. $arr['sex'] = $rs['sex'];
  125. $arr['ranking'] = $rs['ranking'];
  126. $arr['deptname'] = $rs['deptname'];
  127. $arr['mobile'] = $rs['mobile'];
  128. $arr['email'] = $rs['email'];
  129. $arr['tel'] = $rs['tel'];
  130. $arr['superman'] = $rs['superman'];
  131. $arr['pass'] = md5('123456');
  132. $arr['sort'] = $sort+$oi;
  133. $arr['workdate'] = $this->date;
  134. $arr['adddt'] = $this->now;
  135. $arr['companyid'] = 1; //默认公司Id为1
  136. //读取上级主管Id
  137. $superid = (int)$db->getmou('id', "`name`='".$arr['superman']."'");
  138. if($superid==0)$arr['superman'] = '';
  139. $arr['superid'] = $superid;
  140. //读取部门Id
  141. $deptarr = $this->getdeptid($rs['deptname'], $dbs);
  142. if($deptarr['deptid']==0)return returnerror('行'.($k+1).'找不到对应顶级部门['.$rs['deptname'].']');
  143. foreach($deptarr as $k1=>$v1)$arr[$k1]=$v1;
  144. $inarr[] = $arr;
  145. }
  146. foreach($inarr as $k=>$rs){
  147. $bo = $db->insert($rs);
  148. if($bo)$oi++;
  149. }
  150. if($oi>0)$this->updatess();
  151. return returnsuccess('成功导入'.$oi.'个用户');
  152. }
  153. private function getdeptid($str,$dobj)
  154. {
  155. $deptid = '0';
  156. if(isempt($str))return $deptid;
  157. $stra = explode(',', $str);
  158. $depad = $this->getdeptids($stra[0],$dobj);
  159. $deptids= '';
  160. $deptnames= '';
  161. for($i=1;$i<count($stra);$i++){
  162. $depads = $this->getdeptids($stra[$i],$dobj);
  163. if($depads[0]>0){
  164. $deptids.=','.$depads[0].'';
  165. $deptnames.=','.$depads[1].'';
  166. }
  167. }
  168. if($deptids!='')$deptids = substr($deptids, 1);
  169. if($deptnames!='')$deptnames = substr($deptnames, 1);
  170. return array(
  171. 'deptid' => $depad[0],
  172. 'deptname' => $depad[1],
  173. 'deptallname' => $stra[0],
  174. 'deptids' => $deptids,
  175. 'deptnames' => $deptnames,
  176. );
  177. }
  178. private function getdeptids($str,$dobj)
  179. {
  180. $stra = explode('/', $str);
  181. $pid = 0;
  182. $id = 1;//默认顶级ID
  183. $deptname = '';
  184. for($i=0;$i<count($stra);$i++){
  185. $name = $stra[$i];
  186. $deptname = $name;
  187. $id = (int)$dobj->getmou('id',"`pid`='$pid' and `name`='$name'");
  188. //不存在就创建部门
  189. if($id==0){
  190. if($pid==0)return array(0, $deptname);
  191. $cjbm['name'] = $deptname;
  192. $cjbm['pid'] = $pid;
  193. $id = $dobj->insert($cjbm);
  194. $pid = $id;
  195. }else{
  196. $pid = $id;
  197. }
  198. }
  199. return array($id, $deptname);
  200. }
  201. //修改头像
  202. public function editfaceAjax()
  203. {
  204. $fid = (int)$this->post('fid');
  205. $uid = (int)$this->post('uid');
  206. echo m('admin')->changeface($uid, $fid);
  207. }
  208. //获取职位
  209. public function getrankAjax()
  210. {
  211. $arr = array();
  212. $rows = $this->db->getall('select `ranking` from `[Q]admin` group by `ranking`');
  213. foreach($rows as $k=>$rs)$arr[] = array('name'=>$rs['ranking'],'value'=>'');
  214. return $arr;
  215. }
  216. }