Kygame_betting_ogrbv.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: ikeke
  5. * Date: 2018/12/6
  6. * Time: 19:38
  7. */
  8. namespace App\Models;
  9. use DB;
  10. class Kygame_betting_ogrbv extends BaseModel
  11. {
  12. protected $table = "kygame_betting_ogrbv";
  13. public $timestamps = false;
  14. /**
  15. * 获取所有游戏记录
  16. * @param string $where
  17. * @param int $limit
  18. * @return mixed
  19. */
  20. public function getlist($where='',$limit=15)
  21. {
  22. $data = $this->orderBy('id','desc');
  23. if(is_array($where)&&count($where)>0){
  24. $data = $data->where($where);
  25. }
  26. $data=$data->paginate($limit);
  27. return $data->toArray();
  28. }
  29. /**
  30. * 获取指定数据
  31. * @param string $where
  32. * @return mixed
  33. */
  34. public function getOneData($where='')
  35. {
  36. return $data = $this->where('GameID', $where)->first();
  37. }
  38. /**
  39. * 获取最新一条数据
  40. */
  41. public function getLastData()
  42. {
  43. $res = $this->orderBy('GameID','desc')->limit(1)->first()->toArray();
  44. return $res;
  45. }
  46. public function obInsertData($data)
  47. {
  48. $data['GameStartTime'] = strtotime(str_replace('/','-', $data['GameStartTime']));
  49. $data['GameEndTime'] = strtotime($data['GameEndTime']);
  50. $res = $this->insert($data);
  51. if(!$res)
  52. {
  53. return -3020011322;
  54. }
  55. }
  56. //获取回水列表
  57. protected function getMoneyback($value = '', $type = 1, $limit = 10, $wheregame = '', $orwhere = '', $having = '')
  58. {
  59. DB::connection()->enableQueryLog();
  60. $key = $this->getFeild($type);
  61. $data = $this->select('account_name','account_identity','Accounts',DB::raw('sum("AllBet") as betting_money'),DB::raw('sum("CellScore") as ValidAmount'),DB::raw('sum("Profit") as WinLoseAmount'),DB::raw('count("GameID") as bet_count'))->where('type',1)->groupBy('Accounts','account_name','account_identity');
  62. if (!empty($having)) {
  63. foreach ($having as $v) {
  64. $data = $data->havingRaw($v);
  65. }
  66. }
  67. if (!empty($wheregame)) {
  68. $data->whereIn('Accounts', $wheregame);
  69. }
  70. if (empty($value) || is_array($value)) {
  71. $where = $value;
  72. } else {
  73. $where[] = array($key, '=', $value);
  74. }
  75. // $where[] = array('water_status', '=', 1);
  76. $where[] = array('type', '=', 1);
  77. // $where[] = array('ResultType', '!=', 4);
  78. $data = $data->where($where);
  79. $data = $data->paginate($limit);
  80. if (!$data) {
  81. return -5030001202; //没有列表数据
  82. }
  83. return $data->toArray();
  84. }
  85. //字段对应值
  86. private function getFeild($num)
  87. {
  88. $data = array(
  89. '1' => 'id',
  90. '2' => 'GameID',
  91. '3' => 'Accounts',
  92. '4' => 'ServerID',
  93. '5' => 'KindID',
  94. '6' => 'TableID',
  95. '7' => 'ChairID',
  96. '8' => 'UserCount',
  97. '9' => 'CardValue',
  98. '10' => 'CellScore',
  99. '11' => 'AllBet',
  100. '12' => 'Profit',
  101. '13' => 'Revenue',
  102. '14' => 'GameStartTime',
  103. '15' => 'GameEndTime',
  104. '16' => 'ChannelID',
  105. '17' => 'LineCode',
  106. '18' => 'type',
  107. '19' => 'account_identity',
  108. '20' => 'account_name',
  109. );
  110. return $data[$num];
  111. }
  112. //反水更改狀
  113. protected function updateBackWater($name, $timearea)
  114. {
  115. $res = $this->where('account_name', $name)->where($timearea);
  116. $res = $res->update(['type' => '2']);
  117. if (!$res) {
  118. return -3012564406; //反水失败
  119. }
  120. return 1;
  121. }
  122. public function getSum($where)
  123. {
  124. $arr = array();
  125. $ba = 0;
  126. $wa= 0;
  127. $va = 0;
  128. $co = 0;
  129. if(is_array($where) && count($where)>0)
  130. {
  131. //查询总投注金额
  132. $ba = $this->where($where)->sum('AllBet');
  133. //查询总派彩金额
  134. $wa = $this->where($where)->sum('Profit');
  135. //查询总有效投注金额
  136. $vibet = $this->where($where)->sum('CellScore');
  137. $va = $this->where($where)->sum('Revenue');
  138. //查询总条数
  139. $co = $this->where($where)->count();
  140. }
  141. $arr['bettingamount'] = ceil($ba) == $ba ? $ba.'.00' : round($ba ,2);
  142. $arr['winLoseamount'] = ceil($wa) == $wa ? $wa.'.00' : round($wa ,2);
  143. $arr['validamount'] = ceil($vibet) == $vibet ? $vibet.'.00' : round($vibet ,2);
  144. $arr['revenue'] = ceil($va) == $va ? $va.'.00' : round($va ,2);
  145. $arr['co'] = $co;
  146. return $arr;
  147. }
  148. }