78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Actions\Show;
|
|
|
|
use App\Models\User;
|
|
use Dcat\Admin\Show\AbstractTool;
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
use Illuminate\Http\Request;
|
|
use Throwable;
|
|
|
|
class UserDisableBonus extends AbstractTool
|
|
{
|
|
/**
|
|
* @return string
|
|
*/
|
|
protected $title = '<i class="fa fa-jpy icon-shuffle"></i> 关闭奖金分红';
|
|
|
|
/**
|
|
* 按钮样式定义,默认 btn btn-white waves-effect
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $style = 'btn btn-sm btn-danger';
|
|
|
|
/**
|
|
* 权限判断,如不需要可以删除此方法
|
|
*
|
|
* @param Model|Authenticatable|HasPermissions|null $user
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function authorize($user): bool
|
|
{
|
|
return $user->can('dcat.admin.users.disable_bonus');
|
|
}
|
|
|
|
/**
|
|
* 处理请求,如果不需要接口处理,请直接删除这个方法
|
|
*
|
|
* @param Request $request
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function handle(Request $request)
|
|
{
|
|
// 获取主键
|
|
$key = $this->getKey();
|
|
$user = User::findOrFail($key);
|
|
try {
|
|
$user->userInfo->update([
|
|
'bonusable'=>0,
|
|
]);
|
|
} catch (Throwable $th) {
|
|
report($th);
|
|
return $this->response()->error('操作失败:'.$th->getMessage());
|
|
}
|
|
|
|
return $this->response()
|
|
->success(__('admin.update_succeeded'))
|
|
->refresh();
|
|
}
|
|
|
|
public function html()
|
|
{
|
|
return parent::html().' ';
|
|
}
|
|
|
|
/**
|
|
* 确认弹窗信息,如不需要可以删除此方法
|
|
*
|
|
* @return string|array|void
|
|
*/
|
|
public function confirm()
|
|
{
|
|
return ['是否关闭该用户奖金分红?', '该操作不可逆,确认后该用户将不再享受奖金分红。'];
|
|
}
|
|
}
|