Advertisement
sanych_dv

Untitled

Oct 18th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.76 KB | None | 0 0
  1. /// HOURLY VENDOR LOG
  2.  
  3. $nearHour = floor(time() / 3600) * 3600;
  4.  
  5. $query = "SELECT last_id FROM vendor_hourly_log ORDER BY id DESC LIMIT 1";
  6.  
  7. $last_id = Lib_MysqlManage::simpleResult(Lib_MysqlManage::makeQuery($query));
  8.  
  9. $query = "SELECT hour_stamp FROM vendor_hourly_log ORDER BY id DESC LIMIT 1";
  10.  
  11. $last_hour_stamp = Lib_MysqlManage::simpleResult(Lib_MysqlManage::makeQuery($query));
  12.  
  13.  
  14. $query = "INSERT INTO vendor_hourly_log (vendor_hourly_log.hour_stamp, vendor_hourly_log.vendor_id, vendor_hourly_log.printed_all, vendor_hourly_log.money_amount, vendor_hourly_log.hopper_amount, vendor_hourly_log.promocodes_amount, vendor_hourly_log.all_sessions, vendor_hourly_log.printed_sessions, vendor_hourly_log.last_id  ) SELECT floor(session_created_time / 3600) * 3600 as my_date, vendor_id,  SUM(printed_all) as printed_all, SUM(money_amount) as money_amount, SUM(hopper_amount) as hopper_amount , SUM(promocodes_amount) as promocodes_amount, COUNT(*) as all_sessions, SUM( printed_all>0 ) as printed_sessions, MAX(id) as last_id  FROM vendor_log WHERE vendor_log.id > " . $last_id . " AND   vendor_log.session_created_time < " . $nearHour . "  GROUP BY vendor_log.vendor_id, my_date ORDER BY vendor_log.session_created_time ";
  15.  
  16. Lib_MysqlManage::makeQuery($query);
  17.  
  18.  
  19. $query = "UPDATE vendor_hourly_log as temp_vendor_hourly_log INNER JOIN(SELECT floor(timestamp / 3600) * 3600 as my_date, vendor_id, COUNT(*) as uptime_count FROM vendors_uptime WHERE vendors_uptime.timestamp >= " . $last_hour_stamp . " GROUP BY vendors_uptime.vendor_id, my_date ORDER BY vendors_uptime.id ) as src SET temp_vendor_hourly_log.uptime = src.uptime_count WHERE temp_vendor_hourly_log.vendor_id = src.vendor_id AND temp_vendor_hourly_log.hour_stamp = src.my_date";
  20.  
  21. Lib_MysqlManage::makeQuery($query);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement