public function actionGet_ajax() { if (Yii::$app->request->isAjax) { $data = Yii::$app->request->post(); $min = strtotime($data['analytics'][0]); $max = strtotime($data['analytics'][1]); /*ссылки на клиентские кампании*/ $id_user = Yii::$app->user->identity->id; $links = Campaigns::Get_links($id_user); $summary = $max - $min; $summary = $summary / 3600 / 24; for ($i = 0; $i < count($links); $i++) { for ($j = 0; $j < $summary; $j++) { $massive = Analytics::Get_info($links[$i]->id, date('Ymd', $min + $j * 3600 * 24)); $rows[$links[$i]->id][] = $massive; } } for ($i = 0; $i < count($links); $i++) { for ($j = 0; $j < count($rows[$links[$i]->id]); $j++) { if (count($rows[$links[$i]->id][$j]) == 0) { $mass[$i][] = ['data' => ($min + $j * 3600 * 24) * 1000, 'count' => 0, 'id' => $links[$i]->id, 'link' => '/campaigns?id=' . $links[$i]->id]; } else { $result = Detail::Get_count($rows[$links[$i]->id][$j][0]->id); $mass[$i][] = ['data' => strtotime($rows[$links[$i]->id][$j][0]->date) * 1000, 'count' => (int) $result, 'id' => $rows[$links[$i]->id][$j][0]->id_campaigns, 'link' => $rows[$links[$i]->id][$j][0]->link]; } } } \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['data' => $mass, 'counts' => count($rows), 'summary' => $summary, 'max' => $max, 'min' => $min]; } }
public static function Get_statistic($id) { $max = date('Ymd'); $week = date('Ymd', time() - 7 * 3600 * 24); $mounth = date('Ymd', time() - 30 * 3600 * 24); $links_week = Analytics::find()->where(['id_campaigns' => $id])->andWhere(['between', 'date', $week, $max])->orderBy('date')->all(); $links_mounth = Analytics::find()->where(['id_campaigns' => $id])->andWhere(['between', 'date', $mounth, $max])->orderBy('date')->all(); $links_all = Analytics::find()->where(['id_campaigns' => $id])->orderBy('date')->all(); return $result = ['week' => $links_week, 'mounth' => $links_mounth, 'all' => $links_all]; //SELECT SUM(visits) FROM Detail WHERE id_analytics IN(1,3,5,7,8) }
public function getLast() { return $this->hasMany(Analytics::className(), ['id_campaigns' => 'id']); }
public function Get_statistic_all($id) { $statistic = Analytics::Get_statistic($id); $count_week = count($statistic['week']); $count_mounth = count($statistic['mounth']); $count_all = count($statistic['all']); if ($count_week > 0) { for ($i = 0; $i < count($statistic['week']); $i++) { $data = $statistic['week'][$i]; $count_week_stat += Detail::Get_count($data->id); } } else { $count_week_stat = 0; } if ($count_mounth > 0) { for ($i = 0; $i < count($statistic['mounth']); $i++) { $data = $statistic['mounth'][$i]; $count_mounth_stat += Detail::Get_count($data->id); } } else { $count_mounth_stat = 0; } if ($count_all > 0) { for ($i = 0; $i < count($statistic['all']); $i++) { $data = $statistic['all'][$i]; $count_all_stat += Detail::Get_count($data->id); } } else { $count_all_stat = 0; } $data = ['count_week_stat' => $count_week_stat, 'count_mounth_stat' => $count_mounth_stat, 'count_all_stat' => $count_all_stat]; return $data; }