liumiao
2021-04-25 929ec82231b3a025ba0e5915510b6b01b0128741
Merge branch 'pre-release'
2 files added
2 files modified
163 ■■■■■ changed files
app/Http/Controllers/Api/v1/AskForLeaveController.php 108 ●●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/ClassScheduleController.php 21 ●●●●● patch | view | raw | blame | history
app/Models/CourseHourTotalLogModel.php 17 ●●●●● patch | view | raw | blame | history
app/Models/CourseHourTotalModel.php 17 ●●●●● patch | view | raw | blame | history
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();
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");
app/Models/CourseHourTotalLogModel.php
New file
@@ -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;
}
app/Models/CourseHourTotalModel.php
New file
@@ -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;
}