BatchDel.php 987 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Admin\Actions\Device;
  3. use App\Model\UserDevice;
  4. use App\Model\UserInfo;
  5. use Encore\Admin\Actions\BatchAction;
  6. use Illuminate\Database\Eloquent\Collection;
  7. class BatchDel extends BatchAction
  8. {
  9. public $name = '批量解绑';
  10. public function handle(Collection $collection)
  11. {
  12. $ids =[];
  13. $uid =session('list_uid');
  14. $user = UserInfo::find($uid);
  15. if ($user->role == 2){
  16. return $this->response()->error('请在设备中解绑')->refresh();
  17. }
  18. foreach ($collection as $model) {
  19. $ids[]=$model->id;
  20. }
  21. $res = UserDevice::where('user_id',$uid)->whereIn('device_id',$ids)->delete();
  22. if ($res)
  23. return $this->response()->info('解除绑定成功')->refresh();
  24. return $this->response()->error('操作失败,请重试')->refresh();
  25. }
  26. public function dialog()
  27. {
  28. $this->confirm('确定把该用户的所有设备解绑?');
  29. }
  30. }