<?php

namespace App\Models;

use App\Lib\Biz\Sport\Common as commonFunction;
/**
 *
 */
class StoddsCode extends BaseModel
{
    protected $table = 'st_odds_code';
    public $timestamps = false;

    public function getTypeDatas($ret_game_code = '')
    {
        $all = self::all()->toArray();
        if (empty($all)) {
            return [];
        }

        $allIDKey = [];
        foreach ($all as $val) {
            $id = $val['id'];
            $allIDKey[$id] = $val;
        }

        $retall = [];
        foreach ($allIDKey as $id => $val) {
            if ($val['p_id'] != 0) {
                $game_code = $val['game_code'];
                $pid = $val['p_id'];
                $pidcode = $allIDKey[$pid]['odds_code'];
                $nowcode = $val['odds_code'];
                $retall[$game_code][$pidcode][$nowcode] = $val;
            }
        }
        if (empty($ret_game_code)) {
            return $retall;
        } else {
            return $retall[$ret_game_code];
        }
    }

    //根据分类获取各球类父级玩法数据
    public function getpcode($game_type){
        //获取球类父级玩法代码
        $pcode = commonFunction::getOddsPcode($game_type);

        $p_code =  $this->where('p_id',0)->where('game_code',$game_type)->wherein('odds_code',$pcode)->get();

        return $p_code;
    }

}

?>