Oggame_betting_ogrbv.php 4.7 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 Oggame_betting_ogrbv extends BaseModel
  11. {
  12. protected $table = "oggame_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('VendorId', $where)->first();
  37. }
  38. /**
  39. * 获取最新一条数据
  40. */
  41. public function getLastData()
  42. {
  43. $res = $this->orderBy('VendorId','desc')->limit(1)->first();
  44. if (empty($res)) {
  45. return -10101;
  46. }
  47. return $res->toArray();
  48. }
  49. public function obInsertData($data)
  50. {
  51. $data['AddTime'] = strtotime(str_replace('/','-', $data['AddTime']));
  52. $res = $this->insert($data);
  53. if(!$res)
  54. {
  55. return -3020011322;
  56. }
  57. }
  58. //获取回水列表
  59. protected function getMoneyback($value = '', $type = 1, $limit = 10, $wheregame = '', $orwhere = '', $having = '')
  60. {
  61. DB::connection()->enableQueryLog();
  62. $key = $this->getFeild($type);
  63. $data = $this->select('account_name','account_identity',"UserName",DB::raw('sum("BettingAmount") as betting_money'),DB::raw('sum("WinLoseAmount") as WinLoseAmount'),DB::raw('sum("ValidAmount") as ValidAmount'),DB::raw('count("OrderNumber") as bet_count'))->where('type',1)->where('ResultType','<>',4)->groupBy('UserName','account_name','account_identity');
  64. if (!empty($having)) {
  65. foreach ($having as $v) {
  66. $data = $data->havingRaw($v);
  67. }
  68. }
  69. if (!empty($wheregame)) {
  70. $data->whereIn('UserName', $wheregame);
  71. }
  72. if (empty($value) || is_array($value)) {
  73. $where = $value;
  74. } else {
  75. $where[] = array($key, '=', $value);
  76. }
  77. // $where[] = array('water_status', '=', 1);
  78. $where[] = array('type', '=', 1);
  79. $where[] = array('ResultType', '!=', 4);
  80. $data = $data->where($where);
  81. $data = $data->paginate($limit);
  82. if (!$data) {
  83. return -5030001202; //没有列表数据
  84. }
  85. return $data->toArray();
  86. }
  87. //字段对应值
  88. private function getFeild($num)
  89. {
  90. $data = array(
  91. '1' => 'id',
  92. '2' => 'ProductID',
  93. '3' => 'UserName',
  94. '4' => 'GameRecordID',
  95. '5' => 'OrderNumber',
  96. '6' => 'TableID',
  97. '7' => 'Stage',
  98. '8' => 'Inning',
  99. '9' => 'GameNameID',
  100. '10' => 'GameBettingKind',
  101. '11' => 'GameBettingContent',
  102. '12' => 'ResultType',
  103. '13' => 'BettingAmount',
  104. '14' => 'CompensateRate',
  105. '15' => 'WinLoseAmount',
  106. '16' => 'Balance',
  107. '17' => 'AddTime',
  108. '18' => 'PlatformID',
  109. '19' => 'VendorId',
  110. '20' => 'ValidAmount',
  111. '21' => 'GameResult',
  112. '22' => 'account_identity',
  113. '23' => 'account_name',
  114. );
  115. return $data[$num];
  116. }
  117. //反水更改狀
  118. public function updateBackWater($name, $timearea)
  119. {
  120. $res = $this->where('account_name', $name)->where($timearea);
  121. $res = $res->update(['type' => '2']);
  122. if (!$res) {
  123. return -3012564406; //反水失败
  124. }
  125. return 1;
  126. }
  127. public function getSum($where)
  128. {
  129. $arr = array();
  130. $ba = 0;
  131. $wa= 0;
  132. $va = 0;
  133. $co = 0;
  134. if(is_array($where) && count($where)>0)
  135. {
  136. //查询总投注金额
  137. $ba = $this->where($where)->sum('BettingAmount');
  138. //查询总派彩金额
  139. $wa = $this->where($where)->sum('WinLoseAmount');
  140. //查询总有效投注金额
  141. $va = $this->where($where)->sum('ValidAmount');
  142. //查询总条数
  143. $co = $this->where($where)->count();
  144. }
  145. $arr['bettingamount'] = ceil($ba) == $ba ? $ba.'.00' : round($ba ,2);
  146. $arr['winLoseamount'] = ceil($wa) == $wa ? $wa.'.00' : round($wa ,2);
  147. $arr['validamount'] = ceil($va) == $va ? $va.'.00' : round($va ,2);
  148. $arr['co'] = $co;
  149. return $arr;
  150. }
  151. }