小时榜优化
This commit is contained in:
@@ -32,12 +32,29 @@ class RoomHourRanking extends Model
|
|||||||
// $is_open_red_pack = db::name('vs_hour_ranking_config')->where('id', 1)->value('is_open_red_pack');
|
// $is_open_red_pack = db::name('vs_hour_ranking_config')->where('id', 1)->value('is_open_red_pack');
|
||||||
$is_open_red_pack = 0 ;
|
$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.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();
|
||||||
|
// 更进一步的优化版本:
|
||||||
|
$subQuery = Db::name('vs_give_gift')
|
||||||
|
->where('from', 2)
|
||||||
|
->whereBetween('createtime', [$start_time, $end_time])
|
||||||
|
->buildSql();
|
||||||
|
|
||||||
$profit = db::name('vs_room')->alias('a')
|
$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([$subQuery => 'b'], 'a.id = b.from_id', 'left')
|
||||||
->join('vs_room_label c', 'a.label_id = c.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')
|
->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.room_status', 1)
|
||||||
->where('a.apply_status', 2) // 只统计审核通过的房间
|
->where('a.apply_status', 2)
|
||||||
->where('a.type_id', '<>', 6)
|
->where('a.type_id', '<>', 6)
|
||||||
->group('a.id')
|
->group('a.id')
|
||||||
->order('total_price', 'desc')
|
->order('total_price', 'desc')
|
||||||
|
|||||||
Reference in New Issue
Block a user