仓库初始化
This commit is contained in:
224
application/adminapi/controller/Index.php
Normal file
224
application/adminapi/controller/Index.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace app\adminapi\controller;
|
||||
|
||||
use app\admin\model\AdminLog;
|
||||
use app\common\controller\adminApi;
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
use think\Hook;
|
||||
use think\Session;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 后台首页
|
||||
* @internal
|
||||
*/
|
||||
class Index extends adminApi
|
||||
{
|
||||
|
||||
protected $noNeedLogin = ['login'];
|
||||
protected $noNeedRight = ['index', 'logout'];
|
||||
protected $layout = '';
|
||||
public $province = ['北京市', '天津市', '河北省', '内蒙古自治区', '辽宁省', '吉林省', '黑龙江省', '上海市', '江苏省', '浙江省', '安徽省', '福建省', '江西省', '山东省', '河南省', '湖北省', '湖南省', '广东省', '广西壮族自治区', '海南省', '重庆市四川省', '贵州省', '云南省', '西藏自治区', '陕西省', '甘肃省', '青海省', '宁夏回族自治区', '新疆维吾尔自治区', '台湾省', '香港特别行政区', '澳门特别行政区'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
//移除HTML标签
|
||||
$this->request->filter('trim,strip_tags,htmlspecialchars');
|
||||
}
|
||||
/**
|
||||
* 后台首页
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//今日收入金额
|
||||
$return_data['today_money'] = db::name('vs_user_recharge')->where('pay_status',2)->whereTime('pay_time', 'today')->sum('money');
|
||||
//总收入金额
|
||||
$return_data['all_money'] = db::name('vs_user_recharge')->where('pay_status',2)->sum('money');
|
||||
//今日充值笔数
|
||||
$return_data['today_money_num'] = db::name('vs_user_recharge')->where('pay_status',2)->whereTime('pay_time', 'today')->count();
|
||||
//总充值笔数
|
||||
$return_data['all_money_num'] = db::name('vs_user_recharge')->where('pay_status',2)->count();
|
||||
//今日后台充值金币数
|
||||
$return_data['admin_today_coin'] =db::name('vs_admin_recharge_log')->where(['type'=>1])->whereTime('createtime', 'today')->sum('change_value');
|
||||
//总充值数
|
||||
$return_data['admin_coin'] = db::name('vs_admin_recharge_log')->where(['type'=>1])->sum('change_value');
|
||||
//今日待付款金额
|
||||
$return_data['today_wait_pay'] = db::name('vs_user_recharge')->where('pay_status',1)->whereTime('createtime', 'today')->sum('money');
|
||||
//总待付款金额
|
||||
$return_data['all_wait_pay'] = db::name('vs_user_recharge')->where('pay_status',1)->sum('money');
|
||||
//今日待付款笔数
|
||||
$return_data['today_wait_pay_num'] = db::name('vs_user_recharge')->where('pay_status',1)->whereTime('createtime', 'today')->count();
|
||||
//总待付款笔数
|
||||
$return_data['all_wait_pay_num'] = db::name('vs_user_recharge')->where('pay_status',1)->count();
|
||||
|
||||
//待办事项
|
||||
//房间审核数
|
||||
$return_data['room_audit_num'] = db::name('vs_room')->where('apply_status',1)->count();
|
||||
//举报待处理数
|
||||
$return_data['report_audit_num'] = db::name('vs_user_inform')->where('status',1)->count();
|
||||
//反馈待处理数
|
||||
$return_data['feedback_audit_num'] = db::name('vs_suggest')->where('is_deal',1)->count();
|
||||
//代办数据
|
||||
$room_audit = db::name('vs_room')->field('u.nickname as title')->alias('a')->join('user u','a.user_id=u.id')->where('a.apply_status',1)->select();
|
||||
foreach ($room_audit as $key => $value) {
|
||||
$room_audit[$key]['title'] = ''.$value['title'].'的房间申请待处理';
|
||||
}
|
||||
$report_audit = db::name('vs_user_inform')->field('u.nickname as title')->alias('a')->join('user u','a.user_id=u.id')->where('a.status',1)->select();
|
||||
foreach ($report_audit as $key => $value) {
|
||||
$report_audit[$key]['title'] = ''.$value['title'].'的举报待处理';
|
||||
}
|
||||
$feedback_audit = db::name('vs_suggest')->field('u.nickname as title')->alias('a')->join('user u','a.user_id=u.id')->where('a.is_deal',1)->select();
|
||||
foreach ($feedback_audit as $key => $value) {
|
||||
$feedback_audit[$key]['title'] = ''.$value['title'].'的反馈待处理';
|
||||
}
|
||||
$audit = array_merge($room_audit,$report_audit,$feedback_audit);
|
||||
$return_data['todo_list'] = $audit;
|
||||
//消息公告
|
||||
$system_message = db::name('system_message')->field('title,createtime')->where('delete_time',0)->select();
|
||||
foreach ($system_message as $key => $value){
|
||||
$system_message[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||
}
|
||||
$return_data['system_message'] = $system_message;
|
||||
//图标数据
|
||||
//一年内收支情况
|
||||
$year = date('Y');
|
||||
$return_data['income_expend'] = [];//一年内收支情况
|
||||
for($i = 1; $i <= 12; $i++){
|
||||
$key = $i-1;
|
||||
$return_data['income_expend'][$key]['year_month']= $year.'年'.$i.'月';
|
||||
$return_data['income_expend'][$key]['month']= $i.'月';
|
||||
$month_start = strtotime($year.'-'.$i.'-01');
|
||||
$month_end = strtotime($year.'-'.$i.'-31');
|
||||
//充值收入
|
||||
$return_data['income_expend'][$key]['recharge_income'] = db::name('vs_user_recharge')->where('pay_status',2)->where('pay_time', 'between', [$month_start, $month_end])->sum('money');
|
||||
//提现支出
|
||||
$return_data['income_expend'][$key]['withdraw_expend'] = db::name('vs_user_withdrawal')->whereIn('status',[2,6])->where('createtime', 'between', [$month_start, $month_end])->sum('money');
|
||||
}
|
||||
//用户覆盖区域
|
||||
//中国所有省份
|
||||
foreach ($this->province as $key => $value) {
|
||||
$return_data['cover_area'][$key]['province'] = $value;
|
||||
$return_data['cover_area'][$key]['count'] = db::name('user')->where('status', 1)->where('is_robot', 0)->whereLike('address_ip', $value."%")->count();
|
||||
}
|
||||
//会员分析
|
||||
//会员总数
|
||||
$return_data['member_count'] = db::name('user')->where('status', 1)->where('is_robot', 0)->count();
|
||||
//今日登录
|
||||
$return_data['online_count'] = db::name('user')->where('status', 1)->where('is_robot', 0)->whereTime('logintime', 'today')->count();
|
||||
//七天内未登录
|
||||
$return_data['no_login_count'] = db::name('user')->where('status', 1)->where('is_robot', 0)->whereTime('logintime', '<', '7 day ago')->count();
|
||||
//今日注册
|
||||
$return_data['register_count'] = db::name('user')->where('status', 1)->where('is_robot', 0)->whereTime('createtime', 'today')->count();
|
||||
//充值会员数
|
||||
$return_data['recharge_count'] = db::name('vs_user_recharge')->where('pay_status',2)->group('user_id')->count();
|
||||
//充值会员百分比
|
||||
$return_data['recharge_count_percent'] = round(($return_data['recharge_count'] / $return_data['member_count']) * 100);
|
||||
//未充值会员数
|
||||
$return_data['no_recharge_count'] = $return_data['member_count'] - $return_data['recharge_count'];
|
||||
$return_data['no_recharge_count_percent'] = round(($return_data['no_recharge_count'] / $return_data['member_count']) * 100);
|
||||
//IOS用户数
|
||||
$return_data['ios_count'] = db::name('user')->where('status', 1)->where('is_robot', 0)->where('system', 'iOS')->count();
|
||||
$return_data['ios_count_percent'] = round(($return_data['ios_count'] / $return_data['member_count']) * 100);
|
||||
//安卓用户数
|
||||
$return_data['android_count'] = $return_data['member_count']-$return_data['ios_count'];
|
||||
$return_data['android_count_percent'] = round(($return_data['android_count'] / $return_data['member_count']) * 100);
|
||||
|
||||
//礼物打赏实时统计
|
||||
//一个月内的礼物打赏
|
||||
// $start_time_day = 1;
|
||||
$end_time_day = date('d');
|
||||
for ($i = 0; $i <= $end_time_day; $i++) {
|
||||
if($i == 0){
|
||||
$gift_money[$i]['day'] = 0;
|
||||
$gift_money[$i]['time'] = 0;
|
||||
$gift_money[$i]['gift_total_day'] = 0;
|
||||
$gift_money[$i]['gift_buy_day'] = 0;
|
||||
$gift_money[$i]['gift_backpack_day'] = 0;
|
||||
}else{
|
||||
$gift_money[$i]['day'] = $i;
|
||||
$day_time = strtotime(date('Y-m-') . $i);
|
||||
$day_time_end = strtotime(date('Y-m-') . $i . ' 23:59:59');
|
||||
$gift_money[$i]['time'] = date('Y-m-') . $i;
|
||||
//总礼物打赏值
|
||||
$gift_money[$i]['gift_total_day'] = Db::name('vs_give_gift')->where('createtime', 'between', [$day_time, $day_time_end])->sum('total_price');
|
||||
//购买礼物打赏价值
|
||||
$gift_money[$i]['gift_buy_day'] = Db::name('vs_give_gift')->where('type',1)->where('createtime', 'between', [$day_time, $day_time_end])->sum('total_price');
|
||||
//背包礼物打赏价值
|
||||
$gift_money[$i]['gift_backpack_day'] = Db::name('vs_give_gift')->where('type',2)->where('createtime', 'between', [$day_time, $day_time_end])->sum('total_price');
|
||||
}
|
||||
|
||||
}
|
||||
$return_data['gift_give_data'] = $gift_money;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user