关闭房间->举报->审核通过扣款

// 举报审核通过扣款
    public function game_after_dispatch($cid,$uid,$row) {
        
        $yajin = dr_var("jiaonajin");
        $fenpei = 0.8*$yajin;
        $suijishu = rand(1000,9999);
         
        //1.判断该玩家以及该房间是否被举报并且扣除费用($cid,$row['jubaowanjia'],status=1)=>举报并且通过的不再扣除任何费用
        $is_exist=$this->db->select('id')->get_where("imt_1_room_comment_data_0",array('cid' => $cid,'jubaowanjia'=>$row['jubaowanjia'],'status'=>1))->row_array();
            
        //2.判断该玩家是否是新被举报的人(如果在该房间遇到其他被举报人,需要将其上次分配到的钱退回,并且重新参与分配)=>将上次收到的钱退回给未被举报的其他人
        $is_new_exist = $this->db->select('id')->get_where("imt_1_room_comment_data_0",array('cid' => $cid,'status'=>1))->row_array();
       
        if($is_new_exist){
            
            //(1)该房间所有的uids
            $other_uids_str = dr_room_details($cid)['0']['uids'];
            $other_uids_array = explode(',',$other_uids_str);
            array_push($other_uids_array,$uid);
            
            //(2)房间总人数
            $room_person = count($other_uids_array);
            
            //(3)所有举报的玩家的uids
            $jubaowanjias_mazy = $this->db->select('jubaowanjia')->get_where("imt_1_room_comment_data_0",array('cid' => $cid,'status'=>1))->result_array();
            $jubaowanjias=[];
            foreach($jubaowanjias_mazy as $jubaowanjia){
                $jubaowanjias[] = $jubaowanjia['jubaowanjia'];
            }
            array_push($jubaowanjias,$row['jubaowanjia']);
            
            //(4)正常的玩家uids
            $new_uids = array_diff($other_uids_array,$jubaowanjias);
            
            //(5)将上n次收到的钱退回($refund)
            $refund_sum_arrays = $this->db->select('value')->get_where("imt_member_paylog",array('room_close_cid' => $cid,'uid'=>$row['jubaowanjia']))->result_array();
            foreach($refund_sum_arrays as $refund_sum_array){
                $refunds[] =abs($refund_sum_array['value']);
            }
            $refund = array_sum($refunds);
            
            //(6)扣除他的押金以及上n次收到的钱
            $new_refund = $yajin+ number_format($refund, 2, '.', '');
            $this->db->set('money','money-'.$new_refund,false)->where('uid', $row['jubaowanjia'])->update('member');
            $this->db->insert('member_paylog', [
                'uid' => $row['jubaowanjia'],
                'room_close_cid'=>$cid,
                'note' => '扣除房间押金'.$yajin.'以及上前几次分配给的你的房间押金'.number_format($refund, 2, '.', ''),
                'type' => '',
                'value' => -$new_refund,
                'order_number' => SYS_TIME.$suijishu,
                'status' => 0,
                'module' => '',
                'inputtime' => SYS_TIME
            ]);
            
            //(7)分配钱(平台保留20%后剩余的押金部分+refund)
            $new_fenpei = $fenpei+number_format($refund, 2, '.', '');
            $new_person_num = count($new_uids);
            $new_per_money = number_format(($new_fenpei/$new_person_num), 2, '.', '');
           
            foreach($new_uids as $new_uid){
                //给每个用户赏金
                $this->db->set('money','money+'.$new_per_money,false)->where('uid', $new_uid)->update('member');
                
                $this->db->insert('member_paylog', [
                    'uid' => $new_uid,
                    'room_close_cid'=>$cid,
                    'note' => '获得被举报人的房间押金'.$new_per_money,
                    'type' => '',
                    'value' => +$new_per_money,
                    'order_number' => SYS_TIME.$suijishu,
                    'status' => 0,
                    'module' => '',
                    'inputtime' => SYS_TIME
                ]);
            }
        }
        
        if(!$is_exist && !$is_new_exist){
            //3.未被举报的 或者被举报没有通过的 审核通过走正常流程
            //oliver queen
            //房间的所有uids(房间号为$cid)
            $other_uids_str = dr_room_details($cid)['0']['uids'];
            $other_uids_array = explode(',',$other_uids_str);
            array_push($other_uids_array,$uid);
            //排除被举报的uids
            $jubaowanjia = $row['jubaowanjia'];
            foreach($other_uids_array as $value){
                if($value!=$jubaowanjia){
                    $other_uids[]=$value;
                }
            }
            //把钱分配给的人数
            $person_num = count($other_uids);
            //扣除该玩家的缴纳金,平台保留20%('房间内的其他人分80%')
            // $yajin = dr_var("jiaonajin");
            //扣除该玩家的缴纳金
            $this->db->set('money','money-'.$yajin,false)->where('uid', $jubaowanjia)->update('member');
            
            $this->db->insert('member_paylog', [
                'uid' => $row['jubaowanjia'],
                'room_close_cid'=>$cid,
                'note' => '扣除房间押金'.$yajin,
                'type' => '',
                'value' => -$yajin,
                'order_number' => SYS_TIME.$suijishu,
                'status' => 0,
                'module' => '',
                'inputtime' => SYS_TIME
            ]);
            
            //将80%的费用平均分配给该房间的其他玩家
            // $fenpei = 0.8*$yajin;
            //平均每人分得的金钱数
            $per_money = number_format(($fenpei/$person_num), 2, '.', '');
            
            foreach($other_uids as $other_uid){
                //给每个用户赏金
                $this->db->set('money','money+'.$per_money,false)->where('uid', $other_uid)->update('member');
                $this->db->insert('member_paylog', [
                    'uid' => $other_uid,
                    'room_close_cid'=>$cid,
                    'note' => '获得被举报人的房间押金'.$per_money,
                    'type' => '',
                    'value' => +$per_money,
                    'order_number' => SYS_TIME.$suijishu,
                    'status' => 0,
                    'module' => '',
                    'inputtime' => SYS_TIME
                ]);

            }
            
        }
        
    }