64 lines
1.4 KiB
PHP
64 lines
1.4 KiB
PHP
<?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 ['确认标记当前用户为管理者?'];
|
|
}
|
|
}
|