UserController.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Client\User\ApplyCoachRequest;
  5. use App\Http\Requests\Client\User\FeedbackRequest;
  6. use App\Http\Requests\Client\User\RegisterRequest;
  7. use App\Http\Requests\Client\User\UpdateRequest;
  8. use App\Services\Client\UserService;
  9. /**
  10. * @group 用户端
  11. *
  12. * 用户相关的API接口
  13. */
  14. class UserController extends Controller
  15. {
  16. protected UserService $service;
  17. public function __construct(UserService $service)
  18. {
  19. $this->service = $service;
  20. }
  21. /**
  22. * [用户]获取用户信息
  23. *
  24. * @description 获取当前登录用户的详细信息
  25. *
  26. * @authenticated
  27. *
  28. * @response 200 {
  29. * "code": 200,
  30. * "message": "获取成功",
  31. * "data": {
  32. * "id": 1,
  33. * "mobile": "13800138000",
  34. * "nickname": "张三",
  35. * "avatar": "https://example.com/avatar.jpg",
  36. * "gender": "male",
  37. * "created_at": "2024-03-20 10:00:00",
  38. * "updated_at": "2024-03-20 10:00:00"
  39. * }
  40. * }
  41. * @response 401 {
  42. * "code": 401,
  43. * "message": "请先登录",
  44. * "data": null
  45. * }
  46. */
  47. public function show()
  48. {
  49. $data = $this->service->getUserInfo();
  50. return $this->success($data);
  51. }
  52. /**
  53. * [用户]用户注册
  54. *
  55. * @description 新用户注册接口,支持邀请注册功能
  56. *
  57. * @bodyParam mobile string required 手机号码 Example: 13800138000
  58. * @bodyParam code string required 短信验证码 Example: 123456
  59. * @bodyParam invite_code string optional 邀请码 Example: ABC123
  60. * @bodyParam invite_id integer optional 邀请人ID Example: 1
  61. * @bodyParam invite_role string optional 邀请人角色(user/coach) Example: user
  62. *
  63. * @response 200 {
  64. * "code": 200,
  65. * "message": "注册成功",
  66. * "data": {
  67. * "user_id": 1,
  68. * "mobile": "13800138000",
  69. * "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
  70. * "invite_code": "DEF456"
  71. * }
  72. * }
  73. * @response 422 {
  74. * "code": 422,
  75. * "message": "验证失败",
  76. * "errors": {
  77. * "mobile": ["手机号码格式不正确"],
  78. * "code": ["验证码错误"]
  79. * }
  80. * }
  81. */
  82. public function register(RegisterRequest $request)
  83. {
  84. $validated = $request->validated();
  85. $data = $this->service->register(
  86. $validated['mobile'],
  87. $validated['code'],
  88. $validated['invite_code'] ?? null,
  89. $validated['invite_id'] ?? null,
  90. $validated['invite_role'] ?? null
  91. );
  92. return $this->success($data, '注册成功');
  93. }
  94. /**
  95. * [用户]修改用户信息
  96. *
  97. * @description 修改当前登录用户的基本信息
  98. *
  99. * @authenticated
  100. *
  101. * @bodyParam nickname string optional 用户昵称 Example: 张三
  102. * @bodyParam avatar string optional 头像URL Example: https://example.com/avatar.jpg
  103. * @bodyParam gender integer optional 性别(0:未知/1:男/2:女) Example: 0
  104. *
  105. * @response 200 {
  106. * "code": 200,
  107. * "message": "修改成功",
  108. * "data": {
  109. * "id": 1,
  110. * "nickname": "张三",
  111. * "avatar": "https://example.com/avatar.jpg",
  112. * "gender": "male",
  113. * "updated_at": "2024-03-20 10:00:00"
  114. * }
  115. * }
  116. * @response 401 {
  117. * "code": 401,
  118. * "message": "请先登录",
  119. * "data": null
  120. * }
  121. */
  122. public function update(UpdateRequest $request)
  123. {
  124. $validated = $request->validated();
  125. $result = $this->service->updateUserInfo($validated);
  126. return $this->success($result, '修改成功');
  127. }
  128. /**
  129. * [用户]用户反馈
  130. *
  131. * @description 提交用户反馈信息
  132. *
  133. * @authenticated
  134. *
  135. * @bodyParam content string required 反馈内容 Example: 系统使用体验很好,建议增加更多功能
  136. * @bodyParam images array optional 图片数组 Example: ["https://example.com/image1.jpg", "https://example.com/image2.jpg"]
  137. * @bodyParam contact string optional 联系方式 Example: 13800138000
  138. *
  139. * @response 200 {
  140. * "code": 200,
  141. * "message": "反馈提交成功",
  142. * "data": {
  143. * "id": 1,
  144. * "content": "系统使用体验很好,建议增加更多功能",
  145. * "images": ["https://example.com/image1.jpg"],
  146. * "created_at": "2024-03-20 10:00:00"
  147. * }
  148. * }
  149. * @response 422 {
  150. * "code": 422,
  151. * "message": "内容不能为空",
  152. * "data": null
  153. * }
  154. */
  155. public function feedback(FeedbackRequest $request)
  156. {
  157. $validated = $request->validated();
  158. $result = $this->service->feedback(
  159. $validated['content'],
  160. $validated['images'] ?? [],
  161. $validated['contact'] ?? null
  162. );
  163. return $this->success($result, '反馈提交成功');
  164. }
  165. /**
  166. * [用户]申请成为技师
  167. *
  168. * @description 普通用户申请成为平台技师,提交技师申请信息
  169. *
  170. * @authenticated
  171. *
  172. * @bodyParam age integer required 年龄(18-60岁) Example: 25
  173. * @bodyParam mobile string required 联系电话 Example: 13800138000
  174. * @bodyParam gender integer required 性别(1:男/2:女) Example: 1
  175. * @bodyParam work_years integer required 工作年限(0-50年) Example: 5
  176. * @bodyParam intention_city string required 意向城市 Example: 杭州
  177. * @bodyParam portrait_images array required 形象照片(最多6张) Example: ["https://example.com/portrait1.jpg"]
  178. * @bodyParam introduction string optional 个人简介(最多1000字) Example: 专业按摩师,有多年经验
  179. *
  180. * @response 200 {
  181. * "code": 200,
  182. * "message": "申请提交成功",
  183. * "data": {
  184. * "id": 1,
  185. * "coach_id": 100,
  186. * "age": 25,
  187. * "mobile": "13800138000",
  188. * "gender": 1,
  189. * "work_years": 5,
  190. * "intention_city": "杭州",
  191. * "portrait_images": ["https://example.com/portrait1.jpg"],
  192. * "introduction": "专��按摩师,有多年经验",
  193. * "state": "auditing",
  194. * "created_at": "2024-03-20 10:00:00",
  195. * "updated_at": "2024-03-20 10:00:00"
  196. * }
  197. * }
  198. * @response 401 {
  199. * "code": 401,
  200. * "message": "请先登录",
  201. * "data": null
  202. * }
  203. * @response 422 {
  204. * "code": 422,
  205. * "message": "验证失败",
  206. * "errors": {
  207. * "mobile": ["手机号码格式不正确"],
  208. * "gender": ["性别只能是1(男)或2(女)"],
  209. * "work_years": ["工作年限必须是0-50之间的整数"],
  210. * "intention_city": ["意向城市不能为空"],
  211. * "portrait_images": ["形象照片不能为空"],
  212. * "portrait_images.*": ["图片必须是有效的URL地址"]
  213. * }
  214. * }
  215. * @response 422 {
  216. * "code": 422,
  217. * "message": "您已是技师,无需重复申请",
  218. * "data": null
  219. * }
  220. * @response 422 {
  221. * "code": 422,
  222. * "message": "您有正在审核的申请,请耐心等待",
  223. * "data": null
  224. * }
  225. */
  226. public function applyCoach(ApplyCoachRequest $request)
  227. {
  228. $validated = $request->validated();
  229. $result = $this->service->applyCoach(
  230. $validated['age'],
  231. $validated['mobile'],
  232. $validated['gender'],
  233. $validated['work_years'],
  234. $validated['intention_city'],
  235. $validated['portrait_images'],
  236. $validated['introduction'] ?? null
  237. );
  238. return $this->success($result, '申请提交成功');
  239. }
  240. /**
  241. * [用户]生成邀请二维码
  242. *
  243. * @description 生成当前用户专属的邀请码和邀请二维码,支持普通用户和技师两种身份
  244. *
  245. * @authenticated
  246. *
  247. * @queryParam type string required 邀请码类型(user:普通用户/coach:技师) Example: user
  248. *
  249. * @response 200 {
  250. * "code": 200,
  251. * "message": "生成成功",
  252. * "data": {
  253. * "invite_code": "user_1",
  254. * "invite_url": "https://example.com/invite?invite_id=1&invite_role=user&invite_code=user_1",
  255. * "qr_code": "data:image/svg+xml;base64,..."
  256. * }
  257. * }
  258. * @response 401 {
  259. * "code": 401,
  260. * "message": "请先登录",
  261. * "data": null
  262. * }
  263. * @response 422 {
  264. * "code": 422,
  265. * "message": "无法生成邀请码,用户类型不匹配",
  266. * "data": null
  267. * }
  268. */
  269. public function generateInviteCode()
  270. {
  271. $result = $this->service->generateInviteCode();
  272. return $this->success($result, '生成成功');
  273. }
  274. /**
  275. * [用户]查看技师申请记录
  276. *
  277. * @description 获取当前用户的技师申请记录
  278. *
  279. * @authenticated
  280. *
  281. * @response 200 {
  282. * "code": 200,
  283. * "message": "获取成功",
  284. * "data": {
  285. * "id": 1,
  286. * "coach_id": 100,
  287. * "age": 25,
  288. * "mobile": "13800138000",
  289. * "gender": 1,
  290. * "work_years": 5,
  291. * "intention_city": "杭州",
  292. * "portrait_images": ["https://example.com/portrait1.jpg"],
  293. * "introduction": "专业按摩师,有多年经验",
  294. * "state": 1,
  295. * "state_text": "待审核",
  296. * "created_at": "2024-03-20 10:00:00",
  297. * "updated_at": "2024-03-20 10:00:00"
  298. * }
  299. * }
  300. * @response 401 {
  301. * "code": 401,
  302. * "message": "请先登录",
  303. * "data": null
  304. * }
  305. * @response 404 {
  306. * "code": 404,
  307. * "message": "未找到申请记录",
  308. * "data": null
  309. * }
  310. */
  311. public function getCoachApplication()
  312. {
  313. $result = $this->service->getCoachApplication();
  314. return $this->success($result);
  315. }
  316. }