Silent 6 éve
szülő
commit
d63dc6cd38

+ 55 - 0
app/Http/Controllers/WeChat/ApiController.php

xqd
@@ -177,4 +177,59 @@ class ApiController extends Controller
         $student_course->long_leave_times = $student->long_leave_times;
         return response()->json(['status' => 'success', 'courseInfo' => $student_course]);
     }
+
+    public function getMyLearnInfo(Request $request)
+    {
+        if(empty($request->input('student_id')) || empty($student = Student::find($request->input('student_id')))) {
+            return response()->json(['status' => 'fail', 'info' => '找不到用户信息!']);
+        }
+
+        $now = Carbon::now();
+        $begin_date_time = Carbon::create($now->year, $now->month, 1)->toDateTimeString();
+        $thisMonthLearnTime = 0;
+        $totalLearnTime = 0;
+        $checkCardList = collect();
+        $items = CheckCard::where('student_id', $this['id'])->whereNotNull('begin_date_time')->whereNotNull('end_date_time')->get();
+        foreach($items as $item) {
+            $duration = strtotime($item->end_date_time) - strtotime($item->begin_date_time);
+            $totalLearnTime += $duration;
+            if($item->begin_date_time >= $begin_date_time) {
+                $thisMonthLearnTime += $duration;
+                $day = Carbon::createFromTimestamp(strtotime($item->end_date_time))->day;
+                $checkCardList->push(collect(['month' => 'current', 'day' => $day, 'color' => '#77b9b9']));
+            }
+        }
+        $today = $now->day;
+        for($i = 1; $i <= $today; ++$i) {
+            $tmp = $checkCardList->where('day', $i);
+            if(empty($tmp)) {
+                $checkCardList->push(collect(['month' => 'current', 'day' => $i, 'color' => '#f65556']));
+            }
+        }
+
+        $thisMonthLearnTime = $this->getHumanTime($thisMonthLearnTime);
+        $totalLearnTime = $this->getHumanTime($totalLearnTime);
+
+        $checkCardDays = $student->getCheckCardDates()->count();
+        return response()->json(['status' => 'success', 'checkCardList' => $checkCardList, 'thisMonthLearnTime' => $thisMonthLearnTime, 'totalLearnTime' => $totalLearnTime, 'checkCardDays' => $checkCardDays])
+    }
+
+    public function getHumanTime($seconds)
+    {
+        $res = '';
+        $tmp = floor($seconds / 3600);
+        $diff_time = $seconds % 3600;
+        if(!empty($tmp)) {
+            $res .= $tmp . '小时';
+        }
+        $tmp = floor($diff_time / 3600);
+        $diff_time = $diff_time % 60;
+        if(!empty($tmp)) {
+            $res .= $tmp . '分钟';
+        }
+        if(!empty($diff_time)) {
+            $res .= $diff_time . '秒';
+        }
+        return $res;
+    }
 }

+ 2 - 1
routes/wechat.php

xqd
@@ -7,4 +7,5 @@ Route::get('startCheckCard', 'ApiController@startCheckCard');
 Route::get('endCheckCard', 'ApiController@endCheckCard');
 Route::get('getShareInfo', 'ApiController@getShareInfo');
 Route::get('getMoreVideos', 'ApiController@getMoreVideos');
-Route::get('getCourseInfo', 'ApiController@getCourseInfo');
+Route::get('getCourseInfo', 'ApiController@getCourseInfo');
+Route::get('getMyLearnInfo', 'ApiController@getMyLearnInfo');

+ 20 - 2
wechat/pages/mycourse/mycourse.js

xqd
@@ -1,8 +1,26 @@
 
 var app = getApp()
+var api = require('../../utils/api.js');
+
 Page({
-  
+  data: {
+    courseInfo: null
+  },
   onLoad: function () {
-    console.log('onLoad')
+    let pt_student = wx.getStorageSync('pt_student')
+    wx.request({
+      url: api.getCourseInfoUrl,
+      method: 'GET',
+      data: {
+        'student_id': pt_student.id
+      },
+      success: res => {
+        if (res.data.status == 'success') {
+          this.setData({
+            courseInfo: res.data.courseInfo
+          })
+        }
+      }
+    })
   }
 })

+ 7 - 7
wechat/pages/mycourse/mycourse.wxml

xqd xqd
@@ -1,10 +1,10 @@
-<zan-panel title='成人钢琴培训初级'>
+<zan-panel title='{{ courseInfo.course_name }}'>
   <zan-cell-group>
-    <zan-cell title="主讲老师" value="余军"></zan-cell>
-    <zan-cell title="报名日期" value="2018/5/27"></zan-cell>
-    <zan-cell title="课程截至日期" >
+    <zan-cell title="主讲老师" value="{{ courseInfo.teacher_names }}"></zan-cell>
+    <zan-cell title="报名日期" value="{{ courseInfo.apply_date }}"></zan-cell>
+    <zan-cell title="课程截至日期">
     <view slot="footer">
-      <text class="text-new">2018/5/27</text>
+      <text class="text-new">{{ courseInfo.end_date }}</text>
 
     </view> 
     </zan-cell>
@@ -15,7 +15,7 @@
     </view> 
     </zan-cell>
     <!-- <zan-cell title="课程剩余天数" value="332天"></zan-cell> -->
-    <zan-cell title="剩余请假次数(短假)" value="8次"></zan-cell>
-    <zan-cell title="剩余请假次数(长假)" value="2次"></zan-cell>
+    <zan-cell title="请假次数(短假)" value="{{ courseInfo.short_leave_times }}次"></zan-cell>
+    <zan-cell title="请假次数(长假)" value="{{ courseInfo.long_leave_times }}次"></zan-cell>
   </zan-cell-group>
 </zan-panel>

+ 1 - 0
wechat/utils/api.js

xqd
@@ -9,4 +9,5 @@ module.exports = {
   endCheckCardUrl: headUrl + 'endCheckCard',
   getShareInfoUrl: headUrl + 'getShareInfo',
   getMoreVideosUrl: headUrl + 'getMoreVideos',
+  getCourseInfoUrl: headUrl + 'getCourseInfo',
 }