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

namespace App\Lib\Settlement\Adapter;

use Illuminate\Support\Facades\DB;

class LqRule
{

    use RulePlus;

    /**
     * 让球个数公共函数
     * @param mixed $model 注单表数据
     * @param mixed $difference 分差
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function concedeCommon($model, $difference)
    {
        // 让球个数
        $condition = trim($model->condition);
        // 差值
        $resultScore = $difference + $condition;
        if ($resultScore > 0) {
            $result = 1;
        } elseif ($resultScore < 0) {
            $result = -1;
        } else {
            $result = 2;
        }

        return $result;
    }

    /**
     * 大小公共函数
     * @param mixed $model 注单表数据
     * @param mixed $allGoal 总分
     * @param mixed $size 大小 1：大  -1：小
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function sizeCommon($model, $allGoal, $size)
    {
        // 总球条件
        $condition = trim($model->condition);
        // 差值
        if ($size == 1) {
            $resultScore = $allGoal - $condition;
        } else {
            $resultScore = $condition - $allGoal;
        }
        if ($resultScore > 0) {
            $result = 1;
        } elseif ($resultScore < 0) {
            $result = -1;
        } else {
            $result = 2;
        }

        return $result;
    }

    /**
     * 全场|主队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function coh($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['all']['home']);
        // 客队得分
        $guestScore = intval($retdatas['all']['guest']);
        // 分差 - 主 ：客
        $difference = $homeScore - $guestScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(全场)";
        return $data;
    }

    /**
     * 全场|客队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function cog($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['all']['home']);
        // 客队得分
        $guestScore = intval($retdatas['all']['guest']);
        // 分差 - 客 ：主
        $difference = $guestScore - $homeScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(全场)";
        return $data;
    }

    /**
     * 上半场|主队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function coh_h($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);

        // 主队得分
        $homeScore = intval($retdatas['half']['home']);
        // 客队得分
        $guestScore = intval($retdatas['half']['guest']);
        // 分差 - 主 ：客
        $difference = $homeScore - $guestScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(上半场)";
        return $data;
    }

    /**
     * 上半场|客队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function cog_h($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['half']['home']);
        // 客队得分
        $guestScore = intval($retdatas['half']['guest']);
        // 分差 - 客 ：主
        $difference = $guestScore - $homeScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(上半场)";
        return $data;
    }

    /**
     * 第一节|主队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function one_concede_home($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->coh_1($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['1']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['1']->guest_score);
        // 分差 - 主 ：客
        $difference = $homeScore - $guestScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(第一节)";
        return $data;
    }

    /**
     * 第一节|客队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function cog_1($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['1']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['1']->guest_score);
        // 分差 - 客 ：主
        $difference = $guestScore - $homeScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(第一节)";
        return $data;
    }

    /**
     * 第二节|主队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function coh_2($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['2']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['2']->guest_score);
        // 分差 - 主 ：客
        $difference = $homeScore - $guestScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(第二节)";
        return $data;
    }

    /**
     * 第二节|客队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function cog_2($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['2']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['2']->guest_score);
        // 分差 - 客 ：主
        $difference = $guestScore - $homeScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(第二节)";
        return $data;
    }

    /**
     * 第三节|主队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function coh_3($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['3']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['3']->guest_score);
        // 分差 - 主 ：客
        $difference = $homeScore - $guestScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(第三节)";
        return $data;
    }

    /**
     * 第三节|客队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function cog_3($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['3']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['3']->guest_score);
        // 分差 - 客 ：主
        $difference = $guestScore - $homeScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(第三节)";
        return $data;
    }

    /**
     * 第四节|主队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function coh_4($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['4']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['4']->guest_score);
        // 分差 - 主 ：客
        $difference = $homeScore - $guestScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(第四节)";
        return $data;
    }

    /**
     * 第四节|客队|让球
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function cog_4($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['4']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['4']->guest_score);
        // 分差 - 客 ：主
        $difference = $guestScore - $homeScore;

        $data['result'] = $this->concedeCommon($model, $difference);
        $data['matchResult'] = "$homeScore-$guestScore(第四节)";
        return $data;
    }

    /**
     * 全场总分大
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tnb($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);

        // 主队得分
        $homeScore = intval($retdatas['all']['home']);
        // 客队得分
        $guestScore = intval($retdatas['all']['guest']);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, 1);
        $data['matchResult'] = "$homeScore-$guestScore(全场)";
        return $data;
    }

    /**
     * 全场总分小
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tns($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['all']['home']);
        // 客队得分
        $guestScore = intval($retdatas['all']['guest']);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, -1);
        $data['matchResult'] = "$homeScore-$guestScore(全场)";
        return $data;
    }

    /**
     * 上半场总分大
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tnb_h($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['half']['home']);
        // 客队得分
        $guestScore = intval($retdatas['half']['guest']);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, 1);
        $data['matchResult'] = "$homeScore-$guestScore(上半场)";
        return $data;
    }

    /**
     * 上半场总分小
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tns_h($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['half']['home']);
        // 客队得分
        $guestScore = intval($retdatas['half']['guest']);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, -1);
        $data['matchResult'] = "$homeScore-$guestScore(上半场)";
        return $data;
    }

    /**
     * 第一节总分大
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tnb_1($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['1']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['1']->guest_score);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, 1);
        $data['matchResult'] = "$homeScore-$guestScore(第一节)";
        return $data;
    }

    /**
     * 第一节总分小
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tns_1($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['1']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['1']->guest_score);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, -1);
        $data['matchResult'] = "$homeScore-$guestScore(第一节)";
        return $data;
    }

    /**
     * 第二节总分大
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tnb_2($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['2']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['2']->guest_score);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, 1);
        $data['matchResult'] = "$homeScore-$guestScore(第二节)";
        return $data;
    }

    /**
     * 第二节总分小
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tns_2($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['2']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['2']->guest_score);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, -1);
        $data['matchResult'] = "$homeScore-$guestScore(第二节)";
        return $data;
    }

    /**
     * 第三节总分大
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tnb_3($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['3']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['3']->guest_score);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, 1);
        $data['matchResult'] = "$homeScore-$guestScore(第三节)";
        return $data;
    }

    /**
     * 第三节总分小
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tns_3($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['3']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['3']->guest_score);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, -1);
        $data['matchResult'] = "$homeScore-$guestScore(第三节)";
        return $data;
    }

    /**
     * 第四节总分大
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tnb_4($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['4']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['4']->guest_score);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, 1);
        $data['matchResult'] = "$homeScore-$guestScore(第四节)";
        return $data;
    }

    /**
     * 第四节总分小
     * @param mixed $model 注单表数据
     * @param mixed $resultModel 结果表数据
     * @param mixed $resultRecords 结果记录表数据
     * @return string 1：赢  -1：输  2：平  3：赢半平半  4：输半平半
     */
    public function tns_4($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        // 主队得分
        $homeScore = intval($retdatas['list']['4']->home_score);
        // 客队得分
        $guestScore = intval($retdatas['list']['4']->guest_score);
        // 总进球数
        $allGoal = $homeScore + $guestScore;
        $data['result'] = $this->sizeCommon($model, $allGoal, -1);
        $data['matchResult'] = "$homeScore-$guestScore(第四节)";
        return $data;
    }

    /**
     * 篮球 独赢规则
     */
    public function C($bet_match, $result_match, $result_match_r)
    {
        if (empty($bet_match) || empty($result_match)) return false;

        // 篮球 独赢
        $retdatas = $this->lq_scoreDatas($result_match);

        //获取主客队全场得分
        $home_score = $retdatas['all']['home'];
        $guest_score = $retdatas['all']['guest'];
        //返回结果
        $data = [
            'result' => 1,
            'matchResult' => "$home_score-$guest_score(全场得分)"
        ];
        //主队
        if ($bet_match->odds_code == 'ch') {
            if ($home_score > $guest_score) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //客队
        if ($bet_match->odds_code == 'cg') {
            if ($home_score < $guest_score) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //上半场
        if (strstr($bet_match->odds_code, "_h")) {
            //获取上半场最终数据
            $last_stage_data = $retdatas['half'];
            //获取主客队上半场得分
            $home_score = $last_stage_data['home'];
            $guest_score = $last_stage_data['guest'];
            //返回结果
            $data = [
                'result' => 1,
                'matchResult' => "$home_score-$guest_score(上半场得分)"
            ];
            //主队 上半场
            if ($bet_match->odds_code == 'ch_h') {
                if ($home_score > $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //客队 上半场
            if ($bet_match->odds_code == 'cg_h') {
                if ($home_score < $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第一节
        if (strstr($bet_match->odds_code, "_1")) {
            //获取第一节最终数据
            $last_stage_data = $retdatas['list']['1'];
            //获取主客队第一节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //返回结果
            $data = [
                'result' => 1,
                'matchResult' => "$home_score-$guest_score(第一节得分)"
            ];
            //主队 第一节
            if ($bet_match->odds_code == 'ch_1') {
                if ($home_score > $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //客队 第一节
            if ($bet_match->odds_code == 'cg_1') {
                if ($home_score < $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第二节
        if (strstr($bet_match->odds_code, "_2")) {
            //获取第二节最终数据
            $last_stage_data = $retdatas['list']['2'];
            //获取主客队第二节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //返回结果
            $data = [
                'result' => 1,
                'matchResult' => "$home_score-$guest_score(第二节得分)"
            ];
            //主队 第二节
            if ($bet_match->odds_code == 'ch_2') {
                if ($home_score > $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //客队 第二节
            if ($bet_match->odds_code == 'cg_2') {
                if ($home_score < $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第三节
        if (strstr($bet_match->odds_code, "_3")) {
            //获取第三节最终数据
            $last_stage_data = $retdatas['list']['3'];
            //获取主客队第三节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //返回结果
            $data = [
                'result' => 1,
                'matchResult' => "$home_score-$guest_score(第三节得分)"
            ];
            //主队 第三节
            if ($bet_match->odds_code == 'ch_3') {
                if ($home_score > $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //客队 第三节
            if ($bet_match->odds_code == 'cg_3') {
                if ($home_score < $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第四节
        if (strstr($bet_match->odds_code, "_4")) {
            //获取第四节最终数据
            $last_stage_data = $retdatas['list']['4'];
            //获取主客队第四节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //返回结果
            $data = [
                'result' => 1,
                'matchResult' => "$home_score-$guest_score(第四节得分)"
            ];
            //主队 第四节
            if ($bet_match->odds_code == 'ch_4') {
                if ($home_score > $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //客队 第四节
            if ($bet_match->odds_code == 'cg_4') {
                if ($home_score < $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }

        return false;
    }

    /**
     * 篮球 球队得分大小
     */
    public function TB($bet_match, $result_match, $result_match_r)
    {

        if (empty($bet_match) || empty($result_match)) return false;
        // 篮球 球队得分大小

        $retdatas = $this->lq_scoreDatas($result_match);

        //获取主客队全场得分
        $home_score = $retdatas['all']['home'];
        $guest_score = $retdatas['all']['guest'];
        //返回结果
        $data = [
            'result' => 1,
            'matchResult' => ""
        ];
        //界定 分数 条件
        $condition = $bet_match->condition;
        //赔率代码
        $odds_code = $bet_match->odds_code;

        //全场 主队 得分大
        if ($odds_code == 'tbhb') {
            $data['matchResult'] = "$home_score(全场主队得分)";
            if ($home_score > $condition) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //全场 主队 得分小
        if ($odds_code == 'tbhs') {
            $data['matchResult'] = "$home_score(全场主队得分)";
            if ($home_score < $condition) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //全场 客队 得分大
        if ($odds_code == 'tbgb') {
            $data['matchResult'] = "$guest_score(全场客队得分)";
            if ($guest_score > $condition) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //全场 客队 得分小
        if ($odds_code == 'tbgs') {
            $data['matchResult'] = "$guest_score(全场客队得分)";
            if ($guest_score < $condition) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //上半场
        if (strstr($odds_code, "_h")) {
            //获取上半场最终数据
            $last_stage_data = $retdatas['half'];
            //获取主客队上半场得分
            $home_score = $last_stage_data['home'];
            $guest_score = $last_stage_data['guest'];
            //上半场主队得分大
            if ($odds_code == 'tbhb_h') {
                $data['matchResult'] = "$home_score(上半场主队得分)";
                if ($home_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //上半场主队得分小
            if ($odds_code == 'tbhs_h') {
                $data['matchResult'] = "$home_score(上半场主队得分)";
                if ($home_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //上半场客队得分大
            if ($odds_code == 'tbgb_h') {
                $data['matchResult'] = "$guest_score(上半场客队得分)";
                if ($guest_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //上半场客队得分小
            if ($odds_code == 'tbgs_h') {
                $data['matchResult'] = "$guest_score(上半场客队得分)";
                if ($guest_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第一节
        if (strstr($odds_code, "_1")) {
            //获取第一节最终数据
            $last_stage_data = $retdatas['list']['1'];
            //获取主客队第一节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //第一节主队得分大
            if ($odds_code == 'tbhb_1') {
                $data['matchResult'] = "$home_score(第一节主队得分)";
                if ($home_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第一节主队得分小
            if ($odds_code == 'tbhs_1') {
                $data['matchResult'] = "$home_score(第一节主队得分)";
                if ($home_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第一节客队得分大
            if ($odds_code == 'tbgb_1') {
                $data['matchResult'] = "$guest_score(第一节客队得分)";
                if ($guest_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第一节客队得分小
            if ($odds_code == 'tbgs_1') {
                $data['matchResult'] = "$guest_score(第一节客队得分)";
                if ($guest_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第二节
        if (strstr($odds_code, "_2")) {
            //获取第二节最终数据
            $last_stage_data = $retdatas['list']['2'];
            //获取主客队第二节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //第二节主队得分大
            if ($odds_code == 'tbhb_2') {
                $data['matchResult'] = "$home_score(第二节主队得分)";
                if ($home_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第二节主队得分小
            if ($odds_code == 'tbhs_2') {
                $data['matchResult'] = "$home_score(第二节主队得分)";
                if ($home_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第二节客队得分大
            if ($odds_code == 'tbgb_2') {
                $data['matchResult'] = "$guest_score(第二节客队得分)";
                if ($guest_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第二节客队得分小
            if ($odds_code == 'tbgs_2') {
                $data['matchResult'] = "$guest_score(第二节客队得分)";
                if ($guest_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第三节
        if (strstr($odds_code, "_3")) {
            //获取第三节最终数据
            $last_stage_data = $retdatas['list']['3'];
            //获取主客队第三节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //第三节主队得分大
            if ($odds_code == 'tbhb_3') {
                $data['matchResult'] = "$home_score(第三节主队得分)";
                if ($home_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第三节主队得分小
            if ($odds_code == 'tbhs_3') {
                $data['matchResult'] = "$home_score(第三节主队得分)";
                if ($home_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第三节客队得分大
            if ($odds_code == 'tbgb_3') {
                $data['matchResult'] = "$guest_score(第三节客队得分)";
                if ($guest_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第三节客队得分小
            if ($odds_code == 'tbgs_3') {
                $data['matchResult'] = "$guest_score(第三节客队得分)";
                if ($guest_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第四节
        if (strstr($odds_code, "_4")) {
            //获取第四节最终数据
            $last_stage_data = $retdatas['list']['4'];
            //获取主客队第四节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //第四节主队得分大
            if ($odds_code == 'tbhb_4') {
                $data['matchResult'] = "$home_score(第四节主队得分)";
                if ($home_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第四节主队得分小
            if ($odds_code == 'tbhs_4') {
                $data['matchResult'] = "$home_score(第四节主队得分)";
                if ($home_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第四节客队得分大
            if ($odds_code == 'tbgb_4') {
                $data['matchResult'] = "$guest_score(第四节客队得分)";
                if ($guest_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第四节客队得分小
            if ($odds_code == 'tbgs_4') {
                $data['matchResult'] = "$guest_score(第四节客队得分)";
                if ($guest_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        return false;
    }


    //结果单/双 home_score 主队进球数 guest_score 客队进球数 home_rate 主队让球 guest_rate 客队让球
    public function TS($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        $odds_code = $model->odds_code;

        switch ($odds_code) {
            case 'tss':
                $return = $this->two_sides_tooles($retdatas['all']['home'] + $retdatas['all']['guest'], 1);
                break;
            case 'tsd':
                $return = $this->two_sides_tooles($retdatas['all']['home'] + $retdatas['all']['guest'], 2);
                break;
            case 'tss_h':
                $return = $this->two_sides_tooles($retdatas['half']['home'] + $retdatas['half']['guest'], 1);
                break;
            case 'tsd_h':
                $return = $this->two_sides_tooles($retdatas['half']['home'] + $retdatas['half']['guest'], 2);
                break;
            case 'tss_1':
                $return = $this->two_sides_tooles($retdatas['list']['1']->home_score + $retdatas['list']['1']->guest_score, 1);
                break;
            case 'tsd_1':
                $return = $this->two_sides_tooles($retdatas['list']['1']->home_score + $retdatas['list']['1']->guest_score, 2);
                break;
            case 'tss_2':
                $return = $this->two_sides_tooles($retdatas['list']['2']->home_score + $retdatas['list']['2']->guest_score, 1);
                break;
            case 'tsd_2':
                $return = $this->two_sides_tooles($retdatas['list']['2']->home_score + $retdatas['list']['2']->guest_score, 2);
                break;
            case 'tss_3':
                $return = $this->two_sides_tooles($retdatas['list']['3']->home_score + $retdatas['list']['3']->guest_score, 1);
                break;
            case 'tsd_3':
                $return = $this->two_sides_tooles($retdatas['list']['3']->home_score + $retdatas['list']['3']->guest_score, 2);
                break;
            case 'tss_4':
                $return = $this->two_sides_tooles($retdatas['list']['4']->home_score + $retdatas['list']['4']->guest_score, 1);
                break;
            case 'tsd_4':
                $return = $this->two_sides_tooles($retdatas['list']['4']->home_score + $retdatas['list']['4']->guest_score, 2);
                break;
            default:
                $return = ['result' => 2, 'matchResult' => 'noMatch...'];
        }
        return $return;
    }


    //单双判断  $type=1单 2双
    private function two_sides_tooles($score, $type)
    {
        $catds = (($score % 2) == 0) ? 2 : 1;
        if ($type == $catds) {
            $return = ['result' => 1, 'matchResult' => $score . '-last'];
        } else {
            $return = ['result' => -1, 'matchResult' => $score . '-last'];
        }
        return $return;
    }

    //进球最后一位数字
    public function LN($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        $odds_code = $model->odds_code;

        $home_last = intval(substr($retdatas['all']['home'], -1, 1));
        $guest_last = intval(substr($retdatas['all']['guest'], -1, 1));


        switch ($odds_code) {
            case "lnh0":
                $ret = $this->last_number_return($home_last, [0, 5]);
                break;
            case "lnh1":
                $ret = $this->last_number_return($home_last, [1, 6]);
                break;
            case "lnh2":
                $ret = $this->last_number_return($home_last, [2, 7]);
                break;
            case "lnh3":
                $ret = $this->last_number_return($home_last, [3, 8]);
                break;
            case "lnh4":
                $ret = $this->last_number_return($home_last, [4, 9]);
                break;
            case "lng0":
                $ret = $this->last_number_return($guest_last, [0, 5]);
                break;
            case "lng1":
                $ret = $this->last_number_return($guest_last, [1, 6]);
                break;
            case "lng2":
                $ret = $this->last_number_return($guest_last, [2, 7]);
                break;
            case "lng3":
                $ret = $this->last_number_return($guest_last, [3, 8]);
                break;
            case "lng4":
                $ret = $this->last_number_return($guest_last, [4, 9]);
                break;
            default:
                $ret = ['result' => 2, 'matchResult' => 'noError...'];
                break;
        }
        return $ret;
    }


    private function last_number_return($num, $arr = [])
    {
        if (in_array($num, $arr)) {
            $return = ['result' => 1, 'matchResult' => $num . 'last'];
        } else {
            $return = ['result' => -1, 'matchResult' => $num . 'last'];
        }
        return $return;
    }

}