1
0
Fork 0

oarty_cate_user_rank

master
panliang 2023-12-05 17:25:53 +08:00
parent a7c6260e78
commit 0c6ddaf1c5
7 changed files with 104 additions and 9 deletions

View File

@ -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 = <<<JS
doAction([
{ actionType: "ajax", args: { api: { url: url.toString(), method: "get" } } },
{
actionType: "custom",
expression: "\${event.data.responseResult.responseStatus === 0}",
script: "window.open('{$downloadPath}?path='+event.data.responseResult.responseData.path)"
}
])
JS;
$exportAction = amisMake()->VanillaAction()
->label(__('admin.export.title'))
->set('icon', 'fa-solid fa-download')
->align('right')
->onEvent($event(
<<<JS
let url = new URL("{$exportPath}", window.location.origin)
let param = window.location.href.split('?')[1]
if (param) {
url = url + '&' + param
}
{$doAction}
JS
));
$crud = $this->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) {

View File

@ -40,7 +40,6 @@ class UserRankController extends AdminController
$crud = $this->baseCRUD()
->filterTogglable(false)
->columnsTogglable(false)
->loadDataOnce(true)
->footerToolbar([])
->headerToolbar([
$this->exportAction(),

View File

@ -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');
// 评议审核

View File

@ -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;

View File

@ -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;

View File

@ -23,4 +23,9 @@ class UserRankFilter extends ModelFilter
{
$this->where('sn', $sn);
}
public function cate($id)
{
$this->where('cate_id', $id);
}
}

View File

@ -6,6 +6,7 @@ return [
'updated_at' => '更新时间',
'user_rank' => '个人排名',
'cate_rank' => '支部排名',
'user_cate_rank' => '支部内部排名',
'sn' => '期数',
'user_id' => '党员',