176 lines
5.9 KiB
PHP
176 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace app\guildadmin\controller;
|
|
|
|
use app\common\controller\GuildAdmin;
|
|
use think\Config;
|
|
use think\Db;
|
|
use think\Hook;
|
|
use think\Session;
|
|
use think\Validate;
|
|
|
|
/**
|
|
* 后台首页
|
|
* @internal
|
|
*/
|
|
class Index extends GuildAdmin
|
|
{
|
|
|
|
protected $noNeedLogin = ['login'];
|
|
protected $noNeedRight = ['index', 'logout'];
|
|
protected $layout = '';
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
//移除HTML标签
|
|
$this->request->filter('trim,strip_tags,htmlspecialchars');
|
|
}
|
|
/**
|
|
* 后台首页
|
|
*/
|
|
public function index()
|
|
{
|
|
$guild_id = $this->guildId;
|
|
//昨天时间
|
|
$tday = date("Y-m-d", strtotime("-1 day"));
|
|
$stime_input = input('search_stime',0);
|
|
$etime_input = input('search_etime',date("Y-m-d",strtotime($tday)+86400));
|
|
$stime = $stime_input==0 ? strtotime($tday) : strtotime($stime_input);
|
|
$etime = strtotime($etime_input);
|
|
$return_data =[];
|
|
//基础数据
|
|
$guild_user = Db::name('vs_guild_user')->where([
|
|
'guild_id'=>$guild_id,
|
|
'status'=>1,
|
|
])->select();
|
|
$return_data['room_num'] = 0;//房间数量
|
|
$return_data['user_num'] = 0; //用户数量
|
|
$rooms = [];
|
|
foreach ($guild_user as $key => $value) {
|
|
if($value['quit_time']>0 && $value['quit_time']<$stime && $value['quit_time']>$etime){
|
|
continue;
|
|
}
|
|
if($value['createtime']>$etime){
|
|
continue;
|
|
}
|
|
if($value['createtime']<$stime_input){
|
|
continue;
|
|
}
|
|
if(!empty($value['room_id'])){
|
|
$return_data['room_num']++;
|
|
$rooms[] = $value['room_id'];
|
|
}
|
|
$return_data['user_num']++;
|
|
}
|
|
//房间粉丝数
|
|
$return_data['room_follow'] = 0;
|
|
$return_data['room_follow_new'] = 0;
|
|
$follow = Db::name('user_follow')->where([
|
|
'follow_id'=>['in',$rooms],
|
|
'type'=>2,
|
|
'createtime'=>['<',$etime],
|
|
])->select();
|
|
foreach ($follow as $key => $value) {
|
|
$return_data['room_follow']++;
|
|
if($value['createtime']>=$stime && $value['createtime']<$etime){
|
|
$return_data['room_follow_new']++;
|
|
}
|
|
}
|
|
//刷礼物流水
|
|
$return_data['all_money'] = db::name('vs_give_gift')
|
|
->whereIn('from_id',$rooms)
|
|
->where(['from'=>['in',[2,3,6]],'createtime'=>['<',$etime]])
|
|
->where(['createtime'=>['>',$stime_input]])
|
|
->sum('total_price');
|
|
//礼物总分成
|
|
$return_data['gift_money'] = db::name('vs_user_money_log')->where([
|
|
'room_id'=>['in',$rooms],
|
|
'money_type'=>2,
|
|
'change_type'=>11,
|
|
'createtime'=>['<',$etime]
|
|
])->where(['createtime'=>['>',$stime_input]])->sum('change_value');
|
|
//主持分成
|
|
$return_data['host_money'] = db::name('vs_user_money_log')->where([
|
|
'room_id'=>['in',$rooms],
|
|
'money_type'=>2,
|
|
'change_type'=>19,
|
|
'createtime'=>['<',$etime]
|
|
])->where(['createtime'=>['>',$stime_input]])->sum('change_value');
|
|
//房主分成
|
|
$return_data['room_owner_money'] = db::name('vs_user_money_log')->where([
|
|
'room_id'=>['in',$rooms],
|
|
'money_type'=>2,
|
|
'change_type'=>18,
|
|
'createtime'=>['<',$etime]
|
|
])->where(['createtime'=>['>',$stime_input]])->sum('change_value');
|
|
|
|
return V(1,"后台首页", $return_data);
|
|
}
|
|
|
|
/**
|
|
* 管理员登录
|
|
*/
|
|
public function login()
|
|
{
|
|
$url = $this->request->get('url', '', 'url_clean');
|
|
$url = $url ?: 'index/index';
|
|
if ($this->auth->isLogin()) {
|
|
return V(0,"已登录", null);
|
|
}
|
|
//保持会话有效时长,单位:小时
|
|
$keeyloginhours = 24;
|
|
if ($this->request->isPost()) {
|
|
$username = $this->request->post('username');
|
|
$password = $this->request->post('password', '', null);
|
|
$keeplogin = $this->request->post('keeplogin',0);
|
|
$rule = [
|
|
'username' => 'require|length:3,30',
|
|
'password' => 'require|length:3,30',
|
|
];
|
|
$data = [
|
|
'username' => $username,
|
|
'password' => $password,
|
|
];
|
|
$validate = new Validate($rule, [], ['username' => __('Username'), 'password' => __('Password'), 'captcha' => __('Captcha')]);
|
|
$result = $validate->check($data);
|
|
if (!$result) {
|
|
$this->error($validate->getError(), $url, ['token' => $this->request->token()]);
|
|
}
|
|
// AdminLog::setTitle(__('Login'));
|
|
$result = $this->auth->login($username, $password, $keeplogin ? $keeyloginhours * 3600 : 0);
|
|
if ($result === true) {
|
|
Hook::listen("admin_login_after", $this->request);
|
|
$admin = $this->get_admin_info();
|
|
return V(1,"登录成功", ['__token__' => $this->request->token(), 'admin' => $admin]);
|
|
} else {
|
|
return V(0,"用户名或密码错误", null);
|
|
}
|
|
}else{
|
|
return V(0,"用户名或密码错误", null);
|
|
}
|
|
}
|
|
/**
|
|
* 退出登录
|
|
*/
|
|
public function logout()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$this->auth->logout();
|
|
Hook::listen("admin_logout_after", $this->request);
|
|
return V(1,'退出成功', null);
|
|
}else{
|
|
return V(0,'操作失败', null);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* 获取当前登录管理员信息
|
|
*/
|
|
public function get_admin_info(){
|
|
$admin_info = $this->auth->getUserInfo();
|
|
$admin_info['ruleList'] = $this->auth->getRuleList();
|
|
return $admin_info;
|
|
}
|
|
|
|
} |