PPlayController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\Facade\TableName;
  4. use App\Game\GameCard;
  5. use App\Game\GlobalUserInfo;
  6. use App\Game\LogGamecardClick;
  7. use App\Game\Services\OuroGameService;
  8. use App\Game\Services\PgSoftService;
  9. use App\Game\Services\PlatformService;
  10. use App\Game\Services\PPlayService;
  11. use App\Game\Services\ServerService;
  12. use App\Http\helper\NumConfig;
  13. use App\Models\AccountsInfo;
  14. use App\Notification\TelegramBot;
  15. use App\Util;
  16. use App\Utility\SetNXLock;
  17. use GuzzleHttp\Client;
  18. use GuzzleHttp\Exception\RequestException;
  19. use Illuminate\Http\Request;
  20. use Illuminate\Routing\Controller;
  21. use Illuminate\Support\Facades\DB;
  22. use Illuminate\Support\Facades\Redis;
  23. class PPlayController extends Controller
  24. {
  25. protected $ppSoftService;
  26. protected $client;
  27. protected $currency='BRL';
  28. public function __construct(PPlayService $ppSoftService)
  29. {
  30. $this->ppSoftService = $ppSoftService;
  31. $this->client = new Client();
  32. $this->currency=env('CONFIG_24680_CURRENCY',$this->currency);
  33. }
  34. private function handleRequestException(\Exception $e)
  35. {
  36. TelegramBot::getDefault()->sendMsgWithEnv($e->getMessage().$e->getTraceAsString());
  37. }
  38. private function callSubApi($ext_player_id,$request)
  39. {
  40. $apiurl=ServerService::GetApiByGUID($ext_player_id);
  41. try {
  42. // 获取当前请求的 GET 和 POST 数据
  43. // $getData = $request->query(); // 获取 GET 数据
  44. $postData = $request->post(); // 获取 POST 数据
  45. $response = $this->client->post( $apiurl . $_SERVER['REQUEST_URI'], [
  46. 'verify'=>false,
  47. // 'query' => $getData, // 传递 GET 数据
  48. 'form_params' => $postData, // 传递 POST 数据
  49. ]);
  50. $res=json_decode($response->getBody(),true);
  51. Util::WriteLog('pgsub',$res);
  52. return $res;
  53. } catch (RequestException $e) {
  54. return $this->handleRequestException($e);
  55. }
  56. }
  57. public function backLobby()
  58. {
  59. echo "<script>
  60. parent.postMessage({cmd:\"back\"},\"*\");
  61. </script>";
  62. }
  63. public function gameLunch(Request $request)
  64. {
  65. $gid=$request->input('gid');
  66. $user = $request->user();
  67. $userid=$user->UserID;
  68. if($user->Channel!=99){
  69. http_response_code(404);
  70. exit();
  71. }
  72. GameCard::$enableStateCheck=false;
  73. $gamecard=GameCard::where('gid',$gid)->first();
  74. $in_gameid=OuroGameService::getUserInGame($userid,$user->GlobalUID);
  75. if($in_gameid!=intval($gamecard->id)){
  76. Util::WriteLog('24680game',compact('in_gameid','gamecard','user'));
  77. // die;
  78. }
  79. $lang=GlobalUserInfo::getLocale();
  80. $supportLang = ['en','da','de','es','fi','fr','id','it','ja','ko','nl','no','pl','pt','ro','ru','sv','th','tr','vi','zh','my'];
  81. if(!in_array($lang,$supportLang)){
  82. $lang = 'en';
  83. }
  84. $rs = $this->ppSoftService->getLaunchURL($gid,$user->GlobalUID,$user->GlobalUID,$this->currency,$lang);
  85. if(@$rs['gameURL']){
  86. $gamecard=GameCard::where('gid',$gid)->where('brand','PP')->first();
  87. $gamecard->increment('play_num',1);
  88. //$this->logGameClick($gamecard->id,$userid);
  89. LogGamecardClick::recordClick($gamecard->id,$userid);
  90. echo "<script>
  91. parent.postMessage({cmd:\"closeLoading\"},\"*\");
  92. window.location.href='".$rs['gameURL']."';
  93. </script>";
  94. exit();
  95. }else{
  96. echo "<script>alert('system wrong')</script>";
  97. exit();
  98. }
  99. }
  100. public function gameLogin(Request $request)
  101. {
  102. $gid = $request->input('gid','vs20olympx');
  103. $guid = $request->input('guid','0685128230-b53b-eb1a-0004688302');
  104. $uid = $request->input('uid','4688302');
  105. $lang=GlobalUserInfo::getLocale();
  106. $supportLang = ['en','da','de','es','fi','fr','id','it','ja','ko','nl','no','pl','pt','ro','ru','sv','th','tr','vi','zh','my'];
  107. if(!in_array($lang,$supportLang)){
  108. $lang = 'en';
  109. }
  110. $rs = $this->ppSoftService->getLaunchURL($gid,$guid,$guid,$this->currency,$lang);
  111. echo "<script>
  112. window.location.href='".$rs['gameURL']."';
  113. </script>";
  114. // var_dump($rs);
  115. }
  116. public function gameList()
  117. {
  118. $response = $this->ppSoftService->getCasinoGames();
  119. $gameList = $response['gameList'];
  120. foreach ($gameList as &$game) {
  121. unset($game['jurisdictions']);
  122. }
  123. return response()->json($gameList);
  124. }
  125. public function gameLobbyList()
  126. {
  127. $response = $this->ppSoftService->getLobbyGames();
  128. return response()->json($response);
  129. }
  130. public function authenticate(Request $request){
  131. $post = $request->all();
  132. Util::WriteLog('pp_authenticate',$post);
  133. if(!$this->ppSoftService->checkHash($post)){
  134. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  135. }
  136. $token = $post['token'];
  137. if(!ServerService::IsLocalUser($token)) {
  138. return $this->callSubApi($token,$request);
  139. }
  140. $user = GlobalUserInfo::getGameUserInfo('GlobalUID', $token);
  141. if (!$user) return response()->json(['error' => 2,'description' => 'Player not found ']);
  142. $response = [
  143. 'userId' => $token,//$user->UserID,
  144. 'currency' => $this->currency,
  145. 'cash' => GlobalUserInfo::getScoreByUserID($user->UserID),
  146. 'bonus' => 0,
  147. 'error' => 0,
  148. 'description' => 'Success'
  149. ];
  150. return response()->json($response);
  151. }
  152. public function balance(Request $request)
  153. {
  154. $post = $request->all();
  155. if(!ServerService::IsLocalUser($post['userId'])) {
  156. return $this->callSubApi($post['userId'],$request);
  157. }
  158. $UserID=ServerService::GlobalToUserID($post['userId']);
  159. Util::WriteLog('pp_balance',$post);
  160. if(!$this->ppSoftService->checkHash($post)){
  161. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  162. }
  163. $response = [
  164. 'currency' => $this->currency,
  165. 'cash' => GlobalUserInfo::getScoreByUserID($UserID),
  166. 'bonus' => 0,
  167. 'error' => 0,
  168. 'description' => 'Success'
  169. ];
  170. return response()->json($response);
  171. }
  172. public function bet(Request $request)
  173. {
  174. $post = $request->all();
  175. if(!ServerService::IsLocalUser($post['userId'])) {
  176. return $this->callSubApi($post['userId'],$request);
  177. }
  178. $UserID=ServerService::GlobalToUserID($post['userId']);
  179. Util::WriteLog('pp_bet',$post);
  180. if(!$this->ppSoftService->checkHash($post)){
  181. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  182. }
  183. $transactionId = $post['reference'];
  184. $score = GlobalUserInfo::getScoreByUserID($UserID);
  185. $res = SetNXLock::getExclusiveLock('pp_bet'.$transactionId, 600);
  186. if (!$res) {
  187. Util::WriteLog('pp_bet_repeat',$post);
  188. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' => $score,'bonus' => 0,'usedPromo' => 0,'error' => 0,'description' => 'Success'];
  189. }
  190. if(round($post['amount'],2)>round($score,2)){
  191. return response()->json(['error' => 1,'description' => 'Insufficient balance']);
  192. }
  193. $bet = intval($post['amount']*NumConfig::NUM_VALUE);
  194. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $UserID)->decrement('Score', $bet);
  195. PlatformService::platformBet('pp',$post['gameId'],$bet,$UserID);
  196. $betKey = 'pp_bet_amount_'.$transactionId;
  197. Redis::set($betKey,$bet);
  198. Redis::expire($betKey,600);
  199. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' =>round($score-$post['amount'],2),'bonus' => 0,'usedPromo' => 0,'error' => 0,'description' => 'Success'];
  200. }
  201. public function result(Request $request)
  202. {
  203. $post = $request->all();
  204. if(!ServerService::IsLocalUser($post['userId'])) {
  205. return $this->callSubApi($post['userId'],$request);
  206. }
  207. $UserID=ServerService::GlobalToUserID($post['userId']);
  208. Util::WriteLog('pp_result',$post);
  209. if(!$this->ppSoftService->checkHash($post)){
  210. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  211. }
  212. $transactionId = $post['reference'];
  213. $score = GlobalUserInfo::getScoreByUserID($UserID);
  214. $res = SetNXLock::getExclusiveLock('pp_result'.$transactionId, 600);
  215. if (!$res) {
  216. Util::WriteLog('pp_win_repeat',$post);
  217. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' => $score,'bonus' => 0,'error' => 0,'description' => 'Success'];
  218. }
  219. $betKey = 'pp_bet_amount_'.$transactionId;
  220. $bet = Redis::get($betKey)?:0;
  221. Redis::del($betKey);
  222. $win = $post['amount'];
  223. if(isset($post['promoWinAmount'])){
  224. if($post['promoWinAmount']>0){
  225. $win = round($post['promoWinAmount']+$post['amount'],2);
  226. }
  227. }
  228. PlatformService::platformWin($UserID,'pp',$post['gameId'],intval($win*NumConfig::NUM_VALUE),$bet,intval($score+$win)*NumConfig::NUM_VALUE);
  229. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' =>round($score+$win,2),'bonus' => 0,'error' => 0,'description' => 'Success'];
  230. }
  231. public function bonusWin(Request $request)
  232. {
  233. $post = $request->all();
  234. if(!ServerService::IsLocalUser($post['userId'])) {
  235. return $this->callSubApi($post['userId'],$request);
  236. }
  237. $UserID=ServerService::GlobalToUserID($post['userId']);
  238. Util::WriteLog('pp_bonusWin',$post);
  239. if(!$this->ppSoftService->checkHash($post)){
  240. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  241. }
  242. $transactionId = $post['reference'];
  243. $score = GlobalUserInfo::getScoreByUserID($UserID);
  244. // $res = SetNXLock::getExclusiveLock('pp_bonusWin'.$transactionId, 600);
  245. // if (!$res) {
  246. // Util::WriteLog('pp_bonusWin_repeat',$post);
  247. // return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' => $score,'bonus' => 0,'error' => 0,'description' => 'Success'];
  248. // }
  249. //
  250. // PlatformService::platformWin($UserID,'pp','bonusWin',intval($post['amount']*NumConfig::NUM_VALUE),0,intval($score+$post['amount'])*NumConfig::NUM_VALUE);
  251. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' =>round($score,2),'bonus' => 0,'error' => 0,'description' => 'Success'];
  252. }
  253. public function jackpotWin(Request $request)
  254. {
  255. $post = $request->all();
  256. if(!ServerService::IsLocalUser($post['userId'])) {
  257. return $this->callSubApi($post['userId'],$request);
  258. }
  259. $UserID=ServerService::GlobalToUserID($post['userId']);
  260. Util::WriteLog('pp_jackpotWin',$post);
  261. if(!$this->ppSoftService->checkHash($post)){
  262. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  263. }
  264. $transactionId = $post['reference'];
  265. $score = GlobalUserInfo::getScoreByUserID($UserID);
  266. $res = SetNXLock::getExclusiveLock('pp_jackpotWin'.$transactionId, 600);
  267. if (!$res) {
  268. Util::WriteLog('pp_jackpotWin_repeat',$post);
  269. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' => $score,'bonus' => 0,'error' => 0,'description' => 'Success'];
  270. }
  271. PlatformService::platformWin($UserID,'pp',@$post['gameId'],intval($post['amount']*NumConfig::NUM_VALUE),0,intval($score+$post['amount'])*NumConfig::NUM_VALUE);
  272. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' =>round($score+$post['amount'],2),'bonus' => 0,'error' => 0,'description' => 'Success'];
  273. }
  274. public function refund(Request $request)
  275. {
  276. $post = $request->all();
  277. if(!ServerService::IsLocalUser($post['userId'])) {
  278. return $this->callSubApi($post['userId'],$request);
  279. }
  280. $UserID=ServerService::GlobalToUserID($post['userId']);
  281. Util::WriteLog('pp_refund',$post);
  282. if(!$this->ppSoftService->checkHash($post)){
  283. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  284. }
  285. $transactionId = $post['reference'];
  286. $betKey = 'pp_bet_amount_'.$transactionId;
  287. $bet = Redis::get($betKey)?:0;
  288. if($bet){
  289. Redis::del($betKey);
  290. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $UserID)->increment('Score', $bet);
  291. }
  292. return ['transactionId' => $transactionId,'error' => 0,'description' => 'Success'];
  293. }
  294. public function promoWin(Request $request)
  295. {
  296. $post = $request->all();
  297. if(!ServerService::IsLocalUser($post['userId'])) {
  298. return $this->callSubApi($post['userId'],$request);
  299. }
  300. $UserID=ServerService::GlobalToUserID($post['userId']);
  301. Util::WriteLog('pp_promoWin',$post);
  302. if(!$this->ppSoftService->checkHash($post)){
  303. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  304. }
  305. $transactionId = $post['reference'];
  306. $score = GlobalUserInfo::getScoreByUserID($UserID);
  307. $res = SetNXLock::getExclusiveLock('pp_promoWin'.$transactionId, 600);
  308. if (!$res) {
  309. Util::WriteLog('pp_promoWin_repeat',$post);
  310. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' => $score,'bonus' => 0,'error' => 0,'description' => 'Success'];
  311. }
  312. PlatformService::platformWin($UserID,'pp',@$post['gameId'],intval($post['amount']*NumConfig::NUM_VALUE),0,intval($score+$post['amount'])*NumConfig::NUM_VALUE);
  313. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' =>round($score+$post['amount'],2),'bonus' => 0,'error' => 0,'description' => 'Success'];
  314. }
  315. }