IndexController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\web\controller;
  12. use think\Db;
  13. use app\common\plugin\Varbinary;
  14. use PhpOffice\PhpSpreadsheet\IOFactory;
  15. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  16. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  17. use PhpOffice\PhpSpreadsheet\Style\Border;
  18. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  19. //产品类
  20. /**
  21. * @author lyuis
  22. * 小程序首页相应功能类
  23. */
  24. class IndexController extends MainController
  25. {
  26. private $pages = 15;
  27. /*
  28. * @name 站点列表
  29. *
  30. * */
  31. public function index()
  32. {
  33. //站点信息
  34. $index = Db::table('primarydev')->select();
  35. foreach ($index as $k => &$v) {
  36. $res = $this->bd_decrypt($v['DVICLONGITUDE'], $v['DVICLATITUDE']);
  37. $v['DVICLONGITUDE'] = $res['gg_lon'];
  38. $v['DVICLATITUDE'] = $res['gg_lat'];
  39. }
  40. $ALARMSTARTTIME=config('app.ALARMSTARTTIME');
  41. $ALARMENDTIME=config('app.ALARMENDTIME');
  42. $datatime=array('ALARMSTARTTIME'=>$ALARMSTARTTIME,'ALARMENDTIME'=>$ALARMENDTIME);
  43. $num=Db::table('reportdata')->where([['ALARMSTARTTIME','<',$ALARMSTARTTIME],['ALARMENDTIME','>',$ALARMENDTIME]])->count();
  44. $this->api_return_json(compact('index','datatime','num'), 1);
  45. }
  46. /*
  47. *
  48. * @name 报警设备
  49. * */
  50. public function reportdata()
  51. {
  52. $PRIMARYADDR = $this->request->param('PRIMARYADDR');
  53. $type = $this->request->param('type', 0);
  54. if (!intval($this->userid)) {
  55. $this->api_return_json(array('msg' => '请重新登录'), 0);
  56. }
  57. if (isset($PRIMARYADDR) && intval($PRIMARYADDR)) {
  58. //如果为真查询关注报警设备
  59. if ($type) {
  60. $reportdata = Db::table('follow')
  61. ->alias('f')
  62. ->where(array(array('f.UID', '=', $this->userid), array('rp.ALARMENDTIME', '=', ''), array('f.PID', '=', $PRIMARYADDR)))
  63. ->join('reportdata rp', 'f.DID=rp.DEVICEID and F.PID=rp.PRIMARYADDR', 'left')
  64. ->join('realtimedata rt', 'f.DID=rt.DEVICEID and F.PID=rt.PRIMARYADDR', 'left')
  65. ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
  66. ->select();
  67. } else {
  68. //报警设备 查站点id下的
  69. $reportdata = Db::table('reportdata')
  70. ->alias('rp')
  71. ->where(array(array('rp.ALARMENDTIME', '=', ''), array('rp.PRIMARYADDR', '=', $PRIMARYADDR)))
  72. ->join('realtimedata rt', 'rt.DEVICEID=rp.DEVICEID and rt.PRIMARYADDR=rp.PRIMARYADDR', 'left')
  73. ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
  74. ->select();
  75. }
  76. } else {
  77. if ($type) {
  78. $reportdata = Db::table('follow')
  79. ->alias('f')
  80. ->where(array(array('f.UID', '=', $this->userid), array('rp.ALARMENDTIME', '=', '')))
  81. ->join('reportdata rp', 'f.DID=rp.DEVICEID and F.PID=rp.PRIMARYADDR', 'left')
  82. ->join('realtimedata rt', 'f.DID=rt.DEVICEID and F.PID=rt.PRIMARYADDR', 'left')
  83. ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
  84. ->select();
  85. } else {
  86. //报警设备 查所有
  87. $reportdata = Db::table('reportdata')
  88. ->alias('rp')
  89. ->where(array(array('rp.ALARMENDTIME', '=', '')))
  90. ->join('realtimedata rt', 'rt.DEVICEID=rp.DEVICEID and rt.PRIMARYADDR=rp.PRIMARYADDR', 'left')
  91. ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
  92. ->select();
  93. }
  94. }
  95. $arr = array(1 => '80℃', 2 => '2:100℃', 3 => '130℃');
  96. $sta = array('在线', '报警', '不在线', '未配置');
  97. foreach ($reportdata as &$v) {
  98. $v['TEMPERTHRESHOLD'] = $arr[$v['TEMPERTHRESHOLD']];
  99. $v['STATUS'] = $sta[$v['STATUS']];
  100. $v['ADDRESS'] = $v['STATIONNAME'] . $v['POWERDISCABNAME'] . $v['CELLNAME'];
  101. $v['DEVICENAME'] = $v['DEVICENAME'] ? $v['DEVICENAME'] : '未命名';
  102. $res = Db::table('follow')->where([['PID', '=', $v['PRIMARYADDR']], ['DID', '=', $v['DEVICEID']]])->count();
  103. $v['is_follow'] = $res ? 1 : 0;
  104. }
  105. $this->api_return_json(compact('reportdata'), 1);
  106. }
  107. /*
  108. *
  109. * @name 添加/编辑设备
  110. * */
  111. public function addequipment()
  112. {
  113. $param = $this->request->param();
  114. if (!isset($param['PRIMARYADDR']) || empty($param['PRIMARYADDR'])) {
  115. $this->api_return_json(array('msg' => '请填写中继器ID'));
  116. }
  117. if (!isset($param['REPEATERNAME']) || empty($param['REPEATERNAME'])) {
  118. $this->api_return_json(array('msg' => '请填写中继器名称'));
  119. }
  120. if (!isset($param['STATIONNAME']) || empty($param['STATIONNAME'])) {
  121. $this->api_return_json(array('msg' => '请填写站点名称'));
  122. }
  123. if (!isset($param['DVICLONGITUDE']) || empty($param['DVICLONGITUDE'])) {
  124. $this->api_return_json(array('msg' => '请填写经度'));
  125. }
  126. if (!isset($param['DVICLATITUDE']) || empty($param['DVICLATITUDE'])) {
  127. $this->api_return_json(array('msg' => '请填写纬度'));
  128. }
  129. $data=array();
  130. $data['PRIMARYADDR']=$param['PRIMARYADDR'];
  131. $data['REPEATERNAME']=$param['REPEATERNAME'];
  132. $data['STATIONNAME']=$param['STATIONNAME'];
  133. $data['DVICLONGITUDE']=$param['DVICLONGITUDE'];
  134. $data['DVICLATITUDE']=$param['DVICLATITUDE'];
  135. //修改
  136. if (!empty($param['ID'])) {
  137. $ID=$param['ID'];
  138. unset($param['ID']);
  139. $res = Db::name('primarydev')->where([['ID','=',$ID]])->update($data);
  140. } else {
  141. $res = Db::name('primarydev')->insert($data);
  142. }
  143. if ($res) {
  144. $this->api_return_json(array('msg' => '添加成功'), 1);
  145. }else
  146. $this->api_return_json(array('msg' => '操作失败'));
  147. }
  148. /*
  149. * @name 编辑页面数据接口
  150. * */
  151. public function edit(){
  152. $ID = $this->request->param('ID');
  153. $edit['PRIMARYADDR']="";
  154. $edit['REPEATERNAME']="";
  155. $edit['STATIONNAME']="";
  156. $edit['DVICLONGITUDE']="";
  157. $edit['DVICLATITUDE']="";
  158. if ($ID) {
  159. $edit = Db::name('primarydev')->where([['ID','=',$ID]])->find();
  160. }
  161. $this->api_return_json(compact('edit'), 1);
  162. }
  163. /*
  164. * @name 时间数据记录
  165. * */
  166. public function timeadd(){
  167. $ALARMSTARTTIME = $this->request->param('ALARMSTARTTIME');
  168. $ALARMENDTIME = $this->request->param('ALARMENDTIME');
  169. if(isset($ALARMSTARTTIME)&&isset($ALARMENDTIME)){
  170. config('app.ALARMENDTIME',strtotime($ALARMENDTIME));
  171. config('app.ALARMSTARTTIME',strtotime($ALARMSTARTTIME));
  172. }
  173. $this->api_return_json(array('msg' => '时间周期不能为空'), 1);
  174. }
  175. /*
  176. *
  177. * @name FPA列表
  178. * */
  179. public function deviceinfo(){
  180. $PRIMARYADDR = $this->request->param('PRIMARYADDR',0);
  181. $deviceinfo = Db::table('deviceinfo')
  182. ->alias('d')
  183. ->where( array(array('d.PRIMARYADDR', '=', $PRIMARYADDR)))
  184. ->join('realtimedata rt', 'rt.DEVICEID=d.DEVICEID and rt.PRIMARYADDR=d.PRIMARYADDR', 'left')
  185. ->field('d.*,rt.STATUS,rt.LASTTRANSDATE')
  186. ->select();
  187. $arr = array(1 => '80℃', 2 => '2:100℃', 3 => '130℃');
  188. $sta = array('在线', '报警', '不在线', '未配置');
  189. foreach ($deviceinfo as $k => &$v) {
  190. $v['TEMPERTHRESHOLD'] = $arr[$v['TEMPERTHRESHOLD']];
  191. $v['STATUS'] = $sta[$v['STATUS']];
  192. }
  193. $this->api_return_json(compact('deviceinfo'), 1);
  194. }
  195. /*
  196. *
  197. * @name FPA添加编辑
  198. * */
  199. public function deviceinfoinfo(){
  200. $param=$this->request->param();
  201. if(!isset($param['DEVICEID'])||empty($param['DEVICEID'])){$this->api_return_json(array('msg' => '请填写监测点ID'));}
  202. if(!isset($param['DEVICENAME'])||empty($param['DEVICENAME'])){$this->api_return_json(array('msg' => '请填写FPA名称'));}
  203. if(!isset($param['TEMPERTHRESHOLD'])||empty($param['TEMPERTHRESHOLD'])){$this->api_return_json(array('msg' => '请选择温度阈值'));}
  204. if(!isset($param['CELLNAME'])||empty($param['CELLNAME'])){$this->api_return_json(array('msg' => '请填写小室名称'));}
  205. if(!isset($param['POWERDISCABVOLUME'])||empty($param['POWERDISCABVOLUME'])){$this->api_return_json(array('msg' => '请填写开关柜小室体积'));}
  206. if(!isset($param['TEMPERPATCHNUM'])||empty($param['TEMPERPATCHNUM'])){$this->api_return_json(array('msg' => '请填写感温贴片数量'));}
  207. //修改
  208. $data['DEVICEID']=$param['DEVICEID'];
  209. $data['DEVICENAME']=$param['DEVICENAME'];
  210. $data['TEMPERTHRESHOLD']=$param['TEMPERTHRESHOLD'];
  211. $data['CELLNAME']=$param['CELLNAME'];
  212. $data['POWERDISCABVOLUME']=$param['POWERDISCABVOLUME'];
  213. $data['TEMPERPATCHNUM']=$param['TEMPERPATCHNUM'];
  214. $data['PRIMARYADDR']==$param['PRIMARYADDR'];
  215. if (!empty($param['ID'])) {
  216. $ID=$param['ID'];
  217. unset($param['ID']);
  218. $str='添加';
  219. $res = Db::name('deviceinfo')->where([['ID','=',$ID]])->update($data);
  220. } else {
  221. $str='编辑';
  222. $res = Db::name('deviceinfo')->insert($data);
  223. }
  224. if ($res) {
  225. $this->api_return_json(array('msg' => $str.'成功'), 1);
  226. }
  227. }
  228. }