Hjgame_betting_ogrbv.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 Hjgame_betting_ogrbv extends BaseModel
  11. {
  12. protected $table = "hjgame_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, $orby = 'id', $sc = "desc"){
  21. $data = $this->orderBy($orby, $sc);
  22. if (is_array($where) && count($where)>0) {
  23. $data = $data->where($where);
  24. }
  25. $data = $data->paginate($limit);
  26. return $data? $data->toArray():[];
  27. }
  28. protected function getLastTime(){
  29. $data = $this->orderBy('id','desc')->first(['bet_time']);
  30. return $data?date('Y-m-d H:i:s',$data->toArray()['bet_time']):'';
  31. }
  32. /**
  33. * 获取指定数据
  34. * @param string $where
  35. * @return mixed
  36. */
  37. protected function getOneData($where = ''){
  38. return $data = $this->where('record_id', $where)->first();
  39. }
  40. public function getSum($where){
  41. $arr = [];
  42. $ba = 0;
  43. $wa = 0;
  44. $va = 0;
  45. $co = 0;
  46. if (is_array($where) && count($where)>0) {
  47. //查询总投注金额
  48. $ba = $this->where($where)->sum('bet_amount');
  49. //查询总派彩金额
  50. $wa = $this->where($where)->where('profit','>','0')->sum('profit');
  51. //查询总有效投注金额
  52. $va = $this->where($where)->where('state','1')->sum('bet_amount');
  53. //查询总条数
  54. $co = $this->where($where)->count();
  55. }
  56. $arr['bettingamount'] = ceil($ba) == $ba ? $ba : round($ba, 2);
  57. $arr['winLoseamount'] = ceil($wa) == $wa ? $wa : round($wa, 2);
  58. $arr['validamount'] = ceil($va) == $va ? $va : round($va, 2);
  59. $arr['revenue'] = 0;
  60. $arr['co'] = $co;
  61. return $arr;
  62. }
  63. //获取回水列表
  64. protected function getMoneyback($value = '', $type = 1, $limit = 10, $wheregame = '', $orwhere = '', $having = '')
  65. {
  66. DB::connection()->enableQueryLog();
  67. $data = $this->select('account_name','account_identity',"username as Accounts",DB::raw('sum("bet_amount") as betting_money'),DB::raw('sum("profit") as WinLoseAmount'),DB::raw('sum("bet_amount") as ValidAmount'),DB::raw('count("id") as bet_count'))->where('state',1)->groupBy('username','account_name','account_identity');
  68. if (!empty($having)) {
  69. foreach ($having as $v) {
  70. $data = $data->havingRaw($v);
  71. }
  72. }
  73. if (empty($value) || is_array($value)) {
  74. $where = $value;
  75. } else {
  76. $where[] = array( 'id', $value);
  77. }
  78. $where[] = array('type', 1);
  79. $data = $data->where($where);
  80. $data = $data->paginate($limit);
  81. if (!$data) {
  82. return -5030001202; //没有列表数据
  83. }
  84. return $data->toArray();
  85. }
  86. //反水更改狀
  87. public function updateBackWater($name, $timearea)
  88. {
  89. $res = $this->where('account_name', $name)->where($timearea);
  90. $res = $res->update(['type' => '2']);
  91. if (!$res) {
  92. return -3012564406; //反水失败
  93. }
  94. return 1;
  95. }
  96. //添加游戏注单信息
  97. protected function AddGameBet($betinfo){
  98. $users = $indata = [];
  99. $i=$j=0;
  100. foreach ($betinfo as $k => $v) {
  101. if(!empty($v['bet_time'])){
  102. $v['bet_time'] = strtotime($v['bet_time']);
  103. }
  104. if(!empty($v['draw_time'])){
  105. $v['draw_time'] = strtotime($v['draw_time']);
  106. }
  107. if (!array_key_exists($v['username'], $users)) {
  108. //获取本站用户名
  109. $loainfo = \App\Models\Oggame_user::select('lo_name')->where('rp_name', $v['username'])->first();
  110. //获取本站用户ID
  111. if (!empty($loainfo->lo_name)){
  112. $aid = \App\Models\Account::select('identity')->where('account', $loainfo->lo_name)->first();
  113. if (!empty($aid->identity)){
  114. $users[$v['username']] = ['identity' => $aid->identity, 'name' => $loainfo->lo_name];
  115. $indata = [
  116. 'oder_id' =>md5(json_encode($v)),
  117. 'account_identity' =>$users[$v['username']]['identity'],
  118. 'account_name' => $users[$v['username']]['name'],
  119. ];
  120. $indata = (array_merge($indata,$v));
  121. try{
  122. $res = $this->insert($indata);
  123. if($res)++$i;
  124. }catch (\Exception $e){
  125. if(strpos($e->getMessage(),'Unique violation')!==false){continue;}else{
  126. dd($e);
  127. }
  128. }
  129. }
  130. }
  131. }
  132. }
  133. return $i;
  134. }
  135. }