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