PPlayTestController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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\PPlayTestService;
  11. use App\Game\Services\ServerService;
  12. use App\Http\helper\NumConfig;
  13. use App\Models\AccountsInfo;
  14. use App\Util;
  15. use App\Utility\SetNXLock;
  16. use GuzzleHttp\Client;
  17. use GuzzleHttp\Exception\RequestException;
  18. use Illuminate\Http\Request;
  19. use Illuminate\Routing\Controller;
  20. use Illuminate\Support\Facades\DB;
  21. use Illuminate\Support\Facades\Redis;
  22. class PPlayTestController extends Controller
  23. {
  24. protected $ppSoftService;
  25. protected $currency='BRL';
  26. public function __construct(PPlayTestService $ppSoftService)
  27. {
  28. $this->ppSoftService = $ppSoftService;
  29. $this->currency=env('CONFIG_24680_CURRENCY',$this->currency);
  30. }
  31. public function backLobby()
  32. {
  33. echo "<script>
  34. parent.postMessage({cmd:\"back\"},\"*\");
  35. </script>";
  36. }
  37. public function gameLunch(Request $request)
  38. {
  39. $gid=$request->input('gid');
  40. $user = $request->user();
  41. $userid=$user->UserID;
  42. GameCard::$enableStateCheck=false;
  43. $gamecard=GameCard::where('gid',$gid)->first();
  44. $in_gameid=OuroGameService::getUserInGame($userid,$user->GlobalUID);
  45. if($in_gameid!=intval($gamecard->id)){
  46. Util::WriteLog('24680game',compact('in_gameid','gamecard','user'));
  47. // die;
  48. }
  49. $lang=GlobalUserInfo::getLocale();
  50. $supportLang = ['en','da','de','es','fi','fr','id','it','ja','ko','nl','no','pl','pt','ro','ru','sv','th','tr','vi','zh','my'];
  51. if(!in_array($lang,$supportLang)){
  52. $lang = 'en';
  53. }
  54. $rs = $this->ppSoftService->getLaunchURL($gid,$user->GlobalUID,$user->UserID,$this->currency,$lang);
  55. if(@$rs['gameURL']){
  56. $gamecard=GameCard::where('gid',$gid)->where('brand','PP')->first();
  57. $gamecard->increment('play_num',1);
  58. //$this->logGameClick($gamecard->id,$userid);
  59. LogGamecardClick::recordClick($gamecard->id,$userid);
  60. echo "<script>
  61. parent.postMessage({cmd:\"closeLoading\"},\"*\");
  62. window.location.href='".$rs['gameURL']."';
  63. </script>";
  64. exit();
  65. }else{
  66. echo "<script>alert('system wrong')</script>";
  67. exit();
  68. }
  69. }
  70. public function gameLogin(Request $request)
  71. {
  72. $gid = $request->input('gid','vs20olympx');
  73. $guid = $request->input('guid','0685128230-b53b-eb1a-0004688302');
  74. $uid = $request->input('uid','4688302');
  75. $lang=GlobalUserInfo::getLocale();
  76. $supportLang = ['en','da','de','es','fi','fr','id','it','ja','ko','nl','no','pl','pt','ro','ru','sv','th','tr','vi','zh','my'];
  77. if(!in_array($lang,$supportLang)){
  78. $lang = 'en';
  79. }
  80. $rs = $this->ppSoftService->getLaunchURL($gid,$guid,$uid,$this->currency,$lang);
  81. echo "<script>
  82. window.location.href='".$rs['gameURL']."';
  83. </script>";
  84. // var_dump($rs);
  85. }
  86. public function gameList()
  87. {
  88. $response = $this->ppSoftService->getCasinoGames();
  89. $gameList = $response['gameList'];
  90. foreach ($gameList as &$game) {
  91. unset($game['jurisdictions']);
  92. }
  93. return response()->json($gameList);
  94. }
  95. public function gameLobbyList()
  96. {
  97. $response = $this->ppSoftService->getLobbyGames();
  98. return response()->json($response);
  99. }
  100. public function authenticate(Request $request){
  101. $post = $request->all();
  102. Util::WriteLog('pp_authenticate',$post);
  103. if(!$this->ppSoftService->checkHash($post)){
  104. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  105. }
  106. $token = $post['token'];
  107. $user = GlobalUserInfo::getGameUserInfo('GlobalUID', $token);
  108. if (!$user) return response()->json(['error' => 2,'description' => 'Player not found ']);
  109. $response = [
  110. 'userId' => $user->UserID,
  111. 'currency' => $this->currency,
  112. 'cash' => GlobalUserInfo::getScoreByUserID($user->UserID),
  113. 'bonus' => 0,
  114. 'error' => 0,
  115. 'description' => 'Success'
  116. ];
  117. return response()->json($response);
  118. }
  119. public function balance(Request $request)
  120. {
  121. $post = $request->all();
  122. Util::WriteLog('pp_balance',$post);
  123. if(!$this->ppSoftService->checkHash($post)){
  124. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  125. }
  126. $response = [
  127. 'currency' => $this->currency,
  128. 'cash' => GlobalUserInfo::getScoreByUserID($post['userId']),
  129. 'bonus' => 0,
  130. 'error' => 0,
  131. 'description' => 'Success'
  132. ];
  133. return response()->json($response);
  134. }
  135. public function bet(Request $request)
  136. {
  137. $post = $request->all();
  138. Util::WriteLog('pp_bet',$post);
  139. if(!$this->ppSoftService->checkHash($post)){
  140. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  141. }
  142. $UserID = $post['userId'];
  143. $transactionId = $post['reference'];
  144. $score = GlobalUserInfo::getScoreByUserID($UserID);
  145. $res = SetNXLock::getExclusiveLock('pp_bet'.$transactionId, 600);
  146. if (!$res) {
  147. Util::WriteLog('pp_bet_repeat',$post);
  148. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' => $score,'bonus' => 0,'usedPromo' => 0,'error' => 0,'description' => 'Success'];
  149. }
  150. if(round($post['amount'],2)>round($score,2)){
  151. return response()->json(['error' => 1,'description' => 'Insufficient balance']);
  152. }
  153. $bet = intval($post['amount']*100);
  154. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $UserID)->decrement('Score', $bet);
  155. PlatformService::platformBet('PP',$post['gameId'],$bet,$UserID);
  156. $betKey = 'pp_bet_amount_'.$transactionId;
  157. Redis::set($betKey,$bet);
  158. Redis::expire($betKey,600);
  159. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' =>round($score-$post['amount'],2),'bonus' => 0,'usedPromo' => 0,'error' => 0,'description' => 'Success'];
  160. }
  161. public function result(Request $request)
  162. {
  163. $post = $request->all();
  164. Util::WriteLog('pp_result',$post);
  165. if(!$this->ppSoftService->checkHash($post)){
  166. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  167. }
  168. $UserID = $post['userId'];
  169. $transactionId = $post['reference'];
  170. $score = GlobalUserInfo::getScoreByUserID($UserID);
  171. $res = SetNXLock::getExclusiveLock('pp_result'.$transactionId, 600);
  172. if (!$res) {
  173. Util::WriteLog('pp_win_repeat',$post);
  174. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' => $score,'bonus' => 0,'error' => 0,'description' => 'Success'];
  175. }
  176. $betKey = 'pp_bet_amount_'.$transactionId;
  177. $bet = Redis::get($betKey)?:0;
  178. Redis::del($betKey);
  179. $win = $post['amount'];
  180. if(isset($post['promoWinAmount'])){
  181. if($post['promoWinAmount']>0){
  182. $win = round($post['promoWinAmount']+$post['amount'],2);
  183. }
  184. }
  185. PlatformService::platformWin($UserID,'PP',$post['gameId'],intval($win*100),$bet,intval($score+$win)*100);
  186. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' =>round($score+$win,2),'bonus' => 0,'error' => 0,'description' => 'Success'];
  187. }
  188. public function bonusWin(Request $request)
  189. {
  190. $post = $request->all();
  191. Util::WriteLog('pp_bonusWin',$post);
  192. if(!$this->ppSoftService->checkHash($post)){
  193. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  194. }
  195. $UserID = $post['userId'];
  196. $transactionId = $post['reference'];
  197. $score = GlobalUserInfo::getScoreByUserID($UserID);
  198. // $res = SetNXLock::getExclusiveLock('pp_bonusWin'.$transactionId, 600);
  199. // if (!$res) {
  200. // Util::WriteLog('pp_bonusWin_repeat',$post);
  201. // return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' => $score,'bonus' => 0,'error' => 0,'description' => 'Success'];
  202. // }
  203. //
  204. // PlatformService::platformWin($UserID,'PP','bonusWin',intval($post['amount']*100),0,intval($score+$post['amount'])*100);
  205. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' =>round($score,2),'bonus' => 0,'error' => 0,'description' => 'Success'];
  206. }
  207. public function jackpotWin(Request $request)
  208. {
  209. $post = $request->all();
  210. Util::WriteLog('pp_jackpotWin',$post);
  211. if(!$this->ppSoftService->checkHash($post)){
  212. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  213. }
  214. $UserID = $post['userId'];
  215. $transactionId = $post['reference'];
  216. $score = GlobalUserInfo::getScoreByUserID($UserID);
  217. $res = SetNXLock::getExclusiveLock('pp_jackpotWin'.$transactionId, 600);
  218. if (!$res) {
  219. Util::WriteLog('pp_jackpotWin_repeat',$post);
  220. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' => $score,'bonus' => 0,'error' => 0,'description' => 'Success'];
  221. }
  222. PlatformService::platformWin($UserID,'PP',@$post['gameId'],intval($post['amount']*100),0,intval($score+$post['amount'])*100);
  223. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' =>round($score+$post['amount'],2),'bonus' => 0,'error' => 0,'description' => 'Success'];
  224. }
  225. public function refund(Request $request)
  226. {
  227. $post = $request->all();
  228. Util::WriteLog('pp_refund',$post);
  229. if(!$this->ppSoftService->checkHash($post)){
  230. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  231. }
  232. $transactionId = $post['reference'];
  233. $UserID = $post['userId'];
  234. $betKey = 'pp_bet_amount_'.$transactionId;
  235. $bet = Redis::get($betKey)?:0;
  236. if($bet){
  237. Redis::del($betKey);
  238. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $UserID)->increment('Score', $bet);
  239. }
  240. return ['transactionId' => $transactionId,'error' => 0,'description' => 'Success'];
  241. }
  242. public function promoWin(Request $request)
  243. {
  244. $post = $request->all();
  245. Util::WriteLog('pp_promoWin',$post);
  246. if(!$this->ppSoftService->checkHash($post)){
  247. return response()->json(['error' => 5,'description' => 'Invalid hash code']);
  248. }
  249. $UserID = $post['userId'];
  250. $transactionId = $post['reference'];
  251. $score = GlobalUserInfo::getScoreByUserID($UserID);
  252. $res = SetNXLock::getExclusiveLock('pp_promoWin'.$transactionId, 600);
  253. if (!$res) {
  254. Util::WriteLog('pp_promoWin_repeat',$post);
  255. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' => $score,'bonus' => 0,'error' => 0,'description' => 'Success'];
  256. }
  257. PlatformService::platformWin($UserID,'PP',@$post['gameId'],intval($post['amount']*NumConfig::NUM_VALUE),0,intval($score+$post['amount'])*NumConfig::NUM_VALUE);
  258. return ['transactionId' => $transactionId,'currency' => $this->currency,'cash' =>round($score+$post['amount'],2),'bonus' => 0,'error' => 0,'description' => 'Success'];
  259. }
  260. }