field('tab_support.id,tab_support.role_name,tab_support.game_name,tab_support.promote_account,tab_support.create_time,user_account,role_name,server_name,freeze,user.device_number') ->join('left join tab_user as user on tab_support.user_id = user.id') ->where($map) ->page($page,$row) ->order('tab_support.create_time DESC') ->select(); foreach ($data as $key => $value) { $data[$key]['create_time'] = date('Y-m-d H:m:i',$value['create_time']); } $count = M('support','tab_') ->field('tab_support.role_name,tab_support.game_id,tab_support.promote_id,tab_support.create_time,user_account,role_name,server_name,freeze,user.device_number') ->join('left join tab_user as user on tab_support.user_id = user.id') ->where($map) ->select(); $count = count($count); $page = set_pagination($count,$row); if($page) {$this->assign('_page', $page);} $this->assign('data',$data); // var_dump($data); $this->display(); } public function freezeSupport() { $supportId = I('support_id', 0); if ($supportId == 0) { $this->ajaxReturn(['status'=>0,'msg'=>"参数错误"]); } $isFreeze = D('support')->froze($supportId); if ($isFreeze) { $this->ajaxReturn(['status'=>1, 'msg'=> '冻结成功']); } else { $this->ajaxReturn(['status'=>0, 'msg'=> '冻结失败']); } } public function unfreezeSupport() { $supportId = I('support_id', 0); if ($supportId == 0) { $this->ajaxReturn(['status'=>0,'msg'=>"参数错误"]); } $isFreeze = D('support')->unfreeze($supportId); if ($isFreeze) { $this->ajaxReturn(['status'=>1, 'msg'=> '启用成功']); } else { $this->ajaxReturn(['status'=>0, 'msg'=> '启用失败']); } } public function rechangePassward() { $supportId = I('support_id', 0); if ($supportId == 0) { $this->ajaxReturn(['status'=>0,'msg'=>"参数错误"]); } $passward = D('support')->rechangePassward($supportId); if ($passward) { $this->ajaxReturn(['status'=>1, 'msg'=> '新密码:'.$passward]); } else { $this->ajaxReturn(['status'=>0, 'msg'=> '重置密码失败']); } } protected function _initialize() { parent::_initialize(); $map['id'] = get_pid(); $pro = M("promote", "tab_")->where($map)->find(); if ($pro['parent_id']!=0) { $this->error('无权操作!'); } } public function index($p=0) { $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $row=10; if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;} $map =array(); if(!empty(I('role_name'))){ $map['role_name']=['like','%'.I('role_name').'%']; } if(!empty(I('server_name'))){ $map['server_name']=I('server_name'); } if(!empty(I('game_name'))){ $map['game_name']=I('game_name'); } if(!empty(I('user_account'))){ $map['user_account']=['like','%'.I('user_account').'%']; } if(!empty($_REQUEST['start'])&&empty($_REQUEST['end'])){ $map['create_time'] = array('GT',strtotime($_REQUEST['start'])); unset($_REQUEST['start']); } if(empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){ $map['create_time'] = array('LT',strtotime($_REQUEST['end'])+24*60*60-1); unset($_REQUEST['end']); } if(!empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){ $map['create_time'] = array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1)); unset($_REQUEST['start']);unset($_REQUEST['end']); } // $res = D("test_resource")->getResourceCout($map,$page,$row); // dump($res); $parameter =I('get.'); $parameter['p']=I('get.p',1); $parameter['row']=I('get.row'); $page = set_pagination($res["count"],$row,$parameter); if($page) {$this->assign('_page', $page);} $this->meta_title = '测试资源'; $this->assign('data',$res['list']); $this->assign('count',$res["count"]); $this->display(); # code... } /** * 获取区服列表 * @param $game_id */ public function getServer($game_id="") { $map['game_id']=$game_id; $map['start_time']=['lt',time()]; if (I('status')==2) { $map['show_status']=1; } $data = M('server', 'tab_') ->field('tab_server.id,tab_server.server_name,support_quota') ->where($map) ->join('join tab_game tg ON tg.id=tab_server.game_id') ->select(); $this->AjaxReturn($data); } //获取当前和当前子渠道的渠道id public function get_all_promote(){ $pro_id=get_prmoote_chlid_account(session('promote_auth.pid')); foreach ($pro_id as $key => $value) { $pro_id1[]=$value['id']; } if(!empty($pro_id1)){ $pro_id2=array_merge($pro_id1,array(get_pid())); }else{ $pro_id2=array(get_pid()); } return $pro_id2; } /** * 系统非常规MD5加密方法 * @param string $str 要加密的字符串 * @return string */ public function think_ucenter_md5($str, $key = 'ThinkUCenter'){ return '' === $str ? '' : md5(sha1($str) . $key); } //新增扶持 public function add() { // dump(I('post.')); if (IS_POST) { $count=count(I('user_account')); session('apply_status', 0); (empty(I('server_id')) || I('server_id')<1) && $this->ajaxReturn(['msg'=>$i_account.'请选择区服' ,'status'=>0]); M('test_resource', 'tab_')->startTrans(); //事物 for ($i=0; $i < $count ; $i++) { $i_account=I('user_account')[$i]; if (!empty($i_account)) { $user=M('user', 'tab_')->field('promote_id,password,phone')->where(['account'=>$i_account])->find(); $promote = $this->get_all_promote(); if (!in_array($user['promote_id'], $promote)) { M('test_resource', 'tab_')->rollback();//回滚 $this->ajaxReturn(['msg'=>$i_account.'账号不存在' ,'status'=>0]); } if (empty(I('user_password')[$i])) { M('test_resource', 'tab_')->rollback();//回滚 $this->ajaxReturn(['msg'=>I('user_account')[$i].'请输入密码' ,'status'=>0]); } if ($user['password']!=$this->think_ucenter_md5(I('user_password')[$i], UC_AUTH_KEY)) { M('test_resource', 'tab_')->rollback();//回滚 $this->ajaxReturn(['msg'=>$i_account.'密码不正确' ,'status'=>0]); } if (empty(I('role_name')[$i])) { M('test_resource', 'tab_')->rollback();//回滚 $this->ajaxReturn(['msg'=>I('user_account')[$i].'请输入角色名' ,'status'=>0]); } $supportNum = I('apply_resource')[$i]; if (empty($supportNum)) { M('test_resource', 'tab_')->rollback();//回滚 $this->ajaxReturn(['msg'=>I('user_account')[$i].'请输入资源数量' ,'status'=>0]); } if ($supportNum<0 || !preg_match('/^[1-9]\d*$/', $supportNum)) { M('test_resource', 'tab_')->rollback();//回滚 $this->ajaxReturn(['msg'=>I('user_account')[$i].'请输入资源数量' ,'status'=>0]); } $map['game_id']=I('game_id'); $map['server_id']=I('server_id'); $map['user_account']=I('user_account')[$i]; // $map['apply_status']=['neq',0]; $map['apply_type']=0; $list= M('test_resource', 'tab_')->where($map)->find(); if ($list) { M('test_resource', 'tab_')->rollback();//回滚 $this->ajaxReturn(['msg'=>I('user_account')[$i].'账号已存在' ,'status'=>0]); } //TODO:额度未进行验证 // $support_quota = M('game', 'tab_')->field('support_quota')->find(get_game_id(I('game_name'))); // if ($support_quota['support_quota'] < I('support_num')[$i]) { // M('test_resource', 'tab_')->rollback();//回滚 // $this->ajaxReturn(['msg'=>'超出申请额度' ,'status'=>0]); // } $data['game_id']=I('game_id'); $data['game_name']=I('game_name'); $data['server_id']=I('server_id'); $data['server_name']=I('server_name'); $data['user_account']=I('user_account')[$i]; $data['user_id']=get_user_id(I('user_account')[$i]); $data['user_password']=I('user_password')[$i]; $data['phone']=$user['phone']; $data['role_name']=I('role_name')[$i]; $data['apply_resource']=I('apply_resource')[$i]; $data['apply_remark']=I('apply_remark')[$i]; $data['apply_name']=$_SESSION['onethink_home']['promote_auth']['account']; $data['apply_id']=$_SESSION['onethink_home']['promote_auth']['pid']; $data['promote_id']=session("promote_auth.pid"); $data['promote_account']=session("promote_auth.account"); $data['create_time']=time(); $data['apply_type']=0; $model = M('test_resource', 'tab_')->add($data); if ($model) { session('apply_status', 1); } } else { if (I('user_password')[$i]) { M('test_resource', 'tab_')->rollback();//回滚 $this->ajaxReturn(['msg'=>'请输入账号' ,'status'=>0]); } } } if (session('apply_status')==0) { session('apply_status', null); $this->ajaxReturn(['msg'=>'请输入账号' ,'status'=>0]); } M('test_resource', 'tab_')->commit(); //提交事物 $this->ajaxReturn(['msg'=>'' ,'status'=>1]); } else { $this->meta_title = '新增测试账号'; $this->display(); } } //修改申请 public function apply_edit(){ $user=M('user','tab_')->field('password')->where(['account'=>I('user_account')])->find(); if($user['password'] !== $this->think_ucenter_md5(I('user_password'), UC_AUTH_KEY)){ $this->ajaxReturn(['status'=>0,'msg'=>'密码不正确']); } $data['user_password']=I('user_password'); $data['role_name']=I('role_name'); $map = I("post."); unset($map['user_password']); unset($map['role_name']); $res=M('test_resource','tab_')->where($map)->save($data); if($res===false){ $this->ajaxReturn(['status'=>0,'msg'=>'修改失败']); }else{ $this->ajaxReturn(['status'=>1,'msg'=>'修改成功']); } } //后续申请 public function apply(){ $ids = explode(',', I('id')); foreach ($ids as $key => $value) { $map['id']=$value; $support=M('test_resource','tab_')->field('promote_id')->where($map)->find(); if($support['promote_id'] !=session("promote_auth.pid") || empty($support) ){ $this->error('数据错误'); } } $this->meta_title = '申请后续'; $this->display(); } //申请新增扶持(单个或批量申请) public function batch_apply(){ $ids = explode(',', I('apply_id')); M('test_resource','tab_')->startTrans(); //事物 foreach ($ids as $key => $value) { $map['id']=$value; $support=M('test_resource','tab_')->where($map)->find(); if(I('apply_resource') <0 || !preg_match('/^[1-9]\d*$/', I('apply_resource', 0))){ M('test_resource','tab_')->rollback();//回滚 $this->ajaxReturn(['status'=>0,'msg'=>'申请资源数量有误']); } if(empty($support)){ M('test_resource','tab_')->rollback();//回滚 $this->ajaxReturn(['status'=>0,'msg'=>'数据有误']); } //TODO:额度未进行验证 // $max_quota=$this->max_quota($support['game_id'],$support['server_name']);//最大申请额度 // if(count($ids)>1){ // $map_s['game_id']=$support['game_id']; // $map_s['server_name']=$support['server_name']; // $map_s['id'] =['in',$ids]; // $count=M('support','tab_')->where($map_s)->count(); // $max_quota = floor($max_quota/$count); // } // if(I('support_num') > $max_quota){ // M('support','tab_')->rollback();//回滚 // $this->ajaxReturn(['status'=>0,'msg'=>'扶持申请额度不足,最大额度:'.$max_quota]); // } if($support['promote_id'] !=session("promote_auth.pid") || empty($support) ){ M('test_resource','tab_')->rollback();//回滚 $this->ajaxReturn(['status'=>0,'msg'=>'申请失败']); } $data['game_id']=$support['game_id']; $data['game_name']=$support['game_name']; $data['server_id']=$support['server_id']; $data['server_name']=$support['server_name']; $data['user_account']=$support['user_account']; $data['user_id']=$support['user_id']; $data['user_password']=$support['user_password']; $data['phone']=$support['phone']; $data['role_name']=$support['role_name']; $data['apply_resource']=I('apply_resource'); $data['apply_remark']=I('apply_remark'); $data['apply_name']=$_SESSION['onethink_home']['promote_auth']['account']; $data['apply_id']=$_SESSION['onethink_home']['promote_auth']['pid']; $data['promote_id']=session("promote_auth.pid"); $data['promote_account']=session("promote_auth.account"); $data['create_time']=time(); $data['apply_type']=1; // $model = M('test_resource','tab_')->add($data); if($model===false){ M('test_resource','tab_')->rollback();//回滚 $this->ajaxReturn(['status'=>0,'msg'=>'申请失败']); }else{ //成功 } } M('test_resource','tab_')->commit(); //提交事物 $this->ajaxReturn(['status'=>1,'msg'=>'申请成功']); } }