Ver Fonte

fixed:技师端-获取技师详情

刘学玺 há 4 meses atrás
pai
commit
2e936705aa

+ 2 - 6
app/Http/Controllers/Coach/AccountController.php

@@ -452,9 +452,7 @@ class AccountController extends Controller
      *   "status": true,
      *   "message": "获取成功",
      *   "data": {
-     *     "id": 1,
      *     "coach_no": "00000001",
-     *     "user_id": 100,
      *     "mobile": "13800138000",
      *     "nickname": "张三",
      *     "avatar": "https://example.com/avatar.jpg",
@@ -469,16 +467,14 @@ class AccountController extends Controller
      *     "introduction": "专业按摩师,从业5年",
      *     "state": 1,
      *     "state_text": "正常",
-     *     "invite_code": "coach_1",
+     *     "invite_code": "C1",
      *     "wallet": {
      *       "balance": 1000,
      *       "frozen": 200,
      *       "total_income": 5000,
      *       "today_income": 300,
      *       "withdrawable": 800
-     *     },
-     *     "created_at": "2024-03-20 10:00:00",
-     *     "updated_at": "2024-03-20 10:00:00"
+     *     }
      *   }
      * }
      * @response 404 {

+ 22 - 6
app/Services/Coach/AccountService.php

@@ -1077,6 +1077,26 @@ class AccountService
         return Redis::geoadd('coach_locations', $longitude, $latitude, $key);
     }
 
+    /**
+     * 获取技师最新基本信息
+     *
+     * @param CoachUser $coach 技师对象
+     * @return CoachInfoRecord 最新的基本信息记录
+     * @throws \Illuminate\Http\Exceptions\HttpResponseException 当信息不存在时抛出404异常
+     */
+    private function getLatestBaseInfo(CoachUser $coach): CoachInfoRecord
+    {
+        // 获取最新的技师信息记录(排除审核拒绝的记录)
+        $latestInfo = $coach->infoRecords()
+            ->where('state', '<>', TechnicianAuthStatus::REJECTED->value)
+            ->latest()
+            ->first();
+
+        abort_if(!$latestInfo, 404, '技师基本信息不存在');
+
+        return $latestInfo;
+    }
+
     /**
      * 获取技师详细信息
      *
@@ -1099,12 +1119,8 @@ class AccountService
         $coach = $user->coach;
         abort_if(!$coach, 404, '技师信息不存在');
 
-        // 获取最新的技师信息记录(排除审核拒绝的记录)
-        $latestInfo = CoachInfoRecord::where('coach_id', $coach->id)
-            ->where('state', '<>', TechnicianAuthStatus::REJECTED->value)
-            ->latest()
-            ->first();
-        abort_if(!$latestInfo, 404, '技师基本信息不存在');
+        // 获取最新的基本信息记录
+        $latestInfo = $this->getLatestBaseInfo($coach);
 
         // 生成技师工号(例如:8位数字,不足前面补0)
         $coachNo = str_pad($coach->id, 8, '0', STR_PAD_LEFT);