You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

664 lines
24 KiB
PHTML

5 years ago
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use User\Api\UserApi;
use Com\Wechat;
use Com\WechatAuth;
/**
* 后台用户控制器
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
class UserController extends AdminController {
/**
* 用户管理首页
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function index(){
$nickname = I('nickname');
if(isset($_REQUEST['status'])){
$map['status'] = $_REQUEST['status'];
}
if(is_numeric($nickname)){
$map['uid|nickname']= array(intval($nickname),array('like','%'.$nickname.'%'),'_multi'=>true);
}else{
$map['nickname'] = array('like', '%'.(string)$nickname.'%');
}
$list = $this->lists('Member', $map);
int_to_string($list);
$this->assign('_list', $list);
$this->meta_title = '管理员列表';
$this->m_title = '管理员列表';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'User/index','status'=>1])->find());
$this->display();
}
/**
* 修改昵称初始化
* @author huajie <banhuajie@163.com>
*/
public function updateNickname(){
$nickname = M('Member')->getFieldByUid(UID, 'nickname');
$this->assign('nickname', $nickname);
$this->meta_title = '修改昵称';
$this->display('updatenickname');
}
/**
* 修改昵称提交
* @author huajie <banhuajie@163.com>
*/
public function submitNickname(){
//获取参数
$nickname = I('post.nickname');
$password = I('post.password');
empty($nickname) && $this->error('请输入昵称');
empty($password) && $this->error('请输入密码');
//密码验证
$User = new UserApi();
$uid = $User->login(UID, $password, 4);
($uid == -2) && $this->error('密码不正确');
$Member = D('Member');
$data = $Member->create(array('nickname'=>$nickname));
if(!$data){
$this->error($Member->getError());
}
$res = $Member->where(array('uid'=>$uid))->save($data);
if($res){
$user = session('user_auth');
$user['username'] = $data['nickname'];
session('user_auth', $user);
session('user_auth_sign', data_auth_sign($user));
$this->success('修改昵称成功!');
}else{
$this->error('修改昵称失败!');
}
}
/**
* 修改密码初始化
* @author huajie <banhuajie@163.com>
*/
public function updatePassword(){
$this->meta_title = '修改密码';
$this->display('updatepassword');
}
/**
* 修改密码提交
* @author huajie <banhuajie@163.com>
*/
public function submitPassword(){
//获取参数
$password = I('post.old');
empty($password) && $this->error('请输入原密码');
$data['password'] = I('post.password');
empty($data['password']) && $this->error('请输入新密码');
$repassword = I('post.repassword');
empty($repassword) && $this->error('请输入确认密码');
if($data['password'] !== $repassword){
$this->error('您输入的新密码与确认密码不一致');
}
$Api = new UserApi();
$res = $Api->updateInfo(UID, $password, $data);
if($res['status']){
$this->success('修改密码成功!');
}else{
$this->error($res['info']);
}
}
/**
* 用户行为列表
* @author huajie <banhuajie@163.com>
*/
public function action(){
//获取列表数据
$Action = M('Action')->where(array('status'=>array('gt',-1)));
$list = $this->lists($Action);
int_to_string($list);
// 记录当前列表页的cookie
Cookie('__forward__',$_SERVER['REQUEST_URI']);
$this->assign('_list', $list);
$this->meta_title = '用户行为';
$this->display();
}
/**
* 新增行为
* @author huajie <banhuajie@163.com>
*/
public function addAction(){
$this->meta_title = '新增行为';
$this->assign('data',null);
$this->display('editaction');
}
/**
* 编辑行为
* @author huajie <banhuajie@163.com>
*/
public function editAction(){
$id = I('get.id');
empty($id) && $this->error('参数不能为空!');
$data = M('Action')->field(true)->find($id);
$this->assign('data',$data);
$this->meta_title = '编辑行为';
$this->display('editaction');
}
/**
* 更新行为
* @author huajie <banhuajie@163.com>
*/
public function saveAction(){
$res = D('Action')->update();
if(!$res){
$this->error(D('Action')->getError());
}else{
$this->success($res['id']?'更新成功!':'新增成功!', Cookie('__forward__'));
}
}
/**
* 会员状态修改
* @author 朱亚杰 <zhuyajie@topthink.net>
*/
public function changeUserStatus($method=null){
$id = array_unique((array)I('id',0));
if( in_array(C('USER_ADMINISTRATOR'), $id)){
$this->error("不允许对超级管理员执行该操作!");
}
$id = is_array($id) ? implode(',',$id) : $id;
if ( empty($id) ) {
$this->error('请选择要操作的数据!');
}
$map['uid'] = array('in',$id);
$map1['id'] = array('in',$id);
$status=I('method')=='forbidUser'?0:1;
$res= M('UcenterMember')->where($map1)->setField('status',$status);
$res1= M('Member')->where($map)->setField('status',$status);
if($res&&$res1){
$this->success('更新成功!');
}else{
$this->error('更新失败!');
}
}
/**
* 会员状态修改
* @author 朱亚杰 <zhuyajie@topthink.net>
*/
public function changeStatus($method=null){
$id = array_unique((array)I('id',0));
if( in_array(C('USER_ADMINISTRATOR'), $id)){
$this->error("不允许对超级管理员执行该操作!");
}
$id = is_array($id) ? implode(',',$id) : $id;
if ( empty($id) ) {
$this->error('请选择要操作的数据!');
}
$map['uid'] = array('in',$id);
switch ( strtolower($method) ){
case 'forbiduser':
\Think\Log::actionLog('User/changeStatus?method=forbidUser','user',1);
$this->forbid('Member', $map );
break;
case 'resumeuser':
\Think\Log::actionLog('User/changeStatus?method=resumeuser','user',1);
$this->resume('Member', $map );
break;
case 'deleteuser':
\Think\Log::actionLog('User/changeStatus?method=deleteuser','user',1);
$this->delete('Member', $map );
break;
default:
$this->error('参数非法');
}
}
public function add($username = '', $password = '', $repassword = '', $email = '',$second_pwd=''){
if(IS_POST){
/*检测用户名是否为空*/
if (empty($username)){
$this->error('管理员账号不能为空!');
}
/* 检测密码 */
if($password != $repassword){
$this->error('管理员密码和确认密码不一致!');
}
5 years ago
$usernameUser = M('UcenterMember', 'sys_')->field('username')->where(['username' => $username])->find();
if (!empty($usernameUser)) {
$this->error('用户名已存在!');
}
$emailUser = M('UcenterMember', 'sys_')->field('id')->where(['email' => $email])->find();
5 years ago
if (!empty($emailUser)) {
$this->error('邮箱已存在!');
}
5 years ago
/* 调用注册接口注册用户 */
$User = new UserApi;
$uid = $User->register($username, $password, $email,$second_pwd);
if(0 < $uid){ //注册成功
$user = array('uid' => $uid, 'nickname' => $username, 'status' => 1);
$data['uid'] = $uid;
$data['group_id'] = I('auth');
M('auth_group_access')->data($data)->add();
if(!M('Member')->add($user)){
$this->error('用户添加失败!');
} else {
\Think\Log::actionLog('User/add','Member',$uid);
$this->success('用户添加成功!',U('index'));
}
} else { //注册失败,显示错误信息
$this->error($this->showRegError($uid));
}
} else {
$list=D('AuthGroup')->where(array('status'=>1))->select();
$this->assign('lists',$list);
$this->meta_title = '新增管理员';
5 years ago
5 years ago
$this->m_title = '管理员列表';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'User/index','status'=>1])->find());
$this->display();
}
}
/**
* 系统非常规MD5加密方法
* @param string $str 要加密的字符串
* @return string
*/
function think_ucenter_md5($str, $key = 'ThinkUCenter'){
return '' === $str ? '' : md5(sha1($str) . $key);
}
public function edit($id){
// var_dump(session());exit;
if(IS_POST){
if(isset($_POST['bind_wx'])){
if($_POST['bind_wx']=='unbind_wx'){
$info['admin_openid']='';
}else{
$info['admin_openid']=session('admin_openid');
if($info['admin_openid']==''){
$this->error('请在30分钟内扫描并关注微信公众号');
}
}
}
if($_POST['auth']==''&&$id!=1){
$this->error('请选择用户权限!');
}
if($_POST['password']==''){
//$this->error('请填写管理员密码!');
}
if(!empty($_POST['password']) && (strlen($_POST['password'])<6 || strlen($_POST['password']) > 30)){
$this->error('管理员密码长度必须在6-30个字符之间');
}
if($_POST['second_pwd']==''){
//$this->error('请填写二级密码!');
}
if(!empty($_POST['second_pwd']) && (strlen($_POST['second_pwd'])<6 || strlen($_POST['second_pwd']) > 30)){
$this->error('二级密码长度必须在6-30个字符之间');
}
if($_POST['email']==''){
$this->error('请填写邮箱!');
}
$pattern = "/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i";
if(!preg_match( $pattern, $_POST['email'])) {
$this->error('邮箱格式不正确!');
}
if(isset($_POST['mobile'])&&$_POST['mobile']!=''){
$dx = A('Phone');
$res = $dx->check_tel_code($_POST['mobile'],$_POST['code']);
switch ($res) {
case '-1':
$this->error('短信验证码无效,请重新获取');
break;
case '-2':
$this->error('时间超时,请重新获取短信验证码');
break;
case '-3':
$this->error('短信验证码不正确,请重新输入');
break;
}
}
$Member=D('UcenterMember');
$mem=D('Member');
$au=D('AuthGroupAccess');
$map['id']=$id;
$maps['uid']=$id;
$info['username']=$_POST['username'];
$in['nickname']=$_POST['username'];
$pwd=$this->think_ucenter_md5($_POST['password'],UC_AUTH_KEY);
$spwd=$this->think_ucenter_md5($_POST['second_pwd'],UC_AUTH_KEY);
$rpwd=$Member->where(array('id'=>$id))->find();
$oldpwd=$rpwd['password'];
$oldspwd=$rpwd['second_pwd'];
$User = new UserApi;
$info['password']= (empty($pwd) || $pwd==$oldpwd)?$oldpwd:$pwd;
$info['second_pwd']= (empty($spwd) || $spwd==$oldspwd)?$oldspwd:$spwd;
$info['email']=$_POST['email'];
5 years ago
$info['mobile']=isset($_POST['mobile'])?$_POST['mobile']:'';
5 years ago
$ss['group_id']=$_POST['auth'];
$ss['houtai']=$_POST['houtai'];
$smember=$Member->where($map)->save($info);
$meb=$mem->where($maps)->save($in);
if ($au->where(array('uid' => $id))->find()) {
if ($ss['group_id'] == '') {
unset($ss['group_id']);
}
$ag = $au->where(array('uid' => $id))->save($ss);
} else {
$ss['uid'] = $id;
$ag = $au->add($ss);
}
if($smember !== false||$meb||$ag){
M('user_pwd')->where($maps)->setField('password',think_encrypt($info['password']));
$this->success('修改成功!',U('User/index'));
}else{
$this->error('修改失败!',U('User/index'));
}
}else{
$map['id']=$_GET['id'];
$Member=D('UcenterMember')->where($map)->find();
$au=D('AuthGroupAccess')->where(array('uid'=>$_GET['id']))->find();
$this->assign("authid",$au["group_id"]);
$this->assign("houtai",$au["houtai"]);
$list=D('AuthGroup')->where(array('status'=>1))->select();
$username=$_POST['username'];
$password=$_POST['password'];
$this->assign('lists',$list);
$this->assign('list',$Member);
$this->assign('sd',$group);
$this->meta_title = '编辑管理员';
$this->m_title = '管理员列表';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'User/index','status'=>1])->find());
$this->display();
}
}
public function bdwx(){
$map['id']=UID;
$Member=D('UcenterMember')->field('id,username,admin_openid,openid_sign')->where($map)->find();
$this->assign('id',$map['id']);
$this->assign('list',$Member);
$this->meta_title = '绑定微信';
$this->display();
}
public function updatelist($p=0){
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
if(isset($_REQUEST['op_account'])){
if ($_REQUEST['op_account']=='全部') {
unset($_REQUEST['op_account']);
}else{
$map['op_account'] = trim($_REQUEST['op_account']);
unset($_REQUEST['op_account']);
}
}
if(isset($_REQUEST['game_name'])){
$map['game_name'] = trim($_REQUEST['game_name']);
unset($_REQUEST['game_name']);
}
if(isset($_REQUEST['account'])){
$map['user_account'] = array('like','%'.trim($_REQUEST['account']).'%');
unset($_REQUEST['account']);
}
if(isset($_REQUEST['huobi'])){
$map['type'] = $_REQUEST['huobi'];
unset($_REQUEST['huobi']);
}
if(isset($_REQUEST['timestart']) && isset($_REQUEST['timeend'])){
$map['create_time'] = array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1));
unset($_REQUEST['timestart']);unset($_REQUEST['timeend']);
}elseif(isset($_REQUEST['timestart'])){
$map['create_time'] = ['GT',strtotime(I('timestart'))];
unset($_REQUEST['timestart']);
}elseif(isset($_REQUEST['timeend'])){
$map['create_time'] = ['LT',strtotime(I('timeend'))+86399];
unset($_REQUEST['timeend']);
}
$list=M('balance_edit','tab_')
->where($map)
->order('create_time desc')
->page($page, $row)
->select();
$count = M('balance_edit','tab_')->where($map)->count();
//分页
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->assign('list',$list);
$this->meta_title = '修改记录';
$this->m_title = '账户修改记录';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'Member/login_record','status'=>1])->find());
$this->display('updatelist');
}
/**
* 获取用户注册错误信息
* @param integer $code 错误编码
* @return string 错误信息
*/
private function showRegError($code = 0){
switch ($code) {
case -1: $error = '管理员账号长度必须在16个字符以内'; break;
case -2: $error = '管理员账号被禁止注册!'; break;
case -3: $error = '管理员账号被占用!'; break;
case -4: $error = '管理员密码长度必须在6-30个字符之间'; break;
case -5: $error = '邮箱格式不正确!'; break;
case -6: $error = '邮箱长度必须在1-32个字符之间'; break;
case -7: $error = '邮箱被禁止注册!'; break;
case -8: $error = '邮箱被占用!'; break;
case -9: $error = '手机格式不正确!'; break;
case -10: $error = '手机被禁止注册!'; break;
case -11: $error = '手机号被占用!'; break;
case -12: $error = '二级密码长度必须在6-30个字符之间';break;
default: $error = '未知错误';
}
return $error;
}
public function get_openid(){
$User = new UserApi;
if($_POST['id']>999){
$this->ajaxReturn(array('status'=>0,'msg'=>'管理员id不能大于999'));
}
$data = $User->verifyPwd($_POST['id'], $_POST['pwd']);
if(!$data){
$this->ajaxReturn(array('status'=>0,'msg'=>'密码错误,请重新选择'));
}
$appid = C('wechat.appid');
$appsecret = C('wechat.appsecret');
$result=auto_get_access_token(dirname(__FILE__).'/access_token_validity.txt');
if($result['is_validity']){
session('token',$result['access_token']);
$auth = new WechatAuth($appid, $appsecret,$result['access_token']);
}else{
$auth = new WechatAuth($appid, $appsecret);
$token = $auth->getAccessToken();
$token['expires_in_validity']=time()+$token['expires_in'];
wite_text(json_encode($token),dirname(__FILE__).'/access_token_validity.txt');
session('token',$token['access_token']);
}
$times=date('s',time());
// $scene_id=strrev($_POST['id'].$times);
$scene_id=$_POST['id'].$times.$_POST['type'];
session('scene_id',$scene_id);
$ticket = $auth->qrcodeCreate($scene_id,600);//10分钟
if($ticket==''){
$return=array('status'=>0,'data'=>'获取ticket失败');
}
$qrcode = $auth->showqrcode($ticket['ticket']);
$return=array('status'=>1,'data'=>$qrcode);
$this->ajaxReturn($return);
}
function checkpwd(){
$User = new UserApi;
$data = $User->verifyPwd($_POST['id'], $_POST['pwd']);
$this->ajaxReturn(array('data'=>$data));
}
function checkOpenidpic(){
sleep(2);
$data=M('ucenter_member')->where(array('id'=>$_REQUEST['id']))->find();
if($data['openid_sign']==session('scene_id')){
$this->ajaxReturn(array("status"=>1));
}else{
$this->ajaxReturn(array("status"=>0));
}
}
public function delete($id){
M()->startTrans();
$res1 = M('member')->delete($id);
$res2 = M('ucenter_member')->delete($id);
$res3 = M('auth_group_access')->where(array('uid'=>$id))->delete();
if($res1 && $res2 && $res3){
M()->commit();
$this->success('删除成功');
}else{
M()->rollback();
$this->error('删除失败'.M()->getError());
}
}
public function rolelist()
{
5 years ago
$map = [];
5 years ago
if (isset($_REQUEST['game_name'])) {
5 years ago
$map['game_name'] = ['like', trim($_REQUEST['game_name'])."%"];
5 years ago
unset($_REQUEST['game_name']);
}
if (isset($_REQUEST['server_id'])) {
$map['server_id'] = trim($_REQUEST['server_id']);
unset($_REQUEST['server_id']);
}
if (isset($_REQUEST['role_name'])) {
$map['role_name'] = trim($_REQUEST['role_name']);
unset($_REQUEST['role_name']);
}
5 years ago
if (isset($_REQUEST['promote_id'])) {
5 years ago
$queryStr = '';
if ($_REQUEST['promote_id'] == 0) {
$map['promote_id'] = '0';
} else {
5 years ago
$queryStr = "chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}";
5 years ago
$promoter_ids = D("Promote")->where($queryStr)->field('id')->select();
$promoter_ids ? $map['promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))] : null;
}
5 years ago
}
if (isset($_REQUEST['game_type'])) {
$map['sdk_version'] = trim($_REQUEST['game_type']);
unset($_REQUEST['game_type']);
}
5 years ago
empty(I('user_account')) || $map['user_account'] = ['like',"%".I('user_account')."%"];
5 years ago
$list = $this->lists(M('user_play_info', 'tab_'), $map, 'play_time desc');
5 years ago
$this->assign('list', $list);
$this->meta_title = '角色数据';
$this->m_title = '角色查询';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'User/rolelist','status'=>1])->find());
$this->display();
}
/**
* 更新游戏角色数据
* @param $id
*/
public function user_update($ids){
$res = D('User')->update_user_player($ids);
$this->success("更新成功:{$res['suc']}个,失败:{$res['ero']}");
}
/**
* 更新游戏角色数据
* @param $id
*/
public function age(){
if (IS_POST){
$data = $_POST;
$a = new ToolController();
$re = $a->save($data);
\Think\Log::actionLog('User/age','User',1);
$this->success('保存成功');
}else{
$data = I('type',1) == 1? C('age'):C('age_prevent');
$this->assign('data',$data);
$this->meta_title = I('type',1) == 1?"实名认证设置":'防沉迷设置';
$this->m_title = I('type',1)==1?'实名认证设置':'防沉迷设置';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'User/age/type/'.I('type',1),'status'=>1])->find());
$this->display();
}
}
public function update_pwd(){
if(IS_POST){
if(strlen($_POST['new_pwd'])<6||strlen($_POST['new_pwd'])>30){
$this->error('密码格式不正确!');
}
$oldspwd=$this->think_ucenter_md5($_POST['password'],UC_AUTH_KEY);
$newpwd =$this->think_ucenter_md5($_POST['new_pwd'],UC_AUTH_KEY);
$Member=D('UcenterMember');
$rpwd=$Member->where(array('id'=>session('user_auth.uid')))->find();
if($oldspwd==$rpwd['password']){
$Member->where(array('id'=>session('user_auth.uid')))->save(['password'=>$newpwd]);
$this->success('修改成功!',U('User/index'));
}else{
$this->error('原密码错误!');
}
}
$this->display();
}
public function get_server_lists($game_id=0){
$server = M("server","tab_");
$map['game_id'] = $game_id;
$lists = $server->field('id,server_name,game_name')->where($map)->select();
if(empty($lists)){
return $this->ajaxReturn(array('status'=>0,'data'=>''));
}
return $this->ajaxReturn(array('status'=>1,'data'=>$lists));
}
}