xiuwenDataTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. // 修文县项目验收,添加测试数据
  3. require_once './DB.php';
  4. date_default_timezone_set('Asia/Shanghai');
  5. $config = [
  6. 'hostname' => 'rm-wz98r5cn33zq4ou980o.mysql.rds.aliyuncs.com',
  7. 'username' => 'lampmanager',
  8. 'password' => 'lampmanager@2019',
  9. 'dbname' => 'lampmanager',
  10. ];
  11. $begin = date('H:i',time()-60);
  12. while (1) {
  13. $end = date('H:i',time());
  14. if ($end == $begin) {
  15. sleep(1);
  16. $end = date('H:i',time());
  17. continue;
  18. }
  19. $begin = $end;
  20. $db = new Db($config);
  21. $sql = 'select * from lampinfo where projectid = 30319';
  22. $lampinfoList = $db->query($sql);
  23. $count = 1;
  24. foreach ($lampinfoList as $lampinfo) {
  25. if ($lampinfo['status'] == 1 && $lampinfo['lighteness'] > 0) $count ++;
  26. }
  27. $allCount = count($lampinfoList);
  28. $db->table('network')->where('projectid=30319')->update(array('status'=>1));
  29. $now = explode(':', $end);
  30. $now = intval($now[0]) * 60 + intval($now[1]);
  31. if (1) {
  32. if ($now >= 18 * 60 || $now < 8 * 60) {
  33. $lighteness = 100;
  34. $db->table('lampinfo')->where('projectid=30319')->update(array('status'=>1,'lighteness'=>$lighteness));
  35. }
  36. if ($end == '08:00') {
  37. $lighteness = 0;
  38. $db->table('lampinfo')->where('projectid=30319')->update(array('status'=>0,'lighteness'=>$lighteness));
  39. }
  40. $db->table('network')->where('projectid=30319')->update(array('status'=>1));
  41. }else{
  42. foreach ($lampinfoList as $lampinfo) {
  43. if (empty($lampinfo['logtime']) || time() - strtotime($lampinfo['logtime']) > 10*3600) {
  44. $db->table('network')->where('id='.$lampinfo['networkid'])->update(array('status'=>0));
  45. }
  46. }
  47. }
  48. $db->close();
  49. }