1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- // 计算灯控累计亮灯时间
- require_once './DB.php';
- date_default_timezone_set('Asia/Shanghai');
- $config = [
- 'hostname' => 'rm-wz98r5cn33zq4ou980o.mysql.rds.aliyuncs.com',
- 'username' => 'lampmanager',
- 'password' => 'lampmanager@2019',
- 'dbname' => 'lampmanager',
- ];
- // $db = new Db($config);
- while (1) {
- $db = new Db($config);
- $lampLogList = $db->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);
- }
- ?>
|