From 450e7e3be7048498dadd09eef1d464a5fb25e00c Mon Sep 17 00:00:00 2001 From: fomichev Date: Mon, 15 Jun 2026 15:23:40 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D0=B5=20=D1=84=D0=BB=D0=BE=D1=80=D0=B8=D1=81=D1=82=D0=BE=D0=B2?= =?utf8?q?=20=D0=BD=D0=B0=20=D1=81=D0=BC=D0=B5=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataTestController.php | 76 +++++++++---------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/erp24/api2/controllers/DataTestController.php b/erp24/api2/controllers/DataTestController.php index 0b272dc4..d9585471 100644 --- a/erp24/api2/controllers/DataTestController.php +++ b/erp24/api2/controllers/DataTestController.php @@ -7,7 +7,7 @@ use Exception; use Yii; use yii\helpers\Json; use yii_app\records\Admin; -use yii_app\records\AdminGradeHistory; +use yii_app\records\AdminGroup; use yii_app\records\ApiCronTest; use yii_app\records\CityStore; use yii_app\records\CityStoreParams; @@ -17,8 +17,7 @@ use yii_app\records\PricesDynamic; use yii_app\records\Products1c; use yii_app\records\Sales; use yii_app\records\SalesProducts; -use yii_app\records\Timetable; -use yii_app\records\TimetableFact; +use yii_app\records\TimetableFactModel; class DataTestController extends BaseController @@ -278,6 +277,7 @@ class DataTestController extends BaseController 'operation' => $sale['operation'], 'status' => $sale['status'], 'skidka' => (float)$sale['skidka'], + 'seller_id' => $sale['seller_id'] ?? null, 'products' => [] ]; } else { @@ -384,38 +384,28 @@ class DataTestController extends BaseController $shiftType = (int)($input['shift_type'] ?? 0); try { - $nextDateStr = (new \DateTime($date))->modify('+1 day')->format('Y-m-d'); + $nextDate = (new \DateTime($date))->modify('+1 day')->format('Y-m-d'); - // Только фактически работавшие (не отпуск, не больничный, не выходной) - $query = TimetableFact::find() - ->select(['admin_id']) + $query = TimetableFactModel::find() + ->select(['admin_id', 'admin_group_id', 'date_start', 'time_start', 'date_end', 'time_end']) ->andWhere(['store_id' => $storeId]) - ->andWhere(['slot_type_id' => [Timetable::TIMESLOT_WORK, Timetable::TIMESLOT_INTERNSHIP]]); + ->andWhere(['date' => $date]); if ($shiftType === 1) { - $query->andWhere(['between', 'datetime_start', - $date . ' 08:00:00', - $date . ' 19:59:59', - ]); + // Дневная: смена начата и закрыта в тот же день + $query->andWhere(['date_end' => $date]); } elseif ($shiftType === 2) { - $query->andWhere(['OR', - ['between', 'datetime_start', $date . ' 20:00:00', $date . ' 23:59:59'], - ['between', 'datetime_start', $nextDateStr . ' 00:00:00', $nextDateStr . ' 07:59:59'], - ]); - } else { - $query->andWhere(['between', 'datetime_start', - $date . ' 00:00:00', - $date . ' 23:59:59', - ]); + // Ночная: смена переходит за полночь + $query->andWhere(['date_end' => $nextDate]); } - $rows = $query->asArray()->all(); + $rows = $query->indexBy('admin_id')->asArray()->all(); if (empty($rows)) { return $this->asJson(['success' => true, 'data' => []]); } - $adminIds = array_unique(array_column($rows, 'admin_id')); + $adminIds = array_keys($rows); $admins = Admin::find() ->select(['id', 'name_full', 'employee_position_id']) @@ -424,6 +414,17 @@ class DataTestController extends BaseController ->asArray() ->all(); + $groupIds = array_filter(array_unique(array_column($rows, 'admin_group_id'))); + $groups = []; + if (!empty($groupIds)) { + $groups = AdminGroup::find() + ->select(['id', 'name']) + ->where(['id' => $groupIds]) + ->indexBy('id') + ->asArray() + ->all(); + } + $positionIds = array_filter(array_unique(array_column($admins, 'employee_position_id'))); $positions = []; if (!empty($positionIds)) { @@ -435,17 +436,6 @@ class DataTestController extends BaseController ->all(); } - $gradeRows = AdminGradeHistory::find() - ->alias('agh') - ->select(['agh.admin_id', 'g.id AS grade_id', 'g.name AS grade_name']) - ->innerJoin('grade g', 'g.id = agh.grade_id') - ->where(['agh.admin_id' => $adminIds]) - ->andWhere(['agh.closed_at' => '2100-01-01 00:00:00']) - ->asArray() - ->all(); - - $grades = array_column($gradeRows, null, 'admin_id'); - $exportRows = ExportImportTable::find() ->select(['entity_id', 'export_val']) ->where([ @@ -459,19 +449,27 @@ class DataTestController extends BaseController $sellerIds = array_column($exportRows, 'export_val', 'entity_id'); $result = []; - foreach ($adminIds as $adminId) { + foreach ($rows as $adminId => $row) { $admin = $admins[$adminId] ?? []; + $groupId = $row['admin_group_id'] ?? null; $positionId = $admin['employee_position_id'] ?? null; - $grade = $grades[$adminId] ?? null; + $dateStart = $row['date_start'] && $row['time_start'] + ? $row['date_start'] . ' ' . $row['time_start'] + : null; + $dateEnd = $row['date_end'] && $row['time_end'] + ? $row['date_end'] . ' ' . $row['time_end'] + : null; $result[] = [ - 'admin_id' => $adminId, + 'admin_id' => (int)$adminId, 'name' => $admin['name_full'] ?? null, 'seller_id' => $sellerIds[$adminId] ?? null, + 'admin_group_id' => $groupId ? (int)$groupId : null, + 'admin_group_name' => $groupId ? ($groups[$groupId]['name'] ?? null) : null, 'employee_position_id' => $positionId, 'position_name' => $positionId ? ($positions[$positionId]['name'] ?? null) : null, - 'grade_id' => $grade['grade_id'] ?? null, - 'grade_name' => $grade['grade_name'] ?? null, + 'shift_start' => $dateStart, + 'shift_end' => $dateEnd, ]; } -- 2.39.5