<?php
namespace App\Sports\Model;

use \System\Model;

/**
 * Class Account
 * @package App\Sports\Model
 * 用户账号
 */
class St_lq_odds extends Model
{

    protected $table = 'st_lq_odds';

    /**
     * @param array $where 条件
     * @param string $select 字段
     * @param string $sort 排序字段
     * @param string $orderby 排序方式
     * @return mixed
     * 获取赔率数据
     */
    public static function getOddsData($where=[],$select='id',$sort='id',$orderby='asc'){
        $oddsData = self::select($select)->where($where)->groupby("lg_id","match_id","type")->get();
        return $oddsData;
    }

    //获取篮球赛事下 默认赔率数据
    public static function getMatchOdds($source,$match_ids=[],$DefaultOdds=[]){
         
        $oddsData = self::select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
//            ->where($source)
            ->whereIn('match_id',$match_ids)
            ->where(['type'=>0,'status'=>0])//查询滚球赔率
            ->where('is_stringscene',0)
            ->where(function($query)use ($DefaultOdds){
                $query->where('odds_code','concede_home')
                    ->orWhere(function($query)use ($DefaultOdds){
                        $query->where('odds_code',$DefaultOdds['lq_concede_home']);
                    })
                    ->orWhere(function($query)use ($DefaultOdds){
                        $query->where('odds_code',$DefaultOdds['lq_concede_guest']);
                    })
                    ->orWhere(function($query)use ($DefaultOdds){
                        $query->where('odds_code',$DefaultOdds['lq_total_size_big']);
                    })
                    ->orWhere(function($query)use ($DefaultOdds){
                        $query->where('odds_code',$DefaultOdds['lq_total_size_small']);
                    })
                    ->orWhere(function($query)use ($DefaultOdds){
                        $query->where('odds_code',$DefaultOdds['lq_capot_home']);
                    })
                    ->orWhere(function($query)use ($DefaultOdds){
                        $query->where('odds_code',$DefaultOdds['lq_capot_guest']);
                    });
            })
            ->get()
            ->toArray();

        return $oddsData;
    }
}