AdminIndexController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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-04-30
  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. $list = Db::name('user')
  59. ->where(function (Query $query) {
  60. $query->where('user_type','2');
  61. $data = $this->request->param();
  62. if($data['user_status']!=''){
  63. $query->where('user_status', intval($data['user_status']));
  64. }
  65. if($data['isrecommend']!=''){
  66. $query->where('isrecommend', intval($data['isrecommend']));
  67. }
  68. if($data['issuper']!=''){
  69. $query->where('issuper', intval($data['issuper']));
  70. }
  71. if (!empty($data['uid'])) {
  72. $query->where('id', intval($data['uid']));
  73. }
  74. if (!empty($data['keyword'])) {
  75. $keyword = $data['keyword'];
  76. $query->where('user_login|user_nicename|user_email|mobile', 'like', "%$keyword%");
  77. }
  78. })
  79. ->order("create_time DESC")
  80. ->paginate(20);
  81. $now=time();
  82. $list->each(function($v,$k){
  83. $v['user_login']=m_s($v['user_login']);
  84. $v['mobile']=m_s($v['mobile']);
  85. $v['user_email']=m_s($v['user_email']);
  86. if($v['vip_endtime']>$now){
  87. $v['vip_endtime_format']=date("Y-m-d",$v['vip_endtime']);
  88. $v['isvip']=1;
  89. }else{
  90. $v['vip_endtime_format']='--';
  91. $v['isvip']=0;
  92. }
  93. $country_list=$this->getCountrys();
  94. foreach ($country_list as $k1 => $v1) {
  95. if($v['country_code']==$v1['tel']){
  96. $v['country_name']=$v1['name'];
  97. break;
  98. }
  99. }
  100. return $v;
  101. });
  102. //分页-->筛选条件参数
  103. $data = $this->request->param();
  104. $list->appends($data);
  105. // 获取分页显示
  106. $page = $list->render();
  107. $this->assign('list', $list);
  108. $this->assign('page', $page);
  109. // 渲染模板输出
  110. return $this->fetch();
  111. }
  112. /*本站用户添加*/
  113. public function add(){
  114. $this->assign('country_list', $this->getCountrys());
  115. // 渲染模板输出
  116. return $this->fetch();
  117. }
  118. public function add_post(){
  119. if ($this->request->isPost()) {
  120. $data = $this->request->param();
  121. $user= Db::name('user');
  122. $country_code=$data['country_code'];
  123. $user_login=$data['user_login'];
  124. if(!$country_code){
  125. $this->error(lang("请选择国家/地区"));
  126. }
  127. if($user_login == ''){
  128. $this->error('请输入手机号');
  129. }else{
  130. if(!checkMobile($user_login)){
  131. $this->error('请输入正确手机号');
  132. }
  133. $check = Db::name('user')
  134. ->where(['user_login'=>$user_login,'country_code'=>$country_code])
  135. ->find();
  136. if($check){
  137. $this->error('该账号已存在');
  138. }
  139. }
  140. $user_nicename=$data['user_nicename'];
  141. if($user_nicename == ''){
  142. $this->error('请输入昵称');
  143. }else{
  144. $check = Db::name('user')
  145. ->where("user_nicename='{$user_nicename}'")
  146. ->find();
  147. if($check){
  148. $this->error('昵称已存在');
  149. }
  150. }
  151. $data['user_type']=2;
  152. $data['user_pass']=cmf_password($data['user_pass']);
  153. $data['code']=createCode();
  154. $avatar=$data['avatar'];
  155. if($avatar==''){
  156. $data['avatar']= '/default.png';
  157. $data['avatar_thumb']= '/default_thumb.png';
  158. if($data['bg_img']==''){
  159. $data['bg_img']= '/default.png';
  160. }
  161. }else if(strpos($avatar,'http')===0){
  162. /* 绝对路径 */
  163. $data['avatar']= $avatar;
  164. $data['avatar_thumb']= $avatar;
  165. if($data['bg_img']==''){
  166. $data['bg_img']= $avatar;
  167. }
  168. }else if(strpos($avatar,'/')===0){
  169. /* 本地图片 */
  170. $data['avatar']= $avatar;
  171. $data['avatar_thumb']= $avatar;
  172. if($data['bg_img']==''){
  173. $data['bg_img']= $avatar;
  174. }
  175. }
  176. $data['create_time']=time();
  177. $data['birthday']='2000-01-01';
  178. if(trim($data['signature'])==""){
  179. $data['signature']='这家伙很懒,什么都没留下';
  180. }
  181. $result=$user->insert($data);
  182. if($result!==false){
  183. $this->success('添加成功');
  184. }else{
  185. $this->error('添加失败');
  186. }
  187. }
  188. }
  189. //编辑
  190. public function edit(){
  191. $id = $this->request->param('id', 0, 'intval');
  192. $data=Db::name('user')
  193. ->where("id={$id}")
  194. ->find();
  195. if(!$data){
  196. $this->error("信息错误");
  197. }
  198. $this->assign('data', $data);
  199. $this->assign('country_list', $this->getCountrys());
  200. return $this->fetch();
  201. }
  202. public function editPost()
  203. {
  204. if ($this->request->isPost()) {
  205. $data = $this->request->param();
  206. $id=$data['id'];
  207. //获取用户的状态
  208. $user_status=Db::name("user")->where("id={$data['id']}")->value("user_status");
  209. $country_code=$data['country_code'];
  210. if(!$country_code){
  211. $this->error(lang("请选择国家/地区"));
  212. }
  213. $user_pass=$data['user_pass'];
  214. if($user_pass==''){
  215. unset($data['user_pass']);
  216. }else{
  217. $data['user_pass'] = cmf_password($user_pass);
  218. }
  219. $user_nicename=$data['user_nicename'];
  220. if($user_nicename == ''){
  221. $this->error('请输入昵称');
  222. }else if($user_status!=3 && strstr($user_nicename, '已注销')!==false){
  223. $this->error('非注销用户昵称不能包含已注销');
  224. }
  225. if($data['avatar']==''){
  226. $this->error('请上传头像/封面');
  227. }
  228. if($data['avatar_thumb']==''){
  229. $this->error('请上传头像缩略图');
  230. }
  231. if($data['bg_img']==''){
  232. $data['bg_img']=$data['avatar'];
  233. }
  234. $rs = DB::name('user')->update($data);
  235. if($rs === false){
  236. $this->error("保存失败!");
  237. }
  238. // $key='userinfo_'.$id;
  239. // delcache($key);
  240. $this->success("保存成功!");
  241. }
  242. }
  243. //删除用户
  244. public function del(){
  245. $id = $this->request->param('id', 0, 'intval');
  246. $rs = DB::name('user')->where("id={$id}")->delete();
  247. if(!$rs){
  248. $this->error("删除失败!");
  249. }
  250. //删除关注列表
  251. Db::name("user_attention")->where("uid='{$id}' or touid='{$id}'")->delete();
  252. //删除关注消息
  253. Db::name("user_attention_messages")->where("uid='{$id}' or touid='{$id}'")->delete();
  254. //删除用户认证信息
  255. Db::name("user_auth")->where("uid='{$id}'")->delete();
  256. //删除用户拉黑
  257. Db::name("user_black")->where("uid='{$id}' or touid='{$id}'")->delete();
  258. //删除管理员充值用户记录
  259. Db::name("user_charge_admin")->where("touid='{$id}'")->delete();
  260. //删除音乐收藏
  261. Db::name("user_music_collection")->where("uid='{$id}'")->delete();
  262. //删除用户举报
  263. Db::name("user_report")->where("uid='{$id}' or touid='{$id}'")->delete();
  264. //删除用户token
  265. Db::name("user_token")->where("user_id='{$id}'")->delete();
  266. $list=Db::name("user_video")->field("id")->where("uid='{$id}'")->select()->toArray();
  267. foreach ($list as $k => $v) {
  268. //删除视频喜欢
  269. Db::name("user_video_like")->where("videoid='{$v['id']}'")->delete();
  270. }
  271. //删除用户视频
  272. Db::name("user_video")->where("uid='{$id}'")->delete();
  273. //删除视频评论
  274. Db::name("user_video_comments")->where("uid='{$id}' or touid='{$id}'")->delete();
  275. //删除视频评论@信息
  276. Db::name("user_video_comments_at_messages")->where("uid='{$id}' or touid='{$id}'")->delete();
  277. //删除视频评论点赞
  278. Db::name("user_video_comments_like")->where("uid='{$id}' or touid='{$id}'")->delete();
  279. //删除视频评论信息
  280. Db::name("user_video_comments_messages")->where("uid='{$id}' or touid='{$id}'")->delete();
  281. //删除视频喜欢
  282. Db::name("user_video_like")->where("uid='{$id}'")->delete();
  283. //删除视频付费列表
  284. Db::name("user_video_paylists")->where("uid='{$id}'")->delete();
  285. //删除视频举报
  286. Db::name("user_video_report")->where("uid='{$id}' or touid='{$id}'")->delete();
  287. //删除视频观看记录
  288. Db::name("user_video_view")->where("uid='{$id}'")->delete();
  289. //删除用户视频观看记录
  290. Db::name("user_video_watchlists")->where("uid='{$id}'")->delete();
  291. //删除用户视频观看时间记录
  292. Db::name("user_video_watchtime")->where("uid='{$id}'")->delete();
  293. //删除视频观看时长记录
  294. Db::name("view_reward")->where("uid='{$id}'")->delete();
  295. //删除反馈
  296. Db::name("feedback")->where("uid='{$id}'")->delete();
  297. //删除点赞信息表
  298. Db::name("praise_messages")->where("uid='{$id}' or touid='{$id}'")->delete();
  299. //删除系统消息
  300. Db::name("system_push")->where("uid='{$id}'")->delete();
  301. //删除用户的redis
  302. delcache("token_".$id);
  303. $this->success("删除成功!",url("user/adminIndex/index"));
  304. }
  305. /**
  306. * 本站用户禁用
  307. * @adminMenu(
  308. * 'name' => '本站用户禁用',
  309. * 'parent' => 'index',
  310. * 'display'=> false,
  311. * 'hasView'=> false,
  312. * 'order' => 10000,
  313. * 'icon' => '',
  314. * 'remark' => '本站用户禁用',
  315. * 'param' => ''
  316. * )
  317. */
  318. public function ban(){
  319. $id = input('param.id', 0, 'intval');
  320. if ($id) {
  321. $result = Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 0);
  322. if ($result) {
  323. $this->success("会员禁用成功!");
  324. } else {
  325. $this->error('会员禁用失败,会员不存在,或者是管理员!');
  326. }
  327. } else {
  328. $this->error('数据传入失败!');
  329. }
  330. }
  331. /**
  332. * 本站用户启用
  333. * @adminMenu(
  334. * 'name' => '本站用户启用',
  335. * 'parent' => 'index',
  336. * 'display'=> false,
  337. * 'hasView'=> false,
  338. * 'order' => 10000,
  339. * 'icon' => '',
  340. * 'remark' => '本站用户启用',
  341. * 'param' => ''
  342. * )
  343. */
  344. public function cancelBan(){
  345. $id = input('param.id', 0, 'intval');
  346. if ($id) {
  347. Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 1);
  348. $this->success("会员启用成功!", '');
  349. } else {
  350. $this->error('数据传入失败!');
  351. }
  352. }
  353. public function getCountrys(){
  354. //读取国家代号
  355. $key='getCountrys';
  356. $info=getcaches($key);
  357. //$info=false;
  358. if(!$info){
  359. $country=CMF_ROOT.'data/config/country.json';
  360. // 从文件中读取数据到PHP变量
  361. $json_string = file_get_contents($country);
  362. // 用参数true把JSON字符串强制转成PHP数组
  363. $data = json_decode($json_string, true);
  364. $info=$data['country']; //国家
  365. setcaches($key,$info);
  366. }
  367. $country_list=[];
  368. foreach ($info as $k => $v) {
  369. $arr=$v['lists'];
  370. foreach ($arr as $k1 => $v1) {
  371. $country_list[]=$v1;
  372. }
  373. }
  374. return $country_list;
  375. }
  376. }