liumiao
2021-04-01 07e5b3fd4ec38bae10c11d011b75c8d5c5c0d780
Merge branch 'develop' into pre-release
2 files added
5 files modified
345 ■■■■■ changed files
.env 6 ●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/AskForLeaveController.php 255 ●●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/ClassScheduleController.php 6 ●●●● patch | view | raw | blame | history
app/Models/AttendApprovalLogModel.php 41 ●●●●● patch | view | raw | blame | history
app/Models/AttendRecordModel.php 22 ●●●●● patch | view | raw | blame | history
app/Models/ParentsModel.php 11 ●●●●● patch | view | raw | blame | history
routes/api.php 4 ●●●● patch | view | raw | blame | history
.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
app/Http/Controllers/Api/v1/AskForLeaveController.php
New file
@@ -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));
    }
}
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;
            }
app/Models/AttendApprovalLogModel.php
New file
@@ -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;
    }
}
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;
    }
}
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;
    }
}
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 ****************************************/