mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-08-03 06:16:14 -04:00
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\StaffPayroll\Entities;
|
|
|
|
use App\Models\Staff;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Modules\StudioPlus\Entities\StudioPlusVideo;
|
|
|
|
class StaffPayrollUser extends User
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'users';
|
|
|
|
protected $appends = [
|
|
'full_name'
|
|
];
|
|
|
|
public function invoices()
|
|
{
|
|
return $this->hasMany(Invoice::class, 'user_id');
|
|
}
|
|
|
|
public function staff()
|
|
{
|
|
return $this->hasOne(Staff::class, 'user_id');
|
|
}
|
|
|
|
public function downlines()
|
|
{
|
|
return $this->hasMany(self::class, 'parent_id', 'id');
|
|
}
|
|
|
|
public function getFullNameAttribte()
|
|
{
|
|
return "{$this->first_name} {$this->last_name}";
|
|
}
|
|
|
|
public function getPublishedVideos($start_date = null, $end_date = null)
|
|
{
|
|
$videos = StudioPlusVideo::with('asinData')->whereHas('channel.user', function($query) {
|
|
$query->where('id', $this->id);
|
|
})
|
|
->when($start_date && $end_date, function($query) use($start_date, $end_date) {
|
|
$query->whereHas('tracks', function($query) use($start_date, $end_date) {
|
|
$query->where('name', StudioPlusVideo::STATUS_PUBLISHED)->whereBetween('created_at', [$start_date, $end_date]);
|
|
});
|
|
})
|
|
->where('status', StudioPlusVideo::STATUS_PUBLISHED)
|
|
->get();
|
|
|
|
return $videos;
|
|
}
|
|
}
|