物联网后台管理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

108 lines
3.2 KiB

<?php
namespace app\index\controller;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\Request;
use think\response\Json;
class Device extends Base
{
public function _initialize()
{
// parent::_initialize(); // TODO: Change the autogenerated stub
if (!session('root')) {
$this->error('亲,您还没有登录呢!', '/');
}
}
public function index()
{
return $this->fetch();
}
/**
* 获取产品列表
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws Exception
* @throws ModelNotFoundException
*/
public function deviceList()
{
$request = Request::instance();
$receive = $request->get();
$page = input("get.page") ? input("get.page") : 1;
$page = intval($page);
$limit = input("get.limit") ? input("get.limit") : 1;
$limit = intval($limit);
$start = $limit * ($page - 1);
$where = [];
if (isset($receive['message']) && !empty($receive['message'])) {
$where['deviceId'] = $receive['message'];
}
$result = Db::table("bs_product_device")->where($where)->order('id desc')->limit($start, $limit)->select();
$num = Db::table("bs_product_device")->where($where)->count();
foreach ($result as &$item) {
if ($item['onlineAt']) $item['onlineAt'] = date("Y-m-d H:i:s",substr($item['onlineAt'],0,10));
if ($item['offlineAt']) $item['offlineAt'] = date("Y-m-d H:i:s",substr($item['offlineAt'],0,10));
}
$list["msg"] = "";
$list["code"] = 0;
$list["count"] = $num;
$list["data"] = $result;
return json($list);
}
/**
* 设备接收信息页面
* @return mixed
*/
public function receivingInformation()
{
$receive = Request::instance()->get();
$this->assign('deviceId',$receive['deviceId']);
return $this->fetch();
}
/**
* 设备接收信息页面数据接口
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws Exception
* @throws ModelNotFoundException
*/
public function receivingInformationList() {
$receive = Request::instance()->get();
$page = input("get.page") ? input("get.page") : 1;
$page = intval($page);
$limit = input("get.limit") ? input("get.limit") : 1;
$limit = intval($limit);
$start = $limit * ($page - 1);
$where['deviceId'] = $receive['deviceId'] ?: 0;
$result = Db::table("bs_device_receiving_information")->where($where)->order('id desc')->limit($start, $limit)->select();
$num = Db::table("bs_device_receiving_information")->where($where)->count();
foreach ($result as &$item) {
if ($item['timestamp']) $item['timestamp'] = date("Y-m-d H:i:s",substr($item['timestamp'],0,10));
}
$list["msg"] = "";
$list["code"] = 0;
$list["count"] = $num;
$list["data"] = $result;
return json($list);
}
}