<?php
/**
 * Created by PhpStorm.
 * User: Jonlin
 * Date: 2019/4/1
 * Time: 10:12
 */
namespace App\Models;
use Illuminate\Support\Facades\DB;
class BasketOdds extends BaseModel
{
    protected $table = "st_lq_odds";
    public $timestamps = false;

    function getodds($match_id,$where = ''){
        //$data=$this->where($where)->where('expire_time','<',date('Y-m-d H:i:s',time()))->get();
        $data=$this->where('match_id',$match_id)->where($where)->get()->toArray();
        $num=$this->where('match_id',$match_id)->where('sort',0)->get()->toArray();
        $sort = array_column($data,'sort');
        array_multisort($sort,SORT_DESC,$data);
        $data = array_slice($data,0,count($num));

        if(!$data < 0){
            return -2021052003;
        }

        //玩法代码
        $pcode = \App\Models\Matchcode::where('p_id','0')->get();
        $odds_code = \App\Models\Matchcode::where('p_id','!=','0')->get();

        for($i=0;$i<count($data);$i++){
            if($data[$i]['status']==0){
                $data[$i]['status'] = '启用';
            }else if($data[$i]['status']==1){
                $data[$i]['status'] = '停用';
            }else if($data[$i]['status']==-1){
                $data[$i]['status'] = '禁用';
            }

            $data[$i]['p_code_cn'] = '';
            $data[$i]['odds_code_cn'] = '';
            for($j=0;$j<count($pcode);$j++){
                if($data[$i]['p_code'] == $pcode[$j]->odds_code){
                    $data[$i]['p_code_cn'] = $pcode[$j]->odds_name;
                }
            }
            if($data[$i]['p_code_cn'] == ''){
                $data[$i]['p_code_cn'] = $data[$i]['p_code'];
            }

            for($a=0;$a<count($odds_code);$a++){
                if($data[$i]['odds_code'] == $odds_code[$a]->odds_code){
                    $data[$i]['odds_code_cn'] = $odds_code[$a]->odds_name;
                }
            }
            if($data[$i]['odds_code_cn'] == ''){
                $data[$i]['odds_code_cn'] = $data[$i]['odds_code'];
            }
        }
        return $data;

    }
}