392 lines
17 KiB
PHP
392 lines
17 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model;
|
|
|
|
use think\Model;
|
|
use think\Db;
|
|
|
|
class Statistics extends Model
|
|
{
|
|
//获取首页基础统计数据
|
|
public function welcome_data()
|
|
{
|
|
$data = [];
|
|
//获取系统会员总人数
|
|
$data['user_all_count'] = db::name('user')->count();
|
|
//今日会员新增总数
|
|
$data['user_today_count'] = db::name('user')->whereTime('add_time', 'today')->count();
|
|
//本周会员新增总数
|
|
$data['user_week_count'] = db::name('user')->whereTime('add_time', 'week')->count();
|
|
//获取系统订单总人数
|
|
$data['user_player_order_all_amount'] = db::name('user_player_order')->sum('total_amount');
|
|
//今日订单新增总数
|
|
$data['user_player_order_today_amount'] = db::name('user_player_order')->whereTime('add_time', 'today')->sum('total_amount');
|
|
//本周订单新增总数
|
|
$data['user_player_order_week_amount'] = db::name('user_player_order')->whereTime('add_time', 'week')->sum('total_amount');
|
|
//获取系统充值总人数
|
|
$data['user_recharge_all_amount'] = db::name('user_recharge')->where(['pay_status' => 2])->sum('money');
|
|
//今日充值新增总数
|
|
$data['user_recharge_today_amount'] = db::name('user_recharge')->where(['pay_status' => 2])->whereTime('add_time', 'today')->sum('money');
|
|
//本周充值新增总数
|
|
$data['user_recharge_week_amount'] = db::name('user_recharge')->where(['pay_status' => 2])->whereTime('add_time', 'week')->sum('money');
|
|
//获取系统打赏总人数
|
|
$data['user_send_gift_all_amount'] = db::name('user_send_gift')->sum('gift_total_price');
|
|
//今日打赏新增总数
|
|
$data['user_send_gift_today_amount'] = db::name('user_send_gift')->whereTime('add_time', 'today')->sum('gift_total_price');
|
|
//本周打赏新增总数
|
|
$data['user_send_gift_week_amount'] = db::name('user_send_gift')->whereTime('add_time', 'week')->sum('gift_total_price');
|
|
//充值总积分
|
|
$map = [];
|
|
$map[] = ['money_type', '=', 2];
|
|
$map[] = ['change_type', 'in', [1,9]];
|
|
$data['platform_recharge_integral_all_amount'] = db::name('user_money_log')->where($map)->sum('change_value');
|
|
//充值总余额
|
|
$map = [];
|
|
$map[] = ['money_type', '=', 1];
|
|
$map[] = ['change_type', 'in', [1]];
|
|
$data['platform_recharge_money_all_amount'] = db::name('user_money_log')->where($map)->sum('change_value');
|
|
//用户总余额
|
|
$data['user_all_money'] = db::name('user')->sum('money');
|
|
//用户总积分
|
|
$data['user_all_integral'] = db::name('user')->sum('integral');
|
|
//背包礼物总价值
|
|
$map = [];
|
|
$map[] = ['a.num', '>', 0];
|
|
$map[] = ['a.is_tester', '=', 1];
|
|
$data['pack_gift_all_amount'] = db::name('user_gift_pack')->alias('a')->join('yy_gift b', 'a.gid = b.gid')->where($map)->sum('a.num*b.gift_price');
|
|
//总支出
|
|
$map = [];
|
|
$map[] = ['box_type', 'in', [4,5,6]];
|
|
$data['all_out_amount'] = db::name('user_box_count')->where($map)->sum('out_amount');
|
|
//总收入
|
|
$data['all_in_amount'] = db::name('user_box_count')->where($map)->sum('in_amount');
|
|
//总盈亏
|
|
$data['all_profit'] = $data['all_in_amount'] - $data['all_out_amount'];
|
|
//总爆率
|
|
if($data['all_out_amount'] > 0){
|
|
$data['all_rate'] = round($data['all_in_amount']/$data['all_out_amount'],6);
|
|
}else{
|
|
$data['all_rate'] = 0;
|
|
}
|
|
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
//获取打赏金额每天统计
|
|
public function get_send_gift_data_by_day()
|
|
{
|
|
//购买
|
|
$sql = "SELECT FROM_UNIXTIME(add_time, '%Y-%m-%d') AS atime,sum(gift_total_price) as gift_total_price
|
|
FROM yy_user_send_gift where gift_from_type=1 GROUP BY atime ORDER BY atime desc LIMIT 0,72";
|
|
$list = Db::query($sql);
|
|
$gift_data1 = [];
|
|
foreach ($list as $k => $v) {
|
|
$gift_data1[$v['atime']] = $v['gift_total_price'];
|
|
}
|
|
//背包
|
|
$sql = "SELECT FROM_UNIXTIME(add_time, '%Y-%m-%d') AS atime,sum(gift_total_price) as gift_total_price
|
|
FROM yy_user_send_gift where gift_from_type=2 GROUP BY atime ORDER BY atime desc LIMIT 0,72";
|
|
$list = Db::query($sql);
|
|
$gift_data2 = [];
|
|
foreach ($list as $k => $v) {
|
|
$gift_data2[$v['atime']] = $v['gift_total_price'];
|
|
}
|
|
|
|
$now_hour = strtotime(date('Y-m-d'));
|
|
$x_data = [];
|
|
$y_data1 = [];
|
|
$y_data2 = [];
|
|
$y_data3 = [];
|
|
for ($i = 0; $i < 72; $i++) {
|
|
$l_hour = date('Y-m-d', $now_hour - $i * 24 * 3600);
|
|
$x_data[$i] = $l_hour;
|
|
if (!empty($gift_data1[$l_hour])) {
|
|
$y_data2[$i] = $gift_data1[$l_hour];
|
|
} else {
|
|
$y_data2[$i] = 0;
|
|
}
|
|
if (!empty($gift_data2[$l_hour])) {
|
|
$y_data3[$i] = $gift_data2[$l_hour];
|
|
} else {
|
|
$y_data3[$i] = 0;
|
|
}
|
|
$y_data1[$i] = $y_data2[$i] + $y_data3[$i];
|
|
}
|
|
$data = [];
|
|
$data['x_data'] = array_reverse($x_data);
|
|
$data['y_data1'] = array_reverse($y_data1);
|
|
$data['y_data2'] = array_reverse($y_data2);
|
|
$data['y_data3'] = array_reverse($y_data3);
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
//获取打赏金额每小时统计
|
|
public function get_send_gift_data_by_hour()
|
|
{
|
|
//购买
|
|
$sql = "SELECT FROM_UNIXTIME(add_time, '%Y-%m-%d %H:00:00') AS atime,sum(gift_total_price) as gift_total_price
|
|
FROM yy_user_send_gift where gift_from_type=1 GROUP BY atime ORDER BY atime desc LIMIT 0,72";
|
|
$list = Db::query($sql);
|
|
$gift_data1 = [];
|
|
foreach ($list as $k => $v) {
|
|
$gift_data1[$v['atime']] = $v['gift_total_price'];
|
|
}
|
|
//背包
|
|
$sql = "SELECT FROM_UNIXTIME(add_time, '%Y-%m-%d %H:00:00') AS atime,sum(gift_total_price) as gift_total_price
|
|
FROM yy_user_send_gift where gift_from_type=2 GROUP BY atime ORDER BY atime desc LIMIT 0,72";
|
|
$list = Db::query($sql);
|
|
$gift_data2 = [];
|
|
foreach ($list as $k => $v) {
|
|
$gift_data2[$v['atime']] = $v['gift_total_price'];
|
|
}
|
|
|
|
$now_hour = strtotime(date('Y-m-d'));
|
|
$x_data = [];
|
|
$y_data1 = [];
|
|
$y_data2 = [];
|
|
$y_data3 = [];
|
|
for ($i = 0; $i < 72; $i++) {
|
|
$l_hour = date('Y-m-d', $now_hour - $i * 3600);
|
|
$x_data[$i] = $l_hour;
|
|
if (!empty($gift_data1[$l_hour])) {
|
|
$y_data2[$i] = $gift_data1[$l_hour];
|
|
} else {
|
|
$y_data2[$i] = 0;
|
|
}
|
|
if (!empty($gift_data2[$l_hour])) {
|
|
$y_data3[$i] = $gift_data2[$l_hour];
|
|
} else {
|
|
$y_data3[$i] = 0;
|
|
}
|
|
$y_data1[$i] = $y_data2[$i] + $y_data3[$i];
|
|
}
|
|
$data = [];
|
|
$data = [];
|
|
$data['x_data'] = array_reverse($x_data);
|
|
$data['y_data1'] = array_reverse($y_data1);
|
|
$data['y_data2'] = array_reverse($y_data2);
|
|
$data['y_data3'] = array_reverse($y_data3);
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
//不同类型房间统计
|
|
public function get_room_type_date()
|
|
{
|
|
|
|
$room_type_list = db::name('room_type')->column('type_name', 'tid');
|
|
$sql = "SELECT tid,count(1) as count FROM `yy_room` GROUP BY tid";
|
|
$list = Db::query($sql);
|
|
$x_data = [];
|
|
$y_data = [];
|
|
foreach ($list as $k => $v) {
|
|
if (!empty($room_type_list[$v['tid']])) {
|
|
$x_data[$k] = $room_type_list[$v['tid']];
|
|
$y_data[$k]['name'] = $room_type_list[$v['tid']];
|
|
$y_data[$k]['value'] = $v['count'];
|
|
}
|
|
}
|
|
$data = [];
|
|
$data['x_data'] = $x_data;
|
|
$data['y_data'] = $y_data;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
|
|
//陪玩订单数量统计
|
|
public function get_payer_order_date()
|
|
{
|
|
|
|
$game_list = db::name('game')->column('game_name', 'gid');
|
|
$sql = "SELECT gid,count(1) as count,sum(total_amount) AS total_amount FROM `yy_user_player_order` GROUP BY gid";
|
|
$list = Db::query($sql);
|
|
$x_data = [];
|
|
$y_data1 = [];
|
|
$y_data2 = [];
|
|
foreach ($list as $k => $v) {
|
|
if (!empty($game_list[$v['gid']])) {
|
|
$x_data[$k] = $game_list[$v['gid']];
|
|
$y_data1[$k]['name'] = $game_list[$v['gid']];
|
|
$y_data1[$k]['value'] = $v['count'];
|
|
$y_data2[$k]['name'] = $game_list[$v['gid']];
|
|
$y_data2[$k]['value'] = $v['total_amount'];
|
|
}
|
|
}
|
|
$data = [];
|
|
$data['x_data'] = $x_data;
|
|
$data['y_data1'] = $y_data1;
|
|
$data['y_data2'] = $y_data2;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
|
|
|
|
public function get_recharge_rank_list($uid, $time_section, $page, $limit)
|
|
{
|
|
$map = [];
|
|
if (!empty($uid)) {
|
|
$map[] = ['uid', '=', $uid];
|
|
}
|
|
$map[] = ['pay_status', '=', 2];
|
|
if (!empty($time_section)) {
|
|
$time_section = explode(' - ', $time_section);
|
|
if (count($time_section) != 2) {
|
|
return ['code' => 201, 'msg' => '时间区间异常', 'data' => null];
|
|
} else {
|
|
$start_time = $time_section[0];
|
|
$end_time = $time_section[1];
|
|
|
|
$start_time_time = strtotime($start_time);
|
|
$end_time_time = strtotime($end_time);
|
|
$map[] = ['add_time', 'between', [$start_time_time, $end_time_time]];
|
|
}
|
|
}
|
|
$list = db::name('user_recharge')->field('uid,sum(money) as total_money,sum(integral) as total_integral')->where($map)->group('uid')->order('total_money desc')->page($page, $limit)->select();
|
|
$where = [];
|
|
$where[] = ['uid', 'in', array_column($list, 'uid')];
|
|
$user_data = db::name('user')->where($where)->column('*', 'uid');
|
|
foreach ($list as $k => &$v) {
|
|
$v['nick_name'] = mb_convert_encoding(base64_decode($user_data[$v['uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
|
$v['head_pic'] = localpath_to_netpath($user_data[$v['uid']]['head_pic']);
|
|
}
|
|
$data = [];
|
|
$data['count'] = db::name('user_recharge')->where($map)->group('uid')->count();
|
|
$data['list'] = $list;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
public function get_send_gift_rank_list($uid, $time_section, $page, $limit)
|
|
{
|
|
$map = [];
|
|
if (!empty($uid)) {
|
|
$map[] = ['uid', '=', $uid];
|
|
}
|
|
|
|
if (!empty($time_section)) {
|
|
$time_section = explode(' - ', $time_section);
|
|
if (count($time_section) != 2) {
|
|
return ['code' => 201, 'msg' => '时间区间异常', 'data' => null];
|
|
} else {
|
|
$start_time = $time_section[0];
|
|
$end_time = $time_section[1];
|
|
|
|
$start_time_time = strtotime($start_time);
|
|
$end_time_time = strtotime($end_time);
|
|
$map[] = ['add_time', 'between', [$start_time_time, $end_time_time]];
|
|
}
|
|
}
|
|
$list = db::name('user_send_gift')->field('uid,sum(gift_total_price) as total_gift_total_price,sum(gift_num) as total_gift_num')->where($map)->group('uid')->order('total_gift_total_price desc')->page($page, $limit)->select();
|
|
$where = [];
|
|
$where[] = ['uid', 'in', array_column($list, 'uid')];
|
|
$user_data = db::name('user')->where($where)->column('*', 'uid');
|
|
foreach ($list as $k => &$v) {
|
|
$v['nick_name'] = mb_convert_encoding(base64_decode($user_data[$v['uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
|
$v['head_pic'] = localpath_to_netpath($user_data[$v['uid']]['head_pic']);
|
|
}
|
|
$data = [];
|
|
$data['count'] = db::name('user_send_gift')->where($map)->group('uid')->count();
|
|
$data['list'] = $list;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
public function get_receive_gift_rank_list($uid, $time_section, $page, $limit)
|
|
{
|
|
$map = [];
|
|
if (!empty($uid)) {
|
|
$map[] = ['receive_uid', '=', $uid];
|
|
}
|
|
|
|
if (!empty($time_section)) {
|
|
$time_section = explode(' - ', $time_section);
|
|
if (count($time_section) != 2) {
|
|
return ['code' => 201, 'msg' => '时间区间异常', 'data' => null];
|
|
} else {
|
|
$start_time = $time_section[0];
|
|
$end_time = $time_section[1];
|
|
|
|
$start_time_time = strtotime($start_time);
|
|
$end_time_time = strtotime($end_time);
|
|
$map[] = ['add_time', 'between', [$start_time_time, $end_time_time]];
|
|
}
|
|
}
|
|
$list = db::name('user_send_gift')->field('receive_uid,sum(receiver_profit) as total_gift_total_price,sum(gift_num) as total_gift_num')->where($map)->group('receive_uid')->order('total_gift_total_price desc')->page($page, $limit)->select();
|
|
$where = [];
|
|
$where[] = ['uid', 'in', array_column($list, 'receive_uid')];
|
|
$user_data = db::name('user')->where($where)->column('*', 'uid');
|
|
foreach ($list as $k => &$v) {
|
|
$v['nick_name'] = mb_convert_encoding(base64_decode($user_data[$v['receive_uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
|
$v['head_pic'] = localpath_to_netpath($user_data[$v['receive_uid']]['head_pic']);
|
|
}
|
|
$data = [];
|
|
$data['count'] = db::name('user_send_gift')->where($map)->group('receive_uid')->count();
|
|
$data['list'] = $list;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
public function get_player_order_rank_list($uid, $time_section, $order, $sort, $page, $limit)
|
|
{
|
|
$map = [];
|
|
if (!empty($uid)) {
|
|
$map[] = ['player_uid', '=', $uid];
|
|
}
|
|
$map[] = ['status', '=', 3];
|
|
$map[] = ['is_over', '=', 1];
|
|
if (!empty($time_section)) {
|
|
$time_section = explode(' - ', $time_section);
|
|
if (count($time_section) != 2) {
|
|
return ['code' => 201, 'msg' => '时间区间异常', 'data' => null];
|
|
} else {
|
|
$start_time = $time_section[0];
|
|
$end_time = $time_section[1];
|
|
|
|
$start_time_time = strtotime($start_time);
|
|
$end_time_time = strtotime($end_time);
|
|
$map[] = ['add_time', 'between', [$start_time_time, $end_time_time]];
|
|
}
|
|
}
|
|
|
|
$list = db::name('user_player_order')->field('uid,sum(total_amount) as total_total_amount,sum(num) as total_num')->where($map)->group('player_uid')->order('total_total_amount desc')->page($page, $limit)->select();
|
|
$where = [];
|
|
$where[] = ['uid', 'in', array_column($list, 'uid')];
|
|
$user_data = db::name('user')->where($where)->column('*', 'uid');
|
|
foreach ($list as $k => &$v) {
|
|
$v['nick_name'] = mb_convert_encoding(base64_decode($user_data[$v['uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
|
$v['head_pic'] = localpath_to_netpath($user_data[$v['uid']]['head_pic']);
|
|
}
|
|
$data = [];
|
|
$data['count'] = db::name('user_player_order')->where($map)->group('uid')->count();
|
|
$data['list'] = $list;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
|
|
//用户消费排行统计
|
|
|
|
public function get_user_consume_rank_list($uid, $time_section, $page, $limit)
|
|
{
|
|
$map = [];
|
|
if (!empty($uid)) {
|
|
$map[] = ['uid', '=', $uid];
|
|
}
|
|
$map[] = ['money_type', '=', 1];
|
|
$map[] = ['change_value', '<', 0];
|
|
if (!empty($time_section)) {
|
|
$time_section = explode(' - ', $time_section);
|
|
if (count($time_section) != 2) {
|
|
return ['code' => 201, 'msg' => '时间区间异常', 'data' => null];
|
|
} else {
|
|
$start_time = $time_section[0];
|
|
$end_time = $time_section[1];
|
|
|
|
$start_time_time = strtotime($start_time);
|
|
$end_time_time = strtotime($end_time);
|
|
$map[] = ['add_time', 'between', [$start_time_time, $end_time_time]];
|
|
}
|
|
}
|
|
|
|
|
|
$list = db::name('user_money_log')->field('uid,ABS(SUM(change_value)) as total_change_value')->where($map)->group('uid')->order('total_change_value desc')->page($page, $limit)->select();
|
|
$where = [];
|
|
$where[] = ['uid', 'in', array_column($list, 'uid')];
|
|
$user_data = db::name('user')->where($where)->column('*', 'uid');
|
|
foreach ($list as $k => &$v) {
|
|
$v['nick_name'] = mb_convert_encoding(base64_decode($user_data[$v['uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
|
$v['head_pic'] = localpath_to_netpath($user_data[$v['uid']]['head_pic']);
|
|
}
|
|
$data = [];
|
|
$data['count'] = db::name('user_money_log')->where($map)->group('uid')->count();
|
|
$data['list'] = $list;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
}
|