房间送礼信息 和 进入小黑屋

This commit is contained in:
2026-01-07 20:12:49 +08:00
parent 92cf24a9dd
commit 3087e7aa6a
3 changed files with 366 additions and 26 deletions

View File

@@ -0,0 +1,301 @@
<?php
namespace app\api\model;
use app\common\model\GiveGiftBase;
use think\Cache;
use think\Log;
use think\Model;
class GiveGiftBases extends Model
{
protected $giftModel;
public function __construct()
{
parent::__construct();
$this->giftModel = new GiveGiftBase();
}
/**
* 获取送礼记录
*/
public function getGiftRecords($params)
{
// $params = $this->request->param();
$where = [];
$options = [];
// 构建查询条件
if (!empty($params['from_id'])) {
$where['from_id'] = $params['from_id'];
}
if (!empty($params['user_id'])) {
$where['user_id'] = $params['user_id'];
}
if (!empty($params['gift_user'])) {
$where['gift_user'] = $params['gift_user'];
}
if (!empty($params['gift_id'])) {
$where['gift_id'] = $params['gift_id'];
}
if (!empty($params['type'])) {
$where['type'] = $params['type'];
}
if (!empty($params['from'])) {
$where['from'] = $params['from'];
}
if (!empty($params['gift_type'])) {
$where['gift_type'] = $params['gift_type'];
}
// 时间范围
if (!empty($params['start_time'])) {
$options['start_time'] = intval($params['start_time']);
}
if (!empty($params['end_time'])) {
$options['end_time'] = intval($params['end_time']);
}
// 分页参数
$options['page'] = $params['page'] ?? 1;
$options['limit'] = min($params['limit'] ?? 20, 100); // 限制最大100条
// 排序
if (!empty($params['order'])) {
$options['order'] = $params['order'];
}
// 查询数据
$result = $this->giftModel->getGiftRecords($where, $options);
Log::info("查询送礼记录,条件: " . json_encode($where) . ", 结果数: " . count($result['data']));
// $this->success('获取成功', $result);
return $result;
}
/**
* 房间送礼统计
*/
public function getRoomStatistics()
{
$fromId = $this->request->param('from_id/d', 0);
$startTime = $this->request->param('start_time/d', strtotime('-7 days'));
$endTime = $this->request->param('end_time/d', time());
if (!$fromId) {
$this->error('房间ID不能为空');
}
// 尝试从缓存获取
$cacheKey = "gift:room:stats:{$fromId}:" . date('Ymd', $startTime) . '-' . date('Ymd', $endTime);
$cachedData = Cache::get($cacheKey);
if ($cachedData !== false) {
Log::info("从缓存获取房间统计: {$cacheKey}");
$this->success('获取成功', $cachedData);
}
$where = ['from_id' => $fromId];
$options = [
'start_time' => $startTime,
'end_time' => $endTime,
];
// 统计房间总数据
$totalStats = $this->giftModel->getGiftStatistics($where, $options);
// 按送礼人分组统计
$userStats = $this->giftModel->getGiftStatistics($where, array_merge($options, [
'group_by' => 'user_id'
]));
// 按收礼人分组统计
$receiverStats = $this->giftModel->getGiftStatistics($where, array_merge($options, [
'group_by' => 'gift_user'
]));
$result = [
'room_id' => $fromId,
'time_range' => [
'start_time' => $startTime,
'end_time' => $endTime,
'start_date' => date('Y-m-d H:i:s', $startTime),
'end_date' => date('Y-m-d H:i:s', $endTime),
],
'total_stats' => $totalStats,
'user_stats' => $userStats,
'receiver_stats' => $receiverStats,
];
// 缓存5分钟
Cache::set($cacheKey, $result, 300);
Log::info("房间统计计算完成: {$fromId}, 送礼人数: " . count($userStats) . ", 收礼人数: " . count($receiverStats));
$this->success('获取成功', $result);
}
/**
* 用户送礼统计
*/
public function getUserStatistics()
{
$userId = $this->request->param('user_id/d', 0);
$startTime = $this->request->param('start_time/d', strtotime('-30 days'));
$endTime = $this->request->param('end_time/d', time());
if (!$userId) {
$this->error('用户ID不能为空');
}
$cacheKey = "gift:user:stats:{$userId}:" . date('Ymd', $startTime) . '-' . date('Ymd', $endTime);
$cachedData = Cache::get($cacheKey);
if ($cachedData !== false) {
Log::info("从缓存获取用户统计: {$cacheKey}");
$this->success('获取成功', $cachedData);
}
$where = ['user_id' => $userId];
$options = [
'start_time' => $startTime,
'end_time' => $endTime,
];
// 用户总送礼统计
$totalStats = $this->giftModel->getGiftStatistics($where, $options);
// 按房间分组统计
$roomStats = $this->giftModel->getGiftStatistics($where, array_merge($options, [
'group_by' => 'from_id'
]));
// 按收礼人分组统计
$receiverStats = $this->giftModel->getGiftStatistics($where, array_merge($options, [
'group_by' => 'gift_user'
]));
$result = [
'user_id' => $userId,
'time_range' => [
'start_time' => $startTime,
'end_time' => $endTime,
'start_date' => date('Y-m-d H:i:s', $startTime),
'end_date' => date('Y-m-d H:i:s', $endTime),
],
'total_stats' => $totalStats,
'room_stats' => $roomStats,
'receiver_stats' => $receiverStats,
];
// 缓存5分钟
Cache::set($cacheKey, $result, 300);
Log::info("用户统计计算完成: {$userId}, 房间数: " . count($roomStats) . ", 收礼人数: " . count($receiverStats));
$this->success('获取成功', $result);
}
/**
* 收礼统计
*/
public function getReceiveStatistics()
{
$giftUser = $this->request->param('gift_user/d', 0);
$startTime = $this->request->param('start_time/d', strtotime('-30 days'));
$endTime = $this->request->param('end_time/d', time());
if (!$giftUser) {
$this->error('用户ID不能为空');
}
$cacheKey = "gift:receive:stats:{$giftUser}:" . date('Ymd', $startTime) . '-' . date('Ymd', $endTime);
$cachedData = Cache::get($cacheKey);
if ($cachedData !== false) {
Log::info("从缓存获取收礼统计: {$cacheKey}");
$this->success('获取成功', $cachedData);
}
$where = ['gift_user' => $giftUser];
$options = [
'start_time' => $startTime,
'end_time' => $endTime,
];
// 总收礼统计
$totalStats = $this->giftModel->getGiftStatistics($where, $options);
// 按房间分组统计
$roomStats = $this->giftModel->getGiftStatistics($where, array_merge($options, [
'group_by' => 'from_id'
]));
// 按送礼人分组统计
$giverStats = $this->giftModel->getGiftStatistics($where, array_merge($options, [
'group_by' => 'user_id'
]));
$result = [
'gift_user' => $giftUser,
'time_range' => [
'start_time' => $startTime,
'end_time' => $endTime,
'start_date' => date('Y-m-d H:i:s', $startTime),
'end_date' => date('Y-m-d H:i:s', $endTime),
],
'total_stats' => $totalStats,
'room_stats' => $roomStats,
'giver_stats' => $giverStats,
];
// 缓存5分钟
Cache::set($cacheKey, $result, 300);
Log::info("收礼统计计算完成: {$giftUser}, 房间数: " . count($roomStats) . ", 送礼人数: " . count($giverStats));
$this->success('获取成功', $result);
}
/**
* 获取送礼趋势
*/
public function getGiftTrend()
{
$params = $this->request->param();
$startTime = $params['start_time'] ?? strtotime('-7 days');
$endTime = $params['end_time'] ?? time();
$interval = $params['interval'] ?? 'day';
if (!in_array($interval, ['day', 'week', 'month'])) {
$interval = 'day';
}
$cacheKey = "gift:trend:" . date('Ymd', $startTime) . '-' . date('Ymd', $endTime) . ":{$interval}";
$cachedData = Cache::get($cacheKey);
if ($cachedData !== false) {
$this->success('获取成功', $cachedData);
}
$trendData = $this->giftModel->getTrendStatistics($startTime, $endTime, $interval);
// 缓存10分钟
Cache::set($cacheKey, $trendData, 600);
$this->success('获取成功', [
'trend_data' => $trendData,
'interval' => $interval,
'time_range' => [
'start_time' => $startTime,
'end_time' => $endTime
]
]);
}
}

View File

@@ -482,6 +482,15 @@ class Room extends Model
* 按天统计指定房间流水
*/
public function room_turnover_detail($room_id,$stime,$etime,$page,$page_limit) {
$params['from_id'] = $room_id;
$params['start_time'] = $stime;
$params['end_time'] = $etime;
$params['page'] = $page;
$params['limit'] = $page_limit;
$res = model('GiveGiftBases')->getGiftRecords($params);
$page = intval($page);
$page_limit = $page_limit < 20 ? $page_limit : 20;
$s_type =0;
@@ -1795,31 +1804,61 @@ class Room extends Model
//私密房
public function cp_room($room_id,$user_id)
{
//查看房间时间是否已到期
$room_time = db::name('vs_room_cp_movie')->where(['room_id' => $room_id])->value('time_day');
if($room_time <= time()){
db::name('vs_room')->where(['id' => $room_id])->update(['room_status' => 3]);
db::name('vs_room_cp_movie')->where(['room_id' => $room_id])->update(['status' => 2]);
model('api/Tencent')->delete_group('room'.$room_id);
return ['code' => 0, 'msg' => 'cp房间已到期', 'data' => ''];
$room_label = db::name('vs_room')->where(['id' => $room_id])->value('label_id');
if($room_label != 11){
//查看房间时间是否已到期
$room_time = db::name('vs_room_cp_movie')->where(['room_id' => $room_id])->value('time_day');
if($room_time <= time()){
db::name('vs_room')->where(['id' => $room_id])->update(['room_status' => 3]);
db::name('vs_room_cp_movie')->where(['room_id' => $room_id])->update(['status' => 2]);
model('api/Tencent')->delete_group('room'.$room_id);
return ['code' => 0, 'msg' => 'cp房间已到期', 'data' => ''];
}
$room_status = db::name('vs_room_cp_movie')->where(['room_id' => $room_id])->value('status');
if($room_status == 4){
db::name('vs_room')->where(['id' => $room_id])->update(['room_status' => 3]);
return ['code' => 0, 'msg' => '房间已被迫结束', 'data' => ''];
}
$cp_users = db::name('vs_room_cp_movie')->alias('a')
->join('user b', 'a.user_id = b.id', 'left')
->join('user c', 'a.user_id1 = c.id', 'left')
->where(['room_id' => $room_id,'a.status' => 1])
->field('a.time_day,a.cp_id,a.user_id,a.user_id1,b.nickname,c.nickname as nickname1,b.avatar,c.avatar as avatar1,b.user_code,c.user_code as user_code1')
->find();
//非cp房用户不得进入
if($cp_users['user_id'] != $user_id && $cp_users['user_id1'] != $user_id){
return ['code' => 0, 'msg' => '您不是房间的cp用户请勿进入', 'data' => ''];
}
$cp_users['dress'] = model('api/Decorate')->user_decorate_detail($cp_users['user_id'],1);
$cp_users['dress1'] = model('api/Decorate')->user_decorate_detail($cp_users['user_id1'],1);
}else{
//查看房间时间是否已到期
$room_time = db::name('vs_room_bar_movie')->where(['room_id' => $room_id])->value('end_time');
if($room_time <= time()){
db::name('vs_room')->where(['id' => $room_id])->update(['room_status' => 3]);
db::name('vs_room_bar_movie')->where(['room_id' => $room_id])->update(['status' => 2]);
model('api/Tencent')->delete_group('room'.$room_id);
return ['code' => 0, 'msg' => 'cp房间已到期', 'data' => ''];
}
$room_status = db::name('vs_room_bar_movie')->where(['room_id' => $room_id])->value('status');
if($room_status == 4){
db::name('vs_room')->where(['id' => $room_id])->update(['room_status' => 3]);
return ['code' => 0, 'msg' => '房间已被迫结束', 'data' => ''];
}
$cp_users = db::name('vs_room_bar_movie')->alias('a')
->join('user b', 'a.user_id = b.id', 'left')
->join('user c', 'a.meet_user_id = c.id', 'left')
->where(['room_id' => $room_id,'a.status' => 1])
->field('a.end_time as time_day,a.id as cp_id,a.user_id,a.meet_user_id as user_id1,b.nickname,c.nickname as nickname1,b.avatar,c.avatar as avatar1,b.user_code,c.user_code as user_code1')
->find();
//非cp房用户不得进入
if($cp_users['user_id'] != $user_id && $cp_users['user_id1'] != $user_id){
return ['code' => 0, 'msg' => '您不是房间的cp用户请勿进入', 'data' => ''];
}
$cp_users['dress'] = model('api/Decorate')->user_decorate_detail($cp_users['user_id'],1);
$cp_users['dress1'] = model('api/Decorate')->user_decorate_detail($cp_users['user_id1'],1);
}
$room_status = db::name('vs_room_cp_movie')->where(['room_id' => $room_id])->value('status');
if($room_status == 4){
db::name('vs_room')->where(['id' => $room_id])->update(['room_status' => 3]);
return ['code' => 0, 'msg' => '房间已被迫结束', 'data' => ''];
}
$cp_users = db::name('vs_room_cp_movie')->alias('a')
->join('user b', 'a.user_id = b.id', 'left')
->join('user c', 'a.user_id1 = c.id', 'left')
->where(['room_id' => $room_id,'a.status' => 1])
->field('a.time_day,a.cp_id,a.user_id,a.user_id1,b.nickname,c.nickname as nickname1,b.avatar,c.avatar as avatar1,b.user_code,c.user_code as user_code1')
->find();
//非cp房用户不得进入
if($cp_users['user_id'] != $user_id && $cp_users['user_id1'] != $user_id){
return ['code' => 0, 'msg' => '您不是房间的cp用户请勿进入', 'data' => ''];
}
$cp_users['dress'] = model('api/Decorate')->user_decorate_detail($cp_users['user_id'],1);
$cp_users['dress1'] = model('api/Decorate')->user_decorate_detail($cp_users['user_id1'],1);
return $cp_users;
}

View File

@@ -1,5 +1,5 @@
<?php
// application/common/model/GiveGiftBase.php
// application/common/model/GiveGiftBases.php
namespace app\common\model;
@@ -276,7 +276,7 @@ class GiveGiftBase extends Model
$data = [];
if ($total > 0) {
$offset = ($options['page'] - 1) * $options['limit'];
$dataSql = "{$unionSql} ORDER BY {$options['order']} LIMIT {$offset}, {$options['limit']}";
$dataSql = "{$unionSql} ORDER BY {$options['order']} DESC LIMIT {$offset}, {$options['limit']}";
try {
$data = Db::query($dataSql, $params);