mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
[admin] filter improve & fix ad link
This commit is contained in:
@@ -11,7 +11,7 @@ class BaseRepository
|
||||
|
||||
protected function getSortFieldAndType(array $params): array
|
||||
{
|
||||
$field = $params['sort_field'] ?? 'id';
|
||||
$field = !empty($params['sort_field']) ? $params['sort_field'] : 'id';
|
||||
$type = 'desc';
|
||||
if (!empty($params['sort_type']) && Str::startsWith($params['sort_type'], 'asc')) {
|
||||
$type = 'asc';
|
||||
|
||||
@@ -302,6 +302,12 @@ class ExamRepository extends BaseRepository
|
||||
if (!empty($params['exam_id'])) {
|
||||
$query->where('exam_id', $params['exam_id']);
|
||||
}
|
||||
if (isset($params['is_done']) && is_numeric($params['is_done'])) {
|
||||
$query->where('is_done', $params['is_done']);
|
||||
}
|
||||
if (isset($params['status']) && is_numeric($params['status'])) {
|
||||
$query->where('status', $params['status']);
|
||||
}
|
||||
list($sortField, $sortType) = $this->getSortFieldAndType($params);
|
||||
$query->orderBy($sortField, $sortType);
|
||||
$result = $query->with(['user', 'exam'])->paginate();
|
||||
|
||||
@@ -70,7 +70,7 @@ class HitAndRunRepository extends BaseRepository
|
||||
}
|
||||
|
||||
//If is VIP or above, pass
|
||||
if ($row->user->class >= User::CLASS_VIP) {
|
||||
if ($row->user->class >= HitAndRun::MINIMUM_IGNORE_USER_CLASS) {
|
||||
$result = $this->reachedBySpecialUserClass($row);
|
||||
if ($result) {
|
||||
$successCounts++;
|
||||
|
||||
@@ -33,7 +33,7 @@ class TorrentRepository extends BaseRepository
|
||||
* @param array $params
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public function getList(array $params)
|
||||
public function getList(array $params, User $user)
|
||||
{
|
||||
$query = Torrent::query();
|
||||
if (!empty($params['category'])) {
|
||||
@@ -84,9 +84,29 @@ class TorrentRepository extends BaseRepository
|
||||
|
||||
$with = ['user'];
|
||||
$torrents = $query->with($with)->paginate();
|
||||
$userArr = $user->toArray();
|
||||
foreach($torrents as &$item) {
|
||||
$item->download_url = $this->getDownloadUrl($item->id, $userArr);
|
||||
}
|
||||
return $torrents;
|
||||
}
|
||||
|
||||
public function getDetail($id, User $user)
|
||||
{
|
||||
$with = ['user', 'basic_audio_codec', 'basic_category', 'basic_codec', 'basic_media', 'basic_source', 'basic_standard', 'basic_team'];
|
||||
$result = Torrent::query()->with($with)->withCount(['peers', 'thank_users'])->visible()->findOrFail($id);
|
||||
$result->download_url = $this->getDownloadUrl($id, $user->toArray());
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getDownloadUrl($id, array $user): string
|
||||
{
|
||||
return sprintf(
|
||||
'%s/download.php?downhash=%s|%s',
|
||||
getSchemeAndHttpHost(), $user['id'], $this->encryptDownHash($id, $user)
|
||||
);
|
||||
}
|
||||
|
||||
private function handleGetListSort(Builder $query, array $params)
|
||||
{
|
||||
if (empty($params['sort_field']) && empty($params['sort_type'])) {
|
||||
@@ -306,6 +326,9 @@ class TorrentRepository extends BaseRepository
|
||||
|
||||
private function getEncryptDownHashKey($user)
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
$user = $user->toArray();
|
||||
}
|
||||
if (!is_array($user) || empty($user['passkey']) || empty($user['id'])) {
|
||||
$user = User::query()->findOrFail(intval($user), ['id', 'passkey'])->toArray();
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ class UserRepository extends BaseRepository
|
||||
if (!empty($params['email'])) {
|
||||
$query->where('email', 'like',"%{$params['email']}%");
|
||||
}
|
||||
if (!empty($params['class'])) {
|
||||
$query->where('class', $params['class']);
|
||||
}
|
||||
list($sortField, $sortType) = $this->getSortFieldAndType($params);
|
||||
$query->orderBy($sortField, $sortType);
|
||||
return $query->paginate();
|
||||
|
||||
Reference in New Issue
Block a user