|
@@ -0,0 +1,142 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+namespace App\Community\Controllers\User;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+use App\Models\CdmsUsers;
|
|
|
|
+use Encore\Admin\Controllers\AdminController;
|
|
|
|
+use Encore\Admin\Form;
|
|
|
|
+use Encore\Admin\Grid;
|
|
|
|
+use Encore\Admin\Show;
|
|
|
|
+use Encore\Admin\Facades\Admin;
|
|
|
|
+
|
|
|
|
+class UserController extends AdminController
|
|
|
|
+{
|
|
|
|
+ protected $title = '管理账号';
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Make a grid builder.
|
|
|
|
+ *
|
|
|
|
+ * @return Grid
|
|
|
|
+ */
|
|
|
|
+ protected function grid()
|
|
|
|
+ {
|
|
|
|
+ $userModel = config('admin.database.users_model');
|
|
|
|
+
|
|
|
|
+ $grid = new Grid(new $userModel());
|
|
|
|
+ $grid->disableCreateButton(false);
|
|
|
|
+ $org_id = Admin::user()->org_id;
|
|
|
|
+ $aid = Admin::user()->id;
|
|
|
|
+
|
|
|
|
+ if(!empty($org_id)){
|
|
|
|
+ $grid->model()->where('org_id',$org_id);
|
|
|
|
+ }
|
|
|
|
+ $grid->column('id', 'ID')->sortable();
|
|
|
|
+
|
|
|
|
+ $grid->column('username', trans('admin.username'));
|
|
|
|
+ $grid->column('name', trans('admin.name'));
|
|
|
|
+ $grid->column('roles', trans('admin.roles'))->pluck('name')->label();
|
|
|
|
+ $grid->column('created_at', trans('admin.created_at'));
|
|
|
|
+ $grid->column('updated_at', trans('admin.updated_at'));
|
|
|
|
+
|
|
|
|
+ $is_manager = Admin::user()->isRole('manager');
|
|
|
|
+ $grid->actions(function (Grid\Displayers\Actions $actions) use ($is_manager,$aid) {
|
|
|
|
+ $actions->disableDelete();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ $grid->tools(function (Grid\Tools $tools) {
|
|
|
|
+ $tools->batch(function (Grid\Tools\BatchActions $actions) {
|
|
|
|
+ $actions->disableDelete();
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return $grid;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Make a show builder.
|
|
|
|
+ *
|
|
|
|
+ * @param mixed $id
|
|
|
|
+ *
|
|
|
|
+ * @return Show
|
|
|
|
+ */
|
|
|
|
+ protected function detail($id)
|
|
|
|
+ {
|
|
|
|
+ $userModel = config('admin.database.users_model');
|
|
|
|
+
|
|
|
|
+ $show = new Show($userModel::findOrFail($id));
|
|
|
|
+
|
|
|
|
+ $show->field('id', 'ID');
|
|
|
|
+ $show->field('username', trans('admin.username'));
|
|
|
|
+ $show->field('name', trans('admin.name'));
|
|
|
|
+ $show->field('roles', trans('admin.roles'))->as(function ($roles) {
|
|
|
|
+ return $roles->pluck('name');
|
|
|
|
+ })->label();
|
|
|
|
+ $show->field('permissions', trans('admin.permissions'))->as(function ($permission) {
|
|
|
|
+ return $permission->pluck('name');
|
|
|
|
+ })->label();
|
|
|
|
+ $show->field('created_at', trans('admin.created_at'));
|
|
|
|
+ $show->field('updated_at', trans('admin.updated_at'));
|
|
|
|
+
|
|
|
|
+ return $show;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Make a form builder.
|
|
|
|
+ *
|
|
|
|
+ * @return Form
|
|
|
|
+ */
|
|
|
|
+ public function form()
|
|
|
|
+ {
|
|
|
|
+ $userModel = config('tenancy.database.users_model');
|
|
|
|
+ $roleModel = config('tenancy.database.roles_model');
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $org_id = Admin::user()->org_id;
|
|
|
|
+
|
|
|
|
+ $form = new Form(new $userModel());
|
|
|
|
+
|
|
|
|
+ $userTable = config('tenancy.database.users_table');
|
|
|
|
+ $connection = config('tenancy.database.connection');
|
|
|
|
+ $form->display('id', 'ID');
|
|
|
|
+ $form->text('username', trans('tenancy.username'))
|
|
|
|
+ ->creationRules(['required', "unique:{$connection}.{$userTable}"])
|
|
|
|
+ ->updateRules(['required', "unique:{$connection}.{$userTable},username,{{id}}"]);
|
|
|
|
+
|
|
|
|
+ $form->text('name', trans('tenancy.name'))->rules('required');
|
|
|
|
+ $form->image('avatar', trans('tenancy.avatar'));
|
|
|
|
+ $form->password('password', trans('tenancy.password'))->rules('required|confirmed');
|
|
|
|
+ $form->password('password_confirmation', trans('tenancy.password_confirmation'))->rules('required')
|
|
|
|
+ ->default(function ($form) {
|
|
|
|
+ return $form->model()->password;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ $form->ignore(['password_confirmation']);
|
|
|
|
+
|
|
|
|
+ $form->hidden('org_id')->value($org_id);
|
|
|
|
+ $ids = [0,$org_id];
|
|
|
|
+
|
|
|
|
+ if($form->isEditing()){
|
|
|
|
+ $form->multipleSelect('roles', trans('tenancy.roles'))->options($roleModel::whereIn('org_id',$ids)->where('id','>',2)->get()->pluck('name', 'id'));
|
|
|
|
+ } else {
|
|
|
|
+ $form->multipleSelect('roles', trans('tenancy.roles'))->options($roleModel::whereIn('org_id',$ids)->where('id','>',2)->get()->pluck('name', 'id'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $form->display('created_at', trans('tenancy.created_at'));
|
|
|
|
+ $form->display('updated_at', trans('tenancy.updated_at'));
|
|
|
|
+
|
|
|
|
+ $form->saving(function (Form $form) {
|
|
|
|
+ if ($form->password && $form->model()->password != $form->password) {
|
|
|
|
+ $form->password = bcrypt($form->password);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return $form;
|
|
|
|
+ }
|
|
|
|
+}
|