测试资源根据可用余额进行验证

master
zhengyongxing 5 years ago
parent f840a59ce2
commit d6db0d3789

@ -2317,37 +2317,23 @@ function getrelationGameName($id) {
}
/**
* 操作日志
* uid=>用户id,
* radio=>游戏比例,
* 获取测试资源可用余额
* promote_id=>推广员id,
* game_id=>游戏id,
*/
function getAvailableBalance($uid,$radio=0) {
function getAvailableBalance($promote_id=0,$game_id=0) {
if (!$uid) {
if (!$promote_id||!$game_id) {
return 0;
}
$promoteId = M('user','tab_')->field('promote_id')->where(['id'=>$uid])->find()['promote_id'];
// $spendData = M('spend','tab_')
// ->field("date_format(FROM_UNIXTIME( pay_time),'%Y-%m-%d') AS time,sum(`pay_amount`)*{$radio} as pay_amount")
// ->where(['promote_id'=>$promoteId,'pay_status'=>1,'pay_way'=>['egt',1]])
// ->group('time')
// ->select();
$spend = M('spend','tab_')
->field("sum(`pay_amount`)*{$radio} as pay_amount")
->where(['promote_id'=>$promoteId,'pay_status'=>1,'pay_way'=>['egt',1]])
->find()['pay_amount'];
$applyResource = M('test_resource','tab_')
->field('sum(`apply_resource`) as apply_resource')
->where(['promote_id'=>$promoteId,'apply_status'=>2])
->find()['apply_resource'];
$availableBalanceData = M('promote_game_available_balance','tab_')
->field('available_balance')
->where(['promote_id'=>$promote_id,'game_id'=>$game_id])
->find();
return ($spend?$spend:0)-($applyResource?$applyResource:0);
return $availableBalanceData['available_balance']?$availableBalanceData['available_balance']:0;
}

@ -14,8 +14,6 @@ class MemberController extends ThinkController
*玩家列表信息
*/
public function user_info($p=0){
getAvailableBalance(34,0.5);
//设定默认时间
// if(!array_key_exists("time_start",$_REQUEST) && I('type') != 2){
// $this->redirect(ACTION_NAME, array('time_start' => date('Y-m-d',strtotime('-30 day')),"time_end"=>date('Y-m-d')));

@ -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, $i);
$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']);
// 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']])
->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('申请失败');

@ -261,4 +261,66 @@ class TimingController extends AdminController {
return $mid;
}
//格式 starttime 20200229 endtime 20200230
public function setAvailableBalance() {
if (strtotime($_GET['endtime'])<strtotime($_GET['starttime']) && $_GET['endtime']) {
echo '错误,结束时间小于开始时间';
}
// $starttime = 1571587200;
$starttime = strtotime(date('Ymd',time()));
// var_dump($starttime);die();
if ($_GET['starttime']) {
$starttime = strtotime($_GET['starttime']);
}
$endtime = $starttime + 86399;
if ($_GET['endtime']) {
$endtime = strtotime($_GET['endtime']) + 86399;
}
for ($start = $starttime; $start<$endtime; $start=$start + 86400) {
// var_dump($starttime);die();
$data = M('spend','tab_')
->field("sum(`pay_amount`) as pay_amount,promote_id,promote_account,tab_spend.game_id,tab_spend.game_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')
->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'] = $value['available_balance'];
$availableBalanceData = M('promote_game_available_balance','tab_')
->where(['promote_id'=>$value['promote_id'],'game_id'=>$value['game_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']])
->setInc('available_balance',round($value['available_balance'],0));
}
// dump(round($value['available_balance'],0));
}
}
echo '执行成功';
}
}

@ -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) {
if (!$promote_id||!$game_id) {
return 0;
}
$availableBalanceData = M('promote_game_available_balance','tab_')
->field('available_balance')
->where(['promote_id'=>$promote_id,'game_id'=>$game_id])
->find();
return $availableBalanceData['available_balance']?$availableBalanceData['available_balance']:0;
}

@ -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();
@ -480,7 +480,7 @@ class TestResourceController extends BaseController
}
} else {//非新用户
$availableBalance = getAvailableBalance($data['user_id'],$config['old_value_ratio']);
$availableBalance = getAvailableBalance($data['promote_id'],$data['game_id']);
$promoteAllRecharge = sum_promote_total_money($data['promote_id']);//总充值量
$allVerifyValue = $promoteAllRecharge * $config['old_value_ratio'];//可充值总量
@ -502,6 +502,11 @@ class TestResourceController extends BaseController
$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']])
->setDec('available_balance',$data['apply_resource']);
}
}
}
@ -545,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();

Loading…
Cancel
Save