From 190004adb0f567b6f5e8d1138b7b6ae31ca0cac5 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Wed, 3 Dec 2025 15:30:27 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B8=20?= =?utf8?q?=D0=BE=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?utf8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api3/core/services/ReportService.php | 52 +++++++++++++--------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/erp24/api3/core/services/ReportService.php b/erp24/api3/core/services/ReportService.php index 6f57858d..eb87a4c1 100644 --- a/erp24/api3/core/services/ReportService.php +++ b/erp24/api3/core/services/ReportService.php @@ -685,7 +685,8 @@ class ReportService $salesAdminIds[$sale['admin_id']] = true; } - // Добавляем админов из продаж, которых нет в смене + // Определяем админов из продаж, которых нет в смене + $missingAdminIds = []; foreach ($salesAdminIds as $adminId => $_) { $adminExists = false; foreach ($adminNames[$store->id] as $admin) { @@ -695,11 +696,23 @@ class ReportService } } if (!$adminExists) { - // Получаем имя админа - $adminName = Admin::findOne($adminId); + $missingAdminIds[] = $adminId; + } + } + + // Batch-загрузка имен отсутствующих админов одним запросом + if (!empty($missingAdminIds)) { + $missingAdmins = Admin::find() + ->select(['id', 'name']) + ->where(['id' => $missingAdminIds]) + ->indexBy('id') + ->asArray() + ->all(); + + foreach ($missingAdminIds as $adminId) { $adminNames[$store->id][] = [ 'id' => $adminId, - 'name' => $adminName ? $adminName->name : 'Unknown', + 'name' => $missingAdmins[$adminId]['name'] ?? 'Unknown', 'shift_id' => 0, // У админов из продаж нет shift_id ]; } @@ -1294,22 +1307,21 @@ class ReportService "sale_month_total" => ($salesMonth[$store_guids[$store_id]]["total"] ?? 0), "sale_total" => $storeSaleTotalTotal[$store_id] ?? 0, "sale_quantity" => $storeSaleQuantityTotal[$store_id] ?? 0, - "sale_avg" => $storeSaleQuantityTotal[$store_id] ?? 0 > 0 ? floor($storeSaleTotalTotal[$store_id] / $storeSaleQuantityTotal[$store_id]) : 0, + "sale_avg" => ($storeSaleQuantityTotal[$store_id] ?? 0) > 0 ? floor($storeSaleTotalTotal[$store_id] / $storeSaleQuantityTotal[$store_id]) : 0, "total_write_offs_per_date" => $totalWriteOffsPerDateTotal[$store_id] ?? 0, - "total_write_offs_per_date_percent" => $storeSaleTotalTotal[$store_id] ?? 0 > 0 ? floor($totalWriteOffsPerDateTotal[$store_id] / $storeSaleTotalTotal[$store_id] * 100) : 0, + "total_write_offs_per_date_percent" => ($storeSaleTotalTotal[$store_id] ?? 0) > 0 ? floor($totalWriteOffsPerDateTotal[$store_id] / $storeSaleTotalTotal[$store_id] * 100) : 0, "total_write_offs_per_month" => (int)($writeOffsMonth[$store_guids[$store_id]]["total"] ?? 0),//$totalWriteOffsPerMonthTotal[$store_id] ?? 0, // "total_write_offs_per_month_percent" => $storeSaleTotalTotal[$store_id] ?? 0 > 0 ? floor((int)($writeOffsMonth[$store_guids[$store_id]]["total"] ?? 0) / $storeSaleTotalTotal[$store_id] * 100) : 0, "total_write_offs_per_month_percent" => ($salesMonth[$store_guids[$store_id]]["total"] ?? 0) > 0 ? floor((int)($writeOffsMonth[$store_guids[$store_id]]["total"] ?? 0) / ($salesMonth[$store_guids[$store_id]]["total"] ?? 0) * 100) : 0, "total_payroll_days" => $totalPayrollDaysTotal[$store_id] ?? 0, - "total_payroll_days_percent" => $storeSaleTotalTotal[$store_id] ?? 0 > 0 ? floor($totalPayrollDaysTotal[$store_id] / $storeSaleTotalTotal[$store_id] * 100) : 0, - "total_payroll_month" => (int)($adminPayrollDaysMonth[$store_id]['total'] ?? 0),//$totalPayrollMonthTotal[$store_id] ?? 0, -// "total_payroll_month_percent" => $storeSaleTotalTotal[$store_id] ?? 0 > 0 ? floor(($adminPayrollDaysMonth[$store_id]['total'] ?? 0) / $storeSaleTotalTotal[$store_id] * 100) : 0, + "total_payroll_days_percent" => ($storeSaleTotalTotal[$store_id] ?? 0) > 0 ? floor($totalPayrollDaysTotal[$store_id] / $storeSaleTotalTotal[$store_id] * 100) : 0, + "total_payroll_month" => (int)($adminPayrollDaysMonth[$store_id]['total'] ?? 0), "total_payroll_month_percent" => ($salesMonth[$store_guids[$store_id]]["total"] ?? 0) > 0 ? floor(($adminPayrollDaysMonth[$store_id]['total'] ?? 0) / ($salesMonth[$store_guids[$store_id]]["total"] ?? 0) * 100) : 0, - "employee_sale_avg" => $employeeCount[$store_id] ?? 0 > 0 ? floor($storeSaleTotalTotal[$store_id] / $employeeCount[$store_id]) : 0, + "employee_sale_avg" => ($employeeCount[$store_id] ?? 0) > 0 ? floor($storeSaleTotalTotal[$store_id] / $employeeCount[$store_id]) : 0, "visitors_quantity" => $storeVisitorsQuantityTotal[$store_id] ?? 0, - "conversion" => $storeSaleQuantityTotal[$store_id] ?? 0 > 0 ? floor($storeVisitorsQuantityTotal[$store_id] / $storeSaleQuantityTotal[$store_id] * 100) : 0, + "conversion" => ($storeSaleQuantityTotal[$store_id] ?? 0) > 0 ? floor($storeVisitorsQuantityTotal[$store_id] / $storeSaleQuantityTotal[$store_id] * 100) : 0, "bonus_user_count" => $storeSaleBonusCountTotal[$store_id] ?? 0, - "bonus_user_per_sale_percent" => $storeSaleQuantityTotal[$store_id] ?? 0 > 0 ? floor($storeSaleBonusCountTotal[$store_id] / $storeSaleQuantityTotal[$store_id] * 100) : 0, + "bonus_user_per_sale_percent" => ($storeSaleQuantityTotal[$store_id] ?? 0) > 0 ? floor($storeSaleBonusCountTotal[$store_id] / $storeSaleQuantityTotal[$store_id] * 100) : 0, "bonus_new_user_count" => $storeSaleNewBonusCountTotal[$store_id] ?? 0, "bonus_repeat_user_count" => $storeSaleRepeatBonusCountTotal[$store_id] ?? 0, "sale_return_quantity" => $storeSaleReturnQuantityTotal[$store_id] ?? 0, @@ -1770,38 +1782,34 @@ class ReportService "sale_month_total" => ($salesMonth[$store_guids[$store_id]]["total"] ?? 0), "sale_total" => $storeSaleTotalTotal[$store_id] ?? 0, "sale_quantity" => $storeSaleQuantityTotal[$store_id] ?? 0, - "sale_avg" => $storeSaleQuantityTotal[$store_id] ?? 0 > 0 ? floor( + "sale_avg" => ($storeSaleQuantityTotal[$store_id] ?? 0) > 0 ? floor( $storeSaleTotalTotal[$store_id] / $storeSaleQuantityTotal[$store_id] ) : 0, "total_write_offs_per_date" => $totalWriteOffsPerDateTotal[$store_id] ?? 0, - "total_write_offs_per_date_percent" => $storeSaleTotalTotal[$store_id] ?? 0 > 0 ? floor( + "total_write_offs_per_date_percent" => ($storeSaleTotalTotal[$store_id] ?? 0) > 0 ? floor( $totalWriteOffsPerDateTotal[$store_id] / $storeSaleTotalTotal[$store_id] * 100 ) : 0, "total_write_offs_per_month" => (int)($writeOffsMonth[$store_guids[$store_id]]["total"] ?? 0), - //$totalWriteOffsPerMonthTotal[$store_id] ?? 0, -// "total_write_offs_per_month_percent" => $storeSaleTotalTotal[$store_id] ?? 0 > 0 ? floor((int)($writeOffsMonth[$store_guids[$store_id]]["total"] ?? 0) / $storeSaleTotalTotal[$store_id] * 100) : 0, "total_write_offs_per_month_percent" => ($salesMonth[$store_guids[$store_id]]["total"] ?? 0) > 0 ? floor( (int)($writeOffsMonth[$store_guids[$store_id]]["total"] ?? 0) / ($salesMonth[$store_guids[$store_id]]["total"] ?? 0) * 100 ) : 0, "total_payroll_days" => $totalPayrollDaysTotal[$store_id] ?? 0, - "total_payroll_days_percent" => $storeSaleTotalTotal[$store_id] ?? 0 > 0 ? floor( + "total_payroll_days_percent" => ($storeSaleTotalTotal[$store_id] ?? 0) > 0 ? floor( $totalPayrollDaysTotal[$store_id] / $storeSaleTotalTotal[$store_id] * 100 ) : 0, "total_payroll_month" => (int)($adminPayrollDaysMonth[$store_id]['total'] ?? 0), - //$totalPayrollMonthTotal[$store_id] ?? 0, -// "total_payroll_month_percent" => $storeSaleTotalTotal[$store_id] ?? 0 > 0 ? floor(($adminPayrollDaysMonth[$store_id]['total'] ?? 0) / $storeSaleTotalTotal[$store_id] * 100) : 0, "total_payroll_month_percent" => ($salesMonth[$store_guids[$store_id]]["total"] ?? 0) > 0 ? floor( ($adminPayrollDaysMonth[$store_id]['total'] ?? 0) / ($salesMonth[$store_guids[$store_id]]["total"] ?? 0) * 100 ) : 0, - "employee_sale_avg" => $employeeCount[$store_id] ?? 0 > 0 ? floor( + "employee_sale_avg" => ($employeeCount[$store_id] ?? 0) > 0 ? floor( $storeSaleTotalTotal[$store_id] / $employeeCount[$store_id] ) : 0, "visitors_quantity" => $storeVisitorsQuantityTotal[$store_id] ?? 0, - "conversion" => $storeSaleQuantityTotal[$store_id] ?? 0 > 0 ? floor( + "conversion" => ($storeSaleQuantityTotal[$store_id] ?? 0) > 0 ? floor( $storeVisitorsQuantityTotal[$store_id] / $storeSaleQuantityTotal[$store_id] * 100 ) : 0, "bonus_user_count" => $storeSaleBonusCountTotal[$store_id] ?? 0, - "bonus_user_per_sale_percent" => $storeSaleQuantityTotal[$store_id] ?? 0 > 0 ? floor( + "bonus_user_per_sale_percent" => ($storeSaleQuantityTotal[$store_id] ?? 0) > 0 ? floor( $storeSaleBonusCountTotal[$store_id] / $storeSaleQuantityTotal[$store_id] * 100 ) : 0, "bonus_new_user_count" => $storeSaleNewBonusCountTotal[$store_id] ?? 0, -- 2.39.5