feat: [business-card] 명함신청 기능 구현
- 모델: BusinessCardRequest (pending/processed 상태 관리)
- 서비스: 신청/처리/통계/뱃지 카운트
- 컨트롤러: 관리자 2분할 뷰, 파트너 신청폼+이력
- 뷰: admin-index (대기/처리완료 2분할), partner-index (신청폼+이력)
- 라우트: GET/POST /sales/business-cards, POST /{id}/process
- 뱃지: ViewServiceProvider에 대기 건수 연동
This commit is contained in:
92
app/Http/Controllers/Sales/BusinessCardRequestController.php
Normal file
92
app/Http/Controllers/Sales/BusinessCardRequestController.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Sales;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Sales\BusinessCardRequestService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class BusinessCardRequestController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private BusinessCardRequestService $service
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 목록 페이지 (관리자: 관리뷰 / 파트너: 신청뷰)
|
||||
*/
|
||||
public function index(Request $request): View|Response
|
||||
{
|
||||
if ($request->header('HX-Request')) {
|
||||
return response('', 200)->header('HX-Redirect', route('sales.business-cards.index'));
|
||||
}
|
||||
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->isAdmin()) {
|
||||
$search = $request->get('search');
|
||||
$stats = $this->service->getStats();
|
||||
$pendingRequests = $this->service->getPendingRequests($search);
|
||||
$processedRequests = $this->service->getProcessedRequests($search);
|
||||
|
||||
return view('sales.business-cards.admin-index', compact(
|
||||
'stats',
|
||||
'pendingRequests',
|
||||
'processedRequests',
|
||||
'search'
|
||||
));
|
||||
}
|
||||
|
||||
$myRequests = $this->service->getMyRequests($user->id);
|
||||
|
||||
return view('sales.business-cards.partner-index', compact('user', 'myRequests'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 명함 신청 등록
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'phone' => 'required|string|max:20',
|
||||
'title' => 'nullable|string|max:50',
|
||||
'email' => 'nullable|email|max:100',
|
||||
'quantity' => 'nullable|integer|min:1|max:9999',
|
||||
'memo' => 'nullable|string|max:1000',
|
||||
]);
|
||||
|
||||
$this->service->createRequest($validated);
|
||||
|
||||
return redirect()->route('sales.business-cards.index')
|
||||
->with('success', '명함 신청이 완료되었습니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 처리 완료 (관리자 전용)
|
||||
*/
|
||||
public function process(Request $request, int $id)
|
||||
{
|
||||
if (! auth()->user()->isAdmin()) {
|
||||
abort(403, '관리자만 처리할 수 있습니다.');
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'process_memo' => 'nullable|string|max:1000',
|
||||
]);
|
||||
|
||||
$this->service->process($id, $validated['process_memo'] ?? null);
|
||||
|
||||
if ($request->expectsJson() || $request->header('Accept') === 'application/json') {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '처리가 완료되었습니다.',
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('sales.business-cards.index')
|
||||
->with('success', '처리가 완료되었습니다.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user