Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.89 KB | None | 0 0
  1. if (self::showCachedVersion()) {
  2. $extraWhere = implode('', $this->params);
  3. $fields = array(
  4. 'stats' => array(
  5. 'COALESCE(fecha,'. NO_DATA .') ref',
  6. 'COALESCE(SUM(dinero_gasto),0) expenses',
  7. 'COALESCE(SUM(dinero_neto),0) money',
  8. "COALESCE(SUM(IF(especial='R', IF(tipo='SIGNUP', num_cargos, 0), 0)),0) leadsR",
  9. "COALESCE(SUM(IF(especial='P', IF(tipo='SIGNUP', num_cargos, 0), 0)),0) leadsP",
  10. "COALESCE(SUM(IF(especial='R', dinero_neto, 0)),0) moneyR",
  11. "COALESCE(SUM(IF(especial='P', dinero_neto, 0)),0) moneyP",
  12. "COALESCE(SUM(IF(tipo='CHARGE', num_cargos, 0)),0) renoves",
  13. ),
  14. 'imp' => array(
  15. 'COALESCE(SUM(imp),0) clicks'
  16. )
  17. );
  18.  
  19. for (
  20. $fecha = $this->dates['db']['ini'], $fechaAux = strtotime(substr($fecha, 0, 4) .'-'. substr($fecha, 4, 2) .'-'. substr($fecha, 6, 2));
  21. $fecha <= $this->dates['db']['fin'];
  22. $fechaAux = strtotime(substr($fecha, 0, 4) .'-'. substr($fecha, 4, 2) .'-'. substr($fecha, 6, 2)) + 86400, $fecha = date('Ymd', $fechaAux)
  23. ) {
  24. $cached[$fecha] = $fecha == date('Ymd') ? array() : self::isCached($fecha);
  25. if (empty($cached[$fecha])) { // NO CACHEADA
  26. $tableSTATS = self::getTableQuery($fecha, 'stats');
  27. $tableIMP = self::getTableQuery($fecha, 'imp');
  28. $queryStats = 'SELECT '. implode(', ', $fields['stats']) .' FROM '. $tableSTATS .' WHERE fecha='. $fecha . $extraWhere .' GROUP BY fecha';
  29. // echo $queryStats ."\n";
  30. // $tmp = mysql_fetch_assoc(CConfig::PConsulta($queryStats, $this->link));
  31. // tmp
  32. $cached[$fecha] = array_merge(array('ref' => '', 'first' => ''), /*self::$moldeTotal, */(array)mysql_fetch_assoc(CConfig::PConsulta($queryStats, $this->link)));
  33. $cached[$fecha]['first'] = $fechaAux;
  34. $cached[$fecha]['moneyR'] = (float)$cached[$fecha]['moneyR'];
  35. $cached[$fecha]['moneyP'] = (float)$cached[$fecha]['moneyP'];
  36. $cached[$fecha]['money'] = (float)$cached[$fecha]['money'];
  37. $cached[$fecha]['expenses'] = (float)$cached[$fecha]['expenses'];
  38. $cached[$fecha]['leadsR'] = (int)$cached[$fecha]['leadsR'];
  39. $cached[$fecha]['leadsP'] = (int)$cached[$fecha]['leadsP'];
  40. $cached[$fecha]['renoves'] = (int)$cached[$fecha]['renoves'];
  41. // $cached[$fecha]['profits'] = $cached[$fecha]['money'] - $cached[$fecha]['expenses'];
  42. // $cached[$fecha]['moneyLeadsR'] = (float)@($cached[$fecha]['expenses'] / $cached[$fecha]['leadsR']);
  43. // $cached[$fecha]['moneyLeadsP'] = (float)@(($cached[$fecha]['expenses'] - $cached[$fecha]['moneyP']) / $cached[$fecha]['leadsR']);
  44. // $cached[$fecha]['incomeExpense'] = (float)@(($cached[$fecha]['money']) / $cached[$fecha]['expenses']) * 100;
  45.  
  46. // $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));
  47.  
  48. $cached[$fecha]['imp'] = BLOCK_IMP ? 0 : (int)CConfig::SacaDato(implode(', ', $fields['imp']), $tableIMP, 'fecha='. $fecha . $extraWhere .' GROUP BY fecha', $this->link);
  49. // $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));
  50. // $cached[$fecha]['cpm'] = (float)round(@($cached[$fecha]['money'] * 1000 / $cached[$fecha]['clicks']), 4);
  51. // $cached[$fecha]['conversion'] = (float)@($cached[$fecha]['clicks'] / ($cached[$fecha]['leadsR'] + $cached[$fecha]['leadsP']));
  52. if ($fecha != date('Ymd') && !BLOCK_IMP) { // El día de hoy no lo almacenamos en cache ni tampoco si estan bloqueadas las impresiones
  53. self::saveCache($fecha, $cached[$fecha]);
  54. }
  55. } else { // La consulta esta cacheada
  56. self::addVisitCache($fecha); // Actualizamos la fecha utilizada en la cache
  57. // $cached[$fecha] = json_decode(CConfig::SacaDato('datos', 'media.adt_mkt_cache', 'id_cache="'. self::getIdCache($fecha) .'"', $this->link), 1);
  58. }
  59. }
  60.  
  61. if ($this->dateWeek) {
  62. $tmp = self::isCached(0);
  63. if (empty($tmp)) { // NO CACHEADA
  64. $fields = array(
  65. 'stats' => array(
  66. '"week" ref',
  67. 'COALESCE(SUM(dinero_gasto),0) expenses',
  68. 'COALESCE(SUM(dinero_neto),0) money',
  69. "COALESCE(SUM(IF(especial='R', IF(tipo='SIGNUP', num_cargos, 0), 0)),0) leadsR",
  70. "COALESCE(SUM(IF(especial='P', IF(tipo='SIGNUP', num_cargos, 0), 0)),0) leadsP",
  71. "COALESCE(SUM(IF(especial='R', dinero_neto, 0)),0) moneyR",
  72. "COALESCE(SUM(IF(especial='P', dinero_neto, 0)),0) moneyP",
  73. "COALESCE(SUM(IF(tipo='CHARGE', num_cargos, 0)),0) renoves",
  74. ),
  75. 'imp' => array(
  76. 'COALESCE(SUM(imp),0) clicks'
  77. )
  78. );
  79. $l7d = date('Ymd', strtotime('-7 day'));
  80. $horaActual = date('G');
  81.  
  82. $queryStats = 'SELECT '. implode(', ', $fields['stats']) .' FROM media.adt_mkt_stats WHERE fecha='. $l7d .' AND hora<='. $horaActual .' '. $extraWhere;
  83. $tmp = array_merge(array('ref' => '', 'first' => ''), /*self::$moldeTotal, */(array)mysql_fetch_assoc(CConfig::PConsulta($queryStats, $this->link)));
  84. $tmp['first'] = strtotime('-7 day');
  85. $tmp['moneyR'] = (float)$tmp['moneyR'];
  86. $tmp['moneyP'] = (float)$tmp['moneyP'];
  87. $tmp['money'] = (float)$tmp['money'];
  88. $tmp['expenses'] = (float)$tmp['expenses'];
  89. $tmp['leadsR'] = (int)$tmp['leadsR'];
  90. $tmp['leadsP'] = (int)$tmp['leadsP'];
  91. $tmp['renoves'] = (int)$tmp['renoves'];
  92. // $tmp['profits'] = $tmp['money'] - $tmp['expenses'];
  93. // $tmp['moneyLeadsR'] = (float)@($tmp['expenses'] / $tmp['leadsR']);
  94. // $tmp['moneyLeadsP'] = (float)@(($tmp['expenses'] - $tmp['moneyP']) / $tmp['leadsR']);
  95. // $tmp['incomeExpense'] = (float)@(($tmp['money']) / $tmp['expenses']) * 100;
  96. // $tmp['clicks'] = (int)CConfig::SacaDato(implode(', ', $fields['imp']), 'media.adt_mkt_imp', 'fecha='. $l7d .' AND hora<='. $horaActual .' '. $extraWhere, $this->link);
  97. $tmp['imp'] = BLOCK_IMP ? 0 : (int)CConfig::SacaDato(implode(', ', $fields['imp']), 'media.adt_mkt_imp', 'fecha='. $l7d .' AND hora<='. $horaActual .' '. $extraWhere, $this->link);
  98. // $tmp['imp'] = (int)CConfig::SacaDato(implode(', ', $fields['imp']), 'media.adt_mkt_imp', 'fecha='. $l7d .' AND hora<='. $horaActual .' '. $extraWhere, $this->link);
  99. // $tmp['cpm'] = (float)round(@($tmp['money'] * 1000 / $tmp['clicks']), 4);
  100. // $tmp['conversion'] = (float)@($tmp['clicks'] / ($tmp['leadsR'] + $tmp['leadsP']));
  101. unset($l7d, $horaActual);
  102. if (!BLOCK_IMP) { // No almacenamos la cache si estan bloqueadas las impresiones
  103. self::saveCache(0, $tmp);
  104. }
  105. } else {
  106. self::addVisitCache(0); // Actualizamos la fecha utilizada en la cache
  107. }
  108.  
  109. }
  110.  
  111. $cached = array_reverse($cached);
  112. $firstItem = array_shift($cached);
  113. array_unshift($cached, $tmp);
  114. array_unshift($cached, $firstItem);
  115. unset($firstItem, $tmp);
  116.  
  117. $base = $cached;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement