资源自动审核扣除已审核额度,申请后续增加自动审核功能

master
liuweiwen 5 years ago
parent 9d7cfd768e
commit 5d05edbca6

@ -353,7 +353,9 @@ class TestResourceController extends BaseController
session('apply_status', 0);
(empty(I('server_id')) || I('server_id')<1) && $this->ajaxReturn(['msg'=>$i_account.'请选择区服' ,'status'=>0]);
M('test_resource', 'tab_')->startTrans(); //事物
$resource = 0;
for ($i=0; $i < $count ; $i++) {
$data = array();
$i_account=I('user_account')[$i];
if (!empty($i_account)) {
$user=M('user', 'tab_')->field('promote_id,password,phone')->where(['account'=>$i_account])->find();
@ -426,8 +428,9 @@ class TestResourceController extends BaseController
$data['create_time']=time();
$data['apply_type']=0;
$data = $this->checkAutoVerify($data);
$data = $this->checkAutoVerify($data, $resource);
$model = M('test_resource', 'tab_')->add($data);
$resource += $data['apply_resource'];
if ($model) {
session('apply_status', 1);
}
@ -453,7 +456,7 @@ class TestResourceController extends BaseController
/**
*判断申请资源是否自动审核
*/
private function checkAutoVerify($data)
private function checkAutoVerify($data, $resource = 0)
{
$config = M('resource_verify_config', 'tab_')
->where(['game_id' => $data['game_id'], 'status' => 1])
@ -466,19 +469,36 @@ class TestResourceController extends BaseController
//申请资源数量在最低额度和最高额度之间,自动审核
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 {//非新用户
$promoteAllRecharge = sum_promote_total_money($data['promote_id']);//总充值量
$autoVerifyValue = $promoteAllRecharge * $config['old_value_ratio'];
if ($data['apply_resource'] <= $autoVerifyValue) {
$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['verify_remark'] = '自动审核';
$data['verify_resource']= $data['apply_resource'];
$data['verify_time'] = time();
$data['apply_status'] = 2;
$data['is_new'] = 2;
}
}
}
return $data;
}
@ -519,8 +539,9 @@ class TestResourceController extends BaseController
$ids = explode(',', I('apply_id'));
M('test_resource','tab_')->startTrans(); //事物
$resource = 0;
foreach ($ids as $key => $value) {
$data = array();
$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))){
@ -574,8 +595,9 @@ class TestResourceController extends BaseController
$data['create_time']=time();
$data['apply_type']=1;
//
$data = $this->checkAutoVerify($data, $resource);
$model = M('test_resource','tab_')->add($data);
$resource += $data['apply_resource'];
if($model===false){
M('test_resource','tab_')->rollback();//回滚
$this->ajaxReturn(['status'=>0,'msg'=>'申请失败']);

@ -1374,3 +1374,5 @@ CREATE TABLE `tab_resource_verify_config` (
`update_time` int(11) DEFAULT '0' COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='资源审核配置';
ALTER TABLE tab_test_resource ADD COLUMN `is_new` tinyint(1) DEFAULT '0' COMMENT '0-未知1-新用户;2-非新用户';

Loading…
Cancel
Save