Ejemplo n.º 1
0
 public function declineSave($streamId, $bannerId, Request $request)
 {
     $stream = Stream::findOrFail($streamId);
     $banner = Banner::findOrFail($bannerId);
     if (!StreamMapper::checkOwner($this->user, $banner, $stream)) {
         return Redirect::to('/user/client/streams')->withErrors('You have no rights for this');
     }
     if ($stream->time_end == null) {
         return Redirect::to('/user/client/stream/' . $stream->id)->withErrors('Stream is still live');
     }
     $pivot = StreamMapper::getPivot($banner, $stream);
     if ($pivot->status != 'waiting') {
         return Redirect::to('/user/client/stream/' . $stream->id)->withErrors('Stream is not for paying');
     }
     $isFinished = $this->isStreamFinished($stream);
     if (!$isFinished) {
         return Redirect::to('/user/client/stream/' . $stream->id)->withErrors('Stream is still alive');
     }
     $this->validate($request, ['comment' => 'required|min:5']);
     $comment = $request->get('comment');
     $pivot->status = 'declining';
     $pivot->client_comment = $comment;
     $pivot->save();
     LogMapper::log('banner_declining', $banner->id, $stream->id);
     NotificationMapper::bannerPayDeclining($banner, $stream, $pivot->amount);
     return Redirect::to('/user/client/stream/' . $stream->id)->with(['success' => 'You declined to pay the banner in this stream']);
 }
Ejemplo n.º 2
0
 public function payStreams()
 {
     $bannerStreams = BannerStream::whereStatus('waiting')->get();
     $faker = $this->faker;
     foreach ($bannerStreams as $bs) {
         $skip = boolval(rand(0, 1));
         if ($skip) {
             continue;
         }
         $banner = $bs->banner;
         $user = $banner->client;
         $stream = $bs->stream;
         $transfer = StreamMapper::pay($user, $banner, $stream);
         $decline = rand(0, 5);
         if ($decline == 4) {
             $bs->status = 'declining';
             $bs->client_comment = $faker->paragraph;
             $bs->save();
             LogMapper::log('banner_declining', $banner->id, $stream->id);
             NotificationMapper::bannerPayDeclining($banner, $stream, $bs->amount);
         } else {
             $bs->status = 'accepted';
             $bs->save();
             LogMapper::log('banner_paid', $banner->id, $stream->id);
             NotificationMapper::bannerPayAccept($banner, $stream, $bs->amount);
         }
     }
 }