Lcqpgame_betting_ogrbv.php 8.5 KB

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