Mggame_betting_ogrbv.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 Mggame_betting_ogrbv extends BaseModel
  11. {
  12. protected $table = "mggame_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=array(),$limit=15,$orby='GameEndTime',$sc="desc")
  21. {
  22. $data = $this->orderBy($orby,$sc);
  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. protected function getMoneyback($value = '', $type = 1, $limit = 10, $wheregame = '', $orwhere = '', $having = '')
  31. {
  32. DB::connection()->enableQueryLog();
  33. $key = $this->getFeild($type);
  34. $data = $this->select('account_name','account_identity',"AccountNumber",DB::raw('sum("Income") as betting_money'),DB::raw('sum("WinAmount") as WinLoseAmount'),DB::raw('sum("Income") as ValidAmount'),DB::raw('count("RowId") as bet_count'))->where('type',1)->groupBy('AccountNumber','account_name','account_identity');
  35. if (!empty($having)) {
  36. foreach ($having as $v) {
  37. $data = $data->havingRaw($v);
  38. }
  39. }
  40. if (empty($value) || is_array($value)) {
  41. $where = $value;
  42. } else {
  43. $where[] = array($key, '=', $value);
  44. }
  45. $where[] = array('type', '=', 1);
  46. $data = $data->where($where);
  47. $data = $data->paginate($limit);
  48. if (!$data) {
  49. return -5030001202; //没有列表数据
  50. }
  51. return $data->toArray();
  52. }
  53. //反水更改狀态
  54. protected function updateBackWater($name, $timearea)
  55. {
  56. $res = $this->where('account_name', $name)->where($timearea);
  57. $res = $res->update(['type' => '2']);
  58. if (!$res) {
  59. return -3012564406; //反水失败
  60. }
  61. return 1;
  62. }
  63. /**
  64. * 获取指定数据
  65. * @param string $where
  66. * @return mixed
  67. */
  68. protected function getOneData($where='')
  69. {
  70. return $data = $this->where('RowId', $where)->first();
  71. }
  72. protected function getSum($where)
  73. {
  74. $arr = array();
  75. $ba = 0;
  76. $wa= 0;
  77. $va = 0;
  78. $co = 0;
  79. if(is_array($where) && count($where)>0)
  80. {
  81. //查询总投注金额
  82. $ba = $this->where($where)->sum('AllBet');
  83. //查询总派彩金额
  84. $wa = $this->where($where)->sum('Profit');
  85. //查询总有效投注金额
  86. $va = $this->where($where)->sum('CellScore');
  87. $re = $this->where($where)->sum('Revenue');
  88. //查询总条数
  89. $co = $this->where($where)->count();
  90. }
  91. $arr['bettingamount'] = ceil($ba) == $ba ? $ba.'.00' : round($ba ,2);
  92. $arr['winLoseamount'] = ceil($wa) == $wa ? $wa.'.00' : round($wa ,2);
  93. $arr['validamount'] = ceil($va) == $va ? $va.'.00' : round($va ,2);
  94. $arr['revenue'] = ceil($re) == $re ? $re.'.00' : round($re ,2);
  95. $arr['co'] = $co;
  96. return $arr;
  97. }
  98. //字段对应值
  99. private function getFeild($num)
  100. {
  101. $data = array(
  102. '1' => 'id',
  103. '2' => 'RowId',
  104. '3' => 'AccountNumber',
  105. '4' => 'DisplayGameCategory',
  106. '5' => 'GameEndTime',
  107. '6' => 'ModuleId',
  108. '7' => 'ClientId',
  109. '8' => 'Income',
  110. '9' => 'Payout',
  111. '10' => 'winloseamount',
  112. '11' => 'count_status',
  113. '12' => 'WinAmount',
  114. '13' => 'LoseAmount',
  115. '14' => 'type',
  116. '15' => 'mggame_betting_ogrbv.account_identity',
  117. '16' => 'account_name'
  118. );
  119. return $data[$num];
  120. }
  121. //添加游戏注单信息
  122. protected function AddGameBet($betinfo){
  123. if(empty($betinfo) || empty($betinfo['GameID']))return -50630200102;
  124. $hasgid = $this->select('GameID')->whereIn('GameID',$betinfo['GameID'])->get();
  125. $hsinfo = array();
  126. if($hasgid && count($hasgid->toArray())>0){
  127. foreach ($hasgid->toArray() as $k => $v) {
  128. $hsinfo[] = $v['GameID'];
  129. }
  130. }
  131. $indata = array();
  132. foreach ($betinfo['GameID'] as $k => $v) {
  133. if(in_array($v, $hsinfo))continue;
  134. $account = explode('_', $betinfo['Accounts'][$k]);
  135. $rp_name = str_replace($account[0].'_', '', $betinfo['Accounts'][$k]);
  136. if(empty($account[2]))return -50630200202;
  137. //获取本站用户名
  138. $loainfo = \App\Models\Oggame_user::select('lo_name')->where('rp_name',$rp_name)->where('game_type','lygame')->first();
  139. if(!$loainfo || empty($loainfo->lo_name))return -50630201302;
  140. //获取本站用户ID
  141. $aid = \App\Models\Account::select('identity')->where('account',$loainfo->lo_name)->first();
  142. if(!$aid || empty($aid->identity))return -50630200302;
  143. $indata[$k] = array(
  144. 'GameID' => $v,
  145. 'Accounts' => $betinfo['Accounts'][$k],
  146. 'ServerID' => $betinfo['ServerID'][$k],
  147. 'KindID' => $betinfo['KindID'][$k],
  148. 'TableID' => $betinfo['TableID'][$k],
  149. 'ChairID' => $betinfo['ChairID'][$k],
  150. 'UserCount' => $betinfo['UserCount'][$k],
  151. 'CellScore' => $betinfo['CellScore'][$k],
  152. 'AllBet' => $betinfo['AllBet'][$k],
  153. 'Profit' => $betinfo['Profit'][$k],
  154. 'Revenue' => $betinfo['Revenue'][$k],
  155. 'GameStartTime' => strtotime($betinfo['GameStartTime'][$k]),
  156. 'GameEndTime' => strtotime($betinfo['GameEndTime'][$k]),
  157. 'CardValue' => $betinfo['CardValue'][$k],
  158. 'ChannelID' => $betinfo['ChannelID'][$k],
  159. 'LineCode' => $betinfo['LineCode'][$k],
  160. 'account_identity' => $aid->identity,
  161. 'account_name' => $loainfo->lo_name,
  162. );
  163. }
  164. if(!empty($indata)){
  165. $res = $this->insert($indata);
  166. if($res<0)return -50630200402;
  167. }
  168. return 1;
  169. }
  170. //接口地址获取
  171. protected function transferGame($agent,$data,$account,$money=0,$orderid='',$KindID=0,$time=1)
  172. {
  173. $ip= GETIP();
  174. $s = $data['s'];
  175. $robj = '\App\Models\Rgame_setting';
  176. $timestamp = str_pad($robj::getMillisecond(),13,0);//时间戳
  177. $jdata = json_decode($data['extend'], true);
  178. $DESKey = $jdata['desKey'];//'139B4CCEF28033C9';
  179. $lineCode=$jdata['lineCode'];
  180. $prams = 's='.$s;
  181. if ($s==0){
  182. $prams .= '&account='.$account.'&money='.$money.'&orderid='.$orderid.'&ip='.$ip.'&lineCode='.$lineCode.'&KindID='.$KindID;
  183. }elseif ($s==1 || $s==5 || $s==7 || $s==8){
  184. $prams .= '&account='.$account;
  185. }else if($s==2||$s==3){
  186. if($data['game_type'] == 'lygame'){
  187. $prams .= '&account='.$account.'&money='.$money.'&orderid='.$orderid;
  188. }else{
  189. $prams .= '&account='.$account.'&orderid='.$orderid.'&money='.$money;
  190. }
  191. }else if($s==4){
  192. $prams .= '&orderid='.$orderid;
  193. }else if($s==6)
  194. {
  195. $startTime = $timestamp-60*$time*1000;
  196. $endTime = $timestamp;
  197. $prams .= '&startTime='.$startTime.'&endTime='.$endTime;
  198. }
  199. $params = urlencode($robj::openssl_desEncode($prams,$DESKey));//参数加密字符串
  200. $key = md5($agent.$timestamp.$jdata['md5key']);
  201. $param = [
  202. 'agent' => $agent,
  203. 'timestamp' => $timestamp,
  204. 'param' => $params,
  205. 'key' => $key,
  206. ];
  207. if ($s == 6)
  208. {
  209. $url = $jdata['host2'].'?agent='.$agent.'&timestamp='.$timestamp.'&param='.$params.'&key='.$key;
  210. return $url;
  211. }
  212. $url = $jdata['host1'].'?agent='.$agent.'&timestamp='.$timestamp.'&param='.$params.'&key='.$key;
  213. return $url;
  214. }
  215. }