liumiao
2021-03-31 f1e4fba8f79c57202cf7f2df20e69c5ba5979879
请假
1 files modified
73 ■■■■■ changed files
app/Http/Controllers/Api/v1/AskForLeaveController.php 73 ●●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/AskForLeaveController.php
@@ -33,10 +33,6 @@
        $rule = [
            'coursetableId' => 'required',
            'attendRecordId' => 'required',
            'username' => 'required',
            'classCode' => 'required',
            'date' => 'required',
            'contentTime' => 'required',
            "approvalStatus" => 'required',
            "approvalUserId" => 'required',
            "approvalOpinion" => 'required',
@@ -49,14 +45,11 @@
        }
        $coursetableId = explode(',', $request->post("coursetableId"));
        $attendRecordId = explode(',', $request->post("attendRecordId"));
        $username = explode(',', $request->post("username"));
        $classCode = explode(',', $request->post("classCode"));
        $date = explode(',', $request->post("date"));
        $approvalStatus = explode(',', $request->post("approvalStatus"));
        $approvalUserId = explode(',', $request->post("approvalUserId"));
        $approvalOpinion = explode(',', $request->post("approvalOpinion"));
        $classHour = explode(',', $request->post("classHour"));
        $contentTime = explode(',', $request->post("contentTime"));
        DB::beginTransaction(); //开启事务
        try
        {
@@ -84,13 +77,8 @@
                $data = [
                    "coursetableId" => $coursetableId[$key],
                    "attendRecordId" => $val,
                    "status" => $approvalStatus[$key],
                    "studentCode" => $username[$key],
                    "dates" => $date[$key],
                    "contentTime" => $contentTime[$key],
                    "classCode" => $classCode[$key],
                ];
                $this->setAttendApprovalLog($data);
                AttendApprovalLogModel::updateRecordMass(["status" => $approvalStatus[$key]], $data);
            }
            DB::commit();
@@ -101,63 +89,6 @@
            CustomLog::queryinfo("请假日志写入------------>" . json_encode($e->getMessage(), true));
            return $this->_response('', ResponseCode::COMMON_ERROR, "请假失败");
        }
    }
    /**
     * @param $data
     * @Author lium
     * @Date  2021/3/29 14:02
     * @Explain CN【 写入请假日志 】
     * @Explain EN【 ApprovalLog 】
     */
    public function setAttendApprovalLog($data)
    {
        //排课表
        $courseInfo = CourseTableModel::findRecordOneCondition(["id" => $data["coursetableId"]]);
        //学员信息
        $studentInfo = StudentsModel::findRecordOneCondition(["username" => $data["studentCode"]], ["name", "headPhoto"]);
        //教师数据
        $pWhere = ["ctm.classNumber" => $courseInfo["classNumber"], "ctm.classCode" => $data["classCode"], "ctm.isDelete" => 0];
        $pSelect = ["u.EnName", "u.RealCnName", "u.UserId"];
        $tUserInfo = ParentsModel::getDataJoinList(ParentsModel::organizeTeacherCourse(), $pWhere, $pSelect);
        $teacherName = [];
        $teacherId = [];
        foreach($tUserInfo as $tVal)
        {
            if(!empty($tVal["EnName"]))
            {
                $teacherName[] = $tVal["EnName"];
            }
            else
            {
                $teacherName[] = $tVal["RealCnName"];
            }
            $teacherId[] = $tVal['UserId'];
        }
        //班级数据
        $classInfo = ClassModel::findRecordOneCondition(["classCode" => $data["classCode"]], ["className"]);
        $logData = [
            "coursetableId" => $data["coursetableId"],
            "attendRecordId" => $data["attendRecordId"],
            "status" => $data["status"],
            "studentCode" => $data["studentCode"],
            "userName" => $studentInfo["name"],
            "studentsFace" => $studentInfo["headPhoto"],
            "dates" => $data["dates"],
            "contentTime" => $data["contentTime"],
            "teachersId" => implode(',', $teacherId),
            "teachersName" => implode(',', $teacherName),
            "classCode" => $data["classCode"],
            "className" => $classInfo["className"],
            "classNumber" => $courseInfo["classNumber"],
        ];
        AttendApprovalLogModel::addRecord($logData);
    }