suyuan/app/adminapi/logic/WorkbenchLogic.php

188 lines
6.8 KiB
PHP
Raw Permalink Normal View History

2023-11-21 11:51:27 +08:00
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic;
use app\common\logic\BaseLogic;
use app\common\service\ConfigService;
use app\common\service\FileService;
2023-12-01 10:34:32 +08:00
use think\facade\Db;
2023-11-21 11:51:27 +08:00
/**
* 工作台
* Class WorkbenchLogic
* @package app\adminapi\logic
*/
class WorkbenchLogic extends BaseLogic
{
/**
* @notes 工作套
* @param $adminInfo
* @return array
* @author 段誉
* @date 2021/12/29 15:58
*/
public static function index()
{
return [
// 今日数据
'today' => self::today(),
2023-11-27 16:41:48 +08:00
// 快捷入口
2023-11-21 11:51:27 +08:00
'menu' => self::menu(),
2023-11-27 16:41:48 +08:00
// 图表数据
2023-12-01 10:34:32 +08:00
'chart_data' => self::chartData(),
2023-11-21 11:51:27 +08:00
];
}
/**
2023-11-27 16:41:48 +08:00
* @notes 快捷入口
2023-11-21 11:51:27 +08:00
* @return array[]
* @author 段誉
* @date 2021/12/29 16:40
*/
public static function menu(): array
{
return [
[
2023-11-27 16:41:48 +08:00
'name' => '土地列表',
2023-11-21 11:51:27 +08:00
'image' => FileService::getFileUrl(config('project.default_image.menu_dict')),
2023-11-27 16:41:48 +08:00
'url' => '/land/land'
2023-11-21 11:51:27 +08:00
],
[
2023-11-27 16:41:48 +08:00
'name' => '产品列表',
2023-11-21 11:51:27 +08:00
'image' => FileService::getFileUrl(config('project.default_image.menu_file')),
2023-11-27 16:41:48 +08:00
'url' => '/land/product'
2023-11-21 11:51:27 +08:00
],
[
2023-11-27 16:41:48 +08:00
'name' => '设备列表',
2023-11-21 11:51:27 +08:00
'image' => FileService::getFileUrl(config('project.default_image.menu_web')),
2023-11-27 16:41:48 +08:00
'url' => '/device/device'
2023-11-21 11:51:27 +08:00
],
2023-11-27 16:41:48 +08:00
[
'name' => '监控报警',
'image' => FileService::getFileUrl(config('project.default_image.menu_auth')),
'url' => '/device/monitor_alarm'
2023-11-21 11:51:27 +08:00
]
];
}
/**
* @notes 今日数据
* @return int[]
* @author 段誉
* @date 2021/12/29 16:15
*/
public static function today(): array
{
2023-12-01 10:34:32 +08:00
$todayStart = strtotime(date('Y-m-d 00:00:00'));
$todayEnd = strtotime(date('Y-m-d 23:59:59'));
2023-12-02 14:39:15 +08:00
$userWhere['user_id'] = -1;
2023-12-01 10:34:32 +08:00
// 超级管理员数据
if ((request()->adminInfo)['root'] && !(request()->adminInfo)['user_id']) {
unset($userWhere['user_id']);
}
// 普通用户数据
if (!(request()->adminInfo)['root'] && (request()->adminInfo)['user_id']) {
$userWhere['user_id'] = (request()->adminInfo)['user_id'];
}
$totalLand = Db::name('land')->where($userWhere)->count();
$todayLand = Db::name('land')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
$totalProduct = Db::name('product')->where($userWhere)->count();
$todayProduct = Db::name('product')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
$totalDevice = Db::name('device')->where($userWhere)->count();
$todayDevice = Db::name('device')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
$totalAlarm = Db::name('monitor_alarm')->where($userWhere)->count();
$todayAlarm = Db::name('monitor_alarm')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
2023-11-21 11:51:27 +08:00
return [
'time' => date('Y-m-d H:i:s'),
2023-12-01 10:34:32 +08:00
'today_land' => $todayLand,
'total_land' => $totalLand,
'today_product' => $todayProduct,
'total_product' => $totalProduct,
'today_device' => $todayDevice,
'total_device' => $totalDevice,
'today_alarm' => $todayAlarm,
'total_alarm' => $totalAlarm
2023-11-21 11:51:27 +08:00
];
}
/**
2023-12-01 10:34:32 +08:00
* @notes 图表数据
2023-11-21 11:51:27 +08:00
* @return array
* @author 段誉
* @date 2021/12/29 16:57
*/
2023-12-01 10:34:32 +08:00
public static function chartData(): array
2023-11-21 11:51:27 +08:00
{
2023-11-27 16:41:48 +08:00
$land = $device = $product = $alarm = [];
2023-11-21 11:51:27 +08:00
$date = [];
2023-12-02 14:39:15 +08:00
$userWhere['user_id'] = -1;
2023-12-01 10:34:32 +08:00
if ((request()->adminInfo)['root'] && !(request()->adminInfo)['user_id']) {
unset($userWhere['user_id']);
}
if (!(request()->adminInfo)['root'] && (request()->adminInfo)['user_id']) {
$userWhere['user_id'] = (request()->adminInfo)['user_id'];
}
for ($i = 0; $i < 7; $i++) {
$where_start = strtotime(date('Y-m-d 00:00:00', strtotime('-' . $i . ' day')));
$date[] = date('Y-m-d', $where_start);
$todayStart = $where_start;
$todayEnd = $where_start + 86400 -1;
$todayLand = Db::name('land')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
$land[$i] = $todayLand;
$todayProduct = Db::name('product')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
$product[$i] = $todayProduct;
$todayDevice = Db::name('device')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
$device[$i] = $todayDevice;
$todayAlarm = Db::name('monitor_alarm')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
$alarm[$i] = $todayAlarm;
2023-11-21 11:51:27 +08:00
}
return [
2023-12-01 10:34:32 +08:00
'date' => $date,
'list' => [
2023-11-27 16:41:48 +08:00
['name' => '土地数', 'data' => $land],
['name' => '产品数', 'data' => $product],
['name' => '设备数', 'data' => $device],
2023-12-01 10:34:32 +08:00
['name' => '报警数', 'data' => $alarm]
2023-11-21 11:51:27 +08:00
]
];
}
/**
* @notes 服务支持
* @return array[]
* @author 段誉
* @date 2022/7/18 11:18
*/
public static function support()
{
return [
[
'image' => FileService::getFileUrl(config('project.default_image.qq_group')),
'title' => '官方公众号',
'desc' => '关注官方公众号',
],
[
'image' => FileService::getFileUrl(config('project.default_image.customer_service')),
'title' => '添加企业客服微信',
'desc' => '想了解更多请添加客服',
]
];
}
}