Silent пре 6 година
родитељ
комит
d3ee3b992d

+ 15 - 16
app/Http/Controllers/WeChat/ApiController.php

xqd xqd xqd xqd
@@ -342,20 +342,7 @@ class ApiController extends Controller
         $student_course->short_leave_times = $student->short_leave_times;
         $student_course->long_leave_times = $student->long_leave_times;
 
-        $today = Carbon::today();
-        $this_week_begin = null;
-        while($today->dayOfWeekIso != 1) {
-            $today = $today->subDay();
-        }
-        $this_week_begin = $today->toDateTimeString();
-        $this_week_end = $today->addDays(7)->toDateTimeString();
-
-        $tmp = Remark::where([
-            ['student_id', '=', $student->id],
-            ['created_at', '>=', $this_week_begin],
-            ['created_at', '<', $this_week_end],
-        ])->first();
-        $is_new = empty($tmp) ? true : false;
+        $is_new = $student->getIsNew();
 
         return response()->json(['status' => 'success', 'courseInfo' => $student_course, 'is_new' => $is_new]);
     }
@@ -452,6 +439,7 @@ class ApiController extends Controller
         if(empty($request->input('id')) || empty($student = Student::find($request->input('id')))) {
             return response()->json(['status' => 'fail', 'info' => '找不到学员']);
         }
+
         if(empty($student_course = StudentCourse::where('student_id', $student->id)->first())) {
             return response()->json(['status' => 'fail', 'info' => '找不到课程']);
         }
@@ -461,9 +449,18 @@ class ApiController extends Controller
             $teacher_ids = StudentCourseTeacher::where('student_course_id', $student_course->id)->get()->pluck('teacher_id')->unique();
             $teachers = Teacher::whereIn('id', $teacher_ids)->get();
         }
-        $titles = RemarkTitle::where('status', 2)->get();
 
-        return response()->json(['status' => 'success', 'titles' => $titles, 'teachers' => $teachers]);
+        $is_new = $student->getIsNew();
+        if(!$is_new) {
+            $titles = RemarkTitle::where('status', 2)->get();
+            return response()->json(['status' => 'success', 'titles' => $titles, 'teachers' => $teachers, 'is_new' => $is_new]);
+        }
+
+        foreach($teachers as $teacher) {
+            $teacher->average_score = $student->getThisWeekAverageScore($teacher);
+        }
+
+        return response()->json(['status' => 'success', 'is_new' => $is_new, 'teachers' => $teachers]);
     }
 
     public function remarkTeacher(Request $request)
@@ -497,6 +494,8 @@ class ApiController extends Controller
             ], [
                 'course_id' => $student_course->course_id
             ]);
+            $remark->updated_at = Carbon::now()->toDateTimeString();
+            $remark->save();
             foreach($teacher_value as $title_key => $title_value) {
                 $remark_title = RemarkTitle::find($title_key);
                 if(!empty($remark_title)) {

+ 34 - 0
app/Models/Student.php

xqd
@@ -53,4 +53,38 @@ class Student extends Model
     {
         return StudentCourse::where('student_id', $this['id'])->first();
     }
+
+    public function getIsNew()
+    {
+        $today = Carbon::today();
+        $this_week_begin = null;
+        while($today->dayOfWeekIso != 1) {
+            $today = $today->subDay();
+        }
+        $this_week_begin = $today->toDateTimeString();
+        $this_week_end = $today->addDays(7)->toDateTimeString();
+
+        $tmp = Remark::where([
+            ['student_id', '=', $this['id']],
+            ['created_at', '>=', $this_week_begin],
+            ['created_at', '<', $this_week_end],
+        ])->first();
+        return empty($tmp) ? true : false;
+    }
+
+    public function getThisWeekAverageScore(Teacher $teacher)
+    {
+        $today = Carbon::today();
+        $this_week_begin = null;
+        while($today->dayOfWeekIso != 1) {
+            $today = $today->subDay();
+        }
+        $this_week_begin = $today->toDateTimeString();
+
+        return RemarkDetail::where([
+            ['student_id', '=', $this['id']],
+            ['teacher_id', '=', $teacher['id']],
+            ['created_at', '>=', $this_week_begin],
+        ])->get()->avg('score');
+    }
 }

+ 1 - 1
resources/views/admin/remarks/index.blade.php

xqd
@@ -55,7 +55,7 @@
                                             <td>{{ empty($item->course) ? '' : $item->course->name }}</td>
                                             <td>{{ $item->average_score }}</td>
                                             <td>{{ empty($item->student) ? '' : $item->student->name }}</td>
-                                            <td>{{ $item->created_at }}</td>
+                                            <td>{{ $item->updated_at }}</td>
                                             <td>
                                                 <div class="btn-group">
                                                     <a class="btn btn-sm btn-info btn-detail" href="{{ $pre_uri . 'detail?id=' . $item->id }}">详情</a>

+ 24 - 25
wechat/pages/rate/rate.js

xqd
@@ -34,31 +34,30 @@ Page({
   formSubmit: function (e) {
     let data = e.detail.value;
     data.student_id = wx.getStorageSync('pt_student').id
-    console.log(e.detail.value)
-    // wx.request({
-    //   url: api.remarkTeacherUrl,
-    //   method: 'GET',
-    //   data: data,
-    //   success: res => {
-    //     if (res.data.status == 'success') {
-    //       wx.showModal({
-    //         title: '评价成功',
-    //         content: '感谢评价',
-    //         success: function (res) {
-    //           wx.switchTab({
-    //             url: '/pages/userinfo/userinfo',
-    //           })
-    //         }
-    //       })
-    //     } else {
-    //       wx.showToast({
-    //         title: res.data.info,
-    //         icon: 'none',
-    //         duration: 800
-    //       })
-    //     }
-    //   }
-    // })
+    wx.request({
+      url: api.remarkTeacherUrl,
+      method: 'GET',
+      data: data,
+      success: res => {
+        if (res.data.status == 'success') {
+          wx.showModal({
+            title: '评价成功',
+            content: '感谢评价',
+            success: function (res) {
+              wx.switchTab({
+                url: '/pages/userinfo/userinfo',
+              })
+            }
+          })
+        } else {
+          wx.showToast({
+            title: res.data.info,
+            icon: 'none',
+            duration: 800
+          })
+        }
+      }
+    })
   },
   onSubmit: function() {
     wx.navigateTo({url: '/pages/rate-review/rate-review'})