<?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 = intval($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 = intval($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 concede_home($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 concede_guest($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 half_concede_home($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 half_concede_guest($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->lq_scoreDatas($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 one_concede_guest($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 two_concede_home($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 two_concede_guest($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 three_concede_home($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 three_concede_guest($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 four_concede_home($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 four_concede_guest($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 total_size_big($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 total_size_small($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 half_total_sizes_big($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 half_total_sizes_small($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 one_total_sizes_big($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 one_total_sizes_small($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 two_total_sizes_big($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 two_total_sizes_small($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 three_total_sizes_big($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 three_total_sizes_small($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 four_total_sizes_big($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 four_total_sizes_small($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 lq_capot($bet_match, $result_match, $result_match_r)
    {
        if (empty($bet_match) || empty($result_match)) return false;

        // 篮球 独赢
        if ($bet_match->p_code != 'lq_capot') 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 == 'capot_home') {
            if ($home_score > $guest_score) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //客队
        if ($bet_match->odds_code == 'capot_guest') {
            if ($home_score < $guest_score) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //上半场
        if (strstr($bet_match->odds_code, "half")) {
            //获取上半场最终数据
            $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 == 'half_capot_home') {
                if ($home_score > $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //客队 上半场
            if ($bet_match->odds_code == 'half_capot_guest') {
                if ($home_score < $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第一节
        if (strstr($bet_match->odds_code, "one")) {
            //获取第一节最终数据
            $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 == 'one_capot_home') {
                if ($home_score > $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //客队 第一节
            if ($bet_match->odds_code == 'one_capot_guest') {
                if ($home_score < $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第二节
        if (strstr($bet_match->odds_code, "two")) {
            //获取第二节最终数据
            $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 == 'two_capot_home') {
                if ($home_score > $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //客队 第二节
            if ($bet_match->odds_code == 'two_capot_guest') {
                if ($home_score < $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第三节
        if (strstr($bet_match->odds_code, "three")) {
            //获取第三节最终数据
            $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 == 'three_capot_home') {
                if ($home_score > $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //客队 第三节
            if ($bet_match->odds_code == 'three_capot_guest') {
                if ($home_score < $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第四节
        if (strstr($bet_match->odds_code, "four")) {
            //获取第四节最终数据
            $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 == 'four_capot_home') {
                if ($home_score > $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //客队 第四节
            if ($bet_match->odds_code == 'four_capot_guest') {
                if ($home_score < $guest_score) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }

        return false;
    }

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

        if (empty($bet_match) || empty($result_match)) return false;
        // 篮球 球队得分大小
        if ($bet_match->p_code != 'lq_team_score') 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 == 'score_home_big') {
            $data['matchResult'] = "$home_score(全场主队得分)";
            if ($home_score > $condition) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //全场 主队 得分小
        if ($odds_code == 'score_home_small') {
            $data['matchResult'] = "$home_score(全场主队得分)";
            if ($home_score < $condition) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //全场 客队 得分大
        if ($odds_code == 'score_guest_big') {
            $data['matchResult'] = "$guest_score(全场客队得分)";
            if ($guest_score > $condition) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //全场 客队 得分小
        if ($odds_code == 'score_guest_small') {
            $data['matchResult'] = "$guest_score(全场客队得分)";
            if ($guest_score < $condition) {
                return $data;
            }
            $data['result'] = -1;
            return $data;
        }
        //上半场
        if (strstr($odds_code, "half")) {
            //获取上半场最终数据
            $last_stage_data = $retdatas['half'];
            //获取主客队上半场得分
            $home_score = $last_stage_data['home'];
            $guest_score = $last_stage_data['guest'];
            //上半场主队得分大
            if ($odds_code == 'half_score_home_big') {
                $data['matchResult'] = "$home_score(上半场主队得分)";
                if ($home_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //上半场主队得分小
            if ($odds_code == 'half_score_home_small') {
                $data['matchResult'] = "$home_score(上半场主队得分)";
                if ($home_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //上半场客队得分大
            if ($odds_code == 'half_score_guest_big') {
                $data['matchResult'] = "$guest_score(上半场客队得分)";
                if ($guest_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //上半场客队得分小
            if ($odds_code == 'half_score_guest_small') {
                $data['matchResult'] = "$guest_score(上半场客队得分)";
                if ($guest_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第一节
        if (strstr($odds_code, "one")) {
            //获取第一节最终数据
            $last_stage_data = $retdatas['list']['1'];
            //获取主客队第一节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //第一节主队得分大
            if ($odds_code == 'one_score_home_big') {
                $data['matchResult'] = "$home_score(第一节主队得分)";
                if ($home_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第一节主队得分小
            if ($odds_code == 'one_score_home_small') {
                $data['matchResult'] = "$home_score(第一节主队得分)";
                if ($home_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第一节客队得分大
            if ($odds_code == 'one_score_guest_big') {
                $data['matchResult'] = "$guest_score(第一节客队得分)";
                if ($guest_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第一节客队得分小
            if ($odds_code == 'one_score_guest_small') {
                $data['matchResult'] = "$guest_score(第一节客队得分)";
                if ($guest_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第二节
        if (strstr($odds_code, "two")) {
            //获取第二节最终数据
            $last_stage_data = $retdatas['list']['2'];
            //获取主客队第二节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //第二节主队得分大
            if ($odds_code == 'two_score_home_big') {
                $data['matchResult'] = "$home_score(第二节主队得分)";
                if ($home_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第二节主队得分小
            if ($odds_code == 'two_score_home_small') {
                $data['matchResult'] = "$home_score(第二节主队得分)";
                if ($home_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第二节客队得分大
            if ($odds_code == 'two_score_guest_big') {
                $data['matchResult'] = "$guest_score(第二节客队得分)";
                if ($guest_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第二节客队得分小
            if ($odds_code == 'two_score_guest_small') {
                $data['matchResult'] = "$guest_score(第二节客队得分)";
                if ($guest_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第三节
        if (strstr($odds_code, "three")) {
            //获取第三节最终数据
            $last_stage_data = $retdatas['list']['3'];
            //获取主客队第三节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //第三节主队得分大
            if ($odds_code == 'three_score_home_big') {
                $data['matchResult'] = "$home_score(第三节主队得分)";
                if ($home_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第三节主队得分小
            if ($odds_code == 'three_score_home_small') {
                $data['matchResult'] = "$home_score(第三节主队得分)";
                if ($home_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第三节客队得分大
            if ($odds_code == 'three_score_guest_big') {
                $data['matchResult'] = "$guest_score(第三节客队得分)";
                if ($guest_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第三节客队得分小
            if ($odds_code == 'three_score_guest_small') {
                $data['matchResult'] = "$guest_score(第三节客队得分)";
                if ($guest_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
        }
        //第四节
        if (strstr($odds_code, "four")) {
            //获取第四节最终数据
            $last_stage_data = $retdatas['list']['4'];
            //获取主客队第四节得分
            $home_score = $last_stage_data->home_score;
            $guest_score = $last_stage_data->guest_score;
            //第四节主队得分大
            if ($odds_code == 'four_score_home_big') {
                $data['matchResult'] = "$home_score(第四节主队得分)";
                if ($home_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第四节主队得分小
            if ($odds_code == 'four_score_home_small') {
                $data['matchResult'] = "$home_score(第四节主队得分)";
                if ($home_score < $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第四节客队得分大
            if ($odds_code == 'four_score_guest_big') {
                $data['matchResult'] = "$guest_score(第四节客队得分)";
                if ($guest_score > $condition) {
                    return $data;
                }
                $data['result'] = -1;
                return $data;
            }
            //第四节客队得分小
            if ($odds_code == 'four_score_guest_small') {
                $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 two_sides($model, $resultModel, $resultRecords)
    {
        $retdatas = $this->lq_scoreDatas($resultModel);
        $odds_code = $model->odds_code;

        switch ($odds_code) {
            case 'two_sides_single':
                $return = $this->two_sides_tooles($retdatas['all']['home'] + $retdatas['all']['guest'], 1);
                break;
            case 'two_sides_double':
                $return = $this->two_sides_tooles($retdatas['all']['home'] + $retdatas['all']['guest'], 2);
                break;
            case 'half_two_sides_single':
                $return = $this->two_sides_tooles($retdatas['half']['home'] + $retdatas['half']['guest'], 1);
                break;
            case 'half_two_sides_double':
                $return = $this->two_sides_tooles($retdatas['half']['home'] + $retdatas['half']['guest'], 2);
                break;
            case 'one_two_sides_single':
                $return = $this->two_sides_tooles($retdatas['list']['1']->home_score + $retdatas['list']['1']->guest_score, 1);
                break;
            case 'one_two_sides_double':
                $return = $this->two_sides_tooles($retdatas['list']['1']->home_score + $retdatas['list']['1']->guest_score, 2);
                break;
            case 'two_two_sides_single':
                $return = $this->two_sides_tooles($retdatas['list']['2']->home_score + $retdatas['list']['2']->guest_score, 1);
                break;
            case 'two_two_sides_double':
                $return = $this->two_sides_tooles($retdatas['list']['2']->home_score + $retdatas['list']['2']->guest_score, 2);
                break;
            case 'three_two_sides_single':
                $return = $this->two_sides_tooles($retdatas['list']['3']->home_score + $retdatas['list']['3']->guest_score, 1);
                break;
            case 'three_two_sides_double':
                $return = $this->two_sides_tooles($retdatas['list']['3']->home_score + $retdatas['list']['3']->guest_score, 2);
                break;
            case 'four_two_sides_single':
                $return = $this->two_sides_tooles($retdatas['list']['4']->home_score + $retdatas['list']['4']->guest_score, 1);
                break;
            case 'four_two_sides_double':
                $return = $this->two_sides_tooles($retdatas['list']['4']->home_score + $retdatas['list']['4']->guest_score, 2);
                break;
            default:
                $return = ['result' => 0, 'matchResult' => 'error'];
        }
        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 last_number($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 "last_home_zero_five":
                $ret = $this->last_number_return($home_last, [0, 5]);
                break;
            case "last_home_one_six":
                $ret = $this->last_number_return($home_last, [1, 6]);
                break;
            case "last_home_two_seven":
                $ret = $this->last_number_return($home_last, [2, 7]);
                break;
            case "last_home_three_eight":
                $ret = $this->last_number_return($home_last, [3, 8]);
                break;
            case "last_home_four_nine":
                $ret = $this->last_number_return($home_last, [4, 9]);
                break;
            case "last_guest_zero_five":
                $ret = $this->last_number_return($guest_last, [0, 5]);
                break;
            case "last_guest_one_six":
                $ret = $this->last_number_return($guest_last, [1, 6]);
                break;
            case "last_guest_two_seven":
                $ret = $this->last_number_return($guest_last, [2, 7]);
                break;
            case "last_guest_three_eight":
                $ret = $this->last_number_return($guest_last, [3, 8]);
                break;
            case "last_guest_four_nine":
                $ret = $this->last_number_return($guest_last, [4, 9]);
                break;
            default:
                $ret = ['result' => 0, 'matchResult' => '错误'];
                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;
    }

}