liumiao
2021-03-31 2634aeebaec43f541582a3b9514454de2ea7bef7
请假
1 files modified
37 ■■■■ changed files
app/Http/Controllers/Api/v1/AskForLeaveController.php 37 ●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/AskForLeaveController.php
@@ -31,54 +31,51 @@
    public function addAskForLeave(Request $request)
    {
        $rule = [
            'coursetableId' => 'required',
            'attendRecordId' => 'required',
            "approvalStatus" => 'required',
            "approvalUserId" => 'required',
            "approvalOpinion" => 'required',
            "classHour" => 'required',
            "param" => 'required',
        ];
        $message = $this->_validate($request, $rule);
        if(!empty($message))
        {
            return $this->_response(null, ResponseCode::PARAM_ERROR, $message);
        }
        $coursetableId = explode(',', $request->post("coursetableId"));
        $attendRecordId = explode(',', $request->post("attendRecordId"));
        $approvalStatus = explode(',', $request->post("approvalStatus"));
        $approvalUserId = explode(',', $request->post("approvalUserId"));
        $approvalOpinion = explode(',', $request->post("approvalOpinion"));
        $classHour = explode(',', $request->post("classHour"));
        $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($attendRecordId as $key => $val)
            foreach($param as $key => $val)
            {
                // 更新审批数据
                $arrData = [
                    "approvalOpinion" => $approvalOpinion[$key],
                    "approvalUserId" => $approvalUserId[$key],
                    "approvalOpinion" => $approvalOpinion,
                    "approvalUserId" => $approvalUserId,
                    "approvalTime" => date("Y-m-d H:i:s"),
                    "approvalStatus" => $approvalStatus[$key],
                    "classHour" => $classHour[$key],
                    "approvalStatus" => $approvalStatus,
                    "classHour" => $classHour,
                ];
                if($approvalStatus[$key] == 2)
                if($approvalStatus == 2)
                {
                    $arrData["classStatus"] = 4;
                }
                if($approvalStatus[$key] == 3)
                if($approvalStatus == 3)
                {
                    $arrData["status"] = 2;
                }
                AttendRecordModel::updateRecordORM($val, $arrData);
                AttendRecordModel::updateRecordORM($val['attendRecordId'], $arrData);
                //学员请假日志数据
                $data = [
                    "coursetableId" => $coursetableId[$key],
                    "attendRecordId" => $val,
                    "coursetableId" => $val["coursetableId"],
                    "attendRecordId" => $val["attendRecordId"],
                ];
                AttendApprovalLogModel::updateRecordMass(["status" => $approvalStatus[$key]], $data);
                AttendApprovalLogModel::updateRecordMass(["status" => $approvalStatus], $data);
            }
            DB::commit();