/** * Bootstrap the application services. * * @return void */ public function boot() { $connections = []; foreach (\App\Models\Server::where('created', 1)->get() as $server) { $connections[$server->name] = ['host' => $server->ip_address, 'username' => 'root', 'key' => storage_path('webdb.key'), 'keyphrase' => '', 'timeout' => 10]; } config(['remote.connections' => $connections]); }
/** * Handle the event. * * @param ProductWasPurchased $event * @return void */ public function handle(ProductWasPurchased $event) { // if ($event->oreder->status != 2) { $product = Product::where('id', $event->oreder->product_id)->first(); $server = Server::where('id', $product->server_id)->first(); $command = str_replace(':steam_id', $event->oreder->steam_id, $product->command); $command = str_replace(':quantity', $event->oreder->quantity, $command); $data = new SourceQuery(); try { $data->Connect($server->ip, $server->port, 3, $server->engine); $data->SetRconPassword($server->rcon_password); $data->Rcon($command); $event->oreder->status = 2; $event->oreder->completed_at = Carbon::now(); $event->oreder->save(); } catch (\Exception $e) { $e->getMessage(); } } }
public function handle(Requests\OrderRequest $request, Product $product, $id) { $product = $product->where('id', $id)->first(); if ($product !== null) { $quantity = 1; if ($product->countable == true) { $quantity = $request->get('quantity'); } // TODO вынести обработку steam id в отдельный класс или в Request // Нужно полученый STEAM ID проверить в зависимости от игры $steam_id = $request->get('steam_id'); $server = Server::where('id', $product->server_id)->first(); switch ($server->engine) { case 1: if (preg_match("/\\[U:1:(\\d+)\\]/", $steam_id)) { $steam_id = preg_replace("/\\[U:1:(\\d+)\\]/", "\$1", $steam_id); $A = $steam_id % 2; $B = intval($steam_id / 2); $steam_id = "STEAM_0:" . $A . ":" . $B; } break; } //======= $order = new Order(); $order->product_id = $product->id; $order->quantity = $quantity; $order->sum = intval($product->discount_price * $quantity); $order->email = $request->get('email'); $order->steam_id = $steam_id; $order->status = 0; $order->save(); $payment = new Payment(config('robokassa.login'), config('robokassa.paymentPassword'), config('robokassa.validationPassword')); $payment->setInvoiceId($order->id)->setSum($order->sum)->setDescription('Покупка ' . $product->title); return redirect($payment->getPaymentUrl()); } return redirect()->route('shop.index'); }