public static function transfersTwitcher(User $user, $limit = 50) { return UserTransfer::whereSellerId($user->id)->paginate($limit); }
public static function pay(User $user, Banner $banner, Stream $stream) { $pivot = self::getPivot($banner, $stream); $amount = round($pivot->amount, 2); $share = Config::get('banner.withdrawal_share'); $twitcherShare = (100 - $share) / 100; $paymentForTwitcher = $pivot->amount * $twitcherShare; $twitcher = $stream->user; $twitcher->balance = $twitcher->balance + $paymentForTwitcher; $twitcher->save(); $user->balance_blocked = $user->balance_blocked - $amount; if ($user->balance_blocked < 0) { $user->balance_blocked = 0; } $user->balance = $user->balance - $amount; if ($user->balance < 0) { $user->balance = 0; } $user->save(); $transfer = UserTransfer::create(['buyer_id' => $user->id, 'seller_id' => $twitcher->id, 'title' => 'Paid banner#' . $banner->id, 'amount' => $paymentForTwitcher, 'currency' => 'USD']); self::referrerPay($transfer); $pivot->status = 'accepted'; $pivot->transfer_id = $transfer->id; $pivot->save(); return $transfer; }