<?php
namespace App\Sports\Model;

use \System\Model;

/**
 * Class Account
 * @package App\Sports\Model
 * 用户账号
 */
class St_zq_odds extends Model
{
    protected $table = 'st_zq_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;
    }

    //获取赔率数据 用于pc端
    public static function getOddsDataPC($model_odds='',$select=[],$match_ids=[],$whereOr=[],$p_code=[]){
        $oddsData = lm($model_odds,"Sports")
            ->select($select)
            ->whereIn('match_id', $match_ids)
            ->where($whereOr)
            ->whereIn('p_code',['dishes','bureau','total_number'])
            ->get()
            ->toArray();

        return $oddsData;
    }

    //获取足球赛事下 滚球盘默认赔率
    public static function getMatchOdds($source,$models,$match_ids=[]){
        $model_odds = $models['model_odds'];
        $oddsData= lm($model_odds,"Sports")
            ->select($model_odds.'.match_id',$model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','odds_only','sort')
            ->where($model_odds.'.source',$source['source'])
            ->whereIn($model_odds.'.match_id',$match_ids)
            ->where([$model_odds.'.type'=>0])//查询滚球赔率
            //->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
            ->where(function($query)use ($model_odds){
                $query->where($model_odds.'.odds_code','concede_home')
                    ->orWhere(function($query)use ($model_odds){
                        $query->where($model_odds.'.odds_code','concede_guest');
                    })
                    ->orWhere(function($query)use ($model_odds){
                        $query->where($model_odds.'.odds_code','goal_size_big');
                    })
                    ->orWhere(function($query)use ($model_odds){
                        $query->where($model_odds.'.odds_code','goal_size_small');
                    })
                    ->orWhere(function($query)use ($model_odds){
                        $query->where($model_odds.'.odds_code','capot_home');
                    })
                    ->orWhere(function($query)use ($model_odds){
                        $query->where($model_odds.'.odds_code','capot_dogfall');
                    })
                    ->orWhere(function($query)use ($model_odds){
                        $query->where($model_odds.'.odds_code','capot_guest');
                    });
            })
            ->get()
            ->toarray();

        return $oddsData;
    }
}