<?php
namespace App\Sports\Model;

use \System\Model;

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

    protected $table = 'st_bq_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("match_id","type")->get();
        return $oddsData;
    }

    //获取棒球赛事下 默认赔率数据
    public static function getMatchOdds($source,$match_ids=[]){
        $oddsData = self::select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
            ->where($source)
            ->whereIn('match_id',$match_ids)
            ->where(function($query){
                $query->where('odds_code','concede_home')
                    ->orWhere(function($query){
                        $query->where('odds_code','concede_guest');
                    })
                    ->orWhere(function($query){
                        $query->where('odds_code','total_size_small');
                    })
                    ->orWhere(function($query){
                        $query->where('odds_code','total_size_big');
                    })
                    ->orWhere(function($query){
                        $query->where('odds_code','capot_home');
                    })
                    ->orWhere(function($query){
                        $query->where('odds_code','capot_guest');
                    });
            })
            ->get()
            ->toArray();

        return $oddsData;
    }
}