From c04bcb7072e5e8fa92cee5daf24f8e502c758a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Thu, 8 Jan 2026 11:59:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=BF=E9=97=B4=E5=86=85=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/model/Room.php | 68 ++++++++++++++-- application/api/model/RoomDailyIncome.php | 98 +++++++++++++++++++++++ application/api/model/UserDailyIncome.php | 98 +++++++++++++++++++++++ application/api/model/UserToken.php | 6 +- 4 files changed, 260 insertions(+), 10 deletions(-) create mode 100644 application/api/model/RoomDailyIncome.php create mode 100644 application/api/model/UserDailyIncome.php diff --git a/application/api/model/Room.php b/application/api/model/Room.php index ff1d8af5..38058382 100644 --- a/application/api/model/Room.php +++ b/application/api/model/Room.php @@ -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; diff --git a/application/api/model/RoomDailyIncome.php b/application/api/model/RoomDailyIncome.php new file mode 100644 index 00000000..e7a03d4c --- /dev/null +++ b/application/api/model/RoomDailyIncome.php @@ -0,0 +1,98 @@ + '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; + } + +} \ No newline at end of file diff --git a/application/api/model/UserDailyIncome.php b/application/api/model/UserDailyIncome.php new file mode 100644 index 00000000..3969cbaa --- /dev/null +++ b/application/api/model/UserDailyIncome.php @@ -0,0 +1,98 @@ + '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; + } + +} \ No newline at end of file diff --git a/application/api/model/UserToken.php b/application/api/model/UserToken.php index 34ba5393..628dce50 100644 --- a/application/api/model/UserToken.php +++ b/application/api/model/UserToken.php @@ -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']];