UserController.class.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace Admin\Controller;
  3. use Common\Controller\AdminController;
  4. class UserController extends AdminController {
  5. public function __construct(){
  6. parent::__construct();
  7. }
  8. //用户列表
  9. public function index(){
  10. $page = I('get.p','1');
  11. session('page',$page);
  12. $keyword = I('get.keyword','');
  13. $is_admin = I('get.is_admin',2);
  14. $is_auth = I('get.is_auth',2);
  15. $condition = array();
  16. if (!empty($keyword)){
  17. $condition['user_id|user_phone|user_name'] = array('LIKE','%'.$keyword.'%');
  18. $this->assign('keyword',$keyword);
  19. }
  20. if($is_admin==0){
  21. $condition['admin_id']=0;
  22. }elseif($is_admin==1){
  23. $condition['admin_id']=array('GT',0);
  24. }
  25. if($is_auth!=2){
  26. $Model = M();
  27. $sql = "select a.user_id from ((select user_id from `t_choice` where choice_status=3 and choice_type=2) union all (select user_id from `t_course` where course_status=3)) as a group by a.user_id";
  28. $list = $Model->query($sql);
  29. $ids=array();
  30. foreach($list as $k=>$v){
  31. $ids[]=$v['user_id'];
  32. }
  33. if($is_auth==0){
  34. $condition['user_id']=array('not in',$ids);
  35. }elseif($is_auth==1){
  36. $condition['user_id']=array('in',$ids);
  37. }
  38. }
  39. $this->assign('is_admin',$is_admin);
  40. $this->assign('is_auth',$is_auth);
  41. $count = M('User')->where($condition)->count();
  42. //分页
  43. $Page = new \Think\Page($count);
  44. $show = $Page->show();
  45. $userList = M('User')->where($condition)->field()->order('user_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  46. //获取用户等级
  47. $levelRes = M('UserLevel')->field('level_id,level_name')->select();
  48. $levelList = array();
  49. foreach ($levelRes as $level){
  50. $levelList[$level['level_id']] = $level['level_name'];
  51. }
  52. foreach($userList as $k=>$v){
  53. if($v['forbidden']-time()>0){
  54. $userList[$k]['is_forbidden']=1;
  55. $time=$v['forbidden']-time();
  56. $d = floor($time / (3600*24));
  57. $h = floor(($time % (3600*24)) / 3600);
  58. $m = floor((($time % (3600*24)) % 3600) / 60);
  59. $tmp='';
  60. if($d>'0'){
  61. $tmp=$d.'天'.$h.'小时'.$m.'分';
  62. }else{
  63. if($h!='0'){
  64. $tmp=$h.'小时'.$m.'分';
  65. }else{
  66. $tmp=$m.'分';
  67. }
  68. }
  69. $userList[$k]['str_forbidden']=$tmp;
  70. $userList[$k]['is_forbidden']=1;
  71. }else{
  72. $userList[$k]['str_forbidden']='';
  73. $userList[$k]['is_forbidden']=0;
  74. }
  75. }
  76. $this->assign('page',$show);
  77. $this->assign('list',$userList);
  78. $this->assign('levelList',$levelList);
  79. $this->display();
  80. }
  81. //用户详细信息
  82. public function detail(){
  83. $userId = I('user_id','');
  84. if (empty($userId) || $userId<1000000){
  85. //$this->error("用户ID错误",'/admin/user/index');
  86. }
  87. $userInfo = M('User')->where(array('user_id'=>$userId))->find();
  88. //用户好友
  89. $Model = M();
  90. $count = $Model->field('user_id2')->table('t_user_connect')->where(array('user_id1'=>$userId))
  91. ->union(array('field'=>'user_id1','table'=>'t_user_connect','where'=>array('user_id2'=>$userId)))->count();
  92. //分页
  93. $Page = new \Think\Page($count);
  94. $show = $Page->show();
  95. $userIdList = D('UserConnect')->getConnectUserList($userId, $Page->firstRow, $Page->listRows);
  96. $userList = array();
  97. $userIdArr = array();
  98. if (function_exists('array_column')){
  99. $userIdArr = array_column($userIdList, 'user_id');
  100. }else{
  101. foreach ($userIdList as $row){
  102. $userIdArr[] = $row['user_id'];
  103. }
  104. }
  105. if (count($userIdArr)){
  106. $userList = M('User')->where(array('user_id'=>array('IN',implode(',', $userIdArr))))->field()->order('user_id desc')->select();
  107. }
  108. //获取用户等级
  109. $levelRes = M('UserLevel')->field('level_id,level_name')->select();
  110. $levelList = array();
  111. foreach ($levelRes as $level){
  112. $levelList[$level['level_id']] = $level['level_name'];
  113. }
  114. $areaRes = M('China')->select();
  115. $areaList = array();
  116. foreach ($areaRes as $row){
  117. $areaList[$row['id']] = $row['name'];
  118. }
  119. $this->assign('areaList',$areaList);
  120. $this->assign('levelList',$levelList);
  121. $this->assign('userList',$userList);
  122. $this->assign('userInfo',$userInfo);
  123. $this->display();
  124. }
  125. //用户课程
  126. public function course(){
  127. $courseStatus = I('course_status','');
  128. $userId = I('user_id','');
  129. if (empty($userId) || $userId<1000000){
  130. $this->error("用户ID错误",'/admin/user/index');
  131. }
  132. $condition = array('course_source'=>2,'user_id'=>$userId, 'is_delete'=>1,'course_flag'=>1);
  133. if (!empty($courseStatus)){
  134. $condition['course_status'] = array('IN',$courseStatus);
  135. }
  136. $count = M('Course')->where($condition)->count();
  137. //分页
  138. $Page = new \Think\Page($count);
  139. $show = $Page->show();
  140. $courseList = M('Course')->where($condition)->field()->order('course_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  141. $this->assign('page',$show);
  142. $this->assign('list',$courseList);
  143. $this->display();
  144. }
  145. //用户自由记
  146. public function notepad(){
  147. $courseStatus = I('course_status','');
  148. $userId = I('user_id','');
  149. if (empty($userId) || $userId<1000000){
  150. $this->error("用户ID错误",'/admin/user/index');
  151. }
  152. $condition = array('user_id'=>$userId,'course_flag'=>2, 'is_delete'=>1,'course_source'=>2,);
  153. if (!empty($courseStatus)){
  154. $condition['course_status'] = array('IN',$courseStatus);
  155. }
  156. $count = M('Course')->where($condition)->count();
  157. //分页
  158. $Page = new \Think\Page($count);
  159. $show = $Page->show();
  160. $notepadList = M('Course')->where($condition)->field()->order('course_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  161. $this->assign('page',$show);
  162. $this->assign('list',$notepadList);
  163. $this->display();
  164. }
  165. //用户禁言
  166. public function forbidden(){
  167. $userId = I('user_id','');
  168. $days = I('days','0');
  169. if (empty($userId) || $userId<1000000){
  170. $this->error("用户ID错误",'/admin/user/index');
  171. }
  172. M('user')->where(array('user_id'=>$userId))->save(array('forbidden'=>time()+$days*24*60*60));
  173. }
  174. //设置用户管理员
  175. public function set_admin(){
  176. $userId = I('user_id','');
  177. if (empty($userId) || $userId<1000000){
  178. $this->error("用户ID错误",'/admin/user/index');
  179. }
  180. $userInfo = M('User')->where(array('user_id'=>$userId))->find();
  181. if (!$userInfo){
  182. $this->error("用户ID错误",'/admin/user/index');
  183. }
  184. $adminInfo = M('admin')->where(array('admin_account'=>$userInfo['user_phone']))->find();
  185. if (!$adminInfo){
  186. $data=array();
  187. $data['admin_account']=$userInfo['user_phone'];
  188. $data['admin_pwd']=$userInfo['user_pwd'];
  189. $data['group_id']=1;
  190. $data['operate_dt'] = time();
  191. M('admin')->add($data);
  192. $adminInfo = M('admin')->where($data)->find();
  193. }
  194. $admin_id=$adminInfo['admin_id'];
  195. $uid=$userId;
  196. $noticeContent = '您已被设置为管理员,遇到恶意评论长摁评论可以删除,情节严重可长摁用户ID进行一段时间的禁言。';
  197. $temp=array();
  198. M('Notice')->add(array('ref_user_id'=>$uid,'user_id'=>0,'notice_flag'=>0,'notice_status'=>1,'notice_type'=>0,'notice_title'=>$noticeContent,'notice_content'=>$noticeContent,'operate_dt'=>time(),'extra'=>json_encode($temp)));
  199. M('User')->where(array('user_id'=>$uid))->setInc('sys_notice');
  200. $data = array('type'=>0,'msg'=>$noticeContent,'data'=>array());
  201. $url="http://www.hanlinyuanonline.com/api/choice/push?uid=".$uid."&data=".urlencode(base64_encode(json_encode($data)));
  202. $ch = curl_init();
  203. curl_setopt($ch, CURLOPT_URL, $url);
  204. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  205. $output = curl_exec($ch);
  206. curl_close($ch);
  207. M('user')->where(array('user_id'=>$userId))->save(array('admin_id'=>$admin_id,'is_delete'=>1));
  208. }
  209. //取消用户管理员
  210. public function cancle_admin(){
  211. $userId = I('user_id','');
  212. if (empty($userId) || $userId<1000000){
  213. $this->error("用户ID错误",'/admin/user/index');
  214. }
  215. if($userId==0){
  216. $this->error("超管无法取消",'/admin/user/index');
  217. }
  218. $userInfo = M('User')->where(array('user_id'=>$userId))->find();
  219. if (!$userInfo){
  220. $this->error("用户ID错误",'/admin/user/index');
  221. }
  222. M('admin')->where(array('admin_id'=>$userInfo['admin_id']))->delete();
  223. M('user')->where(array('user_id'=>$userId))->save(array('admin_id'=>0));
  224. }
  225. }