|
@@ -57,6 +57,95 @@ class CircleRepository
|
|
|
return $model->find($request['id']);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 加入圈子
|
|
|
+ * @param $request
|
|
|
+ * @param $userInfo
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function joinCircle($request, $userInfo)
|
|
|
+ {
|
|
|
+ $row = $this->interestCircleUser
|
|
|
+ ->where('uid', $userInfo['uid'])
|
|
|
+ ->where('circle_id', $request['circle_id'])
|
|
|
+ ->first();
|
|
|
+ if ($row) {
|
|
|
+ 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){
|
|
|
+ return jsonError('学习学习,明天再来吧~');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $this->interestCircleUser->create(['uid' => $userInfo['uid'], 'circle_id' => $request['circle_id']]);
|
|
|
+ DB::commit();
|
|
|
+ //加入圈子成功后,清除错误回答次数
|
|
|
+ $key = 'circle_error_count_' . $userInfo['uid'];
|
|
|
+ Redis::del($key);
|
|
|
+ return jsonSuccess();
|
|
|
+ } catch (QueryException $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ return jsonError('加入圈子失败,再试试吧');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private function checkQuestion($question,$answer){
|
|
|
+ $result = true;
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $rightAnswer[$key+1] = $answer;
|
|
|
+ }
|
|
|
+ var_dump($rightAnswer);
|
|
|
+ foreach ($answer as $ak=>$av){
|
|
|
+ $right = $rightAnswer[$av['question']];
|
|
|
+ if(array_intersect($right,$av['answer'])){
|
|
|
+ $result = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退出圈子
|
|
|
+ * @param $request
|
|
|
+ * @param $userInfo
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function exitCircle($request, $userInfo)
|
|
|
+ {
|
|
|
+ $info = $this->interestCircleUser
|
|
|
+ ->where('uid', $userInfo['uid'])
|
|
|
+ ->where('circle_id', $request['circle_id'])
|
|
|
+ ->first();
|
|
|
+ if (!$info) {
|
|
|
+ return jsonError('您未加入该圈子');
|
|
|
+ }
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $info->delete();
|
|
|
+ DB::commit();
|
|
|
+ //退出圈子成功后,清除错误回答次数
|
|
|
+ $key = 'circle_error_count_' . $userInfo['uid'];
|
|
|
+ Redis::del($key);
|
|
|
+ return jsonSuccess();
|
|
|
+ } catch (QueryException $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ return jsonError('退出圈子失败,再试试吧');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 相册列表
|