| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 | <?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 api\user\model\UserLikeModel;use app\common\Constant;use app\love\model\ActiveApplyModel;use app\love\model\UserFriendModel;use app\love\model\UserGiftModel;use app\love\model\UserInviteModel;use app\love\model\UserMatingModel;use app\love\model\UserMessageModel;use app\love\model\UserSelectLogModel;use app\love\model\UserSelectModel;use app\love\model\UserVisitModel;use app\user\model\UserFavoriteModel;use app\user\model\UserModel;use cmf\controller\AdminBaseController;use think\Db;use think\db\Query;use \think\facade\Request;/** * 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;        }        $list = Db::name('user')            ->where(function (Query $query) {                $data = $this->request->param();                $query->where('user_type', 2);                if (!empty($data['uid'])) {                    $query->where('id', intval($data['uid']));                }                if (!empty($data['keyword'])) {                    $keyword = $data['keyword'];                    $query->where('username', 'like', "%$keyword%");                }                if (!empty($data['sex'])) {                    $query->where('sex', $data['sex']);                }                if (!empty($data['is_complete'])) {                    $query->where('is_complete', $data['is_complete']);                }                if (!empty($data['check_status'])) {                    $query->where('check_status', $data['check_status']);                }            })            ->order("check_status asc,create_time DESC")            ->paginate(10, false, [                'query' => Request::param(),//不丢失已存在的url参数            ]);        $this->assign('sex', $this->request->param('sex') ?: 0);        $this->assign('is_complete', $this->request->param('is_complete') ?: 0);        $this->assign('check_status', $this->request->param('check_status') ?: 0);        // 获取分页显示        $page = $list->render();        $this->assign('list', $list);        $this->assign('page', $page);        // 渲染模板输出        return $this->fetch();    }    /**     * 审核     */    public function checkPost()    {        $data = $this->request->post();        UserModel::update($data, ['id' => $data['id']]);        $this->success('操作成功');    }    /**     * 详情     */    public function show()    {        //获取id        $id = input('param.id');        if (empty($id)) {            $this->error(lang('信息不存在或已删除'));        }        //获取信息        $info           = UserModel::get($id);        $info['family'] = $info['family'] ? implode(',', json_decode($info['family'], true)) : '未填写';        $info['have_house'] = Constant::COND_TINYINT[$info['have_house']];        $info['have_car'] = Constant::COND_TINYINT[$info['have_car']];        $info['with_parent_live'] = Constant::COND_TINYINT[$info['with_parent_live']];        if (empty($info)) {            $this->error(lang('信息不存在或已删除'));        }        $this->assign('info', $info);        $mating = UserMatingModel::get(['user_id' => $id]);        $mating['have_house'] = Constant::COND_TINYINT[$mating['have_house']];        $mating['have_car'] = Constant::COND_TINYINT[$mating['have_car']];        $mating['with_parent_live'] = Constant::COND_TINYINT[$mating['with_parent_live']];        $this->assign('mating', $mating);        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 delete()    {        $id = input('param.id', 0, 'intval');        if ($id > 1) {            Db::startTrans();            try {                UserModel::destroy($id);                ActiveApplyModel::where('user_id', $id)->delete();                UserFavoriteModel::where('user_id|uid', '=', $id)->delete();                UserFriendModel::where('user_id|friend_id', '=', $id)->delete();                UserGiftModel::where('from_id|to_id', '=', $id)->delete();                UserInviteModel::where('from_id|to_id', '=', $id)->delete();                UserLikeModel::where('user_id', '=', $id)->delete();                UserMatingModel::where('user_id', '=', $id)->delete();                UserMessageModel::where('from_id|to_id', '=', $id)->delete();                UserSelectModel::where('user_id|uid', '=', $id)->delete();                UserSelectLogModel::where('user_id1|user_id2', '=', $id)->delete();                Db::name('user_token')->where('user_id', '=', $id)->delete();                UserVisitModel::where('from_id|to_id', '=', $id)->delete();                Db::commit();            } catch (\Exception $e) {                //回滚事务                Db::rollback();                $this->error('会员删除失败,会员不存在,或者是管理员!');            }            $this->success("会员删除成功!", "adminIndex/index");        } else {            $this->error('数据传入失败!');        }    }}
 |