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 {
$shiftType = (int) ($input['shift_type'] ?? 0);
try {
- $shiftIds = Shift::getShiftIdsByShiftType($shiftType);
+ $dateObj = new \DateTime($date);
+ $nextDateStr = (clone $dateObj)->modify('+1 day')->format('Y-m-d');
- $rows = TimetableFact::find()
+ $query = 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();
+ ->andWhere(['store_id' => $storeId]);
+
+ if ($shiftType === 1) {
+ // Дневная: 08:00 – 20:00
+ $query->andWhere(['between', 'datetime_start',
+ $date . ' 08:00:00',
+ $date . ' 19:59:59',
+ ]);
+ } elseif ($shiftType === 2) {
+ // Ночная: 20:00 – 08:00 следующего дня
+ $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',
+ ]);
+ }
+
+ $rows = $query->asArray()->all();
if (empty($rows)) {
return $this->asJson(['success' => true, 'data' => []]);