Silent пре 6 година
родитељ
комит
b006ded655
2 измењених фајлова са 30 додато и 19 уклоњено
  1. 4 4
      app/Http/Controllers/WeChat/ApiController.php
  2. 26 15
      wechat/pages/index/index.js

+ 4 - 4
app/Http/Controllers/WeChat/ApiController.php

@@ -85,12 +85,12 @@ class ApiController extends Controller
     public function startCheckCard(Request $request)
     public function startCheckCard(Request $request)
     {
     {
         if(empty($request->input('student_id')) || empty($student = Student::find($request->input('student_id')))) {
         if(empty($request->input('student_id')) || empty($student = Student::find($request->input('student_id')))) {
-            return back()->json(['status' => 'fail', 'info' => '找不到学员']);
+            return response()->json(['status' => 'fail', 'info' => '找不到学员']);
         }
         }
 
 
         $student_course = StudentCourse::where('student_id', $student->id)->first();
         $student_course = StudentCourse::where('student_id', $student->id)->first();
         if(empty($student_course)) {
         if(empty($student_course)) {
-            return back()->json(['status' => 'fail', 'info' => '暂无课程']);
+            return response()->json(['status' => 'fail', 'info' => '暂无课程']);
         }
         }
 
 
         $res = CheckCard::create([
         $res = CheckCard::create([
@@ -101,8 +101,8 @@ class ApiController extends Controller
         ]);
         ]);
 
 
         if(empty($res)) {
         if(empty($res)) {
-            return back()->json(['status' => 'fail', 'info' => '创建失败']);
+            return response()->json(['status' => 'fail', 'info' => '创建失败']);
         }
         }
-        return back()->json(['status' => 'success', 'info' => '操作成功']);
+        return response()->json(['status' => 'success', 'info' => '操作成功']);
     }
     }
 }
 }

+ 26 - 15
wechat/pages/index/index.js

@@ -71,6 +71,7 @@ Page({
   handleBtnClick() {
   handleBtnClick() {
     let isLearning = this.data.isLearning
     let isLearning = this.data.isLearning
     let is_btn_disabled = this.data.is_btn_disabled
     let is_btn_disabled = this.data.is_btn_disabled
+    let can_check_card = false;
     if (is_btn_disabled) {
     if (is_btn_disabled) {
       wx.showToast({
       wx.showToast({
         title: '请到学校之后再打卡',
         title: '请到学校之后再打卡',
@@ -85,11 +86,32 @@ Page({
       })
       })
       this.endClock()
       this.endClock()
     } else {
     } else {
-      this.setData({
-        isLearning: !isLearning,
-        startTime: new Date().getTime()
+      wx.request({
+        url: api.startCheckCardUrl,
+        method: 'GET',
+        data: {
+          'student_id': app.globalData.ptStudent.id
+        },
+        success: res => {
+          if (res.data.status == 'success') {
+            can_check_card = true;
+          } else {
+            wx.showToast({
+              title: res.data.info,
+              icon: 'none',
+              duration: 800
+            })
+          }
+        }
       })
       })
-      this.startClock()
+
+      if(can_check_card) {
+        this.setData({
+          isLearning: !isLearning,
+          startTime: new Date().getTime()
+        })
+        this.startClock()
+      }
     }
     }
   },
   },
   startClock() {
   startClock() {
@@ -114,17 +136,6 @@ Page({
         clock: "" + hours + ":" + mins + ":" + sec
         clock: "" + hours + ":" + mins + ":" + sec
       })
       })
     }, SEC)
     }, SEC)
-
-    wx.request({
-      url: api.startCheckCardUrl,
-      method: 'GET',
-      data: {
-        'student_id': app.globalData.ptStudent.id
-      },
-      success: res => {
-        
-      }
-    })
     this.interval = interval
     this.interval = interval
   },
   },
   endClock() {
   endClock() {