Initial commit

This commit is contained in:
Developer
2025-04-21 16:03:20 +02:00
commit 2832896157
22874 changed files with 3092801 additions and 0 deletions

21
app/Models/Account.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models;
class Account extends Model
{
public function users()
{
return $this->hasMany(User::class);
}
public function organizations()
{
return $this->hasMany(Organization::class);
}
public function contacts()
{
return $this->hasMany(Contact::class);
}
}

45
app/Models/Contact.php Normal file
View File

@@ -0,0 +1,45 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class Contact extends Model
{
use SoftDeletes;
public function organization()
{
return $this->belongsTo(Organization::class);
}
public function getNameAttribute()
{
return $this->first_name.' '.$this->last_name;
}
public function scopeOrderByName($query)
{
$query->orderBy('last_name')->orderBy('first_name');
}
public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? null, function ($query, $search) {
$query->where(function ($query) use ($search) {
$query->where('first_name', 'like', '%'.$search.'%')
->orWhere('last_name', 'like', '%'.$search.'%')
->orWhere('email', 'like', '%'.$search.'%')
->orWhereHas('organization', function ($query) use ($search) {
$query->where('name', 'like', '%'.$search.'%');
});
});
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
if ($trashed === 'with') {
$query->withTrashed();
} elseif ($trashed === 'only') {
$query->onlyTrashed();
}
});
}
}

20
app/Models/Model.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\SoftDeletes;
abstract class Model extends Eloquent
{
protected $guarded = [];
// protected $perPage = 10;
// public function resolveRouteBinding($value, $field = null)
// {
// return in_array(SoftDeletes::class, class_uses($this))
// ? $this->where($this->getRouteKeyName(), $value)->withTrashed()->first()
// : parent::resolveRouteBinding($value);
// }
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class Organization extends Model
{
use SoftDeletes;
public function contacts()
{
return $this->hasMany(Contact::class);
}
public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? null, function ($query, $search) {
$query->where('name', 'like', '%'.$search.'%');
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
if ($trashed === 'with') {
$query->withTrashed();
} elseif ($trashed === 'only') {
$query->onlyTrashed();
}
});
}
}

226
app/Models/User.php Normal file
View File

@@ -0,0 +1,226 @@
<?php
namespace App\Models;
use App\Domain\Feeds\Models\Feed;
use App\Domain\Votes\Models\Vote;
use Spatie\MediaLibrary\HasMedia;
use App\Domain\Points\Models\Point;
use Illuminate\Auth\Authenticatable;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Traits\HasRoles;
use App\Domain\Users\Models\UserPackage;
use Illuminate\Notifications\Notifiable;
use App\Domain\Messenger\Models\ChatRoom;
use App\Domain\Payments\Models\Withdrawal;
use Spatie\MediaLibrary\InteractsWithMedia;
use App\Domain\Users\Observers\UserObserver;
use Spatie\Permission\Traits\HasPermissions;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Domain\Payments\Models\BankRequisites;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Domain\Subscriptions\Models\Subscription;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use App\Domain\PaymentGateway\Models\PaymentGatewayOrder;
use App\Domain\Subscriptions\Service\SubscriptionService;
use Illuminate\Auth\MustVerifyEmail as AuthMustVerifyEmail;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Auth\Passwords\CanResetPassword;
// , MustVerifyEmail
class User extends Model implements AuthenticatableContract, AuthorizableContract, MustVerifyEmail, HasMedia, CanResetPasswordContract
{
// , AuthMustVerifyEmail
use SoftDeletes, Authenticatable, Authorizable, HasRoles, HasPermissions, Notifiable, AuthMustVerifyEmail, InteractsWithMedia, CanResetPassword;
const CHECKTIMEUSER = 20;
const PAGINATE = 20;
protected $casts = [
'private' => 'boolean',
'autosubscription_site' => 'boolean',
// 'allow_adult_content' => 'boolean',
'phone_verified' => 'boolean',
'passport_verified' => 'boolean',
'phone_verify_token_expire' => 'datetime',
];
protected static function boot()
{
parent::boot();
self::observe(UserObserver::class);
}
public static function system()
{
return User::where('username', 'inner_systemuser_api')->first();
}
public function withdrawals()
{
return $this->hasMany(Withdrawal::class);
}
public function bank_requisites()
{
return $this->hasMany(BankRequisites::class);
}
public function points()
{
return $this->hasMany(Point::class);
}
public function payments_orders()
{
return $this->hasMany(PaymentGatewayOrder::class);
}
public function live_feeds()
{
// return $this->belongsToMany(Feed::class, 'users_live_feeds')
// ->withPivot('times')->orderByPivot('times', 'desc');
return $this->belongsToMany(Feed::class, 'users_live_feeds')
->withPivot('times')->orderByPivot('feed_id', 'desc');
}
public function customPackage()
{
return $this->hasOne(UserPackage::class);
}
public function feeds()
{
return $this->hasMany(Feed::class);
}
public function bannedUsers()
{
return $this->belongsToMany(User::class, 'user_banned', 'user_id', 'banned_user_id');
}
public function likes()
{
return $this->belongsToMany(Feed::class, 'users_feeds_like');
}
public function views()
{
return $this->belongsToMany(Feed::class, 'users_feeds_view');
}
public function audioLike()
{
return $this->belongsToMany(Media::class, 'user_audio_like')->withTimestamps()->orderByPivot('created_at', 'desc');
}
public function purchases()
{
return $this->belongsToMany(Feed::class, 'user_feed_purchase')->withPivot('amount')->withTimestamps()->orderByPivot('created_at', 'desc');
}
public function subscribers()
{
return $this->belongsToMany(User::class, 'users_subscribers', 'user_id', 'subscriber_id')->withPivot('leader');
}
public function subscriber_reverse()
{
return $this->belongsToMany(User::class, 'users_subscribers', 'subscriber_id', 'user_id')->withPivot('leader');
}
public function subscribersOn()
{
return $this->belongsToMany(User::class, 'users_subscribers', 'user_id', 'subscriber_id')->withPivot('leader')->wherePivot('leader', 1);
}
public function subscribersOff()
{
return $this->belongsToMany(User::class, 'users_subscribers', 'user_id', 'subscriber_id')->withPivot('leader')->wherePivot('leader', 0);
}
public function chat_rooms()
{
return $this->belongsToMany(ChatRoom::class, 'user_chat_room');
}
public function votes()
{
return $this->belongsToMany(Vote::class)->withPivot('payment');
}
// подписки
public function subscription()
{
return $this->hasMany(Subscription::class)->orderBy('ends_at', 'desc');
}
public function getNameAttribute()
{
if ($this->last_name) {
return $this->first_name . ' ' . $this->last_name;
}
return $this->first_name;
}
public function setPasswordAttribute($password)
{
$this->attributes['password'] = Hash::needsRehash($password) ? Hash::make($password) : $password;
}
public function checkClosedAccess()
{
$active_subscription = SubscriptionService::activeSubscription();
$has_subscription = SubscriptionService::hasSubscription();
if($has_subscription > 0 && !$active_subscription){
//имел подписку, нужно продлить
return true;
}elseif ($this->created_at->diffInMinutes(now()) > self::CHECKTIMEUSER && !$active_subscription) {
// пользователь только зарегался, закрываем доступ
return true;
}
return false;
}
public function testPeriodCheck()
{
$has_subscription = SubscriptionService::hasSubscription();
if( $has_subscription === 0 && ($this->created_at->diffInMinutes(now()) <= self::CHECKTIMEUSER) ){
return true;
}
return false;
}
public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? null, function ($query, $search) {
$query->where(function ($query) use ($search) {
$query->where('first_name', 'ilike', '%'.$search.'%')
->orWhere('last_name', 'ilike', '%'.$search.'%');
});
})->when($filters['sex'] ?? null, function ($query, $sex) {
$query->where('sex', $sex);
});
}
public function isVerified()
{
return $this->passport_verified;
// return $this->phone && $this->phone_verified;
}
public function isVerifiedForWithdrawal()
{
return $this->passport_verified && $this->inn && $this->checking_account && $this->bik;
// return $this->phone && $this->phone_verified;
}
}