chore(web/super-manage): tidy up some code

This commit is contained in:
Baoshuo Ren 2022-04-02 18:35:58 +08:00
parent d2ad335128
commit e1efee927b
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
2 changed files with 21 additions and 12 deletions

View File

@ -143,22 +143,14 @@
case 'problem_uploader': case 'problem_uploader':
DB::update("update user_info set usergroup = 'U' where username = '{$username}'"); DB::update("update user_info set usergroup = 'U' where username = '{$username}'");
$user = queryUser($username); $user = queryUser($username);
$usertype = explode(',', $user['usertype']); $user = addUserType($user, 'problem_uploader');
if (!in_array('problem_uploader', $usertype)) { DB::update("update user_info set usertype = '{$user['usertype']}' where username = '{$username}'");
$usertype[] = 'problem_uploader';
}
$usertype = implode(',', $usertype);
DB::update("update user_info set usertype = '{$usertype}' where username = '{$username}'");
break; break;
case 'problem_manager': case 'problem_manager':
DB::update("update user_info set usergroup = 'U' where username = '{$username}'"); DB::update("update user_info set usergroup = 'U' where username = '{$username}'");
$user = queryUser($username); $user = queryUser($username);
$usertype = explode(',', $user['usertype']); $user = addUserType($user, 'problem_manager');
if (!in_array('problem_manager', $usertype)) { DB::update("update user_info set usertype = '{$user['usertype']}' where username = '{$username}'");
$usertype[] = 'problem_manager';
}
$usertype = implode(',', $usertype);
DB::update("update user_info set usertype = '{$usertype}' where username = '{$username}'");
break; break;
case 'superuser': case 'superuser':
DB::update("update user_info set usergroup = 'S' where username = '{$username}'"); DB::update("update user_info set usergroup = 'S' where username = '{$username}'");

View File

@ -194,3 +194,20 @@ function sendSystemMsg($username, $title, $content) {
$title = DB::escape($title); $title = DB::escape($title);
DB::insert("insert into user_system_msg (receiver, title, content, send_time) values ('$username', '$title', '$content', now())"); DB::insert("insert into user_system_msg (receiver, title, content, send_time) values ('$username', '$title', '$content', now())");
} }
function addUserType($user, $type) {
$usertype = explode(',', $user['usertype']);
if (!in_array($type, $usertype)) {
$usertype[] = $type;
}
$user['usertype'] = implode(',', $usertype);
return $user;
}
function removeUserType($user, $type) {
$usertype = explode(',', $user['usertype']);
if (in_array($type, $usertype)) {
$usertype = array_diff($usertype, array($type));
}
$user['usertype'] = implode(',', $usertype);
return $user;
}