/**
  * Show transaction history, reward from published article which approved by admin,
  * and application request to withdraw reward money.
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function index()
 {
     $filter_data = Input::has('data') ? Input::get('data') : 'all';
     $filter_status = 'all';
     $filter_by = Input::has('by') ? Input::get('by') : 'date';
     $filter_sort = Input::has('sort') ? Input::get('sort') : 'desc';
     $transaction = new Transaction();
     $transactions = $transaction->retrieveTransaction($filter_data, $filter_status, $filter_by, $filter_sort)->whereContributorId(Auth::user()->id)->paginate(10);
     $deferred = $this->getDefferWithdrawal();
     return view('contributor.wallet', compact('transactions', 'deferred'));
 }
 /**
  * Show all transactions with filter and query.
  *
  * @return \Illuminate\View\View
  */
 public function index()
 {
     /*
      * --------------------------------------------------------------------------
      * Filtering transaction
      * --------------------------------------------------------------------------
      * Populate optional filter on url break down in data, sorting by and sorting
      * method, retrieve the transaction.
      */
     $filter_data = Input::has('data') ? Input::get('data') : 'all';
     $filter_status = Input::has('status') ? Input::get('status') : 'all';
     $filter_by = Input::has('by') ? Input::get('by') : 'date';
     $filter_sort = Input::has('sort') ? Input::get('sort') : 'desc';
     $query = Input::has('query') ? Input::get('query') : null;
     $countWithdrawal = Transaction::where('type', Transaction::TYPE_WITHDRAWAL)->count();
     $countReward = Transaction::where('type', Transaction::TYPE_REWARD)->count();
     $sumWithdrawal = Transaction::where('type', Transaction::TYPE_WITHDRAWAL)->sum('amount');
     $sumReward = Transaction::where('type', Transaction::TYPE_REWARD)->sum('amount');
     $transaction = new Transaction();
     $transactions = $transaction->retrieveTransaction($filter_data, $filter_status, $filter_by, $filter_sort, $query)->paginate(10);
     return view('admin.transaction.index', compact('transactions', 'countWithdrawal', 'countReward', 'sumWithdrawal', 'sumReward'));
 }
Ejemplo n.º 3
0
 /**
  * Send email notification to followers that contributor create new article.
  *
  * @param $article
  */
 public function sendEmailNotification($article)
 {
     $contributor = $article->contributor;
     // add reward
     if ($article->reward <= 0) {
         $result = DB::transaction(function () use($article, $contributor) {
             try {
                 $rewardValue = Setting::whereKey('Article Reward')->first()->value;
                 if ($rewardValue > 0) {
                     $article->reward = $rewardValue;
                     $article->save();
                     $contributor->balance = $contributor->balance + $rewardValue;
                     $contributor->save();
                     $transaction = Transaction::create(['contributor_id' => $contributor->id, 'type' => Transaction::TYPE_REWARD, 'description' => "You've got " . number_format($rewardValue, 0, ',', '.') . " for article " . $article->title, 'amount' => $rewardValue, 'status' => Transaction::STATUS_SUCCESS]);
                     return $transaction;
                 }
                 return null;
             } catch (\Exception $e) {
                 return redirect()->back()->withErrors(['error' => Lang::get('alert.error.transaction')])->withInput();
             }
         });
         if ($result instanceof RedirectResponse) {
             return $result;
         }
         // notify the contributor
         Mail::send('emails.published', ['article' => $article, 'contributor' => $contributor], function ($message) use($article, $contributor) {
             $message->from(env('MAIL_ADDRESS', '*****@*****.**'), env('MAIL_NAME', 'Infogue.id'));
             $message->replyTo('*****@*****.**', env('MAIL_NAME', 'Infogue.id'));
             $message->to($contributor->email)->subject('Your article ' . $article->title . ' was published');
         });
         // send email
         $followers = $contributor->followers;
         foreach ($followers as $follower) {
             $follower = $follower->contributor;
             if ($follower->email_feed) {
                 $data = ['receiverName' => $follower->name, 'receiverUsername' => $follower->username, 'contributorName' => $contributor->name, 'contributorLocation' => $contributor->location, 'contributorUsername' => $contributor->username, 'contributorAvatar' => $contributor->avatar, 'contributorArticle' => $contributor->articles()->count(), 'contributorFollower' => $contributor->followers()->count(), 'contributorFollowing' => $contributor->following()->count(), 'article' => $article];
                 Mail::send('emails.stream', $data, function ($message) use($follower, $contributor) {
                     $message->from(env('MAIL_ADDRESS', '*****@*****.**'), env('MAIL_NAME', 'Infogue.id'));
                     $message->replyTo('*****@*****.**', env('MAIL_NAME', 'Infogue.id'));
                     $message->to($follower->email)->subject($contributor->name . ' create new article');
                 });
             }
         }
     }
 }