UserController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /**
  3. * Created by JetBrains PhpStorm.
  4. * User: charlie
  5. * Date: 13-11-30
  6. * Time: 下午3:06
  7. * To change this template use File | Settings | File Templates.
  8. */
  9. class UserController extends AdminController
  10. {
  11. /**
  12. * 管理员管理
  13. */
  14. public function actionAdmin(){
  15. $res = array();
  16. $roles = $this->getRoles();
  17. $res['role'] = $roles;
  18. $res['status'] = CommonFn::getComboboxData(User::$status_option, 1, true, 10);
  19. //$res['type'] = CommonFn::getComboboxData(User::$type_option, 1, true, 10);
  20. $criteria = new EMongoCriteria();
  21. $criteria->status('==', 1);
  22. $this->render('admin', $res);
  23. }
  24. public function actiondblog(){
  25. $this->render('dblog');
  26. }
  27. public function actionFakes(){
  28. $criteria = new EMongoCriteria();
  29. $criteria->_id('==',Yii::app()->user->id);
  30. $admin_user = User::model()->find($criteria);
  31. $fake_users = CommonFn::get_val_if_isset($admin_user,'fake_users',array());
  32. $z_user = new ZUser();
  33. $fake_users_arr = $z_user->getUserInfo($fake_users);
  34. $fakes = RUser::model()->parse($fake_users_arr,true,array('id','user_name'));
  35. $_fakes = array();
  36. $_fakes[] = array("id"=>"100","user_name"=> "全部","selected"=>true);
  37. foreach($fakes as $fake){
  38. $_fakes[] = $fake;
  39. }
  40. echo(json_encode($_fakes));exit;
  41. }
  42. /**
  43. * 获取管理员的列表
  44. */
  45. public function actionGetUser(){
  46. $auth = Yii::app()->authManager;
  47. $params = CommonFn::getPageParams();
  48. $filter_type = intval(Yii::app()->request->getParam('filter_type', 1));
  49. $filter_status = intval(Yii::app()->request->getParam('filter_status', 1));
  50. $search = Yii::app()->request->getParam('search', '');
  51. $criteria = new EMongoCriteria($params);
  52. if ($filter_type < 10){
  53. $criteria->type('==', $filter_type);
  54. }
  55. if ($filter_status < 10){
  56. $criteria->status('==', $filter_status);
  57. }
  58. if ($search != ''){
  59. if (is_numeric($search)){
  60. $criteria->_id('or', intval($search));
  61. }
  62. $search = new MongoRegex('/' . $search . '/');
  63. $criteria->email('or', $search);
  64. $criteria->name('or', $search);
  65. }
  66. $cursor = User::model()->findAll($criteria);
  67. $total = $cursor->count();
  68. $rows = CommonFn::getRowsFromCursor($cursor);
  69. $parsedRows = User::model()->parse($rows);
  70. echo CommonFn::composeDatagridData($parsedRows, $total);
  71. // $codes = array();
  72. // $admin_ids = array();
  73. // foreach ($rows as $k => $v){
  74. // $admin_ids[] = $v['_id'];
  75. // $roles = array_keys($auth->getAuthAssignments($v['_id']));
  76. // $rows[$k]['reg_time'] = date("Y-m-d H:i", $v['reg_time']);
  77. // if ($v['last_login'] == 0){
  78. // $rows[$k]['last_login'] = '';
  79. // } else {
  80. // $rows[$k]['last_login'] = date("Y-m-d H:i", $v['last_login']);
  81. // }
  82. // $rows[$k]['role'] = implode(',', $roles);
  83. // }
  84. // //$zs = new ZService();
  85. // echo CommonFn::composeDatagridData($rows, $total);
  86. }
  87. /**
  88. * 更新管理员
  89. */
  90. public function actionUpdateUser(){
  91. $auth = Yii::app()->authManager;
  92. $_id = intval(Yii::app()->request->getParam('_id', 0));
  93. $type = intval(Yii::app()->request->getParam('type', 1));
  94. $status = intval(Yii::app()->request->getParam('status', 1));
  95. $name = Yii::app()->request->getParam('name', '');
  96. $email = Yii::app()->request->getParam('email', '');
  97. $role = Yii::app()->request->getParam('new_role');
  98. $roles = array_filter(explode(',', $role));
  99. $modify_password = Yii::app()->request->getParam('modify_password', 0);
  100. $new_password = Yii::app()->request->getParam('new_password', '');
  101. $confirm_new_password = Yii::app()->request->getParam('confirm_new_password', '');
  102. if ($modify_password == 1 && $new_password != $confirm_new_password){
  103. CommonFn::requestAjax(false, '两次输入的密码不同');
  104. }
  105. $last_admin = false;
  106. if ($auth->isAssigned($auth->super_admin, $_id)){
  107. $last_admin = $auth->checkLastSuperAdmin();
  108. }
  109. if ($last_admin && $status != 1){
  110. CommonFn::requestAjax(false, '最后一个超级管理员不能修改状态');
  111. }
  112. if (empty($email) || !preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email ) ){
  113. CommonFn::requestAjax(false, '邮箱填写错误');
  114. }
  115. $criteria = new EMongoCriteria();
  116. $criteria->_id('==', $_id);
  117. $user = User::model()->find($criteria);
  118. $user->status = $status;
  119. $user->type = $type;
  120. $user->email = $email;
  121. $user->name = $name;
  122. // 如果角色为保洁师
  123. if (in_array('保洁师', $roles)) {
  124. // 用户信息与保洁师信息同步
  125. $techInfo = TechInfo::get($_id);
  126. if (!$techInfo) {
  127. $techInfo = new TechInfo();
  128. $techInfo->_id = $_id;
  129. }
  130. $techInfo->name = $name;
  131. $techInfo->status = $status;
  132. $techInfo->save();
  133. }
  134. // 修改密码
  135. if ($modify_password == 1){
  136. $user->pass = md5($new_password);
  137. }
  138. $user->save();
  139. //新增管理区域划分
  140. $criteria = new EMongoCriteria();
  141. $criteria->type('==', 2);
  142. $criteria->user('==', $_id);
  143. $old_roles = array_keys($auth->getAuthAssignments($_id));
  144. foreach ($old_roles as $v){
  145. if (!in_array($v, $roles)){
  146. if ($v == $auth->super_admin && $last_admin){
  147. CommonFn::requestAjax(false, '最后一个超级管理员不能取消超级管理员角色');
  148. }
  149. $auth->revoke($v, $_id);
  150. }
  151. }
  152. foreach ($roles as $v){
  153. if (!$auth->isAssigned($v, $_id)){
  154. $auth->assign($v, $_id);
  155. }
  156. }
  157. $auth->save();
  158. CommonFn::requestAjax();
  159. }
  160. /**
  161. * 获取DB log列表
  162. */
  163. public function actionGetDBLogList()
  164. {
  165. $params['db_name'] = "backend";
  166. $criteria = new EMongoCriteria($params);
  167. $dbLog = DbAction::model()->findAll($criteria);
  168. CommonFn::showList($dbLog,"dblog");
  169. //echo CommonFn::composeDatagridData($dbLog,count($dbLog));
  170. }
  171. /**
  172. * 获取全部角色
  173. */
  174. public function getRoles(){
  175. $auth = Yii::app()->authManager;
  176. $all_task = $auth->getAuthItems(2);
  177. $rows = array();
  178. foreach ($all_task as $k => $v){
  179. $rows[] = array('value' => $k, 'text' => $k);
  180. }
  181. return $rows;
  182. }
  183. public function actions()
  184. {
  185. return array(
  186. 'multipleSetStatus' => array(
  187. 'class' => 'application.controllers.multipleSet.PostDataAction',
  188. 'model' => User::model(),
  189. 'field' => 'status'
  190. ),
  191. 'multipleSetType' => array(
  192. 'class' => 'application.controllers.multipleSet.PostDataAction',
  193. 'model' => User::model(),
  194. 'field' => 'type'
  195. )
  196. );
  197. }
  198. }