]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Получение флористов на смене origin/feature_fomichev_ERP-325J_category_manager_catalog
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 15 Jun 2026 12:23:40 +0000 (15:23 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 15 Jun 2026 12:23:40 +0000 (15:23 +0300)
erp24/api2/controllers/DataTestController.php

index 0b272dc430691ceff7d17b44521e239207245648..d9585471d067070063112a055c9610e96c089064 100644 (file)
@@ -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,
                 ];
             }