uid = $uid; } public function transform(InterestCircle $interestCircle) { if ($interestCircle['limit_condition']) { $answer = $interestCircle['limit_condition'] - intval(Redis::get('circle_error_count_' . $this->uid)); } else { $answer = -1; } $row = [ 'id' => $interestCircle['id'], 'name' => $interestCircle['name'], 'notice' => $interestCircle['notice'], 'image' => $interestCircle['image'], 'join_limit' => $interestCircle['join_limit'], 'is_join' => $this->isJoin($this->uid, $interestCircle['id']), 'answer_count' => $answer, 'is_black' => $this->isBlack($this->uid, $interestCircle['id']) ]; $funs = $this->getFunction($interestCircle); return array_merge($row, $funs); } //判读当前用户是否圈子黑名单 public function isBlack($uid, $circleId) { $info = InterestCircleUser::where([['circle_id', $circleId], ['uid', $uid], ['is_black', 1]])->first(); Log::debug('blacklist:'.json_encode($info)); return $info ? 1 : 0; } //判读当前用户是否加入圈子 public function isJoin($uid, $circleId) { $info = InterestCircleUser::where([['circle_id', $circleId], ['uid', $uid]])->first(); return $info ? 1 : 0; } /** * 查询圈子开放功能 * @param InterestCircle $interestCircle * @return array */ private function getFunction(InterestCircle $interestCircle) { $functions = json_decode($interestCircle['contains_function'], true); $info['members'] = ['is_open' => 1, 'extra' => intval($interestCircle['join_count'])]; $info['pictures'] = ['is_open' => 0, 'extra' => 0]; $info['chatroom'] = ['is_open' => 0, 'extra' => '']; if (empty($functions)) { return $info; } foreach ($functions as &$func) { if ('pictures' == $func['function']) { if (1 == $func['is_open']) { $info['pictures'] = ['is_open' => 1, 'extra' => intval($interestCircle['picture_count'])]; } } if ('chatroom' == $func['function']) { if (1 == $func['is_open']) { $info['chatroom'] = ['is_open' => 1, 'extra' => (string)$func['relate_id']]; } } } return $info; } }