|
@@ -19,31 +19,40 @@ class StudentsImport implements ToArray
|
|
{
|
|
{
|
|
foreach($rows as $key => $row)
|
|
foreach($rows as $key => $row)
|
|
{
|
|
{
|
|
- if($key == 0) continue;
|
|
|
|
- $student = Student::create([
|
|
|
|
|
|
+ if($key == 0 || empty($row[0])) continue;
|
|
|
|
+ $student = Student::firstOrCreate([
|
|
'name' => $row[0],
|
|
'name' => $row[0],
|
|
- 'phone' => $row[1],
|
|
|
|
- 'remark' => $row[6],
|
|
|
|
|
|
+ 'phone' => $row[1]
|
|
|
|
+ ], [
|
|
|
|
+ 'remark' => $row[6]
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
+ if(empty($student)) continue;
|
|
|
|
+
|
|
$course = Course::firstOrCreate([
|
|
$course = Course::firstOrCreate([
|
|
'name' => $row[2]
|
|
'name' => $row[2]
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
+ if(empty($course)) continue;
|
|
|
|
+
|
|
$assign_teacher = $row[5] == '全部' ? 1 : 2;
|
|
$assign_teacher = $row[5] == '全部' ? 1 : 2;
|
|
|
|
|
|
$duration = null;
|
|
$duration = null;
|
|
if(!empty($row[3]) && !empty($row[4]) && $row[4] > $row[3]) {
|
|
if(!empty($row[3]) && !empty($row[4]) && $row[4] > $row[3]) {
|
|
$duration = Carbon::createFromTimestamp(strtotime($row[3]))->diffInDays(Carbon::createFromTimestamp(strtotime($row[4])));
|
|
$duration = Carbon::createFromTimestamp(strtotime($row[3]))->diffInDays(Carbon::createFromTimestamp(strtotime($row[4])));
|
|
}
|
|
}
|
|
- $student_course = StudentCourse::create([
|
|
|
|
|
|
+
|
|
|
|
+ $student_course = StudentCourse::firstOrCreate([
|
|
'student_id' => $student->id,
|
|
'student_id' => $student->id,
|
|
- 'course_id' => $course->id,
|
|
|
|
|
|
+ 'course_id' => $course->id
|
|
|
|
+ ], [
|
|
'apply_date' => $row[3],
|
|
'apply_date' => $row[3],
|
|
'duration' => $duration,
|
|
'duration' => $duration,
|
|
'assign_teacher' => $assign_teacher
|
|
'assign_teacher' => $assign_teacher
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
+ if(empty($student_course)) continue;
|
|
|
|
+
|
|
if($assign_teacher == 2) {
|
|
if($assign_teacher == 2) {
|
|
$teacher_names = explode(',', $row[5]);
|
|
$teacher_names = explode(',', $row[5]);
|
|
foreach($teacher_names as $teacher_name) {
|
|
foreach($teacher_names as $teacher_name) {
|
|
@@ -51,7 +60,7 @@ class StudentsImport implements ToArray
|
|
'name' => $teacher_name
|
|
'name' => $teacher_name
|
|
]);
|
|
]);
|
|
|
|
|
|
- StudentCourseTeacher::create([
|
|
|
|
|
|
+ StudentCourseTeacher::firstOrCreate([
|
|
'student_course_id' => $student_course->id,
|
|
'student_course_id' => $student_course->id,
|
|
'teacher_id' => $teacher->id,
|
|
'teacher_id' => $teacher->id,
|
|
'student_id' => $student->id,
|
|
'student_id' => $student->id,
|