AdminIndexController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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\common\Excel;
  15. use app\common\Fun;
  16. use app\love\model\ActiveApplyModel;
  17. use app\love\model\UserFollowModel;
  18. use app\love\model\UserFriendModel;
  19. use app\love\model\UserGiftModel;
  20. use app\love\model\UserInviteModel;
  21. use app\love\model\UserMatingModel;
  22. use app\love\model\UserMessageModel;
  23. use app\love\model\UserSelectLogModel;
  24. use app\love\model\UserSelectModel;
  25. use app\love\model\UserVisitModel;
  26. use app\user\model\UserFavoriteModel;
  27. use app\user\model\UserModel;
  28. use cmf\controller\AdminBaseController;
  29. use think\Db;
  30. use think\db\Query;
  31. use \think\facade\Request;
  32. /**
  33. * Class AdminIndexController
  34. * @package app\user\controller
  35. *
  36. * @adminMenuRoot(
  37. * 'name' =>'用户管理',
  38. * 'action' =>'default',
  39. * 'parent' =>'',
  40. * 'display'=> true,
  41. * 'order' => 10,
  42. * 'icon' =>'group',
  43. * 'remark' =>'用户管理'
  44. * )
  45. *
  46. * @adminMenuRoot(
  47. * 'name' =>'用户组',
  48. * 'action' =>'default1',
  49. * 'parent' =>'user/AdminIndex/default',
  50. * 'display'=> true,
  51. * 'order' => 10000,
  52. * 'icon' =>'',
  53. * 'remark' =>'用户组'
  54. * )
  55. */
  56. class AdminIndexController extends AdminBaseController
  57. {
  58. /**
  59. * 后台本站用户列表
  60. * @adminMenu(
  61. * 'name' => '本站用户',
  62. * 'parent' => 'default1',
  63. * 'display'=> true,
  64. * 'hasView'=> true,
  65. * 'order' => 10000,
  66. * 'icon' => '',
  67. * 'remark' => '本站用户',
  68. * 'param' => ''
  69. * )
  70. */
  71. public function index()
  72. {
  73. $content = hook_one('user_admin_index_view');
  74. if (!empty($content)) {
  75. return $content;
  76. }
  77. $count = Db::name('user')
  78. ->where(function (Query $query) {
  79. $data = $this->request->param();
  80. $query->where('user_type', 2);
  81. $query->where('is_complete', 1);
  82. if (!empty($data['uid'])) {
  83. $query->where('id', intval($data['uid']));
  84. }
  85. if (!empty($data['keyword'])) {
  86. $keyword = $data['keyword'];
  87. $query->where('realname', 'like', "%$keyword%");
  88. }
  89. if (!empty($data['sex'])) {
  90. $query->where('sex', $data['sex']);
  91. }
  92. if (!empty($data['check_status'])) {
  93. $query->where('check_status', $data['check_status']);
  94. }
  95. if (!empty($data['want_status'])) {
  96. $query->where('want_status', $data['want_status']);
  97. }
  98. })
  99. ->count();
  100. $this->assign('total', $count);
  101. $list = Db::name('user')
  102. ->where(function (Query $query) {
  103. $data = $this->request->param();
  104. $query->where('user_type', 2);
  105. $query->where('is_complete', 1);
  106. if (!empty($data['uid'])) {
  107. $query->where('id', intval($data['uid']));
  108. }
  109. if (!empty($data['keyword'])) {
  110. $keyword = $data['keyword'];
  111. $query->where('realname', 'like', "%$keyword%");
  112. }
  113. if (!empty($data['sex'])) {
  114. $query->where('sex', $data['sex']);
  115. }
  116. if (!empty($data['check_status'])) {
  117. $query->where('check_status', $data['check_status']);
  118. }
  119. if (!empty($data['want_status'])) {
  120. $query->where('want_status', $data['want_status']);
  121. }
  122. })
  123. ->order("check_status asc,create_time DESC")
  124. ->paginate(10, false, [
  125. 'query' => Request::param(),//不丢失已存在的url参数
  126. ]);
  127. $this->assign('sex', $this->request->param('sex') ?: 0);
  128. $this->assign('is_complete', $this->request->param('is_complete') ?: 0);
  129. $this->assign('check_status', $this->request->param('check_status') ?: 0);
  130. $this->assign('want_status', $this->request->param('want_status') ?: 0);
  131. // 获取分页显示
  132. $page = $list->render();
  133. $this->assign('list', $list);
  134. $this->assign('page', $page);
  135. // 渲染模板输出
  136. return $this->fetch();
  137. }
  138. /**
  139. * 审核
  140. */
  141. public function checkPost()
  142. {
  143. $data = $this->request->post();
  144. UserModel::update($data, ['id' => $data['id']]);
  145. $this->success('操作成功');
  146. }
  147. /**
  148. * 详情
  149. */
  150. public function show()
  151. {
  152. //获取id
  153. $id = input('param.id');
  154. if (empty($id)) {
  155. $this->error(lang('信息不存在或已删除'));
  156. }
  157. //获取信息
  158. $info = UserModel::get($id);
  159. $info['family'] = $info['family'] ? implode(',', json_decode($info['family'], true)) : '未填写';
  160. $info['have_house'] = Constant::TINYINT[$info['have_house']];
  161. $info['have_car'] = Constant::TINYINT[$info['have_car']];
  162. $info['with_parent_live'] = Constant::TINYINT[$info['with_parent_live']];
  163. $info['want_birth'] = Constant::TINYINT[$info['want_birth']];
  164. if (empty($info)) {
  165. $this->error(lang('信息不存在或已删除'));
  166. }
  167. $this->assign('info', $info);
  168. $mating = UserMatingModel::get(['user_id' => $id]);
  169. $mating['have_house'] = Constant::COND_TINYINT[$mating['have_house']];
  170. $mating['have_car'] = Constant::COND_TINYINT[$mating['have_car']];
  171. $mating['with_parent_live'] = Constant::COND_TINYINT[$mating['with_parent_live']];
  172. $mating['want_birth'] = Constant::COND_TINYINT[$mating['want_birth']];
  173. if (empty($mating)) {
  174. $mating['animal_text'] = '';
  175. } else {
  176. $mating['animal_text'] = implode(',', $mating['animal']);
  177. }
  178. $this->assign('mating', $mating);
  179. return $this->fetch();
  180. }
  181. /**
  182. * 本站用户拉黑
  183. * @adminMenu(
  184. * 'name' => '本站用户拉黑',
  185. * 'parent' => 'index',
  186. * 'display'=> false,
  187. * 'hasView'=> false,
  188. * 'order' => 10000,
  189. * 'icon' => '',
  190. * 'remark' => '本站用户拉黑',
  191. * 'param' => ''
  192. * )
  193. */
  194. public function ban()
  195. {
  196. $id = input('param.id', 0, 'intval');
  197. if ($id) {
  198. $result = Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 0);
  199. if ($result) {
  200. $this->success("会员拉黑成功!", "adminIndex/index");
  201. } else {
  202. $this->error('会员拉黑失败,会员不存在,或者是管理员!');
  203. }
  204. } else {
  205. $this->error('数据传入失败!');
  206. }
  207. }
  208. /**
  209. * 本站用户启用
  210. * @adminMenu(
  211. * 'name' => '本站用户启用',
  212. * 'parent' => 'index',
  213. * 'display'=> false,
  214. * 'hasView'=> false,
  215. * 'order' => 10000,
  216. * 'icon' => '',
  217. * 'remark' => '本站用户启用',
  218. * 'param' => ''
  219. * )
  220. */
  221. public function cancelBan()
  222. {
  223. $id = input('param.id', 0, 'intval');
  224. if ($id) {
  225. Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 1);
  226. $this->success("会员启用成功!", '');
  227. } else {
  228. $this->error('数据传入失败!');
  229. }
  230. }
  231. /**
  232. * 删除用户
  233. */
  234. public function delete()
  235. {
  236. $id = input('param.id', 0, 'intval');
  237. if ($id > 1) {
  238. Db::startTrans();
  239. try {
  240. UserModel::destroy($id);
  241. ActiveApplyModel::where('user_id', $id)->delete();
  242. UserFavoriteModel::where('user_id|uid', '=', $id)->delete();
  243. UserFriendModel::where('user_id|friend_id', '=', $id)->delete();
  244. UserGiftModel::where('from_id|to_id', '=', $id)->delete();
  245. UserInviteModel::where('from_id|to_id', '=', $id)->delete();
  246. UserLikeModel::where('user_id', '=', $id)->delete();
  247. UserMatingModel::where('user_id', '=', $id)->delete();
  248. UserMessageModel::where('from_id|to_id', '=', $id)->delete();
  249. UserSelectModel::where('user_id|uid', '=', $id)->delete();
  250. UserSelectLogModel::where('user_id1|user_id2', '=', $id)->delete();
  251. Db::name('user_token')->where('user_id', '=', $id)->delete();
  252. UserVisitModel::where('from_id|to_id', '=', $id)->delete();
  253. Db::commit();
  254. } catch (\Exception $e) {
  255. //回滚事务
  256. Db::rollback();
  257. $this->error('会员删除失败,会员不存在,或者是管理员!');
  258. }
  259. $this->success("会员删除成功!", "adminIndex/index");
  260. } else {
  261. $this->error('数据传入失败!');
  262. }
  263. }
  264. /**
  265. * 导出
  266. */
  267. public function export()
  268. {
  269. $data = $this->request->param();
  270. $where = [
  271. ['user_type', '=', 2],
  272. ['is_complete', '=', 1],
  273. ];
  274. if (!empty($data['uid'])) {
  275. $where[] = ['id', '=', intval($data['uid'])];
  276. }
  277. if (!empty($data['keyword'])) {
  278. $where[] = ['realname', 'like', "%{$data['keyword']}%"];
  279. }
  280. if (!empty($data['sex'])) {
  281. $where[] = ['sex', '=', $data['sex']];
  282. }
  283. if (!empty($data['check_status'])) {
  284. $where[] = ['check_status', '=', $data['check_status']];
  285. }
  286. $list = UserModel::where($where)->order("check_status asc,create_time DESC")->select();
  287. $data = [];
  288. foreach ($list as $v) {
  289. $data[] = [
  290. 'name' => $v['realname'],
  291. 'sex' => $v['sex_text'],
  292. 'age' => Fun::getAgeByBirth($v['birthday']),
  293. 'mobile' => $v['mobile'],
  294. 'company' => $v['company'],
  295. 'id_type' => $v['id_type'],
  296. 'native' => $v['native'],
  297. 'marry' => $v['marry'],
  298. ];
  299. }
  300. if (empty($data)) {
  301. return '暂无数据';
  302. }
  303. $excel = new Excel();
  304. $title = [
  305. ['name', '姓名'],
  306. ['sex', '性别'],
  307. ['age', '年龄'],
  308. ['mobile', '电话'],
  309. ['company', '单位'],
  310. ['id_type', '身份类型'],
  311. ['native', '籍贯'],
  312. ['marry', '婚姻状况'],
  313. ];
  314. $excel->export('本站用户', $title, $data, ['mobile']);
  315. }
  316. public function follow()
  317. {
  318. //获取id
  319. $id = input('param.id');
  320. if (empty($id)) {
  321. $this->error(lang('信息不存在或已删除'));
  322. }
  323. $list = UserFollowModel::where('user_id', $id)->order('create_time desc')->select();
  324. $this->assign('list', $list);
  325. return $this->fetch();
  326. }
  327. public function statusPost()
  328. {
  329. $data = $this->request->post();
  330. if (empty($data['user_id'])) {
  331. $this->error('请选择用户');
  332. }
  333. if (empty($data['status'])) {
  334. $this->error('请选择状态');
  335. }
  336. //数据初始化
  337. $admin = UserModel::get(cmf_get_current_admin_id());
  338. $user = UserModel::get($data['user_id']);
  339. $status_list = ['', '单身不愿意推荐', '单身愿意推荐', '热恋', '已婚'];
  340. $start_status = $status_list[$user['want_status']];
  341. $end_status = $status_list[$data['status']];
  342. $content = "管理员({$admin['user_nickname']})将状态从{$start_status}更改为{$end_status},备注:{$data['content']}";
  343. //状态更改
  344. UserModel::update(['want_status' => $data['status']], ['id' => $data['user_id']]);
  345. UserFollowModel::create([
  346. 'user_id' => $data['user_id'],
  347. 'content' => $content,
  348. 'create_time' => time(),
  349. ]);
  350. $this->success('操作成功');
  351. }
  352. }