Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CorporateVehicle;
|
||||
use App\Models\VehicleLog;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CorporateVehicleController extends Controller
|
||||
@@ -50,6 +52,19 @@ public function list(Request $request): JsonResponse
|
||||
|
||||
$vehicles = $query->orderBy('created_at', 'desc')->get();
|
||||
|
||||
// 각 차량의 운행기록 주행거리 합계 조회
|
||||
$vehicleIds = $vehicles->pluck('id');
|
||||
$logDistances = VehicleLog::whereIn('vehicle_id', $vehicleIds)
|
||||
->select('vehicle_id', DB::raw('SUM(distance_km) as total_log_distance'))
|
||||
->groupBy('vehicle_id')
|
||||
->pluck('total_log_distance', 'vehicle_id');
|
||||
|
||||
// total_mileage = 초기 주행거리 + 운행기록 합계
|
||||
$vehicles->each(function ($vehicle) use ($logDistances) {
|
||||
$vehicle->log_distance = (int) ($logDistances[$vehicle->id] ?? 0);
|
||||
$vehicle->total_mileage = ($vehicle->mileage ?? 0) + $vehicle->log_distance;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $vehicles,
|
||||
|
||||
@@ -195,12 +195,12 @@ public function index(Request $request): JsonResponse
|
||||
->concat($manualRecords)
|
||||
->values();
|
||||
|
||||
// 홈택스 매출 (과세 + 영세만, 면세 제외)
|
||||
// 홈택스 매출 전자세금계산서 (과세 + 영세만, 면세 제외)
|
||||
$hometaxSalesTaxable = $hometaxSalesRecords->whereIn('taxType', ['taxable', 'zero_rated']);
|
||||
$hometaxSalesSupply = $hometaxSalesTaxable->sum('supplyAmount');
|
||||
$hometaxSalesVat = $hometaxSalesTaxable->sum('vatAmount');
|
||||
|
||||
// 홈택스 매입 세금계산서 (과세 + 영세만, 면세 제외)
|
||||
// 홈택스 매입 전자세금계산서 (과세 + 영세만, 면세 제외)
|
||||
$hometaxPurchaseTaxable = $hometaxPurchaseRecords->whereIn('taxType', ['taxable', 'zero_rated']);
|
||||
$hometaxPurchaseSupply = $hometaxPurchaseTaxable->sum('supplyAmount');
|
||||
$hometaxPurchaseVat = $hometaxPurchaseTaxable->sum('vatAmount');
|
||||
@@ -208,23 +208,42 @@ public function index(Request $request): JsonResponse
|
||||
// 홈택스 면세 계산서 (매입 + 매출 모두)
|
||||
$exemptSalesSupply = $hometaxSalesRecords->where('taxType', 'exempt')->sum('supplyAmount');
|
||||
$exemptPurchaseSupply = $hometaxPurchaseRecords->where('taxType', 'exempt')->sum('supplyAmount');
|
||||
$exemptSupply = $exemptSalesSupply + $exemptPurchaseSupply;
|
||||
|
||||
// 카드 매입
|
||||
$cardPurchaseSupply = $cardRecords->sum('supplyAmount');
|
||||
$cardPurchaseVat = $cardRecords->sum('vatAmount');
|
||||
$manualSalesSupply = $manualRecords->where('type', 'sales')->sum('supplyAmount');
|
||||
$manualSalesVat = $manualRecords->where('type', 'sales')->sum('vatAmount');
|
||||
$manualPurchaseSupply = $manualRecords->where('type', 'purchase')->sum('supplyAmount');
|
||||
$manualPurchaseVat = $manualRecords->where('type', 'purchase')->sum('vatAmount');
|
||||
|
||||
// 수동입력 매출 종이세금계산서 (과세+영세)
|
||||
$manualSalesTaxable = $manualRecords->where('type', 'sales')->whereIn('taxType', ['taxable', 'zero_rated']);
|
||||
$manualSalesSupply = $manualSalesTaxable->sum('supplyAmount');
|
||||
$manualSalesVat = $manualSalesTaxable->sum('vatAmount');
|
||||
|
||||
// 수동입력 매입 종이세금계산서 (과세+영세)
|
||||
$manualPurchaseTaxable = $manualRecords->where('type', 'purchase')->whereIn('taxType', ['taxable', 'zero_rated']);
|
||||
$manualPurchaseSupply = $manualPurchaseTaxable->sum('supplyAmount');
|
||||
$manualPurchaseVat = $manualPurchaseTaxable->sum('vatAmount');
|
||||
|
||||
// 수동입력 면세 계산서
|
||||
$manualExemptSalesSupply = $manualRecords->where('type', 'sales')->where('taxType', 'exempt')->sum('supplyAmount');
|
||||
$manualExemptPurchaseSupply = $manualRecords->where('type', 'purchase')->where('taxType', 'exempt')->sum('supplyAmount');
|
||||
|
||||
// 면세 계산서 합계 (홈택스 + 수동)
|
||||
$exemptSupply = $exemptSalesSupply + $exemptPurchaseSupply + $manualExemptSalesSupply + $manualExemptPurchaseSupply;
|
||||
|
||||
$stats = [
|
||||
'salesSupply' => $hometaxSalesSupply + $manualSalesSupply,
|
||||
'salesVat' => $hometaxSalesVat + $manualSalesVat,
|
||||
'purchaseSupply' => $hometaxPurchaseSupply + $cardPurchaseSupply + $manualPurchaseSupply,
|
||||
'purchaseVat' => $hometaxPurchaseVat + $cardPurchaseVat + $manualPurchaseVat,
|
||||
'hometaxSalesSupply' => $hometaxSalesSupply,
|
||||
'hometaxSalesVat' => $hometaxSalesVat,
|
||||
'manualSalesSupply' => $manualSalesSupply,
|
||||
'manualSalesVat' => $manualSalesVat,
|
||||
'hometaxPurchaseSupply' => $hometaxPurchaseSupply,
|
||||
'hometaxPurchaseVat' => $hometaxPurchaseVat,
|
||||
'exemptSupply' => $exemptSupply, // 면세 계산서 공급가액
|
||||
'manualPurchaseSupply' => $manualPurchaseSupply,
|
||||
'manualPurchaseVat' => $manualPurchaseVat,
|
||||
'exemptSupply' => $exemptSupply,
|
||||
'cardPurchaseSupply' => $cardPurchaseSupply,
|
||||
'cardPurchaseVat' => $cardPurchaseVat,
|
||||
'total' => $allRecords->count(),
|
||||
|
||||
177
app/Http/Controllers/System/AiTokenUsageController.php
Normal file
177
app/Http/Controllers/System/AiTokenUsageController.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\System;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\System\AiPricingConfig;
|
||||
use App\Models\System\AiTokenUsage;
|
||||
use App\Models\Tenants\Tenant;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AiTokenUsageController extends Controller
|
||||
{
|
||||
public function index(Request $request): View|Response
|
||||
{
|
||||
if ($request->header('HX-Request')) {
|
||||
return response('', 200)->header('HX-Redirect', route('system.ai-token-usage.index'));
|
||||
}
|
||||
|
||||
return view('system.ai-token-usage.index');
|
||||
}
|
||||
|
||||
public function list(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = $request->input('per_page', 20);
|
||||
$startDate = $request->input('start_date');
|
||||
$endDate = $request->input('end_date');
|
||||
$tenantId = $request->input('tenant_id');
|
||||
$menuName = $request->input('menu_name');
|
||||
|
||||
$query = AiTokenUsage::query()
|
||||
->orderByDesc('created_at');
|
||||
|
||||
if ($tenantId) {
|
||||
$query->where('tenant_id', $tenantId);
|
||||
}
|
||||
|
||||
if ($menuName) {
|
||||
$query->where('menu_name', $menuName);
|
||||
}
|
||||
|
||||
if ($startDate) {
|
||||
$query->whereDate('created_at', '>=', $startDate);
|
||||
}
|
||||
|
||||
if ($endDate) {
|
||||
$query->whereDate('created_at', '<=', $endDate);
|
||||
}
|
||||
|
||||
// 통계 (필터 조건 동일하게 적용)
|
||||
$statsQuery = clone $query;
|
||||
$stats = $statsQuery->selectRaw('
|
||||
COUNT(*) as total_count,
|
||||
SUM(prompt_tokens) as total_prompt_tokens,
|
||||
SUM(completion_tokens) as total_completion_tokens,
|
||||
SUM(total_tokens) as total_total_tokens,
|
||||
SUM(cost_usd) as total_cost_usd,
|
||||
SUM(cost_krw) as total_cost_krw
|
||||
')->first();
|
||||
|
||||
// 페이지네이션
|
||||
$records = $query->paginate($perPage);
|
||||
|
||||
// 테넌트 이름 매핑
|
||||
$tenantIds = $records->pluck('tenant_id')->unique();
|
||||
$tenants = Tenant::whereIn('id', $tenantIds)->pluck('company_name', 'id');
|
||||
|
||||
$data = $records->through(function ($item) use ($tenants) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'tenant_id' => $item->tenant_id,
|
||||
'tenant_name' => $tenants[$item->tenant_id] ?? '-',
|
||||
'model' => $item->model,
|
||||
'menu_name' => $item->menu_name,
|
||||
'prompt_tokens' => $item->prompt_tokens,
|
||||
'completion_tokens' => $item->completion_tokens,
|
||||
'total_tokens' => $item->total_tokens,
|
||||
'cost_usd' => (float) $item->cost_usd,
|
||||
'cost_krw' => (float) $item->cost_krw,
|
||||
'request_id' => $item->request_id,
|
||||
'created_at' => $item->created_at->format('Y-m-d H:i:s'),
|
||||
];
|
||||
});
|
||||
|
||||
// 필터용 메뉴 목록
|
||||
$menuNames = AiTokenUsage::select('menu_name')
|
||||
->distinct()
|
||||
->orderBy('menu_name')
|
||||
->pluck('menu_name');
|
||||
|
||||
// 필터용 테넌트 목록
|
||||
$allTenantIds = AiTokenUsage::select('tenant_id')
|
||||
->distinct()
|
||||
->pluck('tenant_id');
|
||||
$allTenants = Tenant::whereIn('id', $allTenantIds)
|
||||
->orderBy('company_name')
|
||||
->get(['id', 'company_name']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $data->items(),
|
||||
'stats' => [
|
||||
'total_count' => (int) ($stats->total_count ?? 0),
|
||||
'total_prompt_tokens' => (int) ($stats->total_prompt_tokens ?? 0),
|
||||
'total_completion_tokens' => (int) ($stats->total_completion_tokens ?? 0),
|
||||
'total_total_tokens' => (int) ($stats->total_total_tokens ?? 0),
|
||||
'total_cost_usd' => round((float) ($stats->total_cost_usd ?? 0), 6),
|
||||
'total_cost_krw' => round((float) ($stats->total_cost_krw ?? 0), 2),
|
||||
],
|
||||
'filters' => [
|
||||
'menu_names' => $menuNames,
|
||||
'tenants' => $allTenants->map(fn ($t) => ['id' => $t->id, 'name' => $t->company_name]),
|
||||
],
|
||||
'pagination' => [
|
||||
'current_page' => $records->currentPage(),
|
||||
'last_page' => $records->lastPage(),
|
||||
'per_page' => $records->perPage(),
|
||||
'total' => $records->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function pricingList(): JsonResponse
|
||||
{
|
||||
$configs = AiPricingConfig::orderBy('id')->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $configs->map(fn ($c) => [
|
||||
'id' => $c->id,
|
||||
'provider' => $c->provider,
|
||||
'model_name' => $c->model_name,
|
||||
'input_price_per_million' => (float) $c->input_price_per_million,
|
||||
'output_price_per_million' => (float) $c->output_price_per_million,
|
||||
'unit_price' => (float) $c->unit_price,
|
||||
'unit_description' => $c->unit_description,
|
||||
'exchange_rate' => (float) $c->exchange_rate,
|
||||
'is_active' => $c->is_active,
|
||||
'description' => $c->description,
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function pricingUpdate(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'configs' => 'required|array',
|
||||
'configs.*.id' => 'required|integer|exists:ai_pricing_configs,id',
|
||||
'configs.*.model_name' => 'required|string|max:100',
|
||||
'configs.*.input_price_per_million' => 'required|numeric|min:0',
|
||||
'configs.*.output_price_per_million' => 'required|numeric|min:0',
|
||||
'configs.*.unit_price' => 'required|numeric|min:0',
|
||||
'configs.*.exchange_rate' => 'required|numeric|min:0',
|
||||
'configs.*.description' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
foreach ($validated['configs'] as $item) {
|
||||
AiPricingConfig::where('id', $item['id'])->update([
|
||||
'model_name' => $item['model_name'],
|
||||
'input_price_per_million' => $item['input_price_per_million'],
|
||||
'output_price_per_million' => $item['output_price_per_million'],
|
||||
'unit_price' => $item['unit_price'],
|
||||
'exchange_rate' => $item['exchange_rate'],
|
||||
'description' => $item['description'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
AiPricingConfig::clearCache();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '단가 설정이 저장되었습니다.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
271
app/Http/Controllers/System/AiVoiceRecordingController.php
Normal file
271
app/Http/Controllers/System/AiVoiceRecordingController.php
Normal file
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\System;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AiVoiceRecording;
|
||||
use App\Models\Interview\InterviewCategory;
|
||||
use App\Services\AiVoiceRecordingService;
|
||||
use App\Services\GoogleCloudService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AiVoiceRecordingController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AiVoiceRecordingService $service
|
||||
) {}
|
||||
|
||||
/**
|
||||
* React 뷰 반환
|
||||
*/
|
||||
public function index(Request $request): View|Response
|
||||
{
|
||||
if ($request->header('HX-Request')) {
|
||||
return response('', 200)->header('HX-Redirect', route('system.ai-voice-recording.index'));
|
||||
}
|
||||
|
||||
return view('system.ai-voice-recording.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON 목록
|
||||
*/
|
||||
public function list(Request $request): JsonResponse
|
||||
{
|
||||
$params = $request->only(['search', 'status', 'per_page']);
|
||||
$recordings = $this->service->getList($params);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $recordings,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 카테고리 + 템플릿 목록
|
||||
*/
|
||||
public function categories(): JsonResponse
|
||||
{
|
||||
$categories = InterviewCategory::with(['templates' => function ($q) {
|
||||
$q->where('is_active', true)->orderBy('sort_order');
|
||||
}])
|
||||
->where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->get(['id', 'name', 'description']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $categories,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 새 녹음 생성
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'nullable|string|max:200',
|
||||
'interview_template_id' => 'nullable|integer|exists:interview_templates,id',
|
||||
]);
|
||||
|
||||
$recording = $this->service->create($validated);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '녹음이 생성되었습니다.',
|
||||
'data' => $recording,
|
||||
], 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 오디오 업로드 + 처리
|
||||
*/
|
||||
public function processAudio(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$recording = AiVoiceRecording::find($id);
|
||||
|
||||
if (! $recording) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '녹음을 찾을 수 없습니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'audio' => 'required|string',
|
||||
'duration' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$result = $this->service->processAudio(
|
||||
$recording,
|
||||
$validated['audio'],
|
||||
$validated['duration']
|
||||
);
|
||||
|
||||
if (! $result['ok']) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $result['error'] ?? '처리 중 오류가 발생했습니다.',
|
||||
], 500);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '음성 분석이 완료되었습니다.',
|
||||
'data' => $result['recording'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 파일 업로드 + 처리
|
||||
*/
|
||||
public function uploadFile(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'audio_file' => 'required|file|mimes:webm,wav,mp3,ogg,m4a,mp4|max:102400',
|
||||
'title' => 'nullable|string|max:200',
|
||||
'interview_template_id' => 'nullable|integer|exists:interview_templates,id',
|
||||
]);
|
||||
|
||||
$recording = $this->service->create([
|
||||
'title' => $validated['title'] ?? '업로드된 음성녹음',
|
||||
'interview_template_id' => $validated['interview_template_id'] ?? null,
|
||||
]);
|
||||
|
||||
$result = $this->service->processUploadedFile(
|
||||
$recording,
|
||||
$request->file('audio_file')
|
||||
);
|
||||
|
||||
if (! $result['ok']) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $result['error'] ?? '처리 중 오류가 발생했습니다.',
|
||||
], 500);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '음성 분석이 완료되었습니다.',
|
||||
'data' => $result['recording'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 상세 조회
|
||||
*/
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$recording = $this->service->getById($id);
|
||||
|
||||
if (! $recording) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '녹음을 찾을 수 없습니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $recording,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 삭제
|
||||
*/
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$recording = AiVoiceRecording::find($id);
|
||||
|
||||
if (! $recording) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '녹음을 찾을 수 없습니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$this->service->delete($recording);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '녹음이 삭제되었습니다.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 처리 상태 폴링용
|
||||
*/
|
||||
public function status(int $id): JsonResponse
|
||||
{
|
||||
$recording = AiVoiceRecording::find($id);
|
||||
|
||||
if (! $recording) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '녹음을 찾을 수 없습니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'id' => $recording->id,
|
||||
'status' => $recording->status,
|
||||
'status_label' => $recording->status_label,
|
||||
'is_completed' => $recording->isCompleted(),
|
||||
'is_processing' => $recording->isProcessing(),
|
||||
'transcript_text' => $recording->transcript_text,
|
||||
'analysis_text' => $recording->analysis_text,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* GCS 음성파일 다운로드
|
||||
*/
|
||||
public function download(Request $request, int $id): Response|JsonResponse
|
||||
{
|
||||
$recording = AiVoiceRecording::find($id);
|
||||
|
||||
if (! $recording || ! $recording->audio_file_path) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '파일을 찾을 수 없습니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$googleCloudService = app(GoogleCloudService::class);
|
||||
$content = $googleCloudService->downloadFromStorage($recording->audio_file_path);
|
||||
|
||||
if (! $content) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '파일 다운로드에 실패했습니다.',
|
||||
], 500);
|
||||
}
|
||||
|
||||
// 파일 확장자 추출
|
||||
$extension = pathinfo($recording->audio_file_path, PATHINFO_EXTENSION) ?: 'webm';
|
||||
$mimeType = 'audio/'.$extension;
|
||||
|
||||
// 파일명 생성 (한글 제목 지원)
|
||||
$title = $recording->title ?: 'recording';
|
||||
$safeTitle = preg_replace('/[\/\\\\:*?"<>|]/', '_', $title);
|
||||
$filename = $safeTitle.'.'.$extension;
|
||||
$encodedFilename = rawurlencode($filename);
|
||||
|
||||
$disposition = $request->query('inline') ? 'inline' : 'attachment';
|
||||
|
||||
return response($content)
|
||||
->header('Content-Type', $mimeType)
|
||||
->header('Content-Length', strlen($content))
|
||||
->header('Accept-Ranges', 'bytes')
|
||||
->header('Content-Disposition', "{$disposition}; filename=\"{$encodedFilename}\"; filename*=UTF-8''{$encodedFilename}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user