<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/25
 * Time: 14:10
 */

namespace App\Lib\Settlement\Adapter;

use Illuminate\Support\Facades\DB;


class ZqRule
{
    use RulePlus;

    /**
     * 全场|主队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function concede_home($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $home = intval($resultModel->home_score);
        $guest = intval($resultModel->guest_score);
        $word = $home . '-' . $guest . '(全场)';
        $ret = $this->zq_letball($home - $guest, $model->condition, $word);
        return $ret;
    }

    /**
     * 全场|客队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function concede_guest($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $home = intval($resultModel->home_score);
        $guest = intval($resultModel->guest_score);
        $word = $home . '-' . $guest . '(全场)';
        $ret = $this->zq_letball($guest - $home, $model->condition, $word);
        return $ret;
    }


    /**
     * 上半场|主队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function half_concede_home($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $home = intval($resultModel->u_home_score);
        $guest = intval($resultModel->u_guest_score);
        $word = $home . '-' . $guest . '(上半场)';
        $ret = $this->zq_letball($home - $guest, $model->condition, $word);
        return $ret;
    }

    /**
     * 上半场|客队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function half_concede_guest($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $home = intval($resultModel->u_home_score);
        $guest = intval($resultModel->u_guest_score);
        $word = $home . '-' . $guest . '(上半场)';
        $ret = $this->zq_letball($guest - $home, $model->condition, $word);
        return $ret;

    }

    /**
     * 进球|全场|大
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultMgoal_size_smallodel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function goal_size_home($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $home = intval($resultModel->u_home_score);
        $guest = intval($resultModel->u_guest_score);
        $total = $home + $guest;
        $word = $home . '-' . $guest . '(全场)';
        $ret = $this->zq_inball_bigsmall($total, $model->condition, 2, $word);
        return $ret;
    }

    /**
     * 进球|全场|小
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function goal_size_guest($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $home = intval($resultModel->u_home_score);
        $guest = intval($resultModel->u_guest_score);
        $total = $home + $guest;
        $word = $home . '-' . $guest . '(全场)';
        $ret = $this->zq_inball_bigsmall($total, $model->condition, 1, $word);
        return $ret;
    }


    //全场|进球|大
    public function goal_size_big($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $allscore = intval($resultModel->home_score) + intval($resultModel->guest_score);
        $word = $allscore . "(全场)";
        $returnDatas = $this->zq_inball_bigsmall($allscore, $model->condition, 2, $word);
        return $returnDatas;

    }

    //全场|进球|小
    public function goal_size_small($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $allscore = intval($resultModel->home_score) + intval($resultModel->guest_score);
        $word = $allscore . "(全场)";
        $returnDatas = $this->zq_inball_bigsmall($allscore, $model->condition, 1, $word);
        return $returnDatas;
    }

    /**
     * 进球|上半场|大
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function half_goal_size_big($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $score = intval($resultModel->u_home_score) + intval($resultModel->u_guest_score);
        return $this->zq_inball_bigsmall($score, $model->condition, 2, $score . '(上半场)');
    }

    /**
     * 进球|上半场|小
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function half_goal_size_small($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $score = intval($resultModel->u_home_score) + intval($resultModel->u_guest_score);
        return $this->zq_inball_bigsmall($score, $model->condition, 1, $score . '(上半场)');
    }


    /**
     * 全场|主队|独赢
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输
     */
    public function capot_home($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $home = intval($resultModel->home_score);
        $guest = intval($resultModel->guest_score);
        $word = $home . '-' . $guest . '(全场)';
        $ret = $this->zq_duyingv2(1, 4, $resultModel, $word);
        return $ret;
    }

    /**
     * 全场|客队|独赢
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输
     */
    public function capot_guest($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $home = intval($resultModel->home_score);
        $guest = intval($resultModel->guest_score);
        $word = $home . '-' . $guest . '(全场)';
        $ret = $this->zq_duyingv2(2, 4, $resultModel, $word);
        return $ret;
    }

    /**
     * 全场|主客平|独赢
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输
     */
    public function capot_dogfall($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $home = intval($resultModel->home_score);
        $guest = intval($resultModel->guest_score);
        $word = $home . '-' . $guest . '(全场)';
        if ($home == $guest) {
            $return['result'] = 1;
        } else {
            $return['result'] = -1;
        }
        $return['matchResult'] = $word;
        return $return;
    }

    /**
     * 上半场|主队|独赢
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输
     */
    public function half_capot_home($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $word = $resultModel->u_home_score . '-' . $resultModel->u_guest_score . '(上半场)';
        return $this->zq_duyingv2(1, 1, $resultModel, $word);

    }

    /**
     * 上半场|客队|独赢
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输
     */
    public function half_capot_guest($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $word = $resultModel->u_home_score . '-' . $resultModel->u_guest_score . '(上半场)';
        return $this->zq_duyingv2(2, 1, $resultModel, $word);

    }

    /**
     * 上半场|主客平|独赢
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输
     */
    public function half_capot_dogfall($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $word = $resultModel->u_home_score . '-' . $resultModel->u_guest_score . '(上半场)';
        if ($resultModel->u_home_score == $resultModel->u_guest_score) {
            $result = 1;
        } else {
            $result = -1;
        }
        return ['result' => $result, 'matchResult' => $word];
    }



    //  first_last_ball最先/最后进球 开始-----------------------
    //主队|最先进球
    public function first_ball_home($model, $resultModel, $resultRecords)
    {
        $resultModel = $resultModel['0'];
        $word = ($resultModel->first_score != '') ? (($resultModel->first_score == $model->home_team) ? '1:0' : '0:1') : '0:0';
        $word .= '(主客)';

        if (trim($resultModel->first_score) == trim($resultModel->home_team)) {
            return ['result' => 1, 'matchResult' => $word];
        } else {
            return ['result' => -1, 'matchResult' => $word];
        }

    }

    //客队|最先进球
    public function first_ball_guest($model, $resultModel, $resultRecords)
    {
        $resultModel = $resultModel['0'];
        $word = ($resultModel->first_score != '') ? (($resultModel->first_score == $model->guest_team) ? '0:1' : '1:0') : '0:0';
        $word .= '(主客)';

        if (trim($resultModel->first_score) == trim($resultModel->guest_team)) {
            return ['result' => 1, 'matchResult' => $word];
        } else {
            return ['result' => -1, 'matchResult' => $word];
        }

    }

    //主队|最后进球
    public function last_ball_home($model, $resultModel, $resultRecords)
    {
        $resultModel = $resultModel['0'];
        $word = ($resultModel->last_score != '') ? (($resultModel->last_score == $model->home_team) ? '1:0' : '0:1') : '0:0';
        $word .= '(主客)';

        if (trim($resultModel->last_score) == trim($resultModel->home_team)) {
            return ['result' => 1, 'matchResult' => $word];
        } else {
            return ['result' => -1, 'matchResult' => $word];
        }


    }

    //客队|最后进球
    public function last_ball_guest($model, $resultModel, $resultRecords)
    {
        $resultModel = $resultModel['0'];
        $word = ($resultModel->last_score != '') ? (($resultModel->last_score == $model->guest_team) ? '0:1' : '1:0') : '0:0';
        $word .= '(主客)';

        if (trim($resultModel->last_score) == trim($resultModel->guest_team)) {
            return ['result' => 1, 'matchResult' => $word];
        } else {
            return ['result' => -1, 'matchResult' => $word];
        }

    }

    //没有进球
    public function not_ball($model, $resultModel, $resultRecords)
    {
        $resultModel = $resultModel['0'];
        $home = intval($resultModel->home_score);
        $guest = intval($resultModel->guest_score);
        $all_score = $home + $guest;
        $word = ($home > 0 ? 1 : 0) . '-' . ($guest > 0 ? 1 : 0) . '(主客)';

        if ($all_score <= 0) {
            return ['result' => 1, 'matchResult' => $word];
        } else {
            return ['result' => -1, 'matchResult' => $word];
        }

    }
    //////////  first_last_ball最先/最后进球 结束-----------------------

    /**
     * 足球波胆 规则
     * @param $bet_match  投注赛事数据
     * @param $result_match  最终结果
     * @param $result_match_r  结果记录
     */
    public function bodan($bet_match, $result_match, $result_match_r)
    {
//        $bet_match = DB::table('money_buy_match')->where(['match_id'=> 3219925,'p_code'=>'bodan'])->first();
//        $result_match = DB::table('st_zq_result')->where('match_id', 3224833)->limit(10)->get();
//        select * from  st_zq_result where id=1317823 order by id desc limit 10 ;
//        $result_match_r = DB::table('st_zq_result_record')->where('match_id', 3150765)->get()->toArray();
        //获取父/子级赔率代码

        $p_code = $bet_match->p_code;
        $odds_code = $bet_match->odds_code;

        //获取主客队投注比分
        $bet_score = explode('-', $bet_match->condition);
        $bet_home_score = (int)$bet_score[0];
        $bet_guest_score = isset($bet_score[1]) ? intval($bet_score[1]) : 0;
        if ($p_code != 'bodan') return false;

        //获取赛事最终结果数据
        $result_match = $this->getHalfData($result_match);
        if (strstr($odds_code, "half")) {//上半场

            //获取主客队上半场得分
            $home_score = $result_match->u_home_score;
            $guest_score = $result_match->u_guest_score;
            //返回结果
            $data = [
                'result' => 1,
                'matchResult' => "$home_score-$guest_score(上半场)"
            ];
            if (strstr($bet_match->condition, "其他")) {
                if (($home_score > 3) || ($guest_score > 3)) {
                    return $data;
                }
            }
            //判断结果
            if ($bet_home_score == $home_score and $bet_guest_score == $guest_score) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        } else {//全场
            //获取主客队全场得分
            $home_score = $result_match->home_score;
            $guest_score = $result_match->guest_score;

            //返回结果
            $data = [
                'result' => 1,
                'matchResult' => "$home_score-$guest_score(全场)"
            ];
            if (strstr($bet_match->condition, "其他")) {
                if (($home_score > 4) || ($guest_score > 4)) {
                    return $data;
                }
            }
            //判断结果
            if ($bet_home_score == $home_score and $bet_guest_score == $guest_score) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
    }

    //结果单/双 home_score 主队进球数 guest_score 客队进球数 home_rate 主队让球 guest_rate 客队让球 u_home_score 上半场主队进球 u_guest_score 上半场-客队进球数  two_sides_single 全场单 two_sides_double 全场双 half_two_sides_single 上半场单 half_two_sides_double 上半场双
    public function two_sides($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        $resulttod = intval($resultModel->home_score) + intval($resultModel->guest_score);//全场

        if ($resulttod % 2 == 0) {
            $text = '双';
        } else {
            $text = '单';
        }

        if ($model->odds_code == "two_sides_single" || $model->odds_code == 'two_sides_double') {
            if ($text == $model->condition) {
                $dsresult = 1;
            } else {
                $dsresult = -1;
            }
            return ['result' => $dsresult, 'matchResult' => "$resulttod(全场)"];
        } elseif ($model->odds_code == 'half_two_sides_single' || $model->odds_code == 'half_two_sides_double') {
            $hafs = intval($resultModel->u_home_score) + intval($resultModel->u_guest_score);
            $text = ($hafs % 2 == 0) ? '双' : '单';
            $dsresult = ($text == $model->condition) ? 1 : -1;
            return ['result' => $dsresult, 'matchResult' => "$hafs(半场)"];
        } else {
            $data = [
                'result' => 100,
                'matchResult' => "参数不存在",
            ];
            return $data;
        }

    }

    //结果总数 home_score 主队进球数 guest_score 客队进球数 home_rate 主队让球 guest_rate 客队让球 u_home_score 上半场-主队进球数 u_guest_score 上半场-客队进球数
    public function total_goal($model, $resultModels, $resultRecords)
    {
        $resultModel = $resultModels['0'];
        //全场总进球数
        $resulttod = intval($resultModel->home_score) + intval($resultModel->guest_score);
        //上半场总进球数
        $firsthalftod = intval($resultModel->u_home_score) + intval($resultModel->u_guest_score);
        $results = 0;
        $resultb = 0;
        if ($model->odds_code == "total_goal_four") {
            if (4 <= $resulttod and $resulttod <= 6) {
                $results = 1;
            } else {
                $results = -1;
            }
        }
        if ($model->odds_code == "total_goal_zero") {
            if (0 <= $resulttod and $resulttod <= 1) {
                $results = 1;
            } else {
                $results = -1;
            }
        }
        if ($model->odds_code == "total_goal_two") {
            if (2 <= $resulttod and $resulttod <= 3) {
                $results = 1;
            } else {
                $results = -1;
            }
        }
        if ($model->odds_code == "total_goal_seven") {
            if (7 <= $resulttod) {
                $results = 1;
            } else {
                $results = -1;
            }
        }
        if ($model->odds_code == "half_total_goal_zero") {
            if ($firsthalftod == 0) {
                $resultb = 1;
            } else {
                $resultb = -1;
            }
        }
        if ($model->odds_code == "half_total_goal_one") {
            if ($firsthalftod == 1) {
                $resultb = 1;
            } else {
                $resultb = -1;
            }
        }
        if ($model->odds_code == "half_total_goal_two") {
            if ($firsthalftod == 2) {
                $resultb = 1;
            } else {
                $resultb = -1;
            }
        }
        if ($model->odds_code == "half_total_goal_three") {
            if ($firsthalftod == 3) {
                $resultb = 1;
            } else {
                $resultb = -1;
            }
        }

        if ($results == 1) {
            $data = [
                'result' => 1,
                'matchResult' => "$resulttod(全场)",
            ];
        }
        if ($results == -1) {
            $data = [
                'result' => -1,
                'matchResult' => "$resulttod(全场)",
            ];
        }
        if ($resultb == 1) {
            $data = [
                'result' => 1,
                'matchResult' => "$firsthalftod(半场)",
            ];
        }
        if ($resultb == -1) {
            $data = [
                'result' => -1,
                'matchResult' => "$firsthalftod(半场)",
            ];
        }
        return $data;
    }

    //球队进球数:大/小
    //condition   0.5    或   0.5/1  这种
    public function tema_ball($model, $resultModels, $result_match_r = [])
    {
        $resultModel = $resultModels['0'];

        $odds_code = trim($model->odds_code);
        $score_home = intval($resultModel->home_score);
        $score_guest = intval($resultModel->guest_score);
        $score_home_uhalf = intval($resultModel->u_home_score);
        $score_guest_uhalf = intval($resultModel->u_guest_score);

        switch ($odds_code) {
            case 'home_tema_ball_big':
                $returnDatas['matchResult'] = $score_home . '(全场)';
                $returnDatas = $this->zq_inball_bigsmall($score_home, $model->condition, 2, $returnDatas['matchResult']);
                break;
            case 'home_tema_ball_small':
                $returnDatas['matchResult'] = $score_home . '(全场)';
                $returnDatas = $this->zq_inball_bigsmall($score_home, $model->condition, 1, $returnDatas['matchResult']);
                break;
            case 'guest_tema_ball_big':
                $returnDatas['matchResult'] = $score_guest . '(全场)';
                $returnDatas = $this->zq_inball_bigsmall($score_guest, $model->condition, 2, $returnDatas['matchResult']);
                break;
            case 'guest_tema_ball_small':
                $returnDatas['matchResult'] = $score_guest . '(全场)';
                $returnDatas = $this->zq_inball_bigsmall($score_guest, $model->condition, 1, $returnDatas['matchResult']);
                break;
            case 'half_home_tema_ball_big':
                $returnDatas['matchResult'] = $score_home_uhalf . '(上全场)';
                $returnDatas = $this->zq_inball_bigsmall($score_home_uhalf, $model->condition, 2, $returnDatas['matchResult']);
                break;
            case 'half_home_tema_ball_small':
                $returnDatas['matchResult'] = $score_home_uhalf . '(上全场)';
                $returnDatas = $this->zq_inball_bigsmall($score_home_uhalf, $model->condition, 1, $returnDatas['matchResult']);
                break;
            case 'half_guest_tema_ball_big':
                $returnDatas['matchResult'] = $score_guest_uhalf . '(上半场)';
                $returnDatas = $this->zq_inball_bigsmall($score_guest_uhalf, $model->condition, 2, $returnDatas['matchResult']);
                break;
            case 'half_guest_tema_ball_small':
                $returnDatas['matchResult'] = $score_guest_uhalf . '(上半场)';
                $returnDatas = $this->zq_inball_bigsmall($score_guest_uhalf, $model->condition, 1, $returnDatas['matchResult']);
                break;
        }
        return $returnDatas;
    }


    /**
     * 半场/全场 投注规则
     */
    public function half_full($bet_match, $result_match, $result_match_r)
    {
//        $bet_match = DB::table('money_buy_match')->where('match_id', 3210851)->first();
//        $result_match = DB::table('st_zq_result')->where('match_id', 3210851)->first();
//        $result_match_r = DB::table('st_zq_result_record')->where('match_id', 3210851)->get()->toArray();
        if (empty($bet_match) || empty($result_match)) return false;

        //获取父/子级赔率代码
        $p_code = $bet_match->p_code;
        $odds_code = $bet_match->odds_code;

        //获取最终赛事数据
        $result_match = $this->getHalfData($result_match);
        //获取主客队上半场得分
        $half_home_score = $result_match->u_home_score;
        $half_guest_score = $result_match->u_guest_score;

        //获取主客队全场得分
        $full_home_score = $result_match->home_score;
        $full_guest_score = $result_match->guest_score;
        //半场/全场盘口
        if ($p_code != 'half_full') return false;

        //返回结果
        $data = [
            'result' => 1,
            'matchResult' => "$half_home_score-$half_guest_score(上半场);$full_home_score-$full_guest_score(全场)"
        ];
        switch ($odds_code) {
            case 'half_full_home_home':// 主-主
                if ($half_home_score > $half_guest_score and $full_home_score > $full_guest_score) return $data;
                break;
            case 'half_full_home_dogfall':// 主-和
                if ($half_home_score > $half_guest_score and $full_home_score == $full_guest_score) return $data;
                break;
            case 'half_full_home_guest':// 主-客
                if ($half_home_score > $half_guest_score and $full_home_score < $full_guest_score) return $data;
                break;
            case 'half_full_dogfall_home':// 和-主
                if ($half_home_score == $half_guest_score and $full_home_score > $full_guest_score) return $data;
                break;
            case 'half_full_dogfall_dogfall':// 和-和
                if ($half_home_score == $half_guest_score and $full_home_score == $full_guest_score) return $data;
                break;
            case 'half_full_dogfall_guest':// 和-客
                if ($half_home_score == $half_guest_score and $full_home_score < $full_guest_score) return $data;
                break;
            case 'half_full_guest_home':// 客-主
                if ($half_home_score < $half_guest_score and $full_home_score > $full_guest_score) return $data;
                break;
            case 'half_full_guest_dogfall':// 客-和
                if ($half_home_score < $half_guest_score and $full_home_score == $full_guest_score) return $data;
                break;
            case 'half_full_guest_guest':// 客-客
                if ($half_home_score < $half_guest_score and $full_home_score < $full_guest_score) return $data;
                break;
            default:
                return false;
        }

        $data['result'] = -1;
        return $data;
    }

    /**
     * @param $result_match_r 赛事结果记录
     * @return mixed 返回最新一条上半场结果数据
     */
    public function getHalfData($result_match_r = [])
    {
        return $result_match_r['0'];

        if (empty($result_match_r)) return false;
        if (is_array($result_match_r)) {
            foreach ($result_match_r as $k => $v) {
                return $v;
            }
        }
    }

    /**bo
     * 冠军盘口投注
     * $bet_match 投注赛事数据
     * $result_match 联赛结果 数据 根据玩法代码查询一条
     * $result_match_r 无用参数
     */
    public function gj($bet_match, $result_match, $result_match_r)
    {

//        $bet_match = DB::table('money_buy_match')->where('match_id', 127317)->first();
//        $bet_match->odds_code = '巴西小组赛积分成绩';

//        $result_match = DB::table('st_zq_league_result')->where(['lg_id'=>27317,'game_name'=>$bet_match->odds_code])->first();

        //获取 赛事最终数据
        $result_match = $this->getHalfData($result_match);
        if (empty($bet_match) || empty($result_match)) return false;
        if ($bet_match->p_code != 'gj') return false;//冠军玩法

        if ($bet_match->odds_code == $result_match->game_name) {
            $condition = $bet_match->condition;

            //进球数判断
            if (strpos($bet_match->odds_code, '进球数') !== false) {
                //返回结果
                $data = [
                    'result' => 1,
                    'matchResult' => "$result_match->result(球队进球数)"
                ];
                //获取数值
                $bet = $this->findNum($condition);
                //以上/以下判断
                if (strpos($condition, '上') !== false) {
                    if ($bet < $result_match->result) {
                        return $data;
                    }
                    $data['result'] = -1;
                    return $data;
                }
                if (strpos($condition, '下') !== false) {
                    if ($bet > $result_match->result) {
                        return $data;
                    }
                    $data['result'] = -1;
                    return $data;
                }
                //大/小判断
                if (strpos($condition, '大') !== false) {
                    if ($bet < $result_match->result) {
                        return $data;
                    }
                    $data['result'] = -1;
                    return $data;
                }
                if (strpos($condition, '小') !== false) {
                    if ($bet > $result_match->result) {
                        return $data;
                    }
                    $data['result'] = -1;
                    return $data;
                }
            }
            //积分成绩判断
            if (strpos($bet_match->odds_code, '积分') !== false) {
                //返回结果
                $data = [
                    'result' => 1,
                    'matchResult' => "$result_match->result(球队积分)"
                ];
                $condition = $bet_match->condition;
                //获取数值
                $bet = $this->findNum($condition);
                if ($bet == $result_match->result) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }

            //如果条件中没有数字，则获取球队/球员结果
            if ((preg_match('/\d+/', $condition)) == 0) {
                //返回结果
                $data = [
                    'result' => 1,
                    'matchResult' => "$result_match->result(晋级球队)"
                ];
                $result = $this->teamJudge($condition, $result_match->result);

                if ($result) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            };

            return false;
        }
        return false;
    }

    /**
     * 冠军盘口 球队/球员结果判断
     */
    public function teamJudge($condition, $result)
    {
        //返回结果数组中是否包含该球队
        $result = in_array($condition, json_decode($result, true));
        return $result;
    }

    /**
     * @param string $str
     * @return string
     * 处理字符串中的数字
     */
    public function findNum($str = '')
    {
        $str = trim($str);
        if (empty($str)) {
            return '';
        }
        $result = '';
        for ($i = 0; $i < strlen($str); $i++) {
            if (is_numeric($str[$i]) || $str[$i] == '.') {
                $result .= $str[$i];
            }
        }
        //如果有小数点，返回浮点数
        if (strpos($result, '.')) return floatval($result);
        //返回整数
        return (int)$result;
    }


    /**
     * 角球相关--------->开始
     */
    public function corner_ball($model, $resultModels, $result_match_r)
    {
        $odds_code = $model->odds_code;
        $isHalf = strpos(strtolower($odds_code), 'half');
        if ($isHalf) {
            return $this->corner_ball_half($model, $resultModels, $result_match_r);
        } else {
            return $this->corner_ball_all($model, $resultModels, $result_match_r);
        }
    }

    public function corner_ball_all($model, $resultModels, $result_match_r)
    {

        $resultModel = $resultModels['0'];
        if ($resultModel->corner_ball == '') {
            $game_ret = json_decode(json_encode(['home' => 0, 'guest' => 0, 'home_half' => 0, 'guest_half' => 0]));
        } else {
            $game_ret = json_decode($resultModel->corner_ball);
        }
        $word = $game_ret->home . '-' . $game_ret->guest . "(全场)";
        $returnDatas = ['result' => -1, 'matchResult' => $word];

        $odds_code = $model->odds_code;
        switch ($odds_code) {
            case "corner_concede_home":
                $returnDatas = $this->zq_letball($game_ret->home - $game_ret->guest, $model->condition, $word);
                break;
            case "corner_concede_guest":
                $returnDatas = $this->zq_letball($game_ret->guest - $game_ret->home, $model->condition, $word);
                break;
            case "corner_goal_size_home":
                $returnDatas = $this->zq_inball_bigsmall($game_ret->home - $game_ret->guest, $model->condition, 2, $word);
                break;
            case "corner_goal_size_guest":
                $returnDatas = $this->zq_inball_bigsmall($game_ret->guest - $game_ret->home, $model->condition, 1, $word);
                break;
            case "corner_capot_home":
                $returnDatas = $this->zq_duyingv2(1, 4, $resultModel, $word);
                break;
            case "corner_capot_guest":
                $returnDatas = $this->zq_duyingv2(2, 4, $resultModel, $word);
                break;
            case "corner_capot_dogfall":
                $returnDatas['result'] = ($game_ret->home == $game_ret->guest) ? 1 : -1;
                break;
            case "corner_two_sides_single":
                $returnDatas = $this->zq_doublesing($game_ret->home + $game_ret->guest, $model->condition, $word);
                break;
            case "corner_two_sides_double":
                $returnDatas = $this->zq_doublesing($game_ret->home + $game_ret->guest, $model->condition, $word);
                break;
            default:
                $returnDatas = ['result' => 2, 'matchResult' => '(玩法无规则异常)-' . $odds_code];
        }
        return $returnDatas;
    }

    public function corner_ball_half($model, $resultModels, $result_match_r)
    {

        $resultModel = $resultModels['0'];
        if ($resultModel->corner_ball == '') {
            $game_ret = json_decode(json_encode(['home' => 0, 'guest' => 0, 'home_half' => 0, 'guest_half' => 0]));
        } else {
            $game_ret = json_decode($resultModel->corner_ball);
        }
        $word = $game_ret->home_half . '-' . $game_ret->guest_half . "(上半场)";
        $returnDatas = ['result' => -1, 'matchResult' => $word];

        $odds_code = $model->odds_code;
        switch ($odds_code) {
            case "corner_half_concede_home":
                $returnDatas = $this->zq_letball($game_ret->home_half - $game_ret->guest_half, $model->condition, $word);
                break;
            case "corner_half_concede_guest":
                $returnDatas = $this->zq_letball($game_ret->guest_half - $game_ret->home_half, $model->condition, $word);
                break;
            case "corner_half_goal_size_home":
                $returnDatas = $this->zq_inball_bigsmall($game_ret->home_half - $game_ret->guest_half, $model->condition, 2, $word);
                break;
            case "corner_half_goal_size_guest":
                $returnDatas = $this->zq_inball_bigsmall($game_ret->guest_half - $game_ret->home_half, $model->condition, 1, $word);
                break;
            case "corner_half_capot_home":
                $returnDatas = $this->zq_duyingv2(1, 1, $resultModel, $word);
                break;
            case "corner_half_capot_guest":
                $returnDatas = $this->zq_duyingv2(2, 1, $resultModel, $word);
                break;
            case "corner_half_capot_dogfall":
                $returnDatas['result'] = ($game_ret->home_half == $game_ret->guest_half) ? 1 : -1;
                break;
            case "corner_half_two_sides_single":
                $returnDatas = $this->zq_doublesing($game_ret->home_half + $game_ret->guest_half, $model->condition, $word);
                break;
            case "corner_half_two_sides_double":
                $returnDatas = $this->zq_doublesing($game_ret->home_half + $game_ret->guest_half, $model->condition, $word);
                break;
            default:
                $returnDatas = ['result' => 2, 'matchResult' => '(玩法无规则异常)-' . $odds_code];
        }
        return $returnDatas;
    }

    /**
     * 角球相关--------->结束
     */


    /**
     * 发球相关  开始
     */
    public function penalty_card($model, $resultModels, $result_match_r)
    {
        $odde_code = $model->odde_code;
        $isHalf = strpos(strtolower($odde_code), 'half');
        if ($isHalf) {
            return $this->penalty_card_half($model, $resultModels, $result_match_r);
        } else {
            return $this->penalty_card_all($model, $resultModels, $result_match_r);
        }
    }

    public function penalty_card_half($model, $resultModels, $result_match_r)
    {

        $resultModel = $resultModels['0'];
        if ($resultModel->conner_ball == '') {
            $game_ret = json_decode(json_encode(['home' => 0, 'guest' => 0, 'home_half' => 0, 'guest_half' => 0]));
        } else {
            $game_ret = json_decode($resultModel->penalty_card);
        }
        $word = $game_ret->home_half . '-' . $game_ret->guest_half . "(上半场)";
        $returnDatas = ['result' => -1, 'matchResult' => $word];

        $odds_code = $model->odds_code;
        switch ($odds_code) {
            case "penalty_half_concede_home":
                $returnDatas = $this->zq_letball($game_ret->home_half - $game_ret->guest_half, $model->condition, $word);
                break;
            case "penalty_half_concede_guest":
                $returnDatas = $this->zq_letball($game_ret->guest_half - $game_ret->home_half, $model->condition, $word);
                break;
            case "penalty_half_goal_size_home":
                $returnDatas = $this->zq_inball_bigsmall($game_ret->home_half - $game_ret->guest_half, $model->condition, 2, $word);
                break;
            case "penalty_half_goal_size_guest":
                $returnDatas = $this->zq_inball_bigsmall($game_ret->guest_half - $game_ret->home_half, $model->condition, 1, $word);
                break;
            case "penalty_half_capot_home":
                $returnDatas = $this->zq_duyingv2(1, 1, $resultModel, $word);
                break;
            case "penalty_half_capot_guest":
                $returnDatas = $this->zq_duyingv2(2, 1, $resultModel, $word);
                break;
            case "penalty_half_capot_dogfall":
                $returnDatas['result'] = ($game_ret->home_half == $game_ret->guest_half) ? 1 : -1;
                break;
            case "penalty_half_two_sides_single":
                $returnDatas = $this->zq_doublesing($game_ret->home_half + $game_ret->guest_half, $model->condition, $word);
                break;
            case "penalty_half_two_sides_double":
                $returnDatas = $this->zq_doublesing($game_ret->home_half + $game_ret->guest_half, $model->condition, $word);
                break;
            default:
                $returnDatas = ['result' => 2, 'matchResult' => '(玩法无规则异常)-' . $odds_code];
        }
        return $returnDatas;
    }

    public function penalty_card_all($model, $resultModels, $result_match_r)
    {
        $resultModel = $resultModels['0'];
        if ($resultModel->conner_ball == '') {
            $game_ret = json_decode(json_encode(['home' => 0, 'guest' => 0, 'home_half' => 0, 'guest_half' => 0]));
        } else {
            $game_ret = json_decode($resultModel->penalty_card);
        }
        $word = $game_ret->home . '-' . $game_ret->guest . "(全场)";
        $returnDatas = ['result' => -1, 'matchResult' => $word];

        $odds_code = $model->odds_code;
        switch ($odds_code) {
            case "penalty_concede_home":
                $returnDatas = $this->zq_letball($game_ret->home - $game_ret->guest, $model->condition, $word);
                break;
            case "penalty_concede_guest":
                $returnDatas = $this->zq_letball($game_ret->guest - $game_ret->home, $model->condition, $word);
                break;
            case "penalty_goal_size_home":
                $returnDatas = $this->zq_inball_bigsmall($game_ret->home - $game_ret->guest, $model->condition, 2, $word);
                break;
            case "penalty_goal_size_guest":
                $returnDatas = $this->zq_inball_bigsmall($game_ret->guest - $game_ret->home, $model->condition, 1, $word);
                break;
            case "penalty_capot_home":
                $returnDatas = $this->zq_duyingv2(1, 4, $resultModel, $word);
                break;
            case "penalty_capot_guest":
                $returnDatas = $this->zq_duyingv2(2, 4, $resultModel, $word);
                break;
            case "penalty_capot_dogfall":
                $returnDatas['result'] = ($game_ret->home == $game_ret->guest) ? 1 : -1;
                break;
            case "penalty_two_sides_single":
                $returnDatas = $this->zq_doublesing($game_ret->home + $game_ret->guest, $model->condition, $word);
                break;
            case "penalty_two_sides_double":
                $returnDatas = $this->zq_doublesing($game_ret->home + $game_ret->guest, $model->condition, $word);
                break;
            default:
                $returnDatas = ['result' => 2, 'matchResult' => '(玩法无规则异常)-' . $odds_code];
        }
        return $returnDatas;
    }
    /**
     * 发球相关  结束
     */


}