Files
sam-manage/app/Models/Sales/BusinessCardRequest.php
김보곤 85c7a55d00 feat: [business-card] 3단계 워크플로우 구현 (요청→제작의뢰→처리완료)
- 모델: STATUS_ORDERED 추가, markAsOrdered() 헬퍼
- 서비스: order(), getOrderedRequests() 추가
- 컨트롤러: order() 액션 추가
- 관리자 뷰: 좌측 신규요청 + 우측 제작중 + 하단 처리완료
- 파트너 뷰: 제작중(파란) 상태 뱃지 추가
- 라우트: POST business-cards/{id}/order 추가
2026-02-25 05:41:34 +09:00

144 lines
3.6 KiB
PHP

<?php
namespace App\Models\Sales;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class BusinessCardRequest extends Model
{
public const STATUS_PENDING = 'pending';
public const STATUS_ORDERED = 'ordered';
public const STATUS_PROCESSED = 'processed';
public const STATUS_LABELS = [
self::STATUS_PENDING => '요청',
self::STATUS_ORDERED => '제작의뢰',
self::STATUS_PROCESSED => '처리완료',
];
protected $fillable = [
'tenant_id',
'user_id',
'name',
'phone',
'title',
'email',
'quantity',
'memo',
'status',
'ordered_by',
'ordered_at',
'processed_by',
'processed_at',
'process_memo',
];
protected $casts = [
'ordered_at' => 'datetime',
'processed_at' => 'datetime',
'quantity' => 'integer',
];
protected $attributes = [
'status' => self::STATUS_PENDING,
'quantity' => 100,
];
// =========================================================================
// 관계
// =========================================================================
public function requester(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function orderer(): BelongsTo
{
return $this->belongsTo(User::class, 'ordered_by');
}
public function processor(): BelongsTo
{
return $this->belongsTo(User::class, 'processed_by');
}
// =========================================================================
// 스코프
// =========================================================================
public function scopePending($query)
{
return $query->where('status', self::STATUS_PENDING);
}
public function scopeOrdered($query)
{
return $query->where('status', self::STATUS_ORDERED);
}
public function scopeProcessed($query)
{
return $query->where('status', self::STATUS_PROCESSED);
}
public function scopeOfTenant($query, int $tenantId)
{
return $query->where('tenant_id', $tenantId);
}
// =========================================================================
// 접근자
// =========================================================================
public function getStatusLabelAttribute(): string
{
return self::STATUS_LABELS[$this->status] ?? $this->status;
}
public function getIsPendingAttribute(): bool
{
return $this->status === self::STATUS_PENDING;
}
public function getIsOrderedAttribute(): bool
{
return $this->status === self::STATUS_ORDERED;
}
// =========================================================================
// 헬퍼 메서드
// =========================================================================
public function markAsOrdered(int $orderedBy): bool
{
if (! $this->is_pending) {
return false;
}
$this->status = self::STATUS_ORDERED;
$this->ordered_by = $orderedBy;
$this->ordered_at = now();
return $this->save();
}
public function markAsProcessed(int $processedBy, ?string $memo = null): bool
{
if (! $this->is_ordered) {
return false;
}
$this->status = self::STATUS_PROCESSED;
$this->processed_by = $processedBy;
$this->processed_at = now();
$this->process_memo = $memo;
return $this->save();
}
}