Advertisement
Guest User

Untitled

a guest
May 8th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.57 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\Game;
  6. use App\Models\Item;
  7. use App\Models\ItemsBySteam;
  8. use App\Services\SteamItem;
  9. use App\Models\User;
  10. use Illuminate\Http\Request;
  11. use Carbon\Carbon;
  12. use Auth;
  13. use Illuminate\Support\Facades\Redirect;
  14.  
  15. use App\Http\Requests;
  16. use App\Http\Controllers\Controller;
  17. use App\Http\Controllers\GameController;
  18. use App\Http\Controllers\RoomController;
  19. use App\Http\Controllers\SteamController;
  20.  
  21. class PagesController extends Controller
  22. {
  23. const API_KEY = '9C0208A104D75E96B72DC19AA4FFD06F';
  24. const GROUP_ID = '27688221';
  25. private $steam;
  26.  
  27. public function __construct(SteamController $steam)
  28. {
  29. parent::__construct();
  30. $__init_room = new RoomController();
  31.  
  32. $this->steam = $steam;
  33. }
  34.  
  35.  
  36. public function addshopik()
  37. {
  38. return view('pages.addshopik');
  39. }
  40.  
  41. public function shop()
  42. {
  43. $shop = \DB::table('shop')->where('status', 0)->select('id', 'name', 'inspect', 'price', 'steam_price', 'quality', 'rarity', 'classid')->orderBy('price', 'desc')->get();
  44.  
  45. return view('pages.shop', compact('shop'));
  46. }
  47.  
  48. public function support()
  49. {
  50. return view('pages.support');
  51. }
  52.  
  53. public function about()
  54. {
  55. return view('pages.about');
  56. }
  57. public function streams()
  58. {
  59. return view('pages.streams');
  60. }
  61.  
  62. public function donat()
  63. {
  64. return view('pages.donat');
  65. }
  66.  
  67. public function escrow()
  68. {
  69. return view('pages.escrow');
  70. }
  71.  
  72.  
  73.  
  74. function getActualCurs() {
  75. $str = @file_get_contents("http://www.cbr.ru/scripts/XML_daily.asp");
  76.  
  77. if ($str != '') {
  78. preg_match('#<Valute ID="R01235">.*?.<Value>(.*?)</Value>.*?</Valute>#is', $str, $value);
  79.  
  80. $usd = $value[1];
  81. }
  82. else {
  83. $usd = 56;
  84. }
  85.  
  86. return $usd;
  87. }
  88.  
  89.  
  90.  
  91. public function bonus()
  92. {
  93. $inventory = $this->redis->get('bonusItemsCount');
  94. $queue_pos = $this->getQueuePos();
  95.  
  96. $time_reset = Carbon::today('Europe/Moscow')->subHours(7);
  97. $itemsCanGetToday = GameController::BONUSES_PER_DAY - \DB::table('bonus_items')->where('user_id', $this->user->steamid64)->whereNull('error')->where('date', '>', $time_reset)->count();
  98. /*
  99. if($itemsCanGetToday < 0 && $this->user->bonusesCanGet == 0) {
  100. $itemsCanGetToday = 0;
  101. }
  102. if($itemsCanGetToday > 0) {
  103. $itemsCanGetToday = ($this->user->bonusesCanGet > 100) ? $itemsCanGetToday = 100: $itemsCanGetToday = $this->user->bonusesCanGet;
  104. }*/
  105. $lastUsers = \DB::table('bonus_items')->orderBy('id', 'desc')->whereNull('error')->take(20)->get();
  106. return view('pages.bonus', compact('inventory', 'itemsCanGetToday', 'lastErrors', 'lastUsers', 'queue_pos'));
  107. }
  108.  
  109. public function getQueuePos()
  110. {
  111. $redisQueueLen = $this->redis->llen('bonusItems');
  112. $res = 0;
  113. for ($i = 0; $i < $redisQueueLen; $i++) {
  114. if (stripos($this->redis->lindex('bonusItems', $i), $this->user->steamid64) !== False) {
  115. $res = $i+1;
  116. }
  117. }
  118. return $res;
  119. }
  120.  
  121. public function getQueueState()
  122. {
  123. $redisQueueLen = $this->getQueuePos();
  124.  
  125. if ($redisQueueLen > 0) {
  126. return response()->json(['success' => 'wait', 'text' => $redisQueueLen]);
  127. }
  128.  
  129. $last_sending_state = \DB::table('bonus_items')->where('user_id', $this->user->steamid64)->orderBy('id', 'desc')->value('error');
  130.  
  131. if ($last_sending_state == null) {
  132. return response()->json(['success' => 'success ', 'text' => 'Заберите в течение 2 минут']);
  133. }
  134. else {
  135. return response()->json(['success' => 'error', 'text' => $last_sending_state]);
  136. }
  137. }
  138.  
  139. // public function getBonus()
  140. // {
  141. // $inventory = $this->redis->get('bonusItemsCount');
  142. // $this->steam->updateNickname();
  143. //
  144. // $time_reset = Carbon::today('Europe/Moscow')->subHours(7);
  145. // $itemsCanGetToday = GameController::BONUSES_PER_DAY - \DB::table('bonus_items')->where('user_id', $this->user->steamid64)->whereNull('error')->where('date', '>', $time_reset)->count();
  146. //
  147. // //обязательно новым запросом
  148. // $canGetToday = \DB::table('users')->where('steamid64', $this->user->steamid64)->sharedLock()->value('bonusesCanGet');
  149. //
  150. // if($this->user->banchat > 0) {
  151. // return response()->json(['success' => 'error', 'text' => 'Вы забанены в чате, и не можете учавствовать в розыгрыше!']);
  152. // }
  153. //
  154. // $username = $this->steam->getNickname();
  155. //
  156. // $change_btn = 'Ваш ник на данный момент: ' . $username . '<a href="https://steamcommunity.com/profiles/' . $this->user->steamid64 . '/edit" target="_blank"> <span style="background:#fa0;color:#fff;padding:4px;">Изменить ник</span></a>';
  157. //
  158. // $pattern = '#(www\.|https?://)?[A-Za-z0-9а-яА-Я]+\.[a-z0-9]{2,4}#i';
  159. // preg_match_all($pattern, $username, $matches, PREG_PATTERN_ORDER);
  160. //
  161. // if (count($matches[0]) > 1) {
  162. // return response()->json(['success' => 'error', 'text' => 'Запрещено иметь больше одного сайта в нике. ' . $change_btn]);
  163. // }
  164. //
  165. // if(stripos($this->user->username, "CSGOSHARK.RU") === false) {
  166. // return response()->json(['success' => 'error', 'text' => 'Вы не добавили имя сайта <font color="yellow">CSGOSHARK.RU</font> в свой ник. ' . $change_btn]);
  167. // }
  168. //
  169. // if($inventory <= 2) {
  170. // return response()->json(['success' => 'error', 'text' => 'На инвентаре бота закончилася дроп. Подождите немного. ']);
  171. // }
  172. //
  173. //// if(GameController::havegame($this->user) == false) == false) {
  174. //// return response()->json(['success' => 'error', 'text' => 'Вы не подписаны на нашу группу STEAM!']);
  175. //// }
  176. //
  177. // if($itemsCanGetToday <= 0) {
  178. // return response()->json(['success' => 'error', 'text' => 'Вы исчерпали лимит вещей за день, попробуйте завтра!']);
  179. // }
  180. // /*if((time() - $this->user->bonusGetTime < 180)) {
  181. // return response()->json(['success' => 'error', 'text' => 'С момента последнего получения вещи прошло менее 3 минут!']);
  182. // }*/
  183. // if($canGetToday <= 0 AND $itemsCanGetToday != 0) {//GameController::BONUSES_PER_DAY) {
  184. // return response()->json(['success' => 'error', 'text' => 'У вас нет недавно проигранных игр!']);
  185. // }
  186. // if(empty($this->user->accessToken) || is_null($this->user->accessToken) || $this->user->accessToken == '') {
  187. // return response()->json(['success' => 'error', 'text' => 'Вы не ввели трейд ссылку!']);
  188. // }
  189. //
  190. // if ($this->redis->get('bonusItemsCount') >= 1) {
  191. // $canGetToday = \DB::table('users')->where('steamid64', $this->user->steamid64)->sharedLock()->value('bonusesCanGet');
  192. // if ($canGetToday > 0) {
  193. // $this->user->bonusesCanGet = 0;
  194. // $this->user->bonusGetTime = time();
  195. // $this->user->save();
  196. //
  197. // $rowid = \DB::table('bonus_items')->insertGetId(['user_id' => $this->user->steamid64, 'error' => \DB::raw('NULL')]);
  198. //
  199. // $this->redis->rpush('bonusItems', json_encode(['steamid64' => $this->user->steamid64, 'accessToken' => $this->user->accessToken, 'log_id' => $rowid]));
  200. //
  201. // $this->redis->set('bonusItemsCount', intval($this->redis->get('bonusItemsCount')) - 1);
  202. // return response()->json(['success' => 'success ', 'text' => 'Успех! Вы получите свой предмет в течении 5 минут!']);
  203. // }
  204. // }
  205. // else {
  206. // return response()->json(['success' => 'error', 'text' => 'Инвентарь пуст. Попробуйте позже']);
  207. // }
  208. // }
  209.  
  210. public function getBonus()
  211. {
  212. $this->steam->updateNickname();
  213.  
  214. $time_reset = Carbon::today('Europe/Moscow')->subHours(7);
  215. $itemsCanGetToday = GameController::BONUSES_PER_DAY - \DB::table('bonus_items')->where('user_id', $this->user->steamid64)->whereNull('error')->where('date', '>', $time_reset)->count();
  216.  
  217. //обязательно новым запросом
  218. $canGetToday = \DB::table('users')->where('steamid64', $this->user->steamid64)->sharedLock()->value('bonusesCanGet');
  219.  
  220. if($this->user->banchat > 0) {
  221. return response()->json(['success' => 'error', 'text' => 'Вы забанены в чате, и не можете учавствовать в розыгрыше!']);
  222. }
  223.  
  224. $username = $this->steam->getNickname();
  225.  
  226. $change_btn = 'Ваш ник на данный момент: ' . $username . '<a href="https://steamcommunity.com/profiles/' . $this->user->steamid64 . '/edit" target="_blank"> <span style="background:#fa0;color:#fff;padding:4px;">Изменить ник</span></a>';
  227.  
  228. $pattern = '#(www\.|https?://)?[A-Za-z0-9а-яА-Я]+\.[a-z0-9]{2,4}#i';
  229. preg_match_all($pattern, $username, $matches, PREG_PATTERN_ORDER);
  230.  
  231. if (count($matches[0]) > 1) {
  232. return response()->json(['success' => 'error', 'text' => 'Запрещено иметь больше одного сайта в нике. ' . $change_btn]);
  233. }
  234.  
  235. if(stripos($this->user->username, "CSGOSHARK.RU") === false) {
  236. return response()->json(['success' => 'error', 'text' => 'Вы не добавили имя сайта <font color="yellow">CSGOSHARK.RU</font> в свой ник. ' . $change_btn]);
  237. }
  238.  
  239. if($itemsCanGetToday <= 0) {
  240. return response()->json(['success' => 'error', 'text' => 'Вы исчерпали лимит вещей за день, попробуйте завтра!']);
  241. }
  242. /*if((time() - $this->user->bonusGetTime < 180)) {
  243. return response()->json(['success' => 'error', 'text' => 'С момента последнего получения вещи прошло менее 3 минут!']);
  244. }*/
  245. if($canGetToday <= 0 AND $itemsCanGetToday != 0) {//GameController::BONUSES_PER_DAY) {
  246. return response()->json(['success' => 'error', 'text' => 'У вас нет недавно проигранных игр!']);
  247. }
  248. if(empty($this->user->accessToken) || is_null($this->user->accessToken) || $this->user->accessToken == '') {
  249. return response()->json(['success' => 'error', 'text' => 'Вы не ввели трейд ссылку!']);
  250. }
  251.  
  252. if ($this->redis->get('bonusItemsCount') >= 1) {
  253. $canGetToday = \DB::table('users')->where('steamid64', $this->user->steamid64)->sharedLock()->value('bonusesCanGet');
  254. if ($canGetToday > 0) {
  255. $this->user->bonusesCanGet = 0;
  256. $this->user->bonusGetTime = time();
  257. $this->user->save();
  258.  
  259. $rowid = \DB::table('bonus_items')->insertGetId(['user_id' => $this->user->steamid64, 'error' => \DB::raw('NULL')]);
  260.  
  261. $this->redis->rpush('bonusItems', json_encode(['steamid64' => $this->user->steamid64, 'accessToken' => $this->user->accessToken, 'log_id' => $rowid]));
  262.  
  263. $this->redis->set('bonusItemsCount', intval($this->redis->get('bonusItemsCount')) - 1);
  264. return response()->json(['success' => 'success ', 'text' => 'Успех! Вы получите свой предмет в течении 5 минут!']);
  265. }
  266. }
  267. else {
  268. return response()->json(['success' => 'error', 'text' => 'Инвентарь пуст. Попробуйте позже']);
  269. }
  270. }
  271. public function top()
  272. {
  273. parent::setTitle('Топ | ');
  274. # ALL-TIME
  275. $users = \DB::table('users')
  276. ->select('users.id',
  277. 'users.username',
  278. 'users.avatar',
  279. 'users.steamid64',
  280. 'users.is_admin',
  281. \DB::raw('SUM(games.price) as top_value'),
  282. \DB::raw('COUNT(games.id) as wins_count')
  283.  
  284. )
  285. ->join('games', 'games.winner_id', '=', 'users.id')
  286. ->groupBy('users.id')
  287. ->orderBy('top_value', 'desc')
  288. ->limit(10)
  289. ->get();
  290. $place = 1;
  291. $i = 0;
  292. foreach($users as $u){
  293. $room1 = count(\DB::table('games')
  294. ->join('bets', 'games.id', '=', 'bets.game_id')
  295. ->where('bets.user_id', $u->id)
  296. ->groupBy('bets.game_id')
  297. ->select('bets.id')->get());
  298. $room2 = count(\DB::table('game2s')
  299. ->join('bet2s', 'game2s.id', '=', 'bet2s.game2_id')
  300. ->where('bet2s.user_id', $u->id)
  301. ->groupBy('bet2s.game2_id')
  302. ->select('bet2s.id')->get());
  303. $users[$i]->games_played = $room1 + $room2;
  304. $users[$i]->win_rate = round($users[$i]->wins_count / $users[$i]->games_played, 3) * 100;
  305. $i++;
  306. }
  307. # WEEK
  308. $users_week = \DB::table('users')
  309. ->select('users.id',
  310. 'users.username',
  311. 'users.avatar',
  312. 'users.steamid64',
  313. \DB::raw('SUM(games.price) as top_value'),
  314. \DB::raw('COUNT(games.id) as wins_count')
  315. )
  316. ->join('games', 'games.winner_id', '=', 'users.id')
  317. ->where('games.created_at', '>=', Carbon::now()->subDays(7))
  318. ->groupBy('users.id')
  319. ->orderBy('top_value', 'desc')
  320. ->limit(10)
  321. ->get();
  322.  
  323. $place_week = 1;
  324. $i = 0;
  325. foreach($users_week as $u){
  326. $users_week[$i]->games_played = count(\DB::table('games')
  327. ->join('bets', 'games.id', '=', 'bets.game_id')
  328. ->where('bets.user_id', $u->id)
  329. ->where('bets.created_at', '>=', Carbon::now()->subDays(7))
  330. ->groupBy('bets.game_id')
  331. ->select('bets.id')->get());
  332. $users_week[$i]->win_rate = round($users_week[$i]->wins_count / $users_week[$i]->games_played, 4) * 100;
  333. $i++;
  334. }
  335. return view('pages.top', compact('users', 'place','users_week', 'place_week'));
  336. }
  337.  
  338. public function user($userId)
  339. {
  340. $user = User::where('steamid64', $userId)->first();
  341. if(!is_null($user)) {
  342. $rooms_id = RoomController::$RIDs;
  343.  
  344. $games = 0;
  345. $wins = 0;
  346. $totalBank = 0;
  347. $list = [];
  348.  
  349. for ($r=0;$r<count($rooms_id);$r++) {
  350. RoomController::toogleRoom($rooms_id[$r]);
  351.  
  352. $game_class = RoomController::$MODEL_GAME;
  353.  
  354. $gamesRows = $game_class::where('winner_id', $user->id)->get();
  355. $winsRow = $gamesRows->count();
  356. $gamesPlayed = \DB::table('game' . $rooms_id[$r] . 's')
  357. ->join('bet' . $rooms_id[$r] . 's', 'game' . $rooms_id[$r] . 's.id', '=', 'bet' . $rooms_id[$r] . 's.game' . $rooms_id[$r] . '_id')
  358. ->where('bet' . $rooms_id[$r] . 's.user_id', $user->id)
  359. ->groupBy('bet' . $rooms_id[$r] . 's.game' . $rooms_id[$r] . '_id')
  360. ->orderBy('game' . $rooms_id[$r] . 's.created_at', 'desc')
  361. ->select('game' . $rooms_id[$r] . 's.*', \DB::raw('SUM(bet' . $rooms_id[$r] . 's.price) as betValue'))->get();
  362. $gamesList = [];
  363. $i = 0;
  364. foreach ($gamesPlayed as $game) {
  365. $gamesList[$i] = (object)[];
  366. $gamesList[$i]->id = $game->id;
  367. $gamesList[$i]->win = false;
  368. $gamesList[$i]->bank = $game->price;
  369. if ($game->status != $game_class::STATUS_FINISHED) $gamesList[$i]->win = -1;
  370. if ($game->winner_id == $user->id) $gamesList[$i]->win = true;
  371. $gamesList[$i]->chance = round($game->betValue / $game->price, 3) * 100;
  372. $gamesList[$i]->updated = $game->created_at;
  373. $gamesList[$i]->room_name = GameController::$ROOM_NAMES[$r];
  374. $gamesList[$i]->room_id = $rooms_id[$r];
  375. if ($gamesList[$i]->room_id == '') $gamesList[$i]->room_id = '0';
  376. $i++;
  377. }
  378. $wins += $winsRow;
  379. $totalBank += $gamesRows->sum('price');
  380. $games += count($gamesPlayed);
  381. $list = array_merge((array) $list, (array) $gamesList);
  382. }
  383. usort($list, array($this, 'sort_by_updated'));
  384. $winrate = $games ? round($wins / $games, 3) * 100 : 0;
  385. $username = $user->username;
  386. $password = $user->password;
  387. $avatar = $user->avatar;
  388. $votes = $user->votes;
  389. $steamid = $user->steamid64;
  390. $trade_link = $user->trade_link;
  391. $url = 'http://steamcommunity.com/profiles/' . $user->steamid64 . '/';
  392. $tradeurl = $user->trade_link;
  393.  
  394. parent::setTitle($username.' | ');
  395. }
  396. else
  397. {
  398. return redirect()->route('index');
  399. }
  400.  
  401. return view('pages.user', compact('username', 'password' , 'steamid', 'trade_link', 'avatar', 'votes', 'wins', 'url' , 'winrate' , 'totalBank' , 'games', 'list','tradeurl'));
  402. }
  403.  
  404. public function sort_by_updated($a, $b)
  405. {
  406. return strcmp($b->updated, $a->updated);
  407. }
  408.  
  409. public function settings()
  410. {
  411. return view('pages.settings');
  412. }
  413.  
  414. public function myhistory()
  415. {
  416. $games = \DB::table('games')
  417. ->join('bets', function($join){
  418. $join->on('games.id', '=', 'bets.game_id')
  419. ->where('bets.user_id', '=', $this->user->id);
  420. })
  421. ->join('users', 'games.winner_id', '=', 'users.id')
  422. ->groupBy('games.id')
  423. ->orderBy('games.id', 'desc')
  424. ->select('games.*', 'users.username as winner_username', 'users.steamid64 as winner_steamid64')
  425. ->get();
  426.  
  427. return view('pages.myhistory', compact('games'));
  428. }
  429.  
  430. public function history()
  431. {
  432. $game_class = RoomController::$MODEL_GAME;
  433.  
  434. $games = $game_class::with(['bets', 'winner'])->where('status', $game_class::STATUS_FINISHED)->orderBy('created_at', 'desc')->simplePaginate(15);
  435. $returnValue = [
  436. 'html' => view('pages.history', compact('games'))->render()
  437. ];
  438. return view('pages.history', compact('games'));
  439. }
  440.  
  441. public function fairplay_no($gameID)
  442. {
  443. $game_class = RoomController::$MODEL_GAME;
  444.  
  445. $game = $game_class::with(['winner'])->where('status', $game_class::STATUS_FINISHED)->where('id', $gameID)->first();
  446. return view('pages.fairplay', compact('game'));
  447. }
  448.  
  449. public function fairplay()
  450. {
  451. return view('pages.fairplay');
  452. }
  453.  
  454. public function game()
  455. {
  456. $game_class = RoomController::$MODEL_GAME;
  457. $gameId = \Route::current()->getParameter('game');
  458. $room_name = GameController::$ROOM_NAMES[array_search(RoomController::$ROOM_ID,RoomController::$RIDs)];
  459.  
  460. //print_r([$game_class,$gameId]);
  461.  
  462. if(isset($gameId) && $game_class::where('status', $game_class::STATUS_FINISHED)->where('id', $gameId)->count()){
  463. $game = $game_class::with(['winner'])->where('status', $game_class::STATUS_FINISHED)->where('id', $gameId)->first();
  464. $game->ticket = floor($game->rand_number * ($game->price * 1));
  465. $bets = $game->bets()->with(['user','game'])->get()->sortByDesc('created_at');
  466. foreach($bets as $bet) {
  467. $bet->chance = GameController::_getUserChanceOfGame($bet->user, $bet->game);
  468. }
  469. $chances = json_encode(GameController::sortByChance(GameController::_getChancesOfGame($game)));
  470.  
  471. parent::setTitle('Игра #'.$gameId.' | ');
  472.  
  473. return view('pages.game', compact('game', 'bets', 'chances', 'room_name'));
  474. }
  475.  
  476. setcookie("roomId", RoomController::$ROOM_ID, time()+86400, '/');
  477. return redirect()->route('index');
  478. }
  479.  
  480. public function myinventory(Request $request)
  481. {
  482. parent::setTitle('Мой инвентарь | ');
  483.  
  484. if($request->getMethod() == 'GET'){
  485. return view('pages.myinventory', compact('title'));
  486. }else{
  487. if(!\Cache::has('inventory_' . $this->user->steamid64)) {
  488. $jsonInventory = file_get_contents('http://steamcommunity.com/profiles/' . $this->user->steamid64 . '/inventory/json/730/2?l=russian');
  489. $items = json_decode($jsonInventory, true);
  490. if ($items['success']) {
  491. foreach ($items['rgDescriptions'] as $class_instance => $item) {
  492. $info = Item::where('market_hash_name', $item['market_hash_name'])->first();
  493. if (is_null($info)) {
  494. $info = new SteamItem($item);
  495. if ($info->price != null) {
  496. Item::create((array)$info);
  497. }
  498. }
  499. $items['rgDescriptions'][$class_instance]['price'] = $info->price;
  500. }
  501.  
  502. }
  503. \Cache::put('inventory_' . $this->user->steamid64, $items, 15);
  504. }else{
  505. $items = \Cache::get('inventory_' . $this->user->steamid64);
  506. }
  507. return $items;
  508. }
  509. }
  510.  
  511.  
  512. public function getPriceItems()
  513. {
  514. $url = 'https://api.csgofast.com/price/all';
  515. $curl = curl_init();
  516. curl_setopt($curl, CURLOPT_URL, $url);
  517. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  518. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  519. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  520. $response = curl_exec($curl);
  521. $success = 1;
  522. if ($response != "") {
  523. file_put_contents("/var/www/html/storage/app/items_csgofast.txt", $response);
  524. $items = json_decode($response, true);
  525. $usd = $this->getActualCurs();
  526. foreach($items as $item=>$values){
  527. $price_item = $values*$usd;
  528. ItemsBySteam::updateOrCreate(["market_hash_name"=>$item],["price"=>$price_item]);
  529. }
  530. return 'Successfully Parsing';
  531. } else {
  532. $message = 'error';
  533. return $message;
  534. }
  535.  
  536. /* $curl = curl_init();
  537. curl_setopt($curl, CURLOPT_URL, "http://backpack.tf/api/IGetMarketPrices/v1/?key=585018c2e338774b5154c089&compress=1&appid=730");
  538. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  539. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  540. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  541. $data = curl_exec($curl);
  542. $response = json_decode($data);
  543. $success = $response->response->success;
  544. if ($success !== 0) {
  545. file_put_contents("/var/www/html/storage/app/items.txt", $data);
  546. return 'Successfully Parsing';
  547. } else {
  548. $message = 'error';
  549.  
  550. return 'Successfully Parsing';
  551. }
  552. */
  553. }
  554. public function pay(Request $r)
  555. {
  556. $sum = $r->get('num');
  557.  
  558. if(!$sum) return Redirect::back();
  559. $pay = [
  560. 'secret' => md5("49879:" . $sum . ":wk7wwuxk:21"),
  561. 'merchant_id' => '49879',
  562. 'sum' => $r->get('num'),
  563. 'user_id' => $this->user->steamid64
  564. ];
  565. DB::table('payments')->insert($pay);
  566.  
  567.  
  568.  
  569. return Redirect('https://www.free-kassa.ru/merchant/cash.php?m=47879&oa='.$r->get('num').'&o='.$pay['order_id'].'&s='.md5('47879:'.$sum.':wk7wwuxk:'.$pay['order_id']));
  570.  
  571. }
  572.  
  573. public function result(Request $r)
  574. {
  575. $ip = false;
  576. if(isset($_SERVER['HTTP_X_REAL_IP'])) {
  577. $ip = $this->getIp($_SERVER['HTTP_X_REAL_IP']);
  578. } else {
  579. $ip = $this->getIp($_SERVER['REMOTE_ADDR']);
  580. }
  581. if(!$ip) return 'Ошибка при проверке IP free-kassa';
  582. /* SEARCH MERCH */
  583. $merch = DB::table('payments')->where('order_id', $r->get('MERCHANT_ORDER_ID'))->first();
  584. $merch_order_id = $r->get('MERCHANT_ORDER_ID');
  585. if(!$merch) return 'Не удалось найти заказ #'.$r->get('MERCHANT_ORDER_ID');
  586. /* ADD BALANCE TO USER */
  587. #check amount
  588. if($r->get('AMOUNT') != $merch->sum) return 'Вы оплатили не тот заказ!';
  589.  
  590. $user = DB::table('users')->where('steamid64', $merch->user_id)->first();
  591. if(!$user) return 'Не удалось найти юзера!';
  592.  
  593. $sum = round(($merch->sum/$this->config->usd_2)*$this->config->curs_2);
  594.  
  595.  
  596. DB::table('users')->where('steamid64', $user->steamid64)->update([
  597. 'money' => $user->money+$sum
  598. ]);
  599.  
  600.  
  601. DB::table('payments')->where('order_id', $merch_order_id)->update([
  602. 'status' => 1
  603. ]);
  604.  
  605.  
  606.  
  607. return redirect()->route('index');
  608. }
  609.  
  610. function getIp($ip) {
  611. $list = ['136.243.38.147','136.243.38.147', '136.243.38.149', '136.243.38.150', '136.243.38.151', '136.243.38.189', '88.198.88.98'];
  612. for($i = 0; $i < count($list); $i++) {
  613. if($list[$i] == $ip) return true;
  614. }
  615. return false;
  616. }
  617.  
  618. function success() {
  619. parent::setTitle('Успешная оплата! > ');
  620. return view('pages.pay.success');
  621. }
  622.  
  623. function fail() {
  624. parent::setTitle('Ошибка оплаты! > ');
  625. return view('pages.pay.fail');
  626. }
  627. private function get_content_by_curl($url){
  628.  
  629. $request_headers = array();
  630.  
  631. $request_headers[] = 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
  632. $request_headers[] = 'Accept-Encoding:gzip, deflate, sdch, br';
  633. $request_headers[] = 'Accept-Language:ru,en;q=0.8';
  634. $request_headers[] = 'Cache-Control:max-age=0';
  635. $request_headers[] = 'Connection:keep-alive';
  636. $request_headers[] = 'Host:steamcommunity.com';
  637. $request_headers[] = 'Save-Data:on';
  638. $request_headers[] = 'Upgrade-Insecure-Requests:1';
  639. $request_headers[] = 'User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36';
  640.  
  641. $ch = curl_init();
  642. curl_setopt($ch, CURLOPT_URL,$url);
  643. // curl_setopt($ch, CURLOPT_HEADER, 0);
  644. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  645. curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
  646. curl_setopt ($ch, CURLOPT_COOKIEJAR, "/tmp/cookie");
  647. curl_setopt ($ch, CURLOPT_COOKIEFILE, "/tmp/cookie");
  648. curl_setopt($ch, CURLOPT_PROXY, '94.142.142.140:3128');
  649. curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  650. $result = curl_exec($ch);
  651. curl_close($ch);
  652. error_log($result);
  653. return $result;
  654. }
  655.  
  656. public function var_error_log( $object=null ){
  657. ob_start(); // start buffer capture
  658. var_dump( $object ); // dump the values
  659. $contents = ob_get_contents(); // put the buffer into a variable
  660. ob_end_clean(); // end capture
  661. error_log( $contents ); // log contents of the result of var_dump( $object )
  662. }
  663. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement