AccountController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?php
  2. namespace App\Http\Controllers\Coach;
  3. use Illuminate\Http\Request;
  4. use App\Traits\ResponseTrait;
  5. use App\Traits\LocationDataTrait;
  6. use Illuminate\Support\Facades\Log;
  7. use App\Http\Controllers\Controller;
  8. use Illuminate\Support\Facades\Auth;
  9. use App\Enums\TechnicianLocationType;
  10. use App\Services\Coach\AccountService;
  11. use App\Http\Requests\Coach\SetLocationRequest;
  12. use App\Http\Requests\Coach\SubmitBaseInfoRequest;
  13. use App\Http\Requests\Coach\SubmitRealNameRequest;
  14. use App\Http\Requests\Coach\SubmitQualificationRequest;
  15. /**
  16. * @group 技师端
  17. *
  18. * 技师账户相关的API接口
  19. */
  20. class AccountController extends Controller
  21. {
  22. use ResponseTrait;
  23. use LocationDataTrait;
  24. protected AccountService $service;
  25. public function __construct(AccountService $service)
  26. {
  27. $this->service = $service;
  28. }
  29. /**
  30. * [账户]提交基本信息
  31. *
  32. * @description 提交技师的基本个人信息,包括头像、生活照片、个人资料等
  33. *
  34. * 业务流程:
  35. * 1. 验证提交的数据
  36. * 2. 调用服务层处理业务逻辑
  37. * 3. 返回处理结果
  38. *
  39. * 注意事项:
  40. * - 同一时间只能有一条待审核记录
  41. * - 审核不通过可以重新提交
  42. * - 头像和生活照片支持任意格式的图片数据
  43. * - 除性别和手机号外,其他字段均为可选
  44. * - 生活照片为可选,支持多张
  45. *
  46. * @authenticated 需要技师身份认证
  47. *
  48. * @bodyParam nickname string nullable 昵称(2-20个字符) Example: 张三
  49. * @bodyParam avatar string nullable 头像图片 Example: base64或其他格式的图片数据
  50. * @bodyParam life_photos array nullable 生活照片数组
  51. * @bodyParam life_photos.* string required 生活照片 Example: base64或其他格式的图片数据
  52. * @bodyParam gender string required 性别(1:男 2:女) Example: 1
  53. * @bodyParam mobile string required 手机号 Example: 13800138000
  54. * @bodyParam birthday date nullable 出生日期(年龄需满18岁) Example: 1990-01-01
  55. * @bodyParam work_years integer nullable 工作年限(0-99) Example: 5
  56. * @bodyParam intention_city string nullable 意向城市 Example: 北京
  57. * @bodyParam introduction string nullable 个人简介(10-255个字符) Example: 专业按摩师,从业5年
  58. *
  59. * @response 200 {
  60. * "status": true,
  61. * "message": "基本信息提交成功"
  62. * }
  63. * @response 404 {
  64. * "message": "技师信息不存在"
  65. * }
  66. * @response 422 {
  67. * "message": "已有待审核的基本信息记录"
  68. * }
  69. * @response 422 {
  70. * "message": "验证错误",
  71. * "errors": {
  72. * "nickname": ["昵称不能少于2个字符"],
  73. * "gender": ["性别不能为空"],
  74. * "mobile": ["手机号不能为空"],
  75. * "life_photos.*": ["生活照片格式不正确"]
  76. * }
  77. * }
  78. */
  79. public function submitBaseInfo(SubmitBaseInfoRequest $request)
  80. {
  81. // 获取验证后的数据
  82. $data = $request->validated();
  83. // 调用服务层处理业务逻辑
  84. // 传入当前认证用户和验证后的数据
  85. return $this->success(
  86. $this->service->submitBaseInfo(Auth::user(), $data)
  87. );
  88. }
  89. /**
  90. * [账户]提交资质信息
  91. *
  92. * @description 提交技师的资质认证信息,包括资质照片、营业执照和健康证
  93. *
  94. * @authenticated
  95. *
  96. * @bodyParam qual_type int required 资质类型(1:初级按摩师 2:中级按摩师 3:高级按摩师) Example: 1
  97. * @bodyParam qual_photo string required 资质证书照片 Example: base64或其他格式的图片数据
  98. * @bodyParam business_license string required 营业执照照片 Example: base64或其他格式的图片数据
  99. * @bodyParam health_cert string required 健康证照片 Example: base64或其他格式的图片数据
  100. *
  101. * @response {
  102. * "message": "资质信息提交成功"
  103. * }
  104. */
  105. public function submitQualification(SubmitQualificationRequest $request)
  106. {
  107. $data = $request->validated();
  108. return $this->success($this->service->submitQualification(Auth::user(), $data));
  109. }
  110. /**
  111. * [账户]提交实名认证
  112. *
  113. * @description 提交技师的实名认证信息
  114. *
  115. * @authenticated
  116. *
  117. * @bodyParam real_name string nullable 姓名(2-20个字符) Example: 张三
  118. * @bodyParam id_card string nullable 身份证号(18位) Example: 370602199001011234
  119. * @bodyParam id_card_front_photo string required 身份证正面照片 Example: base64或其他格式的图片数据
  120. * @bodyParam id_card_back_photo string required 身份证反面照片 Example: base64或其他格式的图片数据
  121. * @bodyParam id_card_hand_photo string required 手持身份证照片 Example: base64或其他格式的图片数据
  122. *
  123. * @response {
  124. * "message": "实名认证信息提交成功"
  125. * }
  126. */
  127. public function submitRealName(SubmitRealNameRequest $request)
  128. {
  129. $data = $request->validated();
  130. return $this->success($this->service->submitRealName(Auth::user(), $data));
  131. }
  132. /**
  133. * [账户]获取技师信息
  134. *
  135. * @description 获取技师的基本信息、资质信息和实名认证信息
  136. *
  137. * @authenticated
  138. *
  139. * @response {
  140. * "data": {
  141. * "base_info": {
  142. * "nickname": "张三",
  143. * "avatar": "base64或其他格式的图片数据",
  144. * "life_photos": [
  145. * "base64或其他格式的图片数据1",
  146. * "base64或其他格式的图片数据2"
  147. * ],
  148. * "gender": "1",
  149. * "mobile": "138****8000",
  150. * "birthday": "1990-01-01",
  151. * "work_years": 5,
  152. * "intention_city": "北京",
  153. * "introduction": "专业按摩师,从业5年",
  154. * "state": 1,
  155. * "state_text": "已通过",
  156. * "audit_remark": "审核通过"
  157. * },
  158. * "qualification": {
  159. * "qual_type": "高级按摩师",
  160. * "qual_photo": "base64或其他格式的图片数据",
  161. * "business_license": "base64或其他格式的图片数据",
  162. * "health_cert": "base64或其他格式的图片数据",
  163. * "state": 1,
  164. * "state_text": "已通过",
  165. * "audit_remark": "审核通过"
  166. * },
  167. * "real_name": {
  168. * "real_name": "张三",
  169. * "id_card": "370602****1234",
  170. * "id_card_front_photo": "base64或其他格式的图片数据",
  171. * "id_card_back_photo": "base64或其他格式的图片数据",
  172. * "id_card_hand_photo": "base64或其他格式的图片数据",
  173. * "state": 1,
  174. * "state_text": "已通过",
  175. * "audit_remark": "审核通过"
  176. * }
  177. * }
  178. * }
  179. * @response 404 {
  180. * "message": "用户不存在"
  181. * }
  182. * @response 404 {
  183. * "message": "技师信息不存在"
  184. * }
  185. */
  186. public function info()
  187. {
  188. return $this->success($this->service->getCoachInfo(Auth::user()));
  189. }
  190. /**
  191. * [账户]设置技师位置信息
  192. *
  193. * @description 设置技师的当前位置或常用位置
  194. *
  195. * @authenticated
  196. *
  197. * @bodyParam latitude float required 纬度 Example: 39.9042
  198. * @bodyParam longitude float required 经度 Example: 116.4074
  199. * @bodyParam type int nullable 位置类型(1:当前位置 2:常用位置) Example: 2
  200. * @bodyParam province string nullable 省份 Example: 北京市
  201. * @bodyParam city string nullable 城市 Example: 北京市
  202. * @bodyParam district string nullable 区县 Example: 朝阳区
  203. * @bodyParam address string nullable 详细地址 Example: 建国路93号万达广场
  204. * @bodyParam adcode string nullable 行政区划代码 Example: 110105
  205. *
  206. * @response {
  207. * "message": "位置信息设置成功"
  208. * }
  209. */
  210. public function setLocation(SetLocationRequest $request)
  211. {
  212. // 获取验证后的数据
  213. $validated = $request->validated();
  214. // 确保用户和技师存在
  215. $user = Auth::user();
  216. abort_if(!$user->coach, 404, '技师信息不存在');
  217. // 提取位置信息
  218. $locationInfo = $this->extractLocationInfo($validated);
  219. // 传递技师ID给服务层
  220. $this->service->setLocation(
  221. $user->coach->id,
  222. $validated['latitude'],
  223. $validated['longitude'],
  224. $validated['type'] ?? TechnicianLocationType::COMMON->value,
  225. $locationInfo
  226. );
  227. return $this->success(['message' => '位置信息设置成功']);
  228. }
  229. /**
  230. * [账户]获取技师位置信息
  231. *
  232. * @description 取技师的当前位置和常用位置信息
  233. *
  234. * @authenticated
  235. *
  236. * @response {
  237. * "data": {
  238. * "current": {
  239. * "address": "北京市朝阳区建国路93号万达广场"
  240. * },
  241. * "common": {
  242. * "address": "北京市海淀区中关村大街1号"
  243. * }
  244. * }
  245. *idid
  246. */
  247. public function getLocation()
  248. {
  249. $result = $this->service->getLocation(Auth::user()->id);
  250. return $this->success($result);
  251. }
  252. /**
  253. * [账户]设置排班时间
  254. *
  255. * @description 设置技师每天通用的排班时间段
  256. *
  257. * @authenticated
  258. *
  259. * @bodyParam time_ranges array required 时间段数组
  260. * @bodyParam time_ranges[].start_time string required 开始时间(HH:mm格式) Example: "09:00"
  261. * @bodyParam time_ranges[].end_time string required 结束时间(HH:mm格式) Example: "12:00"
  262. *
  263. * @response {
  264. * "status": true,
  265. * "message": "排班设置成功",
  266. * "data": {
  267. * "coach_id": 1,
  268. * "time_ranges": [
  269. * {
  270. * "start_time": "09:00",
  271. * "end_time": "12:00"
  272. * },
  273. * {
  274. * "start_time": "14:00",
  275. * "end_time": "18:00"
  276. * }
  277. * ]
  278. * }
  279. * }
  280. * @response 400 {
  281. * "message": "时间段格式错误"
  282. * }
  283. * @response 400 {
  284. * "message": "时间格式错误,应为HH:mm格式"
  285. * }
  286. * @response 400 {
  287. * "message": "结束时间必须大于开始时间"
  288. * }
  289. * @response 400 {
  290. * "message": "时间段之间不能重叠"
  291. * }
  292. */
  293. public function setSchedule(Request $request)
  294. {
  295. $validated = $request->validate([
  296. 'time_ranges' => 'required|array|min:1',
  297. 'time_ranges.*.start_time' => [
  298. 'required',
  299. 'string',
  300. 'regex:/^([01][0-9]|2[0-3]):[0-5][0-9]$/',
  301. ],
  302. 'time_ranges.*.end_time' => [
  303. 'required',
  304. 'string',
  305. 'regex:/^([01][0-9]|2[0-3]):[0-5][0-9]$/',
  306. ],
  307. ], [
  308. 'time_ranges.required' => '必须设置时间段',
  309. 'time_ranges.array' => '时间段必须是数组格式',
  310. 'time_ranges.min' => '至少设置一个时间段',
  311. 'time_ranges.*.start_time.required' => '开始时间不能为空',
  312. 'time_ranges.*.start_time.regex' => '开始时间格式错误,应为HH:mm格式',
  313. 'time_ranges.*.end_time.required' => '结束时间不能为空',
  314. 'time_ranges.*.end_time.regex' => '结束时间格式错误,应为HH:mm格式',
  315. ]);
  316. return $this->success(
  317. $this->service->setSchedule(Auth::user()->id, $validated['time_ranges'])
  318. );
  319. }
  320. /**
  321. * [账户]更改技师工作状态
  322. *
  323. * @description 更改技师的工作状态(休息中/工作中),工作状态会自动判断为空闲或忙碌
  324. *
  325. * @authenticated
  326. *
  327. * @bodyParam status int required 状态(1:休息中 2:工作中) Example: 2
  328. *
  329. * @response {
  330. * "status": true,
  331. * "message": "状态更新成功",
  332. * "data": {
  333. * "work_status": 2,
  334. * "work_status_text": "空闲中",
  335. * "updated_at": "2024-03-20 10:00:00"
  336. * }
  337. * }
  338. * @response 400 {
  339. * "message": "无效的状态值"
  340. * }
  341. * @response 422 {
  342. * "message": "当前状态不能更改为休息状态"
  343. * }
  344. */
  345. public function updateWorkStatus(Request $request)
  346. {
  347. $validated = $request->validate([
  348. 'status' => 'required|integer|in:1,2',
  349. ], [
  350. 'status.required' => '状态不能为空',
  351. 'status.integer' => '状态必须是整数',
  352. 'status.in' => '无效的状态值',
  353. ]);
  354. return $this->success(
  355. $this->service->updateWorkStatus(Auth::user()->id, $validated['status'])
  356. );
  357. }
  358. /**
  359. * [账户]获取技师工作状态
  360. *
  361. * @description 获取技师当前工作状态
  362. *
  363. * @authenticated
  364. *
  365. * @response {
  366. * "data": {
  367. * "work_status": 2,
  368. * "work_status_text": "空闲中",
  369. * "updated_at": "2024-03-22 10:00:00"
  370. * }
  371. * }
  372. * @response 404 {
  373. * "message": "技师不存在"
  374. * }
  375. */
  376. public function getWorkStatus()
  377. {
  378. return $this->success(
  379. $this->service->getWorkStatus(Auth::user()->coach->id)
  380. );
  381. }
  382. /**
  383. * [账户]获取技师排班信息
  384. *
  385. * @return \Illuminate\Http\JsonResponse
  386. *
  387. * @description 技师获取自己的排班时间段信息
  388. *
  389. * @response {
  390. * "status": true,
  391. * "message": "获取成功",
  392. * "data": {
  393. * "time_ranges": [
  394. * {
  395. * "start_time": "09:00",
  396. * "end_time": "12:00"
  397. * },
  398. * {
  399. * "start_time": "14:00",
  400. * "end_time": "18:00"
  401. * }
  402. * ],
  403. * "updated_at": "2024-03-20 10:00:00"
  404. * }
  405. * }
  406. */
  407. public function getSchedule()
  408. {
  409. $schedule = $this->service->getSchedule(Auth::id());
  410. return $this->success($schedule);
  411. }
  412. }