|
|
<?php
|
|
|
|
|
|
namespace Home\Controller;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 前台首页控制器
|
|
|
* 主要获取首页聚合数据
|
|
|
*/
|
|
|
class SupportController extends BaseController {
|
|
|
|
|
|
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 lists( $p = 1 ){
|
|
|
$page = intval($p);
|
|
|
$page = $page ? $page : 1; //默认显示第一页数据
|
|
|
$row=10;
|
|
|
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
|
|
|
if(!empty(I('type'))||I('type')==='0'){
|
|
|
$map['status']=I('type');
|
|
|
if(I('type')==2){
|
|
|
$map['status']=2;
|
|
|
$map['notice_status']=1;
|
|
|
}
|
|
|
if(I('type')==1){
|
|
|
$map['status']=[1,2,'or'];
|
|
|
$map['notice_status']=0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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']);
|
|
|
}
|
|
|
$map['promote_id']=session("promote_auth.pid");
|
|
|
$data=M('support','tab_')->where($map)->order('id desc')->page($page,$row)->select();
|
|
|
$count=M('support','tab_')->field('id')->where($map)->select();
|
|
|
$count = count($count);
|
|
|
|
|
|
$parameter = I();
|
|
|
$parameter['p']=I('get.p',1);
|
|
|
$parameter['row']=I('get.row');
|
|
|
|
|
|
|
|
|
$page = set_pagination($count,$row,$parameter);
|
|
|
if($page) {$this->assign('_page', $page);}
|
|
|
|
|
|
$this->meta_title = '扶持记录';
|
|
|
$this->assign('data',$data);
|
|
|
$this->assign('count',$count);
|
|
|
$this->display();
|
|
|
}
|
|
|
//扶持申请首页
|
|
|
public function index($p = 0){
|
|
|
$page = intval($p);
|
|
|
$page = $page ? $page : 1; //默认显示第一页数据
|
|
|
$row=10;
|
|
|
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
|
|
|
|
|
|
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']);
|
|
|
}
|
|
|
$map['promote_id']=session("promote_auth.pid");
|
|
|
$map['support_type']=0;
|
|
|
$map['status']=2;
|
|
|
$map['notice_status']=1;
|
|
|
$data=M('support','tab_')->where($map)->order('id desc')->page($page,$row)->select();
|
|
|
$count=M('support','tab_')->field('id')->where($map)->select();
|
|
|
$count = count($count);
|
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
$map1['user_id']=$value['user_id'];
|
|
|
$map1['game_id']=$value['game_id'];
|
|
|
$map1['server_name']=$value['server_name'];
|
|
|
|
|
|
$map1['support_type']=1;
|
|
|
$map1['status']=2;
|
|
|
$map1['notice_status']=1;
|
|
|
$data1 = M('support','tab_')->field('count(id) count_support_num,sum(real_support_num) sum_support_num')->where($map1)->select();
|
|
|
$data[$key]['count_support_num']=$data1[0]['count_support_num']+1;
|
|
|
$data[$key]['sum_support_num'] =$data1[0]['sum_support_num']+$value['real_support_num'];
|
|
|
}
|
|
|
|
|
|
$parameter =I();
|
|
|
$parameter['p']=I('get.p',1);
|
|
|
$parameter['row']=I('get.row');
|
|
|
|
|
|
|
|
|
$page = set_pagination($count,$row,$parameter);
|
|
|
if($page) {$this->assign('_page', $page);}
|
|
|
|
|
|
$this->meta_title = '扶持申请';
|
|
|
$this->assign('data',$data);
|
|
|
$this->assign('count',$count);
|
|
|
$this->display();
|
|
|
}
|
|
|
//扶持额度
|
|
|
public function quota($p = 0){
|
|
|
$page = intval($p);
|
|
|
$page = $page ? $page : 1; //默认显示第一页数据
|
|
|
$arraypage = $page; //默认显示第一页数据
|
|
|
$row=10;
|
|
|
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
|
|
|
if(!empty(I('game_id'))){
|
|
|
$map['id']=I('game_id');
|
|
|
}
|
|
|
$map['game_status']=1;
|
|
|
$map['apply_status']=1;
|
|
|
$map['online_status']=1;
|
|
|
|
|
|
$all_promote = $this->get_all_promote();
|
|
|
$data=M('game','tab_')->field('id,game_name')->where($map)->select();
|
|
|
foreach ($data as $k => $v) {
|
|
|
$map_s['promote_id']=['in',$all_promote];
|
|
|
$map_s['game_id']=$v['id'];
|
|
|
$info=M('support','tab_')
|
|
|
->alias('s')
|
|
|
->field('game_name, game_id,
|
|
|
SUM(if(support_type=1 and notice_status=1,real_support_num,0)) as yifafang,
|
|
|
SUM(if(support_type=0 and notice_status=1,real_support_num,0)) as yifafangxinzeng,
|
|
|
SUM(if(support_type=1 and status!=0 and notice_status=0,support_num,0)) as daishenhehouxu,
|
|
|
SUM(if(support_type=0 and status!=0 and notice_status=0,support_num,0)) as daishenhexinzeng
|
|
|
')
|
|
|
->where($map_s)
|
|
|
->select();
|
|
|
|
|
|
$data[$k]['game_id'] =$v['id'];
|
|
|
$data[$k]['leijiedu'] =$info[0]['leijiedu']==''?0:$info[0]['leijiedu'];
|
|
|
$data[$k]['yifafang'] =$info[0]['yifafang']==''?0:$info[0]['yifafang'];
|
|
|
$data[$k]['yifafangxinzeng'] =$info[0]['yifafangxinzeng']==''?0:$info[0]['yifafangxinzeng'];
|
|
|
$data[$k]['daishenhehouxu'] =$info[0]['daishenhehouxu']==''?0:$info[0]['daishenhehouxu'];
|
|
|
$data[$k]['daishenhexinzeng'] =$info[0]['daishenhexinzeng']==''?0:$info[0]['daishenhexinzeng'];
|
|
|
|
|
|
|
|
|
}
|
|
|
foreach ($data as $key => $value) {
|
|
|
$data[$key]['leijiedu']=floor($this->leijiedu($value['game_id']));
|
|
|
$map_g['promote_id']=['in',$all_promote];
|
|
|
$map_g['create_time']=['between',[strtotime(date('Y-m-d',time())),time()]];
|
|
|
$map_g['game_id']=$value['game_id'];
|
|
|
$today=M('support','tab_')
|
|
|
->field('SUM(if(support_type=1 and notice_status=1,real_support_num,0)) as jinriyishenqing,
|
|
|
SUM(if(support_type=1,support_num,0)) as jinrixinshenqing')
|
|
|
->where($map_g)
|
|
|
->select();
|
|
|
|
|
|
$data[$key]['jinriyishenqing']=$today[0]['jinriyishenqing']==''?0:$today[0]['jinriyishenqing'];
|
|
|
$data[$key]['jinrixinshenqing']=$today[0]['jinrixinshenqing']==''?0:$today[0]['jinrixinshenqing'];
|
|
|
$data[$key]['keyongedu']= floor($data[$key]['leijiedu'] - $data[$key]['yifafang'] - $data[$key]['daishenhehouxu']);
|
|
|
}
|
|
|
//根据字段leijiedu对数组$data进行降序排列
|
|
|
$last_names = array_column($data,'leijiedu');
|
|
|
array_multisort($last_names,SORT_DESC,$data);
|
|
|
|
|
|
$count=count($data);
|
|
|
//分页
|
|
|
$parameter = I();
|
|
|
$parameter['p']=I('get.p',1);
|
|
|
$parameter['row']=I('get.row');
|
|
|
|
|
|
|
|
|
$page = set_pagination($count,$row,$parameter);
|
|
|
if($page) {$this->assign('_page', $page);}
|
|
|
|
|
|
$size=$row;//每页显示的记录数
|
|
|
$pnum = ceil(count($data) / $size); //总页数,ceil()函数用于求大于数字的最小整数
|
|
|
//用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度)
|
|
|
$data = array_slice($data, ($arraypage-1)*$size, $size);
|
|
|
$this->meta_title = '扶持额度';
|
|
|
$this->assign('data',$data);
|
|
|
$this->assign('count',$count);
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
|
|
|
public function leijiedu($game_id){
|
|
|
$ratio=M('game','tab_')->where(['id'=>$game_id])->getField('support_ratio');
|
|
|
$map['game_id']=$game_id;
|
|
|
$map['pay_status']=1;
|
|
|
$all_promote = $this->get_all_promote();
|
|
|
$map['promote_id'] = array('in',$all_promote);
|
|
|
$amount=M('spend','tab_')->field('SUM(pay_amount) as sum_amount')->where($map)->select();
|
|
|
$leijiedu= $amount[0]['sum_amount']*$ratio/100 > 0 ? $amount[0]['sum_amount']*$ratio/100 : 0;
|
|
|
return $leijiedu;
|
|
|
|
|
|
}
|
|
|
|
|
|
//获取当前和当前子渠道的渠道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;
|
|
|
}
|
|
|
|
|
|
|
|
|
//新增扶持
|
|
|
public function add(){
|
|
|
if(IS_POST){
|
|
|
$count=count(I('user_account'));
|
|
|
session('apply_status',0);
|
|
|
M('support','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')->where(['account'=>$i_account])->find();
|
|
|
$promote = $this->get_all_promote();
|
|
|
if(!in_array( $user['promote_id'] , $promote)){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['msg'=>$i_account.'账号不存在' ,'status'=>0]);
|
|
|
}
|
|
|
if(empty(I('user_password')[$i])){
|
|
|
M('support','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('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['msg'=>$i_account.'密码不正确' ,'status'=>0]);
|
|
|
}
|
|
|
if(empty(I('role_name')[$i])){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['msg'=>I('user_account')[$i].'请输入角色名' ,'status'=>0]);
|
|
|
}
|
|
|
$supportNum = I('support_num')[$i];
|
|
|
if(empty($supportNum)){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['msg'=>I('user_account')[$i].'请输入扶持数量' ,'status'=>0]);
|
|
|
}
|
|
|
if($supportNum<0 || !preg_match('/^[1-9]\d*$/', $supportNum)){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['msg'=>I('user_account')[$i].'请输入扶持数量' ,'status'=>0]);
|
|
|
}
|
|
|
$map['game_id']=get_game_id(I('game_name'));
|
|
|
$map['server_name']=I('server_name');
|
|
|
$map['user_account']=I('user_account')[$i];
|
|
|
$map['status']=['neq',0];
|
|
|
$map['support_type']=0;
|
|
|
$list= M('support','tab_')->where($map)->find();
|
|
|
if($list){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['msg'=>I('user_account')[$i].'账号已存在' ,'status'=>0]);
|
|
|
}
|
|
|
|
|
|
$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('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['msg'=>'超出申请额度' ,'status'=>0]);
|
|
|
}
|
|
|
|
|
|
$data['game_id']=get_game_id(I('game_name'));
|
|
|
$data['game_name']=I('game_name');
|
|
|
$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']=base64_encode(I('user_password')[$i]);
|
|
|
$data['role_name']=I('role_name')[$i];
|
|
|
$data['support_num']=I('support_num')[$i];
|
|
|
$data['remarks']=I('remarks')[$i];
|
|
|
$data['promote_id']=session("promote_auth.pid");
|
|
|
$data['promote_account']=session("promote_auth.account");
|
|
|
$data['create_time']=time();
|
|
|
$data['support_type']=0;
|
|
|
$data['status']=C('SUPPORT_AUTO_AUDIT')==1?2:1;
|
|
|
$model = M('support','tab_')->add($data);
|
|
|
if($model){
|
|
|
session('apply_status',1);
|
|
|
}
|
|
|
if(C('SUPPORT_AUTO_AUDIT')==1){ //自动审核开启,请求cp发放扶持
|
|
|
$add_id = M()->getLastInsID();
|
|
|
$res=0;
|
|
|
if($res==1){ //cp对接返回成功
|
|
|
M('support','tab_')->where(['id'=>$add_id])->setField('notice_status',1);
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
if(I('user_password')[$i]){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['msg'=>'请输入账号' ,'status'=>0]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if(session('apply_status')==0){
|
|
|
session('apply_status',null);
|
|
|
$this->ajaxReturn(['msg'=>'请输入账号' ,'status'=>0]);
|
|
|
}
|
|
|
M('support','tab_')->commit(); //提交事物
|
|
|
$this->ajaxReturn(['msg'=>'' ,'status'=>1]);
|
|
|
|
|
|
}else{
|
|
|
$this->meta_title = '新增扶持';
|
|
|
$this->display();
|
|
|
|
|
|
}
|
|
|
}
|
|
|
//判断玩家账号是否属于该渠道
|
|
|
public function is_shuyu_promote(){
|
|
|
$map['account']=I('user_account');
|
|
|
$user=M('user','tab_')->field('promote_id')->where($map)->find();
|
|
|
|
|
|
$promote = $this->get_all_promote();
|
|
|
if( in_array( $user['promote_id'] , $promote)){
|
|
|
|
|
|
$this->ajaxReturn(['status'=>1]);
|
|
|
}else{
|
|
|
|
|
|
$this->ajaxReturn(['status'=>0]);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//修改扶持新增
|
|
|
public function support_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'=>'密码不正确']);
|
|
|
}
|
|
|
$map['id']=I('id');
|
|
|
$data['user_password']=base64_encode(I('user_password'));
|
|
|
$data['role_name']=I('role_name');
|
|
|
$res=M('support','tab_')->where($map)->save($data);
|
|
|
if($res===false){
|
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'修改失败']);
|
|
|
}else{
|
|
|
$this->ajaxReturn(['status'=>1,'msg'=>'修改成功']);
|
|
|
}
|
|
|
}
|
|
|
//申请新增扶持(单个或批量申请)
|
|
|
public function batch_apply(){
|
|
|
$ids = explode(',', I('support_id'));
|
|
|
|
|
|
M('support','tab_')->startTrans(); //事物
|
|
|
foreach ($ids as $key => $value) {
|
|
|
|
|
|
$map['id']=$value;
|
|
|
$support=M('support','tab_')->where($map)->find();
|
|
|
if(I('support_num') <0 || !preg_match('/^[1-9]\d*$/', I('support_num', 0))){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'扶持申请额度有误']);
|
|
|
}
|
|
|
if(empty($support)){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'数据有误']);
|
|
|
}
|
|
|
$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($support['promote_id'] !=session("promote_auth.pid") || empty($support) ){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'申请失败']);
|
|
|
}
|
|
|
if(I('support_num') > $max_quota){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'扶持申请额度不足,最大额度:'.$max_quota]);
|
|
|
}
|
|
|
$data['game_id']=$support['game_id'];
|
|
|
$data['game_name']=$support['game_name'];
|
|
|
$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['role_name']=$support['role_name'];
|
|
|
$data['support_num']=I('support_num');
|
|
|
$data['remarks']=I('remarks');
|
|
|
|
|
|
$data['promote_id']=$support['promote_id'];
|
|
|
$data['promote_account']=$support['promote_account'];
|
|
|
$data['create_time']=time();
|
|
|
$data['support_type']=1;
|
|
|
$data['status']=C('SUPPORT_AUTO_AUDIT')==1?2:1;
|
|
|
$model = M('support','tab_')->add($data);
|
|
|
if($model===false){
|
|
|
M('support','tab_')->rollback();//回滚
|
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'申请失败']);
|
|
|
}else{
|
|
|
//成功
|
|
|
}
|
|
|
}
|
|
|
M('support','tab_')->commit(); //提交事物
|
|
|
$this->ajaxReturn(['status'=>1,'msg'=>'申请成功']);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
//后续扶持
|
|
|
public function apply(){
|
|
|
$ids = explode(',', I('id'));
|
|
|
foreach ($ids as $key => $value) {
|
|
|
$map['id']=$value;
|
|
|
$support=M('support','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 max_quota($game_id,$server_name=0){
|
|
|
|
|
|
$map_s['game_id'] =$game_id;
|
|
|
$map_s['promote_id'] =session("promote_auth.pid");
|
|
|
$map_s['support_type'] =1;
|
|
|
$map_s['notice_status'] =1;
|
|
|
if($server_name!=0){
|
|
|
$map_s['server_name'] =$server_name;
|
|
|
}
|
|
|
$yishenhe_support_sum=M('support','tab_')->field("SUM(real_support_num) as sum_support_num")->where($map_s)->select();
|
|
|
$map_s['status'] =['neq',0];
|
|
|
$map_s['notice_status'] =0;
|
|
|
$weishenhe_support_sum=M('support','tab_')->field("SUM(support_num) as sum_support_num")->where($map_s)->select();
|
|
|
|
|
|
$support_quota=M('game','tab_')->field('support_quota,support_ratio')->where(['id'=>$game_id])->find();
|
|
|
// $max_quota=$support_quota['support_quota']-$yishenhe_support_sum[0]['sum_support_num']-$weishenhe_support_sum[0]['sum_support_num']; //一: 可用额度 = 后台设置额度 - 待审核额度 - 已申请成功发放额度
|
|
|
|
|
|
$map_sp['pay_status']=1;
|
|
|
$map_sp['game_id']=$game_id;
|
|
|
$child_promote = get_zi_promote_id(session("promote_auth.pid"));
|
|
|
if($child_promote==0){
|
|
|
$child_promote = session("promote_auth.pid");
|
|
|
}else{
|
|
|
$child_promote = $child_promote .','.session("promote_auth.pid");
|
|
|
}
|
|
|
$map_sp['promote_id'] = ['in',$child_promote];
|
|
|
$spend=M('spend','tab_')->field('SUM(pay_amount) as sum_amount')->where($map_sp)->select();
|
|
|
// 该渠道该游戏可用额度 = 该渠道和子渠道的所有玩家的充值量 * 扶持额度 - 待审核额度 - 已申请成功发放额度
|
|
|
$promote_quota=floor($spend[0]['sum_amount'] * $support_quota['support_ratio']/100 - $yishenhe_support_sum[0]['sum_support_num']-$weishenhe_support_sum[0]['sum_support_num']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!empty($server_name)){ //单个区服后续可申请额度
|
|
|
unset($map_sp['promote_id']);
|
|
|
$map_sp['server_name']=$server_name;
|
|
|
$spend=M('spend','tab_')->field('SUM(pay_amount) as sum_amount')->where($map_sp)->order('sum_amount desc')->group('user_id')->select();
|
|
|
|
|
|
$spend_quota=$spend[0]['sum_amount'];
|
|
|
}else{ //该渠道可用额度
|
|
|
return floor($promote_quota) < 1 ? 0 : floor($promote_quota);
|
|
|
|
|
|
}
|
|
|
//2个可以用额度去最小额度
|
|
|
$quota=$spend_quota > $promote_quota ? $promote_quota : $spend_quota;
|
|
|
|
|
|
return floor($quota) < 1 ? 0 : floor($quota);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 系统非常规MD5加密方法
|
|
|
* @param string $str 要加密的字符串
|
|
|
* @return string
|
|
|
*/
|
|
|
public function think_ucenter_md5($str, $key = 'ThinkUCenter'){
|
|
|
return '' === $str ? '' : md5(sha1($str) . $key);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取区服列表
|
|
|
* @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.server_name,support_quota')
|
|
|
->where($map)
|
|
|
->join('join tab_game tg ON tg.id=tab_server.game_id')
|
|
|
->select();
|
|
|
|
|
|
$this->AjaxReturn($data);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|