AdminIndexController.php 6.6 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------

namespace app\user\controller;

use app\admin\model\HospitalModel;
use app\admin\model\JobModel;
use app\user\model\UserModel;
use cmf\controller\AdminBaseController;
use think\Db;

/**
 * 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()
    {
        $where   = ['user_type'=>2];
        $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|user_email']    = ['like', "%$keyword%"];
        }
        $usersQuery = Db::name('user');

        $list = $usersQuery->whereOr($keywordComplex)->where($where)->order("create_time DESC")->paginate(20);
        // 获取分页显示
        $page = $list->render();
        $this->assign('list', $list);
        $this->assign('page', $page);
        // 渲染模板输出
        return $this->fetch();
    }

    /**
     * 积分管理
     * @adminMenu(
     *     'name'   => '积分管理',
     *     'parent' => 'default1',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '用户积分管理',
     *     'param'  => ''
     * )
     */
    public function score(){
        return $this->fetch();
    }

    /**
     * 积分管理
     * @adminMenu(
     *     'name'   => '积分管理',
     *     'parent' => 'default1',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '用户积分管理',
     *     'param'  => ''
     * )
     */
    public function scorePost(){
        $data=input();
        if ($data['num']<=0){
            $this->error('积分输入有误');
        }
        $result=addScore($data['user_id'],$data['num'],'后台积分发放');
        if ($result==1){
            $this->success('积分发送成功!');
        }else{
            $this->error('积分发放失败!');
        }
    }




    /**
     * 本站用户拉黑
     * @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 editUserInfo(){
        $map['u.id']=input('id');
        $User=new UserModel();
        $user=$User->alias('u')
            ->field('u.*,u.id,h.name as hospital_name,o.name as office_name,u.user_login,j.name as job_name,u.describe,u.avatar,u.mobile,c.name as platform_name')
            ->join('hospital h','h.id=u.hospital',"LEFT")
            ->join('office o','u.office=o.id',"LEFT")
            ->join('job j','u.job=j.id',"LEFT")
            ->join('portal_category c','c.id=u.platform','LEFT')
            ->where($map)
            ->find()
            ->toArray();
        $Job=new JobModel();
        $jobs=$Job->getJob()->toArray() ;
        $Hospital=new HospitalModel();
        $hospitals=$Hospital->getHospital()->toArray();
        $platform=$Hospital->getPlatment()->toArray();
        $office=$Hospital->getAllOffice()->toArray();
        $this->assign('user',$user);
        $this->assign('office',$office);
        $this->assign('jobs',$jobs);
        $this->assign('hospitals',$hospitals);
        $this->assign('platforms',$platform);
        return $this->fetch();
    }

    /**
     * 编辑用户信息
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function userInfoPost(){
        $map['id']=input('id');

        $data=input();
        unset($data['id']);
       // dump($data);
        $result=\db('user')->where($map)->update($data);
        if ($result==1){
            $this->success('编辑成功!');
        }else{
            $this->error('编辑失败!');
        }
    }



}