|
@@ -74,28 +74,41 @@ class CircleRepository
|
|
return jsonError('您已经加入该圈子了', ['answer_count' => 0]);
|
|
return jsonError('您已经加入该圈子了', ['answer_count' => 0]);
|
|
}
|
|
}
|
|
$circle = $this->interestCircle->where('id', $request['id'])->first();
|
|
$circle = $this->interestCircle->where('id', $request['id'])->first();
|
|
|
|
+ $limitCount = 0;
|
|
if ($circle->join_limit) {
|
|
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);
|
|
$question = json_decode($circle->join_question, true);
|
|
$answer = json_decode($request['answer'], true);
|
|
$answer = json_decode($request['answer'], true);
|
|
$checkRow = $this->checkQuestion($question, $answer);
|
|
$checkRow = $this->checkQuestion($question, $answer);
|
|
if (!$checkRow) {
|
|
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]);
|
|
return jsonError('学习学习,明天再来吧~', ['answer_count' => $answerCount]);
|
|
} else {
|
|
} else {
|
|
return jsonError('真遗憾,没有答对哦~', ['answer_count' => $answerCount]);
|
|
return jsonError('真遗憾,没有答对哦~', ['answer_count' => $answerCount]);
|
|
@@ -114,7 +127,7 @@ class CircleRepository
|
|
return jsonSuccess();
|
|
return jsonSuccess();
|
|
} catch (QueryException $exception) {
|
|
} catch (QueryException $exception) {
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
- return jsonError('加入圈子失败,再试试吧', ['answer_count' => 0]);
|
|
|
|
|
|
+ return jsonError('加入圈子失败,再试试吧', ['answer_count' => $limitCount]);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|