diff --git a/Application/Admin/Common/extend.php b/Application/Admin/Common/extend.php index 9573b6724..19de23562 100644 --- a/Application/Admin/Common/extend.php +++ b/Application/Admin/Common/extend.php @@ -2316,4 +2316,26 @@ function getrelationGameName($id) { } +/** + * 获取测试资源可用余额 + * promote_id=>推广员id, + * game_id=>游戏id, + */ + +function getAvailableBalance($promote_id=0,$game_id=0,$server_id=0) { + + if (!$promote_id||!$game_id||!$server_id) { + return 0; + } + + $availableBalanceData = M('promote_game_available_balance','tab_') + ->field('available_balance') + ->where(['promote_id'=>$promote_id,'game_id'=>$game_id,'server_id'=>$server_id]) + ->find(); + + return $availableBalanceData['available_balance']?$availableBalanceData['available_balance']:0; + +} + + ?> diff --git a/Application/Admin/Controller/MemberController.class.php b/Application/Admin/Controller/MemberController.class.php index 8e3e15ede..c665e20fc 100644 --- a/Application/Admin/Controller/MemberController.class.php +++ b/Application/Admin/Controller/MemberController.class.php @@ -132,14 +132,12 @@ class MemberController extends ThinkController //计算用户列表 $data = M("user","tab_") - ->field("tab_user.id,`device_number`,`age_status`,`account`,`balance`,`gold_coin`,`alipay`,tab_user.promote_id,`register_type`,tab_user.promote_account,`register_time`,`lock_status`,lock_remark,`register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(sum(ss.pay_amount), 0) AS recharge_total") + ->field("tab_user.id,`device_number`,count(`device_number`) as device_count,`age_status`,`account`,`balance`,`gold_coin`,`alipay`,tab_user.promote_id,`register_type`,tab_user.promote_account,`register_time`,`lock_status`,lock_remark,`register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(sum(ss.pay_amount), 0) AS recharge_total") ->where($map) - ->group("tab_user.id") + ->group("tab_user.id,device_number,tab_user.promote_id,tab_user.login_ip") // ->page($page, $row) ->order($order); - if(!isset($_REQUEST['export'])){ - $data ->page($page, $row); - } + if($havs){ $data->having($havs); } @@ -158,7 +156,50 @@ class MemberController extends ThinkController }else{ $data->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1","left"); } + + $data = $data->select(false); + + $data = M()->table('(' . $data . ') as a ')->where(['device_count'=>['elt',1]]); + + if(!isset($_REQUEST['export'])){ + $data ->page($page, $row); + } + $data = $data->select(); +// var_dump($data);die(); + + //计算用户列表重复数量 + $userRepeat = M("user","tab_") + ->field("count(`device_number`) as device_count") + ->where($map) + ->group("tab_user.id,device_number,tab_user.promote_id,tab_user.login_ip") + // ->page($page, $row) + ->order($order); + + if($havs){ + $userRepeat->having($havs); + } + if($gameplay){ + $userRepeat->join(" + (select user_id from tab_user_play where 1 $gameplay group by tab_user_play.user_id) a ON a.user_id = tab_user.id + "); + } + if($game_map){ + $userRepeat->join(" + (select user_id from tab_user_play_info where 1 $game_map group by tab_user_play_info.user_id) a ON a.user_id = tab_user.id + "); + } + if($promoterSelect){ + $userRepeat->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1".$spendprom,"left"); + }else{ + $userRepeat->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1","left"); + } + + $userRepeat = $userRepeat->select(false); + $userRepeat = M()->table('(' . $userRepeat . ') as a ')->where(['device_count'=>['gt',1]])->count(); + + $this->assign('device_count',$userRepeat); + if(isset($_REQUEST['export'])){ $isadmin = is_administrator(); //获取等级 @@ -309,7 +350,7 @@ class MemberController extends ThinkController $this->assign('user_count',$user_count); $this->assign('now_count', $now_count?:0); - $page = set_pagination($user_count, $row); + $page = set_pagination($user_count-$userRepeat, $row); if ($page) { $this->assign('_page', $page); } diff --git a/Application/Admin/Controller/TestResourceController.class.php b/Application/Admin/Controller/TestResourceController.class.php index 8ac8ffc67..6ac905d6a 100644 --- a/Application/Admin/Controller/TestResourceController.class.php +++ b/Application/Admin/Controller/TestResourceController.class.php @@ -352,7 +352,9 @@ class TestResourceController extends ThinkController session('apply_status', 0); (empty(I('server_id')) || I('server_id')<1) && $this->error('请选择区服!');; - M('test_resource', 'tab_')->startTrans(); //事物 + M()->startTrans(); //事物 + + $resource = 0; for ($i=0; $i < $count ; $i++) { $i_account=I('user_account')[$i]; if (!empty($i_account)) { @@ -430,7 +432,10 @@ class TestResourceController extends ThinkController $data['create_time']=time(); $data['apply_type']=0; + $data = $this->checkAutoVerify($data, $resource, 0); + $model = M('test_resource', 'tab_')->add($data); + $resource += $data['apply_resource']; if ($model) { session('apply_status', 1); } @@ -457,6 +462,68 @@ class TestResourceController extends ThinkController } } + /** + *判断申请资源是否自动审核 + * @param $data array 新增数据 + * @param $resource int 此次已申请资源 + * @param $thisCount int 批量申请的第几次 + */ + private function checkAutoVerify($data, $resource = 0, $thisCount = 0) + { + $config = M('resource_verify_config', 'tab_') + ->where(['game_id' => $data['game_id'], 'status' => 1]) + ->find(); + if ($config) {//已存在该游戏的资源审核配置 +// var_dump($config);die(); + $count = M('test_resource', 'tab_') + ->where(['user_id' => $data['user_id'], 'game_id' => $data['game_id']]) + ->count(); + $count += $thisCount; + if ($count < $config['new_apply_count']) {//新用户 + //申请资源数量在最低额度和最高额度之间,自动审核 + if ($data['apply_resource'] >= $config['new_low_value'] && $data['apply_resource'] <= $config['new_high_value']) { + $data['verify_remark'] = '自动审核'; + $data['verify_resource']= $data['apply_resource']; + $data['verify_time'] = time(); + $data['apply_status'] = 2; + $data['is_new'] = 1; + } + } else {//非新用户 + + $availableBalance = getAvailableBalance($data['promote_id'],$data['game_id'],$data['server_id']); +// var_dump($availableBalance);die(); + + $promoteAllRecharge = sum_promote_total_money($data['promote_id']);//总充值量 + $allVerifyValue = $promoteAllRecharge * $config['old_value_ratio'];//可充值总量 + //已用资源(申请通过的) + $used_resource = M('test_resource', 'tab_') + ->where([ + 'promote_id' => $data['promote_id'], + 'game_id' => $data['game_id'], + 'apply_status' => 2, + 'is_new' => 2, + ]) + ->getField('SUM(verify_resource) as used_resource'); + $used_resource = $used_resource ?: 0; + $usable_resource = $allVerifyValue - $used_resource;//小于等于这个值自动审核 + $usable_resource -= $resource; + if ($data['apply_resource'] <= $usable_resource&&$data['apply_resource']<$availableBalance) { + $data['verify_remark'] = '自动审核'; + $data['verify_resource']= $data['apply_resource']; + $data['verify_time'] = time(); + $data['apply_status'] = 2; + $data['is_new'] = 2; + + M('promote_game_available_balance','tab_') + ->where(['promote_id'=>$data['promote_id'],'game_id'=>$data['game_id'],'server_id'=>$data['server_id']]) + ->setDec('available_balance',$data['apply_resource']); + } + } + } + + return $data; + } + public function edit() { $id = I('id'); @@ -519,7 +586,8 @@ class TestResourceController extends ThinkController public function batch_apply(){ $ids = explode(',', I('id')); - M('test_resource','tab_')->startTrans(); //事物 + M()->startTrans(); //事物 + $resource = 0; foreach ($ids as $key => $value) { $map['id']=$value; @@ -575,8 +643,10 @@ class TestResourceController extends ThinkController $data['create_time']=time(); $data['apply_type']=1; + $data = $this->checkAutoVerify($data, $resource, $key); // $model = M('test_resource','tab_')->add($data); + $resource += $data['apply_resource']; if($model===false){ M('test_resource','tab_')->rollback();//回滚 $this->error('申请失败'); diff --git a/Application/Admin/Controller/TimingController.class.php b/Application/Admin/Controller/TimingController.class.php index 438a28079..137324bfc 100644 --- a/Application/Admin/Controller/TimingController.class.php +++ b/Application/Admin/Controller/TimingController.class.php @@ -261,4 +261,68 @@ class TimingController extends AdminController { return $mid; } + //格式 starttime 20200229 endtime 20200230 + public function setAvailableBalance() { + + if (strtotime($_GET['endtime'])field("sum(`pay_amount`) as pay_amount,promote_id,promote_account,tab_spend.game_id,tab_spend.game_name,tab_spend.server_id,tab_spend.server_name,CASE WHEN old_value_ratio is NULL THEN 0 ELSE sum(`pay_amount`) * old_value_ratio END as available_balance") + ->join('left join tab_resource_verify_config as config on tab_spend.game_id = config.game_id') + ->where(['pay_status'=>1,'pay_way'=>['egt',1],'pay_time'=>['between',[$start,$start+86399]]]) + ->group('promote_id,game_id,server_id') + ->select(); +// var_dump($data);die(); + + foreach ($data as $key => $value) { + + $insert['promote_id'] = $value['promote_id']; + $insert['promote_account'] = $value['promote_account']; + $insert['game_id'] = $value['game_id']; + $insert['game_name'] = $value['game_name']; + $insert['available_balance'] = round($value['available_balance'],0); + $insert['server_id'] = $value['server_id']; + $insert['server_name'] = $value['server_name']; + + $availableBalanceData = M('promote_game_available_balance','tab_') + ->where(['promote_id'=>$value['promote_id'],'game_id'=>$value['game_id'],'server_id'=>$value['server_id']]) + ->find(); + + if (round($value['available_balance'],0) > 0 && !$availableBalanceData) { + M('promote_game_available_balance','tab_')->add($insert); + } else if (round($value['available_balance'],0) > 0 && $availableBalanceData) { + M('promote_game_available_balance','tab_') + ->where(['promote_id'=>$value['promote_id'],'game_id'=>$value['game_id'],'server_id'=>$value['server_id']]) + ->setInc('available_balance',round($value['available_balance'],0)); + } +// dump(round($value['available_balance'],0)); + + } + + } + + echo '执行成功'; + + + } + } diff --git a/Application/Admin/View/Member/user_info.html b/Application/Admin/View/Member/user_info.html index 5b9d6eb37..4d78b4460 100644 --- a/Application/Admin/View/Member/user_info.html +++ b/Application/Admin/View/Member/user_info.html @@ -348,15 +348,18 @@ 当前用户累计充值:{$now_count}    历史累计充值:{$history_count}   - 用户数:{$user_count} + 用户数:{$user_count}   + 去充用户数:{$device_count} 当前用户累计充值: 当前属于该推广员的用户的充值累计(不含用户换绑前记录)  /   - 历史累计充值: 历史中属于该推广员的用户的充值累计(含用户换绑前记录) + 历史累计充值: 历史中属于该推广员的用户的充值累计(含用户换绑前记录)   + 去充用户数:{$device_count} - 当前用户累计充值:{$now_count}  用户数:{$user_count} + 当前用户累计充值:{$now_count}  用户数:{$user_count}   + 去充用户数:{$device_count} diff --git a/Application/Home/Common/function.php b/Application/Home/Common/function.php index e52beea47..6a43b98fc 100644 --- a/Application/Home/Common/function.php +++ b/Application/Home/Common/function.php @@ -1301,3 +1301,24 @@ function recordPromoteLogs($module,$action_type) { M('promote_action_logs','tab_')->add($promoteLogsData); } + +/** + * 获取测试资源可用余额 + * promote_id=>推广员id, + * game_id=>游戏id, + */ + +function getAvailableBalance($promote_id=0,$game_id=0,$server_id=0) { + + if (!$promote_id||!$game_id||!$server_id) { + return 0; + } + + $availableBalanceData = M('promote_game_available_balance','tab_') + ->field('available_balance') + ->where(['promote_id'=>$promote_id,'game_id'=>$game_id,'server_id'=>$server_id]) + ->find(); + + return $availableBalanceData['available_balance']?$availableBalanceData['available_balance']:0; + +} diff --git a/Application/Home/Controller/TestResourceController.class.php b/Application/Home/Controller/TestResourceController.class.php index e6dc2f37f..cae0bb858 100644 --- a/Application/Home/Controller/TestResourceController.class.php +++ b/Application/Home/Controller/TestResourceController.class.php @@ -352,7 +352,7 @@ class TestResourceController extends BaseController $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(); //事物 + M()->startTrans(); //事物 $resource = 0; for ($i=0; $i < $count ; $i++) { $data = array(); @@ -428,7 +428,7 @@ class TestResourceController extends BaseController $data['create_time']=time(); $data['apply_type']=0; - $data = $this->checkAutoVerify($data, $resource, $i); + $data = $this->checkAutoVerify($data, $resource, 0); $model = M('test_resource', 'tab_')->add($data); $resource += $data['apply_resource']; if ($model) { @@ -479,6 +479,9 @@ class TestResourceController extends BaseController $data['is_new'] = 1; } } else {//非新用户 + + $availableBalance = getAvailableBalance($data['promote_id'],$data['game_id'],$data['server_id']); + $promoteAllRecharge = sum_promote_total_money($data['promote_id']);//总充值量 $allVerifyValue = $promoteAllRecharge * $config['old_value_ratio'];//可充值总量 //已用资源(申请通过的) @@ -493,12 +496,17 @@ class TestResourceController extends BaseController $used_resource = $used_resource ?: 0; $usable_resource = $allVerifyValue - $used_resource;//小于等于这个值自动审核 $usable_resource -= $resource; - if ($data['apply_resource'] <= $usable_resource) { + if ($data['apply_resource'] <= $usable_resource&&$data['apply_resource']<$availableBalance) { $data['verify_remark'] = '自动审核'; $data['verify_resource']= $data['apply_resource']; $data['verify_time'] = time(); $data['apply_status'] = 2; $data['is_new'] = 2; + + M('promote_game_available_balance','tab_') + ->where(['promote_id'=>$data['promote_id'],'game_id'=>$data['game_id'],'server_id'=>$data['server_id']]) + ->setDec('available_balance',$data['apply_resource']); + } } } @@ -542,7 +550,7 @@ class TestResourceController extends BaseController public function batch_apply(){ $ids = explode(',', I('apply_id')); - M('test_resource','tab_')->startTrans(); //事物 + M()->startTrans(); //事物 $resource = 0; foreach ($ids as $key => $value) { $data = array();