|
|
<?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;
|
|
|
use app\adminapi\service\GameService;
|
|
|
use app\common\model\game\UserRoles;
|
|
|
use app\common\model\log\UserPayOrder;
|
|
|
use app\common\model\log\UserLoginLog;
|
|
|
use app\common\model\game\UserAccount;
|
|
|
|
|
|
/**
|
|
|
* 工作台
|
|
|
* 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 [
|
|
|
// 版本信息
|
|
|
// 'version' => self::versionInfo(),
|
|
|
// 今日数据
|
|
|
'today' => self::today(),
|
|
|
// 常用功能
|
|
|
// 'menu' => self::menu(),
|
|
|
// 近15日访客数
|
|
|
'visitor' => self::orders(),
|
|
|
// 服务支持
|
|
|
'rank' => self::payRank()
|
|
|
];
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @notes 常用功能
|
|
|
* @return array[]
|
|
|
* @author 段誉
|
|
|
* @date 2021/12/29 16:40
|
|
|
*/
|
|
|
public static function menu(): array
|
|
|
{
|
|
|
return [
|
|
|
[
|
|
|
'name' => '管理员',
|
|
|
'image' => FileService::getFileUrl(config('project.default_image.menu_admin')),
|
|
|
'url' => '/permission/admin'
|
|
|
],
|
|
|
[
|
|
|
'name' => '角色管理',
|
|
|
'image' => FileService::getFileUrl(config('project.default_image.menu_role')),
|
|
|
'url' => '/permission/role'
|
|
|
],
|
|
|
[
|
|
|
'name' => '部门管理',
|
|
|
'image' => FileService::getFileUrl(config('project.default_image.menu_dept')),
|
|
|
'url' => '/organization/department'
|
|
|
],
|
|
|
[
|
|
|
'name' => '字典管理',
|
|
|
'image' => FileService::getFileUrl(config('project.default_image.menu_dict')),
|
|
|
'url' => '/dev_tools/dict'
|
|
|
],
|
|
|
[
|
|
|
'name' => '代码生成器',
|
|
|
'image' => FileService::getFileUrl(config('project.default_image.menu_generator')),
|
|
|
'url' => '/dev_tools/code'
|
|
|
],
|
|
|
[
|
|
|
'name' => '素材中心',
|
|
|
'image' => FileService::getFileUrl(config('project.default_image.menu_file')),
|
|
|
'url' => '/material/index'
|
|
|
],
|
|
|
[
|
|
|
'name' => '菜单权限',
|
|
|
'image' => FileService::getFileUrl(config('project.default_image.menu_auth')),
|
|
|
'url' => '/permission/menu'
|
|
|
],
|
|
|
[
|
|
|
'name' => '网站信息',
|
|
|
'image' => FileService::getFileUrl(config('project.default_image.menu_web')),
|
|
|
'url' => '/setting/website/information'
|
|
|
],
|
|
|
];
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @notes 版本信息
|
|
|
* @return array
|
|
|
* @author 段誉
|
|
|
* @date 2021/12/29 16:08
|
|
|
*/
|
|
|
public static function versionInfo(): array
|
|
|
{
|
|
|
return [
|
|
|
'version' => config('project.version'),
|
|
|
'website' => config('project.website.url'),
|
|
|
'name' => ConfigService::get('website', 'name'),
|
|
|
'based' => 'vue3.x、ElementUI、MySQL',
|
|
|
'channel' => [
|
|
|
'website' => 'https://www.likeadmin.cn',
|
|
|
'gitee' => 'https://gitee.com/likeadmin/likeadmin_php',
|
|
|
]
|
|
|
];
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @notes 今日数据
|
|
|
* @return int[]
|
|
|
* @author 段誉
|
|
|
* @date 2021/12/29 16:15
|
|
|
*/
|
|
|
public static function today(): array
|
|
|
{
|
|
|
$uids = GameService::getInnerUids();
|
|
|
$today = date('Y-m-d');
|
|
|
$order = UserPayOrder::where('createTime', 'between', [$today, $today . ' 23:59:59'])
|
|
|
->where('status', 4)
|
|
|
->whereNotIn('uid', $uids)
|
|
|
->field('SUM(commodityPrice) as s,COUNT(1) as c')
|
|
|
->find()
|
|
|
->toArray();
|
|
|
$newUser = UserRoles::where('create', '>=', strtotime($today))
|
|
|
->whereNotIn('uid', $uids)->count();
|
|
|
|
|
|
$logins = UserLoginLog::where('LastLoginTime', 'between', [$today, $today . ' 23:59:59'])
|
|
|
->whereNotIn('Uid', $uids)
|
|
|
->where('UserType', 8)
|
|
|
->count();
|
|
|
return [
|
|
|
'time' => date('Y-m-d H:i:s'),
|
|
|
// 今日销售额
|
|
|
'today_money' => $order['s'] ? round($order['s'], 2) : 0,
|
|
|
|
|
|
// 今日访问量
|
|
|
'today_login' => $logins,
|
|
|
|
|
|
// 今日新增用户量
|
|
|
'today_new_user' => $newUser,
|
|
|
|
|
|
// 订单量 (笔)
|
|
|
'order_num' => $order['c'] ? $order['c'] : 0,
|
|
|
];
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @notes 访问数
|
|
|
* @return array
|
|
|
* @author 段誉
|
|
|
* @date 2021/12/29 16:57
|
|
|
*/
|
|
|
public static function orders(): array
|
|
|
{
|
|
|
$uids = GameService::getInnerUids();
|
|
|
$num = $num2 = [];
|
|
|
$date = [];
|
|
|
$end = date('Y-m-d');
|
|
|
$first = date('Y-m-d', strtotime('-14 days'));
|
|
|
$tmpOrders = UserPayOrder::where('createTime', 'between', [$first, $end . ' 23:59:59'])
|
|
|
->where('status', 4)
|
|
|
->whereNotIn('uid', $uids)
|
|
|
->field('SUM(commodityPrice) as s,DATE(createTime) as d')
|
|
|
->group('d')
|
|
|
->select()
|
|
|
->toArray();
|
|
|
$tmpLogins = UserLoginLog::where('LastLoginTime', 'between', [$first, $end . ' 23:59:59'])
|
|
|
->where('UserType', 8)
|
|
|
->whereNotIn('Uid', $uids)
|
|
|
->field('COUNT(1) as c, DATE(LastLoginTime) as d')
|
|
|
->group('d')
|
|
|
->select()
|
|
|
->toArray();
|
|
|
$orders = $logins = [];
|
|
|
if ($tmpOrders) {
|
|
|
foreach ($tmpOrders as $t) {
|
|
|
$orders[$t['d']] = round($t['s'], 2);
|
|
|
}
|
|
|
}
|
|
|
if ($tmpLogins) {
|
|
|
foreach ($tmpLogins as $l) {
|
|
|
$logins[$l['d']] = $l['c'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for ($i = 0; $i < 15; $i++) {
|
|
|
$d = date('Y-m-d', strtotime("- " . $i . "day"));
|
|
|
$date[] = $d;
|
|
|
$num[$i] = isset($orders[$d]) ? $orders[$d] : 0;
|
|
|
$num2[$i] = isset($logins[$d]) ? $logins[$d] : 0;
|
|
|
}
|
|
|
|
|
|
return [
|
|
|
'date' => $date,
|
|
|
'list' => [
|
|
|
['name' => '充值金额', 'data' => $num],
|
|
|
['name' => '登录人数', 'data' => $num2],
|
|
|
]
|
|
|
];
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @notes 服务支持
|
|
|
* @return array[]
|
|
|
* @author 段誉
|
|
|
* @date 2022/7/18 11:18
|
|
|
*/
|
|
|
public static function payRank()
|
|
|
{
|
|
|
$uids = GameService::getInnerUids();
|
|
|
$tmpOrders = UserPayOrder::where('status', 4)
|
|
|
->whereNotIn('uid', $uids)
|
|
|
->group('uid')
|
|
|
->limit(10)
|
|
|
->order('s', 'desc')
|
|
|
->column('SUM(commodityPrice) as s', 'uid');
|
|
|
$data = [];
|
|
|
if ($tmpOrders) {
|
|
|
$uids = array_keys($tmpOrders);
|
|
|
$account = UserAccount::where('Uid', 'in', $uids)
|
|
|
->column('Nickname', 'Uid');
|
|
|
|
|
|
foreach ($tmpOrders as $uid => $s) {
|
|
|
$data[] = [
|
|
|
'uid' => $uid,
|
|
|
'nickname' => isset($account[$uid]) ? $account[$uid] : '',
|
|
|
'money' => round($s, 2),
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
return $data;
|
|
|
}
|
|
|
}
|