Silent 6 年之前
父节点
当前提交
e697c829bc
共有 2 个文件被更改,包括 22 次插入4 次删除
  1. 14 0
      app/Http/Controllers/WeChat/ApiController.php
  2. 8 4
      wechat/pages/apply-leave/apply-leave.js

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

xqd xqd
@@ -435,6 +435,12 @@ class ApiController extends Controller
         if(empty($request->input('type')) || !in_array($request->input('type'), [1, 2])) {
             return response()->json(['status' => 'fail', 'info' => '找不到学员']);
         }
+        if($request->input('type') == 1 && $student->short_leave_times <= 0) {
+            return response()->json(['status' => 'fail', 'info' => '短假次数达到上限']);
+        }
+        if($request->input('type') == 2 && $student->long_leave_times <= 0) {
+            return response()->json(['status' => 'fail', 'info' => '长假次数达到上限']);
+        }
         $student_course = StudentCourse::where('student_id', $student->id)->first();
         if(empty($student_course)) {
             return response()->json(['status' => 'fail', 'info' => '暂无课程']);
@@ -451,6 +457,14 @@ class ApiController extends Controller
         if(!$res) {
             return response()->json(['status' => 'fail', 'info' => '保存失败']);
         }
+        if($request->input('type') == 1) {
+            $student->short_leave_times -= 1;
+            $student->save();
+        }
+        if($request->input('type') == 2) {
+            $student->long_leave_times -= 1;
+            $student->save();
+        }
         return response()->json(['status' => 'success', 'info' => '请假成功']);
     }
 

+ 8 - 4
wechat/pages/apply-leave/apply-leave.js

xqd
@@ -83,10 +83,14 @@ Page({
             }
           })
         } else {
-          wx.showToast({
-            title: res.data.info,
-            icon: 'none',
-            duration: 800
+          wx.showModal({
+            title: '请假失败',
+            content: res.data.info,
+            success: function (res) {
+              wx.switchTab({
+                url: '/pages/userinfo/userinfo',
+              })
+            }
           })
         }
       }