76 lines
2.9 KiB
PHP
76 lines
2.9 KiB
PHP
<?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')->where('id', 1)->value('open_time');
|
|
if ($open_time == 0) {
|
|
return ['code' => 0, 'msg' => '排行榜暂未开启', 'data' => null];
|
|
}
|
|
|
|
//是否开启巡乐会
|
|
$is_open_xlh = db::name('vs_hour_ranking_config')->where('id', 1)->value('is_open_xlh');
|
|
//是否开启红包(下面的不要删掉,以后要用)
|
|
// $is_open_red_pack = db::name('vs_hour_ranking_config')->where('id', 1)->value('is_open_red_pack');
|
|
$is_open_red_pack = 0 ;
|
|
|
|
// 更进一步的优化版本:
|
|
$subQuery = Db::name('vs_give_gift')
|
|
->where('from', 2)
|
|
->whereBetween('createtime', [$start_time, $end_time])
|
|
->buildSql();
|
|
|
|
$profit = db::name('vs_room')->alias('a')
|
|
->join([$subQuery => '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.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)
|
|
->group('a.id')
|
|
->order('total_price', 'desc')
|
|
->page($page, $page_limit)
|
|
->select();
|
|
|
|
if($profit){
|
|
foreach ($profit as &$v) {
|
|
$v['total_price'] = $v['total_price'] * get_system_config_value('coin_charm_exp');
|
|
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;
|
|
}
|
|
//查询房间是否有红包
|
|
if($v['room_id'] > 0){
|
|
$red_pack_status = Db::name('redpacket')->where(['room_id' => $v['room_id'], 'status' => ['<=',1]])->count();
|
|
$v['redpacket_status'] = $red_pack_status;
|
|
}else{
|
|
$v['redpacket_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]];
|
|
}
|
|
|
|
} |