From 0c6ddaf1c5408c607b0884baf3dbaf7e2aebb950 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Tue, 5 Dec 2023 17:25:53 +0800 Subject: [PATCH] oarty_cate_user_rank --- app/Admin/Controllers/PartyCateController.php | 93 ++++++++++++++++++- app/Admin/Controllers/UserRankController.php | 1 - app/Admin/routes.php | 1 + app/Console/Commands/CateRank.php | 6 +- app/Console/Commands/UserRank.php | 6 +- app/ModelFilters/UserRankFilter.php | 5 + lang/zh_CN/user_rank.php | 1 + 7 files changed, 104 insertions(+), 9 deletions(-) diff --git a/app/Admin/Controllers/PartyCateController.php b/app/Admin/Controllers/PartyCateController.php index 1f25487..aa95252 100644 --- a/app/Admin/Controllers/PartyCateController.php +++ b/app/Admin/Controllers/PartyCateController.php @@ -7,11 +7,13 @@ use App\Admin\Services\ArticleService; use App\Admin\Services\PartyCateService; use App\Admin\Services\PartyUserService; use App\Admin\Services\UserScoreService; +use App\Admin\Services\UserRankService; use App\Enums\CheckStatus; use App\Models\Article; use App\Models\Keyword; use App\Models\PartyCate; use App\Models\PartyUser; +use App\Models\CateRank; use Illuminate\Http\Request; use Illuminate\Support\Str; use Slowlyo\OwlAdmin\Admin; @@ -28,6 +30,8 @@ class PartyCateController extends AdminController protected $userOptions; + protected $snOptions; + public function index() { $user = Admin::user(); @@ -84,6 +88,7 @@ class PartyCateController extends AdminController ) ), amisMake()->LinkAction()->label('审核评定')->level('link')->link('/party-cate/${'.$primary.'}/score'), + amisMake()->LinkAction()->label('排名')->level('link')->link('/party-cate/${'.$primary.'}/rank'), $this->rowShowButton(), $this->rowEditButton(true), $this->rowDeleteButton(), @@ -168,7 +173,7 @@ class PartyCateController extends AdminController ]), ]); return $userController->baseList($crud)->title( - amisMake()->LinkAction()->body($cate->name)->onEvent(['click' => ['actions' => ['actionType' => 'goBack']]]) + amisMake()->LinkAction()->body($cate->name)->onEvent(['click' => ['actions' => [['actionType' => 'goBack']]]]) )->subTitle('党员管理'); } @@ -270,10 +275,94 @@ class PartyCateController extends AdminController ]); return $this->baseList($crud)->title( - amisMake()->LinkAction()->body($cate->name)->onEvent(['click' => ['actions' => ['actionType' => 'goBack']]]) + amisMake()->LinkAction()->body($cate->name)->onEvent(['click' => ['actions' => [['actionType' => 'goBack']]]]) )->subTitle('审核评定'); } + public function rankList($cid) + { + $service = UserRankService::make(); + $cate = PartyCate::find($cid); + request()->offsetSet('cate_id', $cid); + $options = $this->getSnOptions(); + if ($this->actionOfGetData()) { + if (!request()->has('sn') && count($options) > 0) { + request()->offsetSet('sn', $options[0]); + } + return $this->response()->success($service->list()); + } + + if ($this->actionOfExport()) { + $sn = request('sn', data_get($this->getSnOptions(), 0)); + if (!$sn) { + return $this->response()->fail('请选择期数'); + } + // 默认在 storage/app/ 下 + $path = __('user_rank.user_cate_rank') . '-' . $sn . '.xlsx'; + + // 此处使用 laravel-excel 导出,可自行修改 + (new \App\Exports\UserRank)->store($path, 'local'); + + return $this->response()->success(compact('path')); + } + $event = fn($script) => ['click' => ['actions' => [['actionType' => 'custom', 'script' => $script]]]]; + $downloadPath = '/' . admin_url('_download_export', true); + $exportPath = $this->getExportPath(); + $doAction = <<set('icon', 'fa-solid fa-download') + ->align('right') + ->onEvent($event( + <<baseCRUD() + ->filterTogglable(false) + ->columnsTogglable(false) + ->loadDataOnce(true) + ->footerToolbar([]) + ->headerToolbar([ + $exportAction + ]) + ->filter($this->baseFilter()->actions()->body([ + amisMake()->SelectControl()->name('sn')->label(__('user_rank.sn'))->options($options)->value(count($options) > 0 ? $options[0] : '')->size('md'), + amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'), + ])) + ->columns([ + amisMake()->TableColumn()->name('user.name')->label(__('user_rank.user_id')), + amisMake()->TableColumn()->name('sort')->label(__('user_rank.sort'))->set('type', 'tpl')->tpl('${(start - 1) * size + index + 1}'), + amisMake()->TableColumn()->name('score')->label(__('user_rank.score')), + ]); + return $this->baseList($crud)->title( + amisMake()->LinkAction()->body($cate->name)->onEvent(['click' => ['actions' => [['actionType' => 'goBack']]]]) + )->subTitle(__('user_rank.user_cate_rank')); + } + + public function getSnOptions() + { + if (!$this->snOptions) { + $this->snOptions = CateRank::select('sn')->groupBy('sn')->orderBy('sn', 'desc')->pluck('sn'); + } + + return $this->snOptions; + } + public function getUserOptions() { if (!$this->userOptions) { diff --git a/app/Admin/Controllers/UserRankController.php b/app/Admin/Controllers/UserRankController.php index 664cbba..51ebe65 100644 --- a/app/Admin/Controllers/UserRankController.php +++ b/app/Admin/Controllers/UserRankController.php @@ -40,7 +40,6 @@ class UserRankController extends AdminController $crud = $this->baseCRUD() ->filterTogglable(false) ->columnsTogglable(false) - ->loadDataOnce(true) ->footerToolbar([]) ->headerToolbar([ $this->exportAction(), diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 80be8e1..a48a868 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -45,6 +45,7 @@ Route::group([ $router->get('party-cate/{id}/article', [\App\Admin\Controllers\PartyCateController::class, 'articleUpdate']); $router->post('party-cate/{id}/article', [\App\Admin\Controllers\PartyCateController::class, 'articleUpdate']); $router->get('party-cate/{id}/score', [\App\Admin\Controllers\PartyCateController::class, 'scoreIndex']); + $router->get('party-cate/{id}/rank', [\App\Admin\Controllers\PartyCateController::class, 'rankList']); // 党员 $router->resource('party-user', \App\Admin\Controllers\PartyUserController::class)->names('admin.party_user'); // 评议审核 diff --git a/app/Console/Commands/CateRank.php b/app/Console/Commands/CateRank.php index d23662b..6aea1ae 100644 --- a/app/Console/Commands/CateRank.php +++ b/app/Console/Commands/CateRank.php @@ -14,14 +14,14 @@ class CateRank extends Command * * @var string */ - protected $signature = 'app:cate-rank'; + protected $signature = 'app:cate-rank {--quarter=1}'; /** * The console command description. * * @var string */ - protected $description = '生成上一季度的党支部排名'; + protected $description = '生成党支部排名记录, quarter: 上一季度'; /** * Execute the console command. @@ -29,7 +29,7 @@ class CateRank extends Command public function handle() { $now = now(); - $time = $now->copy()->subQuarter(); + $time = $now->copy()->subQuarters($this->option('quarter')); $start = $time->copy()->startOfQuarter(); $end = $time->copy()->endOfQuarter(); $sn = $time->year . '-' . $time->quarter; diff --git a/app/Console/Commands/UserRank.php b/app/Console/Commands/UserRank.php index a5703c5..790d747 100644 --- a/app/Console/Commands/UserRank.php +++ b/app/Console/Commands/UserRank.php @@ -14,14 +14,14 @@ class UserRank extends Command * * @var string */ - protected $signature = 'app:user-rank'; + protected $signature = 'app:user-rank {--quarter=1}'; /** * The console command description. * * @var string */ - protected $description = '生成上一季度的党支部排名'; + protected $description = '生成党员排名记录, quarter: 上一季度'; /** * Execute the console command. @@ -29,7 +29,7 @@ class UserRank extends Command public function handle() { $now = now(); - $time = $now->copy()->subQuarter(); + $time = $now->copy()->subQuarters($this->option('quarter')); $start = $time->copy()->startOfQuarter(); $end = $time->copy()->endOfQuarter(); $sn = $time->year . '-' . $time->quarter; diff --git a/app/ModelFilters/UserRankFilter.php b/app/ModelFilters/UserRankFilter.php index 38db2ce..7b50b66 100644 --- a/app/ModelFilters/UserRankFilter.php +++ b/app/ModelFilters/UserRankFilter.php @@ -23,4 +23,9 @@ class UserRankFilter extends ModelFilter { $this->where('sn', $sn); } + + public function cate($id) + { + $this->where('cate_id', $id); + } } diff --git a/lang/zh_CN/user_rank.php b/lang/zh_CN/user_rank.php index 38ddada..3a79617 100644 --- a/lang/zh_CN/user_rank.php +++ b/lang/zh_CN/user_rank.php @@ -6,6 +6,7 @@ return [ 'updated_at' => '更新时间', 'user_rank' => '个人排名', 'cate_rank' => '支部排名', + 'user_cate_rank' => '支部内部排名', 'sn' => '期数', 'user_id' => '党员',