|
@@ -67,21 +67,38 @@ class CircleRepository
|
|
{
|
|
{
|
|
$row = $this->interestCircleUser
|
|
$row = $this->interestCircleUser
|
|
->where('uid', $userInfo['uid'])
|
|
->where('uid', $userInfo['uid'])
|
|
- ->where('circle_id', $request['circle_id'])
|
|
|
|
|
|
+ ->where('circle_id', $request['id'])
|
|
->first();
|
|
->first();
|
|
if ($row) {
|
|
if ($row) {
|
|
return jsonError('您已经加入该圈子了');
|
|
return jsonError('您已经加入该圈子了');
|
|
}
|
|
}
|
|
- $circle = $this->interestCircle->where('circle_id',$request['id'])->first();
|
|
|
|
- if($circle->join_limit){
|
|
|
|
- $checkRow = $this->checkQuestion($circle->join_question,$request['answer']);
|
|
|
|
- if(!$checkRow){
|
|
|
|
|
|
+ $circle = $this->interestCircle->where('id', $request['id'])->first();
|
|
|
|
+ $key = 'circle_error_count_' . $userInfo['uid'];
|
|
|
|
+ $errorCount = Redis::get($key);
|
|
|
|
+ if ($errorCount >= $circle->limit_condition) {
|
|
|
|
+ return jsonError('今日次数已用完,明天再来吧');
|
|
|
|
+ }
|
|
|
|
+ if ($circle->join_limit) {
|
|
|
|
+ if (empty($request['answer'])) {
|
|
|
|
+ return jsonError('请输入答案~');
|
|
|
|
+ }
|
|
|
|
+ $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);
|
|
|
|
+ }
|
|
return jsonError('学习学习,明天再来吧~');
|
|
return jsonError('学习学习,明天再来吧~');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
try {
|
|
try {
|
|
- $this->interestCircleUser->create(['uid' => $userInfo['uid'], 'circle_id' => $request['circle_id']]);
|
|
|
|
|
|
+ $this->interestCircleUser->create(['uid' => $userInfo['uid'], 'circle_id' => $request['id']]);
|
|
DB::commit();
|
|
DB::commit();
|
|
//加入圈子成功后,清除错误回答次数
|
|
//加入圈子成功后,清除错误回答次数
|
|
$key = 'circle_error_count_' . $userInfo['uid'];
|
|
$key = 'circle_error_count_' . $userInfo['uid'];
|
|
@@ -94,22 +111,32 @@ class CircleRepository
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private function checkQuestion($question,$answer){
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 检测答案是否正确
|
|
|
|
+ * @param $question 问题
|
|
|
|
+ * @param $answer 答案
|
|
|
|
+ * @return bool
|
|
|
|
+ */
|
|
|
|
+ private function checkQuestion($question, $answer)
|
|
|
|
+ {
|
|
$result = true;
|
|
$result = true;
|
|
$rightAnswer = [];
|
|
$rightAnswer = [];
|
|
- foreach($question as $key=>$value){
|
|
|
|
- //$answer['question_id'] = $key+1;
|
|
|
|
- foreach ($value['answer'] as $k=>$v){
|
|
|
|
- if($v['right']){
|
|
|
|
- $answer['answer_id'][] = $k+1;
|
|
|
|
|
|
+ foreach ($question as $key => $value) {
|
|
|
|
+ $temp = [];
|
|
|
|
+ foreach ($value['answer'] as $k => $v) {
|
|
|
|
+ if ($v['right']) {
|
|
|
|
+ $temp['answer_id'][] = $k + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- $rightAnswer[$key+1] = $answer;
|
|
|
|
|
|
+ $rightAnswer[$key + 1] = $temp;
|
|
}
|
|
}
|
|
- var_dump($rightAnswer);
|
|
|
|
- foreach ($answer as $ak=>$av){
|
|
|
|
- $right = $rightAnswer[$av['question']];
|
|
|
|
- if(array_intersect($right,$av['answer'])){
|
|
|
|
|
|
+// var_dump(json_encode($rightAnswer));
|
|
|
|
+ foreach ($answer as $ak => $av) {
|
|
|
|
+ $right = $rightAnswer[$av['question']]['answer_id'];
|
|
|
|
+// var_dump($right);
|
|
|
|
+// var_dump($av['answer']);
|
|
|
|
+// var_dump($right != $av['answer']);
|
|
|
|
+ if ($right != $av['answer']) {
|
|
$result = false;
|
|
$result = false;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -127,7 +154,7 @@ class CircleRepository
|
|
{
|
|
{
|
|
$info = $this->interestCircleUser
|
|
$info = $this->interestCircleUser
|
|
->where('uid', $userInfo['uid'])
|
|
->where('uid', $userInfo['uid'])
|
|
- ->where('circle_id', $request['circle_id'])
|
|
|
|
|
|
+ ->where('circle_id', $request['id'])
|
|
->first();
|
|
->first();
|
|
if (!$info) {
|
|
if (!$info) {
|
|
return jsonError('您未加入该圈子');
|
|
return jsonError('您未加入该圈子');
|