房间小时榜 和房间流水
This commit is contained in:
@@ -330,7 +330,7 @@ class Room extends Model
|
||||
//今日流水
|
||||
//金币与魅力比例
|
||||
$ratio = get_system_config_value('coin_charm_exp');
|
||||
$v['today_profit'] = $this->get_room_today_profit($v['room_id']) * $ratio;
|
||||
$v['today_profit'] = db::name('room_daily_income')->where('room_id', $v['room_id'])->value('income')?? 0 * $ratio;
|
||||
}
|
||||
//关注数
|
||||
$v['follow_num'] = db::name('user_follow')->where('follow_id', $v['room_id'])->where('type', 2)->count();
|
||||
@@ -411,10 +411,10 @@ class Room extends Model
|
||||
{
|
||||
$today_start_time = strtotime(date('Y-m-d'));
|
||||
$today_end_time = $today_start_time + 86400;
|
||||
return Db::name('vs_user_money_log')
|
||||
return Db::name('user_earnings_log')
|
||||
->where(['room_id' => $room_id,'user_id' => $user_id,'change_type' =>19])
|
||||
->whereBetween('createtime', [$today_start_time, $today_end_time])
|
||||
->sum('change_value');
|
||||
->sum('earnings');
|
||||
}
|
||||
|
||||
//房间补贴
|
||||
|
||||
@@ -123,32 +123,35 @@ class RoomHourRanking extends Model
|
||||
{
|
||||
// 1. 生成当前小时标识(固定为整点,保证每小时数据独立)
|
||||
$stat_hour = date('Y-m-d H:00:00');
|
||||
$now = date('Y-m-d H:i:s'); // 统一时间变量,避免重复生成
|
||||
|
||||
// 2. 获取数据库表前缀(自动适配FastAdmin配置,避免硬编码)
|
||||
$tablePrefix = Env::get('database.prefix', 'fa_');
|
||||
$tableName = $tablePrefix . 'room_gift_hourly_sum';
|
||||
|
||||
// 3. 构造原生SQL(关键:每个参数名唯一,避免重复)
|
||||
// 3. 构造SQL:所有参数替换为?(位置占位符),按顺序排列
|
||||
$sql = "INSERT INTO {$tableName}
|
||||
(room_id, stat_hour, gift_amount, gift_count, create_time, update_time)
|
||||
VALUES
|
||||
(:room_id, :stat_hour, :gift_amount_insert, :gift_count_insert, :create_time, :update_time_insert)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
gift_amount = gift_amount + :gift_amount_add,
|
||||
gift_count = gift_count + :gift_count_add,
|
||||
update_time = :update_time_update";
|
||||
(room_id, stat_hour, gift_amount, gift_count, create_time, update_time)
|
||||
VALUES
|
||||
(?, ?, ?, ?, ?, ?) -- 新增部分的6个?
|
||||
ON DUPLICATE KEY UPDATE
|
||||
gift_amount = gift_amount + ?,
|
||||
gift_count = gift_count + ?,
|
||||
update_time = ?";
|
||||
|
||||
// 4. 绑定参数(关键:参数名与SQL完全一致,无重复、无拼写错误)
|
||||
// 4. 构造参数数组:严格按SQL中?的顺序排列(核心!)
|
||||
$params = [
|
||||
':room_id' => $room_id,
|
||||
':stat_hour' => $stat_hour,
|
||||
':gift_amount_insert' => $amount, // 新增时的初始金额(唯一参数名)
|
||||
':gift_count_insert' => $count, // 新增时的初始次数(唯一参数名)
|
||||
':create_time' => date('Y-m-d H:i:s'),
|
||||
':update_time_insert' => date('Y-m-d H:i:s'), // 新增时的更新时间
|
||||
':gift_amount_add' => $amount, // 更新时累加的金额(唯一参数名)
|
||||
':gift_count_add' => $count, // 更新时累加的次数(唯一参数名)
|
||||
':update_time_update' => date('Y-m-d H:i:s') // 更新时的更新时间
|
||||
// 新增部分的6个参数(对应VALUES后的6个?)
|
||||
$room_id, // ?1: room_id
|
||||
$stat_hour, // ?2: stat_hour
|
||||
$amount, // ?3: 新增的gift_amount
|
||||
$count, // ?4: 新增的gift_count
|
||||
$now, // ?5: create_time
|
||||
$now, // ?6: 新增的update_time
|
||||
// 更新部分的3个参数(对应ON DUPLICATE KEY UPDATE后的3个?)
|
||||
$amount, // ?7: 累加的gift_amount
|
||||
$count, // ?8: 累加的gift_count
|
||||
$now // ?9: 更新的update_time
|
||||
];
|
||||
|
||||
try {
|
||||
@@ -171,4 +174,5 @@ class RoomHourRanking extends Model
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user