GameController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\Game\Config\GameBasicConfig;
  4. use App\Game\GameCard;
  5. use App\Game\GlobalUserInfo;
  6. use App\Game\LogGamecardClick;
  7. use App\Game\PageModule;
  8. use App\Game\Services\OuroGameService;
  9. use App\Http\Controllers\Api\ApiController;
  10. use App\Http\Controllers\Controller;
  11. use App\Models\AccountsInfo;
  12. use App\Models\Treasure\GameScoreLocker;
  13. use App\Services\IpCheck;
  14. use App\Util;
  15. use Illuminate\Http\Request;
  16. use Illuminate\Support\Facades\DB;
  17. use Illuminate\Support\Facades\Redis;
  18. // use Yansongda\Pay\Log;
  19. class GameController extends Controller
  20. {
  21. public function __construct()
  22. {
  23. }
  24. public function GetGameInfo(Request $request)
  25. {
  26. $id=$request->input('id');
  27. $card=GameCard::GetGameByID($id);
  28. return apiReturnSuc($card);
  29. }
  30. public function Ouro777GamePage(Request $request)
  31. {
  32. $this->CheckOuroGamePort();
  33. $gid=$request->input('gid');
  34. $level=$request->input('level',1);
  35. $user = $request->globalUser;
  36. $userid=$user->UserID;
  37. $lang=GlobalUserInfo::getLocale();
  38. $clientLang='en';
  39. if($lang=='pt')$clientLang='pu';
  40. else if($lang=='es')$clientLang='sp';
  41. else $lang='en';
  42. GameScoreLocker::where('UserID',$userid)->delete();
  43. $Dollar=GameBasicConfig::$DOLLAR;//['pt'=>'R$','en'=>'$','es'=>'M$'];
  44. GameCard::$enableStateCheck=false;
  45. $gamecard=GameCard::where('gid',$gid)->where('brand','OURO777')->first();
  46. $in_gameid=OuroGameService::getUserInGame($userid,$user->GlobalUID);
  47. if($in_gameid!=intval($gamecard->id)){
  48. Util::WriteLog('24680game',compact('in_gameid','gamecard','user'));
  49. // die;
  50. }
  51. $gamecard->increment('play_num',1);
  52. $this->logGameClick($gamecard->id,$userid);
  53. $servers=DB::table('QPPlatformDB.dbo.GameRoomInfo')
  54. ->where("Nullity",0)
  55. ->where("Alive",1)
  56. ->where("SortID",$level)
  57. ->where('GameID',$gid)->get()->toArray();
  58. $rand=$servers[array_rand($servers)];
  59. $rand=(object)$rand;
  60. $server=[
  61. "KindID"=> $rand->GameID,
  62. "NodeID"=> $rand->NodeID,
  63. "SortID"=> $rand->SortID,
  64. "ServerID"=> $rand->ServerID,
  65. "ServerType"=> $rand->ServerType,
  66. "ServerPort"=> $rand->ServerPort,
  67. "CellScore"=> $rand->CellScore,
  68. "EnterScore"=> $rand->MaxEnterScore,
  69. "ServerRule"=> $rand->MaxEnterScore,
  70. "OnLineCount"=> 1,
  71. "AndroidCount"=> 0,
  72. "FullCount"=> 100,
  73. "ServerAddr"=> "1.1.1.1",
  74. "ServerName"=> $rand->ServerName,
  75. "GameKindItem"=> [
  76. "TypeID"=> 2,
  77. "JoinID"=> 0,
  78. "SortID"=> $rand->SortID,
  79. "KindID"=> $rand->GameID,
  80. "GameID"=> $rand->GameID,
  81. "OnLineCount"=> 0,
  82. "FullCount"=> 0,
  83. ]
  84. ];
  85. $loginData=$this->LoginIPData($request);
  86. $account=new AccountsInfo();
  87. $userData=$account->newQuery()->where('UserID',$userid)->get()->first()->toArray();
  88. $userData['UserScore']=$account->Score($userid);
  89. $userData['Accounts']=$userData['RegisterMachine'];
  90. $userData['GroupName']=$userData['DynamicPass'];
  91. unset($userData['RegAccounts'],$userData['Compellation'],$userData['InsurePass'],$userData['LogonPass'],$userData['RegisterMachine'],$userData['DynamicPass'],$userData['RegisterDate'],$userData['RegisterIP'],$userData['LastLogonMachine'],$userData['LastLogonDate']);
  92. $loading_rand=random_int(1,3);
  93. $loading_color=["","#153343","#211411","#21171c"][$loading_rand];
  94. $open_acts=[1];
  95. $act_rand=$open_acts[random_int(0,count($open_acts)-1)];
  96. if(!in_array($lang,['pt','es','en'])){
  97. $lang='en';
  98. }
  99. $isDesktop=($request->input('_d','m')=='d');
  100. return view($isDesktop?"game.ouro.br24680land":"game.ouro.br24680",compact('userData','server','loginData','lang','Dollar','clientLang','loading_rand','act_rand','loading_color'));
  101. }
  102. public function logGameClick($gameid,$UserID)
  103. {
  104. LogGamecardClick::recordClick($gameid,$UserID);
  105. }
  106. public function CheckOuroGamePort()
  107. {
  108. return;
  109. $existKey="OuroGamePortChecked";
  110. if(Redis::exists($existKey)){
  111. return;
  112. }
  113. Redis::set($existKey,1);
  114. Redis::expire($existKey,600);
  115. $ouroGameInfos=[];
  116. // echo "http://ouro777:happiplay123@".env('CONFIG_OURO_WSS').":1088/haproxy;up;csv;norefresh";die;
  117. $stats=file_get_contents("http://ouro777:happiplay123@".env('CONFIG_OURO_WSS').":1088/haproxy;up;csv;norefresh");
  118. $stats=explode("\n",$stats);
  119. $stats=array_filter($stats,function($stat){
  120. return strstr($stat,"ws_backend_")&&strstr($stat,",UP")&&!strstr($stat,",BACKEND");
  121. });
  122. $portSort=[];
  123. $stats=array_map(function($stat) use (&$portSort){
  124. $stat=str_replace('ws_backend_','',$stat);
  125. $stat=explode(',',$stat);
  126. $portSort[$stat[0]]=$stat[73];
  127. return [$stat[0],$stat[73]];
  128. },$stats);
  129. // print_r($stats);
  130. // print_r($portSort);die;
  131. $servers=DB::table('QPPlatformDB.dbo.GameRoomInfo')->where("Nullity","0")->get();
  132. foreach ($servers as $server){
  133. $Alive=$server->Alive;
  134. $LocalAddress=$server->LocalAddress;
  135. if(isset($portSort[strval($server->ServerPort)])){
  136. $Alive=1;
  137. $LocalAddress=$portSort[strval($server->ServerPort)];
  138. }else{
  139. $Alive=0;
  140. }
  141. if($Alive==1){
  142. //更新记录
  143. if(!isset($ouroGameInfos[$server->GameID])){
  144. $ouroGameInfos[$server->GameID]=[];
  145. };
  146. $ouroGameInfos[$server->GameID][$server->SortID]=$server->MinEnterScore;
  147. }
  148. // print_r($server);
  149. if($Alive!=$server->Alive||$LocalAddress!=$server->LocalAddress){
  150. DB::table('QPPlatformDB.dbo.GameRoomInfo')->where('ServerID',$server->ServerID)->update(compact('Alive','LocalAddress'));
  151. }
  152. }
  153. GameCard::setOuroGameInfo($ouroGameInfos);
  154. return $ouroGameInfos;
  155. }
  156. public function ModuleStat()
  157. {
  158. try {
  159. $stat = LogGamecardClick::getWeeklyStatsByBrand();
  160. $gameIdsAll = $stat['ALL'];
  161. $orderClause = 'FIELD(id, ' . implode(',', $gameIdsAll) . ')';
  162. $gameIdsAll = GameCard::select('id')->whereIn('id', $gameIdsAll)->orderByRaw($orderClause)->limit(16)->pluck('id')->toArray();
  163. $stat['ALL'] = implode(', ', array_slice($gameIdsAll, 0, 16));
  164. foreach ($stat as $brand => $gameids) {
  165. if (PageModule::where('data_key', $brand . '_top')->exists()) PageModule::where('data_key', $brand . '_top')->update(['game_ids' => $gameids]);
  166. }
  167. if (PageModule::where('data_key', 'hot_game')->exists()) PageModule::where('data_key', 'hot_game')->update(['game_ids' => implode(', ', array_slice($gameIdsAll, 0, 50))]);
  168. $this->CheckOuroGamePort();
  169. dd($stat);
  170. }catch (\Exception $e){
  171. }
  172. }
  173. private function LoginIPData(Request $request){
  174. $PackageName='com.24680.br';
  175. $v = $request->get('v')??0;
  176. $service = new IpCheck();
  177. $list = (new ApiController())->getLoginIpMap($PackageName);
  178. $login_ip = $request->ip();
  179. // $ipcheck=$service->ipCheck($login_ip,$PackageName,$v);
  180. $data = [
  181. 'list' => $list,
  182. 'login_ip' => $login_ip,
  183. 'kefu_switch' => 0,
  184. 'ip_check' => true,
  185. 'ip_black'=>false,
  186. 'base_url'=>'',//多对多跳转
  187. 'chatport'=>8340,
  188. 'loc'=>'br',
  189. 'wss_server'=>'wss://'.env('CONFIG_OURO_WSS').':',
  190. 'org'=>true,
  191. ];
  192. return $data;
  193. }
  194. // 客服功能
  195. public function customer_service()
  196. {
  197. $list=(new ApiController())->getServiceList();
  198. foreach($list as $k=>$v){
  199. if($v->StatusString=="cs@ouro777.com"){
  200. $v->StatusString="cs@24680.com";
  201. }
  202. }
  203. return apiReturnSuc($list);
  204. }
  205. }