liumiao
2021-01-26 4c0fe6394e763a7a49c5c5e32b7f184a5a81a009
Merge remote-tracking branch 'origin/master'
1 files added
1 files modified
266 ■■■■■ changed files
app/Http/Controllers/Api/v1/FaceController.php 33 ●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/UsreController.php 233 ●●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/FaceController.php
@@ -150,23 +150,23 @@
        $faceObj = new ALiYunFace();
        $path = SHANGHAI_HTTPS . $request->httpUrl;
        $res = $faceObj->SearchFace($path, 'default');
        print_r($res);
        die;
        #print_r($res);
        #die;
        if($res['status'] != 1)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到该用户人脸');
            return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到用户人脸');
        }
        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.5)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '识别率太低,请重新拍摄');
            return $this->_response([], ResponseCode::PARAM_ERROR, '人脸识别率太低或更换注册人脸后请重新拍摄');
        }
        if($score)
            $arr = explode('_', $entityId);
@@ -220,9 +220,7 @@
            'httpUrl' => 'required|string',
            'dates' => 'required|string',
            'username' => 'required|string',
            'classCodeJson' => 'required|string',
            'contentTimeJson' => 'required|string',
            'classNumberJson' => 'required|string',
            'paramJson' => 'required|string',
            'orgId' => 'required|integer|min:1',
            'studentId' => 'required|integer|min:1',
        ];
@@ -231,20 +229,18 @@
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, $error);
        }
        $classCodeArr = json_encode($request->classCodeJson);
        $contentTimeArr = json_encode($request->contentTimeJson);
        $classNumberArr = json_encode($request->classNumberJson);
        $paramArr = json_encode($request->paramJson);
        $data = [];
        foreach($classCodeArr as $k => $v)
        foreach($paramArr as $k => $v)
        {
            $data[] = [
                'studentId' => $request->studentId,
                'username' => $request->username,
                'faceImg' => $request->httpUrl,
                'teacherId' => $request->teacherId,
                'classCode' => $v,
                'classNumber' => isset($classNumberArr[$k]) ? $classNumberArr[$k] : '',
                'contentTime' => isset($contentTimeArr[$k]) ? $contentTimeArr[$k] : '',
                'classCode' => $v['classCode'],
                'classNumber' => $v['classNumber'],
                'contentTime' => $v['contentTime'],
                'type' => 2,
                'dates' => $request->dates,
                'orgId' => $request->orgId,
@@ -320,18 +316,18 @@
            $res = $faceObj->SearchFace($httpUrl);
            if($res['status'] != 1)
            {
                return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到该用户人脸');
                return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到人脸');
            }
            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.5)
            {
                return $this->_response([], ResponseCode::PARAM_ERROR, '未检测到该用户人脸信息');
                return $this->_response([], ResponseCode::PARAM_ERROR, '人脸识别率太低或更换注册人脸后请重新拍摄');
            }
            $entityIdArr = explode('_', $entityId);
            $studentId = $entityIdArr[1];
@@ -561,6 +557,7 @@
                $name = $v["name"];
            }
            $arr[$k]['name'] = $name;
            $arr[$k]['studentId']= $v['id'];
            $arr[$k]['faceImg'] = $this->fun->stitchingPath($v['faceImg']);
        }
app/Http/Controllers/Api/v1/UsreController.php
New file
@@ -0,0 +1,233 @@
<?php
namespace App\Http\Controllers\Api\v1;
use App\Http\Controllers\ApiController;
use App\Common\ResponseCode;
use Illuminate\Http\Request;
use Validator;
use Illuminate\Support\Facades\DB;
class UsreController extends ApiController
{
    /*
     * 学员列表
     */
    public function userList(Request $request){
        $page = (int)$request->input('page') ? :1;
        $pageSize = (int)$request->input('pageSize') ?: 10;
        $offset = ($page-1)*$pageSize;
        $rule = [
            'orgId' => 'required',
        ];
        $message = $this->_validate($request, $rule);
        if(!empty($message))
        {
            return $this->_response(null, ResponseCode::PARAM_ERROR, $message);
        }
        $orgId = $request->input('orgId');#获取馆id
        $UserId = $request->input('teacherId');#获取登陆人id
        $soso = $request->input('soso');#搜搜
        $roleId = $request->input('roleId');#身份 2026 馆长
        $accurateRoleId = strstr($roleId, '2026');
        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
                      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
                      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%')
                  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%')");
            $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
                      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
                      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%')
                  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%')");
            $total = count($total);
        }
        foreach ($List as $k=>$v){
            $List[$k]['name'] = $v['englishName'].'('.$v['name'].')';
            if (!empty($v['faceImg'])){
                $List[$k]['faceImg'] = $this->fun->stitchingPath($v['faceImg']);
            }else{
                $List[$k]['faceImg'] = $this->fun->stitchingPath($v['headPhoto']);
            }
            $List[$k]['surplusSum'] = $v['courseHourSum'] - $v['HourSum'];
        }
        $result = [];
        $result['page'] = $page;
        $result['pageSize'] = $pageSize;
        $result['total'] = $total;
        $result['list'] = $List;
        return $this->_response($result);
    }
    /*
     * 我的-学员列表
     */
    public function myUserList(Request $request){
        $page = (int)$request->input('page') ? :1;
        $pageSize = (int)$request->input('pageSize') ?: 10;
        $offset = ($page-1)*$pageSize;
        $rule = [
            'orgId' => 'required',
        ];
        $message = $this->_validate($request, $rule);
        if(!empty($message))
        {
            return $this->_response(null, ResponseCode::PARAM_ERROR, $message);
        }
        $orgId = $request->input('orgId');#馆id
        $soso = $request->input('soso');#搜搜
        $faceStatus = $request->input('faceStatus');#录入状态 1 未录入 2 已录入  0 全部
        if ($faceStatus == 1){
            $where[] = ['faceImg','=',null];
        }elseif ($faceStatus == 2){
            $where[] = ['faceImg','!=',null];
        }
        $where['orgId'] = $orgId;
        $where['isDelete'] = 0;
        $where['status'] = 1;
        $List = DB::table('anni_students')
            ->select("id",'username','name','englishName','phoneNumber','faceImg')
            ->where($where)
            ->whereRaw("concat(`phoneNumber`,`englishName`) like '%".$soso."%'")
            ->orderBy('id','desc')
            ->offset($offset)
            ->limit($pageSize)
            ->get()->toArray();
        foreach ($List as $k=>$v){
            $List[$k]['name'] = $v['englishName'].'('.$v['name'].')';
            if (!empty($v['faceImg'])){
                $List[$k]['faceImg'] = $this->fun->stitchingPath($v['faceImg']);
            }
        }
        $total = DB::table('anni_students')->where($where)
            ->whereRaw("concat(`phoneNumber`,`englishName`) like '%".$soso."%'")
            ->count();
        $result = [];
        $result['page'] = $page;
        $result['pageSize'] = $pageSize;
        $result['total'] = $total;
        $result['list'] = $List;
        return $this->_response($result);
    }
    /*
     * 学员详情
     */
    public function userInfo(Request $request){
        $rule = [
            'id' => 'required',
        ];
        $error = $this->_validate($request, $rule);
        if(!empty($error))
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, $error);
        }
        $where = [
            'id' => $request->id
        ];
        $info = DB::table('anni_students')
            ->select('id','username','name','englishName',
                'phoneNumber','faceImg','headPhoto','courseStatus',
                'createTime')
            ->where($where)
            ->first();
        #统计已上总课时
        $classStatus = array(1,5,6);
        $HourSum = DB::table('anni_attendrecord')
            ->where(array('username'=>$info['username'],'isDelete'=>0,'status'=>1))
            ->whereIn('classStatus',$classStatus)
            ->sum('classHour');
        #查询班级总课程
        $userwhere['a.username'] = $info['username'];
        $userwhere['a.isDelete'] = 0;
        $userwhere[] = ['b.classstatus', '!=', 2];
        $courseHourSum = DB::table('anni_classstudent as a')
            ->leftJoin('anni_class as b','b.classCode','=','a.classCode')
            ->where($userwhere)
            ->sum('b.courseHour');
        $info['name'] = $info['englishName'].'('.$info['name'].')';
        if (!empty($info['faceImg'])){
            $info['faceImg'] = $this->fun->stitchingPath($info['faceImg']);
        }else{
            $info['faceImg'] = $this->fun->stitchingPath($info['headPhoto']);
        }
        $info['surplusSum'] = $courseHourSum - $HourSum;
        return $this->_response($info);
    }
    /*
     * 学员班级列表
     */
    public function userClassList(Request $request){
        $date = date("Y-m-d H:i:s");
        $where['a.isDelete'] = 0;
        $username = $request->input('username');
        $where['a.username'] = $username;
        $List = DB::table('anni_classstudent as a')
            ->select('a.id','a.classCode','c.courseName','b.className','b.activationCode',
                'b.courseStatus','b.openclassTime','b.endTime','a.status')
            ->leftjoin('anni_class as b','b.classCode','=','a.classCode')
            ->leftjoin('anni_course as c','c.id','=','b.courseId')
            ->where($where)
            ->orderBy('a.id','desc')
            ->get()->toArray();
        foreach ($List as $k=>$v){
            #状态 1 等课 2 停课 3 结课  4 移除班级 5 开课
            if ($v['status'] == 0){
                $List[$k]['openingstatus'] = 4; #已移除班级
            }else{
                if($v['courseStatus'] == 1){#1 课程状态 1.正常 2.停课 3.结课
                    if ($v['openclassTime'] > $date || $v['openclassTime'] == null){
                        $List[$k]['openingstatus'] = 1;#1 等课
                    }elseif ($v['openclassTime'] < $date && ($v['endTime'] > $date || $v['endTime'] == null )){
                        $List[$k]['openingstatus'] = 5;#5 开课
                    }elseif ($v['endTime'] < $date){
                        $List[$k]['openingstatus'] = 3;#3.结课
                    }
                }else{
                    $List[$k]['openingstatus'] = $v['courseStatus']; # 2.停课 3.结课
                }
            }
            $combineordersInfo = DB::table('anni_combineorders')
                ->select('parentid')
                ->where(array('username'=>$username,'classCode'=>$v['classCode'],'isDelete'=>0))
                ->orderBy('parentid','desc')
                ->first();
            if (!empty($combineordersInfo['parentid'] > 0)){
                $List[$k]['parentStatus'] = 1;
            }else{
                $List[$k]['parentStatus'] = 0;
            }
        }
        return $this->_response($List);
    }
}