fix:coach相關改provider

This commit is contained in:
2025-05-12 01:22:09 +08:00
parent 3d7660a24c
commit 125d4bf8d8
10 changed files with 433 additions and 165 deletions
+16
View File
@@ -5,6 +5,22 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @OA\Schema(
* schema="AdminProfile",
* title="管理員個人資料",
* description="管理員的詳細個人資料",
* @OA\Property(property="id", type="integer", format="int64", example=1, description="資料ID"),
* @OA\Property(property="user_id", type="integer", format="int64", example=1, description="關聯的使用者ID"),
* @OA\Property(property="position", type="string", example="系統管理員", description="職位"),
* @OA\Property(property="department", type="string", example="IT部門", description="部門"),
* @OA\Property(property="permissions", type="array", description="權限列表",
* @OA\Items(type="string", example="manage_users")
* ),
* @OA\Property(property="created_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="創建時間"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="更新時間")
* )
*/
class AdminProfile extends Model
{
use HasFactory;
+17
View File
@@ -4,6 +4,23 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @OA\Schema(
* schema="CoachProfile",
* title="教練個人資料",
* description="教練的詳細個人資料",
* @OA\Property(property="id", type="integer", format="int64", example=1, description="資料ID"),
* @OA\Property(property="user_id", type="integer", format="int64", example=1, description="關聯的使用者ID"),
* @OA\Property(property="bio", type="string", example="專業潛水教練,擁有10年教學經驗", description="個人簡介"),
* @OA\Property(property="expertise", type="string", example="自由潛水,水肺潛水", description="專長領域"),
* @OA\Property(property="certification", type="string", example="PADI專業潛水教練", description="證照資訊"),
* @OA\Property(property="experience", type="string", example="10年教學經驗,帶領超過500名學員", description="教學經驗"),
* @OA\Property(property="rating", type="number", format="float", example=4.8, description="評分"),
* @OA\Property(property="availability", type="string", example="週一至週五 09:00-18:00", description="可授課時間"),
* @OA\Property(property="created_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="創建時間"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="更新時間")
* )
*/
class CoachProfile extends Model
{
/**
+21 -5
View File
@@ -5,6 +5,22 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @OA\Schema(
* schema="MemberProfile",
* title="會員個人資料",
* description="會員的詳細個人資料",
* @OA\Property(property="id", type="integer", format="int64", example=1, description="資料ID"),
* @OA\Property(property="user_id", type="integer", format="int64", example=1, description="關聯的使用者ID"),
* @OA\Property(property="birthday", type="string", format="date", example="1990-01-01", description="生日"),
* @OA\Property(property="gender", type="string", enum={"male", "female", "other"}, example="male", description="性別"),
* @OA\Property(property="address", type="string", example="台北市信義區某街123號", description="地址"),
* @OA\Property(property="emergency_contact", type="string", example="王大明", description="緊急聯絡人"),
* @OA\Property(property="emergency_phone", type="string", example="0987654321", description="緊急聯絡電話"),
* @OA\Property(property="created_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="創建時間"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="更新時間")
* )
*/
class MemberProfile extends Model
{
use HasFactory;
@@ -67,17 +83,17 @@ class MemberProfile extends Model
}
/**
* 獲取會員的教練
* 獲取會員的服務提供者
*/
public function coaches()
public function providers()
{
return $this->hasManyThrough(
CoachProfile::class,
'coach_member',
ProviderProfile::class,
'provider_member',
'member_id',
'user_id',
'user_id',
'coach_id'
'provider_id'
);
}
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @OA\Schema(
* schema="ProviderProfile",
* title="潛水業者資料",
* description="潛水業者的詳細資料",
* @OA\Property(property="id", type="integer", format="int64", example=1, description="資料ID"),
* @OA\Property(property="user_id", type="integer", format="int64", example=1, description="關聯的使用者ID"),
* @OA\Property(property="business_name", type="string", example="藍海潛水中心", description="業者名稱"),
* @OA\Property(property="business_license", type="string", example="A123456789", description="營業執照號碼"),
* @OA\Property(property="description", type="string", example="專業潛水中心,提供各種潛水課程和裝備租賃服務", description="業者描述"),
* @OA\Property(property="contact_person", type="string", example="張三", description="聯絡人"),
* @OA\Property(property="contact_phone", type="string", example="0912345678", description="聯絡電話"),
* @OA\Property(property="contact_email", type="string", example="contact@bluedive.com", description="聯絡電子郵件"),
* @OA\Property(property="address", type="string", example="台灣屏東縣恆春鎮XXX路123號", description="營業地址"),
* @OA\Property(property="dive_sites", type="string", example="墾丁,綠島,蘭嶼", description="提供的潛點"),
* @OA\Property(property="services", type="string", example="體驗潛水,初級潛水課程,進階潛水課程,裝備租賃", description="提供的服務"),
* @OA\Property(property="certifications", type="string", example="PADI五星級潛水中心,SSI認證中心", description="業者相關認證"),
* @OA\Property(property="facilities", type="string", example="空氣填充站,沖洗區,更衣室,休息區", description="設施"),
* @OA\Property(property="business_hours", type="string", example="週一至週五 09:00-18:00,週六日 08:00-19:00", description="營業時間"),
* @OA\Property(property="is_verified", type="boolean", example=true, description="是否通過平台驗證"),
* @OA\Property(property="rating", type="number", format="float", example=4.8, description="評分"),
* @OA\Property(property="website", type="string", example="https://www.bluedive.com", description="官方網站"),
* @OA\Property(property="social_media", type="string", example="https://www.facebook.com/bluedive", description="社群媒體連結"),
* @OA\Property(property="logo_url", type="string", example="https://example.com/logo.png", description="業者標誌URL"),
* @OA\Property(property="banner_url", type="string", example="https://example.com/banner.png", description="業者橫幅URL"),
* @OA\Property(property="is_active", type="boolean", example=true, description="是否啟用"),
* @OA\Property(property="created_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="創建時間"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="更新時間")
* )
*/
class ProviderProfile extends Model
{
/**
* 可以批量分配的屬性
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'business_name',
'business_license',
'description',
'contact_person',
'contact_phone',
'contact_email',
'address',
'dive_sites',
'services',
'certifications',
'facilities',
'business_hours',
'is_verified',
'rating',
'website',
'social_media',
'logo_url',
'banner_url',
'is_active'
];
/**
* 與用戶的關聯
*/
public function user()
{
return $this->belongsTo(User::class);
}
}
+37 -19
View File
@@ -11,6 +11,24 @@ use Laravel\Sanctum\HasApiTokens;
* User 使用者模型
*
* 對應 users 資料表,並提供角色判斷、關聯資料取得等功能。
*
* @OA\Schema(
* schema="User",
* title="使用者",
* description="使用者資料模型",
* @OA\Property(property="id", type="integer", format="int64", example=1, description="使用者ID"),
* @OA\Property(property="name", type="string", example="王小明", description="使用者姓名"),
* @OA\Property(property="email", type="string", format="email", example="user@example.com", description="電子郵件"),
* @OA\Property(property="phone", type="string", example="0912345678", description="電話號碼"),
* @OA\Property(property="role", type="string", enum={"member", "provider", "admin"}, example="member", description="角色"),
* @OA\Property(property="is_active", type="boolean", example=true, description="是否啟用"),
* @OA\Property(property="email_verified_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="電子郵件驗證時間"),
* @OA\Property(property="created_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="創建時間"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2023-01-01T00:00:00.000000Z", description="更新時間"),
* @OA\Property(property="memberProfile", type="object", ref="#/components/schemas/MemberProfile", description="會員詳細資料"),
* @OA\Property(property="providerProfile", type="object", ref="#/components/schemas/ProviderProfile", description="服務提供者詳細資料"),
* @OA\Property(property="adminProfile", type="object", ref="#/components/schemas/AdminProfile", description="管理員詳細資料")
* )
*/
class User extends Authenticatable
{
@@ -75,15 +93,15 @@ class User extends Authenticatable
}
/**
* 判斷用戶是否為教練
* 判斷用戶是否為服務提供者
*/
/**
* 判斷用戶是否為教練
* 判斷用戶是否為服務提供者
* @return bool
*/
public function isCoach()
public function isProvider()
{
return $this->role === 'coach';
return $this->role === 'provider';
}
/**
@@ -111,15 +129,15 @@ class User extends Authenticatable
}
/**
* 獲取用戶的教練資料
* 獲取用戶的服務提供者資料
*/
/**
* 取得用戶的教練詳細資料(關聯 coach_profiles
* 取得用戶的服務提供者詳細資料(關聯 provider_profiles
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function coachProfile()
public function providerProfile()
{
return $this->hasOne(CoachProfile::class);
return $this->hasOne(ProviderProfile::class);
}
/**
@@ -145,45 +163,45 @@ class User extends Authenticatable
{
if ($this->isAdmin()) {
return $this->adminProfile;
} elseif ($this->isCoach()) {
return $this->coachProfile;
} elseif ($this->isProvider()) {
return $this->providerProfile;
} else {
return $this->memberProfile;
}
}
/**
* 獲取教練的會員 (僅適用於教練角色)
* 獲取服務提供者的會員 (僅適用於服務提供者角色)
*/
/**
* 取得教練所帶的會員(僅教練角色適用)
* 取得服務提供者所帶的會員(僅服務提供者角色適用)
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany|null
*/
public function members()
{
if (!$this->isCoach()) {
if (!$this->isProvider()) {
return null;
}
return $this->belongsToMany(User::class, 'coach_member', 'coach_id', 'member_id')
return $this->belongsToMany(User::class, 'provider_member', 'provider_id', 'member_id')
->where('role', 'member');
}
/**
* 獲取會員的教練 (僅適用於會員角色)
* 獲取會員的服務提供者 (僅適用於會員角色)
*/
/**
* 取得會員對應的教練(僅會員角色適用)
* 取得會員對應的服務提供者(僅會員角色適用)
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany|null
*/
public function coaches()
public function providers()
{
if (!$this->isMember()) {
return null;
}
return $this->belongsToMany(User::class, 'coach_member', 'member_id', 'coach_id')
->where('role', 'coach');
return $this->belongsToMany(User::class, 'provider_member', 'member_id', 'provider_id')
->where('role', 'provider');
}
/**