1 changed files with 64 additions and 0 deletions
@ -0,0 +1,64 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\api\controller; |
||||
|
|
||||
|
use think\Db; |
||||
|
use think\Request; |
||||
|
use think\Exception; |
||||
|
use think\db\exception\DataNotFoundException; |
||||
|
use think\db\exception\ModelNotFoundException; |
||||
|
use think\exception\DbException; |
||||
|
|
||||
|
class Hikmessage extends Base |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* 消息列表 |
||||
|
* @param Request $request |
||||
|
* @return false|string |
||||
|
* @throws DataNotFoundException |
||||
|
* @throws DbException |
||||
|
* @throws Exception |
||||
|
* @throws ModelNotFoundException |
||||
|
*/ |
||||
|
public function indexList(Request $request) |
||||
|
{ |
||||
|
if ($request->isPost()) { |
||||
|
$receive = $request->post(); |
||||
|
|
||||
|
$page = input("get.page") ? input("get.page") : 1; |
||||
|
$page = intval($page); |
||||
|
$limit = input("get.limit") ? input("get.limit") : 10; |
||||
|
$limit = intval($limit); |
||||
|
$start = $limit * ($page - 1); |
||||
|
|
||||
|
$where = []; |
||||
|
|
||||
|
if (isset($receive['messageId']) && !empty($receive['messageId'])) { |
||||
|
$where['messageId'] = $receive['messageId']; |
||||
|
} |
||||
|
if (isset($receive['deviceId']) && !empty($receive['deviceId'])) { |
||||
|
$where['deviceId'] = $receive['deviceId']; |
||||
|
} |
||||
|
if (isset($receive['type']) && !empty($receive['type'])) { |
||||
|
$where['type'] = $receive['type']; |
||||
|
} |
||||
|
|
||||
|
$result = Db::table("hikmessage")->where($where)->order('messageTime desc')->limit($start, $limit)->select(); |
||||
|
$num = Db::table("hikmessage")->where($where)->count(); |
||||
|
|
||||
|
foreach ($result as &$item) { |
||||
|
if ($item['messageTime']) $item['messageTime'] = date("Y-m-d H:i:s", substr($item['messageTime'], 0, 10)); |
||||
|
$item['body'] = json_decode($item['body'], true); |
||||
|
unset($item['id']); |
||||
|
} |
||||
|
|
||||
|
$list["count"] = $num; |
||||
|
$list["list"] = $result; |
||||
|
|
||||
|
return $this->jsonSuccess('成功', $list); |
||||
|
} |
||||
|
|
||||
|
return $this->jsonError('请求失败,仅允许POST请求方式'); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue