liumiao
2021-01-26 4c53adbf77a5e0401f643867b8a1ae4fab6f6939
Merge remote-tracking branch 'origin/master'
1 files modified
156 ■■■■ changed files
app/Http/Controllers/Api/v1/FaceController.php 156 ●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/FaceController.php
@@ -229,32 +229,68 @@
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, $error);
        }
        $paramArr = json_encode($request->paramJson);
        $data = [];
        $paramArr = json_decode($request->paramJson, true);
        foreach($paramArr as $k => $v)
        {
            $data[] = [
            $where = [
                'studentId' => $request->studentId,
                'username' => $request->username,
                'faceImg' => $request->httpUrl,
                'teacherId' => $request->teacherId,
                'classCode' => $v['classCode'],
                'classNumber' => $v['classNumber'],
                'contentTime' => $v['contentTime'],
                'type' => 2,
                'dates' => $request->dates,
                'orgId' => $request->orgId,
                'createdTime' => date('Y-m-d H:i:s'),
            ];
        }
        if(count($data) == 0)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '传值有误');
        }
        $res = FaceAttendanceModel::insert($data);
        if(!$res)
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '补录失败');
            $info = FaceAttendanceModel::where($where)->first();
            if(!$info)
            {
                DB::beginTransaction(); //开启事务
                try
                {
                    $data = [
                        'studentId' => $request->studentId,
                        'username' => $request->username,
                        'faceImg' => $request->httpUrl,
                        'teacherId' => $request->teacherId,
                        'classCode' => $v['classCode'],
                        'classNumber' => $v['classNumber'],
                        'contentTime' => $v['contentTime'],
                        'type' => 3,
                        'dates' => $request->dates,
                        'orgId' => $request->orgId,
                        'createdTime' => date('Y-m-d H:i:s'),
                    ];
                    $res = FaceAttendanceModel::insert($data);
                    $attendrecordData = [
                        'orgId' => $request->orgId,
                        'staffId' => $request->teacherId,
                        'username' => $request->username,
                        'classNumber' => $v['classNumber'],
                        'classHour' => $v['classHour'],
                        'className' => $v['className'],
                        'classCode' => $v['classCode'],
                        'sectionid' => '',
                        'createTime' => date('Y-m-d H:i:s'),
                        'updateTime' => date('Y-m-d H:i:s'),
                        'describe' => '人工补录',
                        'remark' => '',
                        'status' => 1,
                        'isDelete' => 0,
                        'classStatus' => 1,
                        'repairTime' => '',
                    ];
                    DB::table('anni_attendrecord')->insert($attendrecordData);
                }
                catch (Exception $e)
                {
                    DB::rollBack();
                }
            }
        }
        return $this->_response([], ResponseCode::SUCCESS, '补录成功');
@@ -265,7 +301,8 @@
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function punchTheClock(Request $request)
    public
    function punchTheClock(Request $request)
    {
        $rule = [
            'httpUrl' => 'required|string',
@@ -273,8 +310,10 @@
            'classCode' => 'required|integer|min:1',
            'contentTime' => 'required|string',
            'classNumber' => 'required|string',
            'className' => 'required|string',
            'orgId' => 'required|integer|min:1',
            'type' => 'required|integer|min:1',
            'classHour' => 'required|integer|min:1',
        ];
        $error = $this->_validate($request, $rule);
        if(!empty($error))
@@ -332,11 +371,13 @@
            $entityIdArr = explode('_', $entityId);
            $studentId = $entityIdArr[1];
            $username = $entityIdArr[2];
            $describe = '人脸签到';
        }
        else
        {
            $studentId = $request->studentId;
            $username = $request->username;
            $describe = '手机号补录';
        }
        $where = [
@@ -362,23 +403,51 @@
            return $this->_response([], ResponseCode::PARAM_ERROR, '已签到,请勿重复签到');
        }
        $data = [
            'studentId' => $studentId,
            'faceImg' => $request->httpUrl,
            'teacherId' => $request->teacherId,
            'classCode' => $request->classCode,
            'classNumber' => $request->classNumber,
            'contentTime' => $request->contentTime,
            'type' => $request->type,
            'dates' => $request->dates,
            'orgId' => $request->orgId,
            'createdTime' => date('Y-m-d H:i:s'),
        ];
        $res = FaceAttendanceModel::insert($data);
        if(!$res)
        DB::beginTransaction(); //开启事务
        try
        {
            return $this->_response([], ResponseCode::PARAM_ERROR, '签到失败');
            $data = [
                'studentId' => $studentId,
                'faceImg' => $request->httpUrl,
                'teacherId' => $request->teacherId,
                'classCode' => $request->classCode,
                'classNumber' => $request->classNumber,
                'contentTime' => $request->contentTime,
                'type' => $request->type,
                'dates' => $request->dates,
                'orgId' => $request->orgId,
                'createdTime' => date('Y-m-d H:i:s'),
            ];
            $res = FaceAttendanceModel::insert($data);
            $attendrecordData = [
                'orgId' => $request->orgId,
                'staffId' => $request->teacherId,
                'username' => $request->username,
                'classNumber' => $request->classNumber,
                'classHour' => $request->classHour,
                'className' => $request->className,
                'classCode' => $request->classCode,
                'sectionid' => '',
                'createTime' => date('Y-m-d H:i:s'),
                'updateTime' => date('Y-m-d H:i:s'),
                'describe' => $describe,
                'remark' => '',
                'status' => 1,
                'isDelete' => 0,
                'classStatus' => 1,
                'repairTime' => '',
            ];
            DB::table('anni_attendrecord')->insert($attendrecordData);
        }
        catch (Exception $e)
        {
            DB::rollBack();
        }
        return $this->_response([], ResponseCode::SUCCESS, '签到成功');
    }
@@ -387,7 +456,8 @@
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function attendanceList(Request $request)
    public
    function attendanceList(Request $request)
    {
        $rule = [
            'dates' => 'required|string',
@@ -407,7 +477,7 @@
            'fa.orgId' => $request->orgId
        ];
        $list = DB::table('anni_face_attendance as fa')
            ->select('s.orgId', 's.username', 's.name', 's.englishName', 's.faceImg', 'fa.createdTime', 'fa.classNumber', 'fa.contentTime')
            ->select('s.orgId', 's.username', 's.name', 's.englishName', 's.faceImg', 'fa.createdTime', 'fa.classNumber', 'fa.contentTime', 'fa.type')
            ->leftJoin('anni_students as s', 'fa.studentId', '=', 's.id')
            ->where($where)
            ->orderBy('fa.createdTime', 'desc')
@@ -427,7 +497,7 @@
                $name = $v["name"];
            }
            $list[$k]['name'] = $name;
            $list[$k]['httpUrl'] = FACE_PATH . $v['faceImg'];
            $list[$k]['httpUrl'] = $this->fun->stitchingPath($v['faceImg']);
        }
        $signInSet = $this->getSignInDetails($request->orgId);
        $result = [
@@ -442,7 +512,8 @@
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function signInSet(Request $request)
    public
    function signInSet(Request $request)
    {
        $rule = [
            'lastMinute' => 'required|integer|min:1',
@@ -466,7 +537,8 @@
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function signInDetails(Request $request)
    public
    function signInDetails(Request $request)
    {
        $rule = [
            'orgId' => 'required|integer|min:1',
@@ -485,7 +557,8 @@
     * @param $orgId
     * @return array|int[]
     */
    public function getSignInDetails($orgId)
    public
    function getSignInDetails($orgId)
    {
        $_key = RedisKey::SIGN_IN_SET . '_' . $orgId;
        $res = $this->redis->get($_key);
@@ -512,7 +585,8 @@
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function searchPhoneStudent(Request $request)
    public
    function searchPhoneStudent(Request $request)
    {
        $rule = [
            #'classCode' => 'required|integer|min:1',
@@ -557,7 +631,7 @@
                $name = $v["name"];
            }
            $arr[$k]['name'] = $name;
            $arr[$k]['studentId']= $v['id'];
            $arr[$k]['studentId'] = $v['id'];
            $arr[$k]['faceImg'] = $this->fun->stitchingPath($v['faceImg']);
        }