MgGameController.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qin
  5. * Date: 2019/2/27
  6. * Time: 15:13
  7. */
  8. namespace App\Http\Controllers\Admin;
  9. use App\Http\Controllers\Controller;
  10. use Request;
  11. use Illuminate\Support\Facades\DB;
  12. use \SoapClient;
  13. use \SoapVar;
  14. use \SoapHeader;
  15. class MgGameController extends Controller
  16. {
  17. protected $SessionGUID = 'ae6b4f27-ffdf-4db1-b1d2-3f99031f6d14';
  18. protected $game_type;
  19. protected $user_prefix;
  20. protected $agent_host;
  21. protected $agent_username;
  22. protected $agent_pincode;
  23. protected $agent_gameinfo;
  24. protected $api_url1;
  25. protected $api_url2;
  26. protected $token = '123321';
  27. protected $callbackurl;
  28. const cache_path = './';
  29. const PWDSTR = '2019';
  30. public function __construct()
  31. {
  32. $set = new \App\Models\Rgame_setting();
  33. $where = array();
  34. $where[] = array('game_type','=','mggame');
  35. $set_obj = $set->getGame($where);
  36. $json = json_decode($set_obj->extend, true);
  37. $this->agent_username = $set_obj->agent_name;
  38. $this->agent_pincode = $set_obj->agent_pwd;
  39. $this->api_url1 = $json['host1'];//api1
  40. $this->api_url2 = $json['host2'] ?? '';//api2
  41. $this->paly_host1 = $json['host3'] ?? '';//play1
  42. $this->paly_host2 = $json['host4'] ?? '';//play2
  43. $this->callbackurl = $json['callbackurl'] ?? '';//返回地址
  44. $this->game_type = $set_obj->game_type;
  45. $this->user_prefix = $set_obj->user_prefix;
  46. $this->agent_host = $set_obj->agent_url;
  47. $this->actype = 1;
  48. }
  49. //获取投注记录
  50. public function getbetlist(){
  51. $limit = Request::has ('limit') ? Request::get ('limit') : 10;
  52. $page = Request::has ('page') ? Request::get ('page') : 1;
  53. $start_time = Request::has ('start_time') ? Request::get ('start_time') : '';
  54. $end_time = Request::has ('end_time') ? Request::get ('end_time') : '';
  55. $mggame = new \App\Models\Mggame_betting_ogrbv();
  56. $where[] = array('GameEndTime','>=',strtotime($start_time.' 00:00:00'));
  57. $where[] = array('GameEndTime','<',strtotime($end_time.' 23:59:59'));
  58. $data = $mggame->getlist($where,$limit);
  59. foreach($data['data'] as $key => $val)
  60. {
  61. $data['data'][$key]['GameEndTime'] = date('Y-m-d H:i:s', $val['GameEndTime']);
  62. }
  63. return \App\Lib\DataTable\DataTable::init ()->toJson ($data['data'], $data['total']);
  64. }
  65. //更新流水
  66. public function updatebetlist(){
  67. $limit = Request::has ('limit') ? Request::get ('limit') : 1000;
  68. $page = Request::has ('page') ? Request::get ('page') : 1;
  69. $start_time = Request::has ('start_time') ? Request::get ('start_time') : date('Y-m-d');
  70. $end_time = Request::has ('end_time') ? Request::get ('end_time') : date('Y-m-d');
  71. $res = array();
  72. $this->IsAuthenticate();
  73. $id=$this->GetBetInfoDetails($start_time,$end_time,$limit);
  74. if(!empty($id)){
  75. $res = $this->GetReportResult($id,$page);
  76. if($res['code'] == 0){
  77. $indata = [];
  78. $indatatwo = [];
  79. foreach ($res['data'] as $key => $value) {
  80. //获取本站用户名
  81. $loainfo = \App\Models\Oggame_user::select('lo_name')->where('rp_name',$value['AccountNumber'])->where('game_type','mggame')->first();
  82. if(!$loainfo || empty($loainfo->lo_name))return -50630201302;
  83. //获取本站用户ID
  84. $aid = \App\Models\Account::select('identity')->where('account',$loainfo->lo_name)->first();
  85. if(!$aid || empty($aid->identity))return -50630200302;
  86. $mginfo = \App\Models\Mggame_betting_ogrbv::where(['AccountNumber'=>$value['AccountNumber'],'GameEndTime'=>strtotime($value['Date'])])->first();
  87. if(empty($mginfo)){
  88. $indata[$key] = array(
  89. 'RowId' => md5(json_encode($value)),
  90. 'AccountNumber' => $value['AccountNumber'],
  91. 'Income' => $value['Income'],
  92. 'Payout' => $value['Payout'],
  93. 'WinAmount' => $value['WinAmount'],
  94. 'LoseAmount' => $value['LoseAmount'],
  95. 'ModuleId' => $value['ModuleId'],
  96. 'ClientId' => $value['ClientId'],
  97. 'DisplayGameCategory' => $value['GameType'],
  98. 'GameEndTime' => strtotime($value['Date']),
  99. 'account_identity'=>$aid->identity,
  100. 'account_name'=>$loainfo->lo_name,
  101. 'winloseamount'=>floatval($value['WinAmount'])+floatval($value['LoseAmount'])
  102. );
  103. }else{
  104. $indatatwo = array(
  105. 'RowId' => md5(json_encode($value)),
  106. 'AccountNumber' => $value['AccountNumber'],
  107. 'Income' => $value['Income'],
  108. 'Payout' => $value['Payout'],
  109. 'WinAmount' => $value['WinAmount'],
  110. 'LoseAmount' => $value['LoseAmount'],
  111. 'ModuleId' => $value['ModuleId'],
  112. 'ClientId' => $value['ClientId'],
  113. 'DisplayGameCategory' => $value['GameType'],
  114. 'GameEndTime' => strtotime($value['Date']),
  115. 'account_identity'=>$aid->identity,
  116. 'account_name'=>$loainfo->lo_name,
  117. 'winloseamount'=>floatval($value['WinAmount'])+floatval($value['LoseAmount'])
  118. );
  119. $restt = \App\Models\Mggame_betting_ogrbv::where('id',$mginfo->id)->update($indatatwo);
  120. }
  121. }
  122. }
  123. if(!empty($indata)){
  124. $res = \App\Models\Mggame_betting_ogrbv::insert($indata);
  125. if($res<0)return -50630200402;
  126. }
  127. }
  128. return 1;
  129. }
  130. /**
  131. * get SessionGUID
  132. *
  133. * Authenticates the agent by login name and password.
  134. * The SessionGUID which retrieved via this method should be used in all other methods in theHeader
  135. *
  136. * @param $agentname
  137. * @param $pincode
  138. */
  139. public function IsAuthenticate(){
  140. $client = new SoapClient($this->api_url1.'?wsdl', array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP));
  141. $result = $client->IsAuthenticate(
  142. array(
  143. 'loginName' => $this->agent_username,
  144. 'pinCode' =>$this->agent_pincode
  145. )
  146. );
  147. if ($result->IsAuthenticateResult->ErrorCode == 0) {
  148. $this->SessionGUID = $result->IsAuthenticateResult->SessionGUID;
  149. }
  150. return $result;
  151. }
  152. //获取投注详情id
  153. public function GetBetInfoDetails($s_time='',$e_time='',$limit){
  154. $client = new SoapClient($this->api_url1.'?wsdl', array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP));
  155. $starttime = date("Y-m-d\TH:i:s",strtotime($s_time)) ?? date("Y-m-d\TH:i:s",strtotime("-1 day"));
  156. $endtime = date("Y-m-d\TH:i:s",strtotime($e_time)) ?? date("Y-m-d\TH:i:s");
  157. $data = [
  158. 'dateFrom' => $starttime,
  159. 'dateTo' => $endtime,
  160. 'maxNumRowsPage' => $limit,
  161. ];
  162. $xml = '
  163. <AgentSession xmlns="https://entservices.totalegame.net">
  164. <SessionGUID>' . $this->SessionGUID . '</SessionGUID>
  165. <IPAddress>' . $_SERVER['REMOTE_ADDR'] . '</IPAddress>
  166. </AgentSession>
  167. ';
  168. $xmlvar = new SoapVar($xml, XSD_ANYXML);
  169. $header = new SoapHeader($this->api_url1, 'AgentSession', $xmlvar);
  170. $client->__setSoapHeaders($header);
  171. $result = $client->GetBetInfoDetails($data);
  172. $res=$result->GetBetInfoDetailsResult;
  173. return $res;
  174. }
  175. //获取投注列表
  176. public function GetReportResult($id,$page){
  177. $client = new SoapClient($this->api_url1.'?wsdl', array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP));
  178. $data = [
  179. 'id' => $id,
  180. 'nPage' => $page
  181. ];
  182. $xml = '
  183. <AgentSession xmlns="https://entservices.totalegame.net">
  184. <SessionGUID>' . $this->SessionGUID . '</SessionGUID>
  185. <IPAddress>' . $_SERVER['REMOTE_ADDR'] . '</IPAddress>
  186. </AgentSession>
  187. ';
  188. $xmlvar = new SoapVar($xml, XSD_ANYXML);
  189. $header = new SoapHeader($this->api_url1, 'AgentSession', $xmlvar);
  190. $client->__setSoapHeaders($header);
  191. $result = $client->GetReportResult($data);
  192. $res=$result->GetReportResultResult;
  193. if($res->ErrorCode ==0){
  194. $json = json_decode(json_encode(simplexml_load_string($res->CurrentPageData->any)),TRUE);
  195. $da['code'] = 0;
  196. if(empty($json)){
  197. $da['data'] = [];
  198. }else{
  199. $da['data'] = $json['NewDataSet']['Table'];
  200. }
  201. $paging = json_decode(json_encode($res->Paging),TRUE);
  202. $da['count'] = count($da['data']);
  203. $da['extras'] =[];
  204. $da['msg'] ='';
  205. }
  206. return $da;
  207. }
  208. }