generated from panliang/owl-admin-starter
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Services;
|
|
|
|
use App\ModelFilters\UserRankFilter;
|
|
use App\Models\{UserRank, PartyUser};
|
|
|
|
class UserRankService extends BaseService
|
|
{
|
|
protected array $withRelationships = ['user', 'cate'];
|
|
|
|
protected string $modelName = UserRank::class;
|
|
|
|
protected string $modelFilterName = UserRankFilter::class;
|
|
|
|
public function listQuery()
|
|
{
|
|
$filter = $this->getModelFilter();
|
|
|
|
$query = $this->query();
|
|
if ($this->withRelationships) {
|
|
$query->with($this->withRelationships);
|
|
}
|
|
|
|
if ($filter) {
|
|
$query->filter(request()->input(), $filter);
|
|
}
|
|
|
|
return $query->sort();
|
|
}
|
|
|
|
public function list()
|
|
{
|
|
$sn = request('sn', '当前');
|
|
$items = [];
|
|
if ($sn == '当前') {
|
|
$items = PartyUser::with(['cate'])->orderBy('current_score', 'desc')->get()->map(fn($item) => [
|
|
'id' => $item->id,
|
|
'name' => $item->name,
|
|
'user' => ['name' => $item->name],
|
|
'cate_id' => $item->cate_id,
|
|
'cate' => ['name' => $item->cate?->name],
|
|
'score' => $item->current_score,
|
|
]);
|
|
} else {
|
|
$query = $this->listQuery();
|
|
|
|
$items = (clone $query)->get();
|
|
}
|
|
|
|
return compact('items');
|
|
}
|
|
}
|