xielin 5 éve
szülő
commit
08ff661819
1 módosított fájl, 29 hozzáadás és 16 törlés
  1. 29 16
      app/Repositories/Circle/CircleRepository.php

+ 29 - 16
app/Repositories/Circle/CircleRepository.php

@@ -74,28 +74,41 @@ class CircleRepository
             return jsonError('您已经加入该圈子了', ['answer_count' => 0]);
         }
         $circle = $this->interestCircle->where('id', $request['id'])->first();
+        $limitCount = 0;
         if ($circle->join_limit) {
-            $key = 'circle_error_count_' . $userInfo['uid'];
-            $errorCount = Redis::get($key);
-            if ($errorCount >= $circle->limit_condition) {
-                return jsonError('今日次数已用完,明天再来吧', ['answer_count' => 0]);
-            }
-            if (empty($request['answer'])) {
-                return jsonError('请输入答案~', ['answer_count' => intval($circle->limit_condition)]);
+            if($circle->limit_condition){
+                $key = 'circle_error_count_' . $userInfo['uid'];
+                $errorCount = Redis::get($key);
+                if ($errorCount >= $circle->limit_condition) {
+                    return jsonError('今日次数已用完,明天再来吧', ['answer_count' => 0]);
+                }
+                if (empty($request['answer'])) {
+                    return jsonError('请输入答案~', ['answer_count' => intval($circle->limit_condition)-$errorCount]);
+                }
+            }else{
+                $limitCount = -1;
+                if (empty($request['answer'])) {
+                    return jsonError('请输入答案~', ['answer_count' => $limitCount]);
+                }
             }
             $question = json_decode($circle->join_question, true);
             $answer = json_decode($request['answer'], true);
             $checkRow = $this->checkQuestion($question, $answer);
             if (!$checkRow) {
-                if (!$errorCount) {
-                    Redis::set($key, 1);
-                    $expire = Carbon::today()->endOfDay()->timestamp - Carbon::now()->timestamp;
-                    Redis::expire($key, $expire);
-                } else {
-                    Redis::incr($key);
+                if($circle->limit_condition){
+                    if (!$errorCount) {
+                        Redis::set($key, 1);
+                        $expire = Carbon::today()->endOfDay()->timestamp - Carbon::now()->timestamp;
+                        Redis::expire($key, $expire);
+                    } else {
+                        Redis::incr($key);
+                    }
+                    $answerCount = intval($circle->limit_condition - Redis::get($key));
+                }else{
+                    $answerCount = -1;
                 }
-                $answerCount = intval($circle->limit_condition - Redis::get($key));
-                if ($answerCount <= 0) {
+
+                if ($answerCount == 0) {
                     return jsonError('学习学习,明天再来吧~', ['answer_count' => $answerCount]);
                 } else {
                     return jsonError('真遗憾,没有答对哦~', ['answer_count' => $answerCount]);
@@ -114,7 +127,7 @@ class CircleRepository
             return jsonSuccess();
         } catch (QueryException $exception) {
             DB::rollBack();
-            return jsonError('加入圈子失败,再试试吧', ['answer_count' => 0]);
+            return jsonError('加入圈子失败,再试试吧', ['answer_count' => $limitCount]);
         }
 
     }