From ef6083f748cbe0d153e8a4eedd4c0a62ec03fd64 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Wed, 18 Mar 2026 15:52:05 +0300 Subject: [PATCH] =?utf8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BD=D0=B8=D0=BA=D0=BE?= =?utf8?q?=D0=B2=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 | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/erp24/api2/controllers/DataTestController.php b/erp24/api2/controllers/DataTestController.php index 81e81971..4e428b08 100644 --- a/erp24/api2/controllers/DataTestController.php +++ b/erp24/api2/controllers/DataTestController.php @@ -7,6 +7,10 @@ use Exception; use Yii; use yii\helpers\Json; use yii_app\records\ApiCronTest; +use yii_app\records\ExportImportTable; +use yii_app\records\Shift; +use yii_app\records\TimetableFact; +use yii_app\records\Timetable; class DataTestController extends BaseController { @@ -309,4 +313,115 @@ class DataTestController extends BaseController { ]); } } + + /** + * Возвращает список сотрудников, вышедших на смену согласно фактическому табелю. + * + * POST /api2/data-test/get-shift-workers + * + * Тело запроса: + * { + * "store_id": 5, + * "date": "2025-10-10", + * "shift_type": 1 + * } + * + * shift_type: + * 0 = все смены + * 1 = дневная (Shift::DAY) + * 2 = ночная (Shift::NIGHT) + * + * Ответ: + * { + * "success": true, + * "data": [ + * { + * "admin_id": 42, + * "name": "Иванова А.В.", + * "seller_id": "56524cb1-4763-11ea-8cce-b42e991aff6c" + * } + * ] + * } + */ + public function actionGetShiftWorkers(): array + { + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + + $request = Yii::$app->request->getRawBody(); + + try { + $input = Json::decode($request); + } catch (Exception $ex) { + return $this->asJson(['success' => false, 'error' => 'Invalid JSON body']); + } + + if (empty($input['store_id'])) { + return $this->asJson(['success' => false, 'error' => 'store_id is required']); + } + + if (empty($input['date'])) { + return $this->asJson(['success' => false, 'error' => 'date is required']); + } + + $storeId = (int) $input['store_id']; + $date = $input['date']; + $shiftType = (int) ($input['shift_type'] ?? 0); + + try { + $shiftIds = Shift::getShiftIdsByShiftType($shiftType); + + $rows = TimetableFact::find() + ->select(['timetable.admin_id']) + ->with('admin') + ->andWhere([ + 'store_id' => $storeId, + 'date' => $date, + 'shift_id' => $shiftIds, + 'slot_type_id' => [Timetable::TIMESLOT_WORK, Timetable::TIMESLOT_INTERNSHIP], + ]) + ->asArray() + ->all(); + + if (empty($rows)) { + return $this->asJson(['success' => true, 'data' => []]); + } + + $adminIds = array_unique(array_column($rows, 'admin_id')); + + // Получаем имена сотрудников + $admins = \yii_app\records\Admin::find() + ->select(['id', 'name_full']) + ->where(['id' => $adminIds]) + ->indexBy('id') + ->asArray() + ->all(); + + // Получаем seller_id (GUID из 1С) для каждого сотрудника + $exportRows = ExportImportTable::find() + ->select(['entity_id', 'export_val']) + ->where([ + 'entity' => 'admin', + 'entity_id' => $adminIds, + 'export_id' => 1, + ]) + ->asArray() + ->all(); + + $sellerIds = array_column($exportRows, 'export_val', 'entity_id'); + + $result = []; + foreach ($adminIds as $adminId) { + $result[] = [ + 'admin_id' => $adminId, + 'name' => $admins[$adminId]['name_full'] ?? null, + 'seller_id' => $sellerIds[$adminId] ?? null, + ]; + } + + return $this->asJson(['success' => true, 'data' => $result]); + + } catch (Exception $e) { + return $this->asJson(['success' => false, 'error' => $e->getMessage()]); + } + } } -- 2.39.5