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(array('id' => $id))->field('id,login_name,name,jurisdiction_group_id')->find(); if (empty($user)) { $this->error('访问有误'); exit; } $this->assign('default', $default); } else { $this->assign('default', array()); } //角色列表 $rolesList = M("jurisdiction_group")->where(array('create_user' => 3, '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; } // if (!preg_match('/^[a-zA-Z0-9.+*-/<>?!@#$%^&*():;]{1,}$/', $password)){ // $res['status'] = 0; // $res['msg'] = '密码错误,必须是字母,数字,符号'; // $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 (!preg_match('/^[a-zA-Z0-9.+*-/<>?!@#$%^&*():;]{1,}$/', $password)){ // $res['status'] = 0; // $res['msg'] = '密码错误,必须是字母,数字,符号'; // $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 == '') { //添加 $msg = '新增用户'; $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 { //修改 $msg = '编辑用户'; $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'] = '操作成功'; //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '角色模块下-' . $msg;//操作行为描述 action_log($source, $type, $request_data, $desc); //end } else { $res['status'] = 2; if (!empty($id)) { $res['msg'] = '暂未修改数据'; } else { $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'] = '修改成功'; //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '角色模块下-修改用户使用状态';//操作行为描述 action_log($source, $type, $request_data, $desc); //end } else { $res['status'] = 2; $res['msg'] = '修改失败'; } $this->ajaxReturn($res); } //角色删除 public function usersDel() { if ($_POST) { $id = I("post.id"); if ($id) { $row = M('jurisdiction_user')->where(['id' => $id])->save(array('state' => 0)); if ($row) { $res['status'] = 1; $res['msg'] = '已删除'; //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '角色模块下-删除用户';//操作行为描述 action_log($source, $type, $request_data, $desc); //end } else { $res['status'] = 0; $res['msg'] = '删除失败'; } } else { $res['status'] = 0; $res['msg'] = '参数有误,请检查'; } $this->ajaxReturn($res); } } }