diff --git a/niucloud/app/api/controller/apiController/Personnel.php b/niucloud/app/api/controller/apiController/Personnel.php index 23fc0982..70d253e6 100644 --- a/niucloud/app/api/controller/apiController/Personnel.php +++ b/niucloud/app/api/controller/apiController/Personnel.php @@ -193,17 +193,14 @@ class Personnel extends BaseApiService $approvalService = new \app\service\school_approval\SchoolApprovalProcessService(); // 获取申请人ID - 如果未登录则使用管理员ID - $applicantId = $this->member_id; - if (!$applicantId) { - // 如果没有登录用户,查找系统管理员或HR作为申请人 - $adminPersonnel = \think\facade\Db::table('school_personnel') - ->where('account_type', 'admin') - ->whereOr('account_type', 'teacher') - ->where('status', 1) - ->order('id', 'asc') - ->find(); - $applicantId = $adminPersonnel ? $adminPersonnel['id'] : 1; - } + // 如果没有登录用户,查找系统管理员或HR作为申请人 + $adminPersonnel = \think\facade\Db::table('school_personnel') + ->where('account_type', 'admin') + ->whereOr('account_type', 'teacher') + ->where('status', 1) + ->order('id', 'asc') + ->find(); + $applicantId = $adminPersonnel ? $adminPersonnel['id'] : 1; $processId = $approvalService->createPersonnelApproval( $params, @@ -367,4 +364,22 @@ class Personnel extends BaseApiService } } + /** + * 获取职位类型列表 + * @param Request $request + * @return mixed + */ + public function getRoleTypes(Request $request) + { + try { + $res = (new PersonnelService())->getRoleTypes(); + if (!$res['code']) { + return fail($res['msg']); + } + return success($res['data']); + } catch (\Exception $e) { + return fail('获取职位类型失败:' . $e->getMessage()); + } + } + } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 9766bf79..21cbac72 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -199,10 +199,12 @@ Route::group(function () { Route::get('common/getCourseAll', 'apiController.Common/getCourseAll'); //公共端-获取全部班级列表 Route::get('common/getClassAll', 'apiController.Common/getClassAll'); - //公共端-获取支付类型字典(员工端) + //公共端-获取支付类型字典(员工端)/ Route::get('common/getPaymentTypes', 'apiController.Common/getPaymentTypes'); //员工端-获取审批配置列表 Route::get('personnel/approval-configs', 'apiController.Personnel/getApprovalConfigs'); + //获取职位类型列表 + Route::get('personnel/role-types', 'apiController.Personnel/getRoleTypes'); })->middleware(ApiChannel::class) ->middleware(ApiLog::class); diff --git a/niucloud/app/service/api/apiService/PersonnelService.php b/niucloud/app/service/api/apiService/PersonnelService.php index 43e8c9a8..76003e3f 100644 --- a/niucloud/app/service/api/apiService/PersonnelService.php +++ b/niucloud/app/service/api/apiService/PersonnelService.php @@ -497,7 +497,7 @@ class PersonnelService extends BaseApiService 'profile' => $data['remark'] ?? '', 'emergency_contact_phone' => $data['emergency_phone'] ?? '', 'employee_number' => $this->generateEmployeeNumber(), - 'status' => 1, + 'status' => $data['status'] ?? 1, // 使用传入的状态,默认为1 'is_sys_user' => 0, 'account_type' => $data['account_type'], 'create_time' => date('Y-m-d H:i:s'), @@ -521,14 +521,12 @@ class PersonnelService extends BaseApiService 'person_id' => $personnelId, 'name' => $data['name'], 'ethnicity' => $data['ethnicity'] ?? '', - 'birthday' => $data['birthday'] ?? '', 'age' => $data['age'] ?? null, 'politics' => $data['politics'] ?? '', 'university' => $data['university'] ?? '', 'education' => $data['education'] ?? '', 'major' => $data['major'] ?? '', 'graduation_date' => $data['graduation_date'] ?? '', - 'native_place' => $data['native_place'] ?? '', 'household_place' => $data['household_place'] ?? '', 'household_type' => $data['household_type'] ?? '', 'household_address' => $data['household_address'] ?? '', @@ -847,4 +845,31 @@ class PersonnelService extends BaseApiService } } + /** + * 获取职位类型列表 + * @return array + */ + public function getRoleTypes(): array + { + try { + $roleTypes = SysRole::where('status', 1) + ->field('role_id, role_name, role_key') + ->order('role_id ASC') + ->select() + ->toArray(); + + return [ + 'code' => 1, + 'msg' => '获取成功', + 'data' => $roleTypes + ]; + } catch (\Exception $e) { + return [ + 'code' => 0, + 'msg' => '获取职位类型失败:' . $e->getMessage(), + 'data' => [] + ]; + } + } + } diff --git a/niucloud/app/service/school_approval/SchoolApprovalProcessService.php b/niucloud/app/service/school_approval/SchoolApprovalProcessService.php index 7b580475..7b1513b8 100644 --- a/niucloud/app/service/school_approval/SchoolApprovalProcessService.php +++ b/niucloud/app/service/school_approval/SchoolApprovalProcessService.php @@ -407,6 +407,9 @@ class SchoolApprovalProcessService (new SchoolApprovalProcess())->where(['id' => $process['id']]) ->update(['business_id' => $personnelId]); + // 根据职位类型创建角色绑定关系 + $this->createPersonnelRoleBinding($personnelId, $personnelData['account_type']); + } catch (\Exception $e) { throw new Exception('创建人员记录失败:' . $e->getMessage()); } @@ -654,4 +657,51 @@ class SchoolApprovalProcessService \think\facade\Log::error('发送审批通知失败:' . $e->getMessage()); } } + + /** + * 根据职位类型创建人员角色绑定关系 + * @param int $personnelId 人员ID + * @param string $accountType 职位类型 + * @throws \Exception + */ + private function createPersonnelRoleBinding(int $personnelId, string $accountType): void + { + try { + // 根据account_type查询对应的角色ID + $roleModel = new \app\model\sys\SysRole(); + $role = $roleModel->where('role_key', $accountType) + ->where('status', 1) + ->find(); + + if (!$role) { + // 如果找不到对应角色,记录警告但不抛出异常 + \think\facade\Log::warning("未找到职位类型 {$accountType} 对应的角色"); + return; + } + + // 在school_campus_person_role表中新增记录 + $campusPersonRoleData = [ + 'campus_id' => 0, // 默认校区ID,可以根据实际需求调整 + 'person_id' => $personnelId, + 'role_id' => $role['role_id'], + 'dept_id' => 0, // 默认部门ID,可以根据实际需求调整 + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + 'deleted_at' => 0, + 'phone' => null, + 'task_num' => 0 + ]; + + $insertResult = Db::table('school_campus_person_role')->insert($campusPersonRoleData); + if (!$insertResult) { + throw new \Exception('创建人员角色绑定关系失败'); + } + + \think\facade\Log::info("成功为人员ID {$personnelId} 创建角色绑定,角色ID: {$role['role_id']}"); + + } catch (\Exception $e) { + // 抛出异常让上层处理 + throw new \Exception('创建人员角色绑定关系失败:' . $e->getMessage()); + } + } } diff --git a/uniapp/common/config.js b/uniapp/common/config.js index 2459f37b..c98a2253 100644 --- a/uniapp/common/config.js +++ b/uniapp/common/config.js @@ -1,6 +1,6 @@ // 环境变量配置 -// const env = 'development' -const env = 'prod' +const env = 'development' +// const env = 'prod' const isMockEnabled = false // 默认禁用Mock优先模式,仅作为回退 const isDebug = false // 默认启用调试模式 const devurl = 'http://localhost:20080/api' diff --git a/uniapp/pages/common/personnel/add_personnel.vue b/uniapp/pages/common/personnel/add_personnel.vue index 49e90ff9..0888d940 100644 --- a/uniapp/pages/common/personnel/add_personnel.vue +++ b/uniapp/pages/common/personnel/add_personnel.vue @@ -96,19 +96,14 @@ - + 职位类型 - - - - + + + {{getRoleTypeName(formData.account_type) || '请选择职位类型'}} + + @@ -290,7 +285,7 @@ 职位: - {{formData.account_type === 'teacher' ? '教师' : '市场'}} + {{getRoleTypeName(formData.account_type)}} @@ -377,7 +372,9 @@ export default { politicsOptions: ['群众', '共青团员', '中共党员', '民主党派', '无党派人士'], educationOptions: ['高中', '中专', '大专', '本科', '硕士', '博士'], householdTypeOptions: ['城镇', '农村'], - maritalStatusOptions: ['未婚', '已婚', '离异', '丧偶'] + maritalStatusOptions: ['未婚', '已婚', '离异', '丧偶'], + // 职位类型选项 + roleTypeOptions: [] } }, computed: { @@ -404,6 +401,8 @@ export default { // 加载审批配置 this.loadApprovalConfigs() + // 加载职位类型 + this.loadRoleTypes() }, methods: { // 返回上一页 @@ -491,6 +490,15 @@ export default { this.detailData.marital_status = this.maritalStatusOptions[e.detail.value] }, + // 职位类型选择事件 + onRoleTypeChange(e) { + const index = e.detail.value + const selectedRole = this.roleTypeOptions[index] + if (selectedRole) { + this.formData.account_type = selectedRole.role_key + } + }, + // 计算年龄 calculateAge() { if (this.formData.birthday) { @@ -588,15 +596,38 @@ export default { this.approvalData.selectedConfig = this.approvalConfigs[index] }, - // 获取职位类型文本 - getAccountTypeText(type) { - const typeMap = { - 'teacher': '教师', - 'market': '市场', - 'admin': '管理员', - 'other': '其他' + // 获取职位类型名称 + getRoleTypeName(roleKey) { + if (!roleKey) return '' + const role = this.roleTypeOptions.find(item => item.role_key === roleKey) + return role ? role.role_name : roleKey + }, + + // 加载职位类型数据 + async loadRoleTypes() { + try { + const response = await apiRoute.get('personnel/role-types') + if (response.code === 1 && response.data) { + this.roleTypeOptions = response.data + console.log('职位类型加载成功:', this.roleTypeOptions) + } else { + console.error('职位类型加载失败:', response.msg) + // 如果加载失败,使用默认选项 + this.roleTypeOptions = [ + { role_id: 1, role_name: '教练主管', role_key: 'teacher_manager' }, + { role_id: 2, role_name: '普通市场', role_key: 'market' }, + { role_id: 3, role_name: '班主任', role_key: 'teacher' } + ] + } + } catch (error) { + console.error('加载职位类型失败:', error) + // 网络错误时使用默认选项 + this.roleTypeOptions = [ + { role_id: 1, role_name: '教练主管', role_key: 'teacher_manager' }, + { role_id: 2, role_name: '普通市场', role_key: 'market' }, + { role_id: 3, role_name: '班主任', role_key: 'teacher' } + ] } - return typeMap[type] || type }, // 提交表单