220 行
8.2 KiB
PHP
可执行文件
220 行
8.2 KiB
PHP
可执行文件
<?php
|
|
namespace Agent\Controller;
|
|
|
|
use Think\Controller;
|
|
//[1.3.11]
|
|
class AgentJurUsersController extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
$arr = array(
|
|
'userAdd' => '/index.php/Agent/AgentJurUsers/userAdd',
|
|
'changeStatus' => '/index.php/Agent/AgentJurUsers/changeStatus',
|
|
'usersDel' => '/index.php/Agent/AgentJurUsers/usersDel',
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$this->display();
|
|
}
|
|
|
|
//全部的登录列表
|
|
public function getUser()
|
|
{
|
|
$user = session('jurisdiction_user');
|
|
if (!empty($user)) {
|
|
$map['u.user_type'] = 0;
|
|
$map['u.pid'] = $user['id'];
|
|
$map['u.state'] = 1;
|
|
$page = I('post.page');
|
|
$limit = I('post.limit');
|
|
$list = M('jurisdiction_user as u')
|
|
->join('ls_jurisdiction_group as g on u.jurisdiction_group_id=g.id')
|
|
->where($map)
|
|
->field('u.id,u.login_name,u.name,u.add_time,u.status,g.role_name')
|
|
->page($page.','.$limit)
|
|
->select();
|
|
$count = M("jurisdiction_user as u")->where($map)->count();
|
|
foreach ($list as $key => &$value) {
|
|
$value['add_time'] = date('Y-m-d H:i:s', $value['add_time']);
|
|
}
|
|
$res['count'] = (int)$count;
|
|
$res['data'] = $list;
|
|
$res['status'] = 1;
|
|
$res['msg'] = '查询成功';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录超时';
|
|
}
|
|
|
|
$this->ajaxReturn($res);
|
|
}
|
|
//添加弹框
|
|
public function userAdd()
|
|
{
|
|
$user = session('jurisdiction_user');
|
|
if (!$user) {
|
|
$this->error('登录超时');
|
|
exit;
|
|
}
|
|
if(I('id')){
|
|
$id = I('id');
|
|
$default = M('jurisdiction_user')->where(['id' => $id])->field('id,login_name,name,jurisdiction_group_id')->find();
|
|
if(empty($default)){
|
|
$this->error('访问有误');
|
|
exit;
|
|
}
|
|
$this->assign('default',$default);
|
|
}else{
|
|
$this->assign('default',array());
|
|
}
|
|
//角色列表
|
|
$rolesList = M("jurisdiction_group")->where(array('create_user' => 2,'create_user_id' => $user['id'],'state' => 1,'status' => 1))->select();
|
|
$this->assign('rolesList',json_encode($rolesList));
|
|
$this->display();
|
|
}
|
|
|
|
//添加ajax
|
|
public function userAddAjax()
|
|
{
|
|
$user = session('jurisdiction_user');
|
|
if($user['first_pid'] == 0){
|
|
$first_pid = $user['id'];
|
|
}else{
|
|
$parent = M('jurisdiction_user')->where(array('id' => $user['first_pid']))->find();
|
|
$first_pid = $parent['id'];
|
|
}
|
|
if (IS_POST && !empty($user)) {
|
|
$id = I('post.id');
|
|
$login_name = I('post.login_name');
|
|
$password = I('post.password');
|
|
$name = I('post.name');
|
|
$group_id = I('post.value');
|
|
$CryptrModel = new \Addons\Api\Crypto ();
|
|
//验证
|
|
$check = M('jurisdiction_user')->where(array('user_type' => 0,'state' => 1,'pid' => $user['id'], 'first_pid' => $first_pid,'login_name' =>$login_name))->find(); //要修改的数据
|
|
if(empty($check)){
|
|
if($login_name == ''){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录账号不能为空';
|
|
$this->ajaxReturn($res);exit;
|
|
}
|
|
if (!preg_match("/^1[3456789]\d{9}$/", $login_name)){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '请输入正确的登录账号';
|
|
$this->ajaxReturn($res);exit;
|
|
}
|
|
if($id == ''){
|
|
//添加验证密码
|
|
if($password == ''){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '密码不能为空';
|
|
$this->ajaxReturn($res);exit;
|
|
}
|
|
if(strlen($password)>16 || strlen($password)<6){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '密码不得少于6个字符串长度,不得超过16个';
|
|
$this->ajaxReturn($res);exit;
|
|
}
|
|
}else{
|
|
//修改验证密码
|
|
if($password != ''){
|
|
if(strlen($password)>16 || strlen($password)<6){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '密码不得少于6个字符串长度,不得超过16个';
|
|
$this->ajaxReturn($res);exit;
|
|
}
|
|
}
|
|
}
|
|
if($name == ''){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录账号不能为空';
|
|
$this->ajaxReturn($res);exit;
|
|
}
|
|
if($group_id == ''){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '请选择角色';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
}else{
|
|
if($id == '' || $check['id'] != $id){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '该登录账号已被使用,请更换手机号';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
$data['login_name'] = $login_name;
|
|
$data['name'] = $name;
|
|
$data['jurisdiction_group_id'] = $group_id;
|
|
if($id == ''){
|
|
//添加
|
|
$data['add_time'] = time();
|
|
$data['password'] = $CryptrModel->encrypt($password, date('YmdHis', $data['add_time']));
|
|
$data['pid'] = $user['id'];
|
|
$data['first_pid'] = $first_pid;
|
|
$add = M("jurisdiction_user")->add($data);
|
|
}else{
|
|
//修改
|
|
$one = M('jurisdiction_user')->where(array('id'=>$id))->find(); //要修改的数据
|
|
$add_time = $one['add_time'];
|
|
if($password != ''){
|
|
$data['password'] = $CryptrModel->encrypt($password, date('YmdHis', $add_time));
|
|
}
|
|
$add = M('jurisdiction_user')->where(array('id'=>$id))->save($data);
|
|
}
|
|
if ($add) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = '操作成功';
|
|
}else{
|
|
$res['status'] = 2;
|
|
$res['msg'] = '操作失败';
|
|
}
|
|
}else{
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录超时';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
//修改开启关闭状态
|
|
public function changeStatus()
|
|
{
|
|
$id = I('post.id');
|
|
$roles = M('jurisdiction_user')->where(array('id' => $id))->find();
|
|
if($roles['status'] == 1){
|
|
$data['status'] = 2;
|
|
}else{
|
|
$data['status'] = 1;
|
|
}
|
|
$saveres = M('jurisdiction_user')->where(array('id' => $id))->save($data);
|
|
if ($saveres) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = '修改成功';
|
|
} else {
|
|
$res['status'] = 2;
|
|
$res['msg'] = '修改失败';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
//角色删除
|
|
public function usersDel()
|
|
{
|
|
if ($_POST) {
|
|
$id = I("post.index");
|
|
if ($id) {
|
|
$row = M("jurisdiction_user")->where("id=" . $id)->save(array('state' => 0));
|
|
if ($row) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = '已删除';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '删除失败';
|
|
}
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '参数有误,请检查';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
} |