AccountController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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. * @queryParam type int 位置类型(1:当前位置 2:常用位置) Example: 2
  237. *
  238. * @response {
  239. * "data": {
  240. * "province": "浙江省",
  241. * "city": "杭州市",
  242. * "district": "西湖区",
  243. * "address": "文三路478号",
  244. * "adcode": "330106",
  245. * "longitude": 120.12345,
  246. * "latitude": 30.12345,
  247. * "updated_at": "2024-03-22 10:00:00"
  248. * }
  249. * }
  250. */
  251. public function getLocation(Request $request)
  252. {
  253. $validated = $request->validate([
  254. 'type' => 'required|integer|in:1,2'
  255. ]);
  256. return $this->success(
  257. $this->service->getLocation(Auth::user(), $validated['type'])
  258. );
  259. }
  260. /**
  261. * [账户]设置排班时间
  262. *
  263. * @description 设置技师每天通用的排班时间段
  264. *
  265. * @authenticated
  266. *
  267. * @bodyParam time_ranges array required 时间段数组
  268. * @bodyParam time_ranges[].start_time string required 开始时间(HH:mm格式) Example: "09:00"
  269. * @bodyParam time_ranges[].end_time string required 结束时间(HH:mm格式) Example: "12:00"
  270. *
  271. * @response {
  272. * "status": true,
  273. * "message": "排班设置成功",
  274. * "data": {
  275. * "coach_id": 1,
  276. * "time_ranges": [
  277. * {
  278. * "start_time": "09:00",
  279. * "end_time": "12:00"
  280. * },
  281. * {
  282. * "start_time": "14:00",
  283. * "end_time": "18:00"
  284. * }
  285. * ]
  286. * }
  287. * }
  288. * @response 400 {
  289. * "message": "时间段格式错误"
  290. * }
  291. * @response 400 {
  292. * "message": "时间格式错误,应为HH:mm格式"
  293. * }
  294. * @response 400 {
  295. * "message": "结束时间必须大于开始时间"
  296. * }
  297. * @response 400 {
  298. * "message": "时间段之间不能重叠"
  299. * }
  300. */
  301. public function setSchedule(Request $request)
  302. {
  303. $validated = $request->validate([
  304. 'time_ranges' => 'required|array|min:1',
  305. 'time_ranges.*.start_time' => [
  306. 'required',
  307. 'string',
  308. 'regex:/^([01][0-9]|2[0-3]):[0-5][0-9]$/',
  309. ],
  310. 'time_ranges.*.end_time' => [
  311. 'required',
  312. 'string',
  313. 'regex:/^([01][0-9]|2[0-3]):[0-5][0-9]$/',
  314. ],
  315. ], [
  316. 'time_ranges.required' => '必须设置时间段',
  317. 'time_ranges.array' => '时间段必须是数组格式',
  318. 'time_ranges.min' => '至少设置一个时间段',
  319. 'time_ranges.*.start_time.required' => '开始时间不能为空',
  320. 'time_ranges.*.start_time.regex' => '开始时间格式错误,应为HH:mm格式',
  321. 'time_ranges.*.end_time.required' => '结束时间不能为空',
  322. 'time_ranges.*.end_time.regex' => '结束时间格式错误,应为HH:mm格式',
  323. ]);
  324. return $this->success(
  325. $this->service->setSchedule(Auth::user()->id, $validated['time_ranges'])
  326. );
  327. }
  328. /**
  329. * [账户]更改技师工作状态
  330. *
  331. * @description 更改技师的工作状态(休息中/工作中),工作状态会自动判断为空闲或忙碌
  332. *
  333. * @authenticated
  334. *
  335. * @bodyParam status int required 状态(1:休息中 2:工作中) Example: 2
  336. *
  337. * @response {
  338. * "status": true,
  339. * "message": "状态更新成功",
  340. * "data": {
  341. * "work_status": 2,
  342. * "work_status_text": "空闲中",
  343. * "updated_at": "2024-03-20 10:00:00"
  344. * }
  345. * }
  346. * @response 400 {
  347. * "message": "无效的状态值"
  348. * }
  349. * @response 422 {
  350. * "message": "当前状态不能更改为休息状态"
  351. * }
  352. */
  353. public function updateWorkStatus(Request $request)
  354. {
  355. $validated = $request->validate([
  356. 'status' => 'required|integer|in:1,2',
  357. ], [
  358. 'status.required' => '状态不能为空',
  359. 'status.integer' => '状态必须是整数',
  360. 'status.in' => '无效的状态值',
  361. ]);
  362. return $this->success(
  363. $this->service->updateWorkStatus(Auth::user()->id, $validated['status'])
  364. );
  365. }
  366. /**
  367. * [账户]获取技师工作状态
  368. *
  369. * @description 获取技师当前工作状态
  370. *
  371. * @authenticated
  372. *
  373. * @response {
  374. * "data": {
  375. * "work_status": 2,
  376. * "work_status_text": "空闲中",
  377. * "updated_at": "2024-03-22 10:00:00"
  378. * }
  379. * }
  380. * @response 404 {
  381. * "message": "技师不存在"
  382. * }
  383. */
  384. public function getWorkStatus()
  385. {
  386. return $this->success(
  387. $this->service->getWorkStatus(Auth::user()->coach->id)
  388. );
  389. }
  390. /**
  391. * [账户]获取技师排班信息
  392. *
  393. * @return \Illuminate\Http\JsonResponse
  394. *
  395. * @description 技师获取自己的排班时间段信息
  396. *
  397. * @response {
  398. * "status": true,
  399. * "message": "获取成功",
  400. * "data": {
  401. * "time_ranges": [
  402. * {
  403. * "start_time": "09:00",
  404. * "end_time": "12:00"
  405. * },
  406. * {
  407. * "start_time": "14:00",
  408. * "end_time": "18:00"
  409. * }
  410. * ],
  411. * "updated_at": "2024-03-20 10:00:00"
  412. * }
  413. * }
  414. */
  415. public function getSchedule()
  416. {
  417. $schedule = $this->service->getSchedule(Auth::id());
  418. return $this->success($schedule);
  419. }
  420. /**
  421. * [账户]获取技师详细信息
  422. *
  423. * @description 获取当前登录技师的详细信息,包括基本信息、邀请码和钱包信息
  424. *
  425. * 业务流程:
  426. * 1. 验证用户身份
  427. * 2. 获取技师详细信息
  428. * 3. 返回数据
  429. *
  430. * @authenticated 需要技师身份认证
  431. *
  432. * @response 200 {
  433. * "status": true,
  434. * "message": "获取成功",
  435. * "data": {
  436. * "coach_no": "00000001",
  437. * "mobile": "13800138000",
  438. * "nickname": "张三",
  439. * "avatar": "https://example.com/avatar.jpg",
  440. * "age": 25,
  441. * "gender": 1,
  442. * "work_years": 5,
  443. * "intention_city": "杭州",
  444. * "life_photos": [
  445. * "https://example.com/photo1.jpg",
  446. * "https://example.com/photo2.jpg"
  447. * ],
  448. * "introduction": "专业按摩师,从业5年",
  449. * "state": 1,
  450. * "state_text": "正常",
  451. * "invite_code": "C1",
  452. * "wallet": {
  453. * "balance": 1000,
  454. * "frozen": 200,
  455. * "total_income": 5000,
  456. * "today_income": 300,
  457. * "withdrawable": 800
  458. * }
  459. * }
  460. * }
  461. * @response 404 {
  462. * "message": "技师信息不存在"
  463. * }
  464. */
  465. public function detail()
  466. {
  467. // 获取技师详细信息
  468. $data = $this->service->getCoachDetail();
  469. // 返回成功响应
  470. return $this->success($data, '获取成功');
  471. }
  472. }