123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- <?php
- namespace App\Http\Controllers\Coach;
- use Illuminate\Http\Request;
- use App\Traits\ResponseTrait;
- use App\Traits\LocationDataTrait;
- use Illuminate\Support\Facades\Log;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
- use App\Enums\TechnicianLocationType;
- use App\Services\Coach\AccountService;
- use App\Http\Requests\Coach\SetLocationRequest;
- use App\Http\Requests\Coach\SubmitBaseInfoRequest;
- use App\Http\Requests\Coach\SubmitRealNameRequest;
- use App\Http\Requests\Coach\SubmitQualificationRequest;
- /**
- * @group 技师端
- *
- * 技师账户相关的API接口
- */
- class AccountController extends Controller
- {
- use ResponseTrait;
- use LocationDataTrait;
- protected AccountService $service;
- public function __construct(AccountService $service)
- {
- $this->service = $service;
- }
- /**
- * [账户]提交基本信息
- *
- * @description 提交技师的基本个人信息,包括头像、生活照片、个人资料等
- *
- * 业务流程:
- * 1. 验证提交的数据
- * 2. 调用服务层处理业务逻辑
- * 3. 返回处理结果
- *
- * 注意事项:
- * - 同一时间只能有一条待审核记录
- * - 审核不通过可以重新提交
- * - 头像和生活照片支持任意格式的图片数据
- * - 除性别和手机号外,其他字段均为可选
- * - 生活照片为可选,支持多张
- *
- * @authenticated 需要技师身份认证
- *
- * @bodyParam nickname string nullable 昵称(2-20个字符) Example: 张三
- * @bodyParam avatar string nullable 头像图片 Example: base64或其他格式的图片数据
- * @bodyParam life_photos array nullable 生活照片数组
- * @bodyParam life_photos.* string required 生活照片 Example: base64或其他格式的图片数据
- * @bodyParam gender string required 性别(1:男 2:女) Example: 1
- * @bodyParam mobile string required 手机号 Example: 13800138000
- * @bodyParam birthday date nullable 出生日期(年龄需满18岁) Example: 1990-01-01
- * @bodyParam work_years integer nullable 工作年限(0-99) Example: 5
- * @bodyParam intention_city string nullable 意向城市 Example: 北京
- * @bodyParam introduction string nullable 个人简介(10-255个字符) Example: 专业按摩师,从业5年
- *
- * @response 200 {
- * "status": true,
- * "message": "基本信息提交成功"
- * }
- * @response 404 {
- * "message": "技师信息不存在"
- * }
- * @response 422 {
- * "message": "已有待审核的基本信息记录"
- * }
- * @response 422 {
- * "message": "验证错误",
- * "errors": {
- * "nickname": ["昵称不能少于2个字符"],
- * "gender": ["性别不能为空"],
- * "mobile": ["手机号不能为空"],
- * "life_photos.*": ["生活照片格式不正确"]
- * }
- * }
- */
- public function submitBaseInfo(SubmitBaseInfoRequest $request)
- {
- // 获取验证后的数据
- $data = $request->validated();
- // 调用服务层处理业务逻辑
- // 传入当前认证用户和验证后的数据
- return $this->success(
- $this->service->submitBaseInfo(Auth::user(), $data)
- );
- }
- /**
- * [账户]提交资质信息
- *
- * @description 提交技师的资质认证信息,包括资质照片、营业执照和健康证
- *
- * @authenticated
- *
- * @bodyParam qual_type int required 资质类型(1:初级按摩师 2:中级按摩师 3:高级按摩师) Example: 1
- * @bodyParam qual_photo string required 资质证书照片 Example: base64或其他格式的图片数据
- * @bodyParam business_license string required 营业执照照片 Example: base64或其他格式的图片数据
- * @bodyParam health_cert string required 健康证照片 Example: base64或其他格式的图片数据
- *
- * @response {
- * "message": "资质信息提交成功"
- * }
- */
- public function submitQualification(SubmitQualificationRequest $request)
- {
- $data = $request->validated();
- return $this->success($this->service->submitQualification(Auth::user(), $data));
- }
- /**
- * [账户]提交实名认证
- *
- * @description 提交技师的实名认证信息
- *
- * @authenticated
- *
- * @bodyParam real_name string nullable 姓名(2-20个字符) Example: 张三
- * @bodyParam id_card string nullable 身份证号(18位) Example: 370602199001011234
- * @bodyParam id_card_front_photo string required 身份证正面照片 Example: base64或其他格式的图片数据
- * @bodyParam id_card_back_photo string required 身份证反面照片 Example: base64或其他格式的图片数据
- * @bodyParam id_card_hand_photo string required 手持身份证照片 Example: base64或其他格式的图片数据
- *
- * @response {
- * "message": "实名认证信息提交成功"
- * }
- */
- public function submitRealName(SubmitRealNameRequest $request)
- {
- $data = $request->validated();
- return $this->success($this->service->submitRealName(Auth::user(), $data));
- }
- /**
- * [账户]获取技师信息
- *
- * @description 获取技师的基本信息、资质信息和实名认证信息
- *
- * @authenticated
- *
- * @response {
- * "data": {
- * "base_info": {
- * "nickname": "张三",
- * "avatar": "base64或其他格式的图片数据",
- * "life_photos": [
- * "base64或其他格式的图片数据1",
- * "base64或其他格式的图片数据2"
- * ],
- * "gender": "1",
- * "mobile": "138****8000",
- * "birthday": "1990-01-01",
- * "work_years": 5,
- * "intention_city": "北京",
- * "introduction": "专业按摩师,从业5年",
- * "state": 1,
- * "state_text": "已通过",
- * "audit_remark": "审核通过"
- * },
- * "qualification": {
- * "qual_type": "高级按摩师",
- * "qual_photo": "base64或其他格式的图片数据",
- * "business_license": "base64或其他格式的图片数据",
- * "health_cert": "base64或其他格式的图片数据",
- * "state": 1,
- * "state_text": "已通过",
- * "audit_remark": "审核通过"
- * },
- * "real_name": {
- * "real_name": "张三",
- * "id_card": "370602****1234",
- * "id_card_front_photo": "base64或其他格式的图片数据",
- * "id_card_back_photo": "base64或其他格式的图片数据",
- * "id_card_hand_photo": "base64或其他格式的图片数据",
- * "state": 1,
- * "state_text": "已通过",
- * "audit_remark": "审核通过"
- * }
- * }
- * }
- * @response 404 {
- * "message": "用户不存在"
- * }
- * @response 404 {
- * "message": "技师信息不存在"
- * }
- */
- public function info()
- {
- return $this->success($this->service->getCoachInfo(Auth::user()));
- }
- /**
- * [账户]设置技师位置信息
- *
- * @description 设置技师的当前位置或常用位置
- *
- * @authenticated
- *
- * @bodyParam latitude float required 纬度 Example: 39.9042
- * @bodyParam longitude float required 经度 Example: 116.4074
- * @bodyParam type int nullable 位置类型(1:当前位置 2:常用位置) Example: 2
- * @bodyParam province string nullable 省份 Example: 北京市
- * @bodyParam city string nullable 城市 Example: 北京市
- * @bodyParam district string nullable 区县 Example: 朝阳区
- * @bodyParam address string nullable 详细地址 Example: 建国路93号万达广场
- * @bodyParam adcode string nullable 行政区划代码 Example: 110105
- *
- * @response {
- * "message": "位置信息设置成功"
- * }
- */
- public function setLocation(SetLocationRequest $request)
- {
- // 获取验证后的数据
- $validated = $request->validated();
- // 确保用户和技师存在
- $user = Auth::user();
- abort_if(!$user->coach, 404, '技师信息不存在');
- // 提取位置信息
- $locationInfo = $this->extractLocationInfo($validated);
- // 传递技师ID给服务层
- $this->service->setLocation(
- $user->coach->id,
- $validated['latitude'],
- $validated['longitude'],
- $validated['type'] ?? TechnicianLocationType::COMMON->value,
- $locationInfo
- );
- return $this->success(['message' => '位置信息设置成功']);
- }
- /**
- * [账户]获取技师位置信息
- *
- * @description 取技师的当前位置和常用位置信息
- *
- * @authenticated
- *
- * @response {
- * "data": {
- * "current": {
- * "address": "北京市朝阳区建国路93号万达广场"
- * },
- * "common": {
- * "address": "北京市海淀区中关村大街1号"
- * }
- * }
- *idid
- */
- public function getLocation()
- {
- $result = $this->service->getLocation(Auth::user()->id);
- return $this->success($result);
- }
- /**
- * [账户]设置排班时间
- *
- * @description 设置技师每天通用的排班时间段
- *
- * @authenticated
- *
- * @bodyParam time_ranges array required 时间段数组
- * @bodyParam time_ranges[].start_time string required 开始时间(HH:mm格式) Example: "09:00"
- * @bodyParam time_ranges[].end_time string required 结束时间(HH:mm格式) Example: "12:00"
- *
- * @response {
- * "status": true,
- * "message": "排班设置成功",
- * "data": {
- * "coach_id": 1,
- * "time_ranges": [
- * {
- * "start_time": "09:00",
- * "end_time": "12:00"
- * },
- * {
- * "start_time": "14:00",
- * "end_time": "18:00"
- * }
- * ]
- * }
- * }
- * @response 400 {
- * "message": "时间段格式错误"
- * }
- * @response 400 {
- * "message": "时间格式错误,应为HH:mm格式"
- * }
- * @response 400 {
- * "message": "结束时间必须大于开始时间"
- * }
- * @response 400 {
- * "message": "时间段之间不能重叠"
- * }
- */
- public function setSchedule(Request $request)
- {
- $validated = $request->validate([
- 'time_ranges' => 'required|array|min:1',
- 'time_ranges.*.start_time' => [
- 'required',
- 'string',
- 'regex:/^([01][0-9]|2[0-3]):[0-5][0-9]$/',
- ],
- 'time_ranges.*.end_time' => [
- 'required',
- 'string',
- 'regex:/^([01][0-9]|2[0-3]):[0-5][0-9]$/',
- ],
- ], [
- 'time_ranges.required' => '必须设置时间段',
- 'time_ranges.array' => '时间段必须是数组格式',
- 'time_ranges.min' => '至少设置一个时间段',
- 'time_ranges.*.start_time.required' => '开始时间不能为空',
- 'time_ranges.*.start_time.regex' => '开始时间格式错误,应为HH:mm格式',
- 'time_ranges.*.end_time.required' => '结束时间不能为空',
- 'time_ranges.*.end_time.regex' => '结束时间格式错误,应为HH:mm格式',
- ]);
- return $this->success(
- $this->service->setSchedule(Auth::user()->id, $validated['time_ranges'])
- );
- }
- /**
- * [账户]更改技师工作状态
- *
- * @description 更改技师的工作状态(休息中/工作中),工作状态会自动判断为空闲或忙碌
- *
- * @authenticated
- *
- * @bodyParam status int required 状态(1:休息中 2:工作中) Example: 2
- *
- * @response {
- * "status": true,
- * "message": "状态更新成功",
- * "data": {
- * "work_status": 2,
- * "work_status_text": "空闲中",
- * "updated_at": "2024-03-20 10:00:00"
- * }
- * }
- * @response 400 {
- * "message": "无效的状态值"
- * }
- * @response 422 {
- * "message": "当前状态不能更改为休息状态"
- * }
- */
- public function updateWorkStatus(Request $request)
- {
- $validated = $request->validate([
- 'status' => 'required|integer|in:1,2',
- ], [
- 'status.required' => '状态不能为空',
- 'status.integer' => '状态必须是整数',
- 'status.in' => '无效的状态值',
- ]);
- return $this->success(
- $this->service->updateWorkStatus(Auth::user()->id, $validated['status'])
- );
- }
- /**
- * [账户]获取技师工作状态
- *
- * @description 获取技师当前工作状态
- *
- * @authenticated
- *
- * @response {
- * "data": {
- * "work_status": 2,
- * "work_status_text": "空闲中",
- * "updated_at": "2024-03-22 10:00:00"
- * }
- * }
- * @response 404 {
- * "message": "技师不存在"
- * }
- */
- public function getWorkStatus()
- {
- return $this->success(
- $this->service->getWorkStatus(Auth::user()->coach->id)
- );
- }
- /**
- * [账户]获取技师排班信息
- *
- * @return \Illuminate\Http\JsonResponse
- *
- * @description 技师获取自己的排班时间段信息
- *
- * @response {
- * "status": true,
- * "message": "获取成功",
- * "data": {
- * "time_ranges": [
- * {
- * "start_time": "09:00",
- * "end_time": "12:00"
- * },
- * {
- * "start_time": "14:00",
- * "end_time": "18:00"
- * }
- * ],
- * "updated_at": "2024-03-20 10:00:00"
- * }
- * }
- */
- public function getSchedule()
- {
- $schedule = $this->service->getSchedule(Auth::id());
- return $this->success($schedule);
- }
- }
|