generated from panliang/owl-admin-starter
cate_rank
parent
d36be767cf
commit
0cd81bfbef
|
|
@ -13,23 +13,6 @@ class CateRankController extends AdminController
|
||||||
|
|
||||||
protected $snOptions;
|
protected $snOptions;
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
if ($this->actionOfGetData()) {
|
|
||||||
$options = $this->getSnOptions();
|
|
||||||
if (!request()->has('sn') && count($options) > 0) {
|
|
||||||
request()->offsetSet('sn', $options[0]);
|
|
||||||
}
|
|
||||||
return $this->response()->success($this->service->list());
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->actionOfExport()) {
|
|
||||||
return $this->export();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->response()->success($this->list());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function list(): Page
|
public function list(): Page
|
||||||
{
|
{
|
||||||
$options = $this->getSnOptions();
|
$options = $this->getSnOptions();
|
||||||
|
|
@ -42,7 +25,7 @@ class CateRankController extends AdminController
|
||||||
->footerToolbar([])
|
->footerToolbar([])
|
||||||
->loadDataOnce()
|
->loadDataOnce()
|
||||||
->filter($this->baseFilter()->actions()->body([
|
->filter($this->baseFilter()->actions()->body([
|
||||||
amisMake()->SelectControl()->name('sn')->label(__('user_rank.sn'))->options($options)->value(count($options) > 0 ? $options[0] : '')->size('md'),
|
amisMake()->SelectControl()->name('sn')->label(__('user_rank.sn'))->options($this->getSnOptions())->size('md'),
|
||||||
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
||||||
]))
|
]))
|
||||||
->columns([
|
->columns([
|
||||||
|
|
@ -57,7 +40,7 @@ class CateRankController extends AdminController
|
||||||
public function getSnOptions()
|
public function getSnOptions()
|
||||||
{
|
{
|
||||||
if (!$this->snOptions) {
|
if (!$this->snOptions) {
|
||||||
$this->snOptions = CateRank::select('sn')->groupBy('sn')->orderBy('sn', 'desc')->pluck('sn');
|
$this->snOptions = CateRank::select('sn')->groupBy('sn')->orderBy('sn', 'desc')->pluck('sn')->prepend('当前');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->snOptions;
|
return $this->snOptions;
|
||||||
|
|
|
||||||
|
|
@ -17,26 +17,8 @@ class UserRankController extends AdminController
|
||||||
|
|
||||||
protected $snOptions;
|
protected $snOptions;
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
if ($this->actionOfGetData()) {
|
|
||||||
$options = $this->getSnOptions();
|
|
||||||
if (!request()->has('sn') && count($options) > 0) {
|
|
||||||
request()->offsetSet('sn', $options[0]);
|
|
||||||
}
|
|
||||||
return $this->response()->success($this->service->list());
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->actionOfExport()) {
|
|
||||||
return $this->export();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->response()->success($this->list());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function list(): Page
|
public function list(): Page
|
||||||
{
|
{
|
||||||
$options = $this->getSnOptions();
|
|
||||||
$crud = $this->baseCRUD()
|
$crud = $this->baseCRUD()
|
||||||
->filterTogglable(false)
|
->filterTogglable(false)
|
||||||
->columnsTogglable(false)
|
->columnsTogglable(false)
|
||||||
|
|
@ -45,7 +27,7 @@ class UserRankController extends AdminController
|
||||||
$this->exportAction(),
|
$this->exportAction(),
|
||||||
])
|
])
|
||||||
->filter($this->baseFilter()->actions()->body([
|
->filter($this->baseFilter()->actions()->body([
|
||||||
amisMake()->SelectControl()->name('sn')->label(__('user_rank.sn'))->options($options)->value(count($options) > 0 ? $options[0] : '')->size('md'),
|
amisMake()->SelectControl()->name('sn')->label(__('user_rank.sn'))->options($this->getSnOptions())->size('md'),
|
||||||
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
||||||
]))
|
]))
|
||||||
->columns([
|
->columns([
|
||||||
|
|
@ -61,7 +43,7 @@ class UserRankController extends AdminController
|
||||||
public function getSnOptions()
|
public function getSnOptions()
|
||||||
{
|
{
|
||||||
if (!$this->snOptions) {
|
if (!$this->snOptions) {
|
||||||
$this->snOptions = UserRank::select('sn')->groupBy('sn')->orderBy('sn', 'desc')->pluck('sn');
|
$this->snOptions = UserRank::select('sn')->groupBy('sn')->orderBy('sn', 'desc')->pluck('sn')->prepend('当前');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->snOptions;
|
return $this->snOptions;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace App\Admin\Services;
|
namespace App\Admin\Services;
|
||||||
|
|
||||||
use App\ModelFilters\CateRankFilter;
|
use App\ModelFilters\CateRankFilter;
|
||||||
use App\Models\CateRank;
|
use App\Models\{CateRank, PartyCate};
|
||||||
|
|
||||||
class CateRankService extends BaseService
|
class CateRankService extends BaseService
|
||||||
{
|
{
|
||||||
|
|
@ -31,9 +31,23 @@ class CateRankService extends BaseService
|
||||||
|
|
||||||
public function list()
|
public function list()
|
||||||
{
|
{
|
||||||
$query = $this->listQuery();
|
$sn = request('sn', '当前');
|
||||||
|
$items = [];
|
||||||
|
if ($sn == '当前') {
|
||||||
|
$items = PartyCate::withCount(['users'])->get()->map(fn($item) => [
|
||||||
|
'id' => $item->id,
|
||||||
|
'name' => $item->name,
|
||||||
|
'cate' => ['name' => $item->name],
|
||||||
|
'current_score' => $item->current_score,
|
||||||
|
'count' => $item->users_count,
|
||||||
|
'avg_score' => $item->users_count ? floor($item->current_score / $item->users_count) : 0,
|
||||||
|
])->sortByDesc('avg_score');
|
||||||
|
} else {
|
||||||
|
$query = $this->listQuery();
|
||||||
|
|
||||||
|
$items = (clone $query)->get();
|
||||||
|
}
|
||||||
|
|
||||||
$items = (clone $query)->get();
|
|
||||||
|
|
||||||
return compact('items');
|
return compact('items');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace App\Admin\Services;
|
namespace App\Admin\Services;
|
||||||
|
|
||||||
use App\ModelFilters\UserRankFilter;
|
use App\ModelFilters\UserRankFilter;
|
||||||
use App\Models\UserRank;
|
use App\Models\{UserRank, PartyUser};
|
||||||
|
|
||||||
class UserRankService extends BaseService
|
class UserRankService extends BaseService
|
||||||
{
|
{
|
||||||
|
|
@ -31,9 +31,22 @@ class UserRankService extends BaseService
|
||||||
|
|
||||||
public function list()
|
public function list()
|
||||||
{
|
{
|
||||||
$query = $this->listQuery();
|
$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();
|
$items = (clone $query)->get();
|
||||||
|
}
|
||||||
|
|
||||||
return compact('items');
|
return compact('items');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class CateRank implements FromQuery, WithHeadings, WithMapping
|
||||||
return [
|
return [
|
||||||
$item->cate?->name,
|
$item->cate?->name,
|
||||||
++$this->index,
|
++$this->index,
|
||||||
$item->avg_score,
|
$item->avg_score . '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class UserRank implements FromQuery, WithHeadings, WithMapping
|
||||||
$item->cate?->name,
|
$item->cate?->name,
|
||||||
$item->user?->name,
|
$item->user?->name,
|
||||||
++$this->index,
|
++$this->index,
|
||||||
$item->score,
|
$item->score . '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class AdminMenuSeeder extends Seeder
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
// 图标: https://iconpark.oceanengine.com/official
|
// 图标: https://iconpark.oceanengine.com/official, https://icones.js.org
|
||||||
$menus = [
|
$menus = [
|
||||||
['title' => '主页', 'icon' => 'icon-park:home-two', 'url' => '/dashboard', 'is_home' => 1, 'permission' => ['dashboard']],
|
['title' => '主页', 'icon' => 'icon-park:home-two', 'url' => '/dashboard', 'is_home' => 1, 'permission' => ['dashboard']],
|
||||||
['title' => '支部管理', 'icon' => 'icon-park:flag', 'url' => '/party-cate', 'permission' => ['party_cate']],
|
['title' => '支部管理', 'icon' => 'icon-park:flag', 'url' => '/party-cate', 'permission' => ['party_cate']],
|
||||||
|
|
@ -27,7 +27,7 @@ class AdminMenuSeeder extends Seeder
|
||||||
['title' => '信息管理', 'icon' => 'icon-park:web-page', 'url' => '/articles', 'permission' => ['article']],
|
['title' => '信息管理', 'icon' => 'icon-park:web-page', 'url' => '/articles', 'permission' => ['article']],
|
||||||
['title' => '广告管理', 'icon' => 'icon-park:picture-one', 'url' => '/banner', 'permission' => ['banner']],
|
['title' => '广告管理', 'icon' => 'icon-park:picture-one', 'url' => '/banner', 'permission' => ['banner']],
|
||||||
['title' => '个人排名', 'icon' => 'icon-park:sort-one', 'url' => '/user-rank', 'permission' => ['user_rank']],
|
['title' => '个人排名', 'icon' => 'icon-park:sort-one', 'url' => '/user-rank', 'permission' => ['user_rank']],
|
||||||
['title' => '支部排名', 'icon' => 'icon-park:sort-one', 'url' => '/cate-rank', 'permission' => ['cate_rank']],
|
['title' => '支部排名', 'icon' => 'icon-park:sort-amount-down', 'url' => '/cate-rank', 'permission' => ['cate_rank']],
|
||||||
['title' => '书记信箱', 'icon' => 'icon-park:comment', 'url' => '/feedback', 'permission' => ['feedback']],
|
['title' => '书记信箱', 'icon' => 'icon-park:comment', 'url' => '/feedback', 'permission' => ['feedback']],
|
||||||
['title' => '系统管理', 'icon' => 'icon-park:setting', 'url' => '/system', 'permission' => ['system'], 'children' => [
|
['title' => '系统管理', 'icon' => 'icon-park:setting', 'url' => '/system', 'permission' => ['system'], 'children' => [
|
||||||
['title' => '用户管理', 'icon' => 'icon-park:people-plus', 'url' => '/system/admin_users', 'permission' => ['admin_user']],
|
['title' => '用户管理', 'icon' => 'icon-park:people-plus', 'url' => '/system/admin_users', 'permission' => ['admin_user']],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue