添加后台标记管理员
parent
fc2f2dc8ee
commit
d9d9a95f55
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Actions\Grid;
|
||||||
|
|
||||||
|
use App\Models\Dealer;
|
||||||
|
use Dcat\Admin\Grid\RowAction;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class DealerSignManager extends RowAction
|
||||||
|
{
|
||||||
|
public function title()
|
||||||
|
{
|
||||||
|
if ($this->title) {
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
return '<i class="feather icon-sunrise grid-action-icon"></i> 标记管理员 ';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Model|Authenticatable|HasPermissions|null $user
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function authorize($user): bool
|
||||||
|
{
|
||||||
|
return $user->can('dcat.admin.dealers.sign_manager');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the action request.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function handle(Request $request)
|
||||||
|
{
|
||||||
|
$dealer = Dealer::findOrFail($this->getKey());
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
$dealer->update([
|
||||||
|
'is_manager'=>true,
|
||||||
|
]);
|
||||||
|
DB::commit();
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
DB::rollBack();
|
||||||
|
report($th);
|
||||||
|
return $this->response()->error('操作失败,'.$th->getMessage())->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response()->success('操作成功')->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string|array|void
|
||||||
|
*/
|
||||||
|
public function confirm()
|
||||||
|
{
|
||||||
|
return ['确认标记当前用户为管理者?'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Actions\Grid;
|
||||||
|
|
||||||
|
use App\Models\Dealer;
|
||||||
|
use Dcat\Admin\Grid\RowAction;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class DealerUnsignManager extends RowAction
|
||||||
|
{
|
||||||
|
public function title()
|
||||||
|
{
|
||||||
|
if ($this->title) {
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
return '<i class="feather icon-sunset grid-action-icon"></i> 取消管理员 ';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Model|Authenticatable|HasPermissions|null $user
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function authorize($user): bool
|
||||||
|
{
|
||||||
|
return $user->can('dcat.admin.dealers.unsign_manager');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the action request.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function handle(Request $request)
|
||||||
|
{
|
||||||
|
$dealer = Dealer::findOrFail($this->getKey());
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
$dealer->update([
|
||||||
|
'is_manager'=>false,
|
||||||
|
]);
|
||||||
|
DB::commit();
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
DB::rollBack();
|
||||||
|
report($th);
|
||||||
|
return $this->response()->error('操作失败,'.$th->getMessage())->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response()->success('操作成功')->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string|array|void
|
||||||
|
*/
|
||||||
|
public function confirm()
|
||||||
|
{
|
||||||
|
return ['确认取消标记当前用户为管理者?'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use App\Admin\Actions\Grid\DealerEditLvl;
|
use App\Admin\Actions\Grid\DealerEditLvl;
|
||||||
|
use App\Admin\Actions\Grid\DealerSignManager;
|
||||||
|
use App\Admin\Actions\Grid\DealerUnsignManager;
|
||||||
use App\Admin\Repositories\Dealer;
|
use App\Admin\Repositories\Dealer;
|
||||||
use Dcat\Admin\Admin;
|
use Dcat\Admin\Admin;
|
||||||
use Dcat\Admin\Form;
|
use Dcat\Admin\Form;
|
||||||
|
|
@ -30,7 +32,7 @@ class DealerController extends AdminController
|
||||||
return $this->lvl_text;
|
return $this->lvl_text;
|
||||||
});
|
});
|
||||||
$grid->column('is_sale');
|
$grid->column('is_sale');
|
||||||
$grid->column('is_manager');
|
$grid->column('is_manager')->bool();
|
||||||
// $grid->column('pay_info');
|
// $grid->column('pay_info');
|
||||||
$grid->column('created_at')->sortable();
|
$grid->column('created_at')->sortable();
|
||||||
|
|
||||||
|
|
@ -38,6 +40,12 @@ class DealerController extends AdminController
|
||||||
if (Admin::user()->can('dcat.admin.dealers.edit_lvl')) {
|
if (Admin::user()->can('dcat.admin.dealers.edit_lvl')) {
|
||||||
$actions->append(new DealerEditLvl());
|
$actions->append(new DealerEditLvl());
|
||||||
}
|
}
|
||||||
|
if (!$actions->row->is_manager && Admin::user()->can('dcat.admin.dealers.sign_manager')) {
|
||||||
|
$actions->append(new DealerSignManager());
|
||||||
|
}
|
||||||
|
if ($actions->row->is_manager && Admin::user()->can('dcat.admin.dealers.sign_manager')) {
|
||||||
|
$actions->append(new DealerUnsignManager());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$grid->filter(function (Grid\Filter $filter) {
|
$grid->filter(function (Grid\Filter $filter) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue