liumiao
2021-01-28 35c6eaef97493bb021c793f98ece5e8a67d24865
Merge remote-tracking branch 'origin/master'
3 files modified
149 ■■■■ changed files
app/Http/Controllers/Api/v1/FaceController.php 102 ●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/UsreController.php 44 ●●●● patch | view | raw | blame | history
app/Library/ALiYunFace.php 3 ●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/FaceController.php
@@ -53,20 +53,20 @@
        }
        $entityId = 'student_' . $request->studentId . '_' . $request->username;
        // 人脸列表
        $faceList = $faceObj->GetFaceEntity($entityId);
        if(!isset($faceList['data']['Data']))
        if(!isset($res['data']['Data']['MatchList']) || count($res['data']['Data']['MatchList']) == 0)
        {
            $res = $faceObj->AddFaceEntity($entityId, '学生');
        }
        else
        {
            // 删除人脸
            if(count($faceList['data']['Data']['Faces']) != 0)
            // 人脸列表
            $faceList = $faceObj->GetFaceEntity($entityId);
            if(!isset($faceList['data']['Data']))
            {
                foreach($faceList['data']['Data']['Faces'] as $k => $v)
                $res = $faceObj->AddFaceEntity($entityId, '学生');
            }
            else
            {
                // 删除人脸
                if(count($faceList['data']['Data']['Faces']) != 0)
                {
                    $id = $v['FaceId'];
                    $id = $faceList['data']['Data']['Faces'][0]['FaceId'];
                    $faceObj->DeleteFace($id);
                }
            }
@@ -74,6 +74,7 @@
        // 添加人脸
        $res = $faceObj->AddFace($entityId, $path);
        if($res['status'] != 1)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '人脸不符合');
@@ -191,14 +192,21 @@
        $faceObj = new ALiYunFace();
        // 人脸检测定位
        $res = $faceObj->DetectFace($path);
        if($res['status'] != 1)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '检测失败');
        }
        if(!isset($res['data']['Data']['FaceCount']) || $res['data']['Data']['FaceCount'] != 1)
        if(!isset($res['data']['Data']['FaceCount']) || $res['data']['Data']['FaceCount'] == 0)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '未找到人脸,请重新录入');
        }
        if(!isset($res['data']['Data']['FaceCount']) || $res['data']['Data']['FaceCount'] > 1)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '区域范围内只能包含1张人脸,请重新录入');
        }
        // 活体检测
        $res = $faceObj->DetectLivingFace($path);
@@ -239,13 +247,12 @@
                'classCode' => $v['classCode'],
                'classNumber' => $v['classNumber'],
                'contentTime' => $v['contentTime'],
                'courseTableId' => $v['courseTableId'],
                'dates' => $request->dates,
            ];
            $info = FaceAttendanceModel::where($where)->first();
            if(!$info)
            {
                DB::beginTransaction(); //开启事务
                try
                {
@@ -257,6 +264,7 @@
                        'classCode' => $v['classCode'],
                        'classNumber' => $v['classNumber'],
                        'contentTime' => $v['contentTime'],
                        'courseTableId' => $v['courseTableId'],
                        'type' => 3,
                        'dates' => $request->dates,
                        'orgId' => $request->orgId,
@@ -272,19 +280,19 @@
                        'classHour' => $v['classHour'],
                        'className' => $v['className'],
                        'classCode' => $v['classCode'],
                        'coursetableId' => $v['courseTableId'],
                        'sectionid' => '',
                        'createTime' => date('Y-m-d H:i:s'),
                        'updateTime' => date('Y-m-d H:i:s'),
                        'describe' => '人工补录',
                        'remark' => '',
                        'remark' => '人工补录',
                        'status' => 1,
                        'isDelete' => 0,
                        'classStatus' => 1,
                        'repairTime' => '',
                    ];
                    DB::table('anni_attendrecord')->insert($attendrecordData);
                    DB::commit();
                }
                catch (Exception $e)
                {
@@ -311,6 +319,7 @@
            'classNumber' => 'required|string',
            'className' => 'required|string',
            'orgId' => 'required|integer|min:1',
            'courseTableId' => 'required|integer|min:1',
            'type' => 'required|integer|min:1',
            'classHour' => 'required|integer|min:1',
        ];
@@ -383,10 +392,13 @@
            'username' => $username,
            'classCode' => $request->classCode,
        ];
        $userInfo = StudentsModel::where(['id' => $studentId])->select("id", "name")->first();
        $res = DB::table('anni_classstudent')->where($where)->first();
        if(empty($info->faceImg))
        if(!$res)
        {
            return $this->_response([], ResponseCode::SUCCESS, $username . '不在此班级');
            return $this->_response([], ResponseCode::SUCCESS, $userInfo['name'] . '不在此班级');
        }
        $where = [
@@ -395,7 +407,7 @@
        $info = StudentsModel::where($where)->select('id', 'faceImg')->first();
        if(empty($info->faceImg))
        {
            return $this->_response([], ResponseCode::SUCCESS, $username . '未录入人脸');
            return $this->_response([], ResponseCode::SUCCESS, $userInfo['name'] . '未录入人脸');
        }
        $where = [
@@ -404,14 +416,14 @@
            'dates' => $request->dates,
            'contentTime' => $request->contentTime,
            'classNumber' => $request->classNumber,
            'classCode' => $request->classCode
            'classCode' => $request->classCode,
            'courseTableId' => $request->courseTableId,
        ];
        $res = FaceAttendanceModel::where($where)->first();
        if(!empty($res))
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, $username . '已签到,请勿重复签到');
            return $this->_response([], ResponseCode::PARAM_ERROR, $userInfo['name'] . '已签到,请勿重复签到');
        }
        DB::beginTransaction(); //开启事务
        try
        {
@@ -422,8 +434,10 @@
                'classCode' => $request->classCode,
                'classNumber' => $request->classNumber,
                'contentTime' => $request->contentTime,
                'username' => $username,
                'type' => $request->type,
                'dates' => $request->dates,
                'courseTableId' => $request->courseTableId,
                'orgId' => $request->orgId,
                'createdTime' => date('Y-m-d H:i:s'),
            ];
@@ -432,32 +446,31 @@
            $attendrecordData = [
                'orgId' => $request->orgId,
                'staffId' => $request->teacherId,
                'username' => $request->username,
                'username' => $username,
                'classNumber' => $request->classNumber,
                'classHour' => $request->classHour,
                'className' => $request->className,
                'classCode' => $request->classCode,
                'coursetableId' => $request->courseTableId,
                'sectionid' => '',
                'createTime' => date('Y-m-d H:i:s'),
                'updateTime' => date('Y-m-d H:i:s'),
                'describe' => $describe,
                'remark' => '',
                'remark' => $describe,
                'status' => 1,
                'isDelete' => 0,
                'classStatus' => 1,
                'repairTime' => '',
            ];
            DB::table('anni_attendrecord')->insert($attendrecordData);
            $res = DB::table('anni_attendrecord')->insert($attendrecordData);
            DB::commit();
            return $this->_response([], ResponseCode::SUCCESS, $userInfo['name'] . '签到成功');
        }
        catch (Exception $e)
        {
            DB::rollBack();
            return $this->_response('', ResponseCode::PARAM_ERROR, $userInfo['name'] . '签到失败');
        }
        return $this->_response([], ResponseCode::SUCCESS, $username . '签到成功');
    }
    /**
@@ -465,8 +478,7 @@
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public
    function attendanceList(Request $request)
    public function attendanceList(Request $request)
    {
        $rule = [
            'dates' => 'required|string',
@@ -506,7 +518,7 @@
                $name = $v["name"];
            }
            $list[$k]['name'] = $name;
            $list[$k]['httpUrl'] = $this->fun->stitchingPath($v['faceImg']);
            $list[$k]['faceImg'] = $this->fun->stitchingPath($v['faceImg']);
        }
        $signInSet = $this->getSignInDetails($request->orgId);
        $result = [
@@ -566,8 +578,7 @@
     * @param $orgId
     * @return array|int[]
     */
    public
    function getSignInDetails($orgId)
    public function getSignInDetails($orgId)
    {
        $_key = RedisKey::SIGN_IN_SET . '_' . $orgId;
        $res = $this->redis->get($_key);
@@ -594,8 +605,7 @@
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public
    function searchPhoneStudent(Request $request)
    public function searchPhoneStudent(Request $request)
    {
        $rule = [
            #'classCode' => 'required|integer|min:1',
@@ -607,18 +617,14 @@
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, $error);
        }
        $where = [
            'cs.orgId' => $request->orgId,
            'cs.status' => 1,
            's.phoneNumber' => $request->phone,
        ];
        if($request->type == 1)
        {
            $where = [
                'cs.classCode' => $request->classCode,
                's.phoneNumber' => $request->phone,
            ];
        }
        else
        {
            $where = [
                's.phoneNumber' => $request->phone,
            ];
            $where['cs.classCode'] = $request->classCode;
        }
        $arr = DB::table('anni_classstudent as cs')
            ->select('s.id', 's.username', 's.phoneNumber', 's.name', 's.orgId', 's.englishName', 's.faceImg')
app/Http/Controllers/Api/v1/UsreController.php
@@ -34,43 +34,43 @@
        if ($accurateRoleId == 2026){
            $List = DB::select(" select st.id,st.username,st.name,st.englishName,
                  st.phoneNumber,st.faceImg,st.headPhoto,st.courseStatus,
                  (select sum(a.classHour) from anni_attendrecord as a
                  (select sum(a.classHour) from anni_attendrecord as a
                      where a.status = 1 and a.isDelete=0 and a.username =st.username and a.classStatus in (1,5,6) ) as HourSum,
                  (select sum(b.courseHour) from anni_classstudent as a
                  (select sum(b.courseHour) from anni_classstudent as a
                      left join anni_class as b on b.classCode = a.classCode
                      where a.username = st.username and a.isDelete = 0 and b.classstatus !=2) as courseHourSum
                  from anni_students as st
                  where st.orgId = $orgId and st.isDelete = 0 and st.status = 1
                  and (st.phoneNumber like '%$soso%' or st.englishName like '%$soso%')
                  where st.orgId = $orgId and st.isDelete = 0 and st.status = 1
                  and (st.phoneNumber like '%$soso%' or st.englishName like '%$soso%' or st.username like '%$soso%')
                  ORDER BY st.id DESC limit $offset,$pageSize");
            $total = DB::select(" select st.id,st.username,st.name,st.englishName,
                  st.phoneNumber,st.faceImg,st.headPhoto,st.courseStatus
                  from anni_students as st
                  where st.orgId = $orgId and st.isDelete = 0 and st.status = 1
                  and (st.phoneNumber like '%$soso%' or st.englishName like '%$soso%')");
                  where st.orgId = $orgId and st.isDelete = 0 and st.status = 1
                  and (st.phoneNumber like '%$soso%' or st.englishName like '%$soso%' or st.username like '%$soso%')");
            $total = count($total);
        }else{
            $List = DB::select(" select distinct st.id,st.username,st.name,st.englishName,
                  st.phoneNumber,st.faceImg,st.headPhoto,st.courseStatus,
                  (select sum(a.classHour) from anni_attendrecord as a
                  (select sum(a.classHour) from anni_attendrecord as a
                      where a.status = 1 and a.isDelete=0 and a.username =st.username and a.classStatus in (1,5,6) ) as HourSum,
                  (select sum(b.courseHour) from anni_classstudent as a
                  (select sum(b.courseHour) from anni_classstudent as a
                      left join anni_class as b on b.classCode = a.classCode
                      where a.username = st.username and a.isDelete = 0 and b.classstatus !=2) as courseHourSum
                  from `anni_students` as `st`
                  left join `anni_classstudent` as `cs` on `cs`.`username` = `st`.`username`
                  left join `anni_classteachermodule` as `ct` on `ct`.`classCode` = `cs`.`classCode`
                  where `st`.`orgId` = $orgId and `st`.`isDelete` = 0 and `st`.`status` = 1 and `ct`.`UserId` = $UserId
                  and (`st`.`phoneNumber` like '%$soso%' or `st`.`englishName` like '%$soso%')
                  from `anni_students` as `st`
                  left join `anni_classstudent` as `cs` on `cs`.`username` = `st`.`username`
                  left join `anni_classteachermodule` as `ct` on `ct`.`classCode` = `cs`.`classCode`
                  where `st`.`orgId` = $orgId and `st`.`isDelete` = 0 and `st`.`status` = 1 and `ct`.`UserId` = $UserId
                  and (`st`.`phoneNumber` like '%$soso%' or `st`.`englishName` like '%$soso%' or st.username like '%$soso%')
                  ORDER BY st.id DESC limit $offset,$pageSize");
            $total = DB::select(" select distinct st.id,st.username,st.name,st.englishName,
                  st.phoneNumber,st.faceImg
                  from `anni_students` as `st`
                  left join `anni_classstudent` as `cs` on `cs`.`username` = `st`.`username`
                  left join `anni_classteachermodule` as `ct` on `ct`.`classCode` = `cs`.`classCode`
                  where `st`.`orgId` = $orgId and `st`.`isDelete` = 0 and `st`.`status` = 1 and `ct`.`UserId` = $UserId
                  and (`st`.`phoneNumber` like '%$soso%' or `st`.`englishName` like '%$soso%')");
                  from `anni_students` as `st`
                  left join `anni_classstudent` as `cs` on `cs`.`username` = `st`.`username`
                  left join `anni_classteachermodule` as `ct` on `ct`.`classCode` = `cs`.`classCode`
                  where `st`.`orgId` = $orgId and `st`.`isDelete` = 0 and `st`.`status` = 1 and `ct`.`UserId` = $UserId
                  and (`st`.`phoneNumber` like '%$soso%' or `st`.`englishName` like '%$soso%' or st.username like '%$soso%')");
            $total = count($total);
        }
        foreach ($List as $k=>$v){
@@ -108,9 +108,9 @@
        $soso = $request->input('soso');#搜搜
        $faceStatus = $request->input('faceStatus');#录入状态 1 未录入 2 已录入  0 全部
        if ($faceStatus == 1){
            $where[] = ['faceImg','=',null];
            $where[] = ['faceImg','=',''];
        }elseif ($faceStatus == 2){
            $where[] = ['faceImg','!=',null];
            $where[] = ['faceImg','!=',''];
        }
        $where['orgId'] = $orgId;
        $where['isDelete'] = 0;
@@ -157,7 +157,7 @@
        $info = DB::table('anni_students')
            ->select('id','username','name','englishName',
                'phoneNumber','faceImg','headPhoto','courseStatus',
                'createTime')
                'createTime','sex')
            ->where($where)
            ->first();
        #统计已上总课时
@@ -230,4 +230,4 @@
        return $this->_response($List);
    }
}
}
app/Library/ALiYunFace.php
@@ -143,11 +143,12 @@
            ]
        ];
        $arr = $this->openApiRequest($data);
        if($arr['status']!=1) {
            return false;
        }
        $label = $arr['data']['Data']['Elements'][0]['Results'][0]['Label'];
        if($label=="liveness") {
        if($label!="liveness") {
           return  false;
        }
        return  true;