Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (self::showCachedVersion()) {
- $extraWhere = implode('', $this->params);
- $fields = array(
- 'stats' => array(
- 'COALESCE(fecha,'. NO_DATA .') ref',
- 'COALESCE(SUM(dinero_gasto),0) expenses',
- 'COALESCE(SUM(dinero_neto),0) money',
- "COALESCE(SUM(IF(especial='R', IF(tipo='SIGNUP', num_cargos, 0), 0)),0) leadsR",
- "COALESCE(SUM(IF(especial='P', IF(tipo='SIGNUP', num_cargos, 0), 0)),0) leadsP",
- "COALESCE(SUM(IF(especial='R', dinero_neto, 0)),0) moneyR",
- "COALESCE(SUM(IF(especial='P', dinero_neto, 0)),0) moneyP",
- "COALESCE(SUM(IF(tipo='CHARGE', num_cargos, 0)),0) renoves",
- ),
- 'imp' => array(
- 'COALESCE(SUM(imp),0) clicks'
- )
- );
- for (
- $fecha = $this->dates['db']['ini'], $fechaAux = strtotime(substr($fecha, 0, 4) .'-'. substr($fecha, 4, 2) .'-'. substr($fecha, 6, 2));
- $fecha <= $this->dates['db']['fin'];
- $fechaAux = strtotime(substr($fecha, 0, 4) .'-'. substr($fecha, 4, 2) .'-'. substr($fecha, 6, 2)) + 86400, $fecha = date('Ymd', $fechaAux)
- ) {
- $cached[$fecha] = $fecha == date('Ymd') ? array() : self::isCached($fecha);
- if (empty($cached[$fecha])) { // NO CACHEADA
- $tableSTATS = self::getTableQuery($fecha, 'stats');
- $tableIMP = self::getTableQuery($fecha, 'imp');
- $queryStats = 'SELECT '. implode(', ', $fields['stats']) .' FROM '. $tableSTATS .' WHERE fecha='. $fecha . $extraWhere .' GROUP BY fecha';
- // echo $queryStats ."\n";
- // $tmp = mysql_fetch_assoc(CConfig::PConsulta($queryStats, $this->link));
- // tmp
- $cached[$fecha] = array_merge(array('ref' => '', 'first' => ''), /*self::$moldeTotal, */(array)mysql_fetch_assoc(CConfig::PConsulta($queryStats, $this->link)));
- $cached[$fecha]['first'] = $fechaAux;
- $cached[$fecha]['moneyR'] = (float)$cached[$fecha]['moneyR'];
- $cached[$fecha]['moneyP'] = (float)$cached[$fecha]['moneyP'];
- $cached[$fecha]['money'] = (float)$cached[$fecha]['money'];
- $cached[$fecha]['expenses'] = (float)$cached[$fecha]['expenses'];
- $cached[$fecha]['leadsR'] = (int)$cached[$fecha]['leadsR'];
- $cached[$fecha]['leadsP'] = (int)$cached[$fecha]['leadsP'];
- $cached[$fecha]['renoves'] = (int)$cached[$fecha]['renoves'];
- // $cached[$fecha]['profits'] = $cached[$fecha]['money'] - $cached[$fecha]['expenses'];
- // $cached[$fecha]['moneyLeadsR'] = (float)@($cached[$fecha]['expenses'] / $cached[$fecha]['leadsR']);
- // $cached[$fecha]['moneyLeadsP'] = (float)@(($cached[$fecha]['expenses'] - $cached[$fecha]['moneyP']) / $cached[$fecha]['leadsR']);
- // $cached[$fecha]['incomeExpense'] = (float)@(($cached[$fecha]['money']) / $cached[$fecha]['expenses']) * 100;
- // $cached[$fecha]['clicks'] = (int)CConfig::SacaDato(implode(', ', $fields['imp']), $tableIMP, 'fecha='. $fecha . $extraWhere .' GROUP BY fecha', $this->link);// mysql_fetch_assoc(CConfig::PConsulta($queryIMP, $this->link));
- $cached[$fecha]['imp'] = BLOCK_IMP ? 0 : (int)CConfig::SacaDato(implode(', ', $fields['imp']), $tableIMP, 'fecha='. $fecha . $extraWhere .' GROUP BY fecha', $this->link);
- // $cached[$fecha]['imp'] = (int)CConfig::SacaDato(implode(', ', $fields['imp']), $tableIMP, 'fecha='. $fecha . $extraWhere .' GROUP BY fecha', $this->link);// mysql_fetch_assoc(CConfig::PConsulta($queryIMP, $this->link));
- // $cached[$fecha]['cpm'] = (float)round(@($cached[$fecha]['money'] * 1000 / $cached[$fecha]['clicks']), 4);
- // $cached[$fecha]['conversion'] = (float)@($cached[$fecha]['clicks'] / ($cached[$fecha]['leadsR'] + $cached[$fecha]['leadsP']));
- if ($fecha != date('Ymd') && !BLOCK_IMP) { // El dÃa de hoy no lo almacenamos en cache ni tampoco si estan bloqueadas las impresiones
- self::saveCache($fecha, $cached[$fecha]);
- }
- } else { // La consulta esta cacheada
- self::addVisitCache($fecha); // Actualizamos la fecha utilizada en la cache
- // $cached[$fecha] = json_decode(CConfig::SacaDato('datos', 'media.adt_mkt_cache', 'id_cache="'. self::getIdCache($fecha) .'"', $this->link), 1);
- }
- }
- if ($this->dateWeek) {
- $tmp = self::isCached(0);
- if (empty($tmp)) { // NO CACHEADA
- $fields = array(
- 'stats' => array(
- '"week" ref',
- 'COALESCE(SUM(dinero_gasto),0) expenses',
- 'COALESCE(SUM(dinero_neto),0) money',
- "COALESCE(SUM(IF(especial='R', IF(tipo='SIGNUP', num_cargos, 0), 0)),0) leadsR",
- "COALESCE(SUM(IF(especial='P', IF(tipo='SIGNUP', num_cargos, 0), 0)),0) leadsP",
- "COALESCE(SUM(IF(especial='R', dinero_neto, 0)),0) moneyR",
- "COALESCE(SUM(IF(especial='P', dinero_neto, 0)),0) moneyP",
- "COALESCE(SUM(IF(tipo='CHARGE', num_cargos, 0)),0) renoves",
- ),
- 'imp' => array(
- 'COALESCE(SUM(imp),0) clicks'
- )
- );
- $l7d = date('Ymd', strtotime('-7 day'));
- $horaActual = date('G');
- $queryStats = 'SELECT '. implode(', ', $fields['stats']) .' FROM media.adt_mkt_stats WHERE fecha='. $l7d .' AND hora<='. $horaActual .' '. $extraWhere;
- $tmp = array_merge(array('ref' => '', 'first' => ''), /*self::$moldeTotal, */(array)mysql_fetch_assoc(CConfig::PConsulta($queryStats, $this->link)));
- $tmp['first'] = strtotime('-7 day');
- $tmp['moneyR'] = (float)$tmp['moneyR'];
- $tmp['moneyP'] = (float)$tmp['moneyP'];
- $tmp['money'] = (float)$tmp['money'];
- $tmp['expenses'] = (float)$tmp['expenses'];
- $tmp['leadsR'] = (int)$tmp['leadsR'];
- $tmp['leadsP'] = (int)$tmp['leadsP'];
- $tmp['renoves'] = (int)$tmp['renoves'];
- // $tmp['profits'] = $tmp['money'] - $tmp['expenses'];
- // $tmp['moneyLeadsR'] = (float)@($tmp['expenses'] / $tmp['leadsR']);
- // $tmp['moneyLeadsP'] = (float)@(($tmp['expenses'] - $tmp['moneyP']) / $tmp['leadsR']);
- // $tmp['incomeExpense'] = (float)@(($tmp['money']) / $tmp['expenses']) * 100;
- // $tmp['clicks'] = (int)CConfig::SacaDato(implode(', ', $fields['imp']), 'media.adt_mkt_imp', 'fecha='. $l7d .' AND hora<='. $horaActual .' '. $extraWhere, $this->link);
- $tmp['imp'] = BLOCK_IMP ? 0 : (int)CConfig::SacaDato(implode(', ', $fields['imp']), 'media.adt_mkt_imp', 'fecha='. $l7d .' AND hora<='. $horaActual .' '. $extraWhere, $this->link);
- // $tmp['imp'] = (int)CConfig::SacaDato(implode(', ', $fields['imp']), 'media.adt_mkt_imp', 'fecha='. $l7d .' AND hora<='. $horaActual .' '. $extraWhere, $this->link);
- // $tmp['cpm'] = (float)round(@($tmp['money'] * 1000 / $tmp['clicks']), 4);
- // $tmp['conversion'] = (float)@($tmp['clicks'] / ($tmp['leadsR'] + $tmp['leadsP']));
- unset($l7d, $horaActual);
- if (!BLOCK_IMP) { // No almacenamos la cache si estan bloqueadas las impresiones
- self::saveCache(0, $tmp);
- }
- } else {
- self::addVisitCache(0); // Actualizamos la fecha utilizada en la cache
- }
- }
- $cached = array_reverse($cached);
- $firstItem = array_shift($cached);
- array_unshift($cached, $tmp);
- array_unshift($cached, $firstItem);
- unset($firstItem, $tmp);
- $base = $cached;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement