회원관련 모델생성

This commit is contained in:
sungro815 2026-01-19 10:19:09 +09:00
parent a45fc93f53
commit 86424023c8
14 changed files with 488 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?php
namespace App\Models\Member\Concerns;
trait HasNoTimestamps
{
public $timestamps = false;
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemAddress extends Model
{
use HasNoTimestamps;
protected $table = 'mem_address';
protected $primaryKey = 'seq';
public $incrementing = true;
protected $keyType = 'int';
protected $guarded = [];
public function member(): BelongsTo
{
return $this->belongsTo(MemInfo::class, 'mem_no', 'mem_no');
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemAuth extends Model
{
use HasNoTimestamps;
protected $table = 'mem_auth';
// 복합키라 Eloquent 기본 save/update 패턴이 불편함
// 조회는 모델로 하고, 쓰기(업서트)는 Repository로 통일 권장
protected $primaryKey = null;
public $incrementing = false;
protected $keyType = 'string';
protected $guarded = [];
public const TYPE_EMAIL = 'email';
public const TYPE_CELL = 'cell';
public const TYPE_ACCOUNT = 'account';
public const TYPE_OTP = 'otp';
public const TYPE_VOW = 'vow';
public const STATE_Y = 'Y'; // 완료
public const STATE_N = 'N'; // 미인증
public const STATE_P = 'P'; // 처리중
public const STATE_R = 'R'; // 요청
public function member(): BelongsTo
{
return $this->belongsTo(MemInfo::class, 'mem_no', 'mem_no');
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemAuthInfo extends Model
{
use HasNoTimestamps;
protected $table = 'mem_auth_info';
protected $primaryKey = 'mem_no';
public $incrementing = false;
protected $keyType = 'int';
protected $guarded = [];
protected $casts = [
'auth_info' => 'array',
];
public function member(): BelongsTo
{
return $this->belongsTo(MemInfo::class, 'mem_no', 'mem_no');
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemAuthLog extends Model
{
use HasNoTimestamps;
protected $table = 'mem_auth_log';
protected $primaryKey = 'seq';
public $incrementing = true;
protected $keyType = 'int';
protected $guarded = [];
protected $casts = [
'info' => 'array',
];
public const STATE_S = 'S'; // success
public const STATE_F = 'F'; // fail
public const STATE_P = 'P'; // pass/processing
public function member(): BelongsTo
{
return $this->belongsTo(MemInfo::class, 'mem_no', 'mem_no');
}
}

View File

@ -0,0 +1,87 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemInfo extends Model
{
use HasNoTimestamps;
protected $table = 'mem_info';
protected $primaryKey = 'mem_no';
protected $keyType = 'int';
public $incrementing = true;
// 테이블이 legacy라 fillable 대신 guarded 추천 (내부에서만 쓰면 []도 가능)
protected $guarded = [];
// zero-date 때문에 datetime/date cast는 걸지 않음 (필요시 별도 accessor로 안전 파싱)
protected $casts = [
'admin_memo' => 'array',
'modify_log' => 'array',
];
/* =====================
* Relationships
* ===================== */
public function authInfo(): HasOne
{
return $this->hasOne(MemAuthInfo::class, 'mem_no', 'mem_no');
}
public function authRows(): HasMany
{
// mem_auth 복합키 테이블이지만 조회 관계는 문제 없음
return $this->hasMany(MemAuth::class, 'mem_no', 'mem_no');
}
public function authLogs(): HasMany
{
return $this->hasMany(MemAuthLog::class, 'mem_no', 'mem_no');
}
public function addresses(): HasMany
{
return $this->hasMany(MemAddress::class, 'mem_no', 'mem_no');
}
public function joinLogs(): HasMany
{
return $this->hasMany(MemJoinLog::class, 'mem_no', 'mem_no');
}
public function stRing(): HasOne
{
return $this->hasOne(MemStRing::class, 'mem_no', 'mem_no');
}
public function loginRecents(): HasMany
{
return $this->hasMany(MemLoginRecent::class, 'mem_no', 'mem_no');
}
public function modLogs(): HasMany
{
return $this->hasMany(MemModLog::class, 'mem_no', 'mem_no');
}
/* =====================
* Helpers (optional)
* ===================== */
public function isWithdrawn(): bool
{
// legacy: dt_out 기본값이 0000-00-00... 이므로 문자열 비교로 처리
return isset($this->attributes['dt_out']) && $this->attributes['dt_out'] !== '0000-00-00 00:00:00';
}
public function hasEmail(): bool
{
return !empty($this->attributes['email']);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemJoinFilter extends Model
{
use HasNoTimestamps;
protected $table = 'mem_join_filter';
protected $primaryKey = 'seq';
public $incrementing = true;
protected $keyType = 'int';
protected $guarded = [];
protected $casts = [
'admin_phone' => 'array',
];
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemJoinLog extends Model
{
use HasNoTimestamps;
protected $table = 'mem_join_log';
protected $primaryKey = 'seq';
public $incrementing = true;
protected $keyType = 'int';
protected $guarded = [];
public function member(): BelongsTo
{
return $this->belongsTo(MemInfo::class, 'mem_no', 'mem_no');
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemLoginRecent extends Model
{
use HasNoTimestamps;
protected $table = 'mem_login_recent';
protected $primaryKey = 'seq';
public $incrementing = true;
protected $keyType = 'int';
protected $guarded = [];
public function member(): BelongsTo
{
return $this->belongsTo(MemInfo::class, 'mem_no', 'mem_no');
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use App\Models\Member\Concerns\HasNoTimestamps;
/**
* 연도별 테이블(mem_login_2026 ) 런타임에 붙이는 모델.
* 쓰기 : (new MemLoginYear())->forYear(2026)->create([...])
*/
class MemLoginYear extends Model
{
use HasNoTimestamps;
protected $primaryKey = 'seq';
public $incrementing = true;
protected $keyType = 'int';
protected $guarded = [];
public function forYear(int $year): self
{
$this->setTable('mem_login_' . $year);
return $this;
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemModLog extends Model
{
use HasNoTimestamps;
protected $table = 'mem_mod_log';
protected $primaryKey = 'seq';
public $incrementing = true;
protected $keyType = 'int';
protected $guarded = [];
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemPasswdModify extends Model
{
use HasNoTimestamps;
protected $table = 'mem_passwd_modify';
protected $primaryKey = 'seq';
public $incrementing = true;
protected $keyType = 'int';
protected $guarded = [];
protected $casts = [
'info' => 'array',
];
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Models\Member;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\Member\Concerns\HasNoTimestamps;
class MemStRing extends Model
{
use HasNoTimestamps;
protected $table = 'mem_st_ring';
protected $primaryKey = 'mem_no';
public $incrementing = false;
protected $keyType = 'int';
protected $guarded = [];
public function member(): BelongsTo
{
return $this->belongsTo(MemInfo::class, 'mem_no', 'mem_no');
}
}

View File

@ -0,0 +1,110 @@
<?php
namespace App\Repositories\Member;
use App\Models\Member\MemAuth;
use App\Models\Member\MemAuthInfo;
use App\Models\Member\MemAuthLog;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Carbon;
class MemberAuthRepository
{
/**
* mem_auth (mem_no, auth_type) 업서트
* - auth_date는 date 컬럼: Y-m-d
*/
public function upsertState(
int $memNo,
string $authType,
string $authState,
?string $authDate = null
): void {
$authDate = $authDate ?: Carbon::now()->toDateString();
DB::table('mem_auth')->updateOrInsert(
['mem_no' => $memNo, 'auth_type' => $authType],
['auth_state' => $authState, 'auth_date' => $authDate]
);
}
public function markRequested(int $memNo, string $authType, array $logInfo = []): void
{
$this->setStateWithLog($memNo, $authType, MemAuth::STATE_R, MemAuthLog::STATE_P, $logInfo);
}
public function markProcessing(int $memNo, string $authType, array $logInfo = []): void
{
$this->setStateWithLog($memNo, $authType, MemAuth::STATE_P, MemAuthLog::STATE_P, $logInfo);
}
public function markSuccess(int $memNo, string $authType, array $logInfo = []): void
{
$this->setStateWithLog($memNo, $authType, MemAuth::STATE_Y, MemAuthLog::STATE_S, $logInfo);
}
public function markFail(int $memNo, string $authType, array $logInfo = []): void
{
$this->setStateWithLog($memNo, $authType, MemAuth::STATE_N, MemAuthLog::STATE_F, $logInfo);
}
/**
* mem_auth_info.auth_info JSON에 타입별로 병합 저장
* - : ["email" => [...], "cell" => [...]]
*/
public function mergeAuthInfo(int $memNo, string $authType, array $payload): void
{
DB::transaction(function () use ($memNo, $authType, $payload) {
/** @var MemAuthInfo $row */
$row = MemAuthInfo::query()->find($memNo);
if (!$row) {
$row = new MemAuthInfo();
$row->mem_no = $memNo;
$row->auth_info = [];
}
$data = $row->auth_info ?: [];
$data[$authType] = array_merge($data[$authType] ?? [], $payload);
$row->auth_info = $data;
$row->save();
});
}
/**
* mem_auth 상태 변경 + mem_auth_log 기록을 트랜잭션으로
*/
private function setStateWithLog(
int $memNo,
string $authType,
string $authState,
string $logState,
array $logInfo
): void {
DB::transaction(function () use ($memNo, $authType, $authState, $logState, $logInfo) {
$this->upsertState($memNo, $authType, $authState);
MemAuthLog::query()->create([
'mem_no' => $memNo,
'type' => $authType,
'state' => $logState,
'info' => $logInfo,
'rgdate' => Carbon::now()->toDateTimeString(),
]);
});
}
public function getState(int $memNo, string $authType): ?string
{
return DB::table('mem_auth')
->where('mem_no', $memNo)
->where('auth_type', $authType)
->value('auth_state');
}
public function isVerified(int $memNo, string $authType): bool
{
return $this->getState($memNo, $authType) === MemAuth::STATE_Y;
}
}