Ejemplo n.º 1
0
 public function index()
 {
     $notifications = NotificationMapper::fresh($this->user, 10);
     $showWelcome = $this->user->is_welcomed == 0;
     if ($showWelcome) {
         $this->user->is_welcomed = 1;
         $this->user->save();
     }
     return view('app.pages.user.client.index', compact('notifications', 'showWelcome'));
 }
Ejemplo n.º 2
0
 public function streamer($bannerStreamId)
 {
     $bannerStream = BannerStream::findOrFail($bannerStreamId);
     $banner = $bannerStream->banner;
     $stream = $bannerStream->stream;
     $client = $banner->client;
     StreamMapper::pay($client, $banner, $stream);
     LogMapper::log('banner_paid', $banner->id, $stream->id);
     LogMapper::log('decline_resolve', $banner->id, $stream->id, ['resolution' => 'streamer wins']);
     NotificationMapper::bannerPayAccept($banner, $stream, $bannerStream->amount);
     return redirect('/admin/decline')->with(['success' => 'You accepted streamer\'s point of view']);
 }
Ejemplo n.º 3
0
 public function password(Request $request)
 {
     $rules = ['password' => 'required|min:6|max:20', 'new_password' => 'required|min:6|max:20|different:password', 'new_password2' => 'required|same:new_password'];
     $this->validate($request, $rules);
     $password = $request->get('password');
     $newPassword = $request->get('new_password');
     if (!Hash::check($password, $this->user->password)) {
         return redirect('/user/client/profile')->withErrors(['password' => 'Wrong current password']);
     }
     $this->user->password = bcrypt($newPassword);
     $this->user->save();
     NotificationMapper::notify($this->user, 'You changed your password');
     return redirect('/user/client/profile')->with('success', 'Your password was changed');
 }
Ejemplo n.º 4
0
 public function index()
 {
     $this->updateStatistics();
     $banners = [];
     $bannerTypes = $this->user->bannerTypes;
     $notifications = NotificationMapper::fresh($this->user, 10);
     $waitingBanners = BannerMapper::waitingTwitcher($this->user);
     foreach ($bannerTypes as $bt) {
         $banners[$bt->id] = BannerMapper::activeTwitcher($this->user, $bt->id);
     }
     $activeBanners = BannerMapper::activeTwitcher($this->user);
     $showWelcome = $this->user->is_welcomed == 0;
     if ($showWelcome) {
         $this->user->is_welcomed = 1;
         $this->user->save();
     }
     return view('app.pages.user.twitcher.index', compact('banners', 'bannerTypes', 'notifications', 'waitingBanners', 'activeBanners', 'showWelcome'));
 }
Ejemplo n.º 5
0
 public function withdraw()
 {
     $user = User::whereType('twitcher')->where('balance', '>', 0.1)->get();
     if (count($user) > 10) {
         $user = $user->random(10);
     }
     $faker = $this->faker;
     foreach ($user as $u) {
         try {
             $account = $faker->freeEmail;
             $amount = rand(3, $u->availableBalance());
             PaymentMapper::withdrawPaypalPrepare($u, $account, $amount);
             NotificationMapper::withdraw($u, $amount, 'USD', 'paypal', $account);
             LogMapper::log('withdraw', $u->id, 'request', ['account' => $account, 'merchant' => 'paypal', 'amount' => $amount]);
         } catch (\Exception $e) {
             dd($e->getTraceAsString());
         }
     }
 }
Ejemplo n.º 6
0
 public function declineSave($withdrawId, Request $request)
 {
     $rules = ['comment' => 'required|min:5|max:255'];
     $this->validate($request, $rules);
     $withdrawal = Withdrawal::findOrFail($withdrawId);
     $withdrawal->admin_id = $this->user->id;
     $withdrawal->admin_comment = $request->get('comment');
     $withdrawal->status = 'declined';
     $user = $withdrawal->user;
     $user->balance_blocked = $user->balance_blocked - $withdrawal->amount;
     if ($user->balance_blocked < 0) {
         $user->balance_blocked = 0;
     }
     $withdrawal->save();
     $user->save();
     NotificationMapper::withdrawDecline($withdrawal);
     LogMapper::log('withdraw_decline', $withdrawal->id, $withdrawal->amount, $withdrawal->toArray());
     return redirect('/admin/withdraw/' . $withdrawal->id . '/show')->with(['success' => 'Withdraw declined']);
 }
Ejemplo n.º 7
0
 public function complainDeclineSave($streamId, $bannerId, Request $request)
 {
     $stream = Stream::findOrFail($streamId);
     $banner = Banner::findOrFail($bannerId);
     if ($stream->user_id != $this->user->id) {
         return Redirect::to('/user/twitcher/streams')->withErrors('You have no rights for this');
     }
     $pivot = StreamMapper::getPivot($banner, $stream);
     if ($pivot->status != 'declining') {
         return Redirect::to('/user/twitcher/stream/' . $stream->id)->withErrors('Stream is not declining');
     }
     $this->validate($request, ['comment' => 'required|min:5']);
     $comment = $request->get('comment');
     $pivot->status = 'complain';
     $pivot->twitcher_comment = $comment;
     $pivot->save();
     LogMapper::log('banner_complained', $banner->id, $stream->id);
     NotificationMapper::bannerPayComplained($banner, $stream, $pivot->amount);
     return Redirect::to('/user/twitcher/stream/' . $stream->id)->with(['success' => 'You complained about banner declined']);
 }
Ejemplo n.º 8
0
 public function addBanners($limit = 2000)
 {
     $clients = User::whereType('client')->get();
     $twitchers = User::whereType('twitcher')->get();
     $bannerTypes = $this->data['bannerTypes'];
     $faker = $this->faker;
     $i = 0;
     foreach ($clients as $c) {
         try {
             $bannerCounts = rand(0, 4);
             if ($i > $limit) {
                 //continue;
             }
             for ($i = 0; $i < $bannerCounts; $i++) {
                 $bannerType = $bannerTypes->random();
                 $twitcher = $twitchers->random();
                 if (BannerMapper::twitcherFree($twitcher, $bannerType->id)) {
                     $limit = rand(0, $c->balance);
                     if ($limit > 0) {
                         $requiredSizes = explode('*', $bannerType->title);
                         $w = $requiredSizes[0];
                         $h = $requiredSizes[1];
                         $file = $faker->imageUrl($w, $h);
                         $banner = BannerMapper::addForTwitcher($twitcher, $c, $bannerType, $file, $limit);
                         NotificationMapper::bannerAdd($banner);
                         LogMapper::log('banner_add', $banner->id);
                         $accept = rand(0, 10);
                         $i++;
                         if ($accept != 0) {
                             BannerMapper::acceptBanner($banner);
                         } else {
                             BannerMapper::declineBanner($banner);
                         }
                     }
                 }
             }
         } catch (\Exception $e) {
             dd($e->getTraceAsString());
         }
     }
 }
Ejemplo n.º 9
0
 public function stream($userId)
 {
     $user = User::findOrFail($userId);
     $banners = BannerMapper::activeTwitcher($user);
     if (count($banners) == 0) {
         echo 'no banners';
         die;
     }
     $faker = FakerFactory::create();
     $streamDate = \Carbon\Carbon::createFromTimestamp($faker->dateTimeBetween($user->created_at)->getTimestamp());
     $stream = Stream::create(['user_id' => $user->id, 'time_start' => $streamDate]);
     BannerMapper::bannersToStream($stream, $banners);
     LogMapper::log('stream_start', $stream->id);
     foreach ($banners as $b) {
         NotificationMapper::bannerStream($b, $stream);
     }
     $maxMinutes = rand(3, 30);
     for ($m = 0; $m < $maxMinutes; $m++) {
         $startTime = $streamDate->getTimestamp();
         $endTime = $streamDate->addMinutes(10)->getTimestamp();
         $startTime = \Carbon\Carbon::createFromTimestamp($startTime);
         $endTime = \Carbon\Carbon::createFromTimestamp($endTime);
         $streamDate = $endTime;
         $status = rand(0, 1);
         if ($status == 1) {
             $screenshot = $faker->imageUrl(640, 360);
             $viewers = rand(0, 100);
             $response = (object) ['stream' => (object) ['viewers' => $viewers, 'preview' => (object) ['medium' => $faker->imageUrl(640, 360)]]];
             $streamTimelog = StreamTimelog::create(['stream_id' => $stream->id, 'timeslot_start' => $startTime, 'timeslot_end' => $endTime, 'viewers' => $viewers, 'status' => 'live', 'screenshot' => $screenshot, 'response' => $response]);
             foreach ($banners as $b) {
                 BannerMapper::trackBanner($b, $stream, $streamTimelog);
             }
         } else {
             $streamTimelog = StreamTimelog::create(['stream_id' => $stream->id, 'timeslot_start' => $startTime, 'timeslot_end' => $endTime, 'viewers' => 0, 'status' => 'died', 'screenshot' => '', 'response' => (object) []]);
         }
     }
     $stream->time_end = $streamDate;
     $stream->save();
 }
Ejemplo n.º 10
0
 public function coupon(Request $request)
 {
     $rules = ['coupon' => 'required|min:3|max:25'];
     $this->validate($request, $rules);
     $couponCode = $request->get('coupon');
     $coupon = CouponMapper::byCode($couponCode);
     if (!$coupon) {
         return Redirect::back()->withErrors(['coupon' => 'This coupon is not valid'])->withInput(['coupon' => $couponCode]);
     }
     if (CouponMapper::usedByUser($this->user, $coupon)) {
         return Redirect::back()->withErrors(['coupon' => 'You already have used this coupon'])->withInput(['coupon' => $couponCode]);
     }
     switch ($coupon->code) {
         case 'ADD25USD':
             CouponMapper::track($this->user, $coupon);
             $this->user->balance = $this->user->balance + 25;
             $this->user->save();
             NotificationMapper::coupon($this->user, $coupon);
             LogMapper::log('coupon', $coupon->code, $this->user->id);
             return Redirect::back()->with(['success' => $coupon->title]);
             break;
     }
     return Redirect::back()->withErrors(['coupon' => 'Coupon is not ready yet']);
 }
Ejemplo n.º 11
0
 public static function referralAdded(User $user, User $referrer)
 {
     $title = '<a href="/profile/' . $user->id . '">' . $user->name . '</a> registered as your referral';
     NotificationMapper::notify($referrer, $title, 'money');
 }
Ejemplo n.º 12
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.º 13
0
 public function postClientSignUp(Request $request)
 {
     $rules = ['email' => 'required|email', 'password' => 'required|min:6|max:20', 'password2' => 'required|same:password'];
     $this->validate($request, $rules);
     $name = $request->get('name', '');
     $email = $request->get('email');
     $password = $request->get('password');
     $localUser = UserMapper::getByEmail($email);
     if ($localUser && $localUser->type == 'client') {
         return Redirect::back()->withErrors(['email' => 'Client with this email already exists'])->withInput($request->all());
     }
     if ($name == '') {
         $name = anonymizeEmail($email);
     }
     $data = ['name' => $name, 'email' => $email, 'password' => $password];
     $localUser = $this->create($data);
     $localUser->is_active = 0;
     $localUser->role = 'user';
     $localUser->type = 'client';
     $localUser->save();
     LogMapper::log('client_register', $localUser->id);
     NotificationMapper::registration($localUser);
     $this->sendClientWelcome($localUser, $password);
     $user = $localUser;
     return view('app.pages.user.client.auth.post_register', compact('user'));
 }
Ejemplo n.º 14
0
 public static function referrerPay(UserTransfer $transfer)
 {
     $seller = $transfer->seller;
     $referrer = $seller->referrer;
     if ($referrer) {
         $share = Config::get('banner.referral_share');
         $referrerShare = $share / 100;
         $amount = $transfer->amount * $referrerShare;
         $amount = round($amount, 2);
         if ($amount == 0) {
             return false;
         }
         $referral = Referral::create(['user_id' => $transfer->seller_id, 'referral_id' => $transfer->seller->referral_id, 'transfer_id' => $transfer->id, 'amount' => $amount, 'currency' => $transfer->currency]);
         $referrer->balance = $referrer->balance + $amount;
         $referrer->save();
         NotificationMapper::referralPaid($referral);
         return true;
     }
     return false;
 }
Ejemplo n.º 15
0
 public function fresh()
 {
     $notifications = NotificationMapper::fresh($this->user, 10);
     $html = view('app.pages.user.client.notification.ajax', compact('notifications'))->render();
     return ['html' => $html];
 }
Ejemplo n.º 16
0
 public function stripe(Request $request)
 {
     $rules = ['amount' => 'required|numeric|min:5|max:1000', 'card_number' => 'required|digits_between:6,21', 'card_holder' => 'required|min:2|max:250', 'card_year' => 'required|numeric|min:1900|max:' . (date('Y') + 10), 'card_month' => 'required|numeric|min:1|max:12', 'card_cvc' => 'required|numeric|min:100|max:999'];
     $this->validate($request, $rules);
     $amount = $request->get('amount');
     $card_number = $request->get('card_number');
     $card_holder = $request->get('card_holder');
     $card_year = $request->get('card_year');
     $card_month = $request->get('card_month');
     $card_cvc = $request->get('card_cvc');
     $stripeService = new StripePaymentService();
     $card = ['number' => $card_number, 'exp_month' => $card_month, 'exp_year' => $card_year, 'cvc' => $card_cvc, 'name' => $card_holder];
     try {
         $charge = $stripeService->refill($card, $amount, $this->user);
         LogMapper::log('stripe_success', $amount, $this->user->id, ['response' => $stripeService->response]);
     } catch (\Exception $e) {
         LogMapper::log('stripe_error', $e->getMessage(), 'stripe_card', ['user' => $this->user->id, 'card' => $card, 'amount' => $amount]);
         return Redirect::to('/user/client/billing')->withErrors(['stripe' => 'Failed payment']);
     }
     $payment = PaymentMapper::refillFromStripe($this->user, $stripeService);
     LogMapper::log('payment', $amount, 'refilled', ['payment_id' => $payment->id, 'merchant' => 'stripe']);
     NotificationMapper::refilled($payment);
     return Redirect::to('/user/client/billing')->with(['success' => 'We got your payment']);
 }
Ejemplo n.º 17
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);
         }
     }
 }
Ejemplo n.º 18
0
 public static function trackBanner(Banner $banner, Stream $stream, StreamTimelog $streamTimelog)
 {
     $price = $streamTimelog->price();
     $duration = $streamTimelog->duration();
     $pivotBannerStream = BannerStream::whereBannerId($banner->id)->whereStreamId($stream->id)->first();
     $pivotBannerStream->minutes = $pivotBannerStream->minutes + $duration;
     $pivotBannerStream->viewers = $pivotBannerStream->viewers + $streamTimelog->viewers;
     $pivotBannerStream->amount = $pivotBannerStream->amount + $price;
     $pivotBannerStream->save();
     $client = $banner->client;
     $client->balance_blocked = $client->balance_blocked + $price;
     $client->save();
     $usedAmount = BannerStream::whereBannerId($banner->id)->sum('amount');
     if ($banner->amount_limit <= $usedAmount) {
         $banner->is_active = 0;
         $banner->status = 'finished';
         $banner->save();
         NotificationMapper::bannerFinished($banner);
     }
     if ($client->availableBalance() <= 0) {
         $banner->is_active = 0;
         $banner->status = 'finished';
         $banner->save();
         NotificationMapper::emptyBalance($banner);
     }
     return $pivotBannerStream;
 }
Ejemplo n.º 19
0
 public function clients($limit = 1000)
 {
     $faker = $this->faker;
     for ($i = 0; $i < $limit; $i++) {
         $user = User::create(['name' => $faker->firstName, 'email' => $faker->freeEmail, 'password' => bcrypt('1'), 'last_activity' => \Carbon\Carbon::createFromTimestamp($faker->unixTime), 'role' => 'user', 'type' => 'client', 'provider' => 'local', 'balance' => rand(0, 100)]);
         $profile = UserProfile::create(['first_name' => $user->name, 'last_name' => $faker->lastName, 'user_id' => $user->id]);
         LogMapper::log('client_register', $user->id);
         NotificationMapper::registration($user);
     }
 }