Последняя версия с сервера прошлого разработчика
This commit is contained in:
54
app/Http/Controllers/Auth/AuthenticatedSessionController.php
Executable file
54
app/Http/Controllers/Auth/AuthenticatedSessionController.php
Executable file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*
|
||||
* @return \Inertia\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return Inertia::render('Auth/Login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(LoginRequest $request)
|
||||
{
|
||||
|
||||
$request->authenticate();
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
25
app/Http/Controllers/Auth/EmailVerificationPromptController.php
Executable file
25
app/Http/Controllers/Auth/EmailVerificationPromptController.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
if($request->user()->hasVerifiedEmail()){
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
return Inertia::render('Auth/VerifyEmail');
|
||||
}
|
||||
}
|
||||
66
app/Http/Controllers/Auth/NewPasswordController.php
Executable file
66
app/Http/Controllers/Auth/NewPasswordController.php
Executable file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rules;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
|
||||
return Inertia::render('Auth/ResetPassword', [
|
||||
'token' => $request->route('token'),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => ['required'],
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function ($user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $status == Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', __($status))
|
||||
: back()->with('status', __($status));
|
||||
}
|
||||
}
|
||||
43
app/Http/Controllers/Auth/PasswordResetLinkController.php
Executable file
43
app/Http/Controllers/Auth/PasswordResetLinkController.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return Inertia::render('Auth/ForgotPassword');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
// to send the link, we will examine the response then see the message we
|
||||
// need to show to the user. Finally, we'll send out a proper response.
|
||||
$status = Password::sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
|
||||
return back()->with('status', __($status));
|
||||
}
|
||||
}
|
||||
60
app/Http/Controllers/Auth/RegisteredUserController.php
Executable file
60
app/Http/Controllers/Auth/RegisteredUserController.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rules;
|
||||
use App\Mail\AfterReigsterToAdmin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return Inertia::render('Auth/Register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'first_name' => 'required|string|max:255',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'password' => ['required', Rules\Password::defaults()],
|
||||
]);
|
||||
$user = User::create([
|
||||
'first_name' => $request->first_name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
Mail::to(env('MAIL_ADMIN_EMAIL'))->send(new AfterReigsterToAdmin($user));
|
||||
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
34
app/Http/Controllers/Auth/VerifyEmailController.php
Executable file
34
app/Http/Controllers/Auth/VerifyEmailController.php
Executable file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Auth\EmailVerificationRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request)
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(
|
||||
config('app.frontend_url').RouteServiceProvider::HOME.'?verified=1'
|
||||
);
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(
|
||||
config('app.frontend_url').RouteServiceProvider::HOME.'?verified=1'
|
||||
);
|
||||
}
|
||||
}
|
||||
151
app/Http/Controllers/CommentController.php
Executable file
151
app/Http/Controllers/CommentController.php
Executable file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Domain\Feeds\Models\Feed;
|
||||
use Illuminate\Pagination\Cursor;
|
||||
use App\Notifications\CommentAdded;
|
||||
use App\Domain\Comments\Models\Comment;
|
||||
use Illuminate\Http\Request as HttpRequest;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('subs.paid');
|
||||
}
|
||||
|
||||
public function show($feed_id)
|
||||
{
|
||||
$count_pagination = 50;
|
||||
$cursor_request = request('cursor') ?? null;
|
||||
$feed = Feed::find($feed_id);
|
||||
if(empty($feed)){
|
||||
return [
|
||||
'nextCursor' => null,
|
||||
'items' => []
|
||||
];
|
||||
}
|
||||
$comments = $feed->comments()
|
||||
->where('parent_id', null)
|
||||
->withCount('children')
|
||||
->with('user:id,first_name,last_name,username,photo_path,color,user_char')->cursorPaginate($count_pagination, ['*'], 'cursor', Cursor::fromEncoded($cursor_request));
|
||||
$nextCursor = $comments->nextCursor();
|
||||
if($nextCursor){
|
||||
$nextCursor = $nextCursor->encode();
|
||||
}else{
|
||||
$nextCursor = null;
|
||||
}
|
||||
return [
|
||||
'nextCursor' => $nextCursor,
|
||||
'items' => $comments->transform(function ($item) {
|
||||
$item->childrens = [];
|
||||
$item->closed_children_comments = 1;
|
||||
$item->created_at_humans = $item->created_at->diffForHumans();
|
||||
return $item;
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
public function children($comment_id)
|
||||
{
|
||||
$count_pagination = 50;
|
||||
$cursor_request = request('cursor') ?? null;
|
||||
$comments = Comment::findOrFail($comment_id)
|
||||
->children()
|
||||
->with('user:id,first_name,last_name,username,photo_path,color,user_char', 'answer_to:id,username')
|
||||
->cursorPaginate($count_pagination, ['*'], 'cursor', Cursor::fromEncoded($cursor_request));
|
||||
|
||||
$nextCursor = $comments->nextCursor();
|
||||
if($nextCursor){
|
||||
$nextCursor = $nextCursor->encode();
|
||||
}else{
|
||||
$nextCursor = null;
|
||||
}
|
||||
|
||||
return [
|
||||
'nextCursor' => $nextCursor,
|
||||
'items' => $comments->transform(function ($item) {
|
||||
$item->created_at_humans = $item->created_at->diffForHumans();
|
||||
return $item;
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
public function store(HttpRequest $request, $feed_id)
|
||||
{
|
||||
$disabled_notify_main = 0;
|
||||
$feed = Feed::findOrFail($feed_id);
|
||||
|
||||
$body = $request->input('body');
|
||||
$body = preg_replace('/(?<=\s|^)@\S+/', "", $body);
|
||||
$body = htmlentities(trim($body));
|
||||
|
||||
$to = $request->input('to');
|
||||
$parent = $request->input('parent');
|
||||
|
||||
$comment = new Comment;
|
||||
$comment->body = $body;
|
||||
$comment->user_id = auth()->user()->id;
|
||||
$comment->feed_id = $feed_id;
|
||||
if($parent){
|
||||
$comment->parent_id = $parent;
|
||||
}
|
||||
if($to){
|
||||
$comment->to_user_id = $to;
|
||||
}
|
||||
|
||||
$feed->comments()->save($comment);
|
||||
$comment->setRelation('user', auth()->user());
|
||||
if($to){
|
||||
$toUser = User::find($to);
|
||||
$comment->setRelation('answer_to', $toUser);
|
||||
if($toUser->id !== auth()->user()->id){
|
||||
$disabled_notify_main = 1;
|
||||
$message = [
|
||||
'user_id' => auth()->user()->id,
|
||||
'node_id' => $feed_id,
|
||||
'comment' => $body
|
||||
];
|
||||
$toUser->notify(new CommentAdded($message));
|
||||
}
|
||||
}
|
||||
|
||||
$comment->created_at_humans = $comment->created_at->diffForHumans();
|
||||
|
||||
if(empty($parent)){
|
||||
$comment->childrens = [];
|
||||
$comment->closed_children_comments = 1;
|
||||
}
|
||||
|
||||
if($feed->user_id !== auth()->user()->id && $disabled_notify_main === 0){
|
||||
$message = [
|
||||
'user_id' => auth()->user()->id,
|
||||
'node_id' => $feed_id,
|
||||
'comment' => $body
|
||||
];
|
||||
$feed->user->notify(new CommentAdded($message));
|
||||
}
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
public function remove($comment_id)
|
||||
{
|
||||
$remove_count = 1;
|
||||
$comment = Comment::findOrFail($comment_id);
|
||||
$children_count = $comment->children()->count();
|
||||
if($children_count){
|
||||
$comment->children()->forceDelete();
|
||||
$remove_count = $remove_count + $children_count;
|
||||
}
|
||||
$comment->forceDelete();
|
||||
|
||||
// Comment::destroy($comment_id);
|
||||
return $remove_count;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
101
app/Http/Controllers/ComplaintController.php
Executable file
101
app/Http/Controllers/ComplaintController.php
Executable file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Comments\Models\Comment;
|
||||
use App\Domain\Complaints\Models\CommentComplaint;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Domain\Feeds\Models\Feed;
|
||||
use App\Domain\Complaints\Models\Reason;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use App\Domain\Complaints\Models\Complaint;
|
||||
use App\Domain\Feeds\Queries\FeedQueryBuilder;
|
||||
|
||||
class ComplaintController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('subs.paid');
|
||||
}
|
||||
|
||||
public function index($feed_id)
|
||||
{
|
||||
$feed = Feed::findOrFail($feed_id);
|
||||
if ($feed->user()->is(auth()->user())) {
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
$reasons = Reason::all();
|
||||
$feed = new FeedQueryBuilder();
|
||||
$feed = $feed->selectByIds($feed_id)->disablePaginate()->transformGet()->first();
|
||||
|
||||
return Inertia::render('Complaint/Index', [
|
||||
'user' => $feed['user'],
|
||||
'feed' => $feed,
|
||||
'reasons' => $reasons,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
$feed_id = $request->get('feed');
|
||||
$feed = Feed::findOrFail($feed_id);
|
||||
|
||||
if(empty($request->get('reason'))){
|
||||
return Redirect::back()->with('error', 'Выберите тип жалобы!');
|
||||
}
|
||||
$reason_id = $request->get('reason');
|
||||
$reason = Reason::findOrFail($reason_id);
|
||||
|
||||
$complaint = new Complaint;
|
||||
$complaint->user_id = auth()->user()->id;
|
||||
$complaint->reason_id = $reason->id;
|
||||
$complaint->feed_id = $feed->id;
|
||||
$complaint->save();
|
||||
|
||||
// return Redirect::route('feeds.layoutsidebar')->with('success', 'Жалоба успешно отправлена');
|
||||
return Redirect::back()->with('success', 'Жалоба успешно отправлена');
|
||||
}
|
||||
|
||||
|
||||
public function commentIndex($comment_id)
|
||||
{
|
||||
$comment = Comment::findOrFail($comment_id);
|
||||
if ($comment->user()->is(auth()->user())) {
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
$reasons = Reason::all();
|
||||
$user = $comment->user;
|
||||
$user->name = $user->name;
|
||||
return Inertia::render('Complaint/IndexComment', [
|
||||
'user' => $comment->user,
|
||||
'comment' => $comment,
|
||||
'reasons' => $reasons,
|
||||
]);
|
||||
}
|
||||
|
||||
public function commentStore(Request $request)
|
||||
{
|
||||
$comment_id = $request->get('comment');
|
||||
$comment = Comment::findOrFail($comment_id);
|
||||
|
||||
if(empty($request->get('reason'))){
|
||||
return Redirect::back()->with('error', 'Выберите тип жалобы!');
|
||||
}
|
||||
$reason_id = $request->get('reason');
|
||||
$reason = Reason::findOrFail($reason_id);
|
||||
|
||||
$complaint = new CommentComplaint;
|
||||
$complaint->user_id = auth()->user()->id;
|
||||
$complaint->reason_id = $reason->id;
|
||||
$complaint->comment_id = $comment->id;
|
||||
$complaint->save();
|
||||
|
||||
return Redirect::back()->with('success', 'Жалоба успешно отправлена');
|
||||
}
|
||||
|
||||
}
|
||||
13
app/Http/Controllers/Controller.php
Executable file
13
app/Http/Controllers/Controller.php
Executable file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
92
app/Http/Controllers/DashboardController.php
Executable file
92
app/Http/Controllers/DashboardController.php
Executable file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use App\Mail\FeedbackToAdmin;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Http\Request as HttpRequest;
|
||||
use App\Domain\Feeds\Queries\FeedQueryBuilder;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('subs.paid');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$filter = Request::get('filter');
|
||||
$feeds = (new FeedQueryBuilder())->filter()->search(Request::only('search'))->build();
|
||||
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if($filter === 'hot'){
|
||||
$feeds = $feeds->sortByDesc('entity.likes')->values();
|
||||
}
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('Dashboard/Index', [
|
||||
'searchFilters' => Request::all('search'),
|
||||
'feeds' => $feeds,
|
||||
'nextCursor' => $nextCursor,
|
||||
'active_filter' => $filter ?? 'new'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function commonSendWriteToUs()
|
||||
{
|
||||
return Inertia::render('Auth/Feedback', []);
|
||||
}
|
||||
|
||||
public function sendWriteToUs(HttpRequest $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if($user){
|
||||
$request->validate([
|
||||
'title' => ['required'],
|
||||
'body' => ['required'],
|
||||
]);
|
||||
|
||||
$userInfo = (object)[
|
||||
'userFullName' => $user->name,
|
||||
'userPhone' => $user->phone,
|
||||
'userEmail' => $user->email,
|
||||
'profileUrl' => env('APP_URL') . '/profile/' . $user->username,
|
||||
'guest' => false
|
||||
];
|
||||
}else{
|
||||
$request->validate([
|
||||
'title' => ['required'],
|
||||
'body' => ['required'],
|
||||
'email' => ['required'],
|
||||
]);
|
||||
|
||||
$userInfo = (object)[
|
||||
'userEmail' => request()->post('email'),
|
||||
'guest' => true
|
||||
];
|
||||
}
|
||||
|
||||
$data = (object) [
|
||||
'title' => request()->post('title'),
|
||||
'body' => request()->post('body'),
|
||||
'userInfo' => $userInfo
|
||||
];
|
||||
|
||||
Mail::to(env('MAIL_ADMIN_EMAIL'))->send(new FeedbackToAdmin($data));
|
||||
|
||||
return back()->with('success', 'Сообщение успешно отправлено')->with('status', 'Сообщение успешно отправлено');
|
||||
}
|
||||
|
||||
}
|
||||
234
app/Http/Controllers/FeedsController.php
Executable file
234
app/Http/Controllers/FeedsController.php
Executable file
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use App\Notifications\LikeAdded;
|
||||
use App\Domain\Feeds\Models\Feed;
|
||||
use App\Domain\Points\Models\Point;
|
||||
use App\Notifications\PurchaseAdded;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use App\Domain\Points\Enums\DirectionEnum;
|
||||
use App\Domain\Feeds\Queries\FeedQueryBuilder;
|
||||
use App\Domain\Feeds\Service\FeedMediaTransform;
|
||||
use App\Domain\Subscriptions\Service\SubscriptionService;
|
||||
|
||||
class FeedsController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('subs.paid')->except('comments', 'commentsShowChildren', 'add_view_feed');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$feeds = (new FeedQueryBuilder(auth()->user()->live_feeds()))->enableAdvertising()->build();
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('Feed/Index', [
|
||||
'feeds' => $feeds,
|
||||
'nextCursor' => $nextCursor,
|
||||
'active_button' => ''
|
||||
]);
|
||||
}
|
||||
|
||||
public function onlyImages()
|
||||
{
|
||||
$feeds = (new FeedQueryBuilder(auth()->user()->live_feeds()))->enableAdvertising()->addType('image')->build();
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('Feed/Index', [
|
||||
'feeds' => $feeds,
|
||||
'nextCursor' => $nextCursor,
|
||||
'active_button' => 'image'
|
||||
]);
|
||||
}
|
||||
|
||||
public function onlyVideos()
|
||||
{
|
||||
$feeds = (new FeedQueryBuilder(auth()->user()->live_feeds()))->enableAdvertising()->addType('video')->build();
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('Feed/Index', [
|
||||
'feeds' => $feeds,
|
||||
'nextCursor' => $nextCursor,
|
||||
'active_button' => 'video'
|
||||
]);
|
||||
}
|
||||
public function onlyMusics()
|
||||
{
|
||||
$feeds = (new FeedQueryBuilder(auth()->user()->live_feeds()))->enableAdvertising()->addType('music')->build();
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('Feed/Index', [
|
||||
'feeds' => $feeds,
|
||||
'nextCursor' => $nextCursor,
|
||||
'active_button' => 'music'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function toggleLike($feed_id)
|
||||
{
|
||||
$auth_user = auth()->user();
|
||||
$feed = Feed::findOrFail($feed_id);
|
||||
$check = \DB::table('users_feeds_like')->where('user_id', $auth_user->id)->where('feed_id', $feed_id)->first();
|
||||
// $check_notifications = \DB::table('notifications')
|
||||
// ->where('notifiable_id', $auth_user->id)
|
||||
// ->where('entity_once', $feed_id)
|
||||
// ->where('once', 1)
|
||||
// ->first();
|
||||
|
||||
$auth_user->likes()->toggle([$feed_id]);
|
||||
|
||||
if(!$check && $feed->user_id !== $auth_user->id){
|
||||
$message = [
|
||||
'user_id' => $auth_user->id,
|
||||
'node_id' => $feed_id,
|
||||
];
|
||||
$feed->user->notify(new LikeAdded($message));
|
||||
}
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
public function audioLike($media_id)
|
||||
{
|
||||
sleep(1);
|
||||
auth()->user()->audioLike()->toggle([$media_id]);
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
public function purchase($feed_id)
|
||||
{
|
||||
\DB::beginTransaction();
|
||||
$feed = Feed::findOrFail($feed_id);
|
||||
$price_feed = (int) $feed->price;
|
||||
$balance = SubscriptionService::calculate(auth()->user()->id);
|
||||
$check = \DB::table('user_feed_purchase')->where('user_id', auth()->user()->id)->where('feed_id', $feed_id)->first();
|
||||
if ($check) {
|
||||
return ['error' => 1, 'msg' => 'Вы уже купили данный продукт'];
|
||||
}
|
||||
if ($feed->user()->is(auth()->user())) {
|
||||
return ['error' => 1, 'msg' => 'Ошибка'];
|
||||
}
|
||||
if ($price_feed > $balance) {
|
||||
return ['error' => 1, 'msg' => 'Недостаточно средств'];
|
||||
}
|
||||
$user = auth()->user();
|
||||
$user->purchases()->attach($feed_id, ['amount' => $price_feed]);
|
||||
|
||||
$point = new Point;
|
||||
$point->user_id = $user->id;
|
||||
$point->feed_id = $feed->id;
|
||||
$point->point = $price_feed;
|
||||
$point->type = 'Покупка - ' . $feed->type; //YSV ENUM!
|
||||
$point->direction = DirectionEnum::EXPENSE();
|
||||
$point->save();
|
||||
|
||||
$point = new Point;
|
||||
$point->user_id = $feed->user_id;
|
||||
$point->feed_id = $feed->id;
|
||||
$point->point = $price_feed;
|
||||
$point->type = 'Покупка - ' . $feed->type; //YSV ENUM!
|
||||
$point->direction = DirectionEnum::COMING();
|
||||
$point->save();
|
||||
|
||||
$new_medias = $this->replace(null, $feed);
|
||||
|
||||
$message = [
|
||||
'user_id' => auth()->user()->id,
|
||||
'node_id' => $feed->id,
|
||||
'price' => $price_feed,
|
||||
];
|
||||
$feed->user->notify(new PurchaseAdded($message));
|
||||
|
||||
\DB::commit();
|
||||
|
||||
return $new_medias;
|
||||
}
|
||||
|
||||
public function replace($feed_id = null, $feed = null)
|
||||
{
|
||||
if(empty($feed)){
|
||||
$feed = Feed::findOrFail($feed_id);
|
||||
}
|
||||
|
||||
$preview = '';
|
||||
$medias = [];
|
||||
|
||||
if($feed->is_paid === 1){
|
||||
$mediaTransform = new FeedMediaTransform($feed);
|
||||
$mediaTransform = $mediaTransform->paid()->spot();
|
||||
$preview = $mediaTransform['preview'];
|
||||
$medias = $mediaTransform['medias'];
|
||||
}
|
||||
|
||||
return ['preview' => $preview, 'collection' => $medias];
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function purchase_check($feed_id)
|
||||
{
|
||||
$check = \DB::table('user_feed_purchase')->where('user_id', auth()->user()->id)->where('feed_id', $feed_id)->first();
|
||||
if ($check) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public function add_view_feed($feed_id)
|
||||
{
|
||||
if(!auth()->check()){
|
||||
return 0;
|
||||
}
|
||||
|
||||
$check = \DB::table('users_feeds_view')->where('user_id', auth()->user()->id)->where('feed_id', $feed_id)->first();
|
||||
if(!$check){
|
||||
\DB::table('users_feeds_view')->insert([
|
||||
'user_id' => auth()->user()->id,
|
||||
'feed_id' => $feed_id
|
||||
]);
|
||||
$feed = Feed::findOrFail($feed_id);
|
||||
$feed->increment('views_count');
|
||||
return 1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function destroy(Feed $feed)
|
||||
{
|
||||
if ($feed->user()->is(auth()->user())) {
|
||||
$feed->delete();
|
||||
}
|
||||
|
||||
return Redirect::route('profile.user', auth()->user()->username)->with('success', 'Запись успешно удалена!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
165
app/Http/Controllers/ImagesController.php
Executable file
165
app/Http/Controllers/ImagesController.php
Executable file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
// use Illuminate\Http\Request as HttpRequest;
|
||||
use App\Domain\Feeds\Models\Feed;
|
||||
use App\Domain\Feeds\Enums\StatusEnum;
|
||||
use App\Http\Requests\ImageFormRequest;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use App\Domain\Tags\Action\CreateTagAction;
|
||||
use App\Domain\Feeds\Action\CreateFeedAction;
|
||||
use App\Domain\Feeds\Queries\FeedQueryBuilder;
|
||||
use App\Domain\Images\Action\CreateImageAction;
|
||||
use App\Domain\Images\Action\UpdateImageAction;
|
||||
use App\Domain\Feeds\Service\FeedMediaTransform;
|
||||
use App\Domain\Images\DataTransferObjects\ImageData;
|
||||
|
||||
class ImagesController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('subs.paid')->except('show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$filter = Request::get('filter');
|
||||
|
||||
$feeds = (new FeedQueryBuilder())
|
||||
->addType('image')
|
||||
->enableAdvertising()
|
||||
->search(Request::only('search'))
|
||||
->filter($filter)
|
||||
->build();
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
$route = route('images.index');
|
||||
return Inertia::render('Image/Index', [
|
||||
'nextCursor' => $nextCursor,
|
||||
'searchFilters' => Request::all('search'),
|
||||
'feeds' => $feeds,
|
||||
'local_route' => $route,
|
||||
'active_filter' => $filter ?? 'new'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return Inertia::render('Image/Create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\ImageFormRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(ImageFormRequest $request)
|
||||
{
|
||||
$action = new CreateFeedAction(
|
||||
new CreateImageAction(),
|
||||
new CreateTagAction(),
|
||||
);
|
||||
|
||||
$imageData = ImageData::fromRequest($request);
|
||||
$action($imageData);
|
||||
$msg = 'Изображение успешно загружено и находится на модерации!';
|
||||
return Redirect::route('profile.user', auth()->user()->username)->with('success', $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($slug)
|
||||
{
|
||||
$feed = new FeedQueryBuilder();
|
||||
$feed = $feed->selectBy('slug', $slug)->disablePaginate()->transformGet()->first();
|
||||
if(!$feed){
|
||||
abort(404);
|
||||
}
|
||||
return Inertia::render('Image/Show', [
|
||||
'user' => $feed['user'],
|
||||
'feed' => $feed,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param string $slug
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($slug)
|
||||
{
|
||||
$feed = Feed::where('slug', $slug)->firstOrFail();
|
||||
if (!$feed->user()->is(auth()->user())) {
|
||||
abort(404);
|
||||
}
|
||||
$tags = $feed->tags()->pluck('name')->toArray();
|
||||
|
||||
$mediaTransformCommon = (new FeedMediaTransform($feed))->default()->spot();
|
||||
$mediaTransformPaid = (new FeedMediaTransform($feed))->paid()->spot();
|
||||
|
||||
return Inertia::render('Image/Edit', [
|
||||
'feed' => $feed,
|
||||
'tags' => $tags,
|
||||
'mediasCount' => count($mediaTransformCommon['medias']),
|
||||
'mediasCommon' => $mediaTransformCommon['medias'],
|
||||
'mediasPaid' => $mediaTransformPaid['medias'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(ImageFormRequest $request, Feed $feed)
|
||||
{
|
||||
$oldStatus = $feed->status;
|
||||
if (!$feed->user()->is(auth()->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$action = new CreateFeedAction(
|
||||
new UpdateImageAction($feed),
|
||||
new CreateTagAction(),
|
||||
);
|
||||
|
||||
$imageData = ImageData::fromRequest($request);
|
||||
$action($imageData);
|
||||
|
||||
$newStatus = $feed->status;
|
||||
|
||||
$message = 'Изображение успешно обновлено!';
|
||||
if($oldStatus === StatusEnum::APPROVED() && $newStatus === StatusEnum::EDITABLE()){
|
||||
$message = 'Изображение успешно обновлено и находится на модерации!';
|
||||
}
|
||||
return Redirect::back()->with('success', $message);
|
||||
|
||||
}
|
||||
}
|
||||
331
app/Http/Controllers/MessengerController.php
Executable file
331
app/Http/Controllers/MessengerController.php
Executable file
@@ -0,0 +1,331 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Messenger\Models\ChatRoom;
|
||||
use App\Domain\Messenger\Models\Message;
|
||||
use App\Models\User;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Http\Request as HttpRequest;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
|
||||
class MessengerController extends Controller
|
||||
{
|
||||
|
||||
protected function getSearchByMessage($currentUser, $search)
|
||||
{
|
||||
return $currentUser
|
||||
->chat_rooms()
|
||||
->orderBy('updated_at', 'desc')
|
||||
->with(['messsages' => function ($query) use($search) {
|
||||
$query->where('message', 'ilike', "{$search}%");
|
||||
}, 'users:id,first_name,last_name,username,photo_path,banner_path,color,user_char'])
|
||||
->whereHas('messsages', function (Builder $query) use($search) {
|
||||
$query->where('message', 'ilike', "{$search}%");
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
protected function getSearchByUser($currentUser, $search)
|
||||
{
|
||||
return $currentUser
|
||||
->chat_rooms()
|
||||
->orderBy('updated_at', 'desc')
|
||||
->with(['users:id,first_name,last_name,username,photo_path,banner_path,color,user_char', 'messsages'])
|
||||
->whereHas('users', function (Builder $query) use($search) {
|
||||
$query->where('first_name', 'ilike', '%'.$search.'%')
|
||||
->orWhere('last_name', 'ilike', '%'.$search.'%');
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Если пользователь выбирается по гет параметру
|
||||
$chatSelectUser = null;
|
||||
$chatSelectUserID = 0;
|
||||
if($getUsername = request()->get('user')){
|
||||
$chatSelectUser = User::where('username', $getUsername)->firstOrFail();
|
||||
$chatSelectUser->name = $chatSelectUser->name;
|
||||
$chatSelectUserID = $chatSelectUser->id;
|
||||
}
|
||||
|
||||
$search = request()->get('search');
|
||||
$type = request()->get('type');
|
||||
$currentUser = auth()->user();
|
||||
|
||||
if($search){
|
||||
if($type == 1){
|
||||
$chat_rooms = $this->getSearchByMessage($currentUser, $search);
|
||||
}else{
|
||||
$chat_rooms = $this->getSearchByUser($currentUser, $search);
|
||||
}
|
||||
|
||||
$chat_rooms->transform(function ($room) {
|
||||
$message = $room->messsages->first();
|
||||
$room->latestMessage = $message;
|
||||
return $room;
|
||||
});
|
||||
}else{
|
||||
$chat_rooms = $currentUser
|
||||
->chat_rooms()
|
||||
->orderBy('updated_at', 'desc')
|
||||
->with('latestMessage', 'users:id,first_name,last_name,username,photo_path,banner_path,color,user_char')
|
||||
->get();
|
||||
}
|
||||
|
||||
$rooms = $chat_rooms->map(function ($room) use ($currentUser, $chatSelectUserID) {
|
||||
$is_my_message = false;
|
||||
$classActive = false;
|
||||
if($room->latestMessage->user_id === $currentUser->id){
|
||||
$is_my_message = true;
|
||||
}
|
||||
$message = $room->latestMessage->message;
|
||||
$updated_at_human = $room->latestMessage->created_at->diffForHumans();
|
||||
$updated_at = $room->latestMessage->created_at->format('U');
|
||||
|
||||
$correspond = $room->users->where('id', '<>', $currentUser->id)->first();
|
||||
unset($correspond->pivot);
|
||||
$correspond->name = $correspond->name;
|
||||
if($chatSelectUserID === $correspond->id){ // делаем активным
|
||||
$classActive = true;
|
||||
}
|
||||
return [
|
||||
'id' => $room->id,
|
||||
'is_freeze' => $room->is_freeze,
|
||||
'classActive' => $classActive,
|
||||
'is_my_message' => $is_my_message,
|
||||
'message' => $message,
|
||||
'is_reading' => $room->latestMessage->is_reading,
|
||||
'updated_at' => $updated_at,
|
||||
'updated_at_human' => $updated_at_human,
|
||||
'correspond' => $correspond->toArray(),
|
||||
];
|
||||
});
|
||||
|
||||
if($chatSelectUserID){
|
||||
$checkActiveRoom = $rooms->contains(function ($item) {
|
||||
return $item['classActive'] === true;
|
||||
});
|
||||
if(!$checkActiveRoom){
|
||||
$globalRoomUser = $this->isRoomCreate($chatSelectUserID);
|
||||
if($globalRoomUser){
|
||||
$globalRoomUser->load('latestMessage');
|
||||
$is_my_message = false;
|
||||
if($globalRoomUser->latestMessage->user_id === auth()->user()->id){
|
||||
$is_my_message = true;
|
||||
}
|
||||
$new_room = [
|
||||
'id' => $globalRoomUser->id,
|
||||
'is_freeze' => $globalRoomUser->is_freeze,
|
||||
'classActive' => true,
|
||||
'is_my_message' => $is_my_message,
|
||||
'message' => $globalRoomUser->latestMessage->message,
|
||||
'is_reading' => $globalRoomUser->latestMessage->is_reading,
|
||||
'updated_at' => $globalRoomUser->updated_at->format('U'),
|
||||
'updated_at_human' => $globalRoomUser->updated_at->diffForHumans(),
|
||||
'correspond' => $chatSelectUser->only(['id','name','first_name','last_name','photo_path','banner_path','color','user_char', 'username']),
|
||||
];
|
||||
$rooms[] = $new_room;
|
||||
}
|
||||
}
|
||||
$rooms = $rooms->sortByDesc('classActive')->values();
|
||||
}
|
||||
|
||||
return Inertia::render('Messenger/Index', [
|
||||
'rooms' => $rooms,
|
||||
'roomSearch' => $search,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$room = ChatRoom::findOrFail($id);
|
||||
$search = request()->get('search');
|
||||
|
||||
$messages = $room->messsages()->with('user:id,first_name,photo_path,color,user_char')->orderBy('id');
|
||||
if($search){
|
||||
$messages = $messages->where('message', 'ilike', "{$search}%");
|
||||
}
|
||||
$messages = $messages->cursorPaginate(50);
|
||||
$nextCursor = get_cursor_hash($messages);
|
||||
|
||||
|
||||
|
||||
$messages->each(function ($message) {
|
||||
if($message->is_reading === false && $message->user_id != auth()->user()->id){
|
||||
$message->is_reading = true;
|
||||
$message->save();
|
||||
}
|
||||
$message->group = $message->created_at->format('d.m.Y');
|
||||
$message->created = $message->created_at->format('H:i');
|
||||
return $message;
|
||||
});
|
||||
$messages = $messages->groupBy(function ($val) {
|
||||
return \Carbon\Carbon::parse($val->created_at)->format('d.m.Y');
|
||||
});
|
||||
|
||||
return ['records' => $messages, 'cursor' => $nextCursor];
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function store(HttpRequest $request)
|
||||
{
|
||||
$message = $request->input('params.message');
|
||||
$chat_room_id = $request->input('params.room');
|
||||
$status = $this->createMessage($message, $chat_room_id);
|
||||
if($status === false){
|
||||
return null;
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function storeFromProfile(HttpRequest $request)
|
||||
{
|
||||
$message = $request->input('message');
|
||||
$chat_room_id = $request->input('chat_room');
|
||||
|
||||
$status = $this->createMessage($message, $chat_room_id);
|
||||
if($status === false){
|
||||
return redirect()->back()->with('error', 'Вы не можете отправить сообщение данному пользователю');
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', 'Сообщение успешно отправлено!');
|
||||
}
|
||||
|
||||
protected function createMessage($text, $chat_room_id)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$chatRoom = ChatRoom::find($chat_room_id);
|
||||
if($chatRoom->is_freeze){
|
||||
return false;
|
||||
}
|
||||
$message = new Message;
|
||||
$message->message = $text;
|
||||
$message->user_id = $user->id;
|
||||
$message->chat_room_id = $chat_room_id;
|
||||
$message->save();
|
||||
|
||||
$chatRoom->touch();
|
||||
|
||||
$message->created = $message->created_at->format('H:i');
|
||||
$message->updated_at_room_human = $message->created_at->diffForHumans();
|
||||
$message->updated_at_room = $message->created_at->format('U');
|
||||
$message->group = $message->created_at->format('d.m.Y');
|
||||
$message->keyGroupDate = $message->created_at->format('d.m.Y');
|
||||
$message->user = $user->only(['id','first_name','photo_path','color','user_char']);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function checkRoom(HttpRequest $request)
|
||||
{
|
||||
$userId = $request->input('params.user');
|
||||
$room = $this->isRoomCreate($userId);
|
||||
return $room ? $room->id : 0;
|
||||
}
|
||||
|
||||
protected function isRoomCreate($userId)
|
||||
{
|
||||
return auth()->user()->chat_rooms()->whereHas('users', function (Builder $query) use($userId) {
|
||||
$query->where('id', $userId);
|
||||
})->first();
|
||||
}
|
||||
|
||||
public function createRoom(HttpRequest $request)
|
||||
{
|
||||
$message = $request->input('message');
|
||||
$user_id = $request->input('user_id');
|
||||
|
||||
$existBannedUsers = $this->getBannedUser($user_id);
|
||||
if($existBannedUsers){
|
||||
return redirect()->back()->with('error', 'Вы не можете отправить сообщение данному пользователю');
|
||||
}
|
||||
|
||||
$room = new ChatRoom;
|
||||
$room->save();
|
||||
$room->users()->attach([$user_id, auth()->user()->id]);
|
||||
|
||||
$this->createMessage($message, $room->id);
|
||||
|
||||
return redirect()->back()->with('success', 'Сообщение успешно отправлено!');
|
||||
}
|
||||
|
||||
public function freezeRoom(HttpRequest $request)
|
||||
{
|
||||
$room_id = $request->input('room');
|
||||
$room = ChatRoom::find($room_id);
|
||||
$roomUsers = $room->users;
|
||||
$isAuthUserExist = $roomUsers->contains(fn($user) => $user->id === auth()->user()->id);
|
||||
$correspond = $roomUsers->where('id', '<>', auth()->user()->id)->first();
|
||||
if(!$isAuthUserExist){
|
||||
return redirect()->back()->with('error', 'Доступ запрещен');
|
||||
}
|
||||
|
||||
// добавляем пользователя
|
||||
$status = auth()->user()->bannedUsers()->toggle([$correspond->id]);
|
||||
|
||||
// проверяем есть ли пользователя из чата в черном списке, если есть замораживаем чат
|
||||
$existBannedUsers = $this->getBannedUser($correspond->id);
|
||||
|
||||
if($existBannedUsers){ //disable touch update_at column
|
||||
\DB::table('chat_rooms')->where('id', $room->id)->update(['is_freeze' => true]);
|
||||
}else{
|
||||
\DB::table('chat_rooms')->where('id', $room->id)->update(['is_freeze' => false]);
|
||||
}
|
||||
|
||||
$msg = 'Пользователь успешно удален из чернго списка';
|
||||
if(count($status['attached'])){
|
||||
$msg = 'Пользователь успешно добавлен в черный список';
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', $msg);
|
||||
}
|
||||
|
||||
public function checkBannedUser(HttpRequest $request)
|
||||
{
|
||||
$correspond_id = $request->input('params.user');
|
||||
$partnerIsBanned = \DB::table('user_banned')
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where('banned_user_id', $correspond_id)->count();
|
||||
if($partnerIsBanned){
|
||||
return ['banned' => true];
|
||||
}
|
||||
|
||||
return ['banned' => false];
|
||||
}
|
||||
|
||||
public function leaveRoom(HttpRequest $request)
|
||||
{
|
||||
$room_id = $request->input('room');
|
||||
|
||||
$room = ChatRoom::find($room_id);
|
||||
$room->users()->detach(auth()->user()->id);
|
||||
|
||||
return redirect()->back()->with('success', 'Успешно покинули беседу');
|
||||
}
|
||||
|
||||
|
||||
public function removeMessage($id)
|
||||
{
|
||||
$message = Message::findOrFail($id);
|
||||
$message->delete();
|
||||
|
||||
return ['success' => true];
|
||||
}
|
||||
|
||||
protected function getBannedUser($correspondId)
|
||||
{
|
||||
return \DB::table('user_banned')
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where('banned_user_id', $correspondId)
|
||||
->orWhere(function($query) use($correspondId) {
|
||||
$query->where('user_id', $correspondId)
|
||||
->where('banned_user_id', auth()->user()->id);
|
||||
})->count();
|
||||
}
|
||||
}
|
||||
326
app/Http/Controllers/MoneyController.php
Executable file
326
app/Http/Controllers/MoneyController.php
Executable file
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use YooKassa\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Domain\Points\Models\Point;
|
||||
use App\Domain\Payments\Models\Withdrawal;
|
||||
use App\Domain\Points\Enums\DirectionEnum;
|
||||
use App\Domain\PaymentGateway\Services\QiwiService;
|
||||
use App\Domain\PaymentGateway\Services\UnitpayService;
|
||||
use App\Domain\PaymentGateway\Services\YookassaService;
|
||||
use App\Domain\PaymentGateway\Models\PaymentGatewayOrder;
|
||||
use App\Domain\PaymentGateway\Services\InterkassaService;
|
||||
use App\Domain\Subscriptions\Service\SubscriptionService;
|
||||
|
||||
class MoneyController extends Controller
|
||||
{
|
||||
|
||||
public function startProcess(Request $request)
|
||||
{
|
||||
|
||||
$this->validate($request, [
|
||||
'sum' => 'required|integer|numeric',
|
||||
]);
|
||||
|
||||
$sum = (int) abs($request->input('sum'));
|
||||
|
||||
$amount = round(($sum * 0.035) + $sum, 1);
|
||||
|
||||
$order = PaymentGatewayOrder::yookassa($sum);
|
||||
$order_number = ['order_number' => $order->number];
|
||||
|
||||
$point = new Point;
|
||||
$point->user_id = auth()->user()->id;
|
||||
$point->point = $sum;
|
||||
$point->type = 'Ожидание поступления';
|
||||
$point->direction = DirectionEnum::PENDING();
|
||||
$point->meta = json_encode($order_number);
|
||||
$point->save();
|
||||
|
||||
|
||||
return redirect(YookassaService::payments_link($amount, $order, auth()->user()));
|
||||
}
|
||||
|
||||
// public function startProcess()
|
||||
// {
|
||||
// $amount = filter_input(INPUT_GET, 'sum', FILTER_VALIDATE_INT);
|
||||
|
||||
// if(empty($amount)){
|
||||
// return redirect()->back();
|
||||
// }
|
||||
|
||||
// $order = PaymentGatewayOrder::yookassa($amount);
|
||||
// return redirect(YookassaService::payments_link($amount, $order, auth()->user()));
|
||||
// }
|
||||
|
||||
|
||||
public function checkPointPay($id)
|
||||
{
|
||||
|
||||
$point = Point::findOrFail($id);
|
||||
|
||||
if($point->direction != 2){
|
||||
return redirect()->route('setting.money')->with('error', 'Ошбика');
|
||||
}
|
||||
|
||||
$order_number = json_decode($point->meta);
|
||||
if(empty($order_number)){
|
||||
return redirect()->route('setting.money')->with('error', 'Ошбика');
|
||||
}
|
||||
$order = PaymentGatewayOrder::where('number', $order_number->order_number)->first();
|
||||
|
||||
if(empty($order)){
|
||||
return redirect()->route('setting.money')->with('error', 'Ошбика');
|
||||
}
|
||||
|
||||
if($order->status !== 0){
|
||||
return redirect()->route('setting.money')->with('error', 'Ошбика');
|
||||
}
|
||||
|
||||
$YOOKASSA_SHOP_ID = env('YOOKASSA_SHOP_ID');
|
||||
$YOOKASSA_KEY = env('YOOKASSA_KEY');
|
||||
|
||||
$client = new Client();
|
||||
$client->setAuth($YOOKASSA_SHOP_ID, $YOOKASSA_KEY);
|
||||
$payment = $client->getPaymentInfo($order->system_payment_id);
|
||||
|
||||
if ($payment->getStatus() === "succeeded")
|
||||
{
|
||||
$order->status = 1;
|
||||
$order->save();
|
||||
|
||||
$point->point = $order->amount;
|
||||
$point->type = 'Пополнение счета: ' . $order->type . ' # ' . $order->id;
|
||||
$point->direction = DirectionEnum::COMING();
|
||||
$point->save();
|
||||
|
||||
return redirect()->route('setting.money')->with('success', 'Счет успешно пополнен!');
|
||||
}
|
||||
else{
|
||||
|
||||
PaymentGatewayOrder::destroy($order->id);
|
||||
Point::destroy($point->id);
|
||||
|
||||
return redirect()->route('setting.money')->with('error', 'Платеж не прошел. Попробуйте еще или выберите другой способ оплаты');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function paymentStatus($number)
|
||||
{
|
||||
|
||||
$order = PaymentGatewayOrder::where('number', $number)->firstOrFail();
|
||||
|
||||
if($order->status !== 0){
|
||||
return redirect()->to('/');
|
||||
}
|
||||
|
||||
$YOOKASSA_SHOP_ID = env('YOOKASSA_SHOP_ID');
|
||||
$YOOKASSA_KEY = env('YOOKASSA_KEY');
|
||||
$client = new Client();
|
||||
$client->setAuth($YOOKASSA_SHOP_ID, $YOOKASSA_KEY);
|
||||
$payment = $client->getPaymentInfo($order->system_payment_id);
|
||||
|
||||
$point = Point::where('meta->order_number', $number)->first();
|
||||
if(empty($point)){
|
||||
$point = new Point;
|
||||
$point->user_id = auth()->user()->id;
|
||||
}
|
||||
|
||||
if ($payment->getStatus() === "succeeded")
|
||||
{
|
||||
$order->status = 1;
|
||||
$order->save();
|
||||
|
||||
|
||||
|
||||
$point->point = $order->amount;
|
||||
$point->type = 'Пополнение счета: ' . $order->type . ' # ' . $order->id;
|
||||
$point->direction = DirectionEnum::COMING();
|
||||
$point->save();
|
||||
|
||||
return redirect()->route('setting.money')->with('success', 'Счет успешно пополнен!');
|
||||
}
|
||||
else{
|
||||
PaymentGatewayOrder::destroy($order->id);
|
||||
Point::destroy($point->id);
|
||||
return redirect()->route('setting.money')->with('error', 'Платеж не прошел. Попробуйте еще или выберите другой способ оплаты');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// public function qiwiStatus($number)
|
||||
// {
|
||||
// $YOOKASSA_SHOP_ID = env('YOOKASSA_SHOP_ID');
|
||||
// $YOOKASSA_KEY = env('YOOKASSA_KEY');
|
||||
// $client = new Client();
|
||||
// $client->setAuth($YOOKASSA_SHOP_ID, $YOOKASSA_KEY);
|
||||
// $payment = $client->getPaymentInfo($number);
|
||||
// dd($payment);
|
||||
|
||||
// $SECRET_KEY = env('QIWI_SECRET');
|
||||
|
||||
// $order = PaymentGatewayOrder::where('number', $number)->firstOrFail();
|
||||
// if($order->status !== 0){
|
||||
// return redirect()->to('/');
|
||||
// }
|
||||
|
||||
// $billPayments = new \Qiwi\Api\BillPayments($SECRET_KEY);
|
||||
// $response = $billPayments->getBillInfo($number);
|
||||
|
||||
// if ($response['status']['value'] === "PAID")
|
||||
// {
|
||||
// $order->status = 1;
|
||||
// $order->save();
|
||||
|
||||
// $point = new Point;
|
||||
// $point->user_id = auth()->user()->id;
|
||||
// $point->point = $order->amount;
|
||||
// $point->type = 'Пополнение счета: ' . $order->type . ' # ' . $order->id;
|
||||
// $point->direction = DirectionEnum::COMING();
|
||||
// $point->save();
|
||||
|
||||
// return redirect()->route('setting.money')->with('success', 'Счет успешно пополнен!');
|
||||
// }
|
||||
// else if ($response['status']['value'] === "WAITING")
|
||||
// {
|
||||
// echo "Ваш платеж в обработке \n Не закрывайте страницу и попробуйте обновить страницу позже";
|
||||
// die;
|
||||
// }
|
||||
|
||||
|
||||
// PaymentGatewayOrder::destroy($order->id);
|
||||
|
||||
// $msg_error = 'Заказ завершен с ошибкой';
|
||||
// if($response['status']['value'] === "REJECTED"){
|
||||
// $msg_error .= ' - Счет отклонен';
|
||||
// }
|
||||
// return redirect()->route('setting.money')->with('error', $msg_error);
|
||||
|
||||
// }
|
||||
|
||||
public function unitpayStatus()
|
||||
{
|
||||
dd(request()->all());
|
||||
}
|
||||
|
||||
public function interkassa()
|
||||
{
|
||||
$amount = filter_input(INPUT_GET, 'ik_am', FILTER_VALIDATE_INT);
|
||||
|
||||
if(empty($amount)){
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$order = PaymentGatewayOrder::interkassa($amount);
|
||||
|
||||
return redirect(InterkassaService::payments_link($amount, $order->id));
|
||||
}
|
||||
|
||||
public function interkassaStatus()
|
||||
{
|
||||
$ik_co_id = request()->ik_co_id; // Идентификатор кассы
|
||||
$ik_inv_id = request()->ik_inv_id; // Идентификатор платежа в системе Интеркасса
|
||||
$ik_inv_st = request()->ik_inv_st; // Состояние платежа. - success; fail
|
||||
$ik_pm_no = request()->ik_pm_no; // Номер заказа. example - ID_4233
|
||||
|
||||
if($ik_inv_st === 'success'){
|
||||
$order = PaymentGatewayOrder::findOrFail($ik_pm_no);
|
||||
if($order->status === 1){
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$order->status = 1;
|
||||
$order->system_payment_id = $ik_inv_id;
|
||||
$order->save();
|
||||
|
||||
$point = new Point;
|
||||
$point->user_id = auth()->user()->id;
|
||||
$point->point = $order->amount;
|
||||
$point->type = 'Пополнение счета: ' . $order->type . ' # ' . $order->id;
|
||||
$point->direction = DirectionEnum::COMING();
|
||||
$point->save();
|
||||
|
||||
return redirect()->route('setting.money')->with('success', 'Счет успешно пополнен!');
|
||||
}
|
||||
|
||||
return $this->fails($ik_pm_no, $ik_inv_st);
|
||||
|
||||
}
|
||||
|
||||
protected function fails($order_id, $status)
|
||||
{
|
||||
PaymentGatewayOrder::destroy($order_id);
|
||||
|
||||
$msg_error = 'Заказ завершен с ошибкой';
|
||||
if($status === 'canceled'){
|
||||
$msg_error = 'Заказ отменен';
|
||||
}
|
||||
return redirect()->route('setting.money')->with('error', $msg_error);
|
||||
}
|
||||
|
||||
|
||||
public function payouts()
|
||||
{
|
||||
$amount = request()->amount;
|
||||
$user = auth()->user();
|
||||
// $bankRequisites = $user->bank_requisites->first();
|
||||
|
||||
if(!$user->isVerifiedForWithdrawal()){
|
||||
return redirect()->back()->with('error', 'Нужно верифицировать аккаунт, загрузить копию паспорта и ввести данные бик, инн, расчетный счет');
|
||||
// return redirect()->back()->with('error', 'Нужно верифицировать ваш номер телефона');
|
||||
}
|
||||
|
||||
// if(empty($bankRequisites)){
|
||||
// return redirect()->back()->with('error', 'Заполните платежные реквизиты');
|
||||
// }
|
||||
|
||||
$balance = SubscriptionService::calculate(auth()->user()->id);
|
||||
if ($amount > $balance) {
|
||||
return redirect()->back()->with('error', 'Недостаточно средств для вывода');
|
||||
}
|
||||
|
||||
if($user->status == 1 || $user->status == 2){
|
||||
if (!Withdrawal::canRequestWithdrawalPhysical($user->id, $amount)) {
|
||||
return redirect()->back()->with('error', 'Превышен лимит выплат за текущий месяц (12000)');
|
||||
}
|
||||
}else{
|
||||
if (!Withdrawal::canRequestWithdrawalLegal($user->id, $amount)) {
|
||||
return redirect()->back()->with('error', 'Превышен лимит выплат за текущий месяц (150000)');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// $requisites = $bankRequisites->requisites;
|
||||
|
||||
// $detailsDescr[] = 'Тип: по номеру телефона';
|
||||
// $detailsDescr[] = 'Номер телефона: ' . $user->phone;
|
||||
$detailsDescr[] = 'Тип: Банк';
|
||||
// $detailsDescr[] = 'Номер карты: ' . $bankRequisites->number;
|
||||
$detailsDescr = implode(PHP_EOL, $detailsDescr);
|
||||
|
||||
$point = new Point;
|
||||
$point->user_id = auth()->user()->id;
|
||||
$point->point = $amount;
|
||||
$point->type = 'Вывод средств (ожидает обработки)'; //YSV ENUM!
|
||||
$point->direction = DirectionEnum::EXPENSE();
|
||||
$point->save();
|
||||
|
||||
$withdrawal = new Withdrawal;
|
||||
$withdrawal->point()->associate($point);
|
||||
$withdrawal->user()->associate(auth()->user());
|
||||
$withdrawal->requisites_id = 1;
|
||||
// $withdrawal->requisites()->associate($requisites);
|
||||
$withdrawal->amount = $amount;
|
||||
$withdrawal->history_payment_details = $detailsDescr;
|
||||
$withdrawal->save();
|
||||
|
||||
|
||||
|
||||
return redirect()->back()->with('success', 'Запрос на вывод денег успешно отправлен!');
|
||||
}
|
||||
}
|
||||
221
app/Http/Controllers/MusicsController.php
Executable file
221
app/Http/Controllers/MusicsController.php
Executable file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use App\Domain\Feeds\Models\Feed;
|
||||
use App\Domain\Feeds\Enums\StatusEnum;
|
||||
use App\Http\Requests\MusicFormRequest;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Domain\Tags\Action\CreateTagAction;
|
||||
use App\Domain\Feeds\Action\CreateFeedAction;
|
||||
use App\Domain\Feeds\Queries\FeedQueryBuilder;
|
||||
use App\Domain\Musics\Action\CreateMusicAction;
|
||||
use App\Domain\Musics\Action\UpdateMusicAction;
|
||||
use App\Domain\Feeds\Service\FeedMediaTransform;
|
||||
use App\Domain\Musics\DataTransferObjects\MusicData;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
class MusicsController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('subs.paid')->except('loadedPlaylist', 'favoritePlaylist', 'show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$filter = Request::get('filter');
|
||||
|
||||
$feeds = (new FeedQueryBuilder())
|
||||
->addType('music')
|
||||
->search(Request::only('search'))
|
||||
->enableAdvertising()
|
||||
->filter($filter)
|
||||
->build();
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
$route = route('musics.index');
|
||||
return Inertia::render('Music/Feed', [
|
||||
'nextCursor' => $nextCursor,
|
||||
'searchFilters' => Request::all('search'),
|
||||
'feeds' => $feeds,
|
||||
'local_route' => $route,
|
||||
'active_filter' => $filter ?? 'new'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return Inertia::render('Music/Create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(MusicFormRequest $request)
|
||||
{
|
||||
$action = new CreateFeedAction(
|
||||
new CreateMusicAction(),
|
||||
new CreateTagAction(),
|
||||
);
|
||||
|
||||
$musicData = MusicData::fromRequest($request);
|
||||
$action($musicData);
|
||||
$msg = 'Музыка успешно загружена и находится на модерации!';
|
||||
return Redirect::route('profile.user', auth()->user()->username)->with('success', $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($slug)
|
||||
{
|
||||
$feed = new FeedQueryBuilder();
|
||||
$feed = $feed->selectBy('slug', $slug)->disablePaginate()->transformGet()->first();
|
||||
if(!$feed){
|
||||
abort(404);
|
||||
}
|
||||
return Inertia::render('Music/Show', [
|
||||
'user' => $feed['user'],
|
||||
'feed' => $feed,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($slug)
|
||||
{
|
||||
$feed = Feed::where('slug', $slug)->firstOrFail();
|
||||
|
||||
if (!$feed->user()->is(auth()->user())) {
|
||||
abort(404);
|
||||
}
|
||||
$tags = $feed->tags()->pluck('name')->toArray();
|
||||
|
||||
|
||||
$mediaTransform = (new FeedMediaTransform($feed))->default();
|
||||
$mediaPreview = $mediaTransform->getPreviewObject();
|
||||
|
||||
$mediaTransformCommon = $mediaTransform->spot();
|
||||
$mediaTransformPaid = (new FeedMediaTransform($feed))->paid()->spot();
|
||||
|
||||
return Inertia::render('Music/Edit', [
|
||||
'feed' => $feed,
|
||||
'tags' => $tags,
|
||||
'mediaPreview' => $mediaPreview,
|
||||
'mediasCount' => count($mediaTransformCommon['medias']),
|
||||
'mediasCommon' => $mediaTransformCommon['medias'],
|
||||
'mediasPaid' => $mediaTransformPaid['medias'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(MusicFormRequest $request, Feed $feed)
|
||||
{
|
||||
$oldStatus = $feed->status;
|
||||
if (!$feed->user()->is(auth()->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$action = new CreateFeedAction(
|
||||
new UpdateMusicAction($feed),
|
||||
new CreateTagAction(),
|
||||
);
|
||||
|
||||
$musicData = MusicData::fromRequest($request);
|
||||
$action($musicData);
|
||||
$newStatus = $feed->status;
|
||||
|
||||
$message = 'Аудио файл успешно обновлен!';
|
||||
if($oldStatus === StatusEnum::APPROVED() && $newStatus === StatusEnum::EDITABLE()){
|
||||
$message = 'Аудио файл успешно обновлен и находится на модерации!';
|
||||
}
|
||||
|
||||
return Redirect::back()->with('success', $message);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function loadedPlaylist()
|
||||
{
|
||||
|
||||
$musics = Media::whereHasMorph(
|
||||
'model',
|
||||
[Feed::class],
|
||||
function (Builder $query) {
|
||||
$query->where('user_id', auth()->user()->id)->where('type', 'musics');
|
||||
}
|
||||
)->where('collection_name', '<>', 'preview')->orderBy('id', 'desc')->cursorPaginate(10);
|
||||
$cursor = get_cursor_hash($musics);
|
||||
|
||||
$musics_collection = [];
|
||||
$musics->each(function ($media) use (&$musics_collection) {
|
||||
$musics_collection[] = [
|
||||
'url' => $media->getFullUrl(),
|
||||
'name' => $media->name,
|
||||
'playing' => false,
|
||||
'time' => $media->getCustomProperty('time'),
|
||||
'id' => $media->id,
|
||||
];
|
||||
});
|
||||
return ['collection' => $musics_collection, 'cursor' => $cursor];
|
||||
}
|
||||
|
||||
public function favoritePlaylist()
|
||||
{
|
||||
$audios = auth()->user()->audioLike()->cursorPaginate(10);
|
||||
$cursor = get_cursor_hash($audios);
|
||||
|
||||
$musics_collection = [];
|
||||
$audios->each(function ($media) use (&$musics_collection) {
|
||||
$musics_collection[] = [
|
||||
'url' => $media->getFullUrl(),
|
||||
'name' => $media->name,
|
||||
'playing' => false,
|
||||
'liked' => true,
|
||||
'time' => $media->getCustomProperty('time'),
|
||||
'id' => $media->id,
|
||||
];
|
||||
});
|
||||
return ['collection' => $musics_collection, 'cursor' => $cursor];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
266
app/Http/Controllers/ProfileController.php
Executable file
266
app/Http/Controllers/ProfileController.php
Executable file
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Domain\Feeds\Queries\FeedQueryBuilder;
|
||||
use App\Domain\Users\Service\ProfileDataService;
|
||||
use App\Domain\Users\DataTransferObjects\UserData;
|
||||
use App\Domain\Subscriptions\Service\SubscriptionService;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
abort_if(Str::contains(request()->url(), 'inner_systemuser_api'), 404);
|
||||
$this->middleware('subs.paid')->except('profile');
|
||||
}
|
||||
|
||||
public function profile($username)
|
||||
{
|
||||
|
||||
$user = User::where('username', $username)->firstOrFail();
|
||||
$authUserActiveSubscription = nova_get_setting('vote_paid_mode') ? SubscriptionService::activeSubscription() : true;
|
||||
|
||||
$packet = null;
|
||||
$packageCompleted = false;
|
||||
|
||||
if($user->private && auth()->user()){
|
||||
$packet = $user->customPackage;
|
||||
if($packet){
|
||||
$check = \DB::table('users_package_customers')
|
||||
->where('user_id', $user->id)
|
||||
->where('customer_id', auth()->user()->id)
|
||||
->where('package_id', $packet->id)
|
||||
->where('time_end', '>', now())
|
||||
->count();
|
||||
$packageCompleted = $check > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
$userData = UserData::fromModel($user);
|
||||
if($userData->is_auth_user){
|
||||
$feeds = (new FeedQueryBuilder($user->feeds()))->enableAdvertising()->disableActiveFeed()->order()->build();
|
||||
}else{
|
||||
$feeds = (new FeedQueryBuilder($user->feeds()))->enableAdvertising()->order()->build();
|
||||
}
|
||||
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
$profileData = ProfileDataService::get($user);
|
||||
// $testPeriod = auth()->user()->testPeriodCheck();
|
||||
if(auth()->user()){
|
||||
$limitLeader = auth()->user()->subscribers()->where('leader', 1)->count() === nova_get_setting('vote_leader_count');
|
||||
}else{
|
||||
$limitLeader = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Inertia::render('Profile/Index', [
|
||||
// 'testPeriod' => $testPeriod,
|
||||
'user' => array_merge([
|
||||
'about' => $user->about,
|
||||
'is_sub' => $user->is_sub,
|
||||
], $userData->toArray()),
|
||||
'packet' => $packet,
|
||||
'authUserActiveSubscription' => $authUserActiveSubscription,
|
||||
'packageCompleted' => $packageCompleted,
|
||||
'feeds' => $feeds,
|
||||
'nextCursor' => $nextCursor,
|
||||
'limitLeader' => $limitLeader,
|
||||
'is_leader' => $profileData->is_leader,
|
||||
'close_account' => $profileData->close_account,
|
||||
'counts' => [
|
||||
'feeds' => $profileData->count_feeds,
|
||||
'subscribers' => $profileData->count_subscribers,
|
||||
'readers' => $profileData->count_readable,
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function profileReaders($username)
|
||||
{
|
||||
$user = User::where('username', $username)->firstOrFail();
|
||||
$limitLeader = auth()->user()->subscribers()->where('leader', 1)->count() === nova_get_setting('vote_leader_count');
|
||||
|
||||
$profileData = ProfileDataService::get($user);
|
||||
|
||||
$packageCompleted = false;
|
||||
|
||||
$authUserActiveSubscription = nova_get_setting('vote_paid_mode') ? SubscriptionService::activeSubscription() : true;
|
||||
|
||||
if($user->private){
|
||||
$packet = $user->customPackage;
|
||||
if($packet){
|
||||
$check = \DB::table('users_package_customers')
|
||||
->where('user_id', $user->id)
|
||||
->where('customer_id', auth()->user()->id)
|
||||
->where('package_id', $packet->id)
|
||||
->where('time_end', '>', now())
|
||||
->count();
|
||||
$packageCompleted = $check > 0 ? true : false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$myPaidListSubscribeTo = \DB::table('users_package_customers')
|
||||
->latest()
|
||||
->where('customer_id', auth()->user()->id)->get()->groupBy('user_id');
|
||||
|
||||
$myPaidListSubscribeTo = $myPaidListSubscribeTo->map(function($item){
|
||||
$first = $item->first();
|
||||
$first->expired = Carbon::parse($first->time_end) < now();
|
||||
return Carbon::parse($first->time_end) < now();
|
||||
});
|
||||
// dd($myPaidListSubscribeTo);
|
||||
|
||||
|
||||
$leader = Request::get('leader');
|
||||
if($leader === '1'){
|
||||
$readers = $user->subscribersOn();
|
||||
}elseif ($leader === '0') {
|
||||
$readers = $user->subscribersOff();
|
||||
}else{
|
||||
$readers = $user->subscribers();
|
||||
}
|
||||
$readers = $readers->filter(Request::only('search'))
|
||||
->orderBy('id', 'desc')
|
||||
->cursorPaginate(User::PAGINATE);
|
||||
$nextCursor = get_cursor_hash($readers);
|
||||
|
||||
$readers->transform(function ($user) {
|
||||
return array_merge([
|
||||
'is_leader' => (boolean) $user->pivot->leader,
|
||||
], UserData::fromModel($user)->toArray());
|
||||
});
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $readers->items(), 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('Profile/Readers', [
|
||||
'nextCursor' => $nextCursor,
|
||||
'user' => array_merge([
|
||||
'about' => $user->about,
|
||||
'is_sub' => $user->is_sub,
|
||||
], UserData::fromModel($user)->toArray()),
|
||||
'packageCompleted' => $packageCompleted,
|
||||
'filters' => Request::all('search', 'leader'),
|
||||
'readers' => $readers->items(),
|
||||
'limitLeader' => $limitLeader,
|
||||
'authUserActiveSubscription' => $authUserActiveSubscription,
|
||||
'is_leader' => $profileData->is_leader,
|
||||
'close_account' => $profileData->close_account,
|
||||
'myPaidListSubscribeTo' => $myPaidListSubscribeTo,
|
||||
'counts' => [
|
||||
'feeds' => $profileData->count_feeds,
|
||||
'subscribers' => $profileData->count_subscribers,
|
||||
'readers' => $profileData->count_readable,
|
||||
]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function profileSubs($username)
|
||||
{
|
||||
$user = User::where('username', $username)->firstOrFail();
|
||||
$limitLeader = auth()->user()->subscribers()->where('leader', 1)->count() === nova_get_setting('vote_leader_count');
|
||||
$profileData = ProfileDataService::get($user);
|
||||
$sub = Request::get('sub');
|
||||
|
||||
$authUserActiveSubscription = nova_get_setting('vote_paid_mode') ? SubscriptionService::activeSubscription() : true;
|
||||
|
||||
|
||||
$packageCompleted = false;
|
||||
|
||||
if($user->private){
|
||||
$packet = $user->customPackage;
|
||||
if($packet){
|
||||
$check = \DB::table('users_package_customers')
|
||||
->where('user_id', $user->id)
|
||||
->where('customer_id', auth()->user()->id)
|
||||
->where('package_id', $packet->id)
|
||||
->where('time_end', '>', now())
|
||||
->count();
|
||||
$packageCompleted = $check > 0 ? true : false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($sub !== null){
|
||||
$query = '';
|
||||
$typeSub = $sub === '1' ? '<>' : '=';
|
||||
|
||||
$subscribers = $user->subscriber_reverse()
|
||||
->withCount([
|
||||
'subscriber_reverse as pizda' => function (Builder $builder) use (&$query) {
|
||||
$query = $builder;
|
||||
$query->where('user_id', auth()->user()->id);
|
||||
},
|
||||
])
|
||||
->whereRaw("({$query->toSql()}) {$typeSub} ?", [$user->id, 0])
|
||||
|
||||
->filter(Request::only('search'))
|
||||
->orderBy('id', 'desc')
|
||||
->cursorPaginate(User::PAGINATE);
|
||||
$subscribers->transform(function ($user) use ($sub) {
|
||||
return array_merge([
|
||||
'is_sub' => (boolean) $sub,
|
||||
], UserData::fromModel($user)->toArray());
|
||||
});
|
||||
}else{
|
||||
$subscribers = $user->subscriber_reverse()
|
||||
->withCount(['subscriber_reverse as is_sub' => function (Builder $query) {
|
||||
$query->where('user_id', auth()->user()->id);
|
||||
}])
|
||||
->withCasts(['is_sub' => 'boolean'])
|
||||
->filter(Request::only('search'))
|
||||
->orderBy('id', 'desc')
|
||||
->cursorPaginate(User::PAGINATE);
|
||||
|
||||
$subscribers->transform(function ($user) {
|
||||
return array_merge([
|
||||
'is_sub' => $user->is_sub,
|
||||
], UserData::fromModel($user)->toArray());
|
||||
});
|
||||
}
|
||||
|
||||
$nextCursor = get_cursor_hash($subscribers);
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $subscribers->items(), 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('Profile/Subs', [
|
||||
'user' => array_merge([
|
||||
'about' => $user->about,
|
||||
'is_sub' => $user->is_sub,
|
||||
], UserData::fromModel($user)->toArray()),
|
||||
'packageCompleted' => $packageCompleted,
|
||||
'authUserActiveSubscription' => $authUserActiveSubscription,
|
||||
'filters' => Request::all('search', 'sub'),
|
||||
'limitLeader' => $limitLeader,
|
||||
'is_leader' => $profileData->is_leader,
|
||||
'subscribers' => $subscribers->items(),
|
||||
'close_account' => $profileData->close_account,
|
||||
'counts' => [
|
||||
'feeds' => $profileData->count_feeds,
|
||||
'subscribers' => $profileData->count_subscribers,
|
||||
'readers' => $profileData->count_readable,
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
98
app/Http/Controllers/PurchaseController.php
Executable file
98
app/Http/Controllers/PurchaseController.php
Executable file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use App\Domain\Feeds\Queries\FeedQueryBuilder;
|
||||
use App\Domain\Feeds\Service\FeedMediaTransform;
|
||||
|
||||
class PurchaseController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$purchases_feeds = new FeedQueryBuilder($user->purchases()->withTrashed());
|
||||
$purchases_feeds = $purchases_feeds->withFeedable()->feed->cursorPaginate(FeedQueryBuilder::PAGINATION_COUNT);
|
||||
$nextCursor = get_cursor_hash($purchases_feeds);
|
||||
|
||||
$feeds = [];
|
||||
foreach ($purchases_feeds as $purchases_feed) {
|
||||
$mediaTransform = (new FeedMediaTransform($purchases_feed))->default();
|
||||
$date = [
|
||||
'price' => $purchases_feed->pivot->amount,
|
||||
'purchase_date' => $purchases_feed->pivot->created_at->format('Y-m-d'),
|
||||
'preview' => $mediaTransform->getPreview(),
|
||||
'id' => $purchases_feed->id,
|
||||
'type' => $purchases_feed->type,
|
||||
];
|
||||
$feeds[] = $date;
|
||||
}
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('Settings/SettingsPurchases', [
|
||||
'nextCursor' => $nextCursor,
|
||||
'feeds' => $feeds,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
|
||||
$purchases_feed = new FeedQueryBuilder(auth()->user()->purchases()->withTrashed());
|
||||
$purchases_feed = $purchases_feed->selectByIds($id)->withFeedable()->withUser()->feed->firstOrFail();
|
||||
|
||||
$seller = $purchases_feed->user;
|
||||
$seller->name = $seller->name;
|
||||
|
||||
$mediaTransformCommon = (new FeedMediaTransform($purchases_feed))->default()->spot();
|
||||
$mediaTransformPaid = (new FeedMediaTransform($purchases_feed))->paid()->spot();
|
||||
|
||||
$purchase = [
|
||||
'id' => $purchases_feed->id,
|
||||
'title' => $purchases_feed->title,
|
||||
'body' => $purchases_feed->body,
|
||||
'type' => $purchases_feed->type,
|
||||
'price' => $purchases_feed->pivot->amount,
|
||||
'purchase_date' => $purchases_feed->pivot->created_at->format('Y-m-d'),
|
||||
|
||||
'preview' => $mediaTransformCommon['preview'],
|
||||
'common_medias' => $mediaTransformCommon['medias'],
|
||||
'paid_medias' => $mediaTransformPaid['medias'],
|
||||
];
|
||||
|
||||
return Inertia::render('Settings/SettingsPurchasesFile', [
|
||||
'purchase' => $purchase,
|
||||
'seller' => $seller,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function downloadPurchases($id)
|
||||
{
|
||||
|
||||
$purchases_feed = new FeedQueryBuilder(auth()->user()->purchases()->withTrashed());
|
||||
$purchases_feed = $purchases_feed->selectByIds($id)->withFeedable()->feed->firstOrFail();
|
||||
$mediaTransformPaid = (new FeedMediaTransform($purchases_feed))->getFullPath()->paid()->spot();
|
||||
|
||||
$purchase_date = $purchases_feed->pivot->created_at->format('Y-m-d');
|
||||
|
||||
$zip_file = "purchase-{$purchases_feed->type}-{$purchase_date}.zip";
|
||||
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
$zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
|
||||
foreach ($mediaTransformPaid['medias'] as $paid_media) {
|
||||
$zip->addFile($paid_media['url'], basename($paid_media['url']));
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
|
||||
//unlink(public_path($zip_file));
|
||||
return response()->download($zip_file);
|
||||
}
|
||||
|
||||
}
|
||||
32
app/Http/Controllers/RequisitesController.php
Executable file
32
app/Http/Controllers/RequisitesController.php
Executable file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Payments\Models\Requisites;
|
||||
use App\Domain\Payments\Models\BankRequisites;
|
||||
|
||||
class RequisitesController extends Controller
|
||||
{
|
||||
public function updateBank()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$number = request()->number;
|
||||
$bankRequisites = $user->bank_requisites->first();
|
||||
if(!$bankRequisites){
|
||||
$bankRequisites = new BankRequisites;
|
||||
$bankRequisites->user()->associate(auth()->user());
|
||||
$bankRequisites->number = $number;
|
||||
$bankRequisites->save();
|
||||
|
||||
$requisites = new Requisites;
|
||||
$requisites->user()->associate(auth()->user());
|
||||
$bankRequisites->requisites()->save($requisites);
|
||||
}else{
|
||||
$bankRequisites->number = $number;
|
||||
$bankRequisites->save();
|
||||
}
|
||||
|
||||
|
||||
return redirect()->back()->with('success', 'Реквизиты успешно обновлены!');
|
||||
|
||||
}
|
||||
}
|
||||
376
app/Http/Controllers/SettingController.php
Executable file
376
app/Http/Controllers/SettingController.php
Executable file
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\User;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Http\Request as HttpRequest;
|
||||
use App\Domain\Subscriptions\Models\Package;
|
||||
use App\Domain\Feeds\Queries\FeedQueryBuilder;
|
||||
use App\Domain\Subscriptions\Service\SubscriptionService;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
|
||||
const NOTIFICATION_THRESHOLD = 20;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
return Inertia::render('Settings/SettingsProfile', [
|
||||
'user' => [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'username' => $user->username,
|
||||
'first_name' => $user->first_name,
|
||||
'last_name' => $user->last_name,
|
||||
'email' => $user->email,
|
||||
'user_char' => $user->user_char,
|
||||
'color' => $user->color,
|
||||
'sex' => $user->sex,
|
||||
'type' => $user->type,
|
||||
'phone' => $user->phone,
|
||||
'date_of_birth' => $user->date_of_birth,
|
||||
'photo_path' => $user->photo_path,
|
||||
'banner_path' => $user->banner_path,
|
||||
'about' => $user->about,
|
||||
'private' => $user->private,
|
||||
'inn' => $user->inn,
|
||||
'checking_account' => $user->checking_account,
|
||||
'bik' => $user->bik,
|
||||
// 'allow_adult_content' => $user->allow_adult_content,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function notify()
|
||||
{
|
||||
auth()->user()->unreadNotifications()->update(['read_at' => Carbon::now()]);
|
||||
|
||||
$notifications = auth()->user()
|
||||
->notifications()
|
||||
->latest()
|
||||
->take(self::NOTIFICATION_THRESHOLD)
|
||||
->get();
|
||||
|
||||
$notifications_transform = [];
|
||||
foreach ($notifications as $notification) {
|
||||
$d = [];
|
||||
$data = $notification->data;
|
||||
|
||||
if($notification->notifiable_type === User::class){
|
||||
if($notification->type === 'App\Notifications\LikeAdded'){
|
||||
$d['type'] = 'like';
|
||||
}
|
||||
if($notification->type === 'App\Notifications\CommentAdded'){
|
||||
$d['type'] = 'comment';
|
||||
}
|
||||
if($notification->type === 'App\Notifications\Subscribed'){
|
||||
$d['type'] = 'subs';
|
||||
}
|
||||
if($notification->type === 'App\Notifications\LeaderChoice'){
|
||||
$d['type'] = 'leader';
|
||||
}
|
||||
if($notification->type === 'App\Notifications\UserCustomPaidSubscription'){
|
||||
$d['type'] = 'custom-paid-subs';
|
||||
}
|
||||
if($notification->type === 'App\Notifications\PurchaseAdded'){
|
||||
$d['type'] = 'purchase';
|
||||
}
|
||||
if($notification->type === 'App\Notifications\RemoveFeed'){
|
||||
$d['type'] = 'remove-feed';
|
||||
}
|
||||
if($notification->type === 'App\Notifications\BannedMessageFeed'){
|
||||
$d['type'] = 'banned-message-feed';
|
||||
}
|
||||
$user_who = User::find($data['user_id']);
|
||||
if(empty($user_who)){
|
||||
$notification->delete();
|
||||
continue;
|
||||
}
|
||||
|
||||
$d['user'] = [
|
||||
'id' => $user_who->id,
|
||||
'name' => $user_who->name,
|
||||
'username' => $user_who->username,
|
||||
'photo_path' => $user_who->photo_path,
|
||||
'color' => $user_who->color,
|
||||
'user_char' => $user_who->user_char,
|
||||
];
|
||||
|
||||
if(@$data['node_id']){
|
||||
$feed = new FeedQueryBuilder;
|
||||
$d['feed'] = $feed->selectByIds($data['node_id'])->disableActiveFeed()->withTrashed()->transformGet()->first();
|
||||
}else{
|
||||
$d['feed'] = '';
|
||||
}
|
||||
|
||||
$d['data'] = $data;
|
||||
$d['id'] = $notification->id;
|
||||
$d['created_at'] = $notification->created_at->diffForHumans();
|
||||
}
|
||||
$notifications_transform[] = $d;
|
||||
}
|
||||
|
||||
return Inertia::render('Settings/SettingsNotify', [
|
||||
'notifications' => $notifications_transform,
|
||||
]);
|
||||
}
|
||||
|
||||
public function money()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$points = $user
|
||||
->points()
|
||||
->orderBy('id', 'desc')
|
||||
->cursorPaginate(User::PAGINATE);
|
||||
|
||||
$nextCursor = get_cursor_hash($points);
|
||||
|
||||
$points->each(function($line){
|
||||
$dt = explode(' ', $line->created_at);
|
||||
$line->date = $dt[0];
|
||||
$line->time = $dt[1];
|
||||
return $line;
|
||||
});
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $points->items(), 'next' => $nextCursor];
|
||||
}
|
||||
return Inertia::render('Settings/SettingsMoney', [
|
||||
'points' => $points->items(),
|
||||
'nextCursor' => $nextCursor,
|
||||
]);
|
||||
}
|
||||
|
||||
public function tarif()
|
||||
{
|
||||
|
||||
$user = auth()->user();
|
||||
$is_active = SubscriptionService::activeSubscription();
|
||||
$user_id = $user->id;
|
||||
$user_autosubscription = $user->autosubscription_site;
|
||||
|
||||
$plans = Package::all();
|
||||
$lastSubscription = $user->subscription->first();
|
||||
|
||||
if ($lastSubscription) {
|
||||
$lastSubscription->setRelation('package', $plans->where('id', $lastSubscription->package_id)->first());
|
||||
$lastSubscription->endDateTime = $lastSubscription->ends_at->format('Y-m-d');
|
||||
}
|
||||
|
||||
return Inertia::render('Settings/SettingsTarif', [
|
||||
'plans' => $plans,
|
||||
'is_active_sub' => $is_active,
|
||||
'user_autosubscription' => $user_autosubscription,
|
||||
'user_id' => $user_id,
|
||||
'lastSubscription' => $lastSubscription,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function likes()
|
||||
{
|
||||
|
||||
$feeds = (new FeedQueryBuilder(auth()->user()->likes()))->order()->build();
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('Settings/SettingsLikes', [
|
||||
'feeds' => $feeds,
|
||||
'nextCursor' => $nextCursor,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function payouts()
|
||||
{
|
||||
|
||||
$user = auth()->user();
|
||||
// $requisites = [];
|
||||
// $bankRequisites = $user->bank_requisites->first();
|
||||
// if($bankRequisites){
|
||||
// $requisites['id'] = $bankRequisites->id;
|
||||
// $requisites['number'] = $bankRequisites->number;
|
||||
// }
|
||||
$withdrawals = $user->withdrawals()
|
||||
->orderBy('id', 'desc')
|
||||
->cursorPaginate(User::PAGINATE);
|
||||
|
||||
|
||||
$nextCursor = get_cursor_hash($withdrawals);
|
||||
|
||||
$statusCode = [
|
||||
'pending' => 'Запрос отправлен',
|
||||
'success' => 'Запрос выполнен',
|
||||
'cancel' => 'Отмена выплаты',
|
||||
];
|
||||
|
||||
$withdrawals->each(function($line) use($statusCode) {
|
||||
$dt = explode(' ', $line->created_at);
|
||||
$line->datePart = $dt[0];
|
||||
$line->timePart = $dt[1];
|
||||
$line->meta = 'Статус: ' . $statusCode[$line->status];
|
||||
$line->history_payment_details = nl2br($line->history_payment_details);
|
||||
return $line;
|
||||
});
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $withdrawals->items(), 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('Settings/SettingsPayouts', [
|
||||
// 'requisites' => $requisites,
|
||||
'isVerified' => $user->isVerified(),
|
||||
'withdrawals' => $withdrawals->items()
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function packet()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$userPackage = $user->customPackage;
|
||||
|
||||
$purchased_subscriptions_by_users = \DB::table('users_package_customers')
|
||||
->where('user_id', auth()->user()->id)->orderBy('customer_id')->orderBy('time_end', 'desc')->get();
|
||||
|
||||
$purchased_subscriptions_by_users = $purchased_subscriptions_by_users->groupBy('customer_id');
|
||||
|
||||
|
||||
|
||||
|
||||
$subscriptions_by_users = \DB::table('users_package_customers')
|
||||
->join('users_subscribers', 'users_package_customers.customer_id', '=', 'users_subscribers.user_id')
|
||||
->select('users_package_customers.*', 'users_subscribers.autosubscription', 'users_subscribers.user_id as usId', 'users_subscribers.subscriber_id as subsId')
|
||||
->where('users_package_customers.customer_id', auth()->user()->id)
|
||||
->orderBy('users_package_customers.user_id')
|
||||
->orderBy('users_package_customers.time_end', 'desc')
|
||||
->get();
|
||||
|
||||
$subscriptions_by_users = $subscriptions_by_users->filter(function ($item) {
|
||||
return $item->user_id === $item->subsId && $item->customer_id === $item->usId;
|
||||
});
|
||||
|
||||
|
||||
// $subscriptions_by_users = \DB::table('users_package_customers')
|
||||
// ->where('customer_id', auth()->user()->id)
|
||||
// ->orderBy('user_id')
|
||||
// ->orderBy('time_end', 'desc')
|
||||
// ->get();
|
||||
|
||||
$subscriptions_by_users = $subscriptions_by_users->groupBy('user_id');
|
||||
|
||||
|
||||
$buyers = $this->getPacketUsers($purchased_subscriptions_by_users);
|
||||
|
||||
$subscriptions = $this->getPacketUsers($subscriptions_by_users);
|
||||
|
||||
|
||||
|
||||
|
||||
return Inertia::render('Settings/SettingsPacket', [
|
||||
'user' => $user,
|
||||
'packet' => $userPackage,
|
||||
'buyers' => $buyers->values()->toArray(),
|
||||
'subscriptions' => $subscriptions->values()->toArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
protected function getPacketUsers($subscriptions)
|
||||
{
|
||||
|
||||
$ids_customer = $subscriptions->keys();
|
||||
$users_customer = User::whereIn('id', $ids_customer)->get();
|
||||
|
||||
return $subscriptions->map(function ($items, $id) use($users_customer) {
|
||||
$new = [];
|
||||
$new['active'] = false;
|
||||
$new['autosubscription'] = false;
|
||||
$new['user'] = $users_customer->where('id', $id)->first()
|
||||
->only([
|
||||
'id', 'first_name', 'last_name',
|
||||
'color', 'user_char', 'username', 'photo_path'
|
||||
]);
|
||||
foreach($items as $item){
|
||||
// dd($items);
|
||||
$carbon = \Carbon\Carbon::parse($item->time_end);
|
||||
$active = now() < $carbon;
|
||||
if($active){
|
||||
$new['active'] = $active;
|
||||
}
|
||||
$new['autosubscription'] = $item->autosubscription ?? false;
|
||||
$new['lists'][] = ['time_end' => $carbon->format('d.m.Y'), 'price' => $item->price, 'active' => $active];
|
||||
}
|
||||
return $new;
|
||||
|
||||
});
|
||||
// dd($test);
|
||||
|
||||
// return $subscriptions->map(function ($item) use($users_customer,$type) {
|
||||
// $carbon = \Carbon\Carbon::parse($item->time_end);
|
||||
|
||||
// return [
|
||||
// 'id' => $item->id,
|
||||
// 'price' => $item->price,
|
||||
// 'time_end' => $carbon->format('d.m.Y'),
|
||||
// 'active' => now() < $carbon,
|
||||
// 'user' => $users_customer->first(function ($value) use($item,$type) {
|
||||
// return $value->id == $item->{$type};
|
||||
// })->toArray()
|
||||
// ];
|
||||
// });
|
||||
}
|
||||
|
||||
public function verification(HttpRequest $request)
|
||||
{
|
||||
|
||||
$document = $request->user()->getMedia('documents');
|
||||
|
||||
$first_document = $document->first();
|
||||
$doc_uuid = null;
|
||||
if($first_document){
|
||||
$doc_uuid = $first_document->uuid;
|
||||
}
|
||||
|
||||
$user = auth()->user();
|
||||
$isPhoneVerify = $user->phone_verified;
|
||||
$isPassportVerified = $user->passport_verified;
|
||||
|
||||
if (!empty($user->phone_verify_token) && $user->phone_verify_token_expire && $user->phone_verify_token_expire->gt(now())) {
|
||||
$isToken = true;
|
||||
}else{
|
||||
$isToken = false;
|
||||
}
|
||||
|
||||
return Inertia::render('Settings/SettingsVerification', [
|
||||
'docUuid' => $doc_uuid,
|
||||
'isToken' => $isToken,
|
||||
'isPhoneVerify' => $isPhoneVerify,
|
||||
'isPassportVerified' => $isPassportVerified,
|
||||
'phone' => $request->user()->phone,
|
||||
]);
|
||||
}
|
||||
|
||||
public function writeToUs(HttpRequest $request)
|
||||
{
|
||||
return Inertia::render('Settings/SettingsWriteToUs', [
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function documentsInfo()
|
||||
{
|
||||
return Inertia::render('Settings/SettingsDocuments', [
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
134
app/Http/Controllers/StaticController.php
Executable file
134
app/Http/Controllers/StaticController.php
Executable file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use League\Glide\ServerFactory;
|
||||
use App\Domain\Feeds\Models\Feed;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use League\Glide\Responses\LaravelResponseFactory;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
class StaticController extends Controller
|
||||
{
|
||||
|
||||
public function show(Filesystem $filesystem, Request $request, $path)
|
||||
{
|
||||
$server = ServerFactory::create([
|
||||
'response' => new LaravelResponseFactory($request),
|
||||
'source' => $filesystem->getDriver(),
|
||||
'cache' => $filesystem->getDriver(),
|
||||
'cache_path_prefix' => '.glide-cache',
|
||||
'base_url' => 'img',
|
||||
]);
|
||||
|
||||
$server->setPresets([
|
||||
'small' => [
|
||||
'w' => 200,
|
||||
'h' => 200,
|
||||
'fit' => 'crop',
|
||||
],
|
||||
'medium' => [
|
||||
'w' => 500,
|
||||
'h' => 500,
|
||||
'fit' => 'crop',
|
||||
],
|
||||
|
||||
'banner' => [
|
||||
'w' => 500,
|
||||
'fit' => 'crop',
|
||||
],
|
||||
'hero' => [
|
||||
'w' => 1600,
|
||||
'h' => 600,
|
||||
'fit' => 'crop',
|
||||
],
|
||||
]);
|
||||
|
||||
return $server->getImageResponse($path, $request->all());
|
||||
}
|
||||
|
||||
public function avatarRemove(Filesystem $filesystem)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$server = ServerFactory::create([
|
||||
'source' => $filesystem->getDriver(),
|
||||
'cache' => $filesystem->getDriver(),
|
||||
'cache_path_prefix' => '.glide-cache',
|
||||
'base_url' => 'img',
|
||||
]);
|
||||
|
||||
Storage::disk('public')->delete($user->photo_path);
|
||||
$server->deleteCache($user->photo_path);
|
||||
$user->photo_path = null;
|
||||
$user->save();
|
||||
|
||||
return Redirect::back()->with('success', 'Аватар успешно удален!');
|
||||
}
|
||||
|
||||
public function avatar(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
request()->validate([
|
||||
'avatar' => 'required|image|mimes:jpeg,jpg,png|max:1024',
|
||||
]);
|
||||
|
||||
$path = $request->file('avatar')->store('avatars', 'public');
|
||||
$user->photo_path = $path;
|
||||
$user->save();
|
||||
|
||||
return Redirect::back()->with('success', 'Аватар успешно обновлен!');
|
||||
}
|
||||
|
||||
public function banner(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
request()->validate([
|
||||
'banner' => 'required|image|mimes:jpeg,jpg,png|max:2048',
|
||||
]);
|
||||
|
||||
$path = $request->file('banner')->store('banners', 'public');
|
||||
$user->banner_path = $path;
|
||||
$user->save();
|
||||
|
||||
return Redirect::back()->with('success', 'Баннер успешно обновлен!');
|
||||
}
|
||||
|
||||
public function bannerRemove(Filesystem $filesystem)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$server = ServerFactory::create([
|
||||
'source' => $filesystem->getDriver(),
|
||||
'cache' => $filesystem->getDriver(),
|
||||
'cache_path_prefix' => '.glide-cache',
|
||||
'base_url' => 'img',
|
||||
]);
|
||||
|
||||
Storage::disk('public')->delete($user->banner_path);
|
||||
$server->deleteCache($user->banner_path);
|
||||
$user->banner_path = null;
|
||||
$user->save();
|
||||
|
||||
return Redirect::back()->with('success', 'Баннер успешно удален!');
|
||||
}
|
||||
|
||||
public function removePreview($id)
|
||||
{
|
||||
$media = Media::findOrFail($id);
|
||||
$feed = $media->model;
|
||||
if (is_a($feed, Feed::class)) {
|
||||
if ($feed->user()->is(auth()->user())) {
|
||||
$media->delete();
|
||||
}
|
||||
}
|
||||
return Redirect::back()->with('success', 'Превью успешно удалено!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
136
app/Http/Controllers/TagController.php
Executable file
136
app/Http/Controllers/TagController.php
Executable file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use App\Domain\Tags\Models\Tag;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Http\Request as HttpRequest;
|
||||
use App\Domain\Feeds\Queries\FeedQueryBuilder;
|
||||
|
||||
class TagController extends Controller
|
||||
{
|
||||
public function index($tag)
|
||||
{
|
||||
$tag = Tag::where('slug', $tag)->first();
|
||||
$filter = Request::get('filter');
|
||||
|
||||
$feeds = (new FeedQueryBuilder())
|
||||
->addTags([$tag->id])
|
||||
->search(Request::only('search'))
|
||||
->filter($filter)
|
||||
->build();
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
$route = route('feed.tags', $tag->slug);
|
||||
|
||||
return Inertia::render('Tag/Feed', [
|
||||
'searchFilters' => Request::all('search'),
|
||||
'feeds' => $feeds,
|
||||
'tag' => $tag,
|
||||
'local_route' => $route,
|
||||
'nextCursor' => $nextCursor,
|
||||
'active_filter' => $filter ?? 'new'
|
||||
]);
|
||||
}
|
||||
|
||||
public function listImagesTag($tag)
|
||||
{
|
||||
$tag = Tag::where('slug', $tag)->first();
|
||||
$filter = Request::get('filter');
|
||||
|
||||
$feeds = (new FeedQueryBuilder())
|
||||
->addTags([$tag->id])
|
||||
->addType('image')
|
||||
->search(Request::only('search'))
|
||||
->filter($filter)
|
||||
->build();
|
||||
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
$route = route('list.images.tag', $tag->slug);
|
||||
|
||||
return Inertia::render('Image/Index', [
|
||||
'nextCursor' => $nextCursor,
|
||||
'searchFilters' => Request::all('search'),
|
||||
'feeds' => $feeds,
|
||||
'tag' => $tag,
|
||||
'local_route' => $route,
|
||||
'active_filter' => $filter ?? 'new'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function listMusicsTag($tag)
|
||||
{
|
||||
$tag = Tag::where('slug', $tag)->first();
|
||||
$filter = Request::get('filter');
|
||||
|
||||
$feeds = (new FeedQueryBuilder())
|
||||
->addTags([$tag->id])
|
||||
->addType('music')
|
||||
->search(Request::only('search'))
|
||||
->filter($filter)
|
||||
->build();
|
||||
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
$route = route('list.musics.tag', $tag->slug);
|
||||
|
||||
return Inertia::render('Music/Feed', [
|
||||
'nextCursor' => $nextCursor,
|
||||
'searchFilters' => Request::all('search'),
|
||||
'feeds' => $feeds,
|
||||
'tag' => $tag,
|
||||
'local_route' => $route,
|
||||
'active_filter' => $filter ?? 'new'
|
||||
]);
|
||||
}
|
||||
|
||||
public function listVideosTag($tag)
|
||||
{
|
||||
$tag = Tag::where('slug', $tag)->first();
|
||||
$filter = Request::get('filter');
|
||||
|
||||
$feeds = (new FeedQueryBuilder())
|
||||
->addTags([$tag->id])
|
||||
->addType('video')
|
||||
->search(Request::only('search'))
|
||||
->filter($filter)
|
||||
->build();
|
||||
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
$route = route('list.videos.tag', $tag->slug);
|
||||
|
||||
return Inertia::render('Video/Feed', [
|
||||
'nextCursor' => $nextCursor,
|
||||
'searchFilters' => Request::all('search'),
|
||||
'feeds' => $feeds,
|
||||
'tag' => $tag,
|
||||
'local_route' => $route,
|
||||
'active_filter' => $filter ?? 'new'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
101
app/Http/Controllers/UserPackageController.php
Executable file
101
app/Http/Controllers/UserPackageController.php
Executable file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Models\User;
|
||||
use Inertia\Inertia;
|
||||
use App\Domain\Points\Models\Point;
|
||||
use App\Domain\Feeds\Service\LiveFeed;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Domain\Users\Models\UserPackage;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use App\Domain\Points\Enums\DirectionEnum;
|
||||
use App\Notifications\UserCustomPaidSubscription;
|
||||
use App\Domain\Subscriptions\Service\SubscriptionService;
|
||||
|
||||
class UserPackageController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('subs.paid')->except('show');
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$id_packet = request()->post('id');
|
||||
if($id_packet){
|
||||
$customPackage = UserPackage::find($id_packet);
|
||||
}else{
|
||||
$customPackage = new UserPackage;
|
||||
}
|
||||
|
||||
$customPackage->price = request()->post('price');
|
||||
$customPackage->user_id = auth()->user()->id;
|
||||
$customPackage->save();
|
||||
|
||||
return Redirect::back()->with('success', 'Успешно обновлено');
|
||||
}
|
||||
|
||||
public function subs() {
|
||||
|
||||
$id_packet = request()->post('packet_id');
|
||||
$customPackage = UserPackage::find($id_packet);
|
||||
|
||||
$balance = SubscriptionService::calculate(auth()->user()->id);
|
||||
if ($customPackage->price > $balance) {
|
||||
return Redirect::back()->with('error', 'Недостаточно средств!');
|
||||
}
|
||||
|
||||
\DB::beginTransaction();
|
||||
|
||||
$userPackage = User::find($customPackage->user_id);
|
||||
|
||||
$check = \DB::table('users_subscribers')
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where('subscriber_id', $customPackage->user_id)
|
||||
->first();
|
||||
|
||||
// в буд. по рефакторить, по сути сейчас этот код выполняется один раз
|
||||
// дальше пользователю нужно отписаться, и заново купить подписку!
|
||||
if(empty($check)){
|
||||
auth()->user()->subscribers()->toggle([$userPackage->id]);
|
||||
LiveFeed::addBySub($userPackage);
|
||||
}
|
||||
|
||||
|
||||
\DB::table('users_package_customers')->insert([
|
||||
'user_id' => $customPackage->user_id,
|
||||
'customer_id' => auth()->user()->id,
|
||||
'package_id' => $customPackage->id,
|
||||
'price' => $customPackage->price,
|
||||
// 'time_end' => now()->addMonths(),
|
||||
'time_end' => now()->addMinutes(10),
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
|
||||
$point = new Point;
|
||||
$point->user_id = auth()->user()->id;
|
||||
$point->point = $customPackage->price;
|
||||
$point->type = 'Оформлена подписка на пользователя: ' . $userPackage->name . ' (' . $userPackage->username . ')'; //YSV ENUM!
|
||||
$point->direction = DirectionEnum::EXPENSE();
|
||||
$point->save();
|
||||
|
||||
$point = new Point;
|
||||
$point->user_id = $userPackage->id;
|
||||
$point->point = $customPackage->price;
|
||||
$point->type = 'Пользователь оформил платную подписку: ' . auth()->user()->name . ' (' . auth()->user()->username . ')'; //YSV ENUM!
|
||||
$point->direction = DirectionEnum::COMING();
|
||||
$point->save();
|
||||
|
||||
\DB::commit();
|
||||
|
||||
$message = [
|
||||
'user_id' => auth()->user()->id,
|
||||
'node_id' => null,
|
||||
];
|
||||
$userPackage->notify(new UserCustomPaidSubscription($message));
|
||||
|
||||
return Redirect::back()->with('success', 'Подписка на пользователя успешно оформлена');
|
||||
|
||||
}
|
||||
}
|
||||
494
app/Http/Controllers/UsersController.php
Executable file
494
app/Http/Controllers/UsersController.php
Executable file
@@ -0,0 +1,494 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use DB;
|
||||
use Hash;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\User;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Domain\Tags\Models\Tag;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Domain\Feeds\Models\Feed;
|
||||
use App\Notifications\Subscribed;
|
||||
use App\Domain\Points\Models\Point;
|
||||
use App\Notifications\LeaderChoice;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use App\Domain\Feeds\Service\LiveFeed;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Domain\Points\Enums\DirectionEnum;
|
||||
use App\Domain\Votes\Services\VoteService;
|
||||
use Illuminate\Http\Request as HttpRequest;
|
||||
use App\Domain\Subscriptions\Models\Package;
|
||||
use App\Domain\Subscriptions\Models\Subscription;
|
||||
use App\Domain\Users\DataTransferObjects\UserData;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use App\Domain\Subscriptions\Service\SubscriptionService;
|
||||
|
||||
class UsersController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('subs.paid')->except('update', 'plan', 'postsCount', 'searchUserTag', 'testPaid');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$users = User::filter(Request::only('search', 'sex'))
|
||||
->where('id', '<>', auth()->user()->id)
|
||||
->where('username', '<>', 'inner_systemuser_api')
|
||||
->withCount(['subscriber_reverse as is_sub' => function (Builder $query) {
|
||||
$query->where('user_id', auth()->user()->id);
|
||||
}])
|
||||
->withCasts(['is_sub' => 'boolean'])
|
||||
->orderBy('id', 'desc')
|
||||
->cursorPaginate(User::PAGINATE);
|
||||
|
||||
$nextCursor = get_cursor_hash($users);
|
||||
$users->transform(function ($user) {
|
||||
return array_merge([
|
||||
'is_sub' => $user->is_sub,
|
||||
], UserData::fromModel($user)->toArray());
|
||||
});
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $users->items(), 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
return Inertia::render('User/Index', [
|
||||
'filters' => Request::all('search', 'sex'),
|
||||
'nextCursor' => $nextCursor,
|
||||
'users' => $users->items(),
|
||||
'per_page' => User::PAGINATE,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testing()
|
||||
{
|
||||
|
||||
|
||||
|
||||
// $leaders = collect(SubscriptionService::leaders());
|
||||
$vote = (object) ['procent_site' => 10, 'procent_top' => 60];
|
||||
$t = (new VoteService($vote))->freeMode();
|
||||
dd($t);
|
||||
// $ids = $leaders->pluck('user_id');
|
||||
// $users = User::whereIn('id', $ids)->get();
|
||||
// $leaderUsers = $leaders->map(function($item) use($users) {
|
||||
// $item->user = $users->where('id', $item->user_id)->first()->only(['id', 'first_name', 'last_name', 'username']);
|
||||
// return $item;
|
||||
// });
|
||||
// dd($leaderUsers);
|
||||
|
||||
// dd(Str::uuid());
|
||||
// $user = new \App\Models\User();
|
||||
// $user->password = \Illuminate\Support\Facades\Hash::make('sysSDFGtemuser345345');
|
||||
// $user->email = 'system@systemuser_api.com';
|
||||
// $user->first_name = 'systemuser_api';
|
||||
// $user->username = 'inner_systemuser_api';
|
||||
// $user->save();
|
||||
|
||||
//dd($user);
|
||||
|
||||
// $needArray = [
|
||||
// 1 => ['time' => true],
|
||||
// 2 => ['time' => true],
|
||||
// 3 => ['time' => true],
|
||||
// ];
|
||||
|
||||
// $user = User::find(4);
|
||||
// $plucks = $user->feeds()->pluck('created_at', 'id')->transform(function ($item) {
|
||||
// return ['time' => $item->getTimestamp()];
|
||||
// })->toArray();
|
||||
|
||||
// dd($plucks);
|
||||
// DB::table('videos')->truncate();
|
||||
// DB::table('musics')->truncate();
|
||||
// DB::table('images')->truncate();
|
||||
// DB::table('user_feed_purchase')->truncate();
|
||||
// DB::table('users_feeds_like')->truncate();
|
||||
// DB::table('points')->truncate();
|
||||
// DB::table('notifications')->truncate();
|
||||
// DB::table('feed_tags')->truncate();
|
||||
// DB::table('feeds_comments')->truncate();
|
||||
// DB::table('complaints')->truncate();
|
||||
// DB::table('comments')->truncate();
|
||||
// DB::table('feeds')->truncate();
|
||||
|
||||
//$feeds = Feed::all();
|
||||
//foreach ($feeds as $feed) {
|
||||
// $enity = $feed->feedable;
|
||||
// $uuid = (string) Str::uuid();
|
||||
// $feed->title = $enity->title;
|
||||
// $feed->body = $enity->body;
|
||||
// $feed->price = $enity->price;
|
||||
// $feed->is_paid = $enity->is_paid;
|
||||
// $feed->type = $feed->type;
|
||||
// $feed->slug = $uuid . '_' . $feed->type;
|
||||
// $feed->save();
|
||||
// $medias = $enity->getMedia('common');
|
||||
// $medias_paid = $enity->getMedia('paid');
|
||||
// $medias_preview = $enity->getMedia('preview');
|
||||
|
||||
// foreach ($medias as $media) {
|
||||
// if(file_exists($media->getPath())){
|
||||
// $feed->addMedia($media->getPath())->toMediaCollection('common');
|
||||
// }
|
||||
// }
|
||||
// foreach ($medias_paid as $media) {
|
||||
// if(file_exists($media->getPath())){
|
||||
// $feed->addMedia($media->getPath())->toMediaCollection('paid');
|
||||
// }
|
||||
// }
|
||||
// foreach ($medias_preview as $media) {
|
||||
// if(file_exists($media->getPath())){
|
||||
// $feed->addMedia($media->getPath())->toMediaCollection('preview');
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function update(User $user)
|
||||
{
|
||||
Request::validate([
|
||||
'first_name' => ['required', 'max:80'],
|
||||
'last_name' => ['required', 'max:80'],
|
||||
'username' => ['required', 'max:80', Rule::unique('users')->ignore($user->id)],
|
||||
'email' => ['required', 'max:50', 'email', Rule::unique('users')->ignore($user->id)],
|
||||
'password' => ['nullable'],
|
||||
'phone' => ['nullable'],
|
||||
'date_of_birth' => ['nullable'],
|
||||
'sex' => ['nullable'],
|
||||
'type' => ['nullable'],
|
||||
'private' => ['nullable'],
|
||||
'inn' => ['nullable'],
|
||||
'checking_account' => ['nullable'],
|
||||
'bik' => ['nullable'],
|
||||
// 'allow_adult_content' => ['nullable'],
|
||||
'about' => ['nullable', 'max:180'],
|
||||
]);
|
||||
|
||||
$user->update(Request::only('first_name', 'last_name', 'email', 'username', 'phone', 'date_of_birth', 'sex', 'about', 'private', 'inn', 'checking_account', 'bik', 'type'));
|
||||
|
||||
if (Request::get('password')) {
|
||||
$user->update(['password' => Request::get('password')]);
|
||||
}
|
||||
|
||||
return Redirect::back()->with('success', 'Профиль обновлен!');
|
||||
}
|
||||
|
||||
public function destroy(User $user)
|
||||
{
|
||||
if (App::environment('demo') && $user->isDemoUser()) {
|
||||
return Redirect::back()->with('error', 'Deleting the demo user is not allowed.');
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
|
||||
return Redirect::back()->with('success', 'User deleted.');
|
||||
}
|
||||
|
||||
public function restore(User $user)
|
||||
{
|
||||
$user->restore();
|
||||
|
||||
return Redirect::back()->with('success', 'User restored.');
|
||||
}
|
||||
|
||||
public function subs(User $user)
|
||||
{
|
||||
|
||||
if($user->private){
|
||||
return Redirect::back()->with('error', 'Закрытый аккаунт');
|
||||
}
|
||||
|
||||
$check = \DB::table('users_subscribers')
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where('subscriber_id', $user->id)
|
||||
->first();
|
||||
|
||||
auth()->user()->subscribers()->toggle([$user->id]);
|
||||
|
||||
if(!$check){
|
||||
$message = [
|
||||
'user_id' => auth()->user()->id,
|
||||
'node_id' => null,
|
||||
];
|
||||
$user->notify(new Subscribed($message));
|
||||
LiveFeed::addBySub($user);
|
||||
}else{
|
||||
LiveFeed::removeBySub($user);
|
||||
}
|
||||
|
||||
return Redirect::back()->with('success', 'Success');
|
||||
}
|
||||
|
||||
public function removePaidSubs(User $user)
|
||||
{
|
||||
auth()->user()->subscribers()->toggle([$user->id]);
|
||||
|
||||
DB::table('users_package_customers')
|
||||
->where('user_id', $user->id)
|
||||
->where('customer_id', auth()->user()->id)
|
||||
->delete();
|
||||
|
||||
LiveFeed::removeBySub($user);
|
||||
|
||||
return Redirect::back()->with('success', 'Успешно отписались от пользователя');
|
||||
}
|
||||
|
||||
public function settingsAutoSubsPaidUser(User $user)
|
||||
{
|
||||
DB::table('users_subscribers')
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where('subscriber_id', $user->id)
|
||||
->update(['autosubscription' => DB::raw('NOT autosubscription')]);
|
||||
|
||||
return Redirect::back()->with('success', 'Успешно выполнено');
|
||||
}
|
||||
|
||||
public function settingsAutoSubs(User $user)
|
||||
{
|
||||
$auto = $user->autosubscription_site;
|
||||
|
||||
if($auto){
|
||||
$msg = 'Автоматическое списание отключено!';
|
||||
$user->autosubscription_site = false;
|
||||
}else{
|
||||
$msg = 'Автоматическое списание включено!';
|
||||
$user->autosubscription_site = true;
|
||||
}
|
||||
|
||||
$user->save();
|
||||
|
||||
return Redirect::back()->with('success', $msg);
|
||||
}
|
||||
|
||||
public function vote(User $user, HttpRequest $request)
|
||||
{
|
||||
|
||||
$authUserActiveSubscription = nova_get_setting('vote_paid_mode') ? SubscriptionService::activeSubscription() : true;
|
||||
if(!$authUserActiveSubscription){
|
||||
return Redirect::back()->with('error', 'Только пользователи с подпиской могут выбрать лидера!');
|
||||
}
|
||||
|
||||
$count_leader = nova_get_setting('vote_leader_count');
|
||||
if(!$request->vote && auth()->user()->subscribers()->where('leader', 1)->count() >= $count_leader){
|
||||
return Redirect::back()->with('error', "Можно выбрать {$count_leader} лидеров");
|
||||
}
|
||||
|
||||
if(!$request->vote){
|
||||
$message = [
|
||||
'user_id' => auth()->user()->id,
|
||||
'node_id' => null,
|
||||
];
|
||||
$user->notify(new LeaderChoice($message));
|
||||
}
|
||||
auth()->user()->subscribers()->updateExistingPivot($user->id, [
|
||||
'leader' => ! $request->vote,
|
||||
]);
|
||||
return Redirect::back()->with('success', 'Success Vote!');
|
||||
}
|
||||
|
||||
|
||||
public function plan($plan_id)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$active_subscription = SubscriptionService::activeSubscription();
|
||||
if ($active_subscription) {
|
||||
return Redirect::back()->with('error', 'Подписка уже активирована');
|
||||
}
|
||||
$balance = SubscriptionService::calculate($user->id);
|
||||
$plan = Package::findOrFail($plan_id);
|
||||
$plan_type = $plan->type;
|
||||
if ($plan_type === 'month3') {
|
||||
$ends_at = Carbon::now()->addMonths(3);
|
||||
} else {
|
||||
$ends_at = Carbon::now()->addMonths();
|
||||
}
|
||||
$price = $plan->price;
|
||||
if ($price > $balance) {
|
||||
return Redirect::back()->with('error', 'Недостаточно средств!');
|
||||
}
|
||||
|
||||
$sub = new Subscription;
|
||||
$sub->user_id = $user->id;
|
||||
$sub->package_id = $plan->id;
|
||||
$sub->price = $price;
|
||||
$sub->ends_at = $ends_at;
|
||||
$sub->status = 'complete'; //YSV ENUM!
|
||||
$sub->save();
|
||||
|
||||
$point = new Point;
|
||||
$point->user_id = $user->id;
|
||||
$point->point = $price;
|
||||
$point->type = 'Оплата за подписку'; //YSV ENUM!
|
||||
$point->direction = DirectionEnum::EXPENSE();
|
||||
$point->save();
|
||||
|
||||
return Redirect::back()->with('success', 'Вы успешо подписались!');
|
||||
}
|
||||
|
||||
public function testPaid()
|
||||
{
|
||||
// $price = 50;
|
||||
// $user = auth()->user();
|
||||
// $point = new Point;
|
||||
// $point->user_id = $user->id;
|
||||
// $point->point = $price;
|
||||
// $point->type = 'Пополнение баланса по кнопки'; //YSV ENUM!
|
||||
// $point->direction = DirectionEnum::COMING();
|
||||
// $point->save();
|
||||
// return Redirect::back()->with('success', 'Баланс успешно пополнен!');
|
||||
}
|
||||
|
||||
|
||||
public function postsCount($user_id)
|
||||
{
|
||||
$user = User::findOrFail($user_id);
|
||||
return $user->feeds()->count();
|
||||
}
|
||||
|
||||
public function searchUserTag()
|
||||
{
|
||||
|
||||
$search = Request::input('search');
|
||||
if(empty($search)){
|
||||
return [
|
||||
'users' => [],
|
||||
'tags' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$sanitize_search = Str::slug($search);
|
||||
|
||||
$users = User::where('username', '%'.$search.'%')
|
||||
->where('username', '<>', 'inner_systemuser_api')
|
||||
->orWhere('first_name', 'ilike', '%'.$search.'%')
|
||||
->orWhere('last_name', 'ilike', '%'.$search.'%')->get();
|
||||
$users->each(function ($item) {
|
||||
$item->name = $item->name;
|
||||
return $item;
|
||||
});
|
||||
$sanitize_search = '%'.$sanitize_search.'%';
|
||||
$tags = Tag::where('slug', 'ilike', $sanitize_search)->withCount('feeds')->get();
|
||||
|
||||
return [
|
||||
'users' => $users,
|
||||
'tags' => $tags,
|
||||
];
|
||||
}
|
||||
|
||||
public function friend() {
|
||||
$user = auth()->user();
|
||||
$readers = $user->subscribers()->filter(Request::only('search'))
|
||||
->orderBy('id', 'desc')
|
||||
->cursorPaginate(50);
|
||||
|
||||
|
||||
$users = [];
|
||||
$nextCursor = get_cursor_hash($readers);
|
||||
$readers->each(function ($item) use(&$users) {
|
||||
$users[] = UserData::fromModel($item)->toArray();
|
||||
});
|
||||
return ['records' => $users, 'cursor' => $nextCursor];
|
||||
|
||||
}
|
||||
|
||||
public function updatePassword(HttpRequest $request)
|
||||
{
|
||||
# Validation
|
||||
$request->validate([
|
||||
'old_password' => 'required',
|
||||
'new_password' => 'required|string|min:6',
|
||||
]);
|
||||
|
||||
#Match The Old Password
|
||||
if(!Hash::check($request->old_password, auth()->user()->password)){
|
||||
return back()->with("error", "Old Password Doesn't match!");
|
||||
}
|
||||
|
||||
#Update the new Password
|
||||
User::whereId(auth()->user()->id)->update([
|
||||
'password' => Hash::make($request->new_password)
|
||||
]);
|
||||
|
||||
return back()->with("success", "Password changed successfully!");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function addDocument(HttpRequest $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'docs' => 'required|file|image',
|
||||
]);
|
||||
|
||||
$documents = $request->user()->getMedia('documents');
|
||||
|
||||
if($documents->count()){
|
||||
foreach ($documents as $document) {
|
||||
$document->delete();
|
||||
}
|
||||
}
|
||||
$file = $request->file('docs');
|
||||
|
||||
auth()->user()->addMedia($file)->toMediaCollection('documents', 'local');
|
||||
|
||||
return back()->with("success", "Документ успешно загружен");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function readDocument(string $uuid)
|
||||
{
|
||||
$media = Media::where('uuid', $uuid)->first();
|
||||
return response()->download($media->getPath(), $media->file_name);
|
||||
}
|
||||
|
||||
public function verifyPhoneRequest(Carbon $now)
|
||||
{
|
||||
$user = auth()->user();
|
||||
if(empty($user->phone)){
|
||||
return back()->with("error", "Нужно ввести телефон");
|
||||
}
|
||||
if (!empty($user->phone_verify_token) && $user->phone_verify_token_expire && $user->phone_verify_token_expire->gt($now)) {
|
||||
return back()->with("error", "Токен уже запрошен.");
|
||||
}
|
||||
|
||||
$user->phone_verified = false;
|
||||
$user->phone_verify_token = (string)random_int(10000, 99999);
|
||||
$user->phone_verify_token_expire = $now->copy()->addSeconds(300);
|
||||
$user->saveOrFail();
|
||||
|
||||
return back()->with("success", "Верификация номера телефона успешно запрошена, ожидайте");
|
||||
}
|
||||
|
||||
public function verifyPhone(HttpRequest $request, Carbon $now)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$token = $request->input('token');
|
||||
if ($token !== $user->phone_verify_token) {
|
||||
return back()->with("error", "Токен уже запрошен.");
|
||||
}
|
||||
if ($user->phone_verify_token_expire->lt($now)) {
|
||||
return back()->with("error", "Срок действия токена истек.");
|
||||
}
|
||||
$user->phone_verified = true;
|
||||
$user->phone_verify_token = null;
|
||||
$user->phone_verify_token_expire = null;
|
||||
$user->saveOrFail();
|
||||
|
||||
return back()->with("success", "Верификация номера телефона успешно завершена");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
172
app/Http/Controllers/VideosController.php
Executable file
172
app/Http/Controllers/VideosController.php
Executable file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use App\Domain\Feeds\Models\Feed;
|
||||
use App\Domain\Feeds\Enums\StatusEnum;
|
||||
use App\Http\Requests\VideoFormRequest;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use App\Domain\Tags\Action\CreateTagAction;
|
||||
use App\Domain\Feeds\Action\CreateFeedAction;
|
||||
use App\Domain\Feeds\Queries\FeedQueryBuilder;
|
||||
use App\Domain\Videos\Action\CreateVideoAction;
|
||||
use App\Domain\Videos\Action\UpdateVideoAction;
|
||||
use App\Domain\Feeds\Service\FeedMediaTransform;
|
||||
use App\Domain\Videos\DataTransferObjects\VideoData;
|
||||
|
||||
class VideosController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('subs.paid')->except('show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
$filter = Request::get('filter');
|
||||
|
||||
$feeds = (new FeedQueryBuilder())
|
||||
->addType('video')
|
||||
->search(Request::only('search'))
|
||||
->filter($filter)
|
||||
->enableAdvertising()
|
||||
->build();
|
||||
$nextCursor = $feeds->nextCursor;
|
||||
$feeds = $feeds->transformData();
|
||||
|
||||
if(request()->wantsJson()){
|
||||
return ['collections' => $feeds, 'next' => $nextCursor];
|
||||
}
|
||||
|
||||
$route = route('videos.index');
|
||||
return Inertia::render('Video/Feed', [
|
||||
'nextCursor' => $nextCursor,
|
||||
'searchFilters' => Request::all('search'),
|
||||
'feeds' => $feeds,
|
||||
'local_route' => $route,
|
||||
'active_filter' => $filter ?? 'new'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return Inertia::render('Video/Create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(VideoFormRequest $request)
|
||||
{
|
||||
|
||||
$action = new CreateFeedAction(
|
||||
new CreateVideoAction(),
|
||||
new CreateTagAction(),
|
||||
);
|
||||
|
||||
$videoData = VideoData::fromRequest($request);
|
||||
$action($videoData);
|
||||
$msg = 'Видео успешно загружено и находится на модерации!';
|
||||
return Redirect::route('profile.user', auth()->user()->username)->with('success', $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($slug)
|
||||
{
|
||||
$feed = new FeedQueryBuilder();
|
||||
$feed = $feed->selectBy('slug', $slug)->disablePaginate()->transformGet()->first();
|
||||
if(!$feed){
|
||||
abort(404);
|
||||
}
|
||||
return Inertia::render('Video/Show', [
|
||||
'user' => $feed['user'],
|
||||
'feed' => $feed,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($slug)
|
||||
{
|
||||
$feed = Feed::where('slug', $slug)->firstOrFail();
|
||||
|
||||
if (!$feed->user()->is(auth()->user())) {
|
||||
abort(404);
|
||||
}
|
||||
$tags = $feed->tags()->pluck('name')->toArray();
|
||||
|
||||
$mediaTransform = (new FeedMediaTransform($feed))->default();
|
||||
$mediaPreview = $mediaTransform->getPreviewObject();
|
||||
|
||||
$mediaTransformCommon = $mediaTransform->spot();
|
||||
$mediaTransformPaid = (new FeedMediaTransform($feed))->paid()->spot();
|
||||
|
||||
|
||||
return Inertia::render('Video/Edit', [
|
||||
'feed' => $feed,
|
||||
'tags' => $tags,
|
||||
'mediaPreview' => $mediaPreview,
|
||||
'mediasCount' => count($mediaTransformCommon['medias']),
|
||||
'mediasCommon' => $mediaTransformCommon['medias'],
|
||||
'mediasPaid' => $mediaTransformPaid['medias'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(VideoFormRequest $request, Feed $feed)
|
||||
{
|
||||
$oldStatus = $feed->status;
|
||||
if (!$feed->user()->is(auth()->user())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$action = new CreateFeedAction(
|
||||
new UpdateVideoAction($feed),
|
||||
new CreateTagAction(),
|
||||
);
|
||||
|
||||
$videoData = VideoData::fromRequest($request);
|
||||
$action($videoData);
|
||||
$newStatus = $feed->status;
|
||||
|
||||
$message = 'Видео успешно обновлено!';
|
||||
if($oldStatus === StatusEnum::APPROVED() && $newStatus === StatusEnum::EDITABLE()){
|
||||
$message = 'Видео успешно обновлено и находится на модерации!';
|
||||
}
|
||||
|
||||
return Redirect::back()->with('success', $message);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user