AdminIndexController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-02-17
  10. // +—————————————————————————————————————————————————————————————————————
  11. namespace app\user\controller;
  12. use cmf\controller\AdminBaseController;
  13. use think\Db;
  14. use think\db\Query;
  15. /**
  16. * Class AdminIndexController
  17. * @package app\user\controller
  18. *
  19. * @adminMenuRoot(
  20. * 'name' =>'用户管理',
  21. * 'action' =>'default',
  22. * 'parent' =>'',
  23. * 'display'=> true,
  24. * 'order' => 10,
  25. * 'icon' =>'group',
  26. * 'remark' =>'用户管理'
  27. * )
  28. *
  29. * @adminMenuRoot(
  30. * 'name' =>'用户组',
  31. * 'action' =>'default1',
  32. * 'parent' =>'user/AdminIndex/default',
  33. * 'display'=> true,
  34. * 'order' => 10000,
  35. * 'icon' =>'',
  36. * 'remark' =>'用户组'
  37. * )
  38. */
  39. class AdminIndexController extends AdminBaseController{
  40. /**
  41. * 后台本站用户列表
  42. * @adminMenu(
  43. * 'name' => '本站用户',
  44. * 'parent' => 'default1',
  45. * 'display'=> true,
  46. * 'hasView'=> true,
  47. * 'order' => 10000,
  48. * 'icon' => '',
  49. * 'remark' => '本站用户',
  50. * 'param' => ''
  51. * )
  52. */
  53. public function index(){
  54. $content = hook_one('user_admin_index_view');
  55. if (!empty($content)) {
  56. return $content;
  57. }
  58. $data = $this->request->param();
  59. $map=[];
  60. $map[]=['user_type','=',2];
  61. $start_time=isset($data['start_time']) ? $data['start_time']: '';
  62. $end_time=isset($data['end_time']) ? $data['end_time']: '';
  63. if($start_time!=""){
  64. $map[]=['create_time','>=',strtotime($start_time)];
  65. }
  66. if($end_time!=""){
  67. $map[]=['create_time','<=',strtotime($end_time) + 60*60*24];
  68. }
  69. $ishot=isset($data['ishot']) ? $data['ishot']: '';
  70. if($ishot!=''){
  71. $map[]=['ishot','=',$ishot];
  72. }
  73. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  74. if($keyword!=''){
  75. $map[]=['user_login|user_nicename','like','%'.$keyword.'%'];
  76. }
  77. $uid=isset($data['uid']) ? $data['uid']: '';
  78. if($uid!=''){
  79. $lianguid=getLianguser($uid);
  80. if($lianguid){
  81. $map[]=['id',['=',$uid],['in',$lianguid],'or'];
  82. }else{
  83. $map[]=['id','=',$uid];
  84. }
  85. }
  86. $configpub=getConfigPub();
  87. $nums=Db::name("user")->where($map)->count();
  88. $list = Db::name("user")
  89. ->where($map)
  90. ->order("id desc")
  91. ->paginate(20);
  92. $list->each(function($v,$k){
  93. $v['user_login']=m_s($v['user_login']);
  94. $v['mobile']=m_s($v['mobile']);
  95. $v['user_email']=m_s($v['user_email']);
  96. $v['avatar']=get_upload_path($v['avatar']);
  97. return $v;
  98. });
  99. $list->appends($data);
  100. // 获取分页显示
  101. $page = $list->render();
  102. $this->assign('list', $list);
  103. $this->assign('page', $page);
  104. $this->assign('nowtime', time());
  105. $this->assign('name_coin', $configpub['name_coin']);
  106. $this->assign('name_votes', $configpub['name_votes']);
  107. $this->assign('nums', $nums);
  108. // 渲染模板输出
  109. return $this->fetch();
  110. }
  111. function del(){
  112. $id = $this->request->param('id', 0, 'intval');
  113. $user_login = DB::name('user')->where(["id"=>$id,"user_type"=>2])->value('user_login');
  114. $rs = DB::name('user')->where(["id"=>$id,"user_type"=>2])->delete();
  115. if(!$rs){
  116. $this->error("删除失败!");
  117. }
  118. /* 删除认证 */
  119. DB::name("user_auth")->where("uid='{$id}'")->delete();
  120. /* 删除直播记录 */
  121. DB::name("live")->where("uid='{$id}'")->delete();
  122. DB::name("live_record")->where("uid='{$id}'")->delete();
  123. /* 删除映票记录 */
  124. DB::name("user_voterecord")->where("uid='{$id}'")->delete();
  125. delcache("userinfo_".$id,"token_".$id);
  126. $this->success("删除成功!");
  127. }
  128. /* 热门 */
  129. function sethot(){
  130. $id = $this->request->param('id', 0, 'intval');
  131. $ishot = $this->request->param('ishot', 0, 'intval');
  132. $rs = DB::name('user')->where("id={$id}")->setField('ishot',$ishot);
  133. if(!$rs){
  134. $this->error("操作失败!");
  135. }
  136. DB::name("live")->where(array("uid"=>$id))->setField('ishot',$ishot);
  137. $this->success("操作成功!");
  138. }
  139. function add(){
  140. return $this->fetch();
  141. }
  142. function addPost(){
  143. if ($this->request->isPost()) {
  144. $data = $this->request->param();
  145. $user_login=$data['user_login'];
  146. if($user_login==""){
  147. $this->error("请填写手机号");
  148. }
  149. if(!checkMobile($user_login)){
  150. $this->error("请填写正确手机号");
  151. }
  152. $isexist=DB::name('user')->where(['user_login'=>$user_login])->value('id');
  153. if($isexist){
  154. $this->error("该账号已存在,请更换");
  155. }
  156. $data['mobile']=$user_login;
  157. $user_pass=$data['user_pass'];
  158. if($user_pass==""){
  159. $this->error("请填写密码");
  160. }
  161. if(!passcheck($user_pass)){
  162. $this->error("密码为6-20位字母数字组合");
  163. }
  164. $data['user_pass']=cmf_password($user_pass);
  165. $user_nicename=$data['user_nicename'];
  166. if($user_nicename==""){
  167. $this->error("请填写昵称");
  168. }
  169. $avatar=$data['avatar'];
  170. $avatar_thumb=$data['avatar_thumb'];
  171. if( ($avatar=="" || $avatar_thumb=='' ) && ($avatar!="" || $avatar_thumb!='' )){
  172. $this->error("请同时上传头像 和 头像小图 或 都不上传");
  173. }
  174. if($avatar=='' && $avatar_thumb==''){
  175. $data['avatar']='/default.jpg';
  176. $data['avatar_thumb']='/default_thumb.jpg';
  177. }
  178. $data['avatar']=set_upload_path($data['avatar']);
  179. $data['avatar_thumb']=set_upload_path($data['avatar_thumb']);
  180. $data['user_type']=2;
  181. $data['create_time']=time();
  182. $id = DB::name('user')->insertGetId($data);
  183. if(!$id){
  184. $this->error("添加失败!");
  185. }
  186. $this->success("添加成功!");
  187. }
  188. }
  189. function edit(){
  190. $id = $this->request->param('id', 0, 'intval');
  191. $data=Db::name('user')
  192. ->where("id={$id}")
  193. ->find();
  194. if(!$data){
  195. $this->error("信息错误");
  196. }
  197. $data['user_login']=m_s($data['user_login']);
  198. $this->assign('data', $data);
  199. return $this->fetch();
  200. }
  201. function editPost(){
  202. if ($this->request->isPost()) {
  203. $data = $this->request->param();
  204. $user_pass=$data['user_pass'];
  205. if($user_pass!=""){
  206. if(!passcheck($user_pass)){
  207. $this->error("密码为6-20位字母数字组合");
  208. }
  209. $data['user_pass']=cmf_password($user_pass);
  210. }else{
  211. unset($data['user_pass']);
  212. }
  213. $user_nicename=$data['user_nicename'];
  214. if($user_nicename==""){
  215. $this->error("请填写昵称");
  216. }
  217. if(mb_substr($user_nicename, 0,1)=="="){
  218. $this->error("昵称内容非法");
  219. }
  220. $avatar=$data['avatar'];
  221. $avatar_thumb=$data['avatar_thumb'];
  222. if( ($avatar=="" || $avatar_thumb=='' ) && ($avatar!="" || $avatar_thumb!='' )){
  223. $this->error("请同时上传头像 和 头像小图 或 都不上传");
  224. }
  225. if($avatar=='' && $avatar_thumb==''){
  226. $data['avatar']='/default.jpg';
  227. $data['avatar_thumb']='/default_thumb.jpg';
  228. }
  229. $avatar_old=$data['avatar_old'];
  230. if($avatar_old!=$avatar){
  231. $data['avatar']=set_upload_path($data['avatar']);
  232. }
  233. $avatar_thumb_old=$data['avatar_thumb_old'];
  234. if($avatar_thumb_old!=$avatar_thumb){
  235. $data['avatar_thumb']=set_upload_path($data['avatar_thumb']);
  236. }
  237. unset($data['avatar_old']);
  238. unset($data['avatar_thumb_old']);
  239. $rs = DB::name('user')->update($data);
  240. if($rs===false){
  241. $this->error("修改失败!");
  242. }
  243. //查询用户信息存入缓存中
  244. $info=Db::name("user")
  245. ->field('id,user_nicename,avatar,avatar_thumb,sex,signature,consumption,votestotal,province,city,birthday,user_status,location')
  246. ->where("id={$data['id']} and user_type=2")
  247. ->find();
  248. if($info){
  249. setcaches("userinfo_".$data['id'],$info);
  250. }
  251. $this->success("修改成功!");
  252. }
  253. }
  254. }