mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-07-31 14:16:57 -04:00
121 lines
3.9 KiB
PHP
121 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\Frontend\Services;
|
|
|
|
use Modules\Frontend\Entities\Creator;
|
|
use Modules\Frontend\Entities\Video;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class Videos
|
|
{
|
|
public function all()
|
|
{
|
|
$videos = Video::get();
|
|
|
|
return $videos;
|
|
}
|
|
|
|
public function getByPage($page, $rows, $filter = null)
|
|
{
|
|
$videos = Video::when(!empty($filter), function ($query) use ($filter) {
|
|
if (is_numeric($filter)) {
|
|
$query->where('id', (int) $filter);
|
|
} else {
|
|
$query
|
|
->orWhere('asin', 'LIKE', "%$filter%")
|
|
->orWhere('title', 'LIKE', "%$filter%")
|
|
->orWhere('description', 'LIKE', "%$filter%")
|
|
->orWhere('product_name', 'LIKE', "%$filter%");
|
|
}
|
|
});
|
|
|
|
$count = (clone $videos)
|
|
->get()
|
|
->count();
|
|
|
|
$videos = Video::with('thumbnail');
|
|
$videos = $videos
|
|
->when(!empty($filter), function ($query) use ($filter) {
|
|
if (is_numeric($filter)) {
|
|
$query->where('id', (int) $filter);
|
|
} else {
|
|
$query
|
|
->orWhere('asin', 'LIKE', "%$filter%")
|
|
->orWhere('title', 'LIKE', "%$filter%")
|
|
->orWhere('description', 'LIKE', "%$filter%")
|
|
->orWhere('product_name', 'LIKE', "%$filter%");
|
|
}
|
|
})
|
|
->skip($page * $rows)
|
|
->take($rows)
|
|
->get();
|
|
|
|
return [
|
|
'count' => $count,
|
|
'videos' => $videos,
|
|
];
|
|
}
|
|
|
|
public function getByCategory($category, $limit = null, $skipped = null)
|
|
{
|
|
return Video::with('thumbnail')
|
|
->where('studio_plus_category_id', $category->id)
|
|
->latest()
|
|
->when($skipped, fn ($query) => $query->skip($skipped))
|
|
->when($limit, fn ($query) => $query->take($limit))
|
|
->get();
|
|
}
|
|
|
|
public function getByCategories($ids, $limit = null, $skipped = null)
|
|
{
|
|
return Video::with('thumbnail')
|
|
->where('is_short', false)
|
|
->whereIn('studio_plus_category_id', $ids)
|
|
->latest()
|
|
->when($skipped, fn ($query) => $query->skip($skipped))
|
|
->when($limit, fn ($query) => $query->take($limit))
|
|
->get();
|
|
}
|
|
|
|
public function getByCreator($creator, $limit = null, $skipped = null)
|
|
{
|
|
return Cache::remember('ott_creator_videos_' . $creator->id, 60 * 60, function () use ($creator,$skipped,$limit) {
|
|
return Video::with('thumbnail')
|
|
->whereHas('channel', function ($query) use ($creator) {
|
|
$query->where('user_id', $creator->id);
|
|
})
|
|
->when(!empty($skipped), fn ($query) => $query->skip($skipped))
|
|
->when(!empty($limit), fn ($query) => $query->take($limit))
|
|
->latest()
|
|
->get();
|
|
});
|
|
}
|
|
|
|
public function getByKeyword($keyword, $limit = null, $skipped = null)
|
|
{
|
|
return Video::with('thumbnail')
|
|
->where(function ($query) use ($keyword) {
|
|
if (is_numeric($keyword)) {
|
|
$query->where('id', (int) $keyword);
|
|
} else {
|
|
$query
|
|
->where('asin', 'LIKE', "%$keyword%")
|
|
->orWhere('title', 'LIKE', "%$keyword%")
|
|
->orWhere('description', 'LIKE', "%$keyword%")
|
|
->orWhere('product_name', 'LIKE', "%$keyword%");
|
|
}
|
|
})
|
|
->when(!empty($skipped), fn ($query) => $query->skip($skipped))
|
|
->when(!empty($limit), fn ($query) => $query->take($limit))
|
|
->latest()
|
|
->get();
|
|
}
|
|
|
|
public function getVideoCreator($video)
|
|
{
|
|
$channel = $video->channel;
|
|
|
|
return Creator::find($channel->user_id);
|
|
}
|
|
}
|