CommonController.php 5.4 KB
<?php
/**
 * Created by PhpStorm.
 * auther: sgj
 * Date: 2018/12/8
 * Time: 15:25
 */

namespace app\portal\controller;

use think\Db;
use cmf\controller\AdminBaseController;

class CommonController extends AdminBaseController
{

    public function selectUsers()
    {
        $param = $this->request->param();
        $ids = $this->request->param('ids');
        $selectedIds         = explode(',',$ids);
        if (!is_array($selectedIds)) {
            $selectedIds = [$selectedIds];
        }

        $where['user_type']   = ['in','1,2,3'];
        $request = input('request.');

        if (!empty($request['uid'])) {
            $where['id'] = intval($request['uid']);
        }
        $keywordComplex = [];
        if (!empty($request['keyword'])) {
            $keyword = $request['keyword'];

            $keywordComplex['user_login|user_nickname|mobile']    = ['like', "%$keyword%"];
        }
        $usersQuery = Db::name('user');
        $list = $usersQuery->field('id,user_nickname,user_login,avatar,mobile')
            ->whereOr($keywordComplex)
            ->where($where)
            ->order("create_time DESC")
            ->paginate(50);
        $list->appends($param);

        $this->assign('selectedIds', $selectedIds);
        $this->assign('uid', isset($param['uid']) ? $param['uid'] : '');
        $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
        $this->assign('ids', isset($param['ids']) ? $param['ids'] : '');
        $this->assign('list', $list->items());
        $this->assign('page', $list->render());

        return $this->fetch();
    }
    public function selectExport()
    {
        $param = $this->request->param();
        $ids = $this->request->param('ids');
        $selectedIds         = explode(',',$ids);
        if (!is_array($selectedIds)) {
            $selectedIds = [$selectedIds];
        }

        $where['user_type']   = ['in','1,2,3'];
        $where['is_expert']   = 1;
        $request = input('request.');

        if (!empty($request['uid'])) {
            $where['id'] = intval($request['uid']);
        }
        $keywordComplex = [];
        if (!empty($request['keyword'])) {
            $keyword = $request['keyword'];

            $keywordComplex['user_login|user_nickname|mobile']    = ['like', "%$keyword%"];
        }
        $usersQuery = Db::name('user');
        $list = $usersQuery->field('id,user_nickname,user_login,avatar,mobile')
            ->whereOr($keywordComplex)
            ->where($where)
            ->order("create_time DESC")
            ->paginate(50);
        $list->appends($param);

        $this->assign('selectedIds', $selectedIds);
        $this->assign('uid', isset($param['uid']) ? $param['uid'] : '');
        $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
        $this->assign('ids', isset($param['ids']) ? $param['ids'] : '');
        $this->assign('list', $list->items());
        $this->assign('page', $list->render());

        return $this->fetch();
    }

    public function selectUsersMore()
    {
        $param = $this->request->param();
        $ids = $this->request->param('ids');
        $selectedIds         = explode(',',$ids);
        if (!is_array($selectedIds)) {
            $selectedIds = [$selectedIds];
        }

        $where['user_type']   = ['in','1,2,3'];
        $request = input('request.');

        if (!empty($request['uid'])) {
            $where['id'] = intval($request['uid']);
        }
        $keywordComplex = [];
        if (!empty($request['keyword'])) {
            $keyword = $request['keyword'];

            $keywordComplex['user_login|user_nickname|mobile']    = ['like', "%$keyword%"];
        }
        $usersQuery = Db::name('user');
        $list = $usersQuery->field('id,user_nickname,user_login,avatar,mobile')
            ->whereOr($keywordComplex)
            ->where($where)
            ->order("create_time DESC")
            ->paginate(50);
        $list->appends($param);

        $this->assign('selectedIds', $selectedIds);
        $this->assign('uid', isset($param['uid']) ? $param['uid'] : '');
        $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
        $this->assign('ids', isset($param['ids']) ? $param['ids'] : '');
        $this->assign('list', $list->items());
        $this->assign('page', $list->render());

        return $this->fetch();
    }

    public function selectGroup(){
        $param = $this->request->param();
        $ids = $this->request->param('ids');
        $selectedIds         = explode(',',$ids);
        if (!is_array($selectedIds)) {
            $selectedIds = [$selectedIds];
        }

        $request = input('request.');

        if (!empty($request['uid'])) {
            $where['id'] = intval($request['uid']);
        }
        $keywordComplex = [];

        $usersQuery = Db::name('group');
        $list = $usersQuery->field('id,name,descripe')
            ->whereOr($keywordComplex)
          //  ->where($where)
              ->where('delete_time',null)
            ->order("addtime DESC")
            ->paginate(50);
        $list->appends($param);

        $this->assign('selectedIds', $selectedIds);
        $this->assign('gid', isset($param['uid']) ? $param['uid'] : '');
        $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
        $this->assign('ids', isset($param['ids']) ? $param['ids'] : '');
        $this->assign('list', $list->items());
        $this->assign('page', $list->render());

        return $this->fetch();
    }

}