소스 검색

feat:用户端-查看申请技师记录-无申请情况

刘学玺 4 달 전
부모
커밋
931013bacd
4개의 변경된 파일77개의 추가작업 그리고 159개의 파일을 삭제
  1. 24 8
      app/Http/Controllers/Client/UserController.php
  2. 11 138
      app/Models/CoachUser.php
  3. 10 13
      app/Services/Client/UserService.php
  4. 32 0
      app/Traits/HasStateText.php

+ 24 - 8
app/Http/Controllers/Client/UserController.php

@@ -8,6 +8,7 @@ use App\Http\Requests\Client\User\FeedbackRequest;
 use App\Http\Requests\Client\User\RegisterRequest;
 use App\Http\Requests\Client\User\UpdateRequest;
 use App\Services\Client\UserService;
+use Illuminate\Support\Facades\Auth;
 
 /**
  * @group 用户端
@@ -205,7 +206,7 @@ class UserController extends Controller
      *     "work_years": 5,
      *     "intention_city": "杭州",
      *     "portrait_images": ["https://example.com/portrait1.jpg"],
-     *     "introduction": "专��按摩师,有多年经验",
+     *     "introduction": "专按摩师,有多年经验",
      *     "state": "auditing",
      *     "created_at": "2024-03-20 10:00:00",
      *     "updated_at": "2024-03-20 10:00:00"
@@ -295,7 +296,7 @@ class UserController extends Controller
     /**
      * [用户]查看技师申请记录
      *
-     * @description 获取当前用户的技师申请记录
+     * @description 获取当前用户的技师申请记录,如果用户不是技师或没有申请记录则返回 null
      *
      * @authenticated
      *
@@ -318,21 +319,36 @@ class UserController extends Controller
      *     "updated_at": "2024-03-20 10:00:00"
      *   }
      * }
+     * @response 200 {
+     *   "code": 200,
+     *   "message": "您还不是技师",
+     *   "data": null
+     * }
+     * @response 200 {
+     *   "code": 200,
+     *   "message": "暂无申请记录",
+     *   "data": null
+     * }
      * @response 401 {
      *   "code": 401,
      *   "message": "请先登录",
      *   "data": null
      * }
-     * @response 404 {
-     *   "code": 404,
-     *   "message": "未找到申请记录",
-     *   "data": null
-     * }
      */
     public function getCoachApplication()
     {
         $result = $this->service->getCoachApplication();
 
-        return $this->success($result);
+        // 如果用户不是技师
+        if ($result === null && ! Auth::user()->coach) {
+            return $this->success(null, '您还不是技师');
+        }
+
+        // 如果是技师但没有申请记录
+        if ($result === null) {
+            return $this->success(null, '暂无申请记录');
+        }
+
+        return $this->success($result, '获取成功');
     }
 }

+ 11 - 138
app/Models/CoachUser.php

@@ -2,167 +2,40 @@
 
 namespace App\Models;
 
+use App\Enums\TechnicianStatus;
+use App\Traits\HasStateText;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use Slowlyo\OwlAdmin\Models\BaseModel as Model;
 
 /**
- * 技师
+ * 技师用户模型
  */
 class CoachUser extends Model
 {
-    use SoftDeletes;
+    use HasStateText, SoftDeletes;
 
     protected $table = 'coach_users';
 
     protected $guarded = [];
 
-    protected static function booted()
-    {
-        static::created(function ($user) {
-            $user->wallet()->create([
-                'owner_type' => CoachUser::class,
-                'owner_id' => $user->id,
-            ]);
-        });
-    }
-
     /**
-     * @Author FelixYin
-     *
-     * @description 技师所属会员
+     * 状态枚举类
      */
-    public function member()
-    {
-        return $this->belongsTo('App\Models\MemberUser', 'user_id');
-    }
+    protected string $stateEnumClass = TechnicianStatus::class;
 
     /**
-     * @Author FelixYin
-     *
-     * @description 技师关联信息
+     * 获取技师的基本信息
      */
     public function info()
     {
-        return $this->hasOne('App\Models\CoachInfoRecord', 'id', 'info_record_id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 技师关联资质信息
-     */
-    public function qual()
-    {
-        return $this->hasOne('App\Models\CoachQualRecord', 'id', 'qualification_record_id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 技师关联评分
-     */
-    public function score()
-    {
-        return $this->hasOne('App\Models\CoachScore', 'coach_id', 'id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 技师关联定位
-     */
-    public function locations()
-    {
-        return $this->hasMany('App\Models\CoachLocation', 'coach_id', 'id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 技师关联抢单记录
-     */
-    public function grabRecords()
-    {
-        return $this->hasMany('App\Models\OrderGrabRecord', 'coach_id', 'id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 技师关联评论
-     */
-    public function comments()
-    {
-        return $this->hasMany('App\Models\OrderComment', 'coach_id', 'id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 技师所属店铺
-     */
-    public function shop()
-    {
-        return $this->belongsTo('App\Models\ShopInfo', 'shop_id', 'shop_id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 技师关联店铺开通服务
-     */
-    public function shopOpenService()
-    {
-        return $this->hasMany('App\Models\ShopCoachService', 'coach_id', 'id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 技师关联实名信息
-     */
-    public function real()
-    {
-        return $this->hasOne('App\Models\CoachRealRecord', 'id', 'real_auth_record_id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 技师开通项目
-     */
-    public function projects()
-    {
-        return $this->hasMany('App\Models\CoachProject', 'coach_id', 'id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 基本信息认证记录
-     */
-    public function infoRecords()
-    {
-        return $this->hasMany('App\Models\CoachInfoRecord', 'coach_id', 'id');
-    }
-
-    /**
-     * @Author FelixYin
-     *
-     * @description 技师关联资质记录
-     */
-    public function qualRecords()
-    {
-        return $this->hasMany('App\Models\CoachQualRecord', 'coach_id', 'id');
+        return $this->belongsTo(CoachInfoRecord::class, 'info_record_id');
     }
 
     /**
-     * @Author FelixYin
-     *
-     * @description 技师关联实名认证记录
+     * 获取技师关联的用户
      */
-    public function realAuthRecords()
+    public function user()
     {
-        return $this->hasMany('App\Models\CoachRealAuthRecord', 'coach_id', 'id');
+        return $this->belongsTo(MemberUser::class, 'user_id');
     }
 }

+ 10 - 13
app/Services/Client/UserService.php

@@ -509,7 +509,7 @@ class UserService
                 'qr_code' => $qrCode,
             ];
         } catch (\Exception $e) {
-            Log::error('生成邀请码失���', [
+            Log::error('生成邀请码失', [
                 'error' => $e->getMessage(),
                 'user_id' => Auth::id(),
                 'type' => $type,
@@ -559,7 +559,7 @@ class UserService
      * 根据类型生成邀请码
      *
      * 业务逻辑:
-     * 1. 合类型和ID
+     * 1. ��合类型和ID
      * 2. 生成格式化的邀请码
      *
      * @param  string  $type  邀请类型(user/coach)
@@ -615,28 +615,25 @@ class UserService
      *
      * 业务逻辑:
      * 1. 获取当前用户的技师信息
-     * 2. 如果用户不是技师,返回 404
+     * 2. 如果用户不是技师,返回 null
      * 3. 获取最新的申请记录
      *
-     * @return CoachInfoRecord 返回申请记录
-     *
-     * @throws \Illuminate\Http\Exceptions\HttpResponseException 未找到申请记录时抛出异常
+     * @return CoachInfoRecord|null 返回申请记录,未找到时返回 null
      */
-    public function getCoachApplication(): CoachInfoRecord
+    public function getCoachApplication(): ?CoachInfoRecord
     {
         try {
             // 1. 获取当前用户的技师信息
             $user = $this->getAndValidateUser();
             $coach = $user->coach;
 
-            // 2. 如果用户不是技师,返回 404
-            abort_if(! $coach, 404, '未找到申请记录');
+            // 2. 如果用户不是技师,返回 null
+            if (! $coach) {
+                return null;
+            }
 
             // 3. 获取最新的申请记录
-            $application = $coach->info;
-            abort_if(! $application, 404, '未找到申请记录');
-
-            return $application;
+            return $coach->info;
         } catch (\Exception $e) {
             // 记录错误日志
             Log::error('获取技师申请记录失败', [

+ 32 - 0
app/Traits/HasStateText.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace App\Traits;
+
+/**
+ * 状态文本转换 Trait
+ */
+trait HasStateText
+{
+    /**
+     * 获取状态文本
+     */
+    public function getStateTextAttribute(): string
+    {
+        if (! isset($this->stateEnumClass)) {
+            return '未知状态';
+        }
+
+        $enumClass = $this->stateEnumClass;
+
+        return $enumClass::fromValue($this->state)?->label() ?? '未知状态';
+    }
+
+    /**
+     * 初始化 HasStateText trait
+     */
+    public function initializeHasStateText(): void
+    {
+        // 自动添加 state_text 到 appends 数组
+        $this->append('state_text');
+    }
+}