diff --git a/app/Console/Commands/UpdateUserNo.php b/app/Console/Commands/UpdateUserNo.php index 2981c2e..22c0ea7 100755 --- a/app/Console/Commands/UpdateUserNo.php +++ b/app/Console/Commands/UpdateUserNo.php @@ -43,14 +43,14 @@ class UpdateUserNo extends Command public function handle() { // 已经开始的课程日期(所有历史数据处理) -// $dateList = Course::whereNotNull('start_date') -// ->where('start_date', '<=', date('Y-m-d')) -// ->orderBy('start_date') -// ->groupBy('start_date') -// ->pluck('start_date') -// ->toArray(); + $dateList = Course::whereNotNull('start_date') + ->where('start_date', '<=', date('Y-m-d')) + ->orderBy('start_date') + ->groupBy('start_date') + ->pluck('start_date') + ->toArray(); // 当日数据处理(日常定时任务) - $dateList = [date('Y-m-d')]; + //$dateList = [date('Y-m-d')]; foreach ($dateList as $date) { $courses = Course::with(['courseSigns' => function ($query) { $query->where('status', 1); @@ -59,14 +59,13 @@ class UpdateUserNo extends Command ->get(); $i = 1; // 编号前缀 - $prefix = date('Ymd', strtotime($date)); foreach ($courses as $course) { foreach ($course->courseSigns as $sign) { $user = User::find($sign->user_id); if ($user->no) { continue; } - $no = $prefix . str_pad($i, 3, '0', STR_PAD_LEFT); + $no = $course->student_prefix . str_pad($i, 3, '0', STR_PAD_LEFT); // 更新用户编号 $user->no = $no; $user->save(); diff --git a/database/migrations/2025_09_26_113323_alert_courses_table.php b/database/migrations/2025_09_26_113323_alert_courses_table.php new file mode 100644 index 0000000..b3a67c0 --- /dev/null +++ b/database/migrations/2025_09_26_113323_alert_courses_table.php @@ -0,0 +1,33 @@ +string('student_prefix')->nullable()->comment('学生编号前缀'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('courses', function (Blueprint $table) { + // + }); + } +};