/**
  * Show artist profile
  * 
  * return @Response
  */
 public function showprofile($user)
 {
     $profile = User::where('profile_url', '=', $user)->where('approved', '=', '0')->where('deleted_at', '=', null)->first();
     if (!is_null($profile)) {
         $activation = Activation::where('user', '=', $profile->id)->first();
         $page = Page::where('title', '=', 'faq-artist')->first();
         $transactions = Purchase::where('artist', '=', $profile->id)->get();
         if ($activation) {
             return View::make('artist.not-activated');
         } else {
             if ($profile) {
                 if ($profile->active == 1) {
                     $songs = Song::where('artist', '=', $profile->id)->where('completed', '=', '1')->orderBy('id', 'desc')->paginate(10);
                     $bundles = Bundle::where('artist', '=', $profile->id)->get();
                     $wall = new \Illuminate\Database\Eloquent\Collection();
                     $wall = $wall->merge($songs);
                     $wall = $wall->merge($bundles);
                     //dd($wall);
                     $followers = Follow::where('artist', '=', $profile->id)->get();
                     $countries = [];
                     foreach ($followers as $f) {
                         if (empty($f->profile->country)) {
                             $f->profile->country = 'Country unknown';
                         }
                         if (isset($countries[$f->profile->country])) {
                             $countries[$f->profile->country]++;
                         } else {
                             $countries[$f->profile->country] = 1;
                         }
                     }
                     $events = ArtistEvent::where('artist', '=', $profile->id)->where('date', '>', \Carbon\Carbon::now())->orderBy('id', 'desc')->take(3)->get();
                     $songs_in = [];
                     foreach ($songs as $s) {
                         $songs_in[] = $s->id;
                     }
                     if (count($songs_in) > 0) {
                         $comments = Comment::whereIn('song', $songs_in)->orderBy('id', 'desc')->take(3)->get();
                     } else {
                         $comments = "";
                     }
                     $wall->sortByDesc('created_at');
                     //dd($wall);
                     $notifications = MyNotification::where('user', '=', $profile->id)->get();
                     return View::make('artist.profile-new', ['profile' => $profile, 'songs' => $songs, 'events' => $events, 'comments' => $comments, 'notifications' => $notifications, 'wall' => $wall, 'page' => $page, 'transactions' => $transactions, 'countries' => $countries]);
                 } else {
                     return Redirect::to('profile/settings');
                 }
             } else {
                 App::abort(404);
             }
         }
     } else {
         App::abort(404);
     }
 }
 public static function enableNameOverride()
 {
     self::$shouldOverrideName = true;
 }
Esempio n. 3
0
 public function fire($job, $data)
 {
     // Fetching Transaction
     $t = MyTransaction::where('paypal_id', '=', $data['transaction'])->first();
     $t->status = "COMPLETE";
     $t->save();
     // Fetching songs also checking if the exists
     $songs = $t->songs;
     $bundles = $t->bundles;
     //Work with songs
     $sarr = explode(",", $songs);
     $for_sending = [];
     foreach ($sarr as $s) {
         if (is_numeric($s)) {
             $song = Song::find($s);
             if (!is_null($song)) {
                 $artist = User::where('id', '=', $song->artist)->first();
                 $for_sending[$artist->id] = true;
                 // Paying out to artist
                 $fee = $song->price / 100 * 46;
                 $amount = $song->price - $fee;
                 if ($song->charity && $song->charity_approved == 1) {
                     $share = $song->charity_share;
                     if ($share > 0) {
                         $full_payment = $amount;
                         $charity_fee = $amount / 100 * $share;
                         //$charity_to_pay = $amount - $charity_fee;
                         $amount = $amount - $charity_fee;
                         if ($share == 100) {
                             $amount = 0;
                         }
                         $charity_to_pay = $full_payment - $amount;
                         $charity = Charity::find($song->charity);
                         $charity_user = User::where('charity_id', '=', $charity->id)->first();
                         $charity->donated += $charity_to_pay;
                         $charity->save();
                         //Send email to the charity
                         $m = new Mailer();
                         $m->send($charity_user, 'emails.charity_notification', [], array('subject' => 'Music Equity Payment for Charity Confirmation', 'from' => '*****@*****.**'));
                         //Send email to the administrator
                         $admin_user = new User();
                         $admin_user->email = '*****@*****.**';
                         $m = new Mailer();
                         $m->send($admin_user, 'emails.admin_notification', ['artist' => $artist->artist_name, 'song_cost' => $song->price, 'sum' => $charity_to_pay, 'charity' => $charity->name], array('subject' => 'Music Equity Payment for Charity Confirmation', 'from' => '*****@*****.**'));
                         $paypal_for_charity = $charity_user->paypal;
                         //Log::info('Artist - '. $amount . ' ---- Charity - '. $charity_to_pay);
                         $p = new MassPay();
                         $result = $p->pay($charity_user->paypal, $charity_to_pay);
                     }
                 }
                 if ($amount > 0) {
                     $p = new MassPay();
                     $result = $p->pay($artist->paypal, $amount);
                 }
                 // Registering new purchase of every single song
                 $p = new Purchase();
                 $p->customer = $t->customer;
                 $p->email = $data['email'];
                 $p->song = $s;
                 $p->code = $data['transaction'];
                 $p->artist = $song->artist;
                 $p->paid = $result;
                 $p->topay = $amount;
                 $p->save();
                 // Generating download links for every single song
                 $d = new Download();
                 $d->url = str_random(40);
                 $d->counter = 10;
                 $d->email = $data['email'];
                 $d->customer = $t->customer;
                 $d->song = $s;
                 $d->save();
                 // Creating temporary user
                 $tuser = new User();
                 $tuser->email = $data['email'];
                 $m = new Mailer();
                 $m->send($tuser, 'emails.download_song', ['link' => $d->url], array('subject' => 'Music Equity Song Download', 'from' => '*****@*****.**'));
                 Log::info('Sending email to' . $tuser->email);
                 if ($t->customer != 0) {
                     $customer = User::find($t->customer);
                 }
                 $n = new Notification();
                 $n->user = $artist->id;
                 if (@empty($customer->city)) {
                     $city = 'Unknown location';
                 } else {
                     $city = $customer->city;
                 }
                 $n->text = 'Someone in ' . $city . ' just bought your song (' . $song->title . ')';
                 $n->save();
             }
         }
     }
     // Work with albums;
     $sarr = explode(",", $bundles);
     $for_sending_bundles = [];
     foreach ($sarr as $s) {
         if (is_numeric($s)) {
             $bundle = Bundle::find($s);
             if (!is_null($bundle)) {
                 $artist = User::where('id', '=', $bundle->artist)->first();
                 $for_sending_bundles[$artist->id] = true;
                 // Paying out to artist
                 $fee = $bundle->price / 100 * 46;
                 $amount = $bundle->price - $fee;
                 $p = new MassPay();
                 $result = $p->pay($artist->paypal, $amount);
                 // Registering new purchase of album
                 $p = new Purchase();
                 $p->customer = $t->customer;
                 $p->email = $data['email'];
                 $p->song = $s;
                 $p->bundle = true;
                 $p->code = $data['transaction'];
                 $p->artist = $bundle->artist;
                 $p->paid = $result;
                 $p->topay = $amount;
                 $p->save();
                 // Generating download links for every single song
                 $song_in_bundle = BundleList::where('bundle_id', '=', $bundle->id)->lists('song');
                 $url = [];
                 foreach ($song_in_bundle as $sib) {
                     $d = new Download();
                     $d->url = str_random(40);
                     $d->counter = 10;
                     $d->email = $data['email'];
                     $d->customer = $t->customer;
                     $d->song = $sib;
                     $d->save();
                     $url[] = $d->url;
                 }
                 // Creating temporary user
                 $tuser = new User();
                 $tuser->email = $data['email'];
                 $m = new Mailer();
                 $m->send($tuser, 'emails.download_album', ['link' => $url], array('subject' => 'Music Equity Album Download', 'from' => '*****@*****.**'));
                 Log::info('Sending email to' . $tuser->email);
                 if ($t->customer != 0) {
                     $customer = User::find($t->customer);
                 }
                 $n = new Notification();
                 $n->user = $artist->id;
                 if (@empty($customer->city)) {
                     $city = 'Unknown location';
                 } else {
                     $city = $customer->city;
                 }
                 $n->text = 'Someone in ' . $city . ' just bought your album (' . $bundle->name . ')';
                 $n->save();
             }
         }
     }
     //Send emails to artsist
     foreach ($for_sending as $k => $v) {
         $artist = User::find($k);
         // Sending email to the artist
         $m = new Mailer();
         $m->send($artist, 'emails.song_purchase', [], array('subject' => 'Music Equity Purchase Confirmation', 'from' => '*****@*****.**'));
     }
     foreach ($for_sending_bundles as $k => $v) {
         $artist = User::find($k);
         // Sending email to the artist
         $m = new Mailer();
         $m->send($artist, 'emails.album_purchase', [], array('subject' => 'Music Equity Purchase Confirmation', 'from' => '*****@*****.**'));
     }
     $job->delete();
 }