AdminIndexController.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. $count = Db::name('user')
  75. ->where(function (Query $query) {
  76. $data = $this->request->param();
  77. $query->where('user_type', 2);
  78. $query->where('is_complete', 1);
  79. if (!empty($data['uid'])) {
  80. $query->where('id', intval($data['uid']));
  81. }
  82. if (!empty($data['keyword'])) {
  83. $keyword = $data['keyword'];
  84. $query->where('username', 'like', "%$keyword%");
  85. }
  86. if (!empty($data['sex'])) {
  87. $query->where('sex', $data['sex']);
  88. }
  89. if (!empty($data['is_complete'])) {
  90. $query->where('is_complete', $data['is_complete']);
  91. }
  92. if (!empty($data['check_status'])) {
  93. $query->where('check_status', $data['check_status']);
  94. }
  95. })
  96. ->count();
  97. $this->assign('total',$count);
  98. $list = Db::name('user')
  99. ->where(function (Query $query) {
  100. $data = $this->request->param();
  101. $query->where('user_type', 2);
  102. $query->where('is_complete', 1);
  103. if (!empty($data['uid'])) {
  104. $query->where('id', intval($data['uid']));
  105. }
  106. if (!empty($data['keyword'])) {
  107. $keyword = $data['keyword'];
  108. $query->where('username', 'like', "%$keyword%");
  109. }
  110. if (!empty($data['sex'])) {
  111. $query->where('sex', $data['sex']);
  112. }
  113. if (!empty($data['is_complete'])) {
  114. $query->where('is_complete', $data['is_complete']);
  115. }
  116. if (!empty($data['check_status'])) {
  117. $query->where('check_status', $data['check_status']);
  118. }
  119. })
  120. ->order("check_status asc,create_time DESC")
  121. ->paginate(10, false, [
  122. 'query' => Request::param(),//不丢失已存在的url参数
  123. ]);
  124. $this->assign('sex', $this->request->param('sex') ?: 0);
  125. $this->assign('is_complete', $this->request->param('is_complete') ?: 0);
  126. $this->assign('check_status', $this->request->param('check_status') ?: 0);
  127. // 获取分页显示
  128. $page = $list->render();
  129. $this->assign('list', $list);
  130. $this->assign('page', $page);
  131. // 渲染模板输出
  132. return $this->fetch();
  133. }
  134. /**
  135. * 审核
  136. */
  137. public function checkPost()
  138. {
  139. $data = $this->request->post();
  140. UserModel::update($data, ['id' => $data['id']]);
  141. $this->success('操作成功');
  142. }
  143. /**
  144. * 详情
  145. */
  146. public function show()
  147. {
  148. //获取id
  149. $id = input('param.id');
  150. if (empty($id)) {
  151. $this->error(lang('信息不存在或已删除'));
  152. }
  153. //获取信息
  154. $info = UserModel::get($id);
  155. $info['family'] = $info['family'] ? implode(',', json_decode($info['family'], true)) : '未填写';
  156. $info['have_house'] = Constant::COND_TINYINT[$info['have_house']];
  157. $info['have_car'] = Constant::COND_TINYINT[$info['have_car']];
  158. $info['with_parent_live'] = Constant::COND_TINYINT[$info['with_parent_live']];
  159. if (empty($info)) {
  160. $this->error(lang('信息不存在或已删除'));
  161. }
  162. $this->assign('info', $info);
  163. $mating = UserMatingModel::get(['user_id' => $id]);
  164. $mating['have_house'] = Constant::COND_TINYINT[$mating['have_house']];
  165. $mating['have_car'] = Constant::COND_TINYINT[$mating['have_car']];
  166. $mating['with_parent_live'] = Constant::COND_TINYINT[$mating['with_parent_live']];
  167. $this->assign('mating', $mating);
  168. return $this->fetch();
  169. }
  170. /**
  171. * 本站用户拉黑
  172. * @adminMenu(
  173. * 'name' => '本站用户拉黑',
  174. * 'parent' => 'index',
  175. * 'display'=> false,
  176. * 'hasView'=> false,
  177. * 'order' => 10000,
  178. * 'icon' => '',
  179. * 'remark' => '本站用户拉黑',
  180. * 'param' => ''
  181. * )
  182. */
  183. public function ban()
  184. {
  185. $id = input('param.id', 0, 'intval');
  186. if ($id) {
  187. $result = Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 0);
  188. if ($result) {
  189. $this->success("会员拉黑成功!", "adminIndex/index");
  190. } else {
  191. $this->error('会员拉黑失败,会员不存在,或者是管理员!');
  192. }
  193. } else {
  194. $this->error('数据传入失败!');
  195. }
  196. }
  197. /**
  198. * 本站用户启用
  199. * @adminMenu(
  200. * 'name' => '本站用户启用',
  201. * 'parent' => 'index',
  202. * 'display'=> false,
  203. * 'hasView'=> false,
  204. * 'order' => 10000,
  205. * 'icon' => '',
  206. * 'remark' => '本站用户启用',
  207. * 'param' => ''
  208. * )
  209. */
  210. public function cancelBan()
  211. {
  212. $id = input('param.id', 0, 'intval');
  213. if ($id) {
  214. Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 1);
  215. $this->success("会员启用成功!", '');
  216. } else {
  217. $this->error('数据传入失败!');
  218. }
  219. }
  220. /**
  221. * 删除用户
  222. */
  223. public function delete()
  224. {
  225. $id = input('param.id', 0, 'intval');
  226. if ($id > 1) {
  227. Db::startTrans();
  228. try {
  229. UserModel::destroy($id);
  230. ActiveApplyModel::where('user_id', $id)->delete();
  231. UserFavoriteModel::where('user_id|uid', '=', $id)->delete();
  232. UserFriendModel::where('user_id|friend_id', '=', $id)->delete();
  233. UserGiftModel::where('from_id|to_id', '=', $id)->delete();
  234. UserInviteModel::where('from_id|to_id', '=', $id)->delete();
  235. UserLikeModel::where('user_id', '=', $id)->delete();
  236. UserMatingModel::where('user_id', '=', $id)->delete();
  237. UserMessageModel::where('from_id|to_id', '=', $id)->delete();
  238. UserSelectModel::where('user_id|uid', '=', $id)->delete();
  239. UserSelectLogModel::where('user_id1|user_id2', '=', $id)->delete();
  240. Db::name('user_token')->where('user_id', '=', $id)->delete();
  241. UserVisitModel::where('from_id|to_id', '=', $id)->delete();
  242. Db::commit();
  243. } catch (\Exception $e) {
  244. //回滚事务
  245. Db::rollback();
  246. $this->error('会员删除失败,会员不存在,或者是管理员!');
  247. }
  248. $this->success("会员删除成功!", "adminIndex/index");
  249. } else {
  250. $this->error('数据传入失败!');
  251. }
  252. }
  253. }