<?php
/*
 * @Author: wang jun
 * @Date: 2021-10-30 16:54:46
 * @Last Modified by: wang jun
 * @Last Modified time: 2021-11-10 16:47:23
 */
namespace app\admin\controller;

use app\admin\logic\webuserlogic;
use app\admin\logic\webuserloglogic;
use think\Controller;

class Webuser extends AdminBase
{
    /**
     * 设置请求数据规则
     * 20220107
     * wj
     */
    protected function setrules()
    {
        $list = [
            'newinfo' => [
                ['name' => 'name', 'title' => '用户名', 'require' => true, 'type' => 'string'],
            ],
            'updateisactive' => [
                ['name' => 'id', 'title' => 'id', 'require' => true, 'type' => 'numeric'],
                ['name' => 'isactive', 'title' => '可用状态', 'require' => true, 'type' => 'numeric'],
            ],
            'updatepasswd' => [
                ['name' => 'name', 'title' => '用户名', 'require' => true, 'type' => 'string'],
                ['name' => 'password', 'title' => '密码', 'require' => true, 'type' => 'string'],
            ],
            'saveuserrole' => [
                ['name' => 'access', 'title' => '权限组标志名', 'require' => true, 'type' => 'string'],
                ['name' => 'uid', 'title' => '用户id', 'require' => true, 'type' => 'numeric'],
            ],
        ];
        return $list;
    }
    /**
     * 创建web用户
     */
    public function newinfo()
    {
        $param = request()->param();
        $t_wu = new webuserlogic();
        $result = $t_wu->newwebuser($param);
        if (1 != $result['status']) {
            return backjson2(0, $result['msg']);
        } else {
            return backjson2(200, "操作成功", $result['data']);
        }
    }
    /**
     * 改用户状态
     * 20211103
     * wj
     */
    public function updateisactive()
    {
        $param = request()->param();
        $t_wu = new webuserlogic();
        $result = $t_wu->updateisactive($param);
        if (1 != $result['status']) {
            return backjson2(0, $result['msg']);
        } else {
            return backjson2(200, "操作成功", $result['data']);
        }
    }
    /**
     * 获取列表
     * 20211103
     * wj
     */
    public function getalllist()
    {
        $param = request()->param();
        $t_wu = new webuserlogic();
        $result = $t_wu->getalllist($param);
        if (1 != $result['status']) {
            return backjson2(0, $result['msg']);
        } else {
            return backjson2(200, "操作成功", $result['data']);
        }
    }

    /**
     * 编辑用户信息
     * 20211103
     * wj
     */
    public function editwebuser()
    {
        $param = request()->param();
        $t_wu = new webuserlogic();
        $result = $t_wu->editwebuser($param);
        if (1 != $result['status']) {
            return backjson2(0, $result['msg']);
        } else {
            return backjson2(200, "操作成功", $result['data']);
        }
    }

    /**
     * 修改用户密码
     * 20211108
     * wj
     */
    public function updatepasswd()
    {
        $param = request()->param();
        $t_wu = new webuserlogic();
        $result = $t_wu->updatepasswd($param);
        if (1 != $result['status']) {
            return backjson2(0, $result['msg']);
        } else {
            return backjson2(200, "操作成功", $result['data']);
        }
    }

    /**
     * 获取用户信息
     * 20211110
     * wj
     */
    public function searchUserInfo()
    {
        $param = request()->param();
        $t_wu = new webuserlogic();
        $result = $t_wu->searchUserInfo($param);
        if (1 != $result['status']) {
            return backjson2(0, $result['msg']);
        } else {
            return backjson2(200, "查询成功", $result['data']);
        }
    }

    /**
     * 保存用户设置
     * 20211110
     * wj
     */
    public function saveuserrole()
    {
        $param = request()->param();
        $t_wu = new webuserlogic();
        $result = $t_wu->saveuserrole($param);
        if (1 != $result['status']) {
            return backjson2(0, $result['msg']);
        } else {
            return backjson2(200, "操作成功", $result['data']);
        }
    }
    /**
     * 获取用户日志
     * 20211223
     * wj
     */
    public function getlogs()
    {
        $param = request()->param();
        $l_wl = new webuserloglogic();
        $result = $l_wl->getlistbywhere($param);
        if (1 != $result['status']) {
            return backjson2(0, $result['msg']);
        } else {
            return backjson2(200, "操作成功", $result['data']);
        }
    }
}
