MoneyBuyMatch.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 allsimplexorder($ssid='', $code='',$select=[],$match_ids = [])
  26. {
  27. //单式下单
  28. $where = array();
  29. $where[] = array('money_buy_match.match_id', '=', $ssid);
  30. $where[] = array('money_buy_match.bet_type', '=', 1);
  31. $where[] = array('money_buy_match.game_code', '=', $code);
  32. if(empty($select)){
  33. //一个赛事所有注单
  34. $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'];
  35. $data = $this->join('money_buy_simplex', 'money_buy_match.batch_id', '=', 'money_buy_simplex.batch_id')->select($select)->where($where)->get()->toArray();
  36. }else if(!empty($match_ids) and !empty($select)){
  37. //多赛事所有注单
  38. $typeWhere = [
  39. ['money_buy_match.bet_type', '=', 1],
  40. ['money_buy_match.game_code', '=', $code],
  41. ['money_buy_simplex.status', '=', 1],
  42. ];
  43. $data = $this->join('money_buy_simplex', 'money_buy_match.batch_id', '=', 'money_buy_simplex.batch_id')->select($select)->whereIn('money_buy_match.match_id',$match_ids)->where($typeWhere)->get();
  44. }else{
  45. $where[] = array('money_buy_simplex.status', '=', 1);
  46. $data = $this->join('money_buy_simplex', 'money_buy_match.batch_id', '=', 'money_buy_simplex.batch_id')->join('st_odds_code', 'money_buy_match.odds_code', '=', 'st_odds_code.odds_code')->select($select)->where($where)->get();
  47. }
  48. return $data;
  49. }
  50. //赛事下所有下注串式下单
  51. function allstrorder($ssid='',$game_code = '',$select=[])
  52. {
  53. //串式下单
  54. $where = array();
  55. $where[] = array('money_buy_match.match_id', '=', $ssid);
  56. $where[] = array('money_buy_match.bet_type', '=', 2);
  57. if(!empty($game_code)){
  58. $where[] = array('money_buy_match.game_code', '=', $game_code);
  59. $where[] = array('money_buy_str.status', '=', 1);
  60. }
  61. if(empty($select)){
  62. $select = ['money_buy_str.order_id'];
  63. $data = $this->join('money_buy_str', 'money_buy_match.batch_id', '=', 'money_buy_str.batch_id')->select($select)->where($where)->distinct('money_buy_match.batch_id')->get()->toArray();
  64. }else{
  65. $data = $this->join('money_buy_str', 'money_buy_match.batch_id', '=', 'money_buy_str.batch_id')->join('st_odds_code', 'money_buy_match.odds_code', '=', 'st_odds_code.odds_code')->select($select)->where($where)->distinct('money_buy_match.batch_id')->get();
  66. }
  67. return $data;
  68. }
  69. //修改串式下注状态
  70. function updatast($match_id)
  71. {
  72. $the = array(
  73. 'updated_at' => date('Y-m-d H:i:s'),
  74. 'result' => 2,
  75. );
  76. $where = array(
  77. 'match_id' => $match_id,
  78. 'bet_type' => 2,
  79. );
  80. $res = $this->where($where)->update($the);
  81. if (!$res) {
  82. return -4010000102; //更新失败
  83. }
  84. return $res;
  85. }
  86. //某个赛事的单式和串式条数统计
  87. public function countByMatch($matchID, $game_code)
  88. {
  89. $matchID = intval($matchID);
  90. $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 )";
  91. $sqlb = "select count(id) as mcount from money_buy_match where match_id=$matchID and game_code='$game_code' and bet_type=2 ";
  92. $reta = DB::select($sqla);
  93. $retb = DB::select($sqlb);
  94. $ret1 = $ret2 = 0;
  95. if ($reta && isset($reta['0']->mcount)) {
  96. $ret1 = intval($reta['0']->mcount);
  97. }
  98. if ($retb && isset($retb['0']->mcount)) {
  99. $ret2 = intval($retb['0']->mcount);
  100. }
  101. return ['bet1' => $ret1, 'bet2' => $ret2, 'count' => $ret1 + $ret2];
  102. }
  103. }