query('select id,lampid,daychargemincurrent,updatetime from battery_info_log where is_sum_light_time = 0 order by updatetime asc limit 10000'); foreach ($lampLogList as $lampLog) { $oldLampLog = $db->query('select lampid,daychargemincurrent from battery_info_log where lampid = '.$lampLog['lampid'].' AND updatetime < "'.$lampLog['updatetime'].'" order by updatetime DESC limit 1'); if (empty($oldLampLog) || empty($oldLampLog[0]['lampid'])) { $lightTime = $lampLog['daychargemincurrent']; }else{ if ($oldLampLog[0]['daychargemincurrent'] < $lampLog['daychargemincurrent']) { $lightTime = $lampLog['daychargemincurrent'] - $oldLampLog[0]['daychargemincurrent']; }else{ $lightTime = $lampLog['daychargemincurrent']; } } $db->execute('update lampinfo set totalLightTime = totalLightTime + '.$lightTime.' where id = '.$lampLog['lampid']); $db->execute('update battery_info_log set is_sum_light_time = 1 where id = '.$lampLog['id']); } $db->close(); // var_dump('ok');die; sleep(30); } ?>