123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: Powerless < wzxaini9@gmail.com>
- // +----------------------------------------------------------------------
- namespace app\user\controller;
- use app\user\model\UserModel;
- use cmf\controller\AdminBaseController;
- use think\Db;
- use think\db\Query;
- /**
- * Class AdminIndexController
- * @package app\user\controller
- *
- * @adminMenuRoot(
- * 'name' =>'用户管理',
- * 'action' =>'default',
- * 'parent' =>'',
- * 'display'=> true,
- * 'order' => 10,
- * 'icon' =>'group',
- * 'remark' =>'用户管理'
- * )
- *
- * @adminMenuRoot(
- * 'name' =>'用户组',
- * 'action' =>'default1',
- * 'parent' =>'user/AdminIndex/default',
- * 'display'=> true,
- * 'order' => 10000,
- * 'icon' =>'',
- * 'remark' =>'用户组'
- * )
- */
- class AdminIndexController extends AdminBaseController
- {
- /**
- * 后台本站用户列表
- * @adminMenu(
- * 'name' => '本站用户',
- * 'parent' => 'default1',
- * 'display'=> true,
- * 'hasView'=> true,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '本站用户',
- * 'param' => ''
- * )
- */
- public function index()
- {
- $content = hook_one('user_admin_index_view');
- if (!empty($content)) {
- return $content;
- }
- $data = $this->request->param();
- $list = Db::name('user')
- ->where('user_type', 2)
- ->where(function (Query $query) use ($data) {
- if (!empty($data['uid'])) {
- $query->where('id', intval($data['uid']));
- }
- if (!empty($data['keyword'])) {
- $keyword = $data['keyword'];
- $query->where('user_nickname|user_name|mobile', 'like', "%$keyword%");
- }
- if (!empty($data['is_talent'])) {
- $query->where('is_talent', $data['is_talent']);
- }
- })
- ->order("create_time DESC")
- ->paginate(10, false, ['query' => $data]);
- // 获取分页显示
- $page = $list->render();
- $this->assign('list', $list);
- $this->assign('page', $page);
- $this->assign('is_talent', empty($data['is_talent']) ? '' : $data['is_talent']);
- // 渲染模板输出
- return $this->fetch();
- }
- /**
- * 本站用户拉黑
- * @adminMenu(
- * 'name' => '本站用户拉黑',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '本站用户拉黑',
- * 'param' => ''
- * )
- */
- public function ban()
- {
- $id = input('param.id', 0, 'intval');
- if ($id) {
- $result = Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 0);
- if ($result) {
- $this->success("会员拉黑成功!", "adminIndex/index");
- } else {
- $this->error('会员拉黑失败,会员不存在,或者是管理员!');
- }
- } else {
- $this->error('数据传入失败!');
- }
- }
- /**
- * 本站用户启用
- * @adminMenu(
- * 'name' => '本站用户启用',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '本站用户启用',
- * 'param' => ''
- * )
- */
- public function cancelBan()
- {
- $id = input('param.id', 0, 'intval');
- if ($id) {
- Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 1);
- $this->success("会员启用成功!", '');
- } else {
- $this->error('数据传入失败!');
- }
- }
- /**
- * 修改积分
- */
- public function changeScore()
- {
- $id = input('param.id', 0, 'intval');
- $score = input('param.score', 0, 'intval');
- $model = new UserModel();
- $model->startTrans();
- try {
- $user = $model->lock(true)->where(
- 'id', $id)->find();
- //记录日志
- Db::name('user_score_log')->insert([
- 'user_id' => $id,
- 'create_time' => time(),
- 'score' => $score - $user['score'] ,
- 'score_before' => $user['score'],
- 'score_after' => $score,
- 'comment' => '后台管理员修改',
- ]);
- $user->score = $score;
- $user->save();
- $model->commit();
- } catch (\Exception $e) {
- $model->rollback();
- $this->error($e->getMessage());
- }
- $this->success('操作成功');
- }
- }
|