Silent 7 years ago
parent
commit
d3cc595d11

+ 9 - 3
app/Http/Controllers/WeChat/ApiController.php

xqd xqd
@@ -349,8 +349,14 @@ class ApiController extends Controller
             return response()->json(['status' => 'fail', 'info' => '找不到用户信息!']);
         }
 
-        $now = Carbon::now();
-        $begin_date_time = Carbon::create($now->year, $now->month, 1)->toDateTimeString();
+        if(empty($request->input('year')) || empty($request->input('month'))) {
+            return response()->json(['status' => 'fail', 'info' => '参数错误!']);
+        }
+
+        $year = $request->input('year');
+        $month = $request->input('month');
+        $begin_date_time = Carbon::create($year, $month, 1)->toDateTimeString();
+        $end_date_time = Carbon::create($year, $month, 1)->addMonth(1)->toDateTimeString();
         $thisMonthLearnTime = 0;
         $totalLearnTime = 0;
         $checkCardList = collect();
@@ -358,7 +364,7 @@ class ApiController extends Controller
         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) {
+            if($item->begin_date_time >= $begin_date_time && $item->begin_date_time < $end_date_time) {
                 $thisMonthLearnTime += $duration;
                 $day = Carbon::createFromTimestamp(strtotime($item->end_date_time))->day;
                 $tmp = $checkCardList->where('day', $day);

+ 3 - 0
wechat/pages/my-log/my-log.js

xqd
@@ -53,6 +53,9 @@ Page({
     totalLearnTime: 0,
     checkCardDays: 0
   },
+  dateChange: function(e) {
+    console.log(e);
+  },
   onLoad: function () {
     var pt_student = wx.getStorageSync('pt_student')
     wx.request({

+ 1 - 0
wechat/pages/my-log/my-log.wxml

xqd
@@ -5,6 +5,7 @@
     weeks-type="cn"
     show-more-days="true"
     active-type="rounded"
+    binddateChange="dateChange"
   />
   <zan-cell-group>
     <zan-cell title="本月积累学习时长" value="{{ thisMonthLearnTime }}"> </zan-cell>