feat 新增部门负责人标识并排第一位

This commit is contained in:
ganzizi 2023-04-27 19:19:01 +08:00
parent 6e68100f86
commit 0b1f433fe4
3 changed files with 31 additions and 3 deletions

View File

@ -707,7 +707,14 @@ class UsersController extends AbstractController
$query->where("department", "")->orWhere("department", ",,");
});
} else {
$builder->where("department", "like", "%,{$keys['department']},%");
// 关联user_departments表中owner_userid查询出负责人重新排序部门负责人始终在前面
$builder->where(function($query) use ($keys) {
$query->where("department", "like", "%,{$keys['department']},%")
->orWhereIn('userid', function ($query) use ($keys) {
$query->select('owner_userid')->from('user_departments')->where("id", "=", trim($keys['department'], ','))
->orderByRaw("FIELD(owner_userid,{$keys['department']}) DESC");
});
});
}
}
if ($getCheckinMac && isset($keys['checkin_mac'])) {
@ -719,11 +726,16 @@ class UsersController extends AbstractController
$builder->whereNull('disable_at');
$builder->where('bot', 0);
}
$list = $builder->orderByDesc('userid')->paginate(Base::getPaginate(50, 20));
$builder = $keys['department'] == '0' ? $builder->orderByDesc('userid') : $builder;
$list = $builder->paginate(Base::getPaginate(50, 20));
//
if ($getCheckinMac) {
if ($getCheckinMac || isset($keys['department'])) {
$list->transform(function (User $user) {
$user->checkin_macs = UserCheckinMac::select(['id', 'mac', 'remark'])->whereUserid($user->userid)->orderBy('id')->get();
// 当为部门负责人时字段identity值为['dm'],表示部门负责人
if ($user->isDepartmentOwner()) {
$user->identity = ['dm'];
}
return $user;
});
}

View File

@ -149,6 +149,15 @@ class User extends AbstractModel
return implode(', ', $array);
}
/**
* 判断是否为部门负责人
*/
public function isDepartmentOwner()
{
return UserDepartment::where('owner_userid', $this->userid)->exists();
}
/**
* 获取机器人所有者
* @return int|mixed

View File

@ -342,6 +342,13 @@ export default {
}
}))
}
if (identity.includes("dm")) {
arr.push(h('Tag', {
props: {
color: 'blue'
}
}, this.$L('负责人')))
}
if (identity.includes("ldap")) {
arr.push(h('Tag', {
props: {