Пример #1
0
 $dbCampaigns = Adv\YandexCampaignTable::getList(array('filter' => array('@ID' => $campaignList, '=ENGINE_ID' => $engine->getId(), '=ACTIVE' => Adv\YandexCampaignTable::ACTIVE), 'select' => array('ID', 'SETTINGS')));
 $campaignList = array();
 while ($campaign = $dbCampaigns->fetch()) {
     $campaignList[$campaign['ID']] = $campaign;
 }
 $dateFinish = new Date();
 $bannerListToCheck = array();
 foreach ($bannerList as $key => $banner) {
     $banner['DATE_START'] = $campaignList[$banner['CAMPAIGN_ID']]['SETTINGS']['StartDate'];
     if ($bSale) {
         $banner['PROFIT'] = 0;
     }
     if ($banner['DATE_START']) {
         $banner['DATE_START'] = new Date($banner['DATE_START'], 'Y-m-d');
         $banner['STATS_DATA'] = Adv\YandexStatTable::getBannerStat($banner['ID'], $banner['DATE_START'], $dateFinish);
         $gaps = Adv\YandexStatTable::getMissedPeriods($banner['STATS_DATA'], $banner['DATE_START'], $dateFinish);
         if (count($gaps) > 0) {
             $banner['LOADING_NEEDED'] = true;
             $bannerListToCheck[] = $banner['ID'];
         } else {
             $bannerListToCheck[] = $banner['ID'];
         }
     }
     $bannerList[$key] = $banner;
 }
 //print_r($bannerListToCheck);
 if ($bSale && count($bannerListToCheck) > 0) {
     $orderStats = Adv\OrderTable::getList(array('filter' => array('@BANNER_ID' => $bannerListToCheck, '=PROCESSED' => Adv\OrderTable::PROCESSED), 'group' => array('BANNER_ID'), 'select' => array('BANNER_ID', 'BANNER_SUM'), 'runtime' => array(new \Bitrix\Main\Entity\ExpressionField('BANNER_SUM', 'SUM(SUM)'))));
     while ($stat = $orderStats->fetch()) {
         $bannerList[$stat['BANNER_ID']]['PROFIT'] = $stat['BANNER_SUM'];
     }
	$tabControl->BeginNextTab();

	CJSCore::Init(array('amcharts_serial'));

	$dateStart = new Main\Type\Date();
	$dateStart->add("-".Engine\YandexDirectLive::MAX_STAT_DAYS_DELTA." days");

	$dateFinish = new Main\Type\Date();

	$statsData = Adv\YandexStatTable::getBannerStat(
		$banner['ID'],
		$dateStart,
		$dateFinish
	);

	$gaps = Adv\YandexStatTable::getMissedPeriods($statsData, $dateStart, $dateFinish);

	$graphData = array();

	$currency = Loc::getMessage('SEO_YANDEX_STATS_GRAPH_AXIS_CURRENCY');
	foreach($statsData as $date => $dayData)
	{
		if($dayData['CURRENCY'] != '')
		{
			$currency = $dayData['CURRENCY'];
		}

		unset($dayData['ID']);
		unset($dayData['CAMPAIGN_ID']);
		unset($dayData['BANNER_ID']);
		unset($dayData['DATE_DAY']);
						$finish = true;
					}
				}

				if($finish)
				{
					if($loadingSession)
					{
						unset($_SESSION[$loadingSession]);
					}

					if(!$res['error'] || $res["code"] == Engine\YandexDirect::ERROR_NO_STATS)
					{
						$statsData = Adv\YandexStatTable::getCampaignStat(
							$campaignId,
							$dateStart,
							$dateFinish
						);

						$graphData = array();

						foreach($statsData as $date => $dayData)
						{
							$graphData[] = array(
								'date' => $date,
								'CURRENCY' => $dayData['CURRENCY'],
								'SUM' => round($dayData['CAMPAIGN_SUM'], 2),
								'SUM_SEARCH' => round($dayData['CAMPAIGN_SUM_SEARCH'], 2),
								'SUM_CONTEXT' => round($dayData['CAMPAIGN_SUM_CONTEXT'], 2),
								'SHOWS' => $dayData['CAMPAIGN_SHOWS'],
								'SHOWS_SEARCH' => $dayData['CAMPAIGN_SHOWS_SEARCH'],