· 9 years ago · Jan 30, 2017, 11:40 PM
1<?php
2
3namespace App\Http\Controllers;
4use App\WinnerTicket;
5use App\Bet;
6use App\Game;
7use App\Bonus;
8use DB;
9use App\Item;
10use App\Services\SteamItem;
11use App\Ticket;
12use App\User;
13use Carbon\Carbon;
14use Illuminate\Http\Request;
15use Illuminate\Database\Eloquent\Model;
16use App\Http\Requests;
17use App\Http\Controllers\Controller;
18
19class GameController extends Controller
20{
21 const GDonate2keypublic = '88908-777';
22 const GDonate2key = '0005843219cf576b540d94bcb6222967';
23 const FILTERS = '(CSGO-BEST|CRAZY-BETS|kickback|ez-win|itemup|CSGORAND|LUCKYDROP|CSGOEASYSKIN|EASYSKIN|csgetto|CSGOBIX|CSGOWOW|csgoup|csgofast|csgolucky|csgo777|csgocasino|game-luck|g2a|csgostar|hellstore|cs-drop|csgo|csgoshuffle|csgotop|csbets|csgobest|csgolike|fast-jackpot|skins-up|hardluck-shop|csgogamble|csgohot|csgofairplay|csgohappy|csgomet|csgohunter|csgoluxe|csgostart|csgo-online|csgottzed|csgotrick|csgorage|csplayer|csgo-chance|csgoswag|csgopvp|mycsarena|csgostars|ezyskins|csbets|csgo-skin-raffle|exgame|csgo4bet|csgo-luxe|csgowinner|csgo-wtf|csgo-asiimov|treasuretoken|ezskinz|csgofresh|csgotrophy|csgogold|csgomagic|catskins|lucky-hand|csgorand|csgobig|csgoduck|csgoammo|csgoway|skins-pro|hard-lucky|csgo-rich|csgoeasy|game-raffle|uitems|csgo-easy|crazy-random|csgo-raffle|csgo-ezpz|csgorumble|lucky-hand|csgonice|csgodraw|csgopick|csgoninja|csgo-winner|csrandom|csgomany|csgolotter|csgokill|ezpzskins|csgofb|csgo1|csgojackpot|kinguin|reall-csgo|csgofart|csgoline|csgoprime|csgolt|onlycs|csgoblaze|dropcsgo-ezz|csgobetes|csmonkey|d2fortune|csgoforce|csgobig|csgovulcan|dota2house|ezitems|csgofox|csgo-ez|csgohs|csgobp|csgovictory|csgo-farm|csgo-lottery|csgo777|csgobank|timeluck|easydrop|csgogift|hardlucky|CSGOSWIFT|skinbets|CSGO-SHOT|CSLOTS|BEELOTERY|CSGOBR|CSGOFAIRPLAY|CSGO-ES|DropSmurf|csgo|CSGOSKINZ|CSGODROPZ|CSGOTROPHY|SkinProfit|UPSKINS|CSGO-PLATINUM|CSGORaffling|csgod|CSGO-JACKPOT|csgo-deposit|easy-skins|ezskinz|CSGOENJOY|CSGOcraft|godrop|JackBets|TopRuletka|CSGOFakeBet|CSGOSELLER|CS-TICKET|csgo-winner|CSGOJUST|CSGOCoin|csgoselector|CSGOFLY|CSGOHAP|GODROP|CSLOTTERY|itemgrad|CSGOIN|csgohouse|csgo-dog|csgobets|CShot|RULETKACSGO|D2DELECTOR|CSGOHyper|CSGOLUX|GODROP|CSGO-MANIA|ezpzskinz|CSGOEX|evil-bets|CSGOWAR|lootbox|onbeast|CSGONOW|crimson|CSGOFORCE|CSGOI3I|CSGOBET|CSGO4FUN|CSGOQUALITY|CSGO-DROPS|EZYGAME|CSGOBLESS|D2SELECTOR|SkinoDro4|FLASHSKINS|CSGO-FIRE|csgocloud|CSGOPEAK|CSGAMBLING|csgoing|royalpot|CSGOSKINSWAR|twitch|CSGOEZY|superskins|BOOMLOTERY|CSGOFORS|MLGBets|csprize|csgoonly|CSGOFORS|flashinew|FUNGUN|csgoexpress|CSGOLDEN|CSGO-HOPE|CSGOHF|CSGO-FARMING|CSGO-SHOT|CSGOEVENT|CSGOlite|SkinsFast|CSGOEASYSKIN|CSGO-JAKPOT|CSGOPOOR|CSGOGAMBLING|CSGO-FACTORY|CSGOLOW|FASTPLAY|csgogalaxy|CSGOHELL|CSGO-BLACK|csbattle|CsgoDesert|CSGOROLLER|CSGO-VIP|CSGOJOKER|HELLBETS|csgofort|CSGO-FATE|csgofresh|OVERSKIN|CS-LOVING|csgo-speed|CSGOENERGY|CSGOWONDER|jointime|CSGOGAMES|CSGODAY|FIRESKINS|tradeigr|CSGOBRAWL|CSGOFOCUS|csgo|Rus-roulette|skinhunt|FIRSTCASE|CSGORiot|csgofarming|CSPOT|Hell-Drop|CSBULLET|CSGOMASTER|CSGOUP|ezsking|agro-bets|CSGORUN|CSPL|GOGUN|GUN|FUCKSKINS|CSGOBANG|USKINS|CSGO-BILLY|CS-SHOTS|CSGOCASE|CSGOSKINS|CSGOEZBET|CSGOFunPot|lucky-cowboy|csgoRamboPot|csgo1337|csgoforwin|SKINSFARM|SGO-HOPE|moneday|CSGОSÐUFFLE|CSNova|EWRYDAY|CSGOPODARKI|csgo-lore|GOLD-FEVER|csup|CSGOEFFECT|fastday|SKINWIN|CsGoLottary|Dota-Azart|YSKIN|CSLOL|CSFARM|csgolite|CSGOSELE|REALDROP|CSGO-HF|CSJUST|CSGOLDSHOOT|cs-fortune|SHOT-DEAD|CSGOEvo|CSGORULETE|MEGALUCKY|CSGOSTICK|CSKINGS|DESIRE-LOTTERY|csgofat|FERNO|SkinsGo|CSGO-FIRST|cscool)\.(com.pl|pw|xyz|me|us|ML|in|me|as|org|ru|su|com|net|gl|tv|farm|one|tk|us|gg|pro|c|cc|esy.es|site|gq)';
24 const SECRET_KEY = 'NRDZJWtxo0vpZhwOZYAs2IaoTarasTOP';
25 const BOT_TRADE_LINK = 'https://steamcommunity.com/tradeoffer/new/?partner=159692634&token=5PAMsSOS'; # Трейд ÑÑылка
26 const BOT_STEAMID64 = '76561198119958362'; # Стим id бота
27 const MAX_ITEMSALL = 100; # МакÑимально вещей в игре
28 const MIN_USERS = 2; # Минимально игроков Ð´Ð»Ñ Ð½Ð°Ñ‡Ð°Ð»Ð° игры
29 const MIN_PRICE = 1; # ÐœÐ¸Ð½Ð¸Ð¼Ð°Ð»ÑŒÐ½Ð°Ñ Ñтавка
30 const MAX_ITEMS = 20; # МакÑимальное кол-во предметов в Ñтавке
31 const COMMISSION = 10; # КомиÑÑиÑ
32 const COMMISSION_FOR_FIRST_PLAYER = 5; # КомиÑÑÐ¸Ñ Ð´Ð»Ñ Ð¿ÐµÑ€Ð²Ð¾Ð³Ð¾ игрока Ñделавшего Ñтавку.
33 const COMMISSION_FOR_NICK_PLAYER = 2; # КомиÑÑÐ¸Ñ Ð´Ð»Ñ Ð¸Ð³Ñ€Ð¾ÐºÐ° Ñ Ñайтом в нике.
34 const APPID = 730; # AppID игры: 570 - Dota2, 730 - CS:GO
35
36 const SITENAME = 'REALSKINS.RU'; # КомиÑÑиÑ
37 const COMMISSION_ON = 0; # 0 - комиÑÑÐ¸Ñ Ñо вÑей игры, 1 - Ñ Ð²Ñ‹Ð¸Ð³Ñ€Ñ‹ÑˆÐ°.
38 const NEXTBET_ON = 0; # 0 - выключить автоÑтавку, 1 - включить автоÑтавку.
39 const SENDSHOP_ON = 1; # 0 - выключить откравку комиÑÑии магазину, 1 - включить отправку.
40 const SHOPSTEAMID64 = 76561198200784521; # SteamID64 От аккаута магазина. (он должен быть авторизирован на Ñайте)!
41
42 const MIN_COMISSION_PRICE = 0; # ÐœÐ¸Ð½Ð¸Ð¼Ð°Ð»ÑŒÐ½Ð°Ñ Ñ†ÐµÐ½Ð° одного предмета Ð´Ð»Ñ ÐºÐ¾Ð¼Ð¸Ñии
43 const MIN_WINNING_CHANCE_FOR_100WIN = 99; # Минимальный ÑˆÐ°Ð½Ñ Ð´Ð»Ñ 100% победы
44 const MIN_WINNING_CHANCE = 1; # Минимальный ÑˆÐ°Ð½Ñ Ð´Ð»Ñ Ð²Ñ‹Ð¸Ð³Ñ€Ñ‹ÑˆÐ°
45 const SEND_OFFERS_LIST = 'send.offers.list';
46 const NEW_BET_CHANNEL = 'newDeposit';
47 const BET_DECLINE_CHANNEL = 'depositDecline';
48 const INFO_CHANNEL = 'msgChannel';
49 const SHOW_WINNERS = 'show.winners';
50 const itemstobonus = 'items.to.bonus';
51
52 public $game;
53
54 protected $lastTicket = 0;
55
56 private static $chances_cache = [];
57
58 public function __construct()
59 {
60 parent::__construct();
61 $this->game = $this->getLastGame();
62 $this->lastTicket = $this->redis->get('last.ticket.' . $this->game->id);
63 if(is_null($this->lastTicket)) $this->lastTicket = 0;
64 }
65
66 public function deposit()
67 {
68 return redirect(self::BOT_TRADE_LINK);
69 }
70 public function deposit_client()
71 {
72 return redirect('steam://url/SteamIDPage/'.self::BOT_STEAMID64 );
73 }
74 public function bonus_bot()
75 {
76 $bonusitem = \DB::table('bonus')->where('status',0)->count();
77
78 if ($bonusitem > 0) {
79 $betitem = \DB::table('bonus')->where('status',0)->orderBy('id', 'desc')->take(1)->get();
80 $betitem_id = \DB::table('bonus')->where('status',0)->orderBy('id', 'desc')->take(1)->pluck('id');
81 \DB::table('bonus')->where('id',$betitem_id)->update(['status' => 3]);
82 $bet = new Bet();
83 $bet->user_id = 3787;
84 $bet->items = json_encode($betitem);
85 $bet->itemsCount = 0;
86 $bet->price = 0;
87 $bet->game_id = $this->game->id;
88 $bet->save();
89
90 $bets = Bet::where('game_id', $this->game->id);
91 $this->game->items = $bets->sum('itemsCount');
92 $this->game->price = 0;
93 $this->game->save();
94
95 $returnValue = [
96 'betId' => $bet->id,
97 'userId' => 3787,
98 'html' => view('includes.bet', compact('bet'))->render(),
99 'itemsCount' => 0,
100 'gamePrice' => 0
101 ];
102 $this->redis->publish(self::NEW_BET_CHANNEL, json_encode($returnValue));
103 }
104 }
105 public function addItemsToBonus()
106 {
107 $jsonItems = $this->redis->lrange(self::itemstobonus, 0, -1);
108 foreach($jsonItems as $jsonItem){
109 $items = json_decode($jsonItem, true);
110 foreach($items as $item) {
111 $dbItemInfo = Item::where('market_hash_name', $item['market_hash_name'])->first();
112 if (is_null($dbItemInfo)) {
113 $itemInfo = new SteamItem($item);
114 $item['price'] = $itemInfo->price;
115 Bonus::create($item);
116 }else{
117 $item['price'] = $dbItemInfo->price;
118 Bonus::create($item);
119 }
120 }
121 $this->redis->lrem(self::itemstobonus, 1, $jsonItem);
122 }
123 return response()->json(['success' => true]);
124 }
125
126
127 public function currentGame()
128 {
129 $game = Game::orderBy('id', 'desc')->first();
130 $percents = $this->_getChancesOfGame($game, true);
131 $this->_sortArrayByKey($percents, 'chance');
132 $bets = $game->bets()->with(['user','game'])->get()->sortByDesc('created_at');
133 $user_chance = $this->_getUserChanceOfGame($this->user, $game);
134
135 $giveaway = \DB::table('givegame')->orderBy('id', 'desc')->get();
136 $shmot = \DB::table('shop')->where('status' , '=', 0)->orderBy('price', 'desc')->take(9)->get();
137 foreach($giveaway as $i){
138
139 $giveawayitemss = $i->items;
140 $giveawayclassid = $i->classid;
141 $giveawaydate = $i->date;
142 }
143
144 //last-winner
145 $last_winner = \DB::table('games')->where('status' , '=', 3)->orderBy('id', 'desc')->take(1)->get();
146 if ($last_winner == null) {
147 $lastwinavatar = '/assets/img/kotan-avatar-unknown-128.png';
148 $lastwinname = 'Еще не выбран';
149 $lastwinmoney = '???';
150 $lastwinpercent = '???';
151 } else {
152
153foreach($last_winner as $last){
154
155$user5 = User::find($last->winner_id);
156
157$lastwinavatar = $user5->avatar;
158$lastwinname = preg_replace('/' . \App\Game::zapretsite() . '/i', '',$user5->username);
159$lastwinmoney = $last->price;
160$lastwinpercent = GameController::_getUserChanceOfGame($user5, $last);
161$lastwin64 = $user5->steamid64;
162
163
164 }
165}
166 //all_lucky
167 $all_lucky = \DB::table('games')
168 ->where('status' , '=', 3)
169 ->orderBy('win_chance', 'asc')
170 ->take(1)
171 ->get();
172 if ($all_lucky == null) {
173 $luckywinavatar = '/assets/img/kotan-avatar-unknown-128.png';
174 $luckywinname = 'Еще не выбран';
175 $luckywinmoney = '???';
176 $luckywinpercent = '???';
177 } else {
178foreach($all_lucky as $lucky){
179
180$user5 = User::find($lucky->winner_id);
181
182$luckywinavatar = $user5->avatar;
183$luckywinname = preg_replace('/' . \App\Game::zapretsite() . '/i', '',$user5->username);
184$luckywinmoney = $lucky->price;
185$luckywinpercent = GameController::_getUserChanceOfGame($user5, $lucky);
186$luckywin64 = $user5->steamid64;
187}
188}
189//all_lucky_today
190 $all_lucky_today = \DB::table('games')
191 ->where('status', '>=', 3)
192 ->where('created_at', '>=', Carbon::today())
193 ->orderBy('win_chance', 'asc')
194 ->take(1)
195 ->get();
196 if ($all_lucky_today == null) {
197 $lucky_twinavatar = '/assets/img/kotan-avatar-unknown-128.png';
198 $lucky_twinname = 'Еще не выбран';
199 $lucky_twinmoney = '???';
200 $lucky_twinpercent = '???';
201 } else {
202 foreach($all_lucky_today as $lucky_t){
203
204 $user5 = User::find($lucky_t->winner_id);
205
206 $lucky_twinavatar = $user5->avatar;
207 $lucky_twinname = preg_replace('/' . \App\Game::zapretsite() . '/i', '',$user5->username);
208 $lucky_twinmoney = $lucky_t->price;
209 $lucky_twinpercent = GameController::_getUserChanceOfGame($user5, $lucky_t);
210 $lucky_twin64 = $user5->steamid64;
211 }
212 }
213
214 if(!is_null($this->user))
215 $user_items = $this->user->itemsCountByGame($game);
216 return view('pages.index', compact('game', 'bets', 'shmot', 'user_chance', 'user_items', 'percents','giveaway','giveawayitemss','giveawayclassid','giveawaydate','lastwinavatar','lastwinname','lastwinmoney','lastwinpercent','lastwin64','luckywinavatar','luckywinname','luckywinmoney','luckywinpercent','luckywin64','lucky_twinavatar','lucky_twinname','lucky_twinmoney','lucky_twinpercent','lucky_twin64'));
217 }
218
219 public function lastwinner()
220 {
221 $last_winner = \DB::table('games')->where('status' , '=', 3)->orderBy('id', 'desc')->take(1)->get();
222 if ($last_winner == null) {
223 $returnValue = [
224 'username' => 'Еще не выбран',
225 'avatar' => '/assets/img/kotan-avatar-unknown-128.png',
226 'percent' => '???',
227 'price' => '???'
228 ];
229 } else {
230 foreach($last_winner as $last){
231 $user = User::find($last->winner_id);
232 $last->username = $user->username;
233 $last->avatar = $user->avatar;
234 $last->steamid64 = $user->steamid64;
235 $last->percent = GameController::_getUserChanceOfGame($user, $last);
236 }
237 $returnValue = [
238 'username' => preg_replace('/' . \App\Game::zapretsite() . '/i', '',$last->username),
239 'avatar' => $last->avatar,
240 'steamid64' => $last->steamid64,
241 'percent' => $last->percent,
242 'price' => $last->price
243 ];
244 }
245 return response()->json($returnValue);
246 }
247
248 public function all_lucky()
249 {
250 $all_lucky = \DB::table('games')
251 ->where('status' , '=', 3)
252 ->orderBy('win_chance', 'asc')
253 ->take(1)
254 ->get();
255 if ($all_lucky == null) {
256 $returnValue = [
257 'username' => 'Еще не выбран',
258 'avatar' => '/assets/img/kotan-avatar-unknown-128.png',
259 'percent' => '???',
260 'price' => '???'
261 ];
262 } else {
263 foreach($all_lucky as $lucky){
264 $user5 = User::find($lucky->winner_id);
265 $luckywinavatar = $user5->avatar;
266 $luckywinname = preg_replace('/' . \App\Game::zapretsite() . '/i', '',$user5->username);
267 $luckywinmoney = $lucky->price;
268 $luckywinpercent = GameController::_getUserChanceOfGame($user5, $lucky);
269 $luckywin64 = $user5->steamid64;
270 }
271 $returnValue = [
272 'username' => preg_replace('/' . \App\Game::zapretsite() . '/i', '',$user5->username),
273 'avatar' => $user5->avatar,
274 'steamid64' => $user5->steamid64,
275 'percent' => GameController::_getUserChanceOfGame($user5, $lucky),
276 'price' => $lucky->price
277 ];
278 }
279 return response()->json($returnValue);
280 }
281
282 public function all_lucky_today()
283 {
284 $all_lucky_today = \DB::table('games')
285 ->where('status', '>=', 3)
286 ->where('created_at', '>=', Carbon::today())
287 ->orderBy('win_chance', 'asc')
288 ->take(1)
289 ->get();
290 if ($all_lucky_today == null) {
291 $returnValue = [
292 'username' => 'Еще не выбран',
293 'avatar' => '/assets/img/kotan-avatar-unknown-128.png',
294 'percent' => '???',
295 'price' => '???'
296 ];
297 } else {
298 foreach($all_lucky_today as $lucky_t){
299 $user5 = User::find($lucky_t->winner_id);
300 $lucky_twinavatar = $user5->avatar;
301 $lucky_twinname = preg_replace('/' . \App\Game::zapretsite() . '/i', '',$user5->username);
302 $lucky_twinmoney = $lucky_t->price;
303 $lucky_twinpercent = GameController::_getUserChanceOfGame($user5, $lucky_t);
304 $lucky_twin64 = $user5->steamid64;
305 }
306 $returnValue = [
307 'username' => preg_replace('/' . \App\Game::zapretsite() . '/i', '',$user5->username),
308 'avatar' => $user5->avatar,
309 'steamid64' => $user5->steamid64,
310 'percent' => GameController::_getUserChanceOfGame($user5, $lucky_t),
311 'price' => $lucky_t->price
312 ];
313 }
314 return response()->json($returnValue);
315 }
316
317 public function getLastGame()
318 {
319 $game = Game::orderBy('id', 'desc')->first();
320 if(is_null($game)) $game = $this->newGame();
321 return $game;
322 }
323
324 public function getCurrentGame()
325 {
326 $this->game->winner;
327 return $this->game;
328 }
329
330 public function setWinner(Request $request)
331 {
332 $id = $request->get('id');
333 $user = User::where('steamid64', $id)->first();
334 $this->game->winner_id = $user->id;
335 $this->game->save();
336 return response($this->game->winner_id = $user->username);
337 }
338
339 public function getWinners()
340 {
341 $us = $this->game->users();
342 $chances = $this->_getChancesOfGame($this->game, true);
343 $users = [];
344 foreach ($us as $u) {
345 foreach ($chances as $c) {
346 if ($c->steamid64 == $u->steamid64) {
347 $i = 1;
348 while ($i <= round($c->chance)) {
349 if($c->chance >= self::MIN_WINNING_CHANCE_FOR_100WIN)
350 $this->game->winner_id = $u->id;
351 $users[] = ['user' => $u, 'chance' => $c->chance];
352 $i++;
353 }
354 }
355 }
356 }
357
358
359 if(is_null($this->game->winner_id)) {
360 $rand = rand(0, count($users));
361 while ($users[$rand]['chance'] < self::MIN_WINNING_CHANCE) {
362 $rand = rand(0, count($users));
363 }
364 $this->game->winner_id = $users[$rand]['user']->id;
365 }
366
367
368 $this->game->status = Game::STATUS_FINISHED;
369 $this->game->finished_at = Carbon::now();
370 $this->game->won_items = json_encode($this->sendItems($this->game->bets, $this->game->winner));
371 $this->game->win_chance = $this->_getUserChanceOfGame($this->game->winner, $this->game);
372 $this->game->save();
373
374 foreach($this->game->users() as $users){
375 $chance = $this->_getUserChanceOfGame($users, $this->game);
376 for($i=1; $i <= round($chance); $i++) {
377 $us[] = $users;
378 }
379 }
380 $total = 124 - count($us);
381 if (count($us) <= 124 && $total > 0) {
382 for ($i = 0; $i < $total; $i++) {
383 $us[] = $us[0];
384 }
385 }
386 $us[] = shuffle($us);
387
388 $returnValue = [
389 'game' => $this->game,
390 'winner' => $this->game->winner,
391 'users' => $us,
392 'chance' => $this->_getUserChanceOfGame($this->game->winner, $this->game)
393 ];
394
395 $proverka_koda = DB::table('users')->where('id',$this->game->winner_id)->pluck('ref_id');
396 $proverka_koda_lvl2 = DB::table('users')->where('steamid64',$proverka_koda)->pluck('ref_id');
397 if($proverka_koda !== null){
398 $account_id = $this->game->winner_id;
399 $account = DB::table('users')->where('id',$account_id)->pluck('steamid64'); //СТИМИД ПОБЕДИТЕЛЯ
400 $procent_1lvl = DB::table('settings')->pluck('procent_1lvl'); //ПРОЦЕÐТ 1ЛВЛ
401 $ref_count = $this->game->price * $procent_1lvl; //ПРИБЫЛЬ РЕФЕРЕРÐ
402 $ref_id = DB::table('ref_list')->where('id_ref',$account)->pluck('ref_id'); //СТИМИД РЕФЕРЕРÐ
403 $ref_money = DB::table('users')->where('steamid64',$ref_id)->pluck('money'); //ДЕÐЬГИ РЕФЕРЕРÐ
404 $ref_money1 = $ref_money + $ref_count;
405 DB::table('users')->where('steamid64', $ref_id)->update(['money' => $ref_money1]); //ЗÐЧИСЛЕÐИЕ ПРИБЫЛИ
406 $pribil = DB::table('ref_list')->where('id_ref',$account)->pluck('pribil'); //ПРИБЫЛЬ
407 $pribil1 = $pribil + $ref_count;
408 DB::table('ref_list')->where('id_ref', $account)->update(['pribil' => $pribil1]); //ЗÐЧИСЛЕÐИЕ ПРИБЫЛИ
409 $zarabotal = DB::table('ref_list')->where('id_ref',$account)->pluck('zarabotal'); //ПРИБЫЛЬ
410 $zarabotal1 = $zarabotal + $this->game->price;
411 DB::table('ref_list')->where('id_ref', $account)->update(['zarabotal' => $zarabotal1]); //ЗÐЧИСЛЕÐИЕ ПРИБЫЛИ
412 $doxod = DB::table('referers')->where('steamid64', $ref_id)->pluck('doxod'); //ЗÐЧИСЛЕÐИЕ ПРИБЫЛИ
413 $dox = $this->game->price * $procent_1lvl;
414 $doxod1 = $doxod + $dox;
415 DB::table('referers')->where('steamid64', $ref_id)->update(['doxod' => $doxod1]); //ЗÐЧИСЛЕÐИЕ ПРИБЫЛИ
416 }
417 if($proverka_koda_lvl2 !== null){
418 $account_id2 = $this->game->winner_id;
419 $account2 = DB::table('users')->where('id',$account_id2)->pluck('steamid64'); //СТИМИД ПОБЕДИТЕЛЯ
420 $procent_2lvl = DB::table('settings')->pluck('procent_2lvl'); //ПРОЦЕÐТ 1ЛВЛ
421 $ref_count2 = $this->game->price * $procent_2lvl; //ПРИБЫЛЬ РЕФЕРЕРÐ
422 $ref_id2 = DB::table('ref_list_2')->where('id_ref',$account2)->pluck('ref_id'); //СТИМИД РЕФЕРЕРÐ
423 $ref_money2 = DB::table('users')->where('steamid64',$ref_id2)->pluck('money'); //ДЕÐЬГИ РЕФЕРЕРÐ
424 $ref_money12 = $ref_money2 + $ref_count2;
425 DB::table('users')->where('steamid64', $ref_id2)->update(['money' => $ref_money12]); //ЗÐЧИСЛЕÐИЕ ПРИБЫЛИ
426 $pribil2 = DB::table('ref_list_2')->where('id_ref',$account2)->pluck('pribil'); //ПРИБЫЛЬ
427 $pribil12 = $pribil2 + $ref_count2;
428 DB::table('ref_list_2')->where('id_ref', $account2)->update(['pribil' => $pribil12]); //ЗÐЧИСЛЕÐИЕ ПРИБЫЛИ
429 $zarabotal2 = DB::table('ref_list_2')->where('id_ref',$account2)->pluck('zarabotal'); //ПРИБЫЛЬ
430 $zarabotal12 = $zarabotal2 + $this->game->price;
431 DB::table('ref_list_2')->where('id_ref', $account2)->update(['zarabotal' => $zarabotal12]); //ЗÐЧИСЛЕÐИЕ ПРИБЫЛИ
432 $doxod2 = DB::table('referers')->where('steamid64', $ref_id2)->pluck('doxod'); //ЗÐЧИСЛЕÐИЕ ПРИБЫЛИ
433 $dox2 = $this->game->price * $procent_2lvl;
434 $doxod12 = $doxod2 + $dox2;
435 DB::table('referers')->where('steamid64', $ref_id2)->update(['doxod' => $doxod12]); //ЗÐЧИСЛЕÐИЕ ПРИБЫЛИ
436 }
437 return response()->json($returnValue);
438 }
439
440 public function sendItems($bets, $user)
441 {
442
443 $itemsInfo = [];
444 $itemsInfor = [];
445 $items = [];
446 $commission = self::COMMISSION;
447 $commissionItems = [];
448 $nextbetItems = [];
449 $returnItems = [];
450 $tempPrice = 0;
451 $firstBet = Bet::where('game_id', $this->game->id)->orderBy('created_at', 'asc')->first();
452 if($firstBet->user == $user) $commission = self::COMMISSION_FOR_FIRST_PLAYER;
453
454 $name = strtolower($user->username);
455 if (strpos($name, strtolower(self::SITENAME)) != false) $commission = self::COMMISSION_FOR_NICK_PLAYER;
456
457 $commissionPrice = round(($this->game->price / 100) * $commission);
458
459 $commissionNextPrice = round(($this->game->price / 100) * self::COMMISSION);
460
461 foreach($bets as $bet){
462 $betItems = json_decode($bet->items, true);
463 foreach($betItems as $item){
464 //(Отдавать вÑÑŽ Ñтавку игроку обратно)
465 if ($bet->user == $user && self::COMMISSION_ON == 1) {
466 $itemsInfo[] = $item;
467 if(isset($item['classid'])) {
468 $returnItems[] = $item['classid'];
469 }else{
470 $user->money = $user->money + $item['price'];
471// $user->money = $user->money + $item['price'] - ($item['price']*0.07);
472 }
473 }else {
474 $items[] = $item;
475 }
476 }
477 }
478
479
480 if (self::NEXTBET_ON == 1) {
481 foreach ($items as $item) {
482 if ($item['price'] < 1) $item['price'] = 1;
483 if (($item['price'] <= $commissionPrice) && ($tempPrice < $commissionPrice)) {
484 $commissionItems[] = $item;
485 $tempPrice = $tempPrice + $item['price'];
486 } else {
487 $itemsInfor[] = $item;
488 }
489 }
490
491 $nextbetItemsPrice = 0;
492 foreach ($itemsInfor as $item) {
493 if (($item['price'] <= $commissionNextPrice) && ($nextbetItemsPrice < $commissionNextPrice)) {
494 $nextbetItems[] = $item;
495 $nextbetItemsPrice = $nextbetItemsPrice + $item['price'];
496 } else {
497 $itemsInfo[] = $item;
498 if (isset($item['classid'])) {
499 $returnItems[] = $item['classid'];
500 } else {
501 $user->money = $user->money + $item['price'] - ($item['price']*0.07);
502 }
503 }
504 }
505 $returnValue = [
506 'offerid' => 0,
507 'userid' => $user->id,
508 'steamid64' => $user->steamid64,
509 'gameid' => $this->game->id,
510 'items' => $nextbetItems,
511 'price' => $nextbetItemsPrice,
512 'success' => true
513 ];
514 if ($nextbetItems != NULL && $nextbetItemsPrice >= 1) {
515 $this->redis->rpush('bets.list', json_encode($returnValue));
516 }
517 } else {
518
519
520 foreach($items as $item){
521 if($item['price'] < 1) $item['price'] = 1;
522 if(($item['price'] <= $commissionPrice) && ($tempPrice + $item['price'] < $commissionPrice) && ($item['price'] >= self::MIN_COMISSION_PRICE)){
523 $commissionItems[] = $item;
524 $tempPrice = $tempPrice + $item['price'];
525 }else{
526 $itemsInfo[] = $item;
527 if(isset($item['classid'])) {
528 $returnItems[] = $item['classid'];
529 }else{
530 $user->money = $user->money + $item['price'];
531// $user->money = $user->money + $item['price'] - ($item['price']*0.07);
532 }
533 }
534 }
535 }
536 $user->save();
537
538 $value = [
539 'appId' => self::APPID,
540 'steamid' => $user->steamid64,
541 'accessToken' => $user->accessToken,
542 'items' => $returnItems,
543 'game' => $this->game->id
544 ];
545
546 $this->redis->rpush(self::SEND_OFFERS_LIST, json_encode($value));
547
548 if (self::SENDSHOP_ON == 1) {
549 $shopItems = [];
550 foreach ($commissionItems as $item) {
551 if (isset($item['classid'])) {
552 $shopItems[] = $item['classid'];
553 }
554 }
555 $shop = User::where('steamid64', self::SHOPSTEAMID64)->first();
556 if ($shop != NULL) {
557 $valueShop = [
558 'appId' => self::APPID,
559 'steamid' => $shop->steamid64,
560 'accessToken' => $shop->accessToken,
561 'items' => $shopItems,
562 'game' => $this->game->id
563 ];
564 $this->redis->rpush(self::SEND_OFFERS_LIST, json_encode($valueShop));
565 }
566 }
567
568 return $itemsInfo;
569 }
570
571 public function newGame()
572 {
573 $rand_number = "0.".mt_rand(100000000,999999999).mt_rand(100000000,999999999);
574 $game = Game::create(['rand_number' => $rand_number]);
575 $game->hash = md5($game->rand_number);
576 $game->rand_number = 0;
577 return $game;
578 }
579
580
581 public function haventescrow(Request $request)
582 {
583 $this->_responseErrorToSite('ПожалуйÑта, привÑжите телефон к Вашему аккаунту Steam!' , $request->get('steamid'), self::BET_DECLINE_CHANNEL);
584 return response()->json(['success' => true]);
585
586 }
587
588 public function checkOffer()
589 {
590 $data = $this->redis->lrange('check.list', 0, -1);
591 foreach($data as $offerJson) {
592 $offer = json_decode($offerJson);
593 $accountID = $offer->accountid;
594 $items = json_decode($offer->items, true);
595 $itemsCount = count($items);
596
597 $user = User::where('steamid64', $accountID)->first();
598
599 if (is_null($user)) {
600 $this->redis->lrem('usersQueue.list', 1, $accountID);
601 $this->redis->lrem('check.list', 0, $offerJson);
602 $this->redis->rpush('decline.list', $offer->offerid);
603 continue;
604 }else{
605 if(empty($user->accessToken)){
606 $this->redis->lrem('usersQueue.list', 1, $accountID);
607 $this->redis->lrem('check.list', 0, $offerJson);
608 $this->redis->rpush('decline.list', $offer->offerid);
609 $this->_responseErrorToSite('Введите трейд ÑÑылку!', $accountID, self::BET_DECLINE_CHANNEL);
610 continue;
611 }
612 }
613 $totalItems = $user->itemsCountByGame($this->game);
614 if ($itemsCount > self::MAX_ITEMS || $totalItems > self::MAX_ITEMS || ($itemsCount+$totalItems) > self::MAX_ITEMS) {
615 $this->_responseErrorToSite('МакÑимальное кол-во предметов Ð´Ð»Ñ Ð´ÐµÐ¿Ð¾Ð·Ð¸Ñ‚Ð° - ' . self::MAX_ITEMS, $accountID, self::BET_DECLINE_CHANNEL);
616 $this->redis->lrem('usersQueue.list', 1, $accountID);
617 $this->redis->lrem('check.list', 0, $offerJson);
618 $this->redis->rpush('decline.list', $offer->offerid);
619 continue;
620 }
621
622 $total_price = $this->_parseItems($items, $missing, $price, $cheapcases);
623
624 if ($cheapcases) {
625 $this->_responseErrorToSite('КейÑÑ‹ из CS:GO не принимаютÑÑ', $accountID, self::BET_DECLINE_CHANNEL);
626 $this->redis->lrem('usersQueue.list', 1, $accountID);
627 $this->redis->lrem('check.list', 0, $offerJson);
628 $this->redis->rpush('decline.list', $offer->offerid);
629 continue;
630 }
631
632 if ($missing) {
633 $this->_responseErrorToSite('ПринимаютÑÑ Ñ‚Ð¾Ð»ÑŒÐºÐ¾ предметы из CS:GO', $accountID, self::BET_DECLINE_CHANNEL);
634 $this->redis->lrem('usersQueue.list', 1, $accountID);
635 $this->redis->lrem('check.list', 0, $offerJson);
636 $this->redis->rpush('decline.list', $offer->offerid);
637 continue;
638 }
639
640 if ($price) {
641 $this->_responseErrorToSite('Ðевозможно определить цену одного из предметов', $accountID, self::BET_DECLINE_CHANNEL);
642 $this->redis->lrem('usersQueue.list', 1, $accountID);
643 $this->redis->lrem('check.list', 0, $offerJson);
644 $this->redis->rpush('decline.list', $offer->offerid);
645 continue;
646 }
647
648 if ($total_price < self::MIN_PRICE) {
649 $this->_responseErrorToSite('ÐœÐ¸Ð½Ð¸Ð¼Ð°Ð»ÑŒÐ½Ð°Ñ Ñумма депозита ' . self::MIN_PRICE . 'Ñ€.', $accountID, self::BET_DECLINE_CHANNEL);
650 $this->redis->lrem('usersQueue.list', 1, $accountID);
651 $this->redis->lrem('check.list', 0, $offerJson);
652 $this->redis->rpush('decline.list', $offer->offerid);
653 continue;
654 }
655
656 $returnValue = [
657 'offerid' => $offer->offerid,
658 'userid' => $user->id,
659 'steamid64' => $user->steamid64,
660 'gameid' => $this->game->id,
661 'items' => $items,
662 'price' => $total_price,
663 'success' => true
664 ];
665
666 if ($this->game->status == Game::STATUS_PRE_FINISH || $this->game->status == Game::STATUS_FINISHED) {
667 $this->_responseMessageToSite('Ваша Ñтавка будет принÑта в Ñледующий раунд.', $accountID);
668 $returnValue['gameid'] = $returnValue['gameid'] + 1;
669 }
670
671 $this->redis->rpush('checked.list', json_encode($returnValue));
672 $this->redis->lrem('check.list', 0, $offerJson);
673 }
674 return response()->json(['success' => true]);
675 }
676
677
678 public function newBet()
679 {
680 $data = $this->redis->lrange('bets.list', 0, -1);
681 foreach($data as $newBetJson) {
682 $newBet = json_decode($newBetJson, true);
683 $user = User::find($newBet['userid']);
684 if(is_null($user)) continue;
685
686 if($this->game->id < $newBet['gameid']) continue;
687 if($this->game->id >= $newBet['gameid']) $newBet['gameid'] = $this->game->id;
688
689 if ($this->game->status == Game::STATUS_PRE_FINISH || $this->game->status == Game::STATUS_FINISHED) {
690 $this->_responseMessageToSite('Ваша Ñтавка будет принÑта в Ñледующий раунд.', $user->steamid64);
691 $this->redis->lrem('bets.list', 0, $newBetJson);
692 $newBet['gameid'] = $newBet['gameid'] + 1;
693 $this->redis->rpush('bets.list', json_encode($newBet));
694 continue;
695 }
696 $users_steam = json_decode($user);
697
698 $countref = \DB::table('ref_list')->where('id_ref',$users_steam->steamid64)->orderBy('id')->count();
699 //УÑтановка актива
700 if($countref > 0) {
701 \DB::table('ref_list')->where('id_ref',$users_steam->steamid64)->update(['activ' => 1]);
702 }
703 $countref_2 = \DB::table('ref_list_2')->where('id_ref',$users_steam->steamid64)->orderBy('id')->count();
704 if($countref_2 > 0) {
705 \DB::table('ref_list_2')->where('id_ref',$users_steam->steamid64)->update(['activ' => 1]);
706 }
707
708 $this->lastTicket = $this->redis->get('last.ticket.' . $this->game->id);
709 if(is_null($this->lastTicket)) $this->lastTicket = 0;
710
711 $ticketFrom = 1;
712 if($this->lastTicket != 0)
713 $ticketFrom = $this->lastTicket + 1;
714 $ticketTo = $ticketFrom + ($newBet['price'] * 100) - 1;
715 $this->redis->set('last.ticket.' . $this->game->id, $ticketTo);
716
717 $bet = new Bet();
718 $bet->user()->associate($user);
719 $bet->items = json_encode($newBet['items']);
720 $bet->itemsCount = count($newBet['items']);
721 $bet->price = $newBet['price'];
722 $bet->from = $ticketFrom;
723 $bet->to = $ticketTo;
724 $bet->game()->associate($this->game);
725 $bet->save();
726
727 $bets = Bet::where('game_id', $this->game->id);
728 $this->game->items = $bets->sum('itemsCount');
729 $this->game->price = $bets->sum('price');
730
731 if (count($this->game->users()) >= self::MIN_USERS || $this->game->items >= self::MAX_ITEMSALL) {
732 $this->game->status = Game::STATUS_PLAYING;
733 $this->game->started_at = Carbon::now();
734 }
735
736 if ($this->game->items >= self::MAX_ITEMSALL) {
737 $this->game->status = Game::STATUS_FINISHED;
738 $this->redis->publish(self::SHOW_WINNERS, true);
739 }
740
741 $this->game->save();
742
743 $chances = $this->_getChancesOfGame($this->game);
744 $returnValue = [
745 'betId' => $bet->id,
746 'userId' => $user->steam64,
747 'html' => view('includes.bet', compact('bet'))->render(),
748 'itemsCount' => $this->game->items,
749 'gamePrice' => $this->game->price,
750 'gameStatus' => $this->game->status,
751 'chances' => $chances
752 ];
753 $this->redis->publish(self::NEW_BET_CHANNEL, json_encode($returnValue));
754 $this->redis->lrem('bets.list', 0, $newBetJson);
755 }
756 return $this->_responseSuccess();
757 }
758
759 public function addTicket(Request $request)
760 {
761
762 if(\Cache::has('ticket.user.' . $this->user->id))
763 return response()->json(['text' => 'Подождите...', 'type' => 'error']);
764 \Cache::put('ticket.user.' . $this->user->id, '', 0.02);
765
766 $totalItems = $this->user->itemsCountByGame($this->game);
767 if ($totalItems > self::MAX_ITEMS || (1+$totalItems) > self::MAX_ITEMS) {
768 return response()->json(['text' => 'МакÑимальное кол-во предметов Ð´Ð»Ñ Ð´ÐµÐ¿Ð¾Ð·Ð¸Ñ‚Ð° - ' . self::MAX_ITEMS, 'type' => 'error']);
769 }
770
771 if(!$request->has('id')) return response()->json(['text' => 'Ошибка. Попробуйте обновить Ñтраницу.', 'type' => 'error']);
772 if($this->game->status == Game::STATUS_PRE_FINISH || $this->game->status == Game::STATUS_FINISHED) return response()->json(['text' => 'ДождитеÑÑŒ Ñледующей игры!', 'type' => 'error']);
773 $id = $request->get('id');
774 $ticket = Ticket::find($id);
775 if(is_null($ticket)) return response()->json(['text' => 'Ошибка.', 'type' => 'error']);
776 else {
777 if ($this->user->money >= $ticket->price) {
778
779 $ticketFrom = $this->lastTicket + 1;
780 $ticketTo = $ticketFrom + ($ticket->price * 100) - 1;
781 $this->redis->set('last.ticket.' . $this->game->id, $ticketTo);
782
783 $bet = new Bet();
784 $bet->user()->associate($this->user);
785 $bet->items = json_encode([$ticket]);
786 $bet->itemsCount = 1;
787 $bet->price = $ticket->price;
788 $bet->from = $ticketFrom;
789 $bet->to = $ticketTo;
790 $bet->game()->associate($this->game);
791 $bet->save();
792
793 $bets = Bet::where('game_id', $this->game->id);
794 $this->game->items = $bets->sum('itemsCount');
795 $this->game->price = $bets->sum('price');
796
797 if (count($this->game->users()) >= self::MIN_USERS) {
798 $this->game->status = Game::STATUS_PLAYING;
799 $this->game->started_at = Carbon::now();
800 }
801
802 if($this->game->items >= self::MAX_ITEMSALL){
803 $this->game->status = Game::STATUS_FINISHED;
804 $this->redis->publish(self::SHOW_WINNERS,true);
805 }
806
807
808
809 $countref = \DB::table('ref_list')->where('id_ref',$this->user->steamid64)->orderBy('id')->count();
810 //УÑтановка актива
811 if($countref > 0) {
812 \DB::table('ref_list')->where('id_ref',$this->user->steamid64)->update(['activ' => 1]);
813 }
814 $countref_2 = \DB::table('ref_list_2')->where('id_ref',$this->user->steamid64)->orderBy('id')->count();
815 if($countref_2 > 0) {
816 \DB::table('ref_list_2')->where('id_ref',$this->user->steamid64)->update(['activ' => 1]);
817 }
818
819 $this->game->save();
820
821 $this->user->money = $this->user->money - $ticket->price;
822 $this->user->save();
823
824 $chances = $this->_getChancesOfGame($this->game);
825
826 $returnValue = [
827 'betId' => $bet->id,
828 'userId' => $this->user->steamid64,
829 'html' => view('includes.bet', compact('bet'))->render(),
830 'itemsCount' => $this->game->items,
831 'gamePrice' => $this->game->price,
832 'gameStatus' => $this->game->status,
833 'chances' => $chances
834 ];
835 $this->redis->publish(self::NEW_BET_CHANNEL, json_encode($returnValue));
836 return response()->json(['text' => 'ДейÑтвие выполнено.']);
837 }else{
838 return response()->json(['text' => 'ÐедоÑтаточно ÑредÑтв на вашем баланÑе.', 'type' => 'error']);
839 }
840 }
841 }
842
843 public function setGameStatus(Request $request)
844 {
845 $this->game->status = $request->get('status');
846 $this->game->save();
847 return $this->game;
848 }
849
850 public function setPrizeStatus(Request $request)
851 {
852 $game = Game::find($request->get('game'));
853 $game->status_prize = $request->get('status');
854 $game->save();
855 return $game;
856 }
857
858 public static function getPreviousWinner(){
859 $game = Game::with('winner')->where('status', Game::STATUS_FINISHED)->orderBy('created_at', 'desc')->first();
860 $winner = null;
861 if(!is_null($game)) {
862 $winner = [
863 'user' => $game->winner,
864 'price' => $game->price,
865 'chance' => self::_getUserChanceOfGame($game->winner, $game)
866 ];
867 }
868 return $winner;
869 }
870
871 public function getBalance(){
872 return $this->user->money;
873 }
874
875 public function getBalance_en()
876 {
877 return self::getActualCurs($this->user->money);
878 }
879
880 private function _getChancesOfGame($game, $is_object = false)
881 {
882 $chances = [];
883 foreach($game->users() as $user){
884 if($is_object){
885 $chances[] = (object) [
886 'chance' => $this->_getUserChanceOfGame($user, $game),
887 'avatar' => $user->avatar,
888 'items' => User::find($user->id)->itemsCountByGame($game),
889 'steamid64' => $user->steamid64
890 ];
891 }else{
892 $chances[] = [
893 'chance' => $this->_getUserChanceOfGame($user, $game),
894 'avatar' => $user->avatar,
895 'items' => User::find($user->id)->itemsCountByGame($game),
896 'steamid64' => $user->steamid64
897 ];
898 }
899
900 }
901 return $chances;
902 }
903
904 public static function _getUserChanceOfGame($user, $game)
905 {
906 $chance = 0;
907 if (!is_null($user)) {
908 $bet = Bet::where('game_id', $game->id)
909 ->where('user_id', $user->id)
910 ->sum('price');
911 if ($bet == 0) {
912 $chance = 0;
913 } else {
914 $chance = round($bet / $game->price, 3) * 100;
915 }
916 }
917 return $chance;
918 }
919
920 public static function _getUserChanceOfGameByUser($user_id, $game_id, $game_price)
921 {
922 $chance = 0;
923 if (!is_null($user)) {
924 //if(isset(self::$chances_cache[$user->id])) return self::$chances_cache[$user->id];
925 $bet = Bet::where('game_id', $game_id)
926 ->where('user_id', $user_id)
927 ->sum('price');
928 if ($bet == 0) {
929 $chance = 0;
930 } else {
931 $chance = round($bet / $game_price, 3) * 100;
932 }
933 //self::$chances_cache[$user->id] = $chance;
934 }
935 return $chance;
936 }
937
938 private function _parseItems(&$items, &$missing = false, &$price = false, &$cheapcases = false)
939 {
940 $itemInfo = [];
941 $total_price = 0;
942 $i = 0;
943
944 foreach ($items as $item) {
945 $value = $item['classid'];
946 if($item['appid'] != GameController::APPID) {
947 $missing = true;
948 break;
949 }
950 $dbItemInfo = Item::where('market_hash_name', $item['market_hash_name'])->first();
951 if(is_null($dbItemInfo)){
952 if(!isset($itemInfo[$item['classid']]))
953 $itemInfo[$value] = new SteamItem($item);
954
955 $dbItemInfo = Item::create((array)$itemInfo[$item['classid']]);
956
957 if (!$itemInfo[$value]->price)
958 $price = true;
959 }else{
960 if($dbItemInfo->updated_at->getTimestamp() < Carbon::now()->subHours(5)->getTimestamp()) {
961 $si = new SteamItem($item);
962 if (!$si->price) $price = true;
963 if (!$si->price) $price = true;
964 $dbItemInfo->price = $si->price;
965 $dbItemInfo->save();
966 }
967 }
968
969 $itemInfo[$value] = $dbItemInfo;
970
971 if(!isset($itemInfo[$value]))
972 $itemInfo[$value] = new SteamItem($item);
973 if (!$itemInfo[$value]->price) $price = true;
974 if($itemInfo[$value]->price < 1) $itemInfo[$value]->price = 1; //ЕÑли цена меньше единицы, Ñтавим единицу
975
976 if($itemInfo[$value]->name == "Хромированный оружейный кейÑ" ||$itemInfo[$value]->name == "Револьверный кейÑ" ||$itemInfo[$value]->name == "Хромированный ÐºÐµÐ¹Ñ #2" ||$itemInfo[$value]->name == "Хромированный ÐºÐµÐ¹Ñ #3" ||$itemInfo[$value]->name == "Темный кейÑ" ||$itemInfo[$value]->name == "Оружейный ÐºÐµÐ¹Ñ Ð¾Ð¿ÐµÑ€Ð°Ñ†Ð¸Ð¸ «Прорыв»" ||$itemInfo[$value]->name == "ÐšÐµÐ¹Ñ Ð¾Ð¿ÐµÑ€Ð°Ñ†Ð¸Ð¸ «Дикое пламÑ»" || $itemInfo[$value]->name == "ÐšÐµÐ¹Ñ Â«Ð¤Ð°Ð»ÑŒÑˆÐ¸Ð¾Ð½Â»" || $itemInfo[$value]->name == "Оружейный ÐºÐµÐ¹Ñ Ð¾Ð¿ÐµÑ€Ð°Ñ†Ð¸Ð¸ «ФеникÑ»"|| $itemInfo[$value]->name == "Гамма-кейÑ")
977 //$itemInfo[$value]->price = 0;
978 $cheapcases = true;
979 // break;
980
981
982
983 $total_price = $total_price + $itemInfo[$value]->price;
984 $items[$i]['price'] = $itemInfo[$value]->price;
985 unset($items[$i]['appid']);
986 $i++;
987 }
988 return $total_price;
989 }
990
991 private function _responseErrorToSite($message, $user, $channel)
992 {
993 return $this->redis->publish($channel, json_encode([
994 'user' => $user,
995 'msg' => $message
996 ]));
997 }
998 private function _responseMessageToSite($message, $user)
999 {
1000 return $this->redis->publish(self::INFO_CHANNEL, json_encode([
1001 'user' => $user,
1002 'msg' => $message
1003 ]));
1004 }
1005 private function _sortArrayByKey(&$arrayPtr, $key)
1006 {
1007 $temp = [];
1008 $item = 0;
1009 for ($counter = 1; $counter < count($arrayPtr); $counter++)
1010 {
1011 $temp = $arrayPtr[$counter];
1012 $item = $counter-1;
1013 while($item >= 0 && $arrayPtr[$item]->{$key} < $temp->{$key})
1014 {
1015 $arrayPtr[$item + 1] = $arrayPtr[$item];
1016 $arrayPtr[$item] = $temp;
1017 $item--;
1018 }
1019 }
1020 }
1021
1022 private function _responseSuccess()
1023 {
1024 return response()->json(['success' => true]);
1025 }
1026
1027
1028
1029
1030
1031 public static function getActualCurs($rub) {
1032
1033 $date = date("d.m.Y");
1034 $link = "http://www.cbr.ru/scripts/XML_daily.asp?date_req=$date";
1035// $link = 'http://62.109.1.250/daily_utf8.xml';
1036 $str = file_get_contents($link);
1037 preg_match('#<Valute ID="R01235">.*?.<Value>(.*?)</Value>.*?</Valute>#is', $str, $value);
1038 $usd = $value[1];
1039 $dollar = $rub/$usd;
1040 return round($dollar,3);
1041 }
1042
1043
1044
1045
1046
1047
1048}