diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 14ba48324..a62990b38 100755 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -1792,7 +1792,94 @@ class UsersController extends AbstractController } /** - * @api {get} api/users/checkin/get 29. 获取签到设置 + * @api {get} api/users/department/sync 29. 同步部门成员(限管理员) + * + * @apiDescription 需要token身份,将子部门成员同步到当前部门 + * @apiVersion 1.0.0 + * @apiGroup users + * @apiName department__sync + * + * @apiParam {Number} id 部门id + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + */ + public function department__sync() + { + User::auth('admin'); + // + $id = intval(Request::input('id')); + // + $userDepartment = UserDepartment::find($id); + if (empty($userDepartment)) { + return Base::retError('部门不存在或已被删除'); + } + + // 获取所有子部门(递归) + $subDepartmentIds = UserDepartment::getAllSubDepartmentIds($id); + if (empty($subDepartmentIds)) { + return Base::retSuccess('同步完成,子部门中没有成员需要同步', [ + 'synced_count' => 0, + 'already_in_dept_count' => 0, + 'sub_department_ids' => $subDepartmentIds + ]); + } + + // 获取子部门中的所有成员 + $subDepartmentMembers = []; + foreach ($subDepartmentIds as $subId) { + $users = User::where("department", "like", "%,{$subId},%")->get(); + foreach ($users as $user) { + if (!in_array($user->userid, $subDepartmentMembers)) { + $subDepartmentMembers[] = $user->userid; + } + } + } + + if (empty($subDepartmentMembers)) { + return Base::retSuccess('同步完成,子部门中没有成员需要同步', [ + 'synced_count' => 0, + 'already_in_dept_count' => 0, + 'sub_department_ids' => $subDepartmentIds + ]); + } + + // 将子部门成员添加到当前部门 + $syncedCount = 0; + $alreadyInDeptCount = 0; + + AbstractModel::transaction(function () use ($id, $subDepartmentMembers, &$syncedCount, &$alreadyInDeptCount) { + foreach ($subDepartmentMembers as $userid) { + $user = User::find($userid); + if ($user) { + $userDepartments = $user->department; + if (!in_array($id, $userDepartments)) { + $userDepartments[] = $id; + $user->department = Base::arrayImplode($userDepartments); + $user->save(); + $syncedCount++; + } else { + $alreadyInDeptCount++; + } + } + } + }); + + $message = "同步完成,共同步 {$syncedCount} 个成员"; + if ($alreadyInDeptCount > 0) { + $message .= ",其中 {$alreadyInDeptCount} 个成员已在当前部门"; + } + + return Base::retSuccess($message, [ + 'synced_count' => $syncedCount, + 'already_in_dept_count' => $alreadyInDeptCount, + 'sub_department_ids' => $subDepartmentIds + ]); + } + + /** + * @api {get} api/users/checkin/get 30. 获取签到设置 * * @apiDescription 需要token身份 * @apiVersion 1.0.0 diff --git a/app/Models/UserDepartment.php b/app/Models/UserDepartment.php index 2b386e045..cdead0c40 100644 --- a/app/Models/UserDepartment.php +++ b/app/Models/UserDepartment.php @@ -170,6 +170,26 @@ class UserDepartment extends AbstractModel }); } + /** + * 递归获取所有子部门ID + * @param int $departmentId + * @return array + */ + public static function getAllSubDepartmentIds($departmentId) + { + $subIds = []; + $directSubs = self::whereParentId($departmentId)->pluck('id')->toArray(); + + foreach ($directSubs as $subId) { + $subIds[] = $subId; + // 递归获取子部门的子部门 + $subSubIds = self::getAllSubDepartmentIds($subId); + $subIds = array_merge($subIds, $subSubIds); + } + + return array_unique($subIds); + } + /** * 获取部门基本信息(缓存时间1小时) * @param int|array $ids diff --git a/app/Module/AI.php b/app/Module/AI.php index 35d939d91..2de492511 100644 --- a/app/Module/AI.php +++ b/app/Module/AI.php @@ -189,7 +189,7 @@ class AI $result = Cache::remember($cacheKey, Carbon::now()->addDays(7), function () use ($text, $targetLanguage) { $post = json_encode([ - "model" => "gpt-4.1-nano", + "model" => "gpt-5-nano", "messages" => [ [ "role" => "system", @@ -264,7 +264,7 @@ class AI $result = Cache::remember($cacheKey, Carbon::now()->addHours(24), function () use ($text) { $post = json_encode([ - "model" => "gpt-4.1-nano", + "model" => "gpt-5-nano", "messages" => [ [ "role" => "system", @@ -333,7 +333,7 @@ class AI $result = Cache::remember($cacheKey, Carbon::now()->addHours(6), function () { $post = json_encode([ - "model" => "gpt-4.1-nano", + "model" => "gpt-5-nano", "messages" => [ [ "role" => "system", diff --git a/resources/assets/js/pages/manage/components/TeamManagement.vue b/resources/assets/js/pages/manage/components/TeamManagement.vue index 713e10a03..97b66dbb0 100644 --- a/resources/assets/js/pages/manage/components/TeamManagement.vue +++ b/resources/assets/js/pages/manage/components/TeamManagement.vue @@ -54,6 +54,9 @@
{{$L('部门交流群')}}
+ +
{{$L('同步部门成员')}}
+
{{$L('编辑')}}
@@ -1336,6 +1339,43 @@ export default { return; } + if ($A.leftExists(val, 'sync_')) { + const departmentId = parseInt(val.substr(5)); + + // 前端先检查是否有子部门 + const hasSubDepartments = this.departmentList.some(dept => dept.parent_id === departmentId); + if (!hasSubDepartments) { + $A.modalWarning({ + title: this.$L('同步部门成员'), + content: this.$L('当前部门没有子部门,无需同步'), + }); + return; + } + + $A.modalConfirm({ + title: this.$L('同步部门成员'), + content: `
${this.$L(`你确定要同步部门成员吗?`)}
${this.$L(`注:此操作会同步子部门成员到当前部门`)}
`, + language: false, + loading: true, + onOk: () => { + return new Promise((resolve, reject) => { + this.$store.dispatch("call", { + url: 'users/department/sync', + data: { + id: departmentId + }, + }).then(({msg}) => { + this.getLists(); + resolve(msg); + }).catch(({msg}) => { + reject(msg); + }); + }); + } + }); + return; + } + if ($A.leftExists(val, 'del_')) { const delItem = this.departmentList.find(({id}) => id === parseInt(val.substr(4))) if (delItem) {