public function removeInvite($id) { try { $log = UserFriendInviteLog::find($id); if (empty($log)) { throw new Exception("好友邀请已删除", 3001); } $u_id = $log->u_id; $friend = $log->friend_id; $userFriend = UsersFriend::findLinkById($u_id, $friend); if ($userFriend === UsersFriend::$RELATION_NONE) { } elseif ($userFriend->t_status == 1) { $userFriend->remove(); } $log->delete(); $re = Tools::reTrue('删除好友邀请成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '删除好友邀请失败:' . $e->getMessage()); } return Response::json($re); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); try { $user = User::chkUserByToken($token, $u_id); $show_user = User::find($id); if (empty($show_user)) { throw new Exception("请求的用户不存在", 3001); } $show_user->load(['school', 'favorites' => function ($q) { $q->where('favorites.u_id', '=', $this->u_id); }, 'praises' => function ($q) { $q->where('praises.u_id', '=', $this->u_id); }]); $data = $show_user->showDetail(); $is_friend = UsersFriend::$RELATION_NONE; $userFriend = UsersFriend::findLinkById($u_id, $show_user->u_id); if ($userFriend === UsersFriend::$RELATION_NONE) { } else { if ($userFriend->t_status == 1) { $is_friend = $userFriend->t_inviter == $u_id ? UsersFriend::$RELATION_INVITED : UsersFriend::$RELATION_PEDDING_CONFIRM; } else { $is_friend = UsersFriend::$RELATION_CONFIRMED; } } $data['is_friend'] = $is_friend; $data['is_praised'] = 0; $data['is_favorited'] = 0; if (count($show_user->praises) > 0) { $data['is_praised'] = 1; } if (count($show_user->favorites) > 0) { $data['is_favorited'] = 1; } $re = ['result' => 2000, 'data' => $data, 'info' => '读取用户成功']; } catch (Exception $e) { $re = ['result' => 2001, 'data' => [], 'info' => $e->getMessage()]; } return Response::json($re); }