UserController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Client\UserService;
  5. use Illuminate\Http\Request;
  6. /**
  7. * @group 用户端
  8. *
  9. * 用户相关的API接口
  10. */
  11. class UserController extends Controller
  12. {
  13. protected UserService $service;
  14. public function __construct(UserService $service)
  15. {
  16. $this->service = $service;
  17. }
  18. /**
  19. * [用户]获取用户信息
  20. *
  21. * 获取当前用户的信息
  22. *
  23. * @authenticated
  24. *
  25. * @response {
  26. * "code": 200,
  27. * "message": "获取成功",
  28. * "data": {
  29. * "id": 1,
  30. * "mobile": "13800138000",
  31. * "nickname": "用户昵称"
  32. * }
  33. * }
  34. */
  35. public function show()
  36. {
  37. return $this->service->getUserInfo();
  38. }
  39. /**
  40. * [用户]用户注册
  41. *
  42. * @return \Illuminate\Http\JsonResponse
  43. *
  44. * @description 用户注册接口
  45. *
  46. * @bodyParam mobile string required 手机号 Example: 13800138000
  47. * @bodyParam code string required 验证码 Example: 123456
  48. * @bodyParam invite_code string optional 邀请码 Example: ABC123
  49. * @bodyParam invite_id integer optional 邀请人ID Example: 1
  50. * @bodyParam invite_role string optional 邀请人角色(user) Example: memberUser
  51. *
  52. * @response {
  53. * "code": 200,
  54. * "message": "注册成功",
  55. * "data": {
  56. * "user_id": 1,
  57. * "mobile": "13800138000",
  58. * "invite_code": "ABC123"
  59. * }
  60. * }
  61. */
  62. public function register(Request $request)
  63. {
  64. $validated = $request->validate([
  65. 'mobile' => 'required|string|size:11|regex:/^1[3-9]\d{9}$/',
  66. 'code' => 'required|string|size:6',
  67. 'invite_code' => 'nullable|string|size:6',
  68. 'invite_id' => 'nullable|integer',
  69. 'invite_role' => 'nullable|string|in:memberUser',
  70. ]);
  71. return $this->service->register(
  72. $validated['mobile'],
  73. $validated['code'],
  74. $validated['invite_code'] ?? null,
  75. $validated['invite_id'] ?? null,
  76. $validated['invite_role'] ?? null
  77. );
  78. }
  79. /**
  80. * [用户]修改用户信息
  81. *
  82. * 修改当前用户的信息
  83. *
  84. * @authenticated
  85. *
  86. * @bodyParam nickname string 用户昵称. Example: 用户昵称
  87. * @bodyParam avatar string 用户头像. Example: https://example.com/avatar.jpg
  88. *
  89. * @response {
  90. * "code": 200,
  91. * "message": "修改成功",
  92. * "data": null
  93. * }
  94. */
  95. public function update(Request $request)
  96. {
  97. $data = $request->all();
  98. $result = $this->service->updateUserInfo($data);
  99. return $result;
  100. }
  101. /**
  102. * [用户]用户反馈
  103. *
  104. * 提交用户的反馈信息
  105. *
  106. * @authenticated
  107. *
  108. * @bodyParam content string 反馈内容. Example: 这是一个反馈信息
  109. *
  110. * @response {
  111. * "code": 200,
  112. * "message": "提交成功",
  113. * "data": null
  114. * }
  115. */
  116. public function feedback(Request $request)
  117. {
  118. $content = $request->input('content');
  119. $result = $this->service->feedback($content);
  120. return $result;
  121. }
  122. /**
  123. * [用户]申请成为技师
  124. *
  125. * 申请成为技师
  126. *
  127. * @authenticated
  128. *
  129. * @bodyParam mobile string 手机号. Example: 13800138000
  130. * @bodyParam gender string 性别. Example: male
  131. * @bodyParam work_years string 工作年限. Example: 5
  132. * @bodyParam intention_city string 意向城市. Example: 杭州
  133. *
  134. * @response {
  135. * "code": 200,
  136. * "message": "申请成功",
  137. * "data": null
  138. * }
  139. */
  140. public function applyCoach(Request $request)
  141. {
  142. $mobile = $request->input('mobile');
  143. $gender = $request->input('gender');
  144. $work_years = $request->input('work_years');
  145. $intention_city = $request->input('intention_city');
  146. $result = $this->service->applyCoach($mobile, $gender, $work_years, $intention_city);
  147. return $result;
  148. }
  149. /**
  150. * [用户]生成二维码
  151. *
  152. * @description 生成当前用户的邀请码和对应的二维码
  153. *
  154. * @response {
  155. * "code": 200,
  156. * "message": "生成成功",
  157. * "data": {
  158. * "invite_code": "ABC123",
  159. * "qr_code": "data:image/png;base64,..."
  160. * }
  161. * }
  162. */
  163. public function generateInviteCode()
  164. {
  165. // 调用服务层生成邀请码
  166. return $this->service->generateInviteCode();
  167. }
  168. }