From 44b785686cc490a88cffe8040a7d1a5ae506f84f Mon Sep 17 00:00:00 2001 From: wangzeyan <258785420@qq.com> Date: Fri, 27 Jun 2025 10:26:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/apiController/Course.php | 9 ++++ niucloud/app/api/route/route.php | 2 + niucloud/app/command/TestCommand.php | 3 +- niucloud/app/dict/schedule/schedule.php | 14 ++++- .../app/job/schedule/HandleCourseSchedule.php | 43 +++++++++++++++ .../transfer/schedule/CourseScheduleJob.php | 2 +- .../service/api/apiService/CourseService.php | 52 +++++++++++++++++-- 7 files changed, 119 insertions(+), 6 deletions(-) create mode 100644 niucloud/app/job/schedule/HandleCourseSchedule.php diff --git a/niucloud/app/api/controller/apiController/Course.php b/niucloud/app/api/controller/apiController/Course.php index 80829641..99ce3419 100644 --- a/niucloud/app/api/controller/apiController/Course.php +++ b/niucloud/app/api/controller/apiController/Course.php @@ -114,5 +114,14 @@ class Course extends BaseApiService return success((new CourseService())->schedule_list($data)); } + public function schedule_del(Request $request) + { + $data = $this->request->params([ + ["id", ''], + ["resources_id", ''], + ["remark", ''] + ]); + return (new CourseService())->schedule_del($data); + } } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index ca9eeb89..9b49719e 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -341,6 +341,8 @@ Route::group(function () { Route::get('course/scheduleList', 'apiController.course/schedule_list'); + Route::post('course/schedule_del', 'apiController.course/schedule_del'); + Route::get('per_list_call_up', 'member.Member/list_call_up'); Route::post('per_update_call_up', 'member.Member/update_call_up'); diff --git a/niucloud/app/command/TestCommand.php b/niucloud/app/command/TestCommand.php index c31f9458..31e30875 100644 --- a/niucloud/app/command/TestCommand.php +++ b/niucloud/app/command/TestCommand.php @@ -3,6 +3,7 @@ declare (strict_types = 1); namespace app\command; +use app\job\transfer\schedule\CourseScheduleJob; use app\job\transfer\schedule\ResourceAutoAllocation; use think\console\Command; use think\console\Input; @@ -22,7 +23,7 @@ class TestCommand extends Command protected function execute(Input $input, Output $output) { // 指令输出 - $obj = new ResourceAutoAllocation(); + $obj = new CourseScheduleJob(); $obj->doJob(); $output->writeln('testcommand'); } diff --git a/niucloud/app/dict/schedule/schedule.php b/niucloud/app/dict/schedule/schedule.php index 89e52859..af8c5baf 100644 --- a/niucloud/app/dict/schedule/schedule.php +++ b/niucloud/app/dict/schedule/schedule.php @@ -40,5 +40,17 @@ return [ 'class' => 'app\job\transfer\schedule\PerformanceCalculation', 'function' => '' ], - + [ + 'key' => 'HandleCourseSchedule', + 'name' => '处理课程状态和学员状态', + 'desc' => '', + 'time' => [ + 'type' => 'day', + 'day' => 1, + 'hour' => 0, + 'min' => 5 + ], + 'class' => 'app\job\schedule\HandleCourseSchedule', + 'function' => '' + ], ]; diff --git a/niucloud/app/job/schedule/HandleCourseSchedule.php b/niucloud/app/job/schedule/HandleCourseSchedule.php new file mode 100644 index 00000000..cce3f58a --- /dev/null +++ b/niucloud/app/job/schedule/HandleCourseSchedule.php @@ -0,0 +1,43 @@ +handleCourseStatus(); + return true; + } + + private function handleCourseStatus() + { + $list = CourseSchedule::where('course_date','<',date('Y-m-d'))->select(); + if (!empty($list)) { + foreach ($list as $item) { + CourseSchedule::update([ + 'status' => 'completed' + ], [ + 'id' => $item['id'] + ]); + } + } + } +} diff --git a/niucloud/app/job/transfer/schedule/CourseScheduleJob.php b/niucloud/app/job/transfer/schedule/CourseScheduleJob.php index 10bdeed6..e3c410fe 100644 --- a/niucloud/app/job/transfer/schedule/CourseScheduleJob.php +++ b/niucloud/app/job/transfer/schedule/CourseScheduleJob.php @@ -189,7 +189,7 @@ class CourseScheduleJob extends BaseJob $newSchedule->auto_schedule = 1; // 复制其他所有字段(除了id和主键相关字段) - $attributes = $schedule->getAttributes(); + $attributes = $schedule->toArray(); // 使用toArray()替代getAttributes() foreach ($attributes as $key => $value) { // 跳过id和主键相关字段 if ($key !== 'id' && $key !== 'course_date' && $key !== 'auto_schedule') { diff --git a/niucloud/app/service/api/apiService/CourseService.php b/niucloud/app/service/api/apiService/CourseService.php index c7eb1868..8a366ccf 100644 --- a/niucloud/app/service/api/apiService/CourseService.php +++ b/niucloud/app/service/api/apiService/CourseService.php @@ -263,7 +263,8 @@ class CourseService extends BaseApiService $query->select(); },'venue' => function($query) { $query->select(); - },'campus','studentCourses'])->select()->toArray(); + },'campus','studentCourses']) + ->select()->toArray(); foreach ($list as $k => $v) { $student = Db::name('person_course_schedule') ->alias('pcs') @@ -307,12 +308,57 @@ class CourseService extends BaseApiService $list = $personCourseSchedule ->alias('a') ->join(['school_customer_resources' => 'b'],'a.resources_id = b.id','left') + ->join(['school_course_schedule' => 'c'],'c.id = a.schedule_id','left') ->where('a.schedule_id',$data['schedule_id']) - ->field("b.name,a.status") - ->select()->toArray(); + ->field("b.name,a.status,a.person_type,c.campus_id,b.id as resources_id") + ->select() + ->toArray(); return $list; } + public function schedule_del(array $data) + { + $personCourseSchedule = new PersonCourseSchedule(); + + // 查询记录 + $record = $personCourseSchedule->where([ + 'schedule_id' => $data['id'], + 'resources_id' => $data['resources_id'] + ])->find(); + + if (!$record) { + return fail('未找到相关记录'); + } + + // 根据person_type执行不同操作 + if ($record['person_type'] == 'customer_resource') { + // 如果是客户资源类型,直接删除记录 + $personCourseSchedule->where([ + 'schedule_id' => $data['id'], + 'resources_id' => $data['resources_id'] + ])->delete(); + + // 更新课程安排表的可用容量 + $CourseSchedule = new CourseSchedule(); + $CourseSchedule->where(['id' => $record['schedule_id']])->inc("available_capacity")->update(); + + return success('删除成功'); + } else if ($record['person_type'] == 'student') { + // 如果是学生类型,更新状态为2并更新备注 + $personCourseSchedule->where([ + 'id' => $data['id'], + 'resources_id' => $data['resources_id'] + ])->update([ + 'status' => 2, + 'remark' => $data['remark'] + ]); + + return success('更新成功'); + } else { + return fail('未知的人员类型'); + } + } + }