58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\controller\device;
|
|
|
|
use app\adminapi\controller\BaseAdminController;
|
|
use app\adminapi\lists\device\DeviceLists;
|
|
use app\common\model\device\UserDevice;
|
|
|
|
/**
|
|
* 设备管理(只读)
|
|
*/
|
|
class DeviceController extends BaseAdminController
|
|
{
|
|
public function lists()
|
|
{
|
|
return $this->dataLists(new DeviceLists());
|
|
}
|
|
|
|
public function detail()
|
|
{
|
|
$id = (int)$this->request->get('id', 0);
|
|
if ($id <= 0) return $this->fail('参数错误');
|
|
$info = UserDevice::findOrEmpty($id)->toArray();
|
|
return $this->data($info);
|
|
}
|
|
|
|
public function delete()
|
|
{
|
|
$id = (int)$this->request->post('id', 0);
|
|
if ($id <= 0) return $this->fail('参数错误');
|
|
UserDevice::destroy($id);
|
|
return $this->success('删除成功', [], 1, 1);
|
|
}
|
|
|
|
/**
|
|
* 设备统计概览
|
|
*/
|
|
public function stats()
|
|
{
|
|
$total = UserDevice::count();
|
|
$platforms = UserDevice::field('platform, COUNT(*) as count')
|
|
->group('platform')
|
|
->select()
|
|
->toArray();
|
|
|
|
$today = strtotime(date('Y-m-d'));
|
|
$todayActive = UserDevice::where('last_at', '>=', $today)->count();
|
|
$todayNew = UserDevice::where('first_at', '>=', $today)->count();
|
|
|
|
return $this->data([
|
|
'total' => $total,
|
|
'today_active' => $todayActive,
|
|
'today_new' => $todayNew,
|
|
'platforms' => $platforms,
|
|
]);
|
|
}
|
|
}
|