From: Vladimir Fomichev Date: Wed, 18 Mar 2026 12:52:05 +0000 (+0300) Subject: получение работников на смене X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ef6083f748cbe0d153e8a4eedd4c0a62ec03fd64;p=erp24_rep%2Fyii-erp24%2F.git получение работников на смене --- 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()]); + } + } }