房间内流水详情

This commit is contained in:
2026-01-08 11:59:42 +08:00
parent 52893ee84f
commit c04bcb7072
4 changed files with 260 additions and 10 deletions

View File

@@ -482,15 +482,69 @@ class Room extends Model
* 按天统计指定房间流水
*/
public function room_turnover_detail($room_id,$stime,$etime,$page,$page_limit) {
$params['from_id'] = $room_id;
$params['start_time'] = $stime;
$params['end_time'] = $etime;
$params['page'] = $page;
$params['limit'] = $page_limit;
$res = model('GiveGiftBases')->getGiftRecords($params);
//如果没有传参数默认查询本月
$stime = empty($stime) ? date('Y-m-01') : $stime;
$etime = empty($etime) ? date('Y-m-d') : $etime;
var_dump($res);exit;
$total_amount = 0;//房间总流水
$list_data_array=[];
$room_user_ratio = get_system_config_value('room_author_ratio')/100;//房主收益比例
//判断开始时间是否小于2026年
if(strtotime($stime) < strtotime('2026-01-01')){
if(strtotime($etime) < strtotime('2026-01-01')){//结束时间是否小于2026年
$this->room_turnover($room_id,$stime,$etime,$page,$page_limit);
}else{
return ['code' => 0, 'msg' => '查询时间跨步暂不支持跨年!', 'data' => null];
}
}else{
$params['from_id'] = $room_id;
$params['start_time'] = $stime;
$params['end_time'] = $etime;
$params['page'] = $page;
$params['limit'] = $page_limit;
$res = model('GiveGiftBases')->getGiftRecords($params);
$list = $res['data'];
$list_data = [];
foreach ($list as &$value) {
$value['time'] = date('Y-m-d', strtotime($value['createtime']));
$value['sender_nickname'] = db::name('user')->where('id', $value['user_id'])->value('nickname');
$value['sender_avatar'] = db::name('user')->where('id', $value['user_id'])->value('avatar');
$value['receive_nickname'] = db::name('user')->where('id', $value['gift_user'])->value('nickname');
$value['receive_avatar'] = db::name('user')->where('id', $value['gift_user'])->value('avatar');
$value['gift_name'] = db::name('vs_gift')->where('gid', $value['gift_id'])->value('gift_name');
//收益计算
$value['earning'] = round($value['total_price'] * $room_user_ratio / get_system_config_value('rmb_coin_ratio'), 4);
//按日期统计
$list_data[$value['time']][] = $value;
}
$i=0;
foreach($list_data as $k => $v){
$list_data_array[$i]['total_price'] = 0;
$list_data_array[$i]['total_earning'] = 0;
$list_data_array[$i]['time'] = $k;
$list_data_array[$i]['list'] = $v;
//每日流水统计
$day_total_price = model('api/RoomDailyIncome')->getTodayIncome($room_id, $k);
$list_data_array[$i]['total_price'] = $day_total_price ;
//每日收益
$list_data_array[$i]['total_earning'] = round($day_total_price * $room_user_ratio / get_system_config_value('rmb_coin_ratio'), 4);
$i++;
}
//房间总流水2026年以后的
$total_amount = model('api/RoomDailyIncome')->getIncomeByPeriod($room_id, $stime, $etime);
}
//房主总收益
$coin_exchange_rate = get_system_config_value('coin_exchange_rate') ?? 1;
$total_earning = round($total_amount * $room_user_ratio / $coin_exchange_rate, 4);
return ['code' => 1, 'msg' => '成功', 'data' => ['total_amount' => $total_amount, 'total_earning' => $total_earning,'list' => $list_data_array]];
}
//房间流水2026年以前的
public function room_turnover($room_id,$stime,$etime,$page,$page_limit) {
$page = intval($page);
$page_limit = $page_limit < 20 ? $page_limit : 20;
$s_type =0;

View File

@@ -0,0 +1,98 @@
<?php
namespace app\api\model;
use think\Model;
class RoomDailyIncome extends Model
{
// 定义表名(如果表名和模型名一致可省略,这里显式定义更清晰)
protected $name = 'room_daily_income';
// 开启自动时间戳TP5.1默认用时间戳格式对应create_time/update_time
protected $autoWriteTimestamp = true;
// 定义字段类型转换(确保金额为浮点型)
protected $type = [
'income' => 'float',
'user_id' => 'integer',
];
/**
* 累加用户当日收益(核心方法)
* @param int $userId 用户ID
* @param float $amount 新增收益金额(正数)
* @return bool
*/
public function addDailyIncome($roomId, $amount)
{
$today = date('Y-m-d'); // 今日日期
$today_res = $this->where([
'room_id' => $roomId,
'date' => $today
])->find();
if($today_res){
$res = $this->where([
'room_id' => $roomId,
'date' => $today
])->update([
'income' => $amount,
'update_time'=> time(),
]);
if($res){return true;}
}else{
$res = $this->insert([
'room_id' => $roomId,
'income' => $amount,
'date' => $today,
'create_time'=> time(),
'update_time'=> time(),
]);
if($res){return true;}
}
return false;
}
/**
* 查询房间某一天收益
* @param int $roomId 房间ID
* @param string $today 日期格式YYYY-MM-DD
* @return float 收益无收益则返回0
*/
public function getTodayIncome($roomId,$today = 0)
{
if (!$today) {
$today = date('Y-m-d');
}
$result = $this->where([
'room_id' => $roomId,
'date' => $today
])->value('income');
return $result ? floatval($result) : 0.00;
}
/**
* 查询用户时间段内的收益总和
* @param int $userId 用户ID
* @param string $startDate 开始日期格式YYYY-MM-DD
* @param string $endDate 结束日期格式YYYY-MM-DD
* @return float 时间段总收益无收益则返回0
*/
public function getIncomeByPeriod($roomId, $startDate, $endDate)
{
// 校验日期格式(可选,增强健壮性)
if (!strtotime($startDate) || !strtotime($endDate)) {
return 0.00;
}
$total = $this->where([
'room_id' => $roomId,
'date' => ['between', [$startDate, $endDate]]
])->sum('income');
return $total ? floatval($total) : 0.00;
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace app\api\model;
use think\Model;
class UserDailyIncome extends Model
{
// 定义表名(如果表名和模型名一致可省略,这里显式定义更清晰)
protected $name = 'user_daily_income';
// 开启自动时间戳TP5.1默认用时间戳格式对应create_time/update_time
protected $autoWriteTimestamp = true;
// 定义字段类型转换(确保金额为浮点型)
protected $type = [
'income' => 'float',
'user_id' => 'integer',
];
/**
* 累加用户当日收益(核心方法)
* @param int $userId 用户ID
* @param float $amount 新增收益金额(正数)
* @return bool
*/
public function addDailyIncome($userId, $amount)
{
$today = date('Y-m-d'); // 今日日期
$today_res = $this->where([
'user_id' => $userId,
'date' => $today
])->find();
if($today_res){
$res = $this->where([
'user_id' => $userId,
'date' => $today
])->update([
'income' => $amount,
'update_time'=> time(),
]);
if($res){return true;}
}else{
$res = $this->insert([
'user_id' => $userId,
'income' => $amount,
'date' => $today,
'create_time'=> time(),
'update_time'=> time(),
]);
if($res){return true;}
}
return false;
}
/**
* 查询用户今日收益
* @param int $userId 用户ID
* @param string $today 日期格式YYYY-MM-DD
* @return float 今日收益无收益则返回0
*/
public function getTodayIncome($userId, $today = 0)
{
if (!$today) {
$today = date('Y-m-d');
}
$result = $this->where([
'user_id' => $userId,
'date' => $today
])->value('income');
return $result ? floatval($result) : 0.00;
}
/**
* 查询用户时间段内的收益总和
* @param int $userId 用户ID
* @param string $startDate 开始日期格式YYYY-MM-DD
* @param string $endDate 结束日期格式YYYY-MM-DD
* @return float 时间段总收益无收益则返回0
*/
public function getIncomeByPeriod($userId, $startDate, $endDate)
{
// 校验日期格式(可选,增强健壮性)
if (!strtotime($startDate) || !strtotime($endDate)) {
return 0.00;
}
$total = $this->where([
'user_id' => $userId,
'date' => ['between', [$startDate, $endDate]]
])->sum('income');
return $total ? floatval($total) : 0.00;
}
}

View File

@@ -23,17 +23,17 @@ class UserToken extends Model
$block1 = db::name('block')->where(['type' => 1,'type_text' => $user_token['user_id']])->find();
$userState = db::name('user')->where(['id' => $user_token['user_id']])->value('status');
if(isset($block1) || $userState == 2){
return ['code' => 204, 'msg'=> '账号已被封禁,请联系管理员','data' => null];
return ['code' => 301, 'msg'=> '账号已被封禁,请联系管理员','data' => null];
}
$login_device = request()->header('deviceId');
$block2 = db::name('block')->where(['type' => 2,'type_text' => $login_device])->find();
if(isset($block2)){
return ['code' => 205, 'msg'=> '设备已被封禁,请联系管理员','data' => null];
return ['code' => 301, 'msg'=> '设备已被封禁,请联系管理员','data' => null];
}
$Ip = request()->ip();
$block3 = db::name('block')->where(['type' => 3,'type_text' => $Ip])->find();
if(isset($block3)){
return ['code' => 206, 'msg'=> 'IP已被封禁请联系管理员','data' => null];
return ['code' => 301, 'msg'=> 'IP已被封禁请联系管理员','data' => null];
}
return ['code' => 1, 'msg'=> '成功','data' => $user_token['user_id']];