Ogsports_betting_ogrbv.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 Ogsports_betting_ogrbv extends BaseModel
  11. {
  12. protected $table = "ogsports_betting_ogrbv";
  13. public $timestamps = false;
  14. protected $guarded = [];
  15. /**
  16. * 获取所有游戏记录
  17. * @param string $where
  18. * @param int $limit
  19. * @return mixed
  20. */
  21. public function getlist($where='',$limit=15)
  22. {
  23. $data = $this->orderBy('id','desc');
  24. if(is_array($where)&&count($where)>0){
  25. $data = $data->where($where);
  26. }
  27. $data=$data->paginate($limit);
  28. return $data->toArray();
  29. }
  30. /**
  31. * 获取指定数据
  32. * @param string $where
  33. * @return mixed
  34. */
  35. public function getOneData($where='')
  36. {
  37. return $data = $this->where('bettingcode', $where)->first();
  38. }
  39. /**
  40. * 获取最新一条数据
  41. */
  42. public function getLastData()
  43. {
  44. $res = $this->orderBy('bettingcode','desc')->limit(1)->first()->toArray();
  45. return $res;
  46. }
  47. public function obInsertData($data)
  48. {
  49. $bettingdate = preg_match('/\d+/', $data['bettingdate'],$bettingda);
  50. $settledate = preg_match('/\d+/', $data['settledate'],$settleda);
  51. $data['bettingdate'] = $bettingda[0];
  52. $data['settledate'] = $settleda[0];
  53. $res = $this->insert($data);
  54. if(!$res)
  55. {
  56. return -3020011322;
  57. }
  58. }
  59. //获取回水列表
  60. protected function getMoneyback($value = '', $type = 1, $limit = 10, $wheregame = '', $orwhere = '', $having = '')
  61. {
  62. DB::connection()->enableQueryLog();
  63. $key = $this->getFeild($type);
  64. $data = $this->select('account_name','account_identity','membername',DB::raw('sum("bettingamount") as betting_money'),DB::raw('sum("validbet") as ValidAmount'),DB::raw('sum("winloseamount") as WinLoseAmount'),DB::raw('count("bettingcode") as bet_count'))->where('type',1)->groupBy('membername','account_name','account_identity');
  65. if (!empty($having)) {
  66. foreach ($having as $v) {
  67. $data = $data->havingRaw($v);
  68. }
  69. }
  70. if (!empty($wheregame)) {
  71. $data->whereIn('membername', $wheregame);
  72. }
  73. if (empty($value) || is_array($value)) {
  74. $where = $value;
  75. } else {
  76. $where[] = array($key, '=', $value);
  77. }
  78. // $where[] = array('water_status', '=', 1);
  79. $where[] = array('type', '=', 1);
  80. $where[] = array('status', '!=', '');
  81. $data = $data->where($where);
  82. $data = $data->paginate($limit);
  83. if (!$data) {
  84. return -5030001202; //没有列表数据
  85. }
  86. return $data->toArray();
  87. }
  88. //字段对应值
  89. private function getFeild($num)
  90. {
  91. $data = array(
  92. '1' => 'id',
  93. '2' => 'gameprovider',
  94. '3' => 'membername',
  95. '4' => 'gamename',
  96. '5' => 'bettingcode',
  97. '6' => 'bettingdate',
  98. '7' => 'gameid',
  99. '8' => 'roundno',
  100. '9' => 'result',
  101. '10' => 'bet',
  102. '11' => 'winloseresult',
  103. '12' => 'bettingamount',
  104. '13' => 'validbet',
  105. '14' => 'winloseamount',
  106. '15' => 'balance',
  107. '16' => 'currency',
  108. '17' => 'handicap',
  109. '18' => 'status',
  110. '19' => 'gamecategory',
  111. '20' => 'settledate',
  112. '21' => 'remark',
  113. '22' => 'type',
  114. '23' => 'account_identity',
  115. '24' => 'account_name',
  116. '25' => 'count_status',
  117. );
  118. return $data[$num];
  119. }
  120. //反水更改狀
  121. protected function updateBackWater($name, $timearea)
  122. {
  123. $res = $this->where('account_name', $name)->where($timearea);
  124. $res = $res->update(['type' => '2']);
  125. if (!$res) {
  126. return -3012564406; //反水失败
  127. }
  128. return 1;
  129. }
  130. public function getSum($where)
  131. {
  132. $arr = array();
  133. $ba = 0;
  134. $wa= 0;
  135. $va = 0;
  136. $co = 0;
  137. if(is_array($where) && count($where)>0)
  138. {
  139. //查询总有效投注金额
  140. $va = $this->where($where)->sum('bettingamount');
  141. $va = $this->where($where)->sum('validbet');
  142. $va = $this->where($where)->sum('winloseamount');
  143. //查询总条数
  144. $co = $this->where($where)->count();
  145. }
  146. $arr['bettingamount'] = ceil($ba) == $ba ? $ba.'.00' : round($ba ,2);
  147. $arr['winloseamount'] = ceil($wa) == $wa ? $wa.'.00' : round($wa ,2);
  148. $arr['validbet'] = ceil($va) == $va ? $va.'.00' : round($va ,2);
  149. // $arr['revenue'] = ceil($va) == $va ? $va.'.00' : round($va ,2);
  150. $arr['co'] = $co;
  151. return $arr;
  152. }
  153. }