MoneyBuyMatch.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: scstf
  5. * Date: 2018/9/28
  6. * Time: 20:05
  7. */
  8. namespace App\Models;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Database\Eloquent\Model;
  11. class MoneyBuyMatch extends Model
  12. {
  13. protected $table = 'money_buy_match';
  14. public $timestamps = false;
  15. public function getByAttrs($where, $orderArray = [])
  16. {
  17. if (empty($orderArray)) {
  18. $datas = $this->where($where)->get();
  19. } else {
  20. $datas = $this->where($where)->orderby($orderArray['orderby'], $orderArray['order'])->get();
  21. }
  22. return $datas;
  23. }
  24. //赛事下所有投注状态的单式下单
  25. function simsettleorder($ssid='', $code=''){
  26. $where = array();
  27. $where[] = array('money_buy_match.match_id', '=', $ssid);
  28. $where[] = array('money_buy_match.bet_type', '=', 1);
  29. $where[] = array('money_buy_match.game_code', '=', $code);
  30. $where[] = array('money_buy_simplex.status', '=', 1);
  31. $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','st_odds_code.odds_name'];
  32. $data = $this->join('money_buy_simplex', 'money_buy_match.order_id', '=', 'money_buy_simplex.order_id')->join('st_odds_code', 'money_buy_match.odds_code', '=', 'st_odds_code.odds_code')->select($select)->where($where)->get()->toArray();
  33. return $data;
  34. }
  35. //赛事下所有投注状态下的串式下单
  36. function strsettleorder($ssid=''){
  37. $where = array();
  38. $where[] = array('money_buy_match.match_id', '=', $ssid);
  39. $where[] = array('money_buy_match.bet_type', '=', 2);
  40. $where[] = array('money_buy_str.status', '=', 1);
  41. $select = ['money_buy_str.order_id'];
  42. $data = $this->join('money_buy_str', 'money_buy_match.order_id', '=', 'money_buy_str.order_id')->join('st_odds_code', 'money_buy_match.odds_code', '=', 'st_odds_code.odds_code')->select($select)->where($where)->distinct('money_buy_match.order_id')->get()->toArray();
  43. return $data;
  44. }
  45. //赛事下所有下注单式下单
  46. function allsimplexorder($ssid='', $code='',$select=[],$match_ids = [])
  47. {
  48. //单式下单
  49. $where = array();
  50. $where[] = array('money_buy_match.match_id', '=', $ssid);
  51. $where[] = array('money_buy_match.bet_type', '=', 1);
  52. $where[] = array('money_buy_match.game_code', '=', $code);
  53. if(empty($select)){
  54. //一个赛事所有注单
  55. $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'];
  56. $data = $this->join('money_buy_simplex', 'money_buy_match.order_id', '=', 'money_buy_simplex.order_id')->select($select)->where($where)->get()->toArray();
  57. }else if(!empty($match_ids) and !empty($select)){
  58. //多赛事所有注单
  59. $typeWhere = [
  60. ['money_buy_match.bet_type', '=', 1],
  61. ['money_buy_match.game_code', '=', $code],
  62. ['money_buy_simplex.status', '=', 1],
  63. ];
  64. $data = $this->join('money_buy_simplex', 'money_buy_match.order_id', '=', 'money_buy_simplex.order_id')->select($select)->whereIn('money_buy_match.match_id',$match_ids)->where($typeWhere)->get();
  65. }else{
  66. $data = $this->join('money_buy_simplex', 'money_buy_match.order_id', '=', 'money_buy_simplex.order_id')->join('st_odds_code', 'money_buy_match.odds_code', '=', 'st_odds_code.odds_code')->select($select)->where($where)->get();
  67. }
  68. return $data;
  69. }
  70. //赛事下所有下注串式下单
  71. function allstrorder($ssid='',$game_code = '',$select=[])
  72. {
  73. //串式下单
  74. $where = array();
  75. $where[] = array('money_buy_match.match_id', '=', $ssid);
  76. $where[] = array('money_buy_match.bet_type', '=', 2);
  77. if(!empty($game_code)){
  78. $where[] = array('money_buy_match.game_code', '=', $game_code);
  79. }
  80. if(empty($select)){
  81. $select = ['money_buy_str.order_id'];
  82. $data = $this->join('money_buy_str', 'money_buy_match.order_id', '=', 'money_buy_str.order_id')->select($select)->where($where)->distinct('money_buy_match.order_id')->get()->toArray();
  83. }else{
  84. $data = $this->join('money_buy_str', 'money_buy_match.order_id', '=', 'money_buy_str.order_id')->join('st_odds_code', 'money_buy_match.odds_code', '=', 'st_odds_code.odds_code')->select($select)->where($where)->distinct('money_buy_match.order_id')->get();
  85. }
  86. return $data;
  87. }
  88. //修改串式下注状态
  89. function updatast($match_id)
  90. {
  91. $the = array(
  92. 'updated_at' => date('Y-m-d H:i:s'),
  93. 'result' => 2,
  94. );
  95. $where = array(
  96. 'match_id' => $match_id,
  97. 'bet_type' => 2,
  98. );
  99. $res = $this->where($where)->update($the);
  100. if (!$res) {
  101. return -4010000102; //更新失败
  102. }
  103. return $res;
  104. }
  105. //某个赛事的单式和串式条数统计
  106. public function countByMatch($matchID, $game_code)
  107. {
  108. $matchID = intval($matchID);
  109. $sqla = "select count(id) as mcount from money_buy_match where match_id=$matchID and game_code='$game_code' and bet_type=1 and order_id in( select order_id from money_buy_simplex where match_id=$matchID and game_code='$game_code' and is_manual=0 )";
  110. $sqlb = "select count(id) as mcount from money_buy_match where match_id=$matchID and game_code='$game_code' and bet_type=2 ";
  111. $reta = DB::select($sqla);
  112. $retb = DB::select($sqlb);
  113. $ret1 = $ret2 = 0;
  114. if ($reta && isset($reta['0']->mcount)) {
  115. $ret1 = intval($reta['0']->mcount);
  116. }
  117. if ($retb && isset($retb['0']->mcount)) {
  118. $ret2 = intval($retb['0']->mcount);
  119. }
  120. return ['bet1' => $ret1, 'bet2' => $ret2, 'count' => $ret1 + $ret2];
  121. }
  122. }