瀏覽代碼

Merge branch 'jeffry' of ssh://git.9026.com:2212/Silent/PianoTime

Mike 6 年之前
父節點
當前提交
211614aed2

+ 16 - 7
app/Imports/StudentsImport.php

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

+ 10 - 0
app/Models/CheckCard.php

xqd
@@ -14,6 +14,16 @@ class CheckCard extends Model
     {
         return $this->belongsTo('App\Models\Student');
     }
+    
+    public function getStudentName()
+    {
+        return empty($this['student']) ? '' : $this['student']->name;
+    }
+
+    public function getCourseName()
+    {
+        return empty($this['course']) ? '' : $this['course']->name;
+    }
 
     public function studentCourse()
     {

+ 11 - 0
app/Models/Leave.php

xqd
@@ -24,4 +24,15 @@ class Leave extends Model
     {
         return $this->belongsTo('App\Models\StudentCourse');
     }
+
+    public function getStudentName()
+    {
+        return empty($this['student']) ? '' : $this['student']->name;
+    }
+
+    public function getCourseName()
+    {
+        return empty($this['course']) ? '' : $this['course']->name;
+    }
+    
 }

+ 2 - 2
resources/views/admin/check-cards/index.blade.php

xqd
@@ -54,8 +54,8 @@
                                 @else
                                     @foreach($list as $item)
                                         <tr>
-                                            <td>{{ $item->student->name }}</td>
-                                            <td>{{ $item->course->name }}</td>
+                                            <td>{{ $item->getStudentName() }}</td>
+                                            <td>{{ $item->getCourseName() }}</td>
                                             <td>{{ $item->begin_date_time }}</td>
                                             <td>{{ $item->end_date_time }}</td>
                                             <td>{{ $item->duration }}</td>

+ 2 - 2
resources/views/admin/leaves/index.blade.php

xqd
@@ -50,8 +50,8 @@
                                 @else
                                     @foreach($list as $item)
                                         <tr>
-                                            <td>{{ $item->student->name }}</td>
-                                            <td>{{ $item->course->name }}</td>
+                                            <td>{{ $item->getStudentName() }}</td>
+                                            <td>{{ $item->getCourseName() }}</td>
                                             <td>{{ $item->date }}</td>
                                             <td>{{ ($item->type == 1 ? '短假' : '长假') . $item->days . '天' }}</td>
                                             <td>{{ $item->remark }}</td>

+ 2 - 2
resources/views/teacher/check-cards/index.blade.php

xqd
@@ -54,8 +54,8 @@
                                 @else
                                     @foreach($list as $item)
                                         <tr>
-                                            <td>{{ $item->student->name }}</td>
-                                            <td>{{ $item->course->name }}</td>
+                                            <td>{{ $item->getStudentName() }}</td>
+                                            <td>{{ $item->getCourseName() }}</td>
                                             <td>{{ $item->begin_date_time }}</td>
                                             <td>{{ $item->end_date_time }}</td>
                                             <td>{{ $item->duration }}</td>