AdminIndexController.php 8.1 KB

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