feat: [pmis] PmisWorker 모델 분리 및 개인정보 관리 개선
- pmis_workers 전용 모델 생성 (SAM 사원관리와 분리) - 프로필 API 응답 worker 키로 변경 - 직책/소속업체 편집 기능 추가 - React 컴포넌트 data.user → data.worker 전환
This commit is contained in:
84
app/Models/Juil/PmisWorker.php
Normal file
84
app/Models/Juil/PmisWorker.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Juil;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class PmisWorker extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'user_id',
|
||||
'name',
|
||||
'login_id',
|
||||
'phone',
|
||||
'email',
|
||||
'department',
|
||||
'position',
|
||||
'role_type',
|
||||
'gender',
|
||||
'company',
|
||||
'profile_photo_path',
|
||||
'options',
|
||||
'last_login_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'options' => 'array',
|
||||
'last_login_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* SAM 로그인 사용자로부터 PMIS Worker 자동 생성 (최초 접근 시)
|
||||
*/
|
||||
public static function findOrCreateFromUser(User $user, int $tenantId = 1): self
|
||||
{
|
||||
$worker = self::where('tenant_id', $tenantId)
|
||||
->where('user_id', $user->id)
|
||||
->first();
|
||||
|
||||
if ($worker) {
|
||||
return $worker;
|
||||
}
|
||||
|
||||
// 부서명 조회
|
||||
$departments = $user->getDepartmentsForTenant($tenantId);
|
||||
$deptName = $departments->first()?->name ?? null;
|
||||
|
||||
return self::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'user_id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'login_id' => $user->user_id,
|
||||
'phone' => $user->phone,
|
||||
'email' => $user->email,
|
||||
'department' => $deptName,
|
||||
'role_type' => $user->role ?? '사용자',
|
||||
'profile_photo_path' => $user->profile_photo_path,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getOption(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return data_get($this->options, $key, $default);
|
||||
}
|
||||
|
||||
public function setOption(string $key, mixed $value): self
|
||||
{
|
||||
$options = $this->options ?? [];
|
||||
$options[$key] = $value;
|
||||
$this->options = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user