Browse Source

修改 bug

master
王泽彦 8 months ago
parent
commit
de4016a61d
  1. 37
      niucloud/app/api/controller/apiController/Personnel.php
  2. 4
      niucloud/app/api/route/route.php
  3. 31
      niucloud/app/service/api/apiService/PersonnelService.php
  4. 50
      niucloud/app/service/school_approval/SchoolApprovalProcessService.php
  5. 4
      uniapp/common/config.js
  6. 73
      uniapp/pages/common/personnel/add_personnel.vue

37
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());
}
}
}

4
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);

31
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' => []
];
}
}
}

50
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());
}
}
}

4
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'

73
uniapp/pages/common/personnel/add_personnel.vue

@ -96,19 +96,14 @@
<input class="form-input" v-model="formData.wx" placeholder="请输入微信号" />
</view>
<!-- 账号类型 -->
<!-- 职位类型 -->
<view class="form-item required">
<view class="label">职位类型</view>
<view class="radio-group">
<label class="radio-item" @click="formData.account_type = 'teacher'">
<view class="radio" :class="formData.account_type === 'teacher' ? 'checked' : ''"></view>
<text>教师</text>
</label>
<label class="radio-item" @click="formData.account_type = 'market'">
<view class="radio" :class="formData.account_type === 'market' ? 'checked' : ''"></view>
<text>市场</text>
</label>
</view>
<picker :range="roleTypeOptions" range-key="role_name" @change="onRoleTypeChange">
<view class="picker-input">
{{getRoleTypeName(formData.account_type) || '请选择职位类型'}}
</view>
</picker>
</view>
<!-- 入职时间 -->
@ -290,7 +285,7 @@
</view>
<view class="info-item">
<text class="info-label">职位</text>
<text class="info-value">{{formData.account_type === 'teacher' ? '教师' : '市场'}}</text>
<text class="info-value">{{getRoleTypeName(formData.account_type)}}</text>
</view>
</view>
@ -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
},
//

Loading…
Cancel
Save