generated from panliang/owl-admin-starter
286 lines
15 KiB
PHP
286 lines
15 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Components;
|
|
use App\Admin\Services\ArticleService;
|
|
use App\Admin\Services\PartyCateService;
|
|
use App\Admin\Services\PartyUserService;
|
|
use App\Admin\Services\UserScoreService;
|
|
use App\Enums\CheckStatus;
|
|
use App\Models\Article;
|
|
use App\Models\Keyword;
|
|
use App\Models\PartyCate;
|
|
use App\Models\PartyUser;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
use Slowlyo\OwlAdmin\Admin;
|
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
|
|
/**
|
|
* 党支部管理
|
|
*/
|
|
class PartyCateController extends AdminController
|
|
{
|
|
protected string $serviceName = PartyCateService::class;
|
|
|
|
protected $userOptions;
|
|
|
|
public function index()
|
|
{
|
|
$user = Admin::user();
|
|
// 判断当前账户拥有的支部权限
|
|
if (!$user->can('party_cate_all')) {
|
|
$permissions = $user->allPermissions()->where(fn ($item) => Str::startsWith($item->slug, 'party_cate_') && $item->http_method)->pluck('http_method')->all();
|
|
request()->offsetSet('ids', $permissions);
|
|
}
|
|
if ($this->actionOfGetData()) {
|
|
return $this->response()->success($this->service->list());
|
|
}
|
|
|
|
if ($this->actionOfExport()) {
|
|
return $this->export();
|
|
}
|
|
|
|
return $this->response()->success($this->list());
|
|
}
|
|
|
|
public function list(): Page
|
|
{
|
|
$primary = $this->service->primaryKey();
|
|
$crud = $this->baseCRUD()
|
|
->filterTogglable(false)
|
|
->columnsTogglable(false)
|
|
->headerToolbar([
|
|
$this->createButton(true),
|
|
])
|
|
->filter($this->baseFilter()->actions([])->body([
|
|
amisMake()->TextControl()->name('name')->label(__('party_cate.name'))->size('md')->clearable(),
|
|
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
|
]))
|
|
->columns([
|
|
amisMake()->TableColumn()->name('id')->label(__('party_cate.id')),
|
|
amisMake()->TableColumn()->name('name')->label(__('party_cate.name')),
|
|
amisMake()->TableColumn()->name('master.name')->label(__('party_cate.master_id')),
|
|
amisMake()->TableColumn()->name('plan.name')->label(__('party_cate.plan_id')),
|
|
amisMake()->TableColumn()->name('score')->label(__('party_cate.score')),
|
|
amisMake()->TableColumn()->name('remarks')->label(__('party_cate.remarks')),
|
|
$this->rowActions([
|
|
amisMake()->LinkAction()->label('党员管理')->level('link')->link('/party-cate/${'.$primary.'}/user'),
|
|
amisMake()->DialogAction()->label('评星规则')->level('link')->level('link')->dialog(
|
|
amisMake()->Dialog()->size('lg')->title('')->body($this->baseForm()
|
|
->title('')
|
|
->onEvent([])
|
|
->redirect('')
|
|
->initApi('/party-cate/${'.$primary.'}/article?_action=getData')
|
|
->api('post:' . admin_url('/party-cate/${'.$primary.'}/article'))
|
|
->body([
|
|
amisMake()->TextControl()->name('title')->label(__('article.title'))->required(true),
|
|
amisMake()->ImageControl()->name('cover')->label(__('article.cover'))->autoUpload(true),
|
|
Components::make()->fuEditorControl('content', __('article.content')),
|
|
])
|
|
)
|
|
),
|
|
amisMake()->LinkAction()->label('审核评定')->level('link')->link('/party-cate/${'.$primary.'}/score'),
|
|
$this->rowShowButton(),
|
|
$this->rowEditButton(true),
|
|
$this->rowDeleteButton(),
|
|
]),
|
|
]);
|
|
|
|
return $this->baseList($crud);
|
|
}
|
|
|
|
public function form(): Form
|
|
{
|
|
return $this->baseForm()->title('')->body([
|
|
amisMake()->TextControl()->name('name')->label(__('party_cate.name'))->required(),
|
|
amisMake()->SelectControl()->name('master_id')->label(__('party_cate.master_id'))->options($this->getUserOptions())->searchable(),
|
|
amisMake()->SelectControl()->name('plan_id')->label(__('party_cate.plan_id'))->options($this->getUserOptions())->searchable(),
|
|
amisMake()->TextControl()->name('remarks')->label(__('party_cate.remarks')),
|
|
]);
|
|
}
|
|
|
|
public function detail(): Form
|
|
{
|
|
return $this->baseDetail()->title('')->body([
|
|
amisMake()->TextControl()->name('id')->label(__('party_cate.id'))->static(),
|
|
amisMake()->TextControl()->name('name')->label(__('party_cate.name'))->static(),
|
|
amisMake()->TextControl()->name('master.name')->label(__('party_cate.master_id'))->static(),
|
|
amisMake()->TextControl()->name('plan.name')->label(__('party_cate.plan_id'))->static(),
|
|
amisMake()->TextControl()->name('remarks')->label(__('party_cate.remarks'))->static(),
|
|
amisMake()->TextControl()->name('score')->label(__('party_cate.score'))->static(),
|
|
amisMake()->TextControl()->name('scores')->label(__('party_cate.scores'))->static()->staticSchema(amisMake()->Json()),
|
|
amisMake()->TextControl()->name('created_at')->label(__('party_cate.created_at'))->static(),
|
|
]);
|
|
}
|
|
|
|
public function userIndex($cid)
|
|
{
|
|
$service = PartyUserService::make();
|
|
$userController = new PartyUserController();
|
|
$primary = $service->primaryKey();
|
|
$cate = PartyCate::find($cid);
|
|
request()->offsetSet('cate_id', $cid);
|
|
if ($userController->actionOfGetData()) {
|
|
return $userController->response()->success($service->list());
|
|
}
|
|
|
|
if ($userController->actionOfExport()) {
|
|
return $userController->export();
|
|
}
|
|
$crud = $userController->baseCRUD()
|
|
->filterTogglable(false)
|
|
->columnsTogglable(false)
|
|
->headerToolbar([
|
|
amisMake()->DialogAction()->label(__('admin.create'))->icon('fa fa-add')->level('primary')->dialog(
|
|
amisMake()->Dialog()->title(__('admin.create'))->body(
|
|
$userController->form(false)->data(['cate_id' => $cid])->api('/party-user')->onEvent([])
|
|
)
|
|
),
|
|
])
|
|
->filter($userController->baseFilter()->actions([])->body([
|
|
amisMake()->TextControl()->name('name')->label(__('party_user.name'))->size('md')->clearable(),
|
|
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
|
]))
|
|
->columns([
|
|
amisMake()->TableColumn()->name('id')->label(__('party_user.id')),
|
|
amisMake()->TableColumn()->name('name')->label(__('party_user.name')),
|
|
amisMake()->TableColumn()->set('type', 'avatar')->set('src', '${avatar}')->name('avatar')->label(__('party_user.avatar')),
|
|
amisMake()->TableColumn()->name('score')->label(__('party_user.score')),
|
|
$userController->rowActions([
|
|
amisMake()->DialogAction()->label(__('admin.show'))->icon('fa-regular fa-eye')->level('link')->dialog(
|
|
amisMake()->Dialog()->title(__('admin.show'))->body($userController->detail('$id')->initApi('/party-user/${' . $primary . '}?_action=getData'))
|
|
),
|
|
amisMake()->DialogAction()->label(__('admin.edit'))->icon('fa-regular fa-pen-to-square')->level('link')->dialog(
|
|
amisMake()->Dialog()->title(__('admin.edit'))->body(
|
|
$userController->form(true)->api('put:' . admin_url('/party-user/${' . $primary . '}'))->initApi('/party-user/${' . $primary . '}/edit?_action=getData')->redirect('')->onEvent([])
|
|
)
|
|
),
|
|
amisMake()->AjaxAction()
|
|
->label(__('admin.delete'))
|
|
->icon('fa-regular fa-trash-can')
|
|
->level('link')
|
|
->confirmText('删除党员: ${name}')
|
|
->api('delete:' . admin_url('/party-user/${'.$primary.'}')),
|
|
]),
|
|
]);
|
|
return $userController->baseList($crud)->title(
|
|
amisMake()->LinkAction()->body($cate->name)->onEvent(['click' => ['actions' => ['actionType' => 'goBack']]])
|
|
)->subTitle('党员管理');
|
|
}
|
|
|
|
public function articleUpdate($cid, Request $request)
|
|
{
|
|
if ($this->actionOfGetData()) {
|
|
return $this->response()->success(Article::where('party_cate_id', $cid)->first());
|
|
}
|
|
$service = ArticleService::make();
|
|
$data = $service->resloveData($request->all());
|
|
Article::updateOrCreate(['party_cate_id' => $cid, 'category_id' => Keyword::where('key', 'category_2')->value('id')], $data);
|
|
|
|
return $this->response()->success();
|
|
}
|
|
|
|
public function scoreIndex($cid)
|
|
{
|
|
$service = UserScoreService::make();
|
|
$userController = new UserScoreController();
|
|
$primary = $service->primaryKey();
|
|
$cate = PartyCate::find($cid);
|
|
request()->offsetSet('cate_id', $cid);
|
|
if ($userController->actionOfGetData()) {
|
|
return $userController->response()->success($service->list());
|
|
}
|
|
|
|
if ($userController->actionOfExport()) {
|
|
return $userController->export();
|
|
}
|
|
|
|
$crud = $this->baseCRUD()
|
|
->filterTogglable(false)
|
|
->columnsTogglable(false)
|
|
->headerToolbar([])
|
|
->filter($this->baseFilter()->actions([])->body([
|
|
amisMake()->SelectControl()->name('type_id')->label(__('user_score.type_id'))->options($userController->getTypeOptions())->clearable()->size('md'),
|
|
amisMake()->SelectControl()->name('user_id')->label(__('user_score.user_id'))->options($userController->getUserOptions())->clearable()->size('md'),
|
|
amisMake()->TextControl()->name('title')->label(__('user_score.title'))->clearable()->size('md'),
|
|
amisMake()->SelectControl()->name('check_status')->label(__('user_score.check_status'))->options(CheckStatus::options())->clearable()->size('md'),
|
|
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
|
]))
|
|
->columns([
|
|
amisMake()->TableColumn()->name('id')->label(__('user_score.id')),
|
|
amisMake()->TableColumn()->name('type.name')->label(__('user_score.type_id')),
|
|
amisMake()->TableColumn()->name('user.name')->label(__('user_score.user_id')),
|
|
amisMake()->TableColumn()->name('title')->label(__('user_score.title')),
|
|
amisMake()->TableColumn()->name('check_status_text')->label(__('user_score.check_status')),
|
|
amisMake()->TableColumn()->name('score')->label(__('user_score.score')),
|
|
amisMake()->TableColumn()->name('created_at')->label(__('user_score.created_at')),
|
|
$this->rowActions([
|
|
amisMake()->DialogAction()
|
|
->label(__('admin.show'))
|
|
->icon('fa-regular fa-eye')
|
|
->level('link')
|
|
->dialog(
|
|
amisMake()->Dialog()->title(__('admin.show'))->size('lg')->body(
|
|
amisMake()->Service()->api('/user-score/${'.$primary.'}?_action=getData')->body(
|
|
amisMake()->Property()->column(3)->items([
|
|
['label' => __('user_score.type_id'), 'content' => '${type.name}'],
|
|
['label' => __('user_score.user_id'), 'content' => '${user.name}'],
|
|
['label' => __('user_score.created_at'), 'content' => '${created_at}'],
|
|
|
|
['label' => __('user_score.check_status'), 'content' => '${check_status_text}'],
|
|
['label' => __('user_score.check_user_id'), 'content' => '${check_user.name}'],
|
|
['label' => __('user_score.check_at'), 'content' => '${check_at}'],
|
|
|
|
['label' => __('user_score.score'), 'content' => '${score}', 'span' => 3],
|
|
|
|
['label' => __('user_score.title'), 'content' => '${title}', 'span' => 3],
|
|
['label' => __('user_score.content'), 'content' => amisMake()->TextareaControl()->value('${content}')->static(), 'span' => 3],
|
|
['label' => __('user_score.images'), 'content' => amisMake()->Images()->source('${images}'), 'span' => 3],
|
|
['label' => __('user_score.file'), 'content' => amisMake()->Link()->body('${file}')->blank()->href('${file}'), 'span' => 3],
|
|
])
|
|
)
|
|
)
|
|
),
|
|
amisMake()->DialogAction()
|
|
->visibleOn('${check_status != '.CheckStatus::Success->value.'}')
|
|
->label('审核')
|
|
->level('link')
|
|
->dialog(
|
|
amisMake()->Dialog()->title('审核')->size('lg')->body(
|
|
amisMake()->Form()
|
|
->data(['check_status' => CheckStatus::Success->value])
|
|
->api('post:' . admin_url('/user-score/${'.$primary.'}/check'))
|
|
->onEvent('')
|
|
->redirect('')
|
|
->body([
|
|
amisMake()->RadiosControl()->name('check_status')->label(__('user_score.check_status'))->options([
|
|
CheckStatus::Success->value => CheckStatus::Success->text(),
|
|
CheckStatus::Fail->value => CheckStatus::Fail->text(),
|
|
])->required(),
|
|
amisMake()->NumberControl()->name('score')->label(__('user_score.score')),
|
|
amisMake()->TextControl()->name('check_remarks')->label(__('user_score.check_remarks')),
|
|
])
|
|
),
|
|
)
|
|
]),
|
|
]);
|
|
|
|
return $this->baseList($crud)->title(
|
|
amisMake()->LinkAction()->body($cate->name)->onEvent(['click' => ['actions' => ['actionType' => 'goBack']]])
|
|
)->subTitle('审核评定');
|
|
}
|
|
|
|
public function getUserOptions()
|
|
{
|
|
if (!$this->userOptions) {
|
|
$this->userOptions = PartyUser::select(['id as value', 'name as label'])->get();
|
|
}
|
|
|
|
return $this->userOptions;
|
|
}
|
|
}
|