AdminIndexController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 app\user\model\UserModel;
  13. use cmf\controller\AdminBaseController;
  14. use think\Db;
  15. use think\db\Query;
  16. /**
  17. * Class AdminIndexController
  18. * @package app\user\controller
  19. *
  20. * @adminMenuRoot(
  21. * 'name' =>'用户管理',
  22. * 'action' =>'default',
  23. * 'parent' =>'',
  24. * 'display'=> true,
  25. * 'order' => 10,
  26. * 'icon' =>'group',
  27. * 'remark' =>'用户管理'
  28. * )
  29. *
  30. * @adminMenuRoot(
  31. * 'name' =>'用户组',
  32. * 'action' =>'default1',
  33. * 'parent' =>'user/AdminIndex/default',
  34. * 'display'=> true,
  35. * 'order' => 10000,
  36. * 'icon' =>'',
  37. * 'remark' =>'用户组'
  38. * )
  39. */
  40. class AdminIndexController extends AdminBaseController
  41. {
  42. /**
  43. * 后台本站用户列表
  44. * @adminMenu(
  45. * 'name' => '本站用户',
  46. * 'parent' => 'default1',
  47. * 'display'=> true,
  48. * 'hasView'=> true,
  49. * 'order' => 10000,
  50. * 'icon' => '',
  51. * 'remark' => '本站用户',
  52. * 'param' => ''
  53. * )
  54. */
  55. public function index()
  56. {
  57. $content = hook_one('user_admin_index_view');
  58. if (!empty($content)) {
  59. return $content;
  60. }
  61. $data = $this->request->param();
  62. $list = Db::name('user')
  63. ->where('user_type', 2)
  64. ->where(function (Query $query) use ($data) {
  65. if (!empty($data['uid'])) {
  66. $query->where('id', intval($data['uid']));
  67. }
  68. if (!empty($data['keyword'])) {
  69. $keyword = $data['keyword'];
  70. $query->where('user_nickname|user_name|mobile', 'like', "%$keyword%");
  71. }
  72. if (!empty($data['is_talent'])) {
  73. $query->where('is_talent', $data['is_talent']);
  74. }
  75. })
  76. ->order("create_time DESC")
  77. ->paginate(10, false, ['query' => $data]);
  78. // 获取分页显示
  79. $page = $list->render();
  80. $this->assign('list', $list);
  81. $this->assign('page', $page);
  82. $this->assign('is_talent', empty($data['is_talent']) ? '' : $data['is_talent']);
  83. // 渲染模板输出
  84. return $this->fetch();
  85. }
  86. /**
  87. * 本站用户拉黑
  88. * @adminMenu(
  89. * 'name' => '本站用户拉黑',
  90. * 'parent' => 'index',
  91. * 'display'=> false,
  92. * 'hasView'=> false,
  93. * 'order' => 10000,
  94. * 'icon' => '',
  95. * 'remark' => '本站用户拉黑',
  96. * 'param' => ''
  97. * )
  98. */
  99. public function ban()
  100. {
  101. $id = input('param.id', 0, 'intval');
  102. if ($id) {
  103. $result = Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 0);
  104. if ($result) {
  105. $this->success("会员拉黑成功!", "adminIndex/index");
  106. } else {
  107. $this->error('会员拉黑失败,会员不存在,或者是管理员!');
  108. }
  109. } else {
  110. $this->error('数据传入失败!');
  111. }
  112. }
  113. /**
  114. * 本站用户启用
  115. * @adminMenu(
  116. * 'name' => '本站用户启用',
  117. * 'parent' => 'index',
  118. * 'display'=> false,
  119. * 'hasView'=> false,
  120. * 'order' => 10000,
  121. * 'icon' => '',
  122. * 'remark' => '本站用户启用',
  123. * 'param' => ''
  124. * )
  125. */
  126. public function cancelBan()
  127. {
  128. $id = input('param.id', 0, 'intval');
  129. if ($id) {
  130. Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 1);
  131. $this->success("会员启用成功!", '');
  132. } else {
  133. $this->error('数据传入失败!');
  134. }
  135. }
  136. /**
  137. * 修改积分
  138. */
  139. public function changeScore()
  140. {
  141. $id = input('param.id', 0, 'intval');
  142. $score = input('param.score', 0, 'intval');
  143. $model = new UserModel();
  144. $model->startTrans();
  145. try {
  146. $user = $model->lock(true)->where(
  147. 'id', $id)->find();
  148. //记录日志
  149. Db::name('user_score_log')->insert([
  150. 'user_id' => $id,
  151. 'create_time' => time(),
  152. 'score' => $score - $user['score'] ,
  153. 'score_before' => $user['score'],
  154. 'score_after' => $score,
  155. 'comment' => '后台管理员修改',
  156. ]);
  157. $user->score = $score;
  158. $user->save();
  159. $model->commit();
  160. } catch (\Exception $e) {
  161. $model->rollback();
  162. $this->error($e->getMessage());
  163. }
  164. $this->success('操作成功');
  165. }
  166. }