From a3a1c0bae74bd8fce63eb13a8f621108fdb22361 Mon Sep 17 00:00:00 2001
From: liumiao <495261512@qq.com>
Date: 星期日, 25 四月 2021 10:45:44 +0800
Subject: [PATCH] Merge branch 'develop' into pre-release

---
 app/Models/CourseHourTotalLogModel.php                  |   17 +++++
 app/Models/CourseHourTotalModel.php                     |   17 +++++
 app/Http/Controllers/Api/v1/ClassScheduleController.php |   21 ++++++
 app/Http/Controllers/Api/v1/AskForLeaveController.php   |  108 +++++++++++++++++++++++++++++++++++
 4 files changed, 161 insertions(+), 2 deletions(-)

diff --git a/app/Http/Controllers/Api/v1/AskForLeaveController.php b/app/Http/Controllers/Api/v1/AskForLeaveController.php
index 3c250d3..4f23802 100644
--- a/app/Http/Controllers/Api/v1/AskForLeaveController.php
+++ b/app/Http/Controllers/Api/v1/AskForLeaveController.php
@@ -8,6 +8,9 @@
 use App\Models\AttendApprovalLogModel;
 use App\Models\AttendRecordModel;
 use App\Models\ClassModel;
+use App\Models\ClassStudentsModel;
+use App\Models\CourseHourTotalLogModel;
+use App\Models\CourseHourTotalModel;
 use App\Models\CourseTableModel;
 use App\Models\CourseTableTeacherModuleModel;
 use App\Models\ParentsModel;
@@ -76,6 +79,13 @@
                     "attendRecordId" => $val["attendRecordId"],
                 ];
                 AttendApprovalLogModel::updateRecordMass(["status" => $approvalStatus], $data);
+
+                //鏇存柊璇炬椂
+                if($approvalStatus == 2)
+                {
+                    $this->upCourseHour($val["username"], $classHour, $val["classcode"], 2);
+                }
+
             }
 
             DB::commit();
@@ -85,6 +95,102 @@
             DB::rollBack();
             CustomLog::queryinfo("璇峰亣鏃ュ織鍐欏叆------------>" . json_encode($e->getMessage(), true));
             return $this->_response('', ResponseCode::COMMON_ERROR, "璇峰亣澶辫触");
+        }
+    }
+
+    /**
+     * @param $userName
+     * @param $hour
+     * @param $classCode
+     * @param int $type 2 鍑忓皯  1澧炲姞
+     * @Author lium
+     * @Date  2021/4/24 10:28
+     * @Explain CN銆� 淇敼瀛﹀憳璇炬椂 銆�
+     * @Explain EN銆�  銆�
+     */
+    public function upCourseHour($userName, $hour, $classCode, $type = 2)
+    {
+        $totalHourInfo = CourseHourTotalModel::findRecordOneCondition(["username" => $userName],
+            ["id", "username", "laohourTotal", "hourTotal", "laoinClassHourTotal", "ClassHourTotal", "laosurplusHourTotal", "surplusHourTotal"]);
+        $classStudentInfo = ClassStudentsModel::findRecordOneCondition(["classCode" => $classCode, "username" => $userName, "isDelete" => 0, "status" => 1]);
+
+        $laosurplusHourTotal = 0; // 鑰佺殑 鍓╀綑鎬昏鏃�
+        $laoinClassHourTotal = 0; // 鑰佺殑 宸蹭笂鎬昏鏃�
+        $ClassHourTotal = 0; // 鏂扮殑 宸蹭笂鎬昏鏃�
+        $surplusHourTotal = 0; // 鏂扮殑 鍓╀綑鎬昏鏃�
+        //鍑忓皯鎿嶄綔
+        if(!empty($totalHourInfo) && !empty($classStudentInfo) && $type == 2)
+        {
+            //鍓╀綑鎬昏鏃� 澶т簬0  && 鎬昏鏃� - 淇敼璇炬椂 涔熷ぇ浜�0
+            if($totalHourInfo["laosurplusHourTotal"] > 0 && ($totalHourInfo["laosurplusHourTotal"] - $hour) > 0)
+            {
+                $laosurplusHourTotal = $totalHourInfo["laosurplusHourTotal"] - $hour;
+                $laoinClassHourTotal = $totalHourInfo["laoinClassHourTotal"] + $hour;
+            }
+            else if($totalHourInfo["laosurplusHourTotal"] == 0)
+            {
+                $ClassHourTotal = $totalHourInfo["ClassHourTotal"] + $hour;
+                $surplusHourTotal = $totalHourInfo["surplusHourTotal"] - $hour;
+            }
+            else
+            {
+                //淇敼璇炬椂锛屽噺鍘诲墿浣欒�佺殑鎬昏鏃�
+                $residueHour = $hour - $totalHourInfo["laosurplusHourTotal"];
+                $laosurplusHourTotal = $totalHourInfo["laosurplusHourTotal"] - $hour > 0 ? $totalHourInfo["laosurplusHourTotal"] - $hour : 0; //鑰佺殑鍓╀綑 鎬昏鏃�
+                $laoinClassHourTotal = $totalHourInfo["laoinClassHourTotal"] + $hour - $residueHour; // 鑰佺殑宸蹭笂鎬昏鏃�
+                $surplusHourTotal = $totalHourInfo["surplusHourTotal"] - $residueHour; // 鏂扮殑 鍓╀綑鎬昏鏃�
+                $ClassHourTotal = $totalHourInfo["ClassHourTotal"] + $residueHour; // 鏂扮殑宸蹭笂鎬昏鏃�
+            }
+            $data = [
+                "laoinClassHourTotal" => $laoinClassHourTotal,  //宸蹭笂鎬昏鏃讹紙鑰侊級
+                "laosurplusHourTotal" => $laosurplusHourTotal, //鍓╀綑鎬昏鏃讹紙鑰侊級
+                "ClassHourTotal" => $ClassHourTotal, //宸蹭笂鎬昏鏃�
+                "surplusHourTotal" => $surplusHourTotal, //鍓╀綑鎬昏鏃�
+                "updateTime" => date("Y-m-d H:i:s"),
+            ];
+            CourseHourTotalModel::updateRecordMass($data, ["username" => $userName]);
+            $usedcourseHour = $classStudentInfo["usedcourseHour"] + $laoinClassHourTotal + $ClassHourTotal;
+            ClassStudentsModel::updateRecordMass(["usedcourseHour" => $usedcourseHour], ["username" => $userName, "classCode" => $classCode]);
+
+            CourseHourTotalLogModel::addRecord([
+                "username" => $userName,
+                "classcode" => $classCode,
+                "courseHour" => $hour,
+                "userId" => $this->getAndCheckTeacherId(),
+                "type" => $type
+            ]);
+        }
+
+        //澧炲姞鎿嶄綔
+        if(!empty($totalHourInfo) && !empty($classStudentInfo) && $type == 1)
+        {
+            if($totalHourInfo["ClassHourTotal"] == 0)
+            {
+                $laoinClassHourTotal = $totalHourInfo["laoinClassHourTotal"] - $hour;
+            }
+            else
+            {
+                $ClassHourTotal = $totalHourInfo["ClassHourTotal"] - $hour;
+            }
+
+            $surplusHourTotal = $totalHourInfo["surplusHourTotal"] + $hour;
+            $addData = [
+                "laoinClassHourTotal" => $laoinClassHourTotal,  //宸蹭笂鎬昏鏃讹紙鑰侊級
+                "ClassHourTotal" => $ClassHourTotal, //宸蹭笂鎬昏鏃�
+                "surplusHourTotal" => $surplusHourTotal, //鍓╀綑鎬昏鏃�
+                "updateTime" => date("Y-m-d H:i:s"),
+            ];
+            CourseHourTotalModel::updateRecordMass($addData, ["username" => $userName]);
+            $usedcourseHour = $classStudentInfo["usedcourseHour"] - $hour;
+            ClassStudentsModel::updateRecordMass(["usedcourseHour" => $usedcourseHour], ["username" => $userName, "classCode" => $classCode]);
+
+            CourseHourTotalLogModel::addRecord([
+                "username" => $userName,
+                "classcode" => $classCode,
+                "courseHour" => $hour,
+                "userId" => $this->getAndCheckTeacherId(),
+                "type" => $type
+            ]);
         }
     }
 
@@ -130,7 +236,7 @@
             $where["ar.approvalStatus"] = $approvalStatus;
         }
 
-        $select = ["ar.createTime", "ct.week", "ct.classNumber", "ar.contentTime", "ar.cause", "s.name", "s.headPhoto", "ct.className", "ct.startTime", "ct.classCode", "ct.staffId", "ar.approvalStatus", "ar.id as attendRecordId", "ct.id as coursetableId", "ar.username", "u.RealCnName", "u.EnName", "ar.approvalOpinion", "ar.approvalTime", "ar.classHour"];
+        $select = ["ar.createTime", "ct.week", "ct.classNumber", "ar.contentTime", "ar.cause", "s.name", "s.headPhoto", "ct.className", "ct.startTime", "ct.classCode", "ct.staffId", "ar.approvalStatus", "ar.id as attendRecordId", "ct.id as coursetableId", "ar.username", "u.RealCnName", "u.EnName", "ar.approvalOpinion", "ar.approvalTime", "ar.classHour", "ar.classCode"];
         $orderBy = ["ar.id" => "desc"];
         $query = AttendRecordModel::getAskForLeave();
         $list = AttendRecordModel::getDataJoinList($query, $where, $select, $orderBy)->toArray();
diff --git a/app/Http/Controllers/Api/v1/ClassScheduleController.php b/app/Http/Controllers/Api/v1/ClassScheduleController.php
index 51ce9be..b6fc324 100644
--- a/app/Http/Controllers/Api/v1/ClassScheduleController.php
+++ b/app/Http/Controllers/Api/v1/ClassScheduleController.php
@@ -143,6 +143,7 @@
         $classStatus = $request->post("classStatus");
         $remark = $request->post("remark");
         $userNames = explode(",", $request->post("userNames"));
+        $ask = new AskForLeaveController();
         foreach($userNames as $username)
         {
             $data = [
@@ -161,6 +162,21 @@
             if($info)
             {
                 AttendRecordModel::updateRecordMass($data, $where);
+                if($classHour > $info["classHour"])
+                {
+                    $hour = $classHour - $info["classHour"];
+                    //鏇存柊璇炬椂鏁版嵁
+                    $ask->upCourseHour($username, $hour, $classCode, 2);
+                }
+                else
+                {
+                    $hour = $info["classHour"] - $classHour;
+                    if($hour > 0)
+                    {
+                        //鏇存柊璇炬椂鏁版嵁
+                        $ask->upCourseHour($username, $hour, $classCode, 1);
+                    }
+                }
             }
             else
             {
@@ -180,6 +196,9 @@
                     "classStatus" => $classStatus,
                 ];
                 AttendRecordModel::addRecord($addData);
+
+                //鏇存柊璇炬椂鏁版嵁
+                $ask->upCourseHour($username, $classHour, $classCode, 2);
             }
 
         }
@@ -358,7 +377,7 @@
         $roleIdArr = $request->post("roleIdArr");
         $courseTableId = $request->post("courseTableId");
         $contentTime = $request->post("contentTime");
-        $teacherId =$this->getAndCheckTeacherId(); //236523
+        $teacherId = $this->getAndCheckTeacherId(); //236523
         if(empty($date))
         {
             $date = date("Y-m-d");
diff --git a/app/Models/CourseHourTotalLogModel.php b/app/Models/CourseHourTotalLogModel.php
new file mode 100644
index 0000000..50aa945
--- /dev/null
+++ b/app/Models/CourseHourTotalLogModel.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Models;
+
+class CourseHourTotalLogModel extends Model
+{
+
+
+    protected $table = 'anni_coursehourtotallog';
+
+    protected $primaryKey = 'id';
+
+    public $incrementing = false;
+
+    public $timestamps = false;
+
+}
diff --git a/app/Models/CourseHourTotalModel.php b/app/Models/CourseHourTotalModel.php
new file mode 100644
index 0000000..930f815
--- /dev/null
+++ b/app/Models/CourseHourTotalModel.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Models;
+
+class CourseHourTotalModel extends Model
+{
+
+
+    protected $table = 'anni_coursehourtotal';
+
+    protected $primaryKey = 'id';
+
+    public $incrementing = false;
+
+    public $timestamps = false;
+
+}

--
Gitblit v1.8.0