房间小时榜相关

This commit is contained in:
2025-09-29 18:29:08 +08:00
parent 5279199cec
commit 0a2f05a928
7 changed files with 138 additions and 9 deletions

View File

@@ -31,7 +31,7 @@ class RoomHourRanking extends BaseCom
return V($reslut['code'], $reslut['msg'], $reslut['data']);
}
//房间小时榜
//房间小时榜 测试 等会删除
public function room_hour_rankings()
{
$page = input('page', 1);

View File

@@ -35,7 +35,7 @@ class RoomHourRanking extends Model
$profit = db::name('vs_room')->alias('a')
->join('vs_give_gift b', 'a.id = b.from_id AND b.from = 2 AND b.createtime BETWEEN '.$start_time.' AND '.$end_time, 'left')
->join('vs_room_label c', 'a.label_id = c.id','left')
->field('a.id as room_id,a.room_name,a.label_id,a.room_cover,IFNULL(sum(b.total_price), 0) as total_price,c.label_icon')
->field('a.id as room_id,a.user_id,a.room_name,a.label_id,a.room_cover,IFNULL(sum(b.total_price), 0) as total_price,c.label_icon')
->where('a.room_status', 1) // 只统计正常状态的房间
->where('a.apply_status', 2) // 只统计审核通过的房间
->where('a.type_id', '<>', 6)

View File

@@ -34,6 +34,8 @@ class UserGiftPack extends Model
const DRAW_GIFT = 7;
//巡乐会抽奖所得
const XLH_DRAW_GIFT_GET = 8;
//小时榜获得
const HOUR_RANK_GET = 9;
public static function init()
{
@@ -51,7 +53,8 @@ class UserGiftPack extends Model
self::GIFT_USE => '礼物使用',
self::FIRST_CHARGE => '首充获得',
self::DRAW_GIFT => '天降好礼获得',
self::XLH_DRAW_GIFT_GET => '巡乐会抽奖所得'
self::XLH_DRAW_GIFT_GET => '巡乐会抽奖所得',
self::HOUR_RANK_GET => '小时榜获得'
];
}

View File

@@ -50,6 +50,7 @@ class UserWallet extends Model
// 1.系统调节 2.充值 3.提现 4.金币转增(送出) 5.每日任务奖励 6.充值返利 7.购买装扮
// 8.礼盒奖励 9.房间补贴 10.购买礼物 11.收礼增加收益 12.工会补贴 13.转赠金币(接收) 14.收益兑换
// 15.首充 16.天降好礼充值 17.退出工会扣款 18.房主收益 19.主持人收益20.发布头条扣除余额,21.公会长收益,22.提现驳回或提现失败返还,23.财富等级奖励金币领取,24.删除关系扣金币
//27.小时榜获得
if($gift_type == 1){ //1金币2收益钻石
if($in_out_type == 1){//1收入
$in_out_types = [2,5,6,8,13,14,15,16,22,23,26];

View File

@@ -73,6 +73,8 @@ class Push
//房间盘推送
//巡乐会推送开启进度推送
const PUSH_ROOM_PAN_XLH_PROGRESS = 8000;
//小时榜
const PUSH_ROOM_PAN_HOUR_PROGRESS = 8001;
public $user_id, $room_id, $topic_room, $topic_client;
@@ -299,6 +301,11 @@ class Push
$this->push(self::PUSH_ROOM_PAN_XLH_PROGRESS, $topic, $data);
}
//小时榜推送
public function hourRanking($data){
$topic = 'qx_hour_ranking';
$this->push(self::PUSH_ROOM_PAN_HOUR_PROGRESS, $topic, $data);
}

View File

@@ -73,6 +73,8 @@ class UserWallet extends Model
const TRANSFER_COIN = 25;
//好友转赠所得金币
const RECEIVE_COIN = 26;
//小时榜获得金币
const HOUR_RANK_COIN = 27;
//金币支出类型数组
@@ -135,7 +137,8 @@ class UserWallet extends Model
self::FINANCE_LEVEL_REWARD => '财富等级奖励金币领取',
self::DELETE_RELATION_COIN => '删除关系扣金币',
self::TRANSFER_COIN => '赠送好友金币',
self::RECEIVE_COIN => '好友转赠所得金币'
self::RECEIVE_COIN => '好友转赠所得金币',
self::HOUR_RANK_COIN => '小时榜获得金币'
];
return $status[$type] ?? '';
}

View File

@@ -2,8 +2,9 @@
namespace app\cron\controller;
use app\common\controller\Push;
use think\Db;
use function fast\e;
use think\Log;
class RoomHourRanking
{
@@ -23,7 +24,8 @@ class RoomHourRanking
//获取上一个小时的开始时间和结束时间
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
$end_time = strtotime(date('Y-m-d H:00:00'));
//当前小时的前一个小时24小时计时法0-23
$pre_hour = date('H', strtotime('-1 hour'));
//是否全局飘瓶
$is_public_server = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('is_public_server');
if ($is_public_server == 1) {
@@ -33,8 +35,7 @@ class RoomHourRanking
if($xlh_time_range == 25){
$is_piao = 1;
}else{
//当前小时的前一个小时24小时计时法0-23
$pre_hour = date('H', strtotime('-1 hour'));
//当前的前一个小时是否在 $xlh_time_range中
if (in_array($pre_hour, explode(',', $xlh_time_range))) {
$is_piao = 1;
@@ -49,7 +50,121 @@ class RoomHourRanking
$is_piao = 0;
}
//获取一个小时的房间排行
//获取一个时间段的配置
$gift_list = db::name('vs_hour_ranking_gift_config')->where('time_id',$pre_hour)->group('ranking')->order('id', 'desc')->select();
//获取上个数组的个数,从而获取配置了多少个名次
$count = count($gift_list);
//获取前一个小时的 前$count名房间排行
$room_list = model('api/RoomHourRanking')->room_hour_ranking(1, $count, $start_time, $end_time);
$room_owner = [];
if ($room_list['code'] == 1) {
//获取房间排行奖励最低值
$min_price = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('min_price');
if ($room_list['data']['lists']) {
$i = 0;
foreach ($room_list['data']['lists'] as $k => $v){
if ($v['total_price'] >= $min_price) {
$room_owner[$i]['user_id'] = $v['user_id'];
$room_owner[$i]['room_name'] = $v['room_name'];
}
$i++;
}
}
}
$push = new Push();
if ($gift_list && $room_owner) {
foreach ($gift_list as $k => $v) {
//礼物全部给他偷偷放在装扮表及金额 中
//有几个用户就发几个
if(count($room_owner) > $k){
if($v['gift_type'] == 1){//1金币2礼物3头像4坐骑
$res = $this->add_coin($v['coin'], $room_owner[$k]['user_id']);
}elseif ($v['gift_type'] == 2){
$res = $this->add_gift($v['gift_id'], $room_owner[$k]['user_id']);
}elseif ($v['gift_type'] == 3){
$res = $this->add_decorate($v['gift_id'], $room_owner[$k]['user_id']);
}elseif ($v['gift_type'] == 4){
$res = $this->add_decorate($v['gift_id'], $room_owner[$k]['user_id']);
}
if(isset($res) && $res){
if($is_piao == 1){
$room_name = $room_owner[$k]['room_name'];
//推送礼物横幅
if($k == 0){
$text = '新科状元!【'.$room_name.'】独占鳌头!';
}
elseif($k == 1){
$text = '金榜榜眼!【'.$room_name.'】才气逼人!';
}
elseif($k == 2){
$text = '风采探花!【'.$room_name.'】实力绽放!';
}
$text_list_new[] = [
'text' => $text ?? '恭喜【'.$room_name.'】获得礼物!'
];
$push->hourRanking($text_list_new);
}
}
}
}
}
return true;
}
//添加金币到钱包
public function add_coin($coin,$user_id){
$data = [
'user_id' => $user_id,
'change_value' => $coin,
// 'room_id' => $room_ids,
'money_type' => 1,
'change_type' => 27,
'from_id' => 0,
'remarks' => '小时榜获得',
'createtime' => time()
];
//开启事务
Db::startTrans();
$res = Db::name('vs_user_money_log')->insert($data);
if(!$res){
Db::rollback();
}
//增加用户金币
$res1 = Db::name('user_wallet')->where(['user_id'=>$user_id])->setInc('coin',$coin);
if(!$res1){
Db::rollback();
}
Db::commit();
return true;
}
//添加礼物到背包
public function add_gift($gift_id,$user_id){
$res = model('api/UserGiftPack')->change_user_gift_pack($user_id,$gift_id,1,model('UserGiftPack')::HOUR_RANK_GET,"小时榜获得");
if($res['code'] == 0){
Log::record("小时榜获取礼物失败:".$res['msg'],"info");
}
return true;
}
//添加装扮到背包
public function add_decorate($avatar_id,$user_id){
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$avatar_id])->find();
if(empty($decorate_price_info)){
Log::record("小时榜获取装扮失败:没有找到装扮!".$avatar_id,"info");
}
$res = model('api/Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],2);
if($res['code'] == 0){
Log::record("小时榜获取装扮失败:".$res['msg']."-".$avatar_id,"info");
}
return true;
}
}