Browse Source

修改 bug

master
王泽彦 8 months ago
parent
commit
b57d2e59c6
  1. 4
      niucloud/app/adminapi/controller/course_schedule/CourseSchedule.php
  2. 44
      niucloud/app/api/controller/apiController/StudentManager.php
  3. 1
      niucloud/app/api/route/route.php
  4. 23
      niucloud/app/common.php
  5. 17
      niucloud/app/service/api/apiService/CustomerResourcesService.php
  6. 45
      niucloud/app/service/api/apiService/StudentService.php
  7. 4
      uniapp/api/apiRoute.js
  8. 29
      uniapp/components/student-info-card/student-info-card.vue
  9. 117
      uniapp/pages-market/clue/clue_info.vue
  10. 92
      uniapp/pages-student/schedule/index.vue

4
niucloud/app/adminapi/controller/course_schedule/CourseSchedule.php

@ -165,8 +165,8 @@ class CourseSchedule extends BaseAdminController
["schedule_id",''], ["schedule_id",''],
["course_date",''], ["course_date",''],
["time_slot",''], ["time_slot",''],
["schedule_type", 1], // 1=正式位, 2=等待位 ["schedule_type", 1], // 1=临时, 2=固定
["course_type", 1], // 1=正式课, 2=体验课, 3=补课, 4=试听课 ["course_type", 1], // 1=课, 2=体验课, 3=补课, 4=试听课
["position", ''] // 位置信息 ["position", ''] // 位置信息
]); ]);
return (new CourseScheduleService())->addSchedule($data); return (new CourseScheduleService())->addSchedule($data);

44
niucloud/app/api/controller/apiController/StudentManager.php

@ -103,4 +103,48 @@ class StudentManager extends BaseApiService
return fail('获取学员列表失败:' . $e->getMessage()); return fail('获取学员列表失败:' . $e->getMessage());
} }
} }
public function edit()
{
try {
$data = $this->request->params([
["id", ""],
["name", ""],
["gender", 0],
["age", 0.00],
["birthday", ""],
["user_id", 0],
["campus_id", 0],
["class_id", 0],
["note", ""],
["status", 1],
["emergency_contact", ""],
["contact_phone", ""],
["member_label", ""],
["consultant_id", ""],
["coach_id", ""],
["trial_class_count", 2]
]);
// 表单验证
if (empty($data['name'])) {
return fail('学员姓名不能为空');
}
if ($data['gender'] == 0) {
return fail('请选择学员性别');
}
if (empty($data['birthday'])) {
return fail('请选择学员出生日期');
}
$result = (new StudentService())->edit($data);
if ($result['code'] === 1) {
return success('修改成功', $result['data']);
} else {
return fail($result['msg']);
}
} catch (\Exception $e) {
return fail('添加学员失败:' . $e->getMessage());
}
}
} }

1
niucloud/app/api/route/route.php

@ -258,6 +258,7 @@ Route::group(function () {
Route::post('resourceSharing/assign', 'apiController.ResourceSharing/assign'); Route::post('resourceSharing/assign', 'apiController.ResourceSharing/assign');
//销售端-学员-新增 //销售端-学员-新增
Route::post('student/add', 'apiController.StudentManager/add'); Route::post('student/add', 'apiController.StudentManager/add');
Route::post('student/edit', 'apiController.StudentManager/edit');
//销售端-学员-列表 //销售端-学员-列表
Route::get('student/list', 'apiController.StudentManager/list'); Route::get('student/list', 'apiController.StudentManager/list');

23
niucloud/app/common.php

@ -1467,3 +1467,26 @@ function sendMessage($touser,$template_id,$value) {
curl_close($ch); curl_close($ch);
} }
/**
* 通过 id 获取员工姓名
*/
function getStaffNameById($id)
{
//获取全部员工的 id 和 name
$staffs = Personnel::column('id,name');
$staffs = array_column($staffs, 'name', 'id');
return $staffs[$id] ?? '';
}
/**
* 获取学员有效的课程
*/
function getValidCourseByStudentId($studentId)
{
$course = \app\model\student_courses\StudentCourses::where('student_id', $studentId)
->where('status', 1)
->order('id', 'desc')
->find();
return $course ?? [];
}

17
niucloud/app/service/api/apiService/CustomerResourcesService.php

@ -1114,21 +1114,8 @@ class CustomerResourcesService extends BaseApiService
->alias('s') ->alias('s')
->leftJoin('school_student_courses sc', 's.id = sc.student_id') ->leftJoin('school_student_courses sc', 's.id = sc.student_id')
->leftJoin('school_customer_resources cr', 's.user_id = cr.id') ->leftJoin('school_customer_resources cr', 's.user_id = cr.id')
->where('s.deleted_at', 0); ->where('s.deleted_at', 0)
->where('s.id', $studentId);
// 根据传入的参数查询 - 优先使用student_id,如果都提供则使用OR条件
if ($studentId && $resourceId) {
// 如果同时提供student_id和resource_id,使用OR条件
$query->where(function($query) use ($studentId, $resourceId) {
$query->where('s.id', $studentId)->whereOr('s.user_id', $resourceId);
});
} elseif ($studentId) {
// 仅提供student_id
$query->where('s.id', $studentId);
} elseif ($resourceId) {
// 仅提供resource_id
$query->where('s.user_id', $resourceId);
}
// 获取学员基本信息和课程信息 // 获取学员基本信息和课程信息
$student = $query $student = $query

45
niucloud/app/service/api/apiService/StudentService.php

@ -158,6 +158,8 @@ class StudentService extends BaseApiService
$student['second_visit_time'] = ''; $student['second_visit_time'] = '';
$student['first_visit_status'] = '未到访'; $student['first_visit_status'] = '未到访';
$student['second_visit_status'] = '未到访'; $student['second_visit_status'] = '未到访';
$student['academic_affairs'] = getStaffNameById($student['consultant_id']);
$student['class_teacher'] = getStaffNameById($student['coach_id']);
// 设置一访和二访信息 // 设置一访和二访信息
if (!empty($visitRecords)) { if (!empty($visitRecords)) {
@ -265,10 +267,12 @@ class StudentService extends BaseApiService
$courseInfo = Db::table('school_student_courses sc') $courseInfo = Db::table('school_student_courses sc')
->leftJoin('school_course c', 'sc.course_id = c.id') ->leftJoin('school_course c', 'sc.course_id = c.id')
->leftJoin('school_customer_resources cr', 'sc.resource_id = cr.id') ->leftJoin('school_customer_resources cr', 'sc.resource_id = cr.id')
->leftJoin('school_resource_sharing rs', 'rs.resource_id = cr.id')
->where([ ->where([
['sc.student_id', '=', $studentId] ['sc.student_id', '=', $studentId]
]) ])
->field('sc.total_hours, sc.gift_hours, sc.use_total_hours, sc.use_gift_hours, sc.end_date, sc.resource_id as resource_sharing_id, c.course_name') ->field('sc.total_hours, sc.gift_hours, sc.use_total_hours,
sc.use_gift_hours, sc.end_date, rs.id as resource_sharing_id, c.course_name')
->order('sc.created_at', 'desc') ->order('sc.created_at', 'desc')
->find(); ->find();
@ -280,7 +284,9 @@ class StudentService extends BaseApiService
'use_gift_hours' => 0, 'use_gift_hours' => 0,
'end_date' => '', 'end_date' => '',
'resource_sharing_id' => 0, 'resource_sharing_id' => 0,
'course_name' => '' 'course_name' => '',
'class_teacher'=>'',
'academic_affairs'=>''
]; ];
} }
@ -322,4 +328,39 @@ class StudentService extends BaseApiService
return 0; return 0;
} }
} }
public function edit(array $data)
{
$res = [
'code' => 0,
'msg' => '操作失败',
'data' => []
];
$course = getValidCourseByStudentId($data['id']);
$consultant_id = $course['education_id'] ?? 0;
$coach_id = $course['main_coach_id'] ?? 0;
$data['updated_at'] = date('Y-m-d H:i:s');
if ($consultant_id || $coach_id){
$data['consultant_id'] = $consultant_id;
$data['coach_id'] = $coach_id;
}
try {
// 插入数据库
$id = Db::table('school_student')
->where('id', $data['id'])
->update($data);
if ($id) {
$res['code'] = 1;
$res['msg'] = '修改成功';
$res['data'] = ['id' => $id];
} else {
$res['msg'] = '添加失败';
}
} catch (\Exception $e) {
$res['msg'] = '添加失败:' . $e->getMessage();
}
return $res;
}
} }

4
uniapp/api/apiRoute.js

@ -491,6 +491,10 @@ export default {
async xs_addStudent(data = {}) { async xs_addStudent(data = {}) {
return await http.post('/student/add', data); return await http.post('/student/add', data);
}, },
//销售端-学员-编辑
async xs_editStudent(data = {}) {
return await http.post('/student/edit', data);
},
//销售端-学员-列表 //销售端-学员-列表
async xs_getStudentList(data = {}) { async xs_getStudentList(data = {}) {
return await http.get('/student/list', data); return await http.get('/student/list', data);

29
uniapp/components/student-info-card/student-info-card.vue

@ -1,8 +1,8 @@
<!--学生信息卡片组件--> <!--学生信息卡片组件-->
<template> <template>
<view class="student-info-card"> <view class="student-info-card" >
<!-- 学生基本信息 --> <!-- 学生基本信息 -->
<view class="student-header"> <view class="student-header" @click="handleStudentClick">
<view class="student-avatar"> <view class="student-avatar">
<text>{{ student.name ? student.name.charAt(0) : '学' }}</text> <text>{{ student.name ? student.name.charAt(0) : '学' }}</text>
</view> </view>
@ -23,7 +23,7 @@
</view> </view>
</view> </view>
</view> </view>
</view> </view >
<!-- 学生详细信息 --> <!-- 学生详细信息 -->
<view class="student-info"> <view class="student-info">
@ -33,7 +33,7 @@
</view> </view>
<view class="info-row"> <view class="info-row">
<text class="info-label">备注</text> <text class="info-label">备注</text>
<text class="info-value">{{ student.remark || '' }}</text> <text class="info-value">{{ student.note || '' }}</text>
</view> </view>
<view class="info-row"> <view class="info-row">
<text class="info-label">班主任</text> <text class="info-label">班主任</text>
@ -52,18 +52,6 @@
<text class="info-value">{{ student.course_visit_status || '' }}</text> <text class="info-value">{{ student.course_visit_status || '' }}</text>
</view> </view>
</view> </view>
<!-- 操作按钮区域 -->
<view class="action-panel">
<view
class="action-btn"
v-for="action in actions"
:key="action.key"
@click="handleAction(action)"
>
<text class="action-text">{{ action.text }}</text>
</view>
</view>
</view> </view>
</template> </template>
@ -90,14 +78,9 @@ export default {
} }
}, },
methods: { methods: {
toggleActions() { handleStudentClick(){
this.$emit('toggle-actions', this.student) this.$emit('action',{ action: 'edit', student: this.student})
},
handleAction(action) {
this.$emit('action', { action, student: this.student })
}, },
// xx // xx
calculateAge(birthday) { calculateAge(birthday) {
if (!birthday) return '' if (!birthday) return ''

117
uniapp/pages-market/clue/clue_info.vue

@ -45,7 +45,6 @@
<view class="student-swiper-content"> <view class="student-swiper-content">
<StudentInfoCard <StudentInfoCard
:student="student" :student="student"
:actions="[]"
:show-details="true" :show-details="true"
@action="handleStudentAction" @action="handleStudentAction"
/> />
@ -656,18 +655,25 @@ export default {
}, },
handleStudentAction({ action, student }) { handleStudentAction({ action, student }) {
this.setCurrentStudent(student) // this.setCurrentStudent(student)
console.log('学生操作:', action, student)
switch (action.key) {
case 'course_info': //
this.switch_tags_type = 2 switch (action) {
case 'edit':
// -
this.openEditStudentDialog(student)
break break
case 'fitness_record': case 'view':
this.switch_tags_type = 4 //
this.viewStudentDetail(student)
break break
case 'study_plan': case 'delete':
this.switch_tags_type = 5 //
this.confirmDeleteStudent(student)
break break
default:
console.log('未处理的学员操作:', action)
} }
}, },
@ -1011,15 +1017,100 @@ export default {
}) })
}, },
//
openEditStudentDialog(student) {
//
this.$nextTick(() => {
if (this.$refs.studentEditPopup) {
console.log('打开编辑学员弹窗,学员信息:', student)
// openEdit
this.$refs.studentEditPopup.openEdit(student)
} else {
console.error('studentEditPopup 组件引用不存在')
uni.showToast({
title: '组件加载中,请稍后再试',
icon: 'none'
})
}
})
},
//
viewStudentDetail(student) {
console.log('查看学员详情:', student)
//
const detailInfo = `
姓名${student.name}
性别${student.gender === 1 ? '男' : student.gender === 2 ? '女' : '未知'}
年龄${student.age || '未知'}
生日${student.birthday || '未知'}
联系电话${student.contact_phone || '未填写'}
紧急联系人${student.emergency_contact || '未填写'}
备注${student.note || '无'}
状态${student.status === 1 ? '有效' : '无效'}
`.trim()
uni.showModal({
title: '学员详情',
content: detailInfo,
showCancel: false,
confirmText: '知道了'
})
},
//
confirmDeleteStudent(student) {
uni.showModal({
title: '确认删除',
content: `确定要删除学员"${student.name}"吗?此操作无法撤销。`,
success: (res) => {
if (res.confirm) {
this.deleteStudent(student)
}
}
})
},
//
async deleteStudent(student) {
try {
// API
// const res = await apiRoute.deleteStudent({ student_id: student.id })
// if (res.code === 1) {
uni.showToast({ title: '删除成功', icon: 'success' })
//
await this.getStudentList()
// } else {
// uni.showToast({ title: res.msg || '', icon: 'none' })
// }
} catch (error) {
console.error('删除学员失败:', error)
uni.showToast({ title: '删除失败', icon: 'none' })
}
},
async handleStudentEditConfirm(result) { async handleStudentEditConfirm(result) {
try { try {
// API console.log('学员编辑确认结果:', result)
const res = await apiRoute.xs_addStudent(result.studentData)
let res
if (result.isEditing) {
// - API
console.log('编辑学员信息:', result.studentData)
res = await apiRoute.xs_editStudent(result.studentData)
} else {
// - API
console.log('新增学员信息:', result.studentData)
res = await apiRoute.xs_addStudent(result.studentData)
}
if (res.code === 1) { if (res.code === 1) {
this.$refs.studentEditPopup.close() this.$refs.studentEditPopup.close()
uni.showToast({ title: '保存成功', icon: 'success' }) uni.showToast({
title: result.isEditing ? '编辑成功' : '添加成功',
icon: 'success'
})
// //
await this.getStudentList() await this.getStudentList()
} else { } else {

92
uniapp/pages-student/schedule/index.vue

@ -238,14 +238,45 @@
async loadStudentInfo() { async loadStudentInfo() {
try { try {
// console.log('加载学员信息:', this.studentId)
const mockStudentInfo = {
// API
const response = await apiRoute.getStudentBasicInfo({
student_id: this.studentId
})
console.log('学员信息API响应:', response)
if (response.code === 1) {
// API
this.studentInfo = {
id: this.studentId,
name: response.data.name || response.data.student_name || '学员',
phone: response.data.phone || response.data.mobile || '',
avatar: response.data.avatar || '/static/icon-img/avatar.png'
}
console.log('学员信息加载成功:', this.studentInfo)
} else {
console.warn('API返回错误,使用默认信息:', response.msg)
// API使
this.studentInfo = {
id: this.studentId, id: this.studentId,
name: '小明' name: '学员',
phone: '',
avatar: '/static/icon-img/avatar.png'
}
} }
this.studentInfo = mockStudentInfo
} catch (error) { } catch (error) {
console.error('获取学员信息失败:', error) console.error('获取学员信息失败:', error)
console.warn('API调用失败,使用默认信息')
// API使
this.studentInfo = {
id: this.studentId,
name: '学员',
phone: '',
avatar: '/static/icon-img/avatar.png'
}
} }
}, },
@ -398,16 +429,53 @@
async loadWeeklyStats() { async loadWeeklyStats() {
try { try {
// console.log('加载本周统计数据:', this.studentId, this.currentWeekStart)
const mockStats = {
total_courses: 8, //
completed_courses: 3, const weekStart = this.formatDateString(this.currentWeekStart)
scheduled_courses: 4, const weekEnd = new Date(this.currentWeekStart)
cancelled_courses: 1 weekEnd.setDate(this.currentWeekStart.getDate() + 6)
} const weekEndStr = this.formatDateString(weekEnd)
this.weeklyStats = mockStats
// API
const response = await apiRoute.getCourseScheduleStatistics({
student_id: this.studentId,
start_date: weekStart,
end_date: weekEndStr
})
console.log('周统计API响应:', response)
if (response.code === 1) {
// API
this.weeklyStats = {
total_courses: response.data.total_courses || 0,
completed_courses: response.data.completed_courses || 0,
scheduled_courses: response.data.scheduled_courses || 0,
cancelled_courses: response.data.cancelled_courses || 0
}
console.log('周统计数据加载成功:', this.weeklyStats)
} else {
console.warn('统计API返回错误,使用默认数据:', response.msg)
// API使
this.weeklyStats = {
total_courses: 0,
completed_courses: 0,
scheduled_courses: 0,
cancelled_courses: 0
}
}
} catch (error) { } catch (error) {
console.error('获取周统计失败:', error) console.error('获取周统计失败:', error)
console.warn('统计API调用失败,使用默认数据')
// API使
this.weeklyStats = {
total_courses: 0,
completed_courses: 0,
scheduled_courses: 0,
cancelled_courses: 0
}
} }
}, },

Loading…
Cancel
Save