ApplyController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace App\Http\Controllers\V2_17_3\Friends;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Controllers\Core\Auth;
  5. use App\Managers\FriendManager;
  6. use App\Services\V2_17_3\Friends\ApplyService;
  7. use Illuminate\Http\Request;
  8. class ApplyController extends Controller
  9. {
  10. /**
  11. * 全部申请列表
  12. * @param Request $request
  13. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  14. * @deprecated Friend/GetApplyAllList
  15. */
  16. public function getAllList(Request $request)
  17. {
  18. $uid = Auth::auth();
  19. $pages = array(
  20. 'limit' => 20,
  21. 'page' => $request->get('page', 1)
  22. );
  23. $as = new FriendManager();
  24. $data = $as->getApplyAllList($uid, $pages);
  25. return response([
  26. 'code' => 200,
  27. 'message' => 'success',
  28. 'data' => $data
  29. ]);
  30. }
  31. /**
  32. * 发出申请列表
  33. * @param Request $request
  34. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  35. * @deprecated Friend/GetApplySendList
  36. */
  37. public function getSendList(Request $request)
  38. {
  39. $uid = Auth::auth();
  40. $pages = array(
  41. 'limit' => 20,
  42. 'page' => $request->get('page', 1)
  43. );
  44. $as = new FriendManager();
  45. $data = $as->getSendList($uid, $pages);
  46. return response([
  47. 'code' => 200,
  48. 'message' => 'success',
  49. 'data' => $data
  50. ]);
  51. }
  52. /**
  53. * 收到申请列表
  54. * @param Request $request
  55. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  56. * @deprecated Friend/GetApplyReceiveList
  57. */
  58. public function getReceiveList(Request $request)
  59. {
  60. $uid = Auth::auth();
  61. $pages = array(
  62. 'limit' => 20,
  63. 'page' => $request->get('page', 1)
  64. );
  65. $as = new FriendManager();
  66. $data = $as->getReceiveList($uid, $pages);
  67. return response([
  68. 'code' => 200,
  69. 'message' => 'success',
  70. 'data' => $data
  71. ]);
  72. }
  73. /**
  74. * 发起好友申请
  75. * @param Request $request
  76. * @return array
  77. * @throws \App\Exceptions\AlertException
  78. */
  79. public function send(Request $request)
  80. {
  81. $uid = Auth::auth();
  82. $this->validate($request, [
  83. 'invite_uid' => 'required|integer', // 被申请用户
  84. 'question' => 'required' // 问答
  85. ]);
  86. $to_uid = $request->post('invite_uid');
  87. $question = $request->post('question', []);
  88. $as = new ApplyService();
  89. if ($as->send($uid, $to_uid, $question)) {
  90. return response(array(
  91. 'code' => 200,
  92. 'message' => 'success'
  93. ));
  94. } else {
  95. return response(array(
  96. 'code' => 401,
  97. 'message' => '发送失败'
  98. ));
  99. }
  100. }
  101. /**
  102. * 同意好友申请
  103. * @param int $apply_uid
  104. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  105. * @throws \App\Exceptions\AlertException
  106. */
  107. public function agree(int $apply_uid)
  108. {
  109. $uid = Auth::auth();
  110. $as = new ApplyService();
  111. $as->agree($uid, $apply_uid);
  112. return response([
  113. 'code' => 200,
  114. 'message' => 'success'
  115. ]);
  116. }
  117. }