Skip to content

Commit

Permalink
fix file share empty user
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Dec 11, 2021
1 parent 0ea82b9 commit f6035de
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions app/Http/Controllers/Api/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,34 +542,36 @@ public function share__update()
$message = '取消成功';
} else {
// 设置共享
if (!in_array($share, [1, 2])) {
return Base::retError('请选择共享对象');
}
if ($share == 1) {
$user->isAdmin();
}
$file->setShare($share);
if ($share == 2) {
$array = [];
if (is_array($userids)) {
foreach ($userids as $userid) {
if (!intval($userid)) continue;
if (!User::whereUserid($userid)->exists()) continue;
FileUser::updateInsert([
'file_id' => $file->id,
'userid' => $userid,
]);
$array[] = $userid;
switch ($share) {
case 1:
$user->isAdmin();
break;

case 2:
$array = [];
if (is_array($userids)) {
foreach ($userids as $userid) {
if (!intval($userid)) continue;
if (!User::whereUserid($userid)->exists()) continue;
FileUser::updateInsert([
'file_id' => $file->id,
'userid' => $userid,
]);
$array[] = $userid;
}
}
if (empty($array)) {
return Base::retError('请选择共享成员');
}
}
if (empty($array)) {
$builder = FileUser::whereFileId($file->id);
} else {
$builder = FileUser::whereFileId($file->id)->whereNotIn('userid', $array);
}
$uids = (clone $builder)->pluck('userid')->toArray();
$builder->delete();
$uids = (clone $builder)->pluck('userid')->toArray();
$builder->delete();
break;

default:
return Base::retError('请选择共享对象');
}
$file->setShare($share);
$message = '设置成功';
}
//
Expand Down

0 comments on commit f6035de

Please sign in to comment.