{
$request = Yii::$app->request;
- if (!$request->get('historyDays') || !$request->get('intervalMonths')) {
+ $historyDays = $request->get('historyDays');
+ $intervalMonths = $request->get('intervalMonths');
+
+
+ if ($historyDays === null || $intervalMonths === null) {
return $this->render('add-activity', [
'historyDays' => $historyDays ?? 14,
'intervalMonths' => $intervalMonths ?? 4,
]);
}
- $historyDays = (int)$request->get('historyDays');
- $intervalMonths = (int)$request->get('intervalMonths');
-
$endDate = date('Y-m-d');
$startDate = date('Y-m-d', strtotime("-{$historyDays} days", strtotime($endDate)));
- $storeIds = array_map(fn($s) => $s->id, $this->getVisibleStores());
- $countStores = count($storeIds);
-
$productIds = (new Query())
->select('sp.product_id')
->from(['s' => 'sales'])
->groupBy('sp.product_id')
//->having(['=', new \yii\db\Expression('COUNT(DISTINCT s.store_id)'), $countStores])
->column();
- var_dump($productIds); die();
+
if (empty($productIds)) {
Yii::$app->session->setFlash('info', 'Нет товаров, удовлетворяющих условиям.');
return $this->render('add-activity', [
<div class="add-activity p-4">
<h1><?= Html::encode($this->title) ?></h1>
-<?php $form = ActiveForm::begin([
- 'method' => 'get',
- 'action' => ['add-activity'],
- 'options' => ['class' => 'form-inline'],
-]); ?>
+ <?php $form = ActiveForm::begin([
+ 'method'=>'get',
+ 'action'=>['add-activity'],
+ ]); ?>
+
+ <?= Html::label('История (дней)', 'historyDays') ?>
+ <?= Html::input('number', 'historyDays', $historyDays, ['min'=>1, 'class'=>'form-control']) ?>
+
+ <?= Html::label('Интервал (месяцы)', 'intervalMonths') ?>
+ <?= Html::input('number', 'intervalMonths', $intervalMonths, ['min'=>1, 'class'=>'form-control']) ?>
+
+ <?= Html::submitButton('Запустить', ['class'=>'btn btn-success mt-3']) ?>
-<div class="row g-3 align-items-end">
- <div class="col-auto">
- <?= $form->field(new \yii\base\DynamicModel(['historyDays'=>$historyDays]), 'historyDays')
- ->textInput(['type'=>'number','min'=>1,'value'=>$historyDays])
- ->label('История (дней)') ?>
- </div>
- <div class="col-auto">
- <?= $form->field(new \yii\base\DynamicModel(['intervalMonths'=>$intervalMonths]), 'intervalMonths')
- ->textInput(['type'=>'number','min'=>1,'value'=>$intervalMonths])
- ->label('Интервал (месяцы)') ?>
- </div>
- <div class="col-auto">
- <?= Html::submitButton('Запустить', ['class'=>'btn btn-success']) ?>
- </div>
<?php ActiveForm::end(); ?>
</div>
\ No newline at end of file