luck há 4 anos atrás
pai
commit
937f905d33

+ 81 - 18
application/web/controller/IndexController.php

@@ -55,24 +55,48 @@ class IndexController extends MainController
     public function reportdata()
     {
         $PRIMARYADDR = $this->request->param('PRIMARYADDR');
+        $type = $this->request->param('type', 0);
+        if (!intval($this->userid)) {
+            $this->api_return_json(array('msg' => '请重新登录'), 0);
+        }
         if (isset($PRIMARYADDR) && intval($PRIMARYADDR)) {
-            //报警设备 查站点id下的
-            $reportdata = Db::table('reportdata')
-                ->alias('rp')
-                ->where(array(array('rp.ALARMENDTIME', '=', ''), array('rp.PRIMARYADDR', '=', $PRIMARYADDR)))
-                ->join('realtimedata rt', 'rt.DEVICEID=rp.DEVICEID and rt.PRIMARYADDR=rp.PRIMARYADDR', 'left')
-                ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
-                ->select();
+            //如果为真查询关注报警设备
+            if ($type) {
+                $reportdata = Db::table('follow')
+                    ->alias('f')
+                    ->where(array(array('f.UID', '=', $this->userid), array('rp.ALARMENDTIME', '=', ''), array('f.PID', '=', $PRIMARYADDR)))
+                    ->join('reportdata rp', 'f.DID=rp.DEVICEID and F.PID=rp.PRIMARYADDR', 'left')
+                    ->join('realtimedata rt', 'f.DID=rt.DEVICEID and F.PID=rt.PRIMARYADDR', 'left')
+                    ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
+                    ->select();
+            } else {
+                //报警设备 查站点id下的
+                $reportdata = Db::table('reportdata')
+                    ->alias('rp')
+                    ->where(array(array('rp.ALARMENDTIME', '=', ''), array('rp.PRIMARYADDR', '=', $PRIMARYADDR)))
+                    ->join('realtimedata rt', 'rt.DEVICEID=rp.DEVICEID and rt.PRIMARYADDR=rp.PRIMARYADDR', 'left')
+                    ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
+                    ->select();
+            }
 
         } else {
-            //报警设备 查所有
-            $reportdata = Db::table('reportdata')
-                ->alias('rp')
-                ->where(array(array('rp.ALARMENDTIME', '=', '')))
-                ->join('realtimedata rt', 'rt.DEVICEID=rp.DEVICEID and rt.PRIMARYADDR=rp.PRIMARYADDR', 'left')
-                ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
-                ->select();
-
+            if ($type) {
+                $reportdata = Db::table('follow')
+                    ->alias('f')
+                    ->where(array(array('f.UID', '=', $this->userid), array('rp.ALARMENDTIME', '=', '')))
+                    ->join('reportdata rp', 'f.DID=rp.DEVICEID and F.PID=rp.PRIMARYADDR', 'left')
+                    ->join('realtimedata rt', 'f.DID=rt.DEVICEID and F.PID=rt.PRIMARYADDR', 'left')
+                    ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
+                    ->select();
+            } else {
+                //报警设备 查所有
+                $reportdata = Db::table('reportdata')
+                    ->alias('rp')
+                    ->where(array(array('rp.ALARMENDTIME', '=', '')))
+                    ->join('realtimedata rt', 'rt.DEVICEID=rp.DEVICEID and rt.PRIMARYADDR=rp.PRIMARYADDR', 'left')
+                    ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
+                    ->select();
+            }
         }
         $arr = array(1 => '80℃', 2 => '2:100℃', 3 => '130℃');
         $sta = array('在线', '报警', '不在线', '未配置');
@@ -80,14 +104,16 @@ class IndexController extends MainController
             $v['TEMPERTHRESHOLD'] = $arr[$v['TEMPERTHRESHOLD']];
             $v['STATUS'] = $sta[$v['STATUS']];
             $v['ADDRESS'] = $v['STATIONNAME'] . $v['POWERDISCABNAME'] . $v['CELLNAME'];
-            $v['DEVICENAME']=$v['DEVICENAME']?$v['DEVICENAME']:'未命名';
+            $v['DEVICENAME'] = $v['DEVICENAME'] ? $v['DEVICENAME'] : '未命名';
+            $res = Db::table('follow')->where([['PID', '=', $v['PRIMARYADDR']], ['DID', '=', $v['DEVICEID']]])->count();
+            $v['is_follow'] = $res ? 1 : 0;
         }
         $this->api_return_json(compact('reportdata'), 1);
     }
 
     /*
      *
-     * @name 添加设备
+     * @name 添加/编辑设备
      * */
     public function addequipment()
     {
@@ -108,12 +134,49 @@ class IndexController extends MainController
             $this->api_return_json(array('msg' => '请填写纬度'));
         }
 
-        $res = Db::name('device')->insertGetId($param);
+        //修改
+        if ($param['ID']) {
+           $ID=$param['ID'];
+           unset($param['ID']);
+            $res = Db::name('device')->where([['ID','=',$ID]])->update($param);
+        } else {
+            $res = Db::name('device')->insert($param);
+        }
         if ($res) {
             $this->api_return_json(array('msg' => '添加成功'), 1);
         }
     }
+    /*
+     * @name 编辑页面数据接口
+     * */
+    public function edit(){
+        $ID = $this->request->param('ID');
+        $edit['PRIMARYADDR']="";
+        $edit['REPEATERNAME']="";
+        $edit['STATIONNAME']="";
+        $edit['DVICLONGITUDE']="";
+        $edit['DVICLATITUDE']="";
+
+        if ($ID) {
+            $edit = Db::name('device')->where([['ID','=',$ID]])->find();
+        }
+        $this->api_return_json(compact('edit'), 1);
+    }
+
+    /*
+     * @name 时间数据记录
+     * */
+
+    public function timeadd(){
+        $ALARMSTARTTIME = $this->request->param('ALARMSTARTTIME');
+        $ALARMENDTIME = $this->request->param('ALARMENDTIME');
+        if(isset($ALARMENDTIME)&&isset($ALARMENDTIME)){
+
+        }
+        $this->api_return_json(array('msg' => '时间周期不能为空'), 1);
+    }
 }
 
 
 
+

+ 45 - 12
application/web/controller/UserController.php

@@ -244,36 +244,69 @@ class UserController extends MainController
             $this->api_return_json(array('msg' => '数据获取失败'), 0);
         $data[$this->userid] = array($ID);
 
-        if(!is_file(CMF_ROOT . 'public/collect.json')){
+        if (!is_file(CMF_ROOT . 'public/collect.json')) {
             file_put_contents(CMF_ROOT . 'public/collect.json', json_encode($data), LOCK_EX);
         }
-        $i=0;
+        $i = 0;
         $res = file_get_contents(CMF_ROOT . 'public/collect.json');
         if ($res) {
-            $userli = json_decode($res,true);
+            $userli = json_decode($res, true);
             if (is_array($userli)) {
-                if(isset($userli[$this->userid])){
+                if (isset($userli[$this->userid])) {
                     $re = array_search($ID, $userli[$this->userid]);
-                    if ($re!==false) {
+                    if ($re !== false) {
                         unset($userli[$this->userid][$re]);
-                        $i=1;
+                        $i = 1;
                         $data = $userli;
                     } else {
-                        array_unshift($userli[$this->userid],$ID);
-                        $data=$userli;
+                        array_unshift($userli[$this->userid], $ID);
+                        $data = $userli;
                     }
-                }else{
-                    $userli[$this->userid]=array($ID);
-                    $data=$userli;
+                } else {
+                    $userli[$this->userid] = array($ID);
+                    $data = $userli;
                 }
             }
         }
 
         file_put_contents(CMF_ROOT . 'public/collect.json', json_encode($data), LOCK_EX);
 
-        $this->api_return_json(array('msg' => $i?'关注':'取消关注'), 1);
+        $this->api_return_json(array('msg' => $i ? '关注' : '取消关注'), 1);
     }
 
+    /*
+     *
+     * @name 关注
+     *
+     * */
+    public function follow()
+    {
+        $PID = $this->request->param('PRIMARYADDR');
+        $DID = $this->request->param('DEVICEID');
+        if (!intval($this->userid)) {
+            $this->api_return_json(array('msg' => '请重新登录'), 0);
+        }
+        $data = array();
+        if (!intval($DID) || !intval($PID))
+            $this->api_return_json(array('msg' => '数据获取失败'), 0);
+
+        $data['UID'] = $this->userid;
+        $data['PID'] = $PID;
+        $data['DID'] = $DID;
+
+        $i = 0;
+        //查询当前用户是否关注 是 取关 否 关注
+        $res = Db::table('follow')->where($data)->find();
+        if ($res) {
+            $i = 1;
+            Db::table('follow')->where($data)->delete();
+        } else {
+            Db::table('follow')->insertGetId($data);
+        }
+        $this->api_return_json(array('msg' => $i ? '关注' : '已关注'), 1);
+    }
+
+
     //取关
     public function quitCollect()
     {

+ 7 - 0
config/config.php

@@ -0,0 +1,7 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-11-09
+ * Time: 16:43
+ */