2026-02-24 21:45:08 +09:00
|
|
|
<?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';
|
|
|
|
|
|
2026-02-25 05:41:34 +09:00
|
|
|
public const STATUS_ORDERED = 'ordered';
|
|
|
|
|
|
2026-02-24 21:45:08 +09:00
|
|
|
public const STATUS_PROCESSED = 'processed';
|
|
|
|
|
|
|
|
|
|
public const STATUS_LABELS = [
|
2026-02-25 05:41:34 +09:00
|
|
|
self::STATUS_PENDING => '요청',
|
|
|
|
|
self::STATUS_ORDERED => '제작의뢰',
|
2026-02-24 21:45:08 +09:00
|
|
|
self::STATUS_PROCESSED => '처리완료',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'tenant_id',
|
|
|
|
|
'user_id',
|
|
|
|
|
'name',
|
|
|
|
|
'phone',
|
|
|
|
|
'title',
|
|
|
|
|
'email',
|
|
|
|
|
'quantity',
|
|
|
|
|
'memo',
|
|
|
|
|
'status',
|
2026-02-25 05:41:34 +09:00
|
|
|
'ordered_by',
|
|
|
|
|
'ordered_at',
|
2026-02-24 21:45:08 +09:00
|
|
|
'processed_by',
|
|
|
|
|
'processed_at',
|
|
|
|
|
'process_memo',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
2026-02-25 05:41:34 +09:00
|
|
|
'ordered_at' => 'datetime',
|
2026-02-24 21:45:08 +09:00
|
|
|
'processed_at' => 'datetime',
|
|
|
|
|
'quantity' => 'integer',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $attributes = [
|
|
|
|
|
'status' => self::STATUS_PENDING,
|
|
|
|
|
'quantity' => 100,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// =========================================================================
|
|
|
|
|
// 관계
|
|
|
|
|
// =========================================================================
|
|
|
|
|
|
|
|
|
|
public function requester(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 05:41:34 +09:00
|
|
|
public function orderer(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'ordered_by');
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 21:45:08 +09:00
|
|
|
public function processor(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'processed_by');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =========================================================================
|
|
|
|
|
// 스코프
|
|
|
|
|
// =========================================================================
|
|
|
|
|
|
|
|
|
|
public function scopePending($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', self::STATUS_PENDING);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 05:41:34 +09:00
|
|
|
public function scopeOrdered($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', self::STATUS_ORDERED);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 21:45:08 +09:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 05:41:34 +09:00
|
|
|
public function getIsOrderedAttribute(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->status === self::STATUS_ORDERED;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 21:45:08 +09:00
|
|
|
// =========================================================================
|
|
|
|
|
// 헬퍼 메서드
|
|
|
|
|
// =========================================================================
|
|
|
|
|
|
2026-02-25 05:41:34 +09:00
|
|
|
public function markAsOrdered(int $orderedBy): bool
|
2026-02-24 21:45:08 +09:00
|
|
|
{
|
|
|
|
|
if (! $this->is_pending) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 05:41:34 +09:00
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 21:45:08 +09:00
|
|
|
$this->status = self::STATUS_PROCESSED;
|
|
|
|
|
$this->processed_by = $processedBy;
|
|
|
|
|
$this->processed_at = now();
|
|
|
|
|
$this->process_memo = $memo;
|
|
|
|
|
|
|
|
|
|
return $this->save();
|
|
|
|
|
}
|
|
|
|
|
}
|