<?php
namespace App\Lib\Biz\Game\Parse;
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/11/30
 * Time: 16:42
 */
class SfsixlotteryGameParse extends BaseParse {
    protected $game='sfsixlottery';
    protected $name='极速六合彩';

    //投注内容 
    function packbet($data) {
        $game = $this->game;
        $this->name = trans('common.' . $game);
        //获取开奖号码
        if (!isset($data['prizes_code'])) {
            $data['prizes_code'] = $data['codes'];
        }
        $data['name'] = $this->name;
        $data['game'] = $this->game;

        //投注号码解析 
        $data['bet_'] = '';
        if (isset($data['codes']) && !empty($data['codes'])) {
            $codes = json_decode($data['codes'], 1);
            if (is_array($codes) && count($codes) > 0) {
                foreach ($codes as $k => $v) {
                    if (is_array($v) && count($v) > 0) {
                        $data['bet_'] .= '<b>' . trans($this->game . '.' . $k) . '</b>:'; //玩法
                        $flag = 1;
                        foreach ($v as $ka => $va) {
                            if($k=='join_born'){
                                $ys = explode('_', $ka);
                                $ka = $ys[0];
                                $typeyn = (isset($ys[1]) && $ys[1]=='Y')?'中':'不中';
                                if($flag==1){
                                    $data['bet_'] =  $data['bet_'] . $typeyn . '(';
                                }
                            }
                            $flag ++;
                            if (is_numeric($ka) || preg_match("/^\d+_\d+$/", $ka)) {
                                if($k=='sum_born'&&$ka==2){
                                    $ka='234';
                                }
                                $data['bet_'] .= $ka . ' ';
                            } else {
                                $data['bet_'] .= trans($this->game . '.' . $ka) . ' ';
                            }
                        }
                        if($k=='join_born'){
                            $data['bet_'] =  $data['bet_'] . ')';
                        }
                        $data['bet_'] .= '<br/>';
                    }
                }
            }
        }

        //中奖撤单未中奖状态的处理
        $data['ceshi'] = $data['game_status'];
        if (isset($data['game_status'])) {
            if ($data['status'] == 4) {
                $data['game_status'] = 4;
            }
            $lang = trans('status.money_buy.game_status');
            $data['game_status'] = $lang[$data['game_status']];
        }

        unset($data['status']);
        return $data;
    }

    /**
     * 单注可赢金额计算
     */
    function winMomey($data){
        //print_r($data);
        $winMoney=0;
        $betmoney = isset($data['money'])?$data['money']:0;
        $prizestatus='';
        $get_money = 0;
        /*if(!empty($data['prize'])){
            $prizetype=json_decode($data['prize'],1);
            foreach ($prizetype as $key => $value) {
                if($key=='seven_colorwave'&&$value[0]=='draw'){
                    $prizestatus='和';
                }
            }
        }*/
        if(isset($data['codes'])){
            $data=json_decode($data['codes'],1);
            $grouptype = $this->groupType();
            foreach ($data as $k=>$v){
                if(in_array($k, $grouptype)){
                    foreach ($v as $key=>$value){
                       if(isset($value['settings']['multiple']['max'])){
                           $winMoney=$betmoney*$value['settings']['multiple']['max'];
                       }else{
                           $winMoney=$betmoney*$value['settings']['multiple'];
                       }
                       break;
                   }
                   break;
                }
                if($k=='general_pass'){
                    $settings = 1;
                    foreach ($v as $key=>$value){
                       if(isset($value['settings']['multiple']['max'])){
                           $settings*=$value['settings']['multiple']['max'];
                       }else{
                           $settings*=$value['settings']['multiple'];
                       }
                   }
                   $winMoney = $betmoney*$settings;
                   break;
                }else if(is_array($v)&&count($v)>0){
                   foreach ($v as $key=>$value){
                       if(isset($value['settings']['multiple']['max'])){
                           $winMoney+=$value[0]*$value['settings']['multiple']['max'];
                       }else{
                           $winMoney+=$value[0]*$value['settings']['multiple'];
                       }
                       if(isset($value['settings']['back'])){
                           $get_money+=$value[0]*$value['settings']['back'];
                       }
                   }
                }
            }
        }

       return array('winmoney'=>$winMoney,'prizestatus'=>$prizestatus,'return_money'=>$get_money);
    }


    /**
     * 开奖号吗解析
     */
    function prizeParse($data,$game='') {
        //print_r($data);
        $game = $this->game;
        $this->name = trans('common.' . $game);
        $prize = json_decode($data['prizes'], 1);
        if (is_array($prize) && count($prize) > 0) {
            $prize = current($prize);
            if (is_array($prize) && count($prize) > 0) {
                foreach ($prize as $k => $v) {
                    if (is_array($v) && count($v) > 0) {
                        $data[$k] = '';
                        foreach ($v as $key => $value) {
                            if($k=='general_color'||$k=='special_colorwave'){
                                $data[$k] .= $key . ' ';
                            }else{
                                $data[$k] .= trans($this->game . '.' . $k . '-' . $key) . '<br/>';
                            }
                        }
                    }
                }
            }
        }

        unset($data['prizes']);

        //解析开奖补充号码
        if (isset($data['extra']) && !empty($data['extra'])) {
            $extra = json_decode($data['extra'], 1);
            if (is_array($extra) && count($extra) > 0) {
                foreach ($extra as $kq => $vq) {
                    if (is_numeric($vq)) {
                        //处理数字开奖号码
                        if ($vq < 0) {
                            //处理未开出奖
                            $data[$kq] = '';
                        } else {
                            $data[$kq] = $vq;
                        }
                    } else {
                        //非数字
                        if (is_array($vq) && count($vq)) {
                            $data[$kq] = '';
                            foreach ($vq as $ka => $va) {
                                if (is_array($va) && count($va)) {
                                    foreach ($va as $kw => $vw) {
                                        $data[$kq] .= trans($this->game . '.' . $kq . '-' . $vw);
                                    }
                                } else {
                                    $data[$kq] .= trans($this->game . '.' . $va) . ' ';
                                }
                            }
                        } else {
                            $data[$kq] = trans($this->game . '.' . $vq);
                        }
                    }
                }
                if (isset($data['one'])) {
                    $data['prizes_code'] = $data['one'] . '+' . $data['two'] . '+' . $data['three'] . '=' . $data['code'];
                } else if (isset($data['prizes_code'])) {
                    $data['prizes_code'] = $data['prizes_code'];
                }
            }
        }
        if (!isset($data['prizes_code'])) {
            $data['prizes_code'] = $data['codes'];
        }
        $data['name'] = $this->name;
        $data['game'] = $this->game;
        //中奖撤单未中奖状态的处理
        if (isset($data['game_status'])) {
            if ($data['status'] == 4) {
                $data['game_status'] = 4;
            }
            $lang = trans('status.money_buy.game_status');
            $data['game_status'] = $lang[$data['game_status']];
        }
        unset($data['status']);
        return $data;
    }

    //赔率
    function getSettings() {
        $game =  'sfsixlottery';
        //权限检测
        $arrys = array(
            'series_twospecial',//二中特
            'series_threetwo-0',
            'series_fiveend-0',
            'series_fourend-0',
            'series_threeend-0',
            'series_twoend-0',

            'series_twoborn-rate',
            'series_twoborn-cattle',
            'series_twoborn-tiger',
            'series_twoborn-rabbit',
            'series_twoborn-dragon',
            'series_twoborn-snake',
            'series_twoborn-horse',
            'series_twoborn-sheep',
            'series_twoborn-monkey',
            'series_twoborn-chick',
            'series_twoborn-dog',
            'series_twoborn-pig',

            'general_born'

        );
        if(!checkRriv('/odds/game/'.$game)){
            return responseToJson(array());
        }
        $db = new \App\Models\GameOdds();
        $data = $db->getOdds($game);
        if($data<0){
            return responseToJson($data);
        }
        $data = json_decode($data['odds'], 1);
        return $data;
        $array = array();
        $i = 0;
        foreach ($arrys as $v){
            $bs[$v]=$data[$v];
        }
        return $bs;
    }

    /**
     *
     */
    function betParse($data, $game = '') {
        $this->game = $game;
        $this->name = trans('common.' . $game);
        //获取开奖号码
        if (isset($data['extra']) && !empty($data['extra'])) {
            $extra = json_decode($data['extra'], 1);
            if (is_array($extra) && count($extra) > 0) {
                if (isset($extra['one'])) {
                    $data['prizes_code'] = $extra['one'] . '+' . $extra['two'] . '+' . $extra['three'] . '=' . $extra['code'];
                } else if (isset($data['prizes_code'])) {
                    $data['prizes_code'] = $data['prizes_code'];
                }
            }
        }
        if (!isset($data['prizes_code'])) {
            $data['prizes_code'] = $data['codes'];
        }
        $data['name'] = $this->name;
        $data['game'] = $this->game;
        //解析投注号码
        if (isset($data['extra']) && !empty($data['extra'])) {
            $codes = json_decode($data['codes'], 1);
            if (is_array($codes) && count($codes) > 0) {
                foreach ($codes as $k => $v) {
                    if (is_array($v) && count($v) > 0) {
                        $data[$k] = '';
                        foreach ($v as $ka => $va) {
                            $data[$k] .= trans($this->game . '.' . $k . '-' . $ka) . ' ';
                        }
                    }
                }
            }
        }
        //中奖撤单未中奖状态的处理
        if (isset($data['game_status'])) {
            if ($data['status'] == 4) {
                $data['game_status'] = 4;
            }
            $lang = trans('status.money_buy.game_status');
            $data['game_status'] = $lang[$data['game_status']];
        }
        unset($data['status']);
        return $data;
    }

    /**
     * 单注号码解析
     * @param $data 号码json
     * @param $game
     * @return array
     */
    function dataChange($data,$orderCode) {
        /*echo '<pre>';
        print_r($data);
        print_r($orderCode);*/

        $year = date('Y',strtotime($orderCode['open_time']));
        $month = date('m',strtotime($orderCode['open_time']));
        $day = date('d',strtotime($orderCode['open_time']));
        $lunar = new \App\Http\Controllers\Admin\LunarHandleController;
        $newdate=$lunar->convertSolarToLunar($year,$month,$day);
        $borrn=$newdate[6];
        $args = array();

        $buy_code = json_decode($data['codes'], 1); //该注购买号码
        $prize_code = json_decode($data['prize'], 1); //该注中奖号码（解析）

        $color_code = json_decode($orderCode['prizes'], 1); //该期开奖号码（解析）
        $prize_num = $orderCode['codes']; //该期开奖号码（未解析）

        //购买号码解析
        $color_codes=$color_code['data']['general_color'];
        $color_coded=$color_code['data']['seven_colorwave'];
        $general_born=$color_code['data']['general_born'];

        //正码1-6
        $asb=array(
            'general_size',
            'general_parity',
            'general_sumsize',
            'general_sumparity',
            'general_endsize',
        );

        //两面1-6
        $assb=array(
            'general_twofacesize',
            'general_twofaceparity',
            'generalsum_twofacesize',
            'generalsum_twofaceparity',
        );

        //合肖、半波、半半波
        $asd =array(
            'join_born',//合肖
            'special_halfwave',//半波
            'special_mixwave',//半半波
        );

        //特码混合
        $iop = array(
            // 特码A_大小、单双、半特（混合）
            'special_size_a',
            'special_parity_a',
            'special_half_a',
            'special_sumsize_a',
            'special_sumparity_a',
            'special_endsize_a',

            // 特码b_大小、单双、半特（混合）
            'special_size_b',
            'special_parity_b',
            'special_half_b',
            'special_sumsize_b',
            'special_sumparity_b',
            'special_endsize_b',

            //两面
            'special_twofaceparity',
            'specialsum_twofaceparity',
            'special_twofacesize',
            'specialsum_twofacesize'
        );

        //正码过关注单详情
        if(array_key_exists('general_pass', $buy_code)){
            return $this->sixGenPass($data);
        }

        $odds=$this->getSettings();//特殊玩法赔率获取
        $dataw=explode(',',$prize_num); //开奖号码转换

        //开奖号码尾数获取
        foreach ($dataw as $k=>$vv){
            $aa[$k]=$vv % 10;
        }
        $bb=array_unique($aa);  

        //分组玩法号码分组对应投注金额及赔率
        $paramt = $this->CodesData($buy_code, 2);
        $paramt = ($paramt<0)?$buy_code:$paramt;
      
        if (is_array($paramt) && count($paramt) > 0) {
            $i = 0;
            $a="";
            foreach ($paramt as $k => $v) {
                if (is_array($v) && count($v) > 0) {
                    foreach ($v as $k1 => $v1) {
                        $name =trans($data['game_name'] . '.' . $k). '-' . trans($data['game_name'] . '.' . $k1);
                        //var_dump($name,$data['game_name']);
                        if(strpos($name,$data['game_name']) !== false){
                            $datas=explode(',',$k1);
                            foreach ($datas as $value){
                                if ($value > 0 || strlen($value) == 1){
                                    $a.=$value.",";
                                }else{
                                    $a.=trans($data['game_name'] . '.' . $value).",";
                                }
                            }
                            $a= rtrim($a, ',');
                            if($k=='sum_born' && $k1==2){
                                $a = '234';
                            }
                            $args[$i] = array(
                                'gameType' => trans($data['game_name'] . '.' . $k),
                                'codes' => trans($data['game_name'] . '.' . $k). '-' . $a,
                                'money' => $v1[0],
                                'maybe' => $v1[0] * $v1['settings']['multiple'],
                                'play' => $k,
                                'p_code' => $k1,
                                'back' => empty($v1['settings']['back']) ? 0 : $v1['settings']['back'],
                            );
                        }else{
                            $args[$i] = array(
                                'gameType' => trans($data['game_name'] . '.' . $k),
                                'codes' => trans($data['game_name'] . '.' . $k). '-' . trans($data['game_name'] . '.' . $k1),
                                'money' => $v1[0],
                                'maybe' => $v1[0] * $v1['settings']['multiple'],
                                'play' => $k,
                                'p_code' => $k1,
                                'back' => empty($v1['settings']['back']) ? 0 : $v1['settings']['back'],
                            );
                        }

                        if (isset($v1['settings']['multiple']['max'])) {
                            $args[$i]['odds'] = $v1['settings']['multiple']['max'];
                        } else {
                            $args[$i]['odds'] = $v1['settings']['multiple'];
                        }
                        if ($data['status'] == 4) {
                            $args[$i]['prize_status'] = '撤单';
                            $args[$i]['get_money']=0;
                        } else if ($data['game_status'] == 0) {
                            $args[$i]['prize_status'] = '待开奖';
                            $args[$i]['back'] = $v1['settings']['back']*$v1[0];
                            $args[$i]['get_money']=0;
                        }elseif(in_array($k,$asd)) {
                            $datas1 = explode(',', $prize_num);
                            if (in_array(49, $datas1)) {
                                $args[$i]['prize_status'] = '和';
                                $args[$i]['back'] = $v1['settings']['back']*$v1[0];
                                $args[$i]['get_money'] = $v1[0];
                                $args[$i]['odds'] = 1;
                            } else {
                                $args[$i]['prize_status'] = '未中奖';
                                $args[$i]['back'] = $v1['settings']['back']*$v1[0];
                                $args[$i]['get_money'] = -$v1[0];
                            }
                        }else{
                            $args[$i]['back'] = $v1['settings']['back']*$v1[0];
                            $args[$i]['prize_status'] = '未中奖';
                            $args[$i]['get_money'] =($v1['settings']['back']*$v1[0])-$v1[0];

                        }
                        $i++;
                        $a="";
                    }
                }
            }
        }
        /*echo '中奖号码';
        print_r($args);
        print_r($prize_code);*/
        $datauu = $dataw;

        if (is_array($prize_code) && count($prize_code)) {
            foreach ($prize_code as $kk => $vv) {
                $name = $kk;    //玩法名称
            }

            foreach ($dataw as $k=>$vv){
                if ($vv > 9){
                    $aa[$k]=$vv % 10;
                }
                $dataw=''.intval($vv).'';
            }


            $bb[$name]=array_unique($aa);
            $cc=array_unique($aa);

            $datass[$name] = $datauu;
            array_pop($datauu);
            $datd[$name] =$datauu;

            //中奖号码
            if (array_key_exists("series_twospecial", $prize_code)) {
                //二中特
                $paramt = $this->CodesDatas($datass, 2, 2, 1);
            } elseif (array_key_exists("series_four", $prize_code)) {
                //四全中
                $paramt = $this->CodesDatas($datd, 4, 4);
            } elseif (array_key_exists("series_three", $prize_code)) {
                //三全中
                $paramt = $this->CodesDatas($datd, 3, 3);
            } elseif (array_key_exists("series_specialmix", $prize_code)) {
                //特串
                $paramt = $this->CodesDatas($datass, 2, 2);
            } elseif (array_key_exists("series_two", $prize_code)) {
                //二全中
                $paramt = $this->CodesDatas($datd, 2, 2);
            } elseif (array_key_exists("series_threetwo", $prize_code)) {
                //三种二
                $paramt = $this->CodesDatas($datass, 3, 2);
            } elseif (array_key_exists("series_fiveborn", $prize_code)) {
                $paramt = $this->CodesDatas($prize_code, 5, 5, '');
            } elseif (array_key_exists("series_fourborn", $prize_code)) {
                $paramt = $this->CodesDatas($prize_code, 4, 4, '');
            } elseif (array_key_exists("series_threeborn", $prize_code)) {
                $paramt = $this->CodesDatas($prize_code, 3, 3, '');
            } elseif (array_key_exists("series_twoborn", $prize_code)) {
                $paramt = $this->CodesDatas($prize_code, 2, 2, '');
            } elseif (array_key_exists("series_fiveend", $prize_code)) {
                //五尾碰
                if (count($cc) >= 5){
                    $paramt = $this->CodesDatas($bb, 5, 5);
                }else{
                    $paramt = $this->CodesDatas($datass, 5, 5);
                }
            } elseif (array_key_exists("series_fourend", $prize_code)) {
                if (count($cc) >= 4){
                    $paramt = $this->CodesDatas($bb, 4, 4);
                }else{
                    $paramt = $this->CodesDatas($datass, 4, 4);
                }
            } elseif (array_key_exists("series_threeend", $prize_code)) {
                if (count($cc) >= 3){
                    $paramt = $this->CodesDatas($bb, 3, 3);
                }else{
                    $paramt = $this->CodesDatas($datass, 3, 3);
                }
            } elseif (array_key_exists("series_twoend", $prize_code)) {
                //二尾碰
                if (count($cc) >= 2){
                    $paramt = $this->CodesDatas($bb, 2, 2);
                }else{
                    $paramt = $this->CodesDatas($datass, 2, 2);
                }
            } elseif (array_key_exists("selfselect_fivelose", $buy_code)) {
                //五不中
                $paramt = $datass;
            } elseif (array_key_exists("selfselect_sevenlose", $buy_code)) {
                //七不中
                $paramt = $datass;
            } elseif (array_key_exists("selfselect_ninelose", $buy_code)) {
                //九不中
                $paramt = $datass;
            } elseif (array_key_exists("selfselect_sixlose", $buy_code)) {
                //六不中
                $paramt = $datass;
            } elseif (array_key_exists("selfselect_tenlose", $buy_code)) {
                //十不中
                $paramt = $datass;
            } elseif (array_key_exists("selfselect_twelvelose", $buy_code)) {
                //十二不中
                $paramt = $datass;
            } elseif (array_key_exists("selfselect_elevenlose", $buy_code)) {
                //十一不中
                $paramt = $datass;
            } elseif (array_key_exists("selfselect_eightlose", $buy_code)) {
                //八不中
                $paramt = $datass;
            } else {
                $paramt = $prize_code;
            }
            //print_r($paramt);

            //自选不中
            $arry = array(
                'selfselect_eightlose',//八不中
                'selfselect_elevenlose',
                'selfselect_twelvelose',
                'selfselect_tenlose',
                'selfselect_sixlose',
                'selfselect_ninelose',
                'selfselect_sevenlose',
                'selfselect_fivelose',//五不中
            );

            //连码
            $arrys = array(
                'series_twospecial',//二中特
                'series_threetwo'
            );

            //连尾
            $asse = array(
                '5'=>'series_fiveend',
                '4'=>'series_fourend',
                '3'=>'series_threeend',
                '2'=>'series_twoend',
            );

            // 连肖
            $assed = array(
                'series_twoborn',
                'series_threeborn',
                'series_fourborn',
                'series_fiveborn',
            );
            /*echo '<br>args:';
            print_r($args);
            echo 'borrn:'.$borrn;*/
            if ($data['status'] != 4) {
                foreach ($paramt as $p_k => $p_v) {
                    //购买号码
                    foreach ($args as $num => $v) {
                        if ($v['play'] == $p_k) {
                            if (is_array($p_v) && count($p_v) > 0) {
                                if (in_array($p_k, $arry)) {
                                    $not_num = 2;
                                    foreach ($p_v as $p_k1 => $p_v2) {
                                        $datas = explode(',', $v['p_code']);
                                        foreach ($datas as $vss) {
                                            if ($vss == $p_v2) {
                                                $not_num = 1;
                                                break;
                                            }
                                        }
                                    }
                                    if ($not_num == 2) {
                                        $args[$num]['prize_status'] = '中奖';
                                        $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];

                                    } else {
                                        $args[$num]['back'] = ($v['back'] * 100) . '%';
                                        $args[$num]['prize_status'] = '未中奖';
                                    }
                                } elseif (in_array($p_k, $arrys)) {
                                    foreach ($p_v as $p_k1 => $p_v2) {
                                        $datass = explode(',', $p_v2);
                                        $datas2 = explode(',', $v['p_code']);

                                        foreach ($datass as $va) {
                                            $datas1[] = intval($va);
                                        }

                                        if (count($datas1) == 2) {
                                            if ($v['p_code'] == $p_v2) {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['get_money'] = ($v['money'] * $odds[$p_k]['settings']['multiple']['min'] + $v['back']) - $v['money'];
                                                $args[$num]['odds'] = $odds[$p_k]['settings']['multiple']['min'];
                                                $args[$num]['maybe'] = $odds[$p_k]['settings']['multiple']['min'] * $v['money'];

                                            }
                                            if ($v['p_code'] == $p_v2 && stripos($v['p_code'], $dataw) !== false) {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['odds'] = $odds[$p_k]['settings']['multiple']['max'];
                                                $args[$num]['get_money'] = ($v['money'] * $odds[$p_k]['settings']['multiple']['max'] + $v['back']) - $v['money'];
                                                $args[$num]['maybe'] = $odds[$p_k]['settings']['multiple']['max'] * $v['money'];
                                            }
                                        }

                                        if (count($datas1) == 3) {
                                            if ($v['p_code'] == $p_v2 && stripos($v['p_code'], $dataw) === false) {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['get_money'] = ($v['money'] * $odds[$p_k]['settings']['multiple']['min'] + $v['back']) - $v['money'];
                                                $args[$num]['odds'] = $odds[$p_k]['settings']['multiple']['min'];
                                                $args[$num]['maybe'] = $v['money'] * $odds[$p_k]['settings']['multiple']['min'];
                                                break;
                                            }

                                            $intersection = array_intersect($datas1, $datas2);
                                            if (count($intersection) == 2 && $v['p_code'] != $p_v2) {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['odds'] = $odds[$p_k]['settings']['multiple']['max'];
                                                $args[$num]['get_money'] = ($v['money'] * $odds[$p_k]['settings']['multiple']['max'] + $v['back']) - $v['money'];
                                                $args[$num]['maybe'] = $v['money'] * $odds[$p_k]['settings']['multiple']['max'];
                                            }
                                        }
                                        unset($datas1);
                                    }
                                } elseif (in_array($p_k, $asd)) {
                                    $datas1 = explode(',', $prize_num);
                                    if (in_array(49, $datas1)) {
                                        $args[$num]['prize_status'] = '和';
                                        $args[$num]['odds'] = 1;
                                        $args[$num]['get_money'] = $v['money'];
                                    } else {
                                        foreach ($p_v as $p_k1 => $p_v2) {
                                            if ($v['p_code'] == $p_v2) {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                                break;
                                            } else {
                                                $args[$num]['prize_status'] = '未中奖';
                                            }
                                        }
                                    }
                                }elseif (in_array($p_k, $iop)) {
                                    $datas1 = explode(',', $prize_num);
                                    $nums= count($datas1);
                                    if ($datas1[$nums-1] == "49") {
                                        $args[$num]['prize_status'] = '和';
                                        $args[$num]['odds'] = 1;
                                        $args[$num]['get_money'] = $v['money'];
                                    } else {
                                        foreach ($p_v as $p_k1 => $p_v2) {

                                            if ($v['p_code'] == $p_v2) {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                            }
                                        }
                                    }
                                } elseif ($p_k == 'series_specialmix') {
                                    foreach ($p_v as $p_k1 => $p_v2) {
                                        if ($v['p_code'] == $p_v2 && stripos($v['p_code'], $dataw) !== false) {
                                            $args[$num]['prize_status'] = '中奖';
                                            $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                            break;
                                        } else {
                                            $args[$num]['prize_status'] = '未中奖';
                                        }
                                    }
                                } elseif ($p_k == 'general_born') {
                                    $num_data = $general_born;
                                    foreach ($num_data as $p_k1 => $p_v2) {
                                        if ($v['p_code'] == $p_k1 && count($p_v2) > 1) {
                                            $args[$num]['prize_status'] = '中奖';
                                            $args[$num]['maybe'] = $v['money'] * $v['odds'] * count($p_v2) - $v['money'] . "   (" . count($p_v2) . "倍)";
                                            $args[$num]['get_money'] = ($v['money'] * $v['odds'] - $v['money']) * count($p_v2) + $v['back'] . "   (" . count($p_v2) . "倍)";
                                            break;
                                        } elseif ($v['p_code'] == $p_k1 && count($p_v2) == 1) {
                                            $args[$num]['prize_status'] = '中奖';
                                            $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                            break;
                                        } else {
                                            $args[$num]['prize_status'] = '未中奖';
                                        }

                                    }
                                }elseif ($p_k == 'seven_colorwave') {
                                    foreach ($p_v as $p_k1 => $p_v2) {
                                        if ($v['p_code'] == $p_v2 && $v['p_code'] == 'draw') {
                                            $args[$num]['prize_status'] = '中奖';
                                            $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                            break;
                                        } else {
                                            $args[$num]['prize_status'] = '和';
                                            $args[$num]['get_money'] = 0;
                                        }
                                        if ($v['p_code'] == $p_v2 ) {
                                            $args[$num]['prize_status'] = '中奖';
                                            $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                            break;
                                        } else {
                                            $args[$num]['prize_status'] = '未中奖';
                                        }
                                    }
                                } elseif (in_array($p_k, $asb)) {
                                    $datas1 = explode(',', $prize_num);
                                    $datrr = explode('_', $v['p_code']);
                                    foreach ($datas1 as $k1 => $v1) {
                                        foreach ($datrr as $k2 => $v2) {
                                            if ((string)$k1 + 1 == $v2 && $v1 == "49") {
                                                $args[$num]['prize_status'] = '和';
                                                $args[$num]['get_money'] = $v['money'];
                                                $args[$num]['odds'] = 1;
                                            } else {
                                                foreach ($p_v as $p_k1 => $p_v2) {
                                                    if ($v['p_code'] == $p_v2) {
                                                        $args[$num]['prize_status'] = '中奖';
                                                        $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } elseif (in_array($p_k, $assb)) {
                                    $datas1 = explode(',', $prize_num);
                                    $datrr = explode('_', $v['p_code']);
                                    foreach ($datas1 as $k1 => $v1) {
                                        foreach ($datrr as $k2 => $v2) {
                                            if ((string)$k1 + 1 == $v2 && $v1 == "49") {
                                                $args[$num]['prize_status'] = '和';
                                                $args[$num]['get_money'] = $v['money'];
                                                $args[$num]['odds'] = 1;
                                            } else {
                                                foreach ($p_v as $p_k1 => $p_v2) {
                                                    if ($v['p_code'] == $p_v2) {
                                                        $args[$num]['prize_status'] = '中奖';
                                                        $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } elseif (in_array($p_k, $asse)) {
                                    foreach ($asse as $kk => $vv) {
                                        if (count($bb) < $kk) {
                                            $args[$num]['prize_status'] = '未中奖';
                                        }
                                    }
                                    foreach ($p_v as $p_k1 => $p_v2) {
                                        if ($v['p_code'] == $p_v2) {
                                            if (stripos($p_v2, '0') !== false) {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['odds'] = $odds[$p_k . '-' . '0']['settings']['multiple']['max'];
                                                $args[$num]['get_money'] = $v['money'] * $odds[$p_k . '-' . '0']['settings']['multiple']['max'] + $v['back'] - $v['money'];
                                                $args[$num]['maybe'] = $v['money'] * $odds[$p_k . '-' . '0']['settings']['multiple']['max'];
                                                break;
                                            } else {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                                break;
                                            }
                                        } else {
                                            $args[$num]['prize_status'] = '未中奖';
                                        }
                                    }
                                } elseif (in_array($p_k, $assed)) {
                                    foreach ($p_v as $p_k1 => $p_v2) {
                                        //echo '<br>'.$v['p_code'].'p-v2:'.$p_v2;
                                        if ($v['p_code'] == $p_v2) {
                                            if (stripos($p_v2, $borrn) !== false) {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['odds'] = $odds[$p_k . '-' . $borrn]['settings']['multiple']['max'];
                                                $args[$num]['get_money'] = $v['money'] * $odds[$p_k . '-' . $borrn]['settings']['multiple']['max'] + $v['back'] - $v['money'];
                                                $args[$num]['maybe'] = $v['money'] * $odds[$p_k . '-' . $borrn]['settings']['multiple']['max'];
                                                break;
                                            } else {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                                break;
                                            }
                                        } else {
                                            $args[$num]['prize_status'] = '未中奖';
                                        }
                                    }
                                } else {
                                    foreach ($p_v as $p_k1 => $p_v2) {
                                        if ($v['p_code'] == $p_v2) {
                                            $args[$num]['prize_status'] = '中奖';
                                            $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                                            break;
                                        } else {
                                            $args[$num]['prize_status'] = '未中奖';
                                        }
                                    }
                                }

                            }
                        }
                    }
                }
            }
        }
        //echo '</pre>';
        return $args;
    }

    //购买号码
    function buyCodes($data, $game) {
    }

    private function groupTypedata($type){
        $codegroup = array(
            'series_twospecial'=>array(2,2,1),//二中特
            'series_four' => array(4,4),//四全中
            'series_three' => array(3,3),//三全中
            'series_specialmix' => array(2,2),//特串
            'series_two' => array(2,2),//二全中
            'series_threetwo' => array(3,2),//三中二
            'series_fiveborn' => array(5,5,''),//五连肖
            'series_fourborn' => array(4,4,''),//四连肖
            'series_threeborn' => array(3,3,''),//三连肖
            'series_twoborn' => array(2,2,''),//二连肖
            'series_fiveend' => array(5,5,''),//五尾碰
            'series_fourend' => array(4,4,''),//四尾碰
            'series_threeend' => array(3,3,''),//三尾碰
            'series_twoend' => array(2,2,''),//二尾碰
            'selfselect_fivelose' => array(5,5),//五不中
            'selfselect_sixlose' => array(6,6),//六不中
            'selfselect_sevenlose' => array(7,7),//七不中
            'selfselect_eightlose' => array(8,8),//八不中
            'selfselect_ninelose' => array(9,9),//九不中
            'selfselect_tenlose' => array(10,10),//十不中
            'selfselect_elevenlose' => array(11,11),//十一不中
            'selfselect_twelvelose' => array(12,12),//十二不中
        );
        if(isset($codegroup[$type])){
            return $codegroup[$type];
        }else{
            return -1;
        }
    }

    function CodesData($data, $num, $is_prize = '', $is_str = '', $game = '')
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $groupinfo = $this->groupTypedata($k);
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $money = $v[$k1][0];
                    if ($k == 'series_twospecial'){
                        $codes[]= str_replace('g_','',$k1);
                    }else{
                        $codes[] = $k1;
                    }
                }
            }
        }
        if($groupinfo<0){
            return $groupinfo;
        }
        $num = $groupinfo[0];

        $datas=array();
        $datad=array();
        sort($codes);

        if(count($codes) >= $num){
            $a = $this->Isniu($codes, $num);
        }else{
            $nums = count($codes);
            $a = $this->Isniu($codes, $nums);
        }

        foreach ($data as $val){
            foreach ($val as $value){
                foreach ($a as $k=>$v){
                    $datas[$v]=$value;

                }
            }
        }
        $datad[$type]=$datas;
        return $datad;
    }

    function CodeData($data)
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $temp = explode('_', $k1);
                    $money = $v[$k1][0];
                    if (!array_key_exists($temp[0] - 1, $codes)) {
                        $codes[$temp[0] - 1] = array();
                        array_push($codes[$temp[0] - 1], intval($temp[1]));
                    } else {
                        array_push($codes[$temp[0] - 1], intval($temp[1]));
                    }
                }
            }
        }
        $tempArr = $this->countNum($codes, $money, $type);
        return $tempArr;

    }

    function CodesDatas($data, $num, $is_prize = '', $is_str = '', $game = '')
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $money = $v[$k1][0];
                    $codes[] = is_numeric($v1)?intval($v1):$v1;
                }
            }
        }
        $datas=array();
        $datad=array();
        sort($codes);
        $a = $this->Isniu($codes, $num);

        foreach ($a as $k=>$v){
            $datas[$k]=$v;
        }

        $datad[$type]=$datas;
        return $datad;

    }
    function getCombinationToString($arr, $m)
    {
        $result = array();
        if ($m == 1) {
            return $arr;
        }
        if ($m == count($arr)) {
            $result[] = implode(',', $arr);
            return $result;
        }
        $temp_firstelement = $arr[0];
        unset($arr[0]);
        $arr = array_values($arr);
        $temp_list1 = $this->getCombinationToString($arr, ($m - 1));
        foreach ($temp_list1 as $s) {
            $s = $temp_firstelement . ',' . $s;
            $result[] = $s;
        }
        unset($temp_list1);
        $temp_list2 = $this->getCombinationToString($arr, $m);
        foreach ($temp_list2 as $s) {
            $result[] = $s;
        }
        unset($temp_list2);
        return $result;
    }

    function Isniu($codes, $num)
    {
        $r = $this->getCombinationToString($codes, $num);
        return $r;
    }


    function CodesDatasd($data, $num, $game_name)
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $money = $v[$k1][0];
                    $codes[] = $k1;

                }
            }
        }
//         dump($codes);
        foreach ($codes as $v) {
            $coded[] = lang($game_name)->get($v);
        }
//        dump($coded);
        if(count($codes) >= $num){
            $a = $this->Isniu($codes, $num);
        }else{
            $nums = count($codes);
            $a = $this->Isniu($codes, $nums);
        }
//        dump($a);
        foreach ($a as $k => $v) {
            $codelists[$k]['codes'] = $v;
            $codelists[$k]['money'] = $money;
            $codelists[$k]['codeDate'] = $type;
        }
//        dump($codelists);
        return $codelists;

    }
    //六合彩正码过关解析
    function sixGenPass($data){
        $buy_code = json_decode($data['codes'], 1); //该注购买号码
        $prize_code = json_decode($data['prize'], 1); //改注中奖号码
        $game=$data['game_name'];
        if (is_array($buy_code) && count($buy_code) > 0) {
                $return_data=array();
                //投注数组
            foreach ($buy_code as $k=>$v){
                $return_data['gameType']=trans($game. '.' . $k);//玩法
                    if (is_array($v) && count($v) > 0) {
                        $codes_content='';//号码
                        $money=0;//投注金额
                        $maybe=0;//可赢金额
                        $odds=1;//倍率
                        foreach ($v as $ka => $va) {
                            $codes_content.=trans($game . '.' . $ka).' ';//号码
                            $money+=$va[0];
                            $maybe += $va[0] * $va['settings']['multiple'];
                            $back = empty($va['settings']['back']) ? 0 : $va['settings']['back'];
                            $return_data['play'] = $k;
                            $return_data['p_code'] = $ka;
                            if (isset($va['settings']['multiple']['max'])) {
                                $odds *= $va['settings']['multiple']['max'];
                            } else {
                                $odds *= $va['settings']['multiple'];
                            }
                        }
                        //中奖状态
                        if ($data['status'] == 4) {
                            $return_data['prize_status'] = '撤单';
                        } else if ($data['game_status'] == 0) {
                            $return_data['prize_status'] = '待开奖';
                        }else if ($data['game_status'] == 1){
                            $return_data['prize_status']='中奖';
                            $odds=round($data['prize_money']/$data['money'],2);
                        } else if ($data['game_status'] == 2){
                            $return_data['prize_status']='未中奖';
                        }
                        $maybe=$odds*$data['money'];
                        $return_data['codes']=$codes_content;
                        $return_data['money']=round($data['money'],2);
                        $return_data['maybe']=round($maybe,2);
                        $return_data['odds']=round($odds,2);
                        $return_data['get_money']=round($data['get_money'],2);
                    }
                $res_data[]=$return_data;
                }
        }
        return $res_data;
    }

    //六合彩组合类型
    private function groupType(){
        return array('series_threetwo','series_three','series_two','series_four','series_twospecial','series_specialmix','selfselect_fivelose','selfselect_sixlose','selfselect_sevenlose','selfselect_eightlose','selfselect_ninelose','selfselect_tenlose','selfselect_elevenlose','selfselect_twelvelose','join_born','series_twoborn','series_threeborn','series_fourborn','series_fiveborn','series_twoend','series_threeend','series_fourend','series_fiveend','join_born');
    }
}