generated from panliang/owl-admin-starter
192 lines
8.5 KiB
PHP
192 lines
8.5 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Services\{UserScoreService, PartyCateService};
|
|
use App\Enums\CheckStatus;
|
|
use App\Exceptions\BaseException;
|
|
use App\Models\PartyUser;
|
|
use App\Models\PartyCate;
|
|
use App\Models\UserScore;
|
|
use Illuminate\Http\Request;
|
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
|
|
class UserScoreController extends AdminController
|
|
{
|
|
protected string $serviceName = UserScoreService::class;
|
|
|
|
protected $typeOptions;
|
|
|
|
protected $userOptions;
|
|
|
|
protected $cateOptions;
|
|
|
|
public function index()
|
|
{
|
|
if (!request()->filled('cate_id')) {
|
|
$cateIds = PartyCateService::make()->catePermissions();
|
|
request()->offsetSet('cate_id', $cateIds);
|
|
}
|
|
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
|
|
{
|
|
$crud = $this->baseCRUD()
|
|
->filterTogglable(false)
|
|
->columnsTogglable(false)
|
|
->headerToolbar([
|
|
$this->createButton(true),
|
|
])
|
|
->filter($this->baseFilter()->actions([])->body([
|
|
amisMake()->SelectControl()->name('type_id')->label(__('user_score.type_id'))->options($this->getTypeOptions())->clearable()->size('md'),
|
|
amisMake()->SelectControl()->name('cate_id')->label(__('user_score.cate_id'))->options($this->getCateOptions())->clearable()->searchable()->size('md'),
|
|
amisMake()->SelectControl()->name('user_id')->label(__('user_score.user_id'))->options($this->getUserOptions())->clearable()->searchable()->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()->DateRangeControl()->name('created_range')->label(__('user_score.created_at'))->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('cate.name')->label(__('user_score.cate_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([
|
|
$this->rowShowButton(),
|
|
$this->rowEditButton(true),
|
|
$this->rowDeleteButton(),
|
|
]),
|
|
]);
|
|
|
|
return $this->baseList($crud);
|
|
}
|
|
|
|
public function form($edit): Form
|
|
{
|
|
return $this->baseForm()->title('')->body([
|
|
amisMake()->SelectControl()->name('type_id')->label(__('user_score.type_id'))->options($this->getTypeOptions())->required(),
|
|
amisMake()->SelectControl()->name('user_id')->label(__('user_score.user_id'))->options($this->getUserOptions())->required(),
|
|
amisMake()->TextControl()->name('title')->label(__('user_score.title'))->required(),
|
|
amisMake()->TextareaControl()->name('content')->label(__('user_score.content')),
|
|
amisMake()->ImageControl()->name('images')->label(__('user_score.images'))->multiple()->receiver(admin_url('upload_image') . '?full-url=1')->autoUpload(),
|
|
amisMake()->FileControl()->name('file')->label(__('user_score.file'))->autoUpload()
|
|
]);
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
if ($this->actionOfGetData()) {
|
|
return $this->response()->success($this->service->getDetail($id));
|
|
}
|
|
$info = UserScore::findOrFail($id);
|
|
$detail = amisMake()
|
|
->Card()
|
|
->className('base-form')
|
|
->header(['title' => __('admin.detail')])
|
|
->body($this->detail())
|
|
->toolbar([
|
|
amisMake()->Button()
|
|
->visible($info->check_status != CheckStatus::Success)
|
|
->label('审核')
|
|
->level('danger')
|
|
->className('mr-1')
|
|
->actionType('dialog')
|
|
->dialog(amisMake()->Dialog()->title('审核')->body(amisMake()->Form()->api("/user-score/$id/check")->body([
|
|
amisMake()->RadiosControl()->name('check_status')->label(__('user_score.check_status'))->options([
|
|
CheckStatus::Success->value => CheckStatus::Success->text(),
|
|
CheckStatus::Fail->value => CheckStatus::Fail->text(),
|
|
])->value(CheckStatus::Success->value)->required(),
|
|
amisMake()->NumberControl()->name('score')->label(__('user_score.score')),
|
|
amisMake()->TextControl()->name('check_remarks')->label(__('user_score.check_remarks')),
|
|
])->onEvent([
|
|
'submitSucc' => [
|
|
'actions' => [
|
|
['actionType' => 'custom', 'script' => 'window.$owl.refreshAmisPage()',]
|
|
]
|
|
]
|
|
]))),
|
|
$this->backButton(),
|
|
]);
|
|
|
|
$page = $this->basePage()->body($detail);
|
|
|
|
return $this->response()->success($page);
|
|
}
|
|
|
|
public function detail(): Form
|
|
{
|
|
return $this->baseDetail()->title('')->body(amisMake()->Property()->items([
|
|
['label' => __('user_score.user_id'), 'content' => '${user.name}'],
|
|
['label' => __('user_score.cate_id'), 'content' => '${cate.name}'],
|
|
['label' => __('user_score.type_id'), 'content' => '${type.name}'],
|
|
['label' => __('user_score.check_status'), 'content' => '${check_status_text}'],
|
|
['label' => __('user_score.check_user_id'), 'content' => '${check_user.name}'],
|
|
['label' => __('user_score.check_remarks'), 'content' => '${check_remarks}'],
|
|
|
|
['label' => __('user_score.score'), 'content' => '${score}'],
|
|
['label' => __('user_score.created_at'), 'content' => '${created_at}', 'span' => 2],
|
|
|
|
['label' => __('user_score.title'), 'content' => '${title}', 'span' => 3],
|
|
['label' => __('user_score.content'), 'content' => amisMake()->TextareaControl()->labelWidth('0px')->static()->value('${content}'), 'span' => 3],
|
|
['label' => __('user_score.content'), 'content' => amisMake()->Images()->source('${images}')->defaultImage(null), 'span' => 3],
|
|
['label' => __('user_score.file'), 'content' => amisMake()->Link()->body('${file}')->href('${file}')->blank(), 'span' => 3],
|
|
|
|
]));
|
|
}
|
|
|
|
public function check($id, Request $request)
|
|
{
|
|
$info = UserScore::findOrFail($id);
|
|
try {
|
|
$this->service->check($info, $request->all());
|
|
return $this->response()->success();
|
|
} catch (BaseException $e) {
|
|
return $this->response()->fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function getTypeOptions()
|
|
{
|
|
if (!$this->typeOptions) {
|
|
$this->typeOptions = UserScore::getTypeList()->map(fn($item) => ['value' => $item->id, 'label' => $item->name]);
|
|
}
|
|
|
|
return $this->typeOptions;
|
|
}
|
|
|
|
public function getUserOptions()
|
|
{
|
|
if (!$this->userOptions) {
|
|
$cateIds = PartyCateService::make()->catePermissions();
|
|
$this->userOptions = PartyUser::select(['id as value', 'name as label'])->filter(['cate' => $cateIds])->get();
|
|
}
|
|
|
|
return $this->userOptions;
|
|
}
|
|
|
|
public function getCateOptions()
|
|
{
|
|
if (!$this->cateOptions) {
|
|
$cateIds = PartyCateService::make()->catePermissions();
|
|
$this->cateOptions = PartyCate::select(['id as value', 'name as label'])->filter(['ids' => $cateIds])->get();
|
|
}
|
|
|
|
return $this->cateOptions;
|
|
}
|
|
}
|