Silent 6 years ago
parent
commit
7e2da8e74d

+ 11 - 1
app/Http/Controllers/Admin/StudentController.php

xqd
@@ -38,7 +38,17 @@ class StudentController extends Controller
             $list = $list->where('name', 'like', $keyword);
         }
 
-        $list = $list->paginate()->withPath($this->getPaginateUrl());
+        $list = $list->get();
+
+        foreach($list as $item) {
+            $tmp = $item->getCourseInfo();
+            $item->course_name = $tmp['course_name'];
+            $item->apply_date = $tmp['apply_date'];
+            $item->end_date = $tmp['end_date'];
+            $item->teacher_names = $tmp['teacher_names'];
+        }
+
+        $list = $this->paginate($list);
 
         list($pre_uri, $model_name) = array($this->pre_uri, $this->model_name);
         return view($this->view_path . 'index', compact('list', 'pre_uri', 'model_name'));

+ 41 - 0
app/Models/Student.php

xqd
@@ -54,6 +54,47 @@ class Student extends Model
         return StudentCourse::where('student_id', $this['id'])->first();
     }
 
+    public function getCourseInfo()
+    {
+        $student_course = StudentCourse::where('student_id', $this['id'])->first();
+        if(empty($student_course)) {
+            return [
+                'course_name' => '',
+                'apply_date' => '',
+                'end_date' => '',
+                'teacher_names' => ''
+            ];
+        }
+        $course = Course::find($student_course->course_id);
+        if(empty($course)) {
+            $course_name = '';
+        } else {
+            $course_name = $course->name;
+        }
+
+        $apply_date = $student_course->apply_date;
+        if(empty($apply_date) || empty($student_course->duration)) {
+            $end_date = '';
+        } else {
+            $end_date = Carbon::createFromTimestamp(strtotime($apply_date))->addDays($student_course->duration)->toDateString();
+        }
+        $teacher_names = $student_course->getTeacherFullNames();
+        return [
+            'course_name' => $course_name,
+            'apply_date' => $apply_date,
+            'end_date' => $end_date,
+            'teacher_names' => $teacher_names
+        ];
+    }
+
+    public function getCourseName()
+    {
+        $student_course = StudentCourse::where('student_id', $this['id'])->first();
+        if(empty($student_course)) return '';
+        $course = Course::find($student_course->course_id);
+        return empty($course) ? '' : $course->name;
+    }
+
     public function getIsNew()
     {
         $today = Carbon::today();

+ 10 - 0
app/Models/StudentCourse.php

xqd
@@ -25,6 +25,16 @@ class StudentCourse extends Model
         return (new Teacher())->whereIn('id', $ids)->get()->implode('name', ',');
     }
 
+    public function getTeacherFullNames()
+    {
+        if($this['assign_teacher'] == 1) {
+            return '全部';
+        }
+
+        $ids = $this['studentCourseTeachers']->pluck('teacher_id');
+        return (new Teacher())->whereIn('id', $ids)->get()->implode('name', '/');
+    }
+
     public function studentCourseTeachers()
     {
         return $this->hasMany('App\Models\StudentCourseTeacher');

+ 1 - 1
database/migrations/2018_07_28_174327_add_info_to_students.php

xqd
@@ -14,7 +14,7 @@ class AddInfoToStudents extends Migration
     public function up()
     {
         Schema::table('students', function (Blueprint $table) {
-            $table->string('remark', 200)->nullable()->after('addr')->comment('备注');
+            $table->text('remark')->nullable()->after('addr')->comment('备注');
             $table->string('finger_number', 200)->nullable()->after('remark')->comment('指纹编号');
             $table->rememberToken();
         });

+ 11 - 15
resources/views/admin/students/index.blade.php

xqd xqd
@@ -39,14 +39,12 @@
                             <thead>
                                 <tr>
                                     <th>姓名</th>
-                                    <th>年龄</th>
-                                    <th>婚姻状况</th>
-                                    <th>职业</th>
-                                    <th>工作地点</th>
-                                    <th>住址</th>
-                                    <th>指纹编号</th>
+                                    <th>手机号</th>
+                                    <th>课程名称</th>
+                                    <th>报名日期</th>
+                                    <th>截止日期</th>
+                                    <th>任课老师</th>
                                     <th>备注</th>
-                                    <th colspan="2">请假次数</th>
                                     <th>操作</th>
                                 </tr>
                             </thead>
@@ -59,18 +57,16 @@
                                     @foreach($list as $item)
                                         <tr>
                                             <td>{{ $item->name }}</td>
-                                            <td>{{ $item->age }}</td>
-                                            <td>{{ $item->getMarry() }}</td>
-                                            <td>{{ $item->job }}</td>
-                                            <td>{{ $item->work_addr }}</td>
-                                            <td>{{ $item->addr }}</td>
-                                            <td>{{ $item->finger_number }}</td>
+                                            <td>{{ $item->phone }}</td>
+                                            <td>{{ $item->course_name }}</td>
+                                            <td>{{ $item->apply_date }}</td>
+                                            <td>{{ $item->end_date }}</td>
+                                            <td>{{ $item->teacher_names }}</td>
                                             <td>{{ $item->remark }}</td>
-                                            <td>{{ empty($item->short_leave_times) ? 0 : $item->short_leave_times }}</td>
-                                            <td>{{ empty($item->long_leave_times) ? 0 : $item->long_leave_times }}</td>
                                             <td>
                                                 <div class="btn-group">
                                                     <a class="btn btn-sm btn-success btn-courses" href="{{ $pre_uri . 'Course/index?student_id=' . $item->id }}">课程</a>
+                                                    <a class="btn btn-sm btn-warning btn-detail" href="{{ $pre_uri . 'detail?student_id=' . $item->id }}">详情</a>
                                                     <a class="btn btn-sm btn-info btn-edit" href="{{ $pre_uri . 'edit?id=' . $item->id }}">编辑</a>
                                                     <div class="btn btn-sm btn-danger btn-delete" data-id="{{ $item->id }}">删除</div>
                                                 </div>