|
@@ -54,7 +54,7 @@ class CircleRepository
|
|
|
if ($isTrashed) {
|
|
|
$model->withTrashed();
|
|
|
}
|
|
|
- $this->interestCircle->where('id',$request['id'])->increment('view_count');
|
|
|
+ $this->interestCircle->where('id', $request['id'])->increment('view_count');
|
|
|
return $model->find($request['id']);
|
|
|
}
|
|
|
|
|
@@ -71,17 +71,17 @@ class CircleRepository
|
|
|
->where('circle_id', $request['id'])
|
|
|
->first();
|
|
|
if ($row) {
|
|
|
- return jsonError('您已经加入该圈子了');
|
|
|
+ return jsonError('您已经加入该圈子了', ['answer_count' => 0]);
|
|
|
}
|
|
|
$circle = $this->interestCircle->where('id', $request['id'])->first();
|
|
|
if ($circle->join_limit) {
|
|
|
$key = 'circle_error_count_' . $userInfo['uid'];
|
|
|
$errorCount = Redis::get($key);
|
|
|
if ($errorCount >= $circle->limit_condition) {
|
|
|
- return jsonError('今日次数已用完,明天再来吧');
|
|
|
+ return jsonError('今日次数已用完,明天再来吧', ['answer_count' => 0]);
|
|
|
}
|
|
|
if (empty($request['answer'])) {
|
|
|
- return jsonError('请输入答案~');
|
|
|
+ return jsonError('请输入答案~', ['answer_count' => intval($circle->limit_condition)]);
|
|
|
}
|
|
|
$question = json_decode($circle->join_question, true);
|
|
|
$answer = json_decode($request['answer'], true);
|
|
@@ -94,13 +94,19 @@ class CircleRepository
|
|
|
} else {
|
|
|
Redis::incr($key);
|
|
|
}
|
|
|
- return jsonError('学习学习,明天再来吧~');
|
|
|
+ $answerCount = intval($circle->limit_condition - Redis::get($key));
|
|
|
+ if ($answerCount <= 0) {
|
|
|
+ return jsonError('学习学习,明天再来吧~', ['answer_count' => $answerCount]);
|
|
|
+ } else {
|
|
|
+ return jsonError('真遗憾,没有答对哦~', ['answer_count' => $answerCount]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
$this->interestCircleUser->create(['uid' => $userInfo['uid'], 'circle_id' => $request['id']]);
|
|
|
- $this->interestCircle->where('id',$request['id'])->increment('join_count');
|
|
|
+ $this->interestCircle->where('id', $request['id'])->increment('join_count');
|
|
|
DB::commit();
|
|
|
//加入圈子成功后,清除错误回答次数
|
|
|
$key = 'circle_error_count_' . $userInfo['uid'];
|
|
@@ -108,7 +114,7 @@ class CircleRepository
|
|
|
return jsonSuccess();
|
|
|
} catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- return jsonError('加入圈子失败,再试试吧');
|
|
|
+ return jsonError('加入圈子失败,再试试吧', ['answer_count' => 0]);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -164,7 +170,7 @@ class CircleRepository
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
$info->delete();
|
|
|
- $this->interestCircle->where('id',$request['id'])->decrement('join_count');
|
|
|
+ $this->interestCircle->where('id', $request['id'])->decrement('join_count');
|
|
|
DB::commit();
|
|
|
//退出圈子成功后,清除错误回答次数
|
|
|
$key = 'circle_error_count_' . $userInfo['uid'];
|