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

    function getinfo($list = 10, $page, $where = '')
    {
        if (is_array ($where) && count ($where) > 0) {
            $data = $this->join('st_zq_league','st_bet_order.lg_id','=','st_zq_league.lg_id')
                ->join('st_zq_competition','st_bet_order.match_id','=','st_zq_competition.match_id')
                ->join('account','st_bet_order.account_id','=','account.id')
                ->select('st_bet_order.id','st_bet_order.match_id','st_bet_order.lg_id','st_zq_league.name_chinese','st_bet_order.odds_id','st_bet_order.game_code','st_bet_order.ctime','st_bet_order.utime','st_bet_order.bet_amount','st_bet_order.win_amount','st_bet_order.bet_odds','st_bet_order.order_number','st_bet_order.status','st_zq_competition.home_team','st_zq_competition.guest_team','st_zq_competition.match_date','st_zq_competition.match_time','account.account')
                ->where('st_bet_order.game_code','zq')
                ->where($where)
                ->orderby('st_bet_order.utime','desc')
                ->orderby('st_bet_order.ctime','desc')
                ->paginate ($list);
        } else {
            $data = $this->join('st_zq_league','st_bet_order.lg_id','=','st_zq_league.lg_id')
                ->join('st_zq_competition','st_bet_order.match_id','=','st_zq_competition.match_id')
                ->join('account','st_bet_order.account_id','=','account.id')
                ->select('st_bet_order.id','st_bet_order.match_id','st_bet_order.lg_id','st_zq_league.name_chinese','st_bet_order.odds_id','st_bet_order.game_code','st_bet_order.ctime','st_bet_order.utime','st_bet_order.bet_amount','st_bet_order.win_amount','st_bet_order.bet_odds','st_bet_order.order_number','st_bet_order.status','st_zq_competition.home_team','st_zq_competition.guest_team','st_zq_competition.match_date','st_zq_competition.match_time','account.account')
                ->where('st_bet_order.game_code','zq')
                ->orderby('st_bet_order.utime','desc')
                ->orderby('st_bet_order.ctime','desc')
                ->paginate ($list);
        }
        if (!$data < 0) {
            return -2021052003; //
        }
        for($i=0;$i<count($data);$i++){
//            if($data[$i]->match_date <= date('Y-m-d',time()) && strtotime($data[$i]->match_time)+5400 <= strtotime(date('H:i:s',time()))){
//                $data[$i]->status = '2';
//                $this->where('id', $data[$i]->id)->update(['status' => 2]);
//            }
            if($data[$i]->status==1){
                $data[$i]->status = '待处理';
            }else if($data[$i]->status==1){
                $data[$i]->status = '已取消';
            }else if($data[$i]->status==2){
                $data[$i]->status = '已完成';
            }
            $data[$i]->home_guest = $data[$i]->home_team.' VS '.$data[$i]->guest_team;
            $data[$i]->competition_time = $data[$i]->match_date.' '.$data[$i]->match_time;
        }
        return $data->toArray();

    }


}