public function postNewReferrals()
 {
     if (Input::has('emails')) {
         $emails = explode(',', Input::get('emails'));
         foreach ($emails as $email) {
             $referral = UserReferral::where('referral_id', Auth::user()->id)->where('email', $email)->first();
             if (sizeof($referral) > 0) {
                 //Send email if tries less than 3 else skip
                 if ($referral->tries < 5) {
                     $referral->tries = $referral->tries + 1;
                     $referral->save();
                 } else {
                     continue;
                 }
             } else {
                 $user_referral = new UserReferral();
                 $user_referral->user_id = 0;
                 $user_referral->referral_id = Auth::user()->id;
                 $user_referral->email = $email;
                 $user_referral->tries = 1;
                 $user_referral->save();
             }
         }
         Session::flash('success_msg', 'Referral email sent successfully');
         return Redirect::back();
     } else {
         Session::flash('error_msg', 'Please enter emails to sent referral email');
         return Redirect::back();
     }
 }
Exemplo n.º 2
0
 public function getUpChain($user_id)
 {
     //Find if any one referred this user if yes always will be only 1
     $user = UserReferral::where('user_id', $user_id)->first();
     if (!empty($user)) {
         array_push($this->chain, $user->user_id);
         $this->depth++;
         //User have a referral .
         if ($user->referral_id > 0) {
             $this->getUpChain($user->referral_id);
         }
     } else {
         //this was first user who started referral system
         array_push($this->chain, $user_id);
         array_splice($this->chain, 0, 1);
         return;
     }
 }
Exemplo n.º 3
0
 private function addUsers()
 {
     $password = Hash::make('311311');
     $user = new User();
     $user->name = "Imran Iqbal";
     $user->email = "*****@*****.**";
     $user->password = $password;
     $user->referral_code = Utils::generateReferralCode();
     $user->activated = 1;
     $user->save();
     $user_groups = new \Cashout\Models\UsersGroups();
     $user_groups->group_id = 2;
     $user_groups->user_id = $user->id;
     $user_groups->save();
     $user = new User();
     $user->name = "Imran Iqbal";
     $user->email = "*****@*****.**";
     $user->password = $password;
     $user->referral_code = Utils::generateReferralCode();
     $user->activated = 1;
     $user->save();
     $user_groups = new \Cashout\Models\UsersGroups();
     $user_groups->group_id = 2;
     $user_groups->user_id = $user->id;
     $user_groups->save();
     $this->command->info("Created Admins Vincent and Imran ....");
     for ($i = 1; $i < 20; $i++) {
         $user = new User();
         $user->name = "User {$i}";
         $user->email = "user{$i}@gmail.com";
         $user->password = $password;
         $user->referral_code = Utils::generateReferralCode();
         $user->activated = 1;
         $user->save();
         $user_groups = new \Cashout\Models\UsersGroups();
         $user_groups->group_id = 1;
         $user_groups->user_id = $user->id;
         $user_groups->save();
         $this->command->info("User {$i} ....");
     }
     $this->command->info('Seeding referrals ....');
     $user_referral = new UserReferral();
     $user_referral->referral_id = 1;
     $user_referral->user_id = 2;
     $user_referral->save();
     $user_referral = new UserReferral();
     $user_referral->referral_id = 1;
     $user_referral->user_id = 3;
     $user_referral->save();
     $user_referral = new UserReferral();
     $user_referral->referral_id = 2;
     $user_referral->user_id = 4;
     $user_referral->save();
     $user_referral = new UserReferral();
     $user_referral->referral_id = 2;
     $user_referral->user_id = 5;
     $user_referral->save();
     $user_referral = new UserReferral();
     $user_referral->referral_id = 3;
     $user_referral->user_id = 6;
     $user_referral->save();
     $user_referral = new UserReferral();
     $user_referral->referral_id = 3;
     $user_referral->user_id = 7;
     $user_referral->save();
     $user_referral = new UserReferral();
     $user_referral->referral_id = 4;
     $user_referral->user_id = 8;
     $user_referral->save();
     $user_referral = new UserReferral();
     $user_referral->referral_id = 4;
     $user_referral->user_id = 9;
     $user_referral->save();
     $user_referral = new UserReferral();
     $user_referral->referral_id = 5;
     $user_referral->user_id = 10;
     $user_referral->save();
     $user_referral = new UserReferral();
     $user_referral->referral_id = 5;
     $user_referral->user_id = 11;
     $user_referral->save();
     $this->command->info('Done ....');
 }