AtmosferaController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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\Services\OuroGameService;
  7. use App\Game\Services\PlatformService;
  8. use App\Http\helper\NumConfig;
  9. use App\Models\AccountsInfo;
  10. use App\Util;
  11. use App\Utility\SetNXLock;
  12. use Illuminate\Http\Request;
  13. use App\Game\Services\AtmosferaService;
  14. use Illuminate\Routing\Controller;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Redis;
  17. class AtmosferaController extends Controller
  18. {
  19. protected $atmosferaService;
  20. public function __construct(AtmosferaService $atmosferaService)
  21. {
  22. $this->atmosferaService = $atmosferaService;
  23. }
  24. /**
  25. * 获取玩家余额
  26. *
  27. * @param Request $request
  28. * @return \Illuminate\Http\JsonResponse
  29. *
  30. * 请求参数:
  31. * - user_id (string): 玩家ID,必须是先前传递给create_user_ex方法的值
  32. * - merchant_id (integer): 商户ID
  33. * - session_id (string, 可选): 会话ID
  34. *
  35. * 调用示例:
  36. * {
  37. * "user_id": "123654",
  38. * "merchant_id": 1,
  39. * "session_id": "session123"
  40. * }
  41. */
  42. public function getBalance(Request $request)
  43. {
  44. $post = $request->post();
  45. if(!$this->atmosferaService->checkSignature($post)){
  46. return response()->json(['result' => false,'err_code' => 1]);
  47. }
  48. // $data = json_decode($post['data'],true);
  49. $data = $post['data'];
  50. $AccountsInfoModel = new AccountsInfo();
  51. // 用户余额
  52. $score = $AccountsInfoModel->Score($data['user_id']);
  53. $response = ['result' => true,'err_code' => 0,'amount' => $score/100,'currency' => env('CONFIG_24680_CURRENCY')];
  54. return response()->json($response);
  55. }
  56. /**
  57. * 获取玩家账户详情
  58. *
  59. * @param Request $request
  60. * @return \Illuminate\Http\JsonResponse
  61. *
  62. * 请求参数:
  63. * - user_id (string): 玩家ID,必须是先前传递给create_user_ex方法的值
  64. * - merchant_id (integer): 商户ID
  65. * - session_id (string, 可选): 会话ID
  66. *
  67. * 调用示例:
  68. * {
  69. * "user_id": "123654",
  70. * "merchant_id": 1,
  71. * "session_id": "session123"
  72. * }
  73. */
  74. public function getAccountDetails(Request $request)
  75. {
  76. $post = $request->post();
  77. if(!$this->atmosferaService->checkSignature($post)){
  78. return response()->json(['result' => false,'err_code' => 1]);
  79. }
  80. //$data = json_decode($post['data'],true);
  81. $data = $post['data'];
  82. $userInfo = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  83. ->where('UserID', $data['user_id'])
  84. ->first();
  85. if(!$userInfo){
  86. return response()->json(['result' => false,'err_code' => 3]);
  87. }
  88. $response = ['result' => true,'err_code' => 0,'user_name' => $userInfo->NickName];
  89. return response()->json($response);
  90. }
  91. /**
  92. * 提现
  93. *
  94. * @param Request $request
  95. * @return \Illuminate\Http\JsonResponse
  96. *
  97. * 请求参数:
  98. * - user_id (string): 玩家ID,必须是先前传递给create_user_ex方法的值
  99. * - transaction_id (string): 在ATMOSFERA端的唯一事务标识
  100. * - currency (string): 货币ISO代码
  101. * - amount (numeric): 提现金额
  102. * - bonus_amount (numeric): 从玩家的奖金账户中提现的金额
  103. * - game_type (integer): 游戏标识符
  104. * - game_id (string): 游戏回合标识符
  105. * - merchant_id (integer): 商户ID
  106. * - session_id (string, 可选): 会话ID
  107. * - bonus_game (boolean): 如果为true,bonus_amount大于0且amount等于0
  108. * - bet_data (array): 包含下注信息的JSON编码数组
  109. *
  110. * 调用示例:
  111. * {
  112. * "user_id": "123654",
  113. * "transaction_id": "123456_0",
  114. * "currency": "EUR",
  115. * "amount": 0.25,
  116. * "bonus_amount": 0,
  117. * "game_type": 70,
  118. * "game_id": "1234",
  119. * "merchant_id": 1,
  120. * "session_id": "session123",
  121. * "bonus_game": false,
  122. * "bet_data": [
  123. * {"bet_id": 123, "nominal": 0.15, "content": "{\"numbers\":[34],\"pos\":\"34\"}"},
  124. * {"bet_id": 124, "nominal": 0.1, "content": "{\"numbers\":[33],\"pos\":\"33\"}"}
  125. * ]
  126. * }
  127. */
  128. public function withdraw(Request $request)
  129. {
  130. $post = $request->post();
  131. if(!$this->atmosferaService->checkSignature($post)){
  132. return response()->json(['result' => false,'err_code' => 1]);
  133. }
  134. //$data = json_decode($post['data'],true);
  135. $data = $post['data'];
  136. $UserID = $data['user_id'];
  137. // GameCard::$enableStateCheck=false;
  138. // $gamecard=GameCard::where('gid',$post['game_bundle'])->first();
  139. // $in_gameid = OuroGameService::getUserInGame($UserID);
  140. // if(!$gamecard){
  141. // $gamecard="notfind :::: ".$post['game_bundle'];
  142. // Util::WriteLog('24680game', compact('in_gameid', 'gamecard', 'UserID'));
  143. // }else {
  144. //
  145. // if ($in_gameid != intval($gamecard->id)) {
  146. // Util::WriteLog('24680game', compact('in_gameid', 'gamecard', 'UserID'));
  147. //// die;
  148. // }
  149. // }
  150. $res = SetNXLock::getExclusiveLock('bet'.$data['transaction_id'], 86400);
  151. if (!$res) {
  152. Util::WriteLog('atmosfera_bet_error',$data);
  153. return response()->json( ['result' => false,'err_code' => 4]);
  154. }
  155. $AccountsInfoModel = new AccountsInfo();
  156. // 用户余额
  157. $score = intval($AccountsInfoModel->Score($UserID));
  158. $bet = intval($data['amount']*NumConfig::NUM_VALUE);
  159. if($bet>$score){
  160. return response()->json( ['result' => false,'err_code' => 5]);
  161. }
  162. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $UserID)->decrement('Score', $bet);
  163. //用户cancel的时候
  164. Redis::set('bet_amount_'.$data['transaction_id'],$bet);
  165. Redis::expire('bet_amount_'.$data['transaction_id'],120);
  166. PlatformService::platformBet('atmosfera',$data['game_type'],$bet,$UserID);
  167. $response = ['result' => true,'err_code' => 0,'balance' => ($score-$bet)/100,'bonus_balance' => 0,'operation_id' => $data['transaction_id']];
  168. return response()->json($response);
  169. }
  170. /**
  171. * 存款
  172. *
  173. * @param Request $request
  174. * @return \Illuminate\Http\JsonResponse
  175. *
  176. * 请求参数:
  177. * - user_id (string): 玩家ID,必须是先前传递给create_user_ex方法的值
  178. * - transaction_id (string): 在ATMOSFERA端的唯一事务标识
  179. * - currency (string): 货币ISO代码
  180. * - amount (numeric): 存款金额
  181. * - start_operation_id (string): 在withdraw方法中接收到的操作ID
  182. * - game_type (integer): 游戏标识符
  183. * - game_id (string): 游戏回合标识符
  184. * - game_data (string): 包含游戏结果信息的字符串或对象
  185. * - merchant_id (integer): 商户ID
  186. * - session_id (string, 可选): 会话ID
  187. * - bonus_game (boolean): 如果为true,表示奖金游戏
  188. * - bet_data (array): 包含下注信息的JSON编码数组
  189. *
  190. * 调用示例:
  191. * {
  192. * "user_id": "123654",
  193. * "transaction_id": "123457_0",
  194. * "currency": "EUR",
  195. * "amount": 1,
  196. * "start_operation_id": "123",
  197. * "game_type": 70,
  198. * "game_id": "1234",
  199. * "game_data": "{\"balls\":[3],\"cards\":null}",
  200. * "merchant_id": 1,
  201. * "session_id": "session123",
  202. * "bonus_game": false,
  203. * "bet_data": [
  204. * {"bet_id": 123, "win_amount": 1, "jp_amount": 0},
  205. * {"bet_id": 124, "win_amount": 0, "jp_amount": 0}
  206. * ]
  207. * }
  208. */
  209. public function deposit(Request $request)
  210. {
  211. $post = $request->post();
  212. if(!$this->atmosferaService->checkSignature($post)){
  213. return response()->json(['result' => false,'err_code' => 1]);
  214. }
  215. //$data = json_decode($post['data'],true);
  216. $data = $post['data'];
  217. $UserID = $data['user_id'];
  218. $AccountsInfoModel = new AccountsInfo();
  219. // 用户余额
  220. $score = intval($AccountsInfoModel->Score($UserID));
  221. $res = SetNXLock::getExclusiveLock('win_'.$data['transaction_id'], 86400);
  222. if (!$res) {
  223. Util::WriteLog('atmosfera_win_error',$data);
  224. return response()->json(['result' => true,'err_code' => 0,'balance' => ($score)/100,'bonus_balance' => 0,'operation_id' => $data['transaction_id']]);
  225. }
  226. $win = intval($data['amount']*NumConfig::NUM_VALUE);
  227. $betKey = 'bet_amount_'.$data['start_operation_id'];
  228. $bet = Redis::get($betKey)?:0;
  229. if(true){
  230. PlatformService::platformWin($UserID,'atmosfera',$data['game_type'],$win,$bet,$score+$win);
  231. }
  232. Redis::del($betKey);
  233. $response = ['result' => true,'err_code' => 0,'balance' => ($score+$win)/100,'bonus_balance' => 0,'operation_id' => $data['transaction_id']];
  234. return response()->json($response);
  235. }
  236. /**
  237. * 回滚
  238. *
  239. * @param Request $request
  240. * @return \Illuminate\Http\JsonResponse
  241. *
  242. * 请求参数:
  243. * - user_id (string): 玩家ID,必须是先前传递给create_user_ex方法的值
  244. * - transaction_id (string): 需要回滚的提现事务的唯一标识符
  245. * - merchant_id (integer): 商户ID
  246. * - session_id (string, 可选): 会话ID
  247. * - bonus_game (boolean): 如果为true,表示奖金游戏
  248. *
  249. * 调用示例:
  250. * {
  251. * "user_id": "123654",
  252. * "transaction_id": "123457_0",
  253. * "merchant_id": 1,
  254. * "session_id": "session123",
  255. * "bonus_game": false
  256. * }
  257. */
  258. public function rollback(Request $request)
  259. {
  260. $post = $request->post();
  261. if(!$this->atmosferaService->checkSignature($post)){
  262. return response()->json(['result' => false,'err_code' => 1]);
  263. }
  264. //$data = json_decode($post['data'],true);
  265. $data = $post['data'];
  266. $UserID = $data['user_id'];
  267. $AccountsInfoModel = new AccountsInfo();
  268. // 用户余额
  269. $score = intval($AccountsInfoModel->Score($UserID));
  270. $bet=0;
  271. $key='bet_amount_'.$data['transaction_id'];
  272. if(Redis::exists($key)){
  273. $bet=Redis::get($key);
  274. if($bet>0){
  275. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $UserID)->increment('Score', $bet);
  276. PlatformService::platformBet('atmosfera','',-$bet,$UserID);
  277. Redis::del('bet_amount_'.$data['transaction_id']);
  278. }
  279. }
  280. $score+=$bet;
  281. $response = ['result' => true,'err_code' => 0,'balance' => ($score)/100,'bonus_balance' => 0];
  282. return response()->json($response);
  283. }
  284. public function gameList()
  285. {
  286. $response = $this->atmosferaService->getGamesList();
  287. return response()->json($response);
  288. }
  289. public function token(Request $request)
  290. {
  291. $uid=$request->input('uid');
  292. $response = $this->atmosferaService->registerTokenEx($uid,0,'session123');
  293. return response()->json($response);
  294. }
  295. public function checkUser(Request $request)
  296. {
  297. $uid=$request->input('uid');
  298. $response = $this->atmosferaService->checkUserEx($uid);
  299. return response()->json($response);
  300. }
  301. public function gameLunch(Request $request)
  302. {
  303. $gid=$request->input('gid');
  304. $level=$request->input('level',1);
  305. $user = $request->user();
  306. $userid=$user->UserID;
  307. $response = $this->atmosferaService->checkUserEx($userid);
  308. if($response['result'] == false && $response['err_code'] == 20){
  309. $rs = $this->atmosferaService->createUserEx($userid,0);
  310. if($rs['result'] == false && $rs['err_code'] != 21){
  311. echo "<script>alert('system wrong')</script>";
  312. exit();
  313. }
  314. }
  315. $token = $this->atmosferaService->registerTokenEx($userid);
  316. if($token['result'] == false){
  317. echo "<script>alert('system wrong')</script>";
  318. exit();
  319. }
  320. // GameCard::$enableStateCheck=false;
  321. // $gamecard=GameCard::where('gid',$gid)->first();
  322. //
  323. // $in_gameid=OuroGameService::getUserInGame($userid,$user->GlobalUID);
  324. // if($in_gameid!=intval($gamecard->id)){
  325. // Util::WriteLog('24680game',compact('in_gameid','gamecard','user'));
  326. //// die;
  327. // }
  328. $lang=GlobalUserInfo::getLocale();
  329. $clientLang='en';
  330. if($lang=='pt')$clientLang='pt';
  331. else if($lang=='es')$clientLang='pt';
  332. else if($lang=='ru')$clientLang='ru';
  333. else if($lang=='tr')$clientLang='tr';
  334. else $clientLang='en';;
  335. $links = [
  336. 'atmosfera_auto' => 'https://game.atmob2b.net/24680/roulette_auto',
  337. // 'atmosfera_black' => ['https://game.atmob2b.net/24680/blackjack_a','https://game.atmob2b.net/24680/blackjack_b','https://game.atmob2b.net/24680/blackjack_c','https://game.atmob2b.net/24680/blackjack_d','https://game.atmob2b.net/24680/blackjack_e'][random_int(0,4)],
  338. 'atmosfera_black' => 'https://game.atmob2b.net/24680/blackjack_e',
  339. 'atmosfera_black_a' => 'https://game.atmob2b.net/24680/blackjack_a',
  340. 'atmosfera_black_b' => 'https://game.atmob2b.net/24680/blackjack_b',
  341. 'atmosfera_black_c' => 'https://game.atmob2b.net/24680/blackjack_c',
  342. 'atmosfera_black_d' => 'https://game.atmob2b.net/24680/blackjack_d',
  343. 'atmosfera_black_e' => 'https://game.atmob2b.net/24680/blackjack_e',
  344. 'atmosfera_cock' => 'https://game.atmob2b.net/24680/roulette_cocktail',
  345. 'atmosfera_live' => 'https://game.atmob2b.net/24680/roulette_eng',
  346. 'atmosfera_keno' => 'https://game.atmob2b.net/24680/keno',
  347. 'atmosfera_music' => 'https://game.atmob2b.net/24680/musicwheel',
  348. ];
  349. // $links = [
  350. // 'atmosfera_auto' => 'https://game.igramba.com/24680/roulette_auto',
  351. // 'atmosfera_black' => 'https://game.igramba.com/24680/roulette_auto',
  352. // 'atmosfera_cock' => 'https://game.igramba.com/24680/roulette_cocktail',
  353. // 'atmosfera_live' => 'https://game.igramba.com/24680/roulette_eng',
  354. // 'atmosfera_keno' => 'https://game.igramba.com/24680/keno',
  355. // 'atmosfera_music' => 'https://game.igramba.com/24680/musicwheel',
  356. // ];
  357. $url = ($links[$gid]?:'https://game.igramba.com/24680/roulette_auto')."?lang=$clientLang&token={$token['token']}";
  358. echo "<script>
  359. parent.postMessage({cmd:\"closeLoading\"},\"*\");
  360. window.location.href='".$url."';
  361. </script>";
  362. exit();
  363. }
  364. }