<?php
/**
 * Created by PhpStorm.
 * User: scstf
 * Date: 2018/9/28
 * Time: 20:05
 */

namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class MoneyBuyMatch extends Model
{
    protected $table='money_buy_match';
    public $timestamps = false;

    public function getByAttrs($where,$orderArray=[]){
        if (empty($order)){
            $datas = $this->where($where)->get();
        }else{
            $datas = $this->where($where)->orderby($orderArray['orderby'],$orderArray['order'])->get();
        }
        return $datas ;
    }

  	//赛事下所有下注单式下单
    function allsimplexorder($ssid,$code){ 
        //单式下单
        $where = array();
        $where[] = array('money_buy_match.match_id', '=', $ssid);
        $where[] = array('money_buy_match.bet_type', '=', 1);
		$where[] = array('money_buy_match.game_code', '=', $code);
        $data = $this->join('money_buy_simplex','money_buy_match.match_id','=','money_buy_simplex.match_id')->select('money_buy_simplex.order_id','money_buy_simplex.money','money_buy_simplex.account_identity','money_buy_simplex.info_identity','money_buy_simplex.match_id')->where($where)->get()->toArray();
        return $data;
    }

    //赛事下所有下注串式下单
    function allstrorder($ssid){ 
        //串式下单
        $where = array();
        $where[] = array('money_buy_match.match_id', '=', $ssid);
        $where[] = array('money_buy_match.bet_type', '=', 2);
        $data = $this->join('money_buy_str','money_buy_match.batch_id','=','money_buy_str.batch_id')->select('money_buy_str.order_id')->where($where)->get()->toArray();
        return $data;
    }

    //修改串式下注状态
    function updatast($match_id){
        $the = array(
            'updated_at'=>date('Y-m-d H:i:s'),
            'result'=>2,
        );
        $where = array(
        	'match_id'=>$match_id,
        	'bet_type'=>2,
        );

        $res = $this->where($where)->update($the);
          
        if (!$res) {
            return -4010000102; //更新失败
        }
        return $res;
    }


}