AdminIndexController.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: Powerless < wzxaini9@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\user\controller;
  12. use api\user\model\UserLikeModel;
  13. use app\common\Constant;
  14. use app\love\model\ActiveApplyModel;
  15. use app\love\model\UserFriendModel;
  16. use app\love\model\UserGiftModel;
  17. use app\love\model\UserInviteModel;
  18. use app\love\model\UserMatingModel;
  19. use app\love\model\UserMessageModel;
  20. use app\love\model\UserSelectLogModel;
  21. use app\love\model\UserSelectModel;
  22. use app\love\model\UserVisitModel;
  23. use app\user\model\UserFavoriteModel;
  24. use app\user\model\UserModel;
  25. use cmf\controller\AdminBaseController;
  26. use think\Db;
  27. use think\db\Query;
  28. use \think\facade\Request;
  29. /**
  30. * Class AdminIndexController
  31. * @package app\user\controller
  32. *
  33. * @adminMenuRoot(
  34. * 'name' =>'用户管理',
  35. * 'action' =>'default',
  36. * 'parent' =>'',
  37. * 'display'=> true,
  38. * 'order' => 10,
  39. * 'icon' =>'group',
  40. * 'remark' =>'用户管理'
  41. * )
  42. *
  43. * @adminMenuRoot(
  44. * 'name' =>'用户组',
  45. * 'action' =>'default1',
  46. * 'parent' =>'user/AdminIndex/default',
  47. * 'display'=> true,
  48. * 'order' => 10000,
  49. * 'icon' =>'',
  50. * 'remark' =>'用户组'
  51. * )
  52. */
  53. class AdminIndexController extends AdminBaseController
  54. {
  55. /**
  56. * 后台本站用户列表
  57. * @adminMenu(
  58. * 'name' => '本站用户',
  59. * 'parent' => 'default1',
  60. * 'display'=> true,
  61. * 'hasView'=> true,
  62. * 'order' => 10000,
  63. * 'icon' => '',
  64. * 'remark' => '本站用户',
  65. * 'param' => ''
  66. * )
  67. */
  68. public function index()
  69. {
  70. $content = hook_one('user_admin_index_view');
  71. if (!empty($content)) {
  72. return $content;
  73. }
  74. $list = Db::name('user')
  75. ->where(function (Query $query) {
  76. $data = $this->request->param();
  77. $query->where('user_type', 2);
  78. if (!empty($data['uid'])) {
  79. $query->where('id', intval($data['uid']));
  80. }
  81. if (!empty($data['keyword'])) {
  82. $keyword = $data['keyword'];
  83. $query->where('username', 'like', "%$keyword%");
  84. }
  85. if (!empty($data['department'])) {
  86. $query->where('department', $data['department']);
  87. }
  88. if (!empty($data['sex'])) {
  89. $query->where('sex', $data['sex']);
  90. }
  91. if (!empty($data['is_complete'])) {
  92. $query->where('is_complete', $data['is_complete']);
  93. }
  94. if (!empty($data['check_status'])) {
  95. $query->where('check_status', $data['check_status']);
  96. }
  97. })
  98. ->order("check_status asc,create_time DESC")
  99. ->paginate(10, false, [
  100. 'query' => Request::param(),//不丢失已存在的url参数
  101. ]);
  102. $this->assign('department', $this->request->param('department') ?: '');
  103. $this->assign('department_list',Constant::DEPARTMENT);
  104. $this->assign('sex', $this->request->param('sex') ?: 0);
  105. $this->assign('is_complete', $this->request->param('is_complete') ?: 0);
  106. $this->assign('check_status', $this->request->param('check_status') ?: 0);
  107. // 获取分页显示
  108. $page = $list->render();
  109. $this->assign('list', $list);
  110. $this->assign('page', $page);
  111. // 渲染模板输出
  112. return $this->fetch();
  113. }
  114. /**
  115. * 审核
  116. */
  117. public function checkPost()
  118. {
  119. $data = $this->request->post();
  120. UserModel::update($data, ['id' => $data['id']]);
  121. $this->success('操作成功');
  122. }
  123. /**
  124. * 详情
  125. */
  126. public function show()
  127. {
  128. //获取id
  129. $id = input('param.id');
  130. if (empty($id)) {
  131. $this->error(lang('信息不存在或已删除'));
  132. }
  133. //获取信息
  134. $info = UserModel::get($id);
  135. $info['family'] = $info['family'] ? implode(',', json_decode($info['family'], true)) : '未填写';
  136. if (empty($info)) {
  137. $this->error(lang('信息不存在或已删除'));
  138. }
  139. $this->assign('info', $info);
  140. $mating = UserMatingModel::get(['user_id' => $id]);
  141. $this->assign('mating', $mating);
  142. return $this->fetch();
  143. }
  144. /**
  145. * 本站用户拉黑
  146. * @adminMenu(
  147. * 'name' => '本站用户拉黑',
  148. * 'parent' => 'index',
  149. * 'display'=> false,
  150. * 'hasView'=> false,
  151. * 'order' => 10000,
  152. * 'icon' => '',
  153. * 'remark' => '本站用户拉黑',
  154. * 'param' => ''
  155. * )
  156. */
  157. public function ban()
  158. {
  159. $id = input('param.id', 0, 'intval');
  160. if ($id) {
  161. $result = Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 0);
  162. if ($result) {
  163. $this->success("会员拉黑成功!", "adminIndex/index");
  164. } else {
  165. $this->error('会员拉黑失败,会员不存在,或者是管理员!');
  166. }
  167. } else {
  168. $this->error('数据传入失败!');
  169. }
  170. }
  171. /**
  172. * 本站用户启用
  173. * @adminMenu(
  174. * 'name' => '本站用户启用',
  175. * 'parent' => 'index',
  176. * 'display'=> false,
  177. * 'hasView'=> false,
  178. * 'order' => 10000,
  179. * 'icon' => '',
  180. * 'remark' => '本站用户启用',
  181. * 'param' => ''
  182. * )
  183. */
  184. public function cancelBan()
  185. {
  186. $id = input('param.id', 0, 'intval');
  187. if ($id) {
  188. Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 1);
  189. $this->success("会员启用成功!", '');
  190. } else {
  191. $this->error('数据传入失败!');
  192. }
  193. }
  194. /**
  195. * 删除用户
  196. */
  197. public function delete()
  198. {
  199. $id = input('param.id', 0, 'intval');
  200. if ($id > 1) {
  201. Db::startTrans();
  202. try {
  203. UserModel::destroy($id);
  204. ActiveApplyModel::where('user_id', $id)->delete();
  205. UserFavoriteModel::where('user_id|uid', '=', $id)->delete();
  206. UserFriendModel::where('user_id|friend_id', '=', $id)->delete();
  207. UserGiftModel::where('from_id|to_id', '=', $id)->delete();
  208. UserInviteModel::where('from_id|to_id', '=', $id)->delete();
  209. UserLikeModel::where('user_id', '=', $id)->delete();
  210. UserMatingModel::where('user_id', '=', $id)->delete();
  211. UserMessageModel::where('from_id|to_id', '=', $id)->delete();
  212. UserSelectModel::where('user_id|uid', '=', $id)->delete();
  213. UserSelectLogModel::where('user_id1|user_id2', '=', $id)->delete();
  214. Db::name('user_token')->where('user_id', '=', $id)->delete();
  215. UserVisitModel::where('from_id|to_id', '=', $id)->delete();
  216. Db::commit();
  217. } catch (\Exception $e) {
  218. //回滚事务
  219. Db::rollback();
  220. $this->error('会员删除失败,会员不存在,或者是管理员!');
  221. }
  222. $this->success("会员删除成功!", "adminIndex/index");
  223. } else {
  224. $this->error('数据传入失败!');
  225. }
  226. }
  227. }