ThirdService.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Service;
  3. use App\Model\Area;
  4. use App\Model\Device;
  5. use App\Model\DeviceType;
  6. use App\Model\Screen;
  7. use App\Model\SystemL;
  8. /**
  9. * 区域相关
  10. * @package App\Models
  11. */
  12. class ThirdService extends Service
  13. {
  14. public function pushThird(){
  15. $list = Device::where('del_time',0)->select('*')->get()->toArray();
  16. while (true) {
  17. sleep(60);
  18. $insert = [];
  19. $jwkey = [];
  20. foreach ($list as $k=>$v){
  21. $value = 0;
  22. $point_name = $point_name1 = '';
  23. switch ($v['device_type_id']){
  24. case 1:
  25. $value = $this->cgq_rand();
  26. $point_name = strpos($v['title'], '温度') !== false ? '温度' : '湿度';
  27. if($this->zt_rand()) $point_name1 = $point_name.'异常';
  28. break;
  29. case 2:
  30. $value = $this->kg_rand();
  31. $point_name = '仓门行程开关';
  32. break;
  33. case 3:
  34. $value = $this->yj_rand();
  35. $point_name = '预警';
  36. break;
  37. case 4:
  38. if(!isset($jwkey[$v['id']])) $jwkey[$v['id']] = [
  39. 'j' => 120,
  40. 'w' => 30
  41. ];
  42. $point_name = 'GPS';
  43. $jwkey[$v['id']]['j'] = $jwkey[$v['id']]['j']+$this->j_rand();
  44. $jwkey[$v['id']]['w'] = $jwkey[$v['id']]['w']+$this->w_rand();
  45. $value = (string)$jwkey[$v['id']]['j'].','.(string)$jwkey[$v['id']]['w'];
  46. break;
  47. default:
  48. break;
  49. }
  50. //获取节点名称
  51. $detail = [
  52. 'device_name' => $v['title'],
  53. 'time' => time()*1000,
  54. 'value' => $value,
  55. 'device_no' => $v['code'],
  56. 'data_point_id' => $k,
  57. 'data_point_name' => $point_name,
  58. 'push_time' => time()*1000,
  59. 'slave_name' => '',
  60. ];
  61. $insert[] = $detail;
  62. if(! empty($point_name1)){
  63. $detail['data_point_id'] = $k.$k;
  64. $detail['data_point_name'] = $point_name1;
  65. $detail['value'] = 1;
  66. $insert[] = $detail;
  67. }
  68. }
  69. // var_dump($insert);die;
  70. $a = SystemL::insert($insert);
  71. // var_dump($a);die;
  72. }
  73. }
  74. public function j_rand(){
  75. return (rand(0,100)/10000);
  76. }
  77. public function w_rand(){
  78. return (rand(0,100)/10000);
  79. }
  80. public function cgq_rand(){
  81. return rand(0,20)+(rand(0,100)/100);
  82. }
  83. public function kg_rand(){
  84. return rand(0,1);
  85. }
  86. public function yj_rand(){
  87. return rand(0,1);
  88. }
  89. public function zt_rand(){
  90. return rand(0,1);
  91. }
  92. }