93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
|
|
<?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', '처리가 완료되었습니다.');
|
||
|
|
}
|
||
|
|
}
|