liumiao
2021-01-29 d506eac55087ffd31f6b6fe7a2424026a800d874
Merge remote-tracking branch 'origin/master'

# Conflicts:
# app/Http/Controllers/Api/v1/ClassScheduleController.php
3 files modified
138 ■■■■ changed files
app/Http/Controllers/Api/v1/ClassScheduleController.php 38 ●●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/FaceController.php 94 ●●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/UsreController.php 6 ●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/ClassScheduleController.php
@@ -299,8 +299,8 @@
            }
            $csVal["name"] = $name;
            $csVal["signInType"] = $csVal["signInType"] > 0 ? $csVal["signInType"] : 0;
            $csVal["headPhoto"] = $this->fun->getFacePath($csVal["headPhoto"]);
            $csVal["faceImg"] = $this->fun->getFacePath($csVal["faceImg"]);
            $csVal["headPhoto"] = $this->fun->stitchingPath($csVal["headPhoto"]);
            $csVal["faceImg"] = $this->fun->stitchingPath($csVal["faceImg"]);
            $csVal["createdTime"] = !empty($csVal["createdTime"]) ? substr($csVal["createdTime"], 11, 16) : '';
            $classMap[] = $csVal;
        }
@@ -395,10 +395,8 @@
        }
        $classCodeArr = [];
        $homeTeacherId = [];
        $staffIdArr = [];
        foreach($list as $lVal)
        {
            $staffIdArr[] = $lVal["staffId"];
            $classCodeArr[] = $lVal["classCode"];
            $homeTeacherId[] = $lVal["hometeacherId"];
        }
@@ -420,10 +418,6 @@
        //获取人脸签到
        $faceList = $this->getFaceList($classCodeArr);
        //获取面授班级教师
        $staffUser = $this->getStaffUser($staffIdArr);
        $mapList = [];
        foreach($list as $val)
        {
@@ -446,17 +440,7 @@
                        break;
                }
            }
            if($val["staffId"] > 0)
            {
                $teacherName = !empty($staffUser[$val["staffId"]]) ? $staffUser[$val["staffId"]] : '';
            }
            else
            {
                $teacherName = !empty($teacherName[$val["classCode"] . '-' . $val['classNumber']]) ? implode(",", array_values(array_unique($teacherName[$val["classCode"] . '-' . $val['classNumber']]))) : '';
            }
            $val["teacherName"] = $teacherName;//教师名字
            $val["teacherName"] = !empty($teacherName[$val["classCode"] . '-' . $val['classNumber']]) ? implode(",", array_values(array_unique($teacherName[$val["classCode"] . '-' . $val['classNumber']]))) : '';//教师名字
            $val["homeBakers"] = !empty($homeTeacherList[$val["hometeacherId"]]) ? $homeTeacherList[$val["hometeacherId"]] : ''; //家培师名字
            $val["notNum"] = $classStudentsNum ? ($classStudentsNum - $signIn > 0 ? $classStudentsNum - $signIn : 0) : 0; //未签到
            $val["checkedInNum"] = count($recordList);//签到
@@ -580,22 +564,6 @@
        }
        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;
    }
    /**
app/Http/Controllers/Api/v1/FaceController.php
@@ -18,12 +18,16 @@
use App\Models\UsersModel;
use Carbon\Carbon;
use Illuminate\Http\Request;
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url;
use Validator;
use Illuminate\Support\Facades\DB;
class FaceController extends ApiController
{
    public function getFaceUrl($httpUrl) {
        return SHANGHAI_HTTPS . $httpUrl."?x-oss-process=style/thumb";
    }
    /**
     * 注册人脸
     * @param Request $request
@@ -44,7 +48,7 @@
        }
        $faceObj = new ALiYunFace();
        $path = SHANGHAI_HTTPS . $request->httpUrl;
        $path = $this->getFaceUrl( $request->httpUrl);
        $res = $this->checkFace($path);
        if($res != 'success')
@@ -61,9 +65,10 @@
            {
                return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到用户人脸');
            }
            if(isset($res['data']['Data']['MatchList'][0]['FaceItems'][0]['Score'])) {
            if(isset($res['data']['Data']['MatchList'][0]['FaceItems'][0]['Score']))
            {
                $score = $res['data']['Data']['MatchList'][0]['FaceItems'][0]['Score'];
                if($score > 0.6)
                if($score > 0.65)
                {
                    return $this->_response([], ResponseCode::PARAM_ERROR, '人脸已存在,请更改');
                }
@@ -130,8 +135,8 @@
            return $this->_response([], ResponseCode::SUCCESS, '未录入人脸无法比对');
        }
        $path = SHANGHAI_HTTPS . $info->faceImg;
        $httpUrl = SHANGHAI_HTTPS . $request->httpUrl;
        $path = $this->getFaceUrl( $info->faceImg);
        $httpUrl = $this->getFaceUrl( $request->httpUrl);
        $res = $this->checkFace($httpUrl);
        if($res != 'success')
        {
@@ -145,55 +150,6 @@
        }
        return $this->_response([], ResponseCode::SUCCESS, '比对成功');
    }
    /**
     * 获取人脸
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getFaceInfo(Request $request)
    {
        $rule = [
            'httpUrl' => 'required|string',
        ];
        $error = $this->_validate($request, $rule);
        if(!empty($error))
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, $error);
        }
        $faceObj = new ALiYunFace();
        $path = SHANGHAI_HTTPS . $request->httpUrl;
        $res = $faceObj->SearchFace($path, 'default');
        #print_r($res);
        #die;
        if($res['status'] != 1)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到用户人脸');
        }
        if(!isset($res['data']['Data']['MatchList']) || count($res['data']['Data']['MatchList']) == 0)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到用户人脸');
        }
        $entityId = $res['data']['Data']['MatchList'][0]['FaceItems'][0]['EntityId'];
        $score = $res['data']['Data']['MatchList'][0]['FaceItems'][0]['Score'];
        if($score < 0.6)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '人脸识别率太低或更换注册人脸后请重新拍摄');
        }
        if($score)
            $arr = explode('_', $entityId);
        $where = [
            'UserId' => $arr[1],
        ];
        $info = UsersModel::    select('UserId', 'RealCnName')->where($where)->first();
        $result = [
            'info' => $info,
        ];
        return $this->_response($result, ResponseCode::SUCCESS, '登录成功');
    }
    /**
     * 检测人脸
@@ -376,7 +332,7 @@
        $timeEnd = $request->dates . ' ' . $classNumberArr[1];
        if($signInSet['lastMinute'] != 0 && $signInSet['nextMinute'] != 0)
        {
            $beginsTime = $request->dates . ' ' . date("H:i", strtotime("$classNumberArr[0] +" . $signInSet['lastMinute'] . " min"));
            $beginsTime = $request->dates . ' ' . date("H:i", strtotime("$classNumberArr[0] -" . $signInSet['lastMinute'] . " min"));
            $timeEnd = $request->dates . ' ' . date("H:i", strtotime("$classNumberArr[1] +" . $signInSet['nextMinute'] . " min"));
            $timeStatus = $this->get_time($beginsTime, $timeEnd);
        }
@@ -387,7 +343,7 @@
        }
        else if($signInSet['lastMinute'] != 0 && $signInSet['nextMinute'] == 0)
        {
            $beginsTime = $request->dates . ' ' . date("H:i", strtotime("$classNumberArr[0] +" . $signInSet['lastMinute'] . " min"));
            $beginsTime = $request->dates . ' ' . date("H:i", strtotime("$classNumberArr[0] -" . $signInSet['lastMinute'] . " min"));
            $timeStatus = $this->get_time($beginsTime, $timeEnd);
        }
        else
@@ -400,9 +356,10 @@
            return $this->_response([], ResponseCode::PARAM_ERROR, '签到失败,不在排课时间范围');
        }
        $faceObj = new ALiYunFace();
        $httpUrl = $this->getFaceUrl( $request->httpUrl);
        if($request->type == 1)
        {
            $httpUrl = SHANGHAI_HTTPS . $request->httpUrl;
            $res = $this->checkFace($httpUrl);
            if($res != 'success')
            {
@@ -421,7 +378,7 @@
            }
            $entityId = $res['data']['Data']['MatchList'][0]['FaceItems'][0]['EntityId'];
            $score = $res['data']['Data']['MatchList'][0]['FaceItems'][0]['Score'];
            if($score < 0.8)
            if($score < 0.65)
            {
                return $this->_response([], ResponseCode::PARAM_ERROR, '人脸识别率太低或更换注册人脸后请重新拍摄');
            }
@@ -432,7 +389,6 @@
        }
        else
        {
            $httpUrl = SHANGHAI_HTTPS . $request->httpUrl;
            $res = $this->checkFace($httpUrl, 2);
            if($res != 'success')
            {
@@ -447,7 +403,19 @@
            'username' => $username,
            'classCode' => $request->classCode,
        ];
        $userInfo = StudentsModel::where(['id' => $studentId])->select("id", "name")->first();
        $userInfo = StudentsModel::where(['id' => $studentId])->select("id", "name", "faceImg")->first();
        if(!$userInfo)
        {
            return $this->_response([], ResponseCode::SUCCESS, $userInfo['name'] . '未注册人脸无法打卡');
        }
        if($request->type == 1)
        {
            $path = $this->getFaceUrl( $userInfo['faceImg']);
            $comStatus = $faceObj->CompareFace($path,$httpUrl);
            if(!$comStatus) {
                return $this->_response([], ResponseCode::SUCCESS, $userInfo['name'] . '人脸比对失败,请重新拍摄');
            }
        }
        $res = DB::table('anni_classstudent')->where($where)->first();
@@ -550,6 +518,7 @@
            'fa.dates' => $request->dates,
            'fa.classCode' => $request->classCode,
            'fa.classNumber' => $request->classNumber,
            'fa.courseTableId' => $request->courseTableId,
            'fa.orgId' => $request->orgId
        ];
        $list = DB::table('anni_face_attendance as fa')
@@ -573,7 +542,7 @@
                $name = $v["name"];
            }
            $list[$k]['name'] = $name;
            $list[$k]['faceImg'] = $this->fun->stitchingPath($v['faceImg']);
            $list[$k]['faceImg'] = $this->fun->getFacePath($v['faceImg']);
        }
        $signInSet = $this->getSignInDetails($request->orgId);
        $result = [
@@ -612,8 +581,7 @@
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public
    function signInDetails(Request $request)
    public function signInDetails(Request $request)
    {
        $rule = [
            'orgId' => 'required|integer|min:1',
app/Http/Controllers/Api/v1/UsreController.php
@@ -76,7 +76,7 @@
        foreach ($List as $k=>$v){
            $List[$k]['name'] = $v['englishName'].'('.$v['name'].')';
            if (!empty($v['faceImg'])){
                $List[$k]['faceImg'] = $this->fun->stitchingPath($v['faceImg']);
                $List[$k]['faceImg'] = $this->fun->getFacePath($v['faceImg']);
            }else{
                $List[$k]['faceImg'] = $this->fun->stitchingPath($v['headPhoto']);
            }
@@ -126,7 +126,7 @@
        foreach ($List as $k=>$v){
            $List[$k]['name'] = $v['englishName'].'('.$v['name'].')';
            if (!empty($v['faceImg'])){
                $List[$k]['faceImg'] = $this->fun->stitchingPath($v['faceImg']);
                $List[$k]['faceImg'] = $this->fun->getFacePath($v['faceImg']);
            }
        }
        $total = DB::table('anni_students')->where($where)
@@ -176,7 +176,7 @@
            ->sum('b.courseHour');
        $info['name'] = $info['englishName'].'('.$info['name'].')';
        if (!empty($info['faceImg'])){
            $info['faceImg'] = $this->fun->stitchingPath($info['faceImg']);
            $info['faceImg'] = $this->fun->getFacePath($info['faceImg']);
        }else{
            $info['faceImg'] = $this->fun->stitchingPath($info['headPhoto']);
        }