房间小时榜
This commit is contained in:
@@ -43,4 +43,10 @@ class Cron
|
|||||||
$cron = new \app\cron\controller\FriendEnd();
|
$cron = new \app\cron\controller\FriendEnd();
|
||||||
$cron->index();
|
$cron->index();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//房间小时榜发礼物(每小时执行一次)
|
||||||
|
public function RoomHourRanking(){
|
||||||
|
$cron = new \app\cron\controller\RoomHourRanking();
|
||||||
|
$cron->index();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,39 +26,9 @@ class RoomHourRanking extends BaseCom
|
|||||||
{
|
{
|
||||||
$page = input('page', 1);
|
$page = input('page', 1);
|
||||||
$page_limit = input('page_limit', 20);
|
$page_limit = input('page_limit', 20);
|
||||||
//判断是否开启
|
|
||||||
$open_time = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('open_time');
|
|
||||||
if ($open_time = 0) {
|
|
||||||
return V(0, '排行榜暂未开启');
|
|
||||||
}
|
|
||||||
|
|
||||||
//当前小时开始时间
|
$reslut = model('RoomHourRanking')->room_hour_ranking($page, $page_limit);
|
||||||
$start_time = strtotime(date('Y-m-d H:00:00'));
|
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||||
|
|
||||||
$profit = db::name('vs_room')->alias('a')
|
|
||||||
->join('vs_give_gift b', 'a.id = b.from_id','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')
|
|
||||||
->where('a.room_status', 1) // 只统计正常状态的房间
|
|
||||||
->where('a.apply_status', 2) // 只统计审核通过的房间
|
|
||||||
->where('b.from', 2)
|
|
||||||
->where('b.createtime', 'between', [$start_time, time()])
|
|
||||||
->group('a.id')
|
|
||||||
->order('total_price', 'desc')
|
|
||||||
->page($page, $page_limit)
|
|
||||||
->select();
|
|
||||||
|
|
||||||
if($profit){
|
|
||||||
foreach ($profit as &$v) {
|
|
||||||
if($v['room_id'] > 0){
|
|
||||||
$xlh_status = model('BlindBoxTurntableGift')->get_user_xlh_info($v['room_id']);
|
|
||||||
$v['xlh_status'] = $xlh_status['xlh_status'];
|
|
||||||
}else{
|
|
||||||
$v['xlh_status'] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return V(1, '获取成功', $profit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//房间小时榜
|
//房间小时榜
|
||||||
@@ -72,6 +42,12 @@ class RoomHourRanking extends BaseCom
|
|||||||
// return V(0, '排行榜暂未开启');
|
// return V(0, '排行榜暂未开启');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//是否开启巡乐会
|
||||||
|
$is_open_xlh = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('is_open_xlh');
|
||||||
|
//是否开启红包(下面的不要删掉)
|
||||||
|
// $is_open_red_pack = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('is_open_red_pack');
|
||||||
|
$is_open_red_pack = 0 ;
|
||||||
|
|
||||||
//当前小时开始时间
|
//当前小时开始时间
|
||||||
$start_time = strtotime(date('Y-m-d H:00:00'));
|
$start_time = strtotime(date('Y-m-d H:00:00'));
|
||||||
|
|
||||||
@@ -107,7 +83,7 @@ class RoomHourRanking extends BaseCom
|
|||||||
foreach ($rooms as &$room) {
|
foreach ($rooms as &$room) {
|
||||||
$room['total_price'] = isset($gift_map[$room['room_id']]) ? $gift_map[$room['room_id']] : 0;
|
$room['total_price'] = isset($gift_map[$room['room_id']]) ? $gift_map[$room['room_id']] : 0;
|
||||||
|
|
||||||
if($room['room_id'] > 0){
|
if($room['room_id'] > 0 && $is_open_xlh == 1){
|
||||||
$xlh_status = model('BlindBoxTurntableGift')->get_user_xlh_info($room['room_id']);
|
$xlh_status = model('BlindBoxTurntableGift')->get_user_xlh_info($room['room_id']);
|
||||||
$room['xlh_status'] = $xlh_status['xlh_status'];
|
$room['xlh_status'] = $xlh_status['xlh_status'];
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
61
application/api/model/RoomHourRanking.php
Normal file
61
application/api/model/RoomHourRanking.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\model;
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class RoomHourRanking extends Model
|
||||||
|
{
|
||||||
|
//房间小时榜
|
||||||
|
public function room_hour_ranking($page, $page_limit,$start_time = null, $end_time = null)
|
||||||
|
{
|
||||||
|
//当前小时开始时间
|
||||||
|
if($start_time == null){
|
||||||
|
$start_time = strtotime(date('Y-m-d H:00:00'));
|
||||||
|
}
|
||||||
|
|
||||||
|
//结束时间
|
||||||
|
if($end_time == null){
|
||||||
|
$end_time = strtotime(date('Y-m-d H:59:59'));
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否开启
|
||||||
|
$open_time = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('open_time');
|
||||||
|
if ($open_time == 0) {
|
||||||
|
return ['code' => 0, 'msg' => '排行榜暂未开启', 'data' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
//是否开启巡乐会
|
||||||
|
$is_open_xlh = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('is_open_xlh');
|
||||||
|
//是否开启红包(下面的不要删掉,以后要用)
|
||||||
|
// $is_open_red_pack = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('is_open_red_pack');
|
||||||
|
$is_open_red_pack = 0 ;
|
||||||
|
|
||||||
|
$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')
|
||||||
|
->where('a.room_status', 1) // 只统计正常状态的房间
|
||||||
|
->where('a.apply_status', 2) // 只统计审核通过的房间
|
||||||
|
->group('a.id')
|
||||||
|
->order('total_price', 'desc')
|
||||||
|
->page($page, $page_limit)
|
||||||
|
->select();
|
||||||
|
|
||||||
|
if($profit){
|
||||||
|
foreach ($profit as &$v) {
|
||||||
|
if($v['room_id'] > 0 && $is_open_xlh == 1){
|
||||||
|
$xlh_status = model('BlindBoxTurntableGift')->get_user_xlh_info($v['room_id']);
|
||||||
|
$v['xlh_status'] = $xlh_status['xlh_status'];
|
||||||
|
}else{
|
||||||
|
$v['xlh_status'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//当前小时开始时间 和结束时间 00:00-00:59 这样的格式
|
||||||
|
$time_range = date('H:') . '00-' . date('H:'). '59';
|
||||||
|
return ['code' => 1, 'msg' => '获取成功', 'data' => ['time_range' => $time_range, 'lists' =>$profit]];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
55
application/cron/controller/RoomHourRanking.php
Normal file
55
application/cron/controller/RoomHourRanking.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\cron\controller;
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
use function fast\e;
|
||||||
|
|
||||||
|
class RoomHourRanking
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* 运行函数
|
||||||
|
*/
|
||||||
|
function index()
|
||||||
|
{
|
||||||
|
echo "小时榜 开始发礼物:\n";
|
||||||
|
$this->send_gift();//小时榜 送礼物
|
||||||
|
echo "发礼物结束 \n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function send_gift()
|
||||||
|
{
|
||||||
|
//获取上一个小时的开始时间和结束时间
|
||||||
|
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||||
|
$end_time = strtotime(date('Y-m-d H:00:00'));
|
||||||
|
|
||||||
|
//是否全局飘瓶
|
||||||
|
$is_public_server = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('is_public_server');
|
||||||
|
if ($is_public_server == 1) {
|
||||||
|
//全局飘瓶时间段
|
||||||
|
$xlh_time_range = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('broadcast_times');
|
||||||
|
if($xlh_time_range){
|
||||||
|
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;
|
||||||
|
} else {
|
||||||
|
$is_piao = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$is_piao = 0;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$is_piao = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取前一个小时的房间排行
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user