liumiao
2021-01-25 540be6af370073e5127e40f801509053d78b6cf8
Merge remote-tracking branch 'origin/master'
3 files modified
105 ■■■■ changed files
app/Http/Controllers/Api/v1/FaceController.php 80 ●●●● patch | view | raw | blame | history
app/Library/ALiYunFace.php 20 ●●●● patch | view | raw | blame | history
routes/api.php 5 ●●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/FaceController.php
@@ -78,7 +78,7 @@
        $where = [
            'id' => $request->studentId
        ];
        $faceImg = 'https://face.anniekids.com' . $request->httpUrl;
        $faceImg = $request->httpUrl;
        $res = StudentsModel::where($where)->update(['faceImg' => $faceImg]);
        if($res)
        {
@@ -113,7 +113,7 @@
            return $this->_response([], ResponseCode::SUCCESS, '未录入人脸无法比对');
        }
        $path = SHANGHAI_HTTPS . $info->httpUrl;
        $path = SHANGHAI_HTTPS . $info->faceImg;
        $httpUrl = SHANGHAI_HTTPS . $request->httpUrl;
        $res = $this->checkFace($httpUrl);
        if($res != 'success')
@@ -169,7 +169,7 @@
        $where = [
            'UserId' => $arr[1],
        ];
        $info = UsersModel::select('UserId', 'RealCnName')->where($where)->first();
        $info = UsersModel::    select('UserId', 'RealCnName')->where($where)->first();
        $result = [
            'info' => $info,
        ];
@@ -306,8 +306,14 @@
        if($request->type == 1)
        {
            $faceObj = new ALiYunFace();
            $path = SHANGHAI_HTTPS . $request->httpUrl;
            $res = $faceObj->SearchFace($path);
            $httpUrl = SHANGHAI_HTTPS . $request->httpUrl;
            $res = $this->checkFace($httpUrl);
            if($res != 'success')
            {
                return $res;
            }
            $res = $faceObj->SearchFace($httpUrl);
            if($res['status'] != 1)
            {
                return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到该用户人脸');
@@ -315,14 +321,14 @@
            if(!isset($res['data']['Data']['MatchList']) || count($res['data']['Data']['MatchList']) == 0)
            {
                return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到该用户人脸');
                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.98)
             {
                 return $this->_response([], ResponseCode::PARAM_ERROR, '人脸比较模糊,请重新拍摄');
             }*/
            $score = $res['data']['Data']['MatchList'][0]['FaceItems'][0]['Score'];
            if($score < 0.5)
            {
                return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到该用户人脸信息');
            }
            $entityIdArr = explode('_', $entityId);
            $studentId = $entityIdArr[1];
            $username = $entityIdArr[2];
@@ -332,6 +338,16 @@
            $studentId = $request->studentId;
            $username = $request->username;
        }
        $where = [
            'id' => $studentId
        ];
        $info = StudentsModel::where($where)->select('id', 'faceImg')->first();
        if(empty($info->faceImg))
        {
            return $this->_response([], ResponseCode::SUCCESS, '未录入人脸');
        }
        $where = [
            'studentId' => $studentId,
            'username' => $username,
@@ -398,6 +414,19 @@
            ->get()->toArray();
        foreach($list as $k => $v)
        {
            if($v["englishName"] && $v["name"])
            {
                $name = $v["englishName"] . "(" . $v["name"] . ")";
            }
            elseif($v["englishName"] && !$v["name"])
            {
                $name = $v["englishName"];
            }
            else
            {
                $name = $v["name"];
            }
            $list[$k]['name'] = $name;
            $list[$k]['httpUrl'] = FACE_PATH . $v['faceImg'];
        }
        $signInSet = $this->getSignInDetails($request->orgId);
@@ -486,10 +515,8 @@
    public function searchPhoneStudent(Request $request)
    {
        $rule = [
            'orgId' => 'required|integer|min:1',
            'classCode' => 'required|integer|min:1',
            'phone' => 'required|string',
            #'classNumber' => 'required|integer|min:1',
        ];
        $error = $this->_validate($request, $rule);
        if(!empty($error))
@@ -500,14 +527,31 @@
            'cs.classCode' => $request->classCode,
            's.phoneNumber' => $request->phone,
        ];
        $info = DB::table('anni_classstudent as cs')
            ->select('s.id', 's.username', 's.headPhoto', 's.phoneNumber', 's.name', 's.orgId', 's.englishName')
        $arr = DB::table('anni_classstudent as cs')
            ->select('s.id', 's.username', 's.phoneNumber', 's.name', 's.orgId', 's.englishName', 's.faceImg')
            ->leftJoin('anni_students as s', 's.username', '=', 'cs.username')
            ->where($where)
            ->first();
        $info['httpUrl'] = $this->fun->stitchingPath($info['headPhoto']);
            ->get()->toArray();
        foreach($arr as $k => $v)
        {
            if($v["englishName"] && $v["name"])
            {
                $name = $v["englishName"] . "(" . $v["name"] . ")";
            }
            elseif($v["englishName"] && !$v["name"])
            {
                $name = $v["englishName"];
            }
            else
            {
                $name = $v["name"];
            }
            $arr[$k]['name'] = $name;
            $arr[$k]['faceImg'] = $this->fun->stitchingPath($v['faceImg']);
        }
        $result = [
            'info' => $info
            'info' => $arr
        ];
        return $this->_response($result, ResponseCode::SUCCESS, '学员');
    }
app/Library/ALiYunFace.php
@@ -19,7 +19,7 @@
     * @param null $labels
     * @return array
     */
    public function AddFaceEntity($entityId,$labels=null) {
    public function AddFaceEntity($entityId,$labels=null,$dbname='students') {
        $data = [
            'product' => 'facebody',
            'version' => '2019-12-30',
@@ -28,7 +28,7 @@
            'options' => [
                'query' => [
                    'RegionId' => "cn-shanghai",
                    'DbName' => 'default',
                    'DbName' => $dbname,
                    'EntityId' => $entityId,
                    'Labels' => $labels
                ],
@@ -43,7 +43,7 @@
     * @param $imgUrl
     * @return array
     */
    public  function AddFace($entityId,$imgUrl) {
    public  function AddFace($entityId,$imgUrl, $dbname='students') {
        $data = [
            'product' => 'facebody',
            'version' => '2019-12-30',
@@ -52,7 +52,7 @@
            'options' => [
                'query' => [
                    'RegionId' => "cn-shanghai",
                    'DbName' => "default",
                    'DbName' => $dbname,
                    'ImageUrl' => $imgUrl,
                    'EntityId' => $entityId
                ],
@@ -66,7 +66,7 @@
     * @param $entityId
     * @return array
     */
    public function GetFaceEntity($entityId) {
    public function GetFaceEntity($entityId,$dbname='students') {
        $data = [
            'product' => 'facebody',
            'version' => '2019-12-30',
@@ -75,7 +75,7 @@
            'options' => [
                'query' => [
                    'RegionId' => "cn-shanghai",
                    'DbName' => "default",
                    'DbName' => $dbname,
                    'EntityId' => $entityId
                ],
            ]
@@ -88,7 +88,7 @@
     * @param $id
     * @return array
     */
    public function DeleteFace($id) {
    public function DeleteFace($id,$dbname='students') {
        $data = [
            'product' => 'facebody',
            'version' => '2019-12-30',
@@ -97,7 +97,7 @@
            'options' => [
                'query' => [
                    'RegionId' => "cn-shanghai",
                    'DbName' => "default",
                    'DbName' => $dbname,
                    'FaceId' => $id,
                ],
            ]
@@ -189,7 +189,7 @@
     * @param $httpUrl
     * @return array|false
     */
    public function SearchFace($httpUrl) {
    public function SearchFace($httpUrl,$dbname='students') {
        $data = [
            'product' => 'facebody',
            'version' => '2019-12-30',
@@ -200,7 +200,7 @@
                    'RegionId' => "cn-shanghai",
                    'ImageUrl' => $httpUrl,
                    'Limit' => 1,
                    'DbName' => 'default',
                    'DbName' => $dbname,
                ],
            ]
        ];
routes/api.php
@@ -72,6 +72,11 @@
        $api->post('/ClassSchedule/getHumanFaceSignInList', 'ClassScheduleController@humanFaceSignInList');         //人脸打卡list
        /*******************************  end  lium ****************************************/
        /******************************* start Cuiyb ****************************************/
        $api->post('/Usre/userList', 'UsreController@userList');#学员列表
        $api->post('/Usre/myUserList', 'UsreController@myUserList');#我的-学员列表
        /******************************* end Cuiyb ****************************************/
    });
});