$id_agent]); // Create wallet if is not exist $category = null; if($networks){ $reload = false; $id = $id_agent; foreach ($networks as $network){ $category = $network->category; // Create wallet if is not exist if(!$network->id){ DB::insert('INSERT INTO wallets (id_networkAgent) VALUES (?);', [$network->id_networkAgent]); $reload = true; } } if($reload) return $this->activated($id); } // Return only single wallet if it is hypervisor or supervisor if(in_array( $category , ['hyper','super'])){ // Remove unnecessary fields $networks = $this->array_except($networks,['id_networkAgent','category']); return $this->successResponse(collect($networks)->first()); }else{ // Remove unnecessary fields $networks = $this->array_except($networks,['id_networkAgent','category','balance_princ','balance_com','created_date','taux_com_client_depot']); return $this->successResponse($networks); } } private function array_except($array, $keys){ foreach ($array as $row){ foreach($keys as $key){ unset($row->$key); } } return $array; } public function show($id_wallet) { // $wallet = Wallet::findOrFail($id_wallet); $wallet = collect(DB::select('SELECT wa.wallet_id AS id, wa.balance_princ, wa.balance_com, wa.created_date, wa.network , cw.taux_com_client_depot, c.name AS country, cw.type, c.currency_code FROM wallet_agent wa INNER JOIN configWallet cw ON wa.network_id = cw.id_network INNER JOIN networks n ON n.id = wa.network_id INNER JOIN countries_currencies c ON c.id = n.country_id WHERE wa.wallet_id = :id',['id' => $id_wallet]))->first(); if($wallet) return $this->successResponse($wallet); else return $this->errorResponse(trans('errors.model_not_found',['model'=>'wallet']),Response::HTTP_BAD_REQUEST); } public function create(Request $request) { $rules = [ 'id_networkAgent'=>'required|integer|min:1' ]; $this->validate($request,$rules); DB::insert('INSERT INTO wallets (id_networkAgent) VALUES (?);', [$request->id_networkAgent]); return $this->successResponse(trans('messages.new_wallet_added')); } // Wallets users iLink public function showWalletUser($id_user){ $wallet = collect(DB::select('SELECT wu.* , u.user_code , u.numero_carte , u.expiration_date from wallets_users wu INNER JOIN users u ON u.id = wu.idUser WHERE wu.idUser = :id_user',['id_user' => $id_user]))->first(); if($wallet){ $wallet->country = 'Gabon'; $wallet->network = 'iLink World'; $walletUser = WalletsUser::findOrFail($wallet->id); $init_country = $walletUser->user->network->country->id; $wallet->currency_code = $this->getCurrency($init_country); return $this->successResponse($wallet); } else return $this->errorResponse(trans('errors.model_not_found',['model'=>'wallet']),Response::HTTP_BAD_REQUEST); } }