From 07e5b3fd4ec38bae10c11d011b75c8d5c5c0d780 Mon Sep 17 00:00:00 2001
From: liumiao <495261512@qq.com>
Date: 星期四, 01 四月 2021 09:10:08 +0800
Subject: [PATCH] Merge branch 'develop' into pre-release

---
 routes/api.php                                          |    4 
 app/Http/Controllers/Api/v1/ClassScheduleController.php |    6 
 .env                                                    |    6 
 app/Http/Controllers/Api/v1/AskForLeaveController.php   |  255 ++++++++++++++++++++++++++++++++++++++++++
 app/Models/ParentsModel.php                             |   11 +
 app/Models/AttendApprovalLogModel.php                   |   41 ++++++
 app/Models/AttendRecordModel.php                        |   22 +++
 7 files changed, 338 insertions(+), 7 deletions(-)

diff --git a/.env b/.env
index 86c9e73..dd77043 100644
--- a/.env
+++ b/.env
@@ -16,7 +16,7 @@
 #DB_PASSWORD=anniekids@2019
 
 DB_CONNECTION=mysql
-DB_HOST=rm-bp10kr0f1v52a140rqo.mysql.rds.aliyuncs.com
+DB_HOST=rm-bp19c9r223a1e03a390130.mysql.rds.aliyuncs.com
 DB_PORT=3306
 DB_DATABASE=anniproject
 DB_DATABASE_SYS=annieportal
@@ -31,9 +31,9 @@
 SESSION_DRIVER=file
 SESSION_LIFETIME=120
 
-REDIS_HOST=r-bp1b9ee217c39ef4pd.redis.rds.aliyuncs.com
+REDIS_HOST=r-bp1x4t9mjqejtoufej.redis.rds.aliyuncs.com
 REDIS_PASSWORD=anniekids@2019
-REDIS_USERNAME=r-bp1b9ee217c39ef4
+REDIS_USERNAME=r-bp1x4t9mjqejtoufej
 REDIS_PORT=6379
 REDIS_DB = 1
 REDIS_PREFIX = testgardener
diff --git a/app/Http/Controllers/Api/v1/AskForLeaveController.php b/app/Http/Controllers/Api/v1/AskForLeaveController.php
new file mode 100644
index 0000000..3c250d3
--- /dev/null
+++ b/app/Http/Controllers/Api/v1/AskForLeaveController.php
@@ -0,0 +1,255 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Common\CustomLog;
+use App\Http\Controllers\ApiController;
+use App\Common\ResponseCode;
+use App\Models\AttendApprovalLogModel;
+use App\Models\AttendRecordModel;
+use App\Models\ClassModel;
+use App\Models\CourseTableModel;
+use App\Models\CourseTableTeacherModuleModel;
+use App\Models\ParentsModel;
+use App\Models\Portal\UserModel;
+use App\Models\StudentsModel;
+use Illuminate\Http\Request;
+use Illuminate\Support\Arr;
+use Illuminate\Support\Facades\DB;
+use Validator;
+
+class AskForLeaveController extends ApiController
+{
+
+    /**
+     * @param Request $request
+     * @Author lium
+     * @Date  2021/3/29 9:17
+     * @Explain CN銆� 璇峰亣  銆�
+     * @Explain EN銆� add Ask For Leave 銆�
+     */
+    public function addAskForLeave(Request $request)
+    {
+        $rule = [
+            "approvalStatus" => 'required',
+            "approvalOpinion" => 'required',
+            "classHour" => 'required',
+            "param" => 'required',
+        ];
+        $message = $this->_validate($request, $rule);
+        if(!empty($message))
+        {
+            return $this->_response(null, ResponseCode::PARAM_ERROR, $message);
+        }
+        $approvalStatus = $request->post("approvalStatus");
+        $approvalUserId = $this->getAndCheckTeacherId();
+        $approvalOpinion = $request->post("approvalOpinion");
+        $classHour = $request->post("classHour");
+        $param = !empty($request->post("param")) ? json_decode($request->post("param"), true) : [];
+
+        DB::beginTransaction(); //寮�鍚簨鍔�
+        try
+        {
+            foreach($param as $key => $val)
+            {
+                // 鏇存柊瀹℃壒鏁版嵁
+                $arrData = [
+                    "approvalOpinion" => $approvalOpinion,
+                    "approvalUserId" => $approvalUserId,
+                    "approvalTime" => date("Y-m-d H:i:s"),
+                    "approvalStatus" => $approvalStatus,
+                    "classHour" => $classHour,
+                ];
+                if($approvalStatus == 2)
+                {
+                    $arrData["classStatus"] = 4;
+                }
+                if($approvalStatus == 3)
+                {
+                    $arrData["status"] = 2;
+                }
+                AttendRecordModel::updateRecordORM($val['attendRecordId'], $arrData);
+
+                //瀛﹀憳璇峰亣鏃ュ織鏁版嵁
+                $data = [
+                    "coursetableId" => $val["coursetableId"],
+                    "attendRecordId" => $val["attendRecordId"],
+                ];
+                AttendApprovalLogModel::updateRecordMass(["status" => $approvalStatus], $data);
+            }
+
+            DB::commit();
+            return $this->_response();
+        } catch (\Exception $e)
+        {
+            DB::rollBack();
+            CustomLog::queryinfo("璇峰亣鏃ュ織鍐欏叆------------>" . json_encode($e->getMessage(), true));
+            return $this->_response('', ResponseCode::COMMON_ERROR, "璇峰亣澶辫触");
+        }
+    }
+
+
+    /**
+     * @param Request $request
+     * @Author lium
+     * @Date  2021/3/30 17:46
+     * @Explain CN銆� 鑾峰彇璇峰亣鏁版嵁 銆�
+     * @Explain EN銆� Obtain leave data 銆�
+     */
+    public function askForLeaveList(Request $request)
+    {
+        $rule = [
+            'roleIdArr' => 'required',
+        ];
+        $message = $this->_validate($request, $rule);
+        if(!empty($message))
+        {
+            return $this->_response(null, ResponseCode::PARAM_ERROR, $message);
+        }
+
+        $roleIdArr = $request->post("roleIdArr");
+        $monthTime = date("Y-m-d", strtotime("- 6 month")) . " 23:59:59";
+        $teacherId = $this->getAndCheckTeacherId(); //236523
+
+        $approvalStatus = $request->post("approvalStatus", 1);
+        //鑾峰彇鐝骇code
+        $classCode = $this->getClassCode($teacherId, $roleIdArr);
+
+        $where = ["ct.classCode" => ["wherein" => $classCode], "ar.approvalStatus" => [">" => 0], "ar.createTime" => [">=" => $monthTime]];
+
+        if($approvalStatus == 3)
+        {
+            $where["ar.status"] = 2;
+        }
+        else
+        {
+            $where["ar.status"] = 1;
+        }
+        if(is_numeric($approvalStatus) && $approvalStatus > 0)
+        {
+            $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"];
+        $orderBy = ["ar.id" => "desc"];
+        $query = AttendRecordModel::getAskForLeave();
+        $list = AttendRecordModel::getDataJoinList($query, $where, $select, $orderBy)->toArray();
+        $mapList = [];
+        if(!empty($list))
+        {
+            $staffIdArr = [];
+            foreach($list as $v_val)
+            {
+                $staffIdArr[] = $v_val["staffId"];
+            }
+            //鑾峰彇闈㈡巿鐝骇鏁欏笀
+            $staffUser = $this->getStaffUser(array_unique($staffIdArr));
+
+            //鏁欏笀鍚嶇О
+            $teacherName = $this->getTeacherList($classCode);
+
+
+            foreach($list as $key => $val)
+            {
+                //鏁欏笀鍚嶇О
+                if(!empty($val["staffId"]) && $val["staffId"] > 0)
+                {
+                    $tName = !empty($staffUser[$val["staffId"]]) ? $staffUser[$val["staffId"]] : '';
+                }
+                else
+                {
+                    $tName = !empty($teacherName[$val["classCode"] . '-' . $val['classNumber']]) ? implode(",", array_values(array_unique($teacherName[$val["classCode"] . '-' . $val['classNumber']]))) : '';
+                }
+
+                $val["headPhoto"] = $this->fun->stitchingPath($val["headPhoto"]);
+                $val["startTime"] = substr($val["startTime"], 0, 10);
+                $val["subTime"] = substr($val["createTime"], 0, 16);
+                $val["approvalTime"] = substr($val["approvalTime"], 0, 16);
+                $val["teacherName"] = $tName;//鏁欏笀鍚嶅瓧
+                $val["approvalUserName"] = !empty($val['EnName']) ? $val['EnName'] : $val['RealCnName'];//鏁欏笀鍚嶅瓧
+                $mapList[] = $val;
+            }
+        }
+
+        return $this->_response($mapList);
+    }
+
+    /**
+     * @param $classCodeArr
+     * @return array
+     * 鑾峰彇鏁欏笀
+     */
+    public function getTeacherList($classCodeArr)
+    {
+        // 鑾峰彇鏁欏笀
+        $tWhere = ["ctm.classCode" => ["wherein" => array_unique($classCodeArr)], "ctm.isDelete" => 0];
+        $tSelect = ["u.RealCnName", "u.EnName", "ctm.classCode", "ctm.classNumber"];
+        $tUserInfo = CourseTableModel::getDataJoinList(CourseTableModel::queryTeacherList(), $tWhere, $tSelect);
+        $teacherName = [];
+        foreach($tUserInfo as $tKey => $tVal)
+        {
+            $teacherName[$tVal["classCode"] . "-" . $tVal["classNumber"]][] = !empty($tVal["EnName"]) ? $tVal["EnName"] : $tVal["RealCnName"];
+        }
+
+        return $teacherName;
+    }
+
+    /**
+     * @param $staffIdMap
+     * @return array
+     * 鑾峰彇闈㈡巿鐝骇鏁欏笀
+     */
+    public function getStaffUser($staffIdMap)
+    {
+        $list = UserModel::getRecordListCondition(["StaffId" => ["wherein" => $staffIdMap]], ["EnName", "RealCnName", "StaffId"])->toArray();
+        $mapList = [];
+        foreach($list as $val)
+        {
+            $mapList[$val["StaffId"]] = !empty($val["EnName"]) ? $val["EnName"] : $val["RealCnName"];
+        }
+        return $mapList;
+    }
+
+    /**
+     * @param $parentId
+     * @param $roleIdArr
+     * @return int
+     * 鑾峰彇鐝骇code
+     */
+    public function getClassCode($parentId, $roleIdArr)
+    {
+        $codeMap = [];
+        $roleIdList = explode(",", $roleIdArr);
+        if(in_array(2020, $roleIdList))
+        {
+            $teacherList = CourseTableTeacherModuleModel::getRecordListCondition(["UserId" => $parentId, "isDelete" => 0], ["classCode"])->toArray();
+            if(!empty($teacherList))
+            {
+                $fTeacherCode = array_unique(Arr::flatten($teacherList));
+                array_push($codeMap, $fTeacherCode);
+            }
+        }
+        if(in_array(3085, $roleIdList))
+        {
+            $courseList = CourseTableModel::getRecordListCondition(["hometeacherId" => $parentId, "isDelete" => 0, "status" => 1], ["classCode"])->toArray();
+            if(!empty($courseList))
+            {
+                $fCourseCode = array_unique(Arr::flatten($courseList));
+                array_push($codeMap, $fCourseCode);
+            }
+        }
+
+        if(in_array(2022, $roleIdList))
+        {
+            $classList = ClassModel::getRecordListCondition(["staffTaId" => $parentId, "status" => 1, "isDelete" => 0], ["classCode"])->toArray();
+            if(!empty($classList))
+            {
+                $fClassCode = array_unique(Arr::flatten($classList));
+                array_push($codeMap, $fClassCode);
+            }
+        }
+
+        return array_unique(Arr::flatten($codeMap));
+    }
+}
+
diff --git a/app/Http/Controllers/Api/v1/ClassScheduleController.php b/app/Http/Controllers/Api/v1/ClassScheduleController.php
index 6b31661..51ce9be 100644
--- a/app/Http/Controllers/Api/v1/ClassScheduleController.php
+++ b/app/Http/Controllers/Api/v1/ClassScheduleController.php
@@ -358,7 +358,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");
@@ -394,7 +394,7 @@
                 }
                 $classNumber = !empty($classNumberMap) ? implode(',', array_unique(explode(',', rtrim($classNumberMap, ',')))) : '""';
                 $classCode = !empty($classCodeMap) ? implode(',', array_unique($classCodeMap)) : 0;
-                $where .= " and (ct.classNumber in ({$classNumber}) and ct.classCode in ({$classCode})  or (ct.hometeacherId = '{$teacherId}'))";
+                $where .= " and (ct.classNumber in ({$classNumber}) and ct.classCode in ({$classCode})  or ct.hometeacherId = '{$teacherId}')";
                 $list = CourseTableModel::queryRoleJoinList($where);
                 break;
             case 3:
@@ -445,7 +445,7 @@
                 continue;
             }
             //鏁欏笀 鎴� 瀹跺煿甯� 鏁版嵁 鍒ゆ柇鍘婚櫎妯″潡鏁欏笀涓嶄竴鑷寸殑鏁版嵁
-            if(empty($classNumberMaps[$val["classNumber"] . "-" . $val["classCode"]]) && $roleId == 2)
+            if(!empty($classNumberMaps) && empty($classNumberMaps[$val["classNumber"] . "-" . $val["classCode"]]) && $roleId == 2)
             {
                 continue;
             }
diff --git a/app/Models/AttendApprovalLogModel.php b/app/Models/AttendApprovalLogModel.php
new file mode 100644
index 0000000..4738506
--- /dev/null
+++ b/app/Models/AttendApprovalLogModel.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Support\Facades\DB;
+
+/**
+ * Class FunctionMenuModel
+ * @package App\Models
+ * app 瀛﹀憳璇峰亣鏃ュ織琛�
+ */
+class AttendApprovalLogModel extends Model
+{
+    //use SoftDeletes;
+    /**
+     * @var string
+     */
+    protected $table = 'anni_attend_approval_log';
+
+    protected $primaryKey = 'id';
+
+    public $incrementing = true;
+
+
+    protected $guarded = [];
+
+    const UPDATED_AT = null; //鏇存柊涓嶉渶瑕佽繖涓瓧娈靛彲浠ヨ缃负null
+
+    const CREATED_AT = null; //鏇存柊涓嶉渶瑕佽繖涓瓧娈靛彲浠ヨ缃负null
+
+    public static function queryLogInfo()
+    {
+        $query = DB::table("anni_attend_approval_log as aal")
+            ->leftJoin("anni_attendrecord as ar", "aal.attendRecordId", "=", "ar.id")
+            ->leftJoin(ANNIEPORTAL . "sys_user as u", "ar.approvalUserId", "=", "u.UserId");
+        return $query;
+
+
+    }
+
+}
diff --git a/app/Models/AttendRecordModel.php b/app/Models/AttendRecordModel.php
index 1a8af2c..1823b1c 100644
--- a/app/Models/AttendRecordModel.php
+++ b/app/Models/AttendRecordModel.php
@@ -3,6 +3,8 @@
 namespace App\Models;
 
 use App\Models\Model;
+use Illuminate\Support\Facades\DB;
+use function foo\func;
 
 class AttendRecordModel extends Model
 {
@@ -28,7 +30,7 @@
      */
     public static function getFaceStudentsList()
     {
-        $query = \DB::table("anni_face_attendance as fa")
+        $query = DB::table("anni_face_attendance as fa")
             ->join("anni_students as s", function($query) {
                 $query->on("fa.username", "=", "s.username")
                     ->on("fa.studentId", "=", "s.id");
@@ -36,4 +38,22 @@
         return $query;
     }
 
+    /**
+     * @Author lium
+     * @Date  2021/3/30 18:13
+     * @Explain CN銆� 鑾峰彇璇峰亣鏁版嵁 銆�
+     * @Explain EN銆�  銆�
+     */
+    public static function getAskForLeave()
+    {
+        $query = DB::table("anni_attendrecord as ar")
+            ->join("anni_coursetable as ct", function($query) {
+                $query->on("ar.classNumber", "=", "ct.classNumber")
+                    ->on("ar.coursetableId", "=", "ct.id");
+            }, null, null, "left")
+            ->leftJoin("anni_students as s", "ar.username", "=", "s.username")
+            ->leftJoin("anniePortal.sys_user as u", "ar.approvalUserId", "=", "u.UserId");
+        return $query;
+    }
+
 }
diff --git a/app/Models/ParentsModel.php b/app/Models/ParentsModel.php
index de7ac1e..219d5d6 100644
--- a/app/Models/ParentsModel.php
+++ b/app/Models/ParentsModel.php
@@ -22,5 +22,16 @@
 
     const CREATED_AT = null;
 
+    /**
+     * @return mixed
+     * 鎺掕鏁欏笀鏁版嵁
+     */
+    public static function organizeTeacherCourse()
+    {
+        $query = \DB::table('anni_coursetableteachermodule as ctm')
+            ->leftjoin('anniePortal.sys_user as u', 'ctm.UserId', '=', 'u.UserId');
+        return $query;
+    }
+
 }
 
diff --git a/routes/api.php b/routes/api.php
index 8af9d39..c2266eb 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -71,6 +71,10 @@
         $api->post('/ClassSchedule/getHumanFaceSignInList', 'ClassScheduleController@humanFaceSignInList');         //浜鸿劯鎵撳崱list
         $api->post('/ClassSchedule/getStudentsCourse', 'ClassScheduleController@studentsCourse');                   //瀛﹀憳璇剧▼
 
+        # 璇峰亣
+        $api->post('/AskForLeave/getAskForLeaveList', 'AskForLeaveController@askForLeaveList');                     //璇峰亣鍒楄〃
+        $api->post('/AskForLeave/addAskForLeave', 'AskForLeaveController@addAskForLeave');                          //瀹℃壒璇峰亣
+
         /*******************************  end  lium ****************************************/
 
         /******************************* start Cuiyb ****************************************/

--
Gitblit v1.8.0