AdminOauthController.php 9.4 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 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 cmf\controller\AdminBaseController;
use think\Db;
use think\Request;

class AdminOauthController extends AdminBaseController
{

    /**
     * 后台第三方用户列表
     * @adminMenu(
     *     'name'   => '第三方用户',
     *     'parent' => 'user/AdminIndex/default1',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '第三方用户',
     *     'param'  => ''
     * )
     */
    public function index()
    {

        $oauthUserQuery = Db::name('third_party_user');

        $lists = $oauthUserQuery->field('a.*,u.user_nickname,u.sex,u.avatar')->alias('a')->join('__USER__ u', 'a.user_id = u.id')->where("status", 1)->order("create_time DESC")->paginate(10);
        // 获取分页显示
        $page = $lists->render();
        $this->assign('lists', $lists);
        $this->assign('page', $page);
        // 渲染模板输出
        return $this->fetch();
    }

    public function user()
    {
//        用户
        $where_member['type'] = 1;
        $data = $this->request->param();
        if($data){
            $startTime = empty($data['start_time']) ? 0 : strtotime($data['start_time']);
            $endTime   = empty($data['end_time']) ? 0 : strtotime($data['end_time']);
            if ($startTime && $endTime) {
                $where_member['create_time'] = array('between',"$startTime,$endTime");
                $this->assign('start_time', $data['start_time']);
                $this->assign('end_time', $data['end_time']);
            }else{
                if($startTime){
                    $where_member['create_time'] = array('egt',$startTime);
                    $this->assign('start_time', $data['start_time']);
                }
                if($endTime){
                    $where_member['create_time'] = array('elt',$endTime);
                    $this->assign('end_time', $data['end_time']);
                }
            }

            if(!empty($data['name'])){
                $where_member['name'] = array('like','%'.$data['name'].'%');
                $this->assign('name', $data['name']);
            }
            if(!empty($data['tel'])){
                $where_member['tel'] = array('like','%'.$data['tel'].'%');
                $this->assign('tel', $data['tel']);
            }
        }
        $lists = Db::name('Member')->where($where_member)->select()->toArray();
        foreach ($lists as $lk=>$lv){
           $where_referee['id'] = $lv['referee_id'];
           $referee =  Db::name('Member')->where($where_referee)->field('id,name')->find();
           if($referee){
               $lists[$lk]['referee_name'] = $referee['name'];
           }else{
               $lists[$lk]['referee_name'] = '';
           }
        }
        // 获取分页显示
//        $page = $lists->render();
        $this->assign('lists', $lists);
//        $this->assign('page', $page);
        // 渲染模板输出
        return $this->fetch();
    }

    public function intermediary()
    {
//        中介
        $data = $this->request->param();
        if($data){
            $startTime = empty($data['start_time']) ? 0 : strtotime($data['start_time']);
            $endTime   = empty($data['end_time']) ? 0 : strtotime($data['end_time']);
            if ($startTime && $endTime) {
                $where_member['create_time'] = array('between',"$startTime,$endTime");
                $this->assign('start_time', $data['start_time']);
                $this->assign('end_time', $data['end_time']);
            }else{
                if($startTime){
                    $where_member['create_time'] = array('egt',$startTime);
                    $this->assign('start_time', $data['start_time']);
                }
                if($endTime){
                    $where_member['create_time'] = array('elt',$endTime);
                    $this->assign('end_time', $data['end_time']);
                }
            }

            if(!empty($data['name'])){
                $where_member['name'] = array('like','%'.$data['name'].'%');
                $this->assign('name', $data['name']);
            }
            if(!empty($data['tel'])){
                $where_member['tel'] = array('like','%'.$data['tel'].'%');
                $this->assign('tel', $data['tel']);
            }
        }
        $where_member['type'] = 2;
        $lists = Db::name('Member')->where($where_member)->select()->toArray();
        foreach ($lists as $lk=>$lv){
            $where_referee['id'] = $lv['referee_id'];
            $referee =  Db::name('Member')->where($where_referee)->field('id,name')->find();
            if($referee){
                $lists[$lk]['referee_name'] = $referee['name'];
            }else{
                $lists[$lk]['referee_name'] = '';
            }
        }
        // 获取分页显示
//        $page = $lists->render();
        $this->assign('lists', $lists);
//        $this->assign('page', $page);
        // 渲染模板输出
        return $this->fetch();
    }
    /**
     * 后台删除第三方用户绑定
     * @adminMenu(
     *     'name'   => '删除第三方用户绑定',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除第三方用户绑定',
     *     'param'  => ''
     * )
     */
    public function delete()
    {
        $id = input('param.id', 0, 'intval');
        if (empty($id)) {
            $this->error('非法数据!');
        }
        Db::name("third_party_user")->where("id", $id)->delete();
        $this->success("删除成功!", "admin_oauth/index");
    }
//    黑名单
    public function del(Request $request)
    {
        $where_member['id'] = $request->param('id');
        $is_isset = Db::name('Member')->where($where_member)->field('status')->find();
        if(!$is_isset){
            $this->error('用户信息错误!');
        }
        $save['status'] = 8;
        $save['update_time'] = time();
        $update = Db::name('Member')->where($where_member)->update($save);
        if($update){
            $this->success("删除成功!", "admin_oauth/intermediary");
        }else{
            $this->error('删除失败!');
        }
    }


//    黑名单
    public function black(Request $request)
    {
        $where_member['status'] = 8;
        $data = $request->param();
        if($data){
            $startTime = empty($data['start_time']) ? 0 : strtotime($data['start_time']);
            $endTime   = empty($data['end_time']) ? 0 : strtotime($data['end_time']);
            if ($startTime && $endTime) {
                $where_member['create_time'] = array('between',"$startTime,$endTime");
                $this->assign('start_time', $data['start_time']);
                $this->assign('end_time', $data['end_time']);
            }else{
                if($startTime){
                    $where_member['create_time'] = array('egt',$startTime);
                    $this->assign('start_time', $data['start_time']);
                }
                if($endTime){
                    $where_member['create_time'] = array('elt',$endTime);
                    $this->assign('end_time', $data['end_time']);
                }
            }

            if(!empty($data['name'])){
                $where_member['name'] = array('like','%'.$data['name'].'%');
                $this->assign('name', $data['name']);
            }
            if(!empty($data['tel'])){
                $where_member['tel'] = array('like','%'.$data['tel'].'%');
                $this->assign('tel', $data['tel']);
            }
        }
        $is_isset = Db::name('Member')->where($where_member)->select()->toArray();
        if(!$is_isset){
            $is_isset = array();
        }else{
            foreach ($is_isset as $lk=>$lv){
                $where_referee['id'] = $lv['referee_id'];
                $referee =  Db::name('Member')->where($where_referee)->field('id,name')->find();
                if($referee){
                    $is_isset[$lk]['referee_name'] = $referee['name'];
                }else{
                    $is_isset[$lk]['referee_name'] = '';
                }
            }
        }
        $this->assign('lists', $is_isset);
        return $this->fetch();
    }

//    恢复黑名单
    public function recovery(Request $request)
    {
        $where_member['id'] = $request->param('id');
        $where_member['status'] = 8;
        $is_isset = Db::name('Member')->where($where_member)->field('status')->find();
        if(!$is_isset){
            $this->error('用户信息错误!');
        }
        $save['status'] = 1;
        $save['update_time'] = time();
        $update = Db::name('Member')->where($where_member)->update($save);
        if($update){
            $this->success("恢复成功!", "admin_oauth/black");
        }else{
            $this->error('恢复失败!');
        }
    }
}