2025-08-07 20:21:47 +08:00
< ? php
namespace app\adminapi\controller ;
use app\admin\model\AdminLog ;
use app\common\controller\adminApi ;
use think\Config ;
use think\Db ;
use think\Hook ;
use think\Model ;
use think\Session ;
use think\Validate ;
/**
* 房间
* @ internal
*/
class Room extends adminApi
{
protected $noNeedLogin = [];
protected $noNeedRight = [ 'room_user_log' , 'room_flow' ];
protected $table = 'vs_room' ;
protected $table_room_label = 'vs_room_label' ;
protected $table_room_type = 'vs_room_type' ;
protected $relation = 'vs_relation' ;
protected $table_room_subsidy_config = 'vs_room_subsidy_config' ;
protected $table_room_subsidy = 'vs_room_subsidy' ;
protected $table_room_log = 'vs_room_operation_log' ;
public function _initialize ()
{
parent :: _initialize ();
}
/**
* 房间标签列表
*/
public function label_lists (){
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$search_name = input ( 'search_name' , '' );
$where = [];
//标签名称
if ( $search_name !== '' ){
$where [ 'label_name' ] = [ 'like' , '%' . $search_name . '%' ];
}
$count = db :: name ( $this -> table_room_label ) -> where ( $where ) -> count ();
$lists = db :: name ( $this -> table_room_label ) -> where ( $where ) -> page ( $page , $page_limit ) -> select ();
foreach ( $lists as $key => $value ) {
$lists [ $key ][ 'createtime' ] = date ( 'Y-m-d H:i:s' , $value [ 'createtime' ]);
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $lists
];
return V ( 1 , " 成功 " , $return_data );
}
/**
* 添加房间类标签
*/
public function add_label (){
$label_name = input ( 'label_name' , '' );
$label_icon = input ( 'label_icon' , '' );
$label_icon_room = input ( 'label_icon_room' , '' );
$status = input ( 'status' , 1 );
if ( $label_name == '' ){
return V ( 0 , " 请输入房间标签名称 " );
}
$data = [
'label_name' => $label_name ,
'label_icon' => $label_icon ,
'label_icon_room' => $label_icon_room ,
'status' => $status ,
'updatetime' => time (),
'createtime' => time ()
];
$label_id = db :: name ( $this -> table_room_label ) -> insertGetId ( $data );
if ( ! $label_id ){
return V ( 0 , " 失败 " , null );
}
return V ( 1 , " 成功 " , [ 'id' => $label_id ]);
}
/**
* 删除标签
*/
public function del_label (){
$label_id = input ( 'label_id' , '' );
if ( $label_id == '' ){
return V ( 0 , " 参数错误 " );
}
$label_data = db :: name ( $this -> table_room_label ) -> where ([ 'id' => $label_id ]) -> find ();
if ( ! $label_data ){
return V ( 0 , " 标签不存在 " );
}
$result = db :: name ( $this -> table_room_label ) -> where ([ 'id' => $label_id ]) -> delete ();
if ( ! $result ){
return V ( 0 , " 删除失败 " );
}
return V ( 1 , " 成功 " );
}
/*
* 标签详情
*/
public function label_info (){
$label_id = input ( 'label_id' , '' );
if ( $label_id == '' ){
return V ( 0 , " 标签ID不能为空 " );
}
$tag_data = db :: name ( $this -> table_room_label ) -> where ([ 'id' => $label_id ]) -> find ();
if ( ! $tag_data ){
return V ( 0 , " 标签不存在 " );
}
$tag_data [ 'createtime' ] = date ( 'Y-m-d H:i:s' , $tag_data [ 'createtime' ]);
$type_list = db :: name ( $this -> table_room_type ) -> where ([ 'status' => 1 ]) -> select ();
$tag_data [ 'type_list' ] = [];
foreach ( $type_list as $key => $value ) {
$tag_data [ 'type_list' ][ $key ][ 'id' ] = $value [ 'id' ];
$tag_data [ 'type_list' ][ $key ][ 'type_name' ] = $value [ 'type_name' ];
if ( $value [ 'id' ] == $tag_data [ 'type_id' ]){
$tag_data [ 'type_list' ][ $key ][ 'is_checked' ] = 1 ;
} else {
$tag_data [ 'type_list' ][ $key ][ 'is_checked' ] = 0 ;
}
}
return V ( 1 , " 成功 " , $tag_data );
}
/*
* 编辑标签
*/
public function edit_label (){
$label_id = input ( 'label_id' , '' );
$label_name = input ( 'label_name' , '' );
$label_icon = input ( 'label_icon' , '' );
$label_icon_room = input ( 'label_icon_room' , '' );
$status = input ( 'status' , 1 );
if ( $label_id == '' ){
return V ( 0 , " 标签ID不能为空 " );
}
$tag_data = db :: name ( $this -> table_room_label ) -> where ([ 'id' => $label_id ]) -> find ();
if ( ! $tag_data ){
return V ( 0 , " 标签不存在 " );
}
if ( $label_name == '' ){
return V ( 0 , " 标签名称不能为空 " );
}
$label = db :: name ( $this -> table_room_label ) -> where ([ 'label_name' => $label_name , 'id' => [ '<>' , $label_id ]]) -> find ();
if ( $label ){
return V ( 0 , " 标签已存在 " );
}
$data = [];
if ( $label_name ){
$data [ 'label_name' ] = $label_name ;
}
if ( $label_icon ){
$data [ 'label_icon' ] = $label_icon ;
}
if ( $label_icon_room ){
$data [ 'label_icon_room' ] = $label_icon_room ;
}
if ( $status ){
$data [ 'status' ] = $status ;
}
$data [ 'updatetime' ] = time ();
$result = db :: name ( $this -> table_room_label ) -> where ([ 'id' => $label_id ]) -> update ( $data );
if ( ! $result ){
return V ( 0 , " 添加失败 " );
}
return V ( 1 , " 成功 " , [ 'id' => $label_id ]);
}
/*
* 房间类型列表
*/
public function type_lists (){
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$search_name = input ( 'search_name' , '' );
$where = [];
//标签名称
if ( $search_name !== '' ){
$where [ 'label_name' ] = [ 'like' , '%' . $search_name . '%' ];
}
$count = db :: name ( $this -> table_room_type ) -> where ( $where ) -> count ();
$lists = db :: name ( $this -> table_room_type ) -> where ( $where ) -> page ( $page , $page_limit ) -> select ();
foreach ( $lists as $key => $value ) {
$lists [ $key ][ 'createtime' ] = date ( 'Y-m-d H:i:s' , $value [ 'createtime' ]);
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $lists
];
return V ( 1 , " 成功 " , $return_data );
}
/**
* 添加房间类型
*/
public function add_type (){
$type_name = input ( 'type_name' , '' );
$status = input ( 'status' , 1 );
if ( $type_name == '' ){
return V ( 0 , " 请输入房间类型名称 " );
}
$data = [
'type_name' => $type_name ,
'status' => $status ,
'createtime' => time ()
];
$type_id = db :: name ( $this -> table_room_type ) -> insertGetId ( $data );
if ( ! $type_id ){
return V ( 0 , " 失败 " , null );
}
return V ( 1 , " 成功 " , [ 'id' => $type_id ]);
}
/**
* 删除房间类型
*/
public function del_type (){
$type_id = input ( 'type_id' , '' );
if ( $type_id == '' ){
return V ( 0 , " 参数错误 " );
}
$type_data = db :: name ( $this -> table_room_type ) -> where ([ 'id' => $type_id ]) -> find ();
if ( ! $type_data ){
return V ( 0 , " 房间类型不存在 " );
}
$result = db :: name ( $this -> table_room_type ) -> where ([ 'id' => $type_id ]) -> delete ();
if ( ! $result ){
return V ( 0 , " 删除失败 " );
}
return V ( 1 , " 成功 " );
}
/**
* 房间类型详情
*/
public function type_info (){
$type_id = input ( 'type_id' , '' );
if ( $type_id == '' ){
return V ( 0 , " 房间类型ID不能为空 " );
}
$type_data = db :: name ( $this -> table_room_type ) -> where ([ 'id' => $type_id ]) -> find ();
if ( ! $type_data ){
return V ( 0 , " 房间类型不存在 " );
}
$type_data [ 'createtime' ] = date ( 'Y-m-d H:i:s' , $type_data [ 'createtime' ]);
return V ( 1 , " 成功 " , $type_data );
}
/**
* 编辑房间类型
*/
public function edit_type (){
$type_id = input ( 'type_id' , '' );
$type_name = input ( 'type_name' , '' );
$status = input ( 'status' , 1 );
if ( $type_id == '' ){
return V ( 0 , " 房间类型ID不能为空 " );
}
$type_data = db :: name ( $this -> table_room_type ) -> where ([ 'id' => $type_id ]) -> find ();
if ( ! $type_data ){
return V ( 0 , " 房间类型不存在 " );
}
if ( $type_name == '' ){
return V ( 0 , " 请输入房间类型名称 " );
}
$data = [];
if ( $type_name ){
$data [ 'type_name' ] = $type_name ;
}
if ( $status ){
$data [ 'status' ] = $status ;
}
$result = db :: name ( $this -> table_room_type ) -> where ([ 'id' => $type_id ]) -> update ( $data );
if ( ! $result ){
return V ( 0 , " 添加失败 " );
}
return V ( 1 , " 成功 " , [ 'id' => $type_id ]);
}
/*
* 关系列表
*/
public function relation_lists (){
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$search_name = input ( 'search_name' , '' );
$where = [];
//标签名称
if ( $search_name !== '' ){
$where [ 'name' ] = [ 'like' , '%' . $search_name . '%' ];
}
$where [ 'delete_time' ] = 0 ;
$count = db :: name ( $this -> relation ) -> where ( $where ) -> count ();
$lists = db :: name ( $this -> relation ) -> where ( $where ) -> page ( $page , $page_limit ) -> select ();
foreach ( $lists as $key => $value ) {
$lists [ $key ][ 'type_str' ] = model ( 'Room' ) -> relation_type [ $value [ 'type' ]];
$lists [ $key ][ 'is_open_movie' ] = $value [ 'is_open_movie' ] == 1 ? '是' : '否' ;
$lists [ $key ][ 'createtime' ] = date ( 'Y-m-d H:i:s' , $value [ 'createtime' ]);
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $lists
];
return V ( 1 , " 成功 " , $return_data );
}
/**
* 添加关系
*/
public function add_relation (){
$name = input ( 'name' , '' );
$type = input ( 'type' , '' );
$is_open_movie = input ( 'is_open_movie' , 1 );
$icon = input ( 'icon' , '' );
if ( $name == '' ){
return V ( 0 , " 请输入关系名称 " );
}
if ( $type == '' ){
return V ( 0 , " 请选择关系类型 " );
}
$data = [
'name' => $name ,
'type' => $type ,
'is_open_movie' => $is_open_movie ,
'icon' => $icon ,
'createtime' => time ()
];
$relation_id = db :: name ( $this -> relation ) -> insertGetId ( $data );
if ( ! $relation_id ){
return V ( 0 , " 失败 " , null );
}
return V ( 1 , " 成功 " , [ 'id' => $relation_id ]);
}
/**
* 删除关系
*/
public function del_relation (){
$relation_id = input ( 'relation_id' , '' );
if ( $relation_id == '' ){
return V ( 0 , " 参数错误 " );
}
$relation_data = db :: name ( $this -> relation ) -> where ([ 'id' => $relation_id ]) -> find ();
if ( ! $relation_data ){
return V ( 0 , " 关系不存在 " );
}
$result = db :: name ( $this -> relation ) -> where ([ 'id' => $relation_id ]) -> update ([ 'delete_time' => time ()]);
if ( ! $result ){
return V ( 0 , " 删除失败 " );
}
return V ( 1 , " 成功 " );
}
/*
* 关系详情
*/
public function relation_info (){
$relation_id = input ( 'relation_id' , '' );
if ( $relation_id == '' ){
return V ( 0 , " 参数错误 " );
}
$relation_data = db :: name ( $this -> relation ) -> where ([ 'id' => $relation_id ]) -> find ();
if ( ! $relation_data ){
return V ( 0 , " 关系不存在 " );
}
$relation_data [ 'createtime' ] = date ( 'Y-m-d H:i:s' , $relation_data [ 'createtime' ]);
$relation_data [ 'type_list' ] = model ( 'Room' ) -> relation_type ;
return V ( 1 , " 成功 " , $relation_data );
}
/**
* 编辑关系
*/
public function edit_relation (){
$relation_id = input ( 'relation_id' , '' );
$name = input ( 'name' , '' );
$type = input ( 'type' , '' );
$is_open_movie = input ( 'is_open_movie' , 1 );
$icon = input ( 'icon' , '' );
if ( $relation_id == '' ){
return V ( 0 , " 参数错误 " );
}
$relation_data = db :: name ( $this -> relation ) -> where ([ 'id' => $relation_id ]) -> find ();
if ( ! $relation_data ){
return V ( 0 , " 关系不存在 " );
}
$data = [];
if ( $name ){
$data [ 'name' ] = $name ;
}
if ( $type ){
$data [ 'type' ] = $type ;
}
if ( $is_open_movie ){
$data [ 'is_open_movie' ] = $is_open_movie ;
}
if ( $icon ){
$data [ 'icon' ] = $icon ;
}
$result = db :: name ( $this -> relation ) -> where ([ 'id' => $relation_id ]) -> update ( $data );
if ( ! $result ){
return V ( 0 , " 失败 " );
}
return V ( 1 , " 成功 " , [ 'id' => $relation_id ]);
}
/*
* 房间列表
*/
public function room_lists (){
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$search_room_id = input ( 'search_room_id' , '' );
$search_user_id = input ( 'search_user_id' , '' );
$search_status = input ( 'search_status' , '' );
$where = [];
//房间号
if ( $search_room_id !== '' ){
$where [ 'room_number' ] = $search_room_id ;
}
if ( $search_user_id !== '' ){
$user_id = db :: name ( 'user' ) -> where ( 'user_code' , $search_user_id ) -> value ( 'id' );
$where [ 'user_id' ] = $user_id ;
}
if ( $search_status !== '' ){
$where [ 'room_status' ] = $search_status ;
}
//房间列表只展示 审核通过的房间
$where [ 'apply_status' ] = 2 ; //1待审核 2审核通过 3审核失败
$where [ 'type_id' ] = [ '<>' , 6 ];
$count = db :: name ( $this -> table ) -> where ( $where ) -> count ();
$room_lists = db :: name ( $this -> table ) -> where ( $where ) -> page ( $page , $page_limit ) -> select ();
$lists = [];
foreach ( $room_lists as $key => $value ) {
$lists [ $key ][ 'room_id' ] = $value [ 'id' ];
$lists [ $key ][ 'room_code' ] = model ( 'api/Decorate' ) -> user_decorate_detail ( $value [ 'id' ], 7 );
//靓号处理
//查询用是否有靓号
$special_num = db :: name ( 'vs_user_decorate' ) -> where ([ 'user_id' => $value [ 'id' ], 'type' => 7 , 'is_using' => 1 ]) -> where ( 'end_time' ,[ '>=' , time ()], 'or' ) -> value ( 'special_num' );
if ( $special_num ){
$lists [ $key ][ 'room_number' ] = $special_num ;
} else {
$lists [ $key ][ 'room_number' ] = " 无 " ;
}
$lists [ $key ][ 'user_name' ] = model ( 'User' ) -> where ([ 'id' => $value [ 'user_id' ]]) -> value ( 'nickname' );
$lists [ $key ][ 'room_name' ] = $value [ 'room_name' ];
$lists [ $key ][ 'room_cover' ] = $value [ 'room_cover' ];
$lists [ $key ][ 'room_type_str' ] = db :: name ( $this -> table_room_type ) -> where ([ 'id' => $value [ 'type_id' ]]) -> value ( 'type_name' );
$lists [ $key ][ 'room_label_str' ] = db :: name ( $this -> table_room_label ) -> where ([ 'id' => $value [ 'label_id' ]]) -> value ( 'label_name' );
$lists [ $key ][ 'is_recommend' ] = $value [ 'is_recommend' ] != 1 ? '是' : '否' ;
$lists [ $key ][ 'is_top' ] = $value [ 'is_top' ] != 1 ? '是' : '否' ;
$lists [ $key ][ 'is_hot' ] = $value [ 'is_hot' ] != 1 ? '是' : '否' ;
$lists [ $key ][ 'is_earnings' ] = $value [ 'is_earnings' ] = 1 ? '是' : '否' ;
//所属工会
$guild = model ( 'Guild' ) -> getGuildByUserId ( $value [ 'user_id' ]);
$lists [ $key ][ 'guild_name' ] = ! empty ( $guild ) ? $guild [ 'guild_name' ] : " " ;
$lists [ $key ][ 'room_status_str' ] = model ( 'Room' ) -> room_status [ $value [ 'room_status' ]];
$lists [ $key ][ 'createtime' ] = date ( 'Y-m-d H:i:s' , $value [ 'createtime' ]);
2025-08-11 11:38:52 +08:00
$lists [ $key ][ 'is_robot_num' ] = $value [ 'robot_num' ] == 0 ? 1 : 2 ;
2025-08-07 20:21:47 +08:00
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $lists
];
return V ( 1 , " 成功 " , $return_data );
}
/*
* 删除房间
*
*/
public function del_room (){
$room_id = input ( 'room_id' , '' );
if ( $room_id == '' ){
return V ( 0 , " 参数错误 " );
} else {
return V ( 0 , " 房间不许删除 " );
}
$room_data = db :: name ( $this -> table ) -> where ([ 'id' => $room_id ]) -> find ();
if ( ! $room_data ){
return V ( 0 , " 房间不存在 " );
}
$result = db :: name ( $this -> table ) -> where ([ 'id' => $room_id ]) -> update ([ 'delete_time' => time ()]);
if ( ! $result ){
return V ( 0 , " 删除失败 " );
}
return V ( 1 , " 成功 " );
}
//房间详情
public function room_info (){
$room_id = input ( 'room_id' , '' );
if ( $room_id == '' ){
return V ( 0 , " 参数错误 " );
}
$room_data = db :: name ( $this -> table ) -> where ([ 'id' => $room_id ]) -> find ();
if ( ! $room_data ){
return V ( 0 , " 房间不存在 " );
}
$room_data [ 'createtime' ] = date ( 'Y-m-d H:i:s' , $room_data [ 'createtime' ]);
$room_data [ 'updatetime' ] = date ( 'Y-m-d H:i:s' , $room_data [ 'updatetime' ]);
$room_data [ 'room_type_str' ] = db :: name ( 'vs_room_type' ) -> where ([ 'id' => $room_data [ 'type_id' ]]) -> value ( 'type_name' );
$room_data [ 'liang' ] = model ( 'api/Decorate' ) -> user_decorate_detail ( $room_data [ 'id' ], 7 );
$room_data [ 'owner' ] = db :: name ( 'user' ) -> where ([ 'id' => $room_data [ 'user_id' ]]) -> value ( 'nickname' );
2025-08-11 11:38:52 +08:00
$room_data [ 'is_robot_num' ] = $room_data [ 'robot_num' ] == 0 ? 2 : 1 ;
2025-08-07 20:21:47 +08:00
$room_data [ 'guild_name' ] = '' ;
$guild_id = db :: name ( 'vs_guild_user' ) -> where ( 'user_id' , $room_data [ 'user_id' ]) -> value ( 'guild_id' );
if ( $guild_id ){
$room_data [ 'guild_name' ] = db :: name ( 'vs_guild' ) -> where ( 'id' , $guild_id ) -> value ( 'guild_name' );
}
$room_data [ 'jiqirennum' ] = 0 ;
$roomUser = db :: name ( 'vs_room_visitor' ) -> where ( 'room_id' , $room_data [ 'id' ]) -> select ();
if ( $roomUser ){
foreach ( $roomUser as $key => $value ){
if ( db :: name ( 'user' ) -> where ( 'id' , $value [ 'user_id' ]) -> value ( 'is_robot' )){
$room_data [ 'jiqirennum' ] += 1 ;
}
}
}
//前天的收益
$room_data [ 'two_day_ago_earnings' ] = $this -> get_room_today_profit ( $room_id , 4 );
//昨天的收益
$room_data [ 'yesterday_earnings' ] = $this -> get_room_today_profit ( $room_id , 3 );
//今日的收益
$room_data [ 'today_earnings' ] = $this -> get_room_today_profit ( $room_id , 2 );
// 计算今日收益比昨日收益的增长百分比
if ( $room_data [ 'yesterday_earnings' ] > 0 ) {
$growthPercentage = (( $room_data [ 'today_earnings' ] - $room_data [ 'yesterday_earnings' ]) / $room_data [ 'yesterday_earnings' ]) * 100 ;
} else {
// 如果昨日收益为0, 避免除以零错误
$growthPercentage = $room_data [ 'today_earnings' ] > 0 ? 100 : 0 ; // 如果今天有收益而昨天没有, 则视为增长100%
}
//比昨日收益增长百分之多少
$room_data [ 'growth_percentage' ] = round ( $growthPercentage , 2 ); // 保留两位小数
//计算昨日比前天的收益增长百分比
if ( $room_data [ 'two_day_ago_earnings' ] > 0 ) {
$yesterdayGrowthPercentage = (( $room_data [ 'yesterday_earnings' ] - $room_data [ 'two_day_ago_earnings' ]) / $room_data [ 'two_day_ago_earnings' ]) * 100 ;
} else {
// 如果前天收益为0, 避免除以零错误
$yesterdayGrowthPercentage = $room_data [ 'yesterday_earnings' ] > 0 ? 100 : 0 ; // 如果昨天有收益而前天没有, 则视为增长100%
}
//昨日比前天的收益增长百分之多少
$room_data [ 'yesterday_growth_percentage' ] = round ( $yesterdayGrowthPercentage , 2 ); // 保留两位小数
//今日访客
$room_data [ 'visitor' ] = $this -> get_room_visitor ( $room_id , 1 );
//昨日访客
$room_data [ 'yesterday_visitor' ] = $this -> get_room_visitor ( $room_id , 2 );
//今日比昨日访客增长百分比
if ( $room_data [ 'yesterday_visitor' ] > 0 ) {
$yesterdayVisitor = (( $room_data [ 'visitor' ] - $room_data [ 'yesterday_visitor' ]) / $room_data [ 'yesterday_visitor' ]) * 100 ;
} else {
// 如果前天收益为0, 避免除以零错误
$yesterdayVisitor = $room_data [ 'visitor' ] > 0 ? 100 : 0 ; // 如果今天有而昨天没有, 则视为增长100%
}
$room_data [ 'growth_visitor' ] = round ( $yesterdayVisitor , 2 ); // 保留两位小数
//补贴
$roomSubsidy = model ( 'api/Room' ) -> room_ubsidy ( $room_id );
//上周补贴
$room_data [ 'last_week_subsidy' ] = $roomSubsidy [ 'lastweek' ][ 'subsidy_amount' ];
//本周补贴
$room_data [ 'this_week_subsidy' ] = $roomSubsidy [ 'thisweek' ][ 'subsidy_amount' ];
//本周补贴比上周增长百分比
if ( $room_data [ 'last_week_subsidy' ] > 0 ) {
$weekSubsidy = (( $room_data [ 'this_week_subsidy' ] - $room_data [ 'last_week_subsidy' ]) / $room_data [ 'last_week_subsidy' ]) * 100 ;
} else {
// 如果上周收益为0, 避免除以零错误
$weekSubsidy = $room_data [ 'this_week_subsidy' ] > 0 ? 100 : 0 ; // 如果本周有收益而上周没有, 则100%
}
$room_data [ 'growth_week_subsidy' ] = round ( $weekSubsidy , 2 );
return V ( 1 , " 成功 " , $room_data );
}
//房间收益
//type 1:总收益 2:今日收益 3:昨日收益 4:前天的收益
public function get_room_today_profit ( $room_id , $type )
{
if ( $type == 2 ){
$start_time = strtotime ( date ( 'Y-m-d' ));
$end_time = $start_time + 86400 ;
} elseif ( $type == 3 ){
$start_time = strtotime ( date ( 'Y-m-d' , strtotime ( '-1 day' )));
$end_time = $start_time + 86400 ;
} elseif ( $type == 4 ){
$start_time = strtotime ( date ( 'Y-m-d' , strtotime ( '-2 day' )));
$end_time = $start_time + 86400 ;
} elseif ( $type == 1 ){
$start_time = 1748676768 ; //2025-06-00 15:32:48
$end_time = time ();
}
$profit = db :: name ( 'vs_give_gift' ) -> where ( 'from_id' , $room_id ) -> where ( 'from' , 2 ) -> where ( 'createtime' , 'between' , [ $start_time , $end_time ]) -> sum ( 'total_price' );
return $profit ;
}
//房间访客
//type 1:今日 2:昨日 3: 所有
public function get_room_visitor ( $room_id , $type )
{
if ( $type == 1 ){
$start_time = strtotime ( date ( 'Y-m-d' ));
$end_time = $start_time + 86400 ;
} elseif ( $type == 2 ){
$start_time = strtotime ( date ( 'Y-m-d' , strtotime ( '-1 day' )));
$end_time = $start_time + 86400 ;
} elseif ( $type == 3 ){
$start_time = 1748676768 ; //2025-06-00 15:32:48
$end_time = time ();
}
$profit = db :: name ( 'user_visit_log' ) -> where ([ 'to_id' => $room_id , 'type' => 2 ]) -> where ( 'createtime' , 'between' , [ $start_time , $end_time ]) -> count ();
return $profit ;
}
//房间流水
public function room_flow ()
{
$room_id = input ( 'room_id' , '' );
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 10 );
$type = input ( 'type' , 1 ); //1:全部流水 2:日流水 3:周流水 4:月流水
if ( $room_id == '' ){
return V ( 0 , " 参数错误 " );
}
if ( $type == 1 ){
$begin_time = 1748676768 ; //2025-06-00 15:32:48
$end_time = time ();
$where [ 'a.createtime' ] = [ 'between' , [ $begin_time , $end_time ]];
} elseif ( $type == 2 ){
//日流水
$begin_time = strtotime ( date ( 'Y-m-d 00:00:00' , time ()));
$end_time = time ();
$where [ 'a.createtime' ] = [ 'between' , [ $begin_time , $end_time ]];
}
elseif ( $type == 3 ){
//周流水
//周一
$begin_time = strtotime ( date ( 'Y-m-d 24:00:00' , strtotime ( '-' . date ( 'w' ) . 'days' )));
$end_time = time ();
$where [ 'a.createtime' ] = [ 'between' , [ $begin_time , $end_time ]];
}
elseif ( $type == 4 ){
$begin_time = strtotime ( date ( 'Y-m-01' ));
$end_time = time ();
$where [ 'a.createtime' ] = [ 'between' , [ $begin_time , $end_time ]];
}
$count = db :: name ( 'vs_give_gift' ) -> alias ( 'a' )
-> field ( 'a.id' )
-> join ( 'user b' , 'a.user_id = b.id' , 'left' )
-> join ( 'user c' , 'a.gift_user = c.id' , 'left' )
-> join ( 'vs_gift d' , 'a.gift_id = d.gid' , 'left' )
-> where ( 'a.from' , 2 )
-> where ( 'a.from_id' , $room_id )
-> where ( $where )
-> count ();
$list = db :: name ( 'vs_give_gift' ) -> alias ( 'a' )
-> field ( 'a.number,a.createtime,a.total_price,a.type,b.nickname,b.avatar,c.nickname as gift_nickname,c.avatar as gift_avatar,d.gift_name,a.from,a.from_id' )
-> join ( 'user b' , 'a.user_id = b.id' , 'left' )
-> join ( 'user c' , 'a.gift_user = c.id' , 'left' )
-> join ( 'vs_gift d' , 'a.gift_id = d.gid' , 'left' )
-> where ( 'a.from' , 2 )
-> where ( 'a.from_id' , $room_id )
-> where ( $where )
-> order ( 'a.id desc' )
-> page ( $page , $page_limit )
-> select ();
if ( $list ){
foreach ( $list as & $v ){
$v [ 'createtime' ] = date ( 'Y-m-d H:i:s' , $v [ 'createtime' ]);
$v [ 'content' ] = $v [ 'nickname' ] . ' 给 ' . $v [ 'gift_nickname' ] . ' 送了 ' . $v [ 'gift_name' ] . ' x ' . $v [ 'number' ];
// 来源: 1聊天送礼物 2房间语聊送礼 3直播送礼 4动态打赏
$v [ 'from_str' ] = model ( 'Gift' ) -> GiveGiftFromStr [ $v [ 'from' ]];
}
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $list ,
'total' => [
'total_price' => db :: name ( 'vs_give_gift' ) -> alias ( 'a' )
-> join ( 'user b' , 'a.user_id = b.id' , 'left' )
-> where ( 'a.from' , 2 )
-> where ( 'a.from_id' , $room_id )
-> where ( $where ) -> sum ( 'total_price' )
]
];
return V ( 1 , " 成功 " , $return_data );
}
//房间用户进入记录
public function room_user_log ()
{
$room_id = input ( 'room_id' , '' );
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 10 );
if ( $room_id == '' ){
return V ( 0 , " 参数错误 " );
}
$count = db :: name ( 'user_visit_log' ) -> alias ( 'a' )
-> field ( 'a.id,a.createtime,b.nickname,b.user_code' )
-> join ( 'user b' , 'a.from_uid = b.id' , 'left' )
-> where ( 'a.to_id' , $room_id )
-> where ( 'a.type' , 2 )
-> count ();
$list = db :: name ( 'user_visit_log' ) -> alias ( 'a' )
-> field ( 'a.id,a.createtime,b.nickname,b.user_code' )
-> join ( 'user b' , 'a.from_uid = b.id' , 'left' )
-> where ( 'a.to_id' , $room_id )
-> where ( 'a.type' , 2 )
-> order ( 'a.id desc' )
-> page ( $page , $page_limit )
-> select ();
if ( $list ){
foreach ( $list as & $v ){
$v [ 'createtime' ] = date ( 'Y-m-d H:i:s' , $v [ 'createtime' ]);
}
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $list
];
return V ( 1 , " 成功 " , $return_data );
}
//编辑房间
public function edit_room ()
{
$room_id = input ( 'room_id' , '' ); //固定值不可变
$admin_id = Session :: get ( 'admin_id' );
$room_number = input ( 'room_number' , '' ); //房间编号
if ( $room_number ){
$data [ 'room_number' ] = $room_number ;
}
$room_name = input ( 'room_name' , '' ); //房间名称
if ( $room_name ){
$data [ 'room_name' ] = $room_name ;
}
$room_intro = input ( 'room_intro' , '' ); //房间简介(公告)
if ( $room_intro ){
$data [ 'room_intro' ] = $room_intro ;
}
$room_cover = input ( 'room_cover' , '' ); //房间封面
if ( $room_cover ){
$data [ 'room_cover' ] = $room_cover ;
}
$room_background_id = input ( 'room_background' , '' ); //房间背景url
if ( $room_background_id ){
$data [ 'room_background' ] = $room_background_id ;
}
$type_id = input ( 'type_id' , '' ); //房间类型id
if ( $type_id ){
$data [ 'type_id' ] = $type_id ;
}
$is_earnings = input ( 'is_earnings' , '' ); //是否获取收益 1是 2否
if ( $is_earnings ){
$data [ 'is_earnings' ] = $is_earnings ;
}
$is_top = input ( 'is_top' , '' ); //是否置顶 1非置顶 2置顶
if ( $is_top ){
$data [ 'is_top' ] = $is_top ;
}
$is_hot = input ( 'is_hot' , '' ); //是否热门 1非热门 2热门
if ( $is_hot ){
$data [ 'is_hot' ] = $is_hot ;
}
$is_recommend = input ( 'is_recommend' , '' ); //是否推荐 1非推荐 2推荐
if ( $is_recommend ){
$data [ 'is_recommend' ] = $is_recommend ;
}
$room_status = input ( 'room_status' , '' ); //房间状态 1正常 2封禁 3关闭
if ( $room_status ){
$data [ 'room_status' ] = $room_status ;
}
$is_show_room = input ( 'is_show_room' , '' ); //是否显示房间 1是 2否
if ( $is_show_room ){
$data [ 'is_show_room' ] = $is_show_room ;
}
$room_password = input ( 'room_password' , '' ); //房间密码
$is_room_password = input ( 'is_room_password' , '' ); //是否密码房 1是 2否
if ( $is_room_password == 1 ){
if ( $room_password == '' ){
return V ( 0 , " 请填写房间密码 " );
}
$data [ 'room_password' ] = $room_password ;
} elseif ( $is_room_password == 2 ){
$data [ 'room_password' ] = '' ;
}
$robot_num = input ( 'robot_num' , '' ); //机器人数量
$is_robot_num = input ( 'is_robot_num' , '' ); //是否投送机器人 1是 2否
if ( $is_robot_num == 1 ){
if ( $robot_num == '' ){
return V ( 0 , " 请填写机器人数量 " );
}
$data [ 'robot_num' ] = $robot_num ;
//在用户表里找 $robot_num 个机器人 进入到房间
$user_list = db :: name ( 'user' ) -> field ( 'id' ) -> where ( 'is_robot' , 1 ) -> limit ( $robot_num ) -> orderRaw ( 'rand()' ) -> select ();
if ( $user_list ){
2025-08-11 14:26:45 +08:00
if ( count ( $user_list ) != $robot_num ){
return V ( 0 , " 机器人数量不足 " );
}
2025-08-07 20:21:47 +08:00
foreach ( $user_list as $v ){
model ( 'api/Room' ) -> join_room ( $v [ 'id' ], $room_id , $room_password );
}
2025-08-11 14:26:45 +08:00
} else {
return V ( 0 , " 没有可用机器人 " );
2025-08-07 20:21:47 +08:00
}
2025-08-11 14:26:45 +08:00
} elseif ( $is_robot_num == 2 || $robot_num == 0 ){
2025-08-07 20:21:47 +08:00
$data [ 'robot_num' ] = 0 ;
//查询在房间中的机器人 并退出
$user_list = db :: name ( 'vs_room_visitor' ) -> alias ( 'a' ) -> join ( 'user b' , 'a.user_id = b.id' , 'left' )
-> field ( 'a.id,a.user_id' )
-> where ( 'a.room_id' , $room_id )
-> where ( 'b.is_robot' , 1 )
-> select ();
if ( $user_list ){
foreach ( $user_list as $v ){
model ( 'api/Room' ) -> quit_room ( 1 , $room_id , $v [ 'user_id' ], 0 );
}
}
}
$res = db :: name ( 'vs_room' ) -> where ( 'id' , $room_id ) -> update ( $data );
if ( $res ){
return V ( 1 , " 成功 " );
}
else {
return V ( 0 , " 失败 " );
}
}
//房间背景列表
public function room_background_list ()
{
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$search_name = input ( 'search_name' , '' );
$status = input ( 'status' , '' );
// $where['status'] = 1;
$where [ 'delete_time' ] = null ;
//标签名称
if ( $search_name !== '' ){
$where [ 'image_name' ] = [ 'like' , '%' . $search_name . '%' ];
}
if ( $status !== '' ){
$where [ 'status' ] = $status ;
}
$count = db :: name ( 'vs_room_background' ) -> where ( $where ) -> count ();
$lists = db :: name ( 'vs_room_background' ) -> where ( $where ) -> order ( 'id desc' ) -> page ( $page , $page_limit ) -> select ();
foreach ( $lists as & $value ) {
$value [ 'createtime' ] = date ( 'Y-m-d H:i:s' , $value [ 'createtime' ]);
if ( $value [ 'upload_user' ] > 0 ){
$value [ 'upload_user' ] = db :: name ( 'user' ) -> where ( 'id' , $value [ 'upload_user' ]) -> value ( 'nickname' );
} else {
$value [ 'upload_user' ] = '系统' ;
}
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $lists
];
return V ( 1 , " 成功 " , $return_data );
}
//房间背景添加/修改
public function room_background_add ()
{
//管理员ID
$admin_id = Session :: get ( 'admin_id' );
if ( ! $admin_id ){
return V ( 0 , " 管理员ID不能为空 " );
}
$id = input ( 'id' , '' );
if ( $id ){
$data = [
// 'upload_user' => $admin_id,
'updatetime' => time (),
];
$image_name = input ( 'image_name' , '' );
if ( $image_name ){
$data [ 'image_name' ] = $image_name ;
}
$image_url = input ( 'image_url' , '' );
if ( $image_url ){
$data [ 'image_url' ] = $image_url ;
}
$status = input ( 'status' , '' );
if ( $status ){
$data [ 'status' ] = $status ;
}
$res = db :: name ( 'vs_room_background' ) -> where ( 'id' , $id ) -> update ( $data );
if ( $res ){
return V ( 1 , " 成功 " );
}
else {
return V ( 0 , " 失败 " );
}
} else {
$data = [
'image_name' => input ( 'image_name' , '' ),
'image_url' => input ( 'image_url' , '' ),
'status' => input ( 'status' , 1 ),
// 'upload_user' => $admin_id,
'createtime' => time (),
'updatetime' => time (),
];
$res = db :: name ( 'vs_room_background' ) -> insert ( $data );
if ( $res ){
return V ( 1 , " 成功 " );
}
else {
return V ( 0 , " 失败 " );
}
}
}
//房间背景删除
public function room_background_del ()
{
$id = input ( 'id' , '' );
if ( ! $id ){
return V ( 0 , " ID不能为空 " );
}
$res = db :: name ( 'vs_room_background' ) -> where ( 'id' , $id ) -> update ([ 'status' => 2 , 'delete_time' => time ()]);
if ( $res ){
return V ( 1 , " 成功 " );
}
else {
return V ( 0 , " 失败 " );
}
}
//Cp电影房
public function cp_movie_room ()
{
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$search_room_number = input ( 'search_room_number' , '' );
$search_onwer_number = input ( 'search_onwer_number' , '' );
$room_status = input ( 'room_status' , '' );
if ( $search_room_number !== '' ){
$where [ 'room_number' ] = $search_room_number ;
}
if ( $search_onwer_number !== '' ){
$where [ 'user_id' ] = $search_onwer_number ;
}
if ( $room_status !== '' ){
$where [ 'room_status' ] = $room_status ;
}
$where [ 'type_id' ] = 6 ;
$count = db :: name ( 'vs_room' ) -> where ( $where ) -> count ();
$lists = db :: name ( 'vs_room' ) -> field ( 'id,room_name,room_cover,room_number,user_id,room_status,createtime' )
-> where ( $where )
-> order ( 'id desc' )
-> page ( $page , $page_limit ) -> select ();
foreach ( $lists as & $value ) {
$guild = model ( 'Guild' ) -> getGuildByUserId ( $value [ 'user_id' ]);
$value [ 'createtime' ] = date ( 'Y-m-d H:i:s' , $value [ 'createtime' ]);
$value [ 'is_on_line' ] = db :: name ( 'vs_room_visitor' ) -> where ( 'room_id' , $value [ 'id' ]) -> value ( 'user_id' ) ? 1 : 0 ;
$value [ 'is_on_line_str' ] = $value [ 'is_on_line' ] ? " 在线 " : " 离线 " ;
$value [ 'user_guild' ] = $guild [ 'guild_name' ] ? ? '' ;
$value [ 'user_nickname' ] = db :: name ( 'user' ) -> where ( 'id' , $value [ 'user_id' ]) -> value ( 'nickname' );
$value [ 'room_code' ] = model ( 'api/Decorate' ) -> user_decorate_detail ( $value [ 'id' ], 7 );
//房间状态1正常2封禁3关闭
$value [ 'room_status_str' ] = $value [ 'room_status' ] == 1 ? " 正常 " : ( $value [ 'room_status' ] == 2 ? " 封禁 " : " 关闭 " );
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $lists
];
return V ( 1 , " 成功 " , $return_data );
}
//Cp电影房封禁
public function cp_movie_room_forbid ()
{
$room_id = input ( 'room_id' , '' );
if ( ! $room_id ){
return V ( 0 , " 房间ID不能为空 " );
}
$data = [
'room_status' => 2 ,
'updatetime' => time (),
];
$res = db :: name ( 'vs_room' ) -> where ( 'id' , $room_id ) -> update ( $data );
if ( $res ){
$res1 = db :: name ( 'vs_room_cp_movie' ) -> where ( 'room_id' , $room_id ) -> update ([ 'status' => 3 ]);
if ( ! $res1 ){
return V ( 0 , " 失败 " );
}
//给前端推消息
return V ( 1 , " 成功 " );
}
else {
return V ( 0 , " 失败 " );
}
}
/*
* 房间补贴配置添加
*/
public function room_subsidy_config_add (){
$start_amount = input ( 'start_amount' , 0 );
$end_amount = input ( 'end_amount' , 0 );
$subsidy_ratio = input ( 'subsidy_ratio' , 0 );
if ( $start_amount && $end_amount && $subsidy_ratio ) {
$res = db :: name ( $this -> table_room_subsidy_config ) -> insertGetId ([
'start_amount' => $start_amount ,
'end_amount' => $end_amount ,
'subsidy_ratio' => $subsidy_ratio ,
'createtime' => time (),
]);
if ( ! $res ) {
return V ( 0 , " 添加失败 " );
}
} else {
return V ( 0 , " 参数错误 " );
}
return V ( 1 , " 添加成功 " );
}
/*
* 房间补贴配置列表
*/
public function room_subsidy_config_lists (){
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$where = [];
$count = db :: name ( $this -> table_room_subsidy_config ) -> where ( $where ) -> count ();
$lists = db :: name ( $this -> table_room_subsidy_config ) -> where ( $where ) -> page ( $page , $page_limit ) -> order ( 'id desc' ) -> select ();
foreach ( $lists as $key => $value ) {
$lists [ $key ][ 'createtime' ] = date ( 'Y-m-d H:i:s' , $value [ 'createtime' ]);
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $lists
];
return V ( 1 , " 成功 " , $return_data );
}
/*
* 房间补贴配置 删除
*/
public function del_room_config_subsidy (){
$id = input ( 'id' , '' );
if ( $id == '' ){
return V ( 0 , " 参数错误 " );
}
$result = db :: name ( $this -> table_room_subsidy_config ) -> where ([ 'id' => $id ]) -> delete ();
if ( ! $result ){
return V ( 0 , " 删除失败 " );
}
return V ( 1 , " 成功 " );
}
/*
* 房间补贴配置 编辑
*/
public function edit_room_config_subsidy (){
$id = input ( 'id' , '' );
if ( $id == '' ){
return V ( 0 , " 参数错误 " );
}
$guild_subsidy_config = db :: name ( $this -> table_room_subsidy_config ) -> where ([ 'id' => $id ]) -> find ();
if ( ! $guild_subsidy_config ){
return V ( 0 , " 数据不存在 " );
}
$start_amount = input ( 'start_amount' , " " );
$end_amount = input ( 'end_amount' , " " );
$subsidy_ratio = input ( 'subsidy_ratio' , " " );
$data = [];
if ( $start_amount != " " ){
$data [ 'start_amount' ] = $start_amount ;
}
if ( $end_amount != " " ){
$data [ 'end_amount' ] = $end_amount ;
}
if ( $subsidy_ratio != " " ){
$data [ 'subsidy_ratio' ] = $subsidy_ratio ;
}
$result = db :: name ( $this -> table_room_subsidy_config ) -> where ([ 'id' => $id ]) -> update ( $data );
if ( ! $result ){
return V ( 0 , " 修改失败 " );
}
return V ( 1 , " 成功 " );
}
/*
* 房间补贴配置 状态修改
*/
public function room_config_subsidy_status (){
$id = input ( 'id' , '' );
if ( $id == '' ){
return V ( 0 , " 参数错误 " );
}
$status = input ( 'status' , '' );
if ( $status == '' ){
return V ( 0 , " 参数错误 " );
}
$result = db :: name ( $this -> table_room_subsidy_config ) -> where ([ 'id' => $id ]) -> update ([ 'status' => $status ]);
if ( ! $result ){
return V ( 0 , " 修改失败 " );
}
return V ( 1 , " 成功 " );
}
/*
* 房间周补贴列表
*/
public function room_subsidy_list (){
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$search_user_id = input ( 'search_user_id' , '' );
$search_room_id = input ( 'search_room_id' , '' );
$search_status_time = input ( 'search_status_time' , '' );
$search_end_time = input ( 'search_end_time' , '' );
$search_status = input ( 'search_status' , '' );
$where = [ 'b.delete_time' => 0 ];
if ( $search_user_id ){
$where [ 'b.user_id' ] = $search_user_id ;
}
if ( $search_room_id ){
$where [ 'a.room_id' ] = $search_room_id ;
}
if ( $search_status_time ){
$where [ 'a.start_time' ] = [ '>=' , $search_status_time ];
}
if ( $search_end_time ){
$where [ 'a.end_time' ] = [ '<=' , $search_end_time ];
}
if ( $search_status ){
$where [ 'a.status' ] = $search_status ;
}
$count = db :: name ( $this -> table_room_subsidy ) -> alias ( 'a' )
-> join ( 'vs_room b' , 'a.room_id = b.id' )
-> where ( $where )
-> count ();
$lists_data = db :: name ( $this -> table_room_subsidy ) -> alias ( 'a' )
-> join ( 'vs_room b' , 'a.room_id = b.id' )
-> where ( $where )
-> order ( 'a.id desc' )
-> field ( 'a.*,b.room_name,b.user_id' )
-> page ( $page , $page_limit )
-> select ();
$lists = [];
foreach ( $lists_data as $key => $value ) {
$lists [ $key ][ 'id' ] = $value [ 'id' ];
$lists [ $key ][ 'user_id' ] = $value [ 'user_id' ];
$lists [ $key ][ 'user_name' ] = model ( 'user' ) -> where ([ 'id' => $value [ 'user_id' ]]) -> value ( 'nickname' );
$lists [ $key ][ 'room_id' ] = $value [ 'room_id' ];
$lists [ $key ][ 'room_name' ] = $value [ 'room_name' ];
$lists [ $key ][ 'total_transaction' ] = $value [ 'total_transaction' ];
$lists [ $key ][ 'subsidy_amount' ] = $value [ 'subsidy_amount' ];
$lists [ $key ][ 'time' ] = date ( 'Y-m-d' , strtotime ( $value [ 'start_time' ])) . '~' . date ( 'Y-m-d' , strtotime ( $value [ 'end_time' ]));
$lists [ $key ][ 'status' ] = $value [ 'status' ];
$lists [ $key ][ 'status_str' ] = $value [ 'status' ] ? '已发放' : '未发放' ;
$lists [ $key ][ 'room_code' ] = model ( 'api/Decorate' ) -> user_decorate_detail ( $value [ 'room_id' ], 7 );
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $lists
];
return V ( 1 , " 成功 " , $return_data );
}
//房间审核列表
public function room_audit_list (){
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$search_user_id = input ( 'search_user_id' , '' );
$search_room_id = input ( 'search_room_id' , '' );
$apply_status = input ( 'apply_status' , '' ); //1待审核 2审核通过 3审核失败
if ( $search_room_id !== '' ){
$where [ 'room_number' ] = $search_room_id ;
}
if ( $search_user_id !== '' ){
$where [ 'user_id' ] = $search_user_id ;
}
if ( $apply_status !== '' ){
$where [ 'apply_status' ] = $apply_status ;
} else {
$where [ 'apply_status' ] = [ '<>' , 2 ];
}
$count = db :: name ( $this -> table ) -> where ( $where ) -> count ();
$room_lists = db :: name ( $this -> table )
-> field ( 'id,room_name,room_number,user_id,room_cover,room_intro,apply_status,createtime' )
-> where ( $where ) -> page ( $page , $page_limit ) -> select ();
foreach ( $room_lists as & $value ) {
$value [ 'room_code' ] = model ( 'api/Decorate' ) -> user_decorate_detail ( $value [ 'id' ], 7 );
$value [ 'user_name' ] = model ( 'User' ) -> where ([ 'id' => $value [ 'user_id' ]]) -> value ( 'nickname' ) . '-' . $value [ 'user_id' ];
$value [ 'createtime' ] = date ( 'Y-m-d H:i:s' , $value [ 'createtime' ]);
$value [ 'room_name' ] = $value [ 'room_name' ] . '-' . $value [ 'room_number' ];
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $room_lists
];
return V ( 1 , " 成功 " , $return_data );
}
//房间审核
public function room_audit (){
$id = input ( 'id' , '' );
if ( $id == '' ){
return V ( 0 , " 参数错误 " );
}
$apply_status = input ( 'apply_status' , '' );
if ( $apply_status == '' ){
return V ( 0 , " 参数错误 " );
}
$result = db :: name ( 'vs_room' ) -> where ([ 'id' => $id ]) -> update ([ 'apply_status' => $apply_status ]);
if ( ! $result ){
return V ( 0 , " 修改失败 " );
}
return V ( 1 , " 成功 " );
}
/*
* 补贴发放
*/
public function subsidy_give (){
$id = input ( 'id' );
$status = input ( 'status' , 0 );
$remark = input ( 'remark' , 0 );
if ( ! $id ){
return V ( 0 , " 参数错误 " );
}
$data = db :: name ( $this -> table_room_subsidy ) -> alias ( 'a' )
-> join ( 'vs_room b' , 'a.room_id = b.id' )
-> where ([ 'a.id' => $id ])
-> field ( 'a.subsidy_amount,b.user_id,a.status,a.id,b.room_status' )
-> find ();
if ( ! $data ){
return V ( 0 , " 补贴数据不存在 " );
}
if ( $data [ 'room_status' ] == 3 ){
return V ( 0 , " 房间已关闭 " );
}
if ( $data [ 'status' ] != 0 ){
return V ( 0 , " 该申请已处理 " );
}
Db :: startTrans ();
try {
if ( $status == 1 ){
//发放处理用户资金
$reslut = model ( 'common/UserWallet' ) -> change_user_money ( $data [ 'user_id' ], $data [ 'subsidy_amount' ], model ( 'common/UserWallet' ) :: MONEYTYPEARNINGS , model ( 'common/UserWallet' ) :: ROOM_SUBSIDY , model ( 'common/UserWallet' ) :: ChangeTypeLable ( model ( 'common/UserWallet' ) :: ROOM_SUBSIDY ));
if ( $reslut [ 'code' ] != 1 ) {
Db :: rollback ();
return V ( $reslut [ 'code' ], $reslut [ 'msg' ]);
}
}
$res = DB :: name ( $this -> table_room_subsidy ) -> where ( 'id' , $id ) -> update ([
'status' => $status ,
'remark' => $remark
]);
if ( $res ){
Db :: commit ();
return V ( 1 , " 操作成功 " );
} else {
Db :: rollback ();
return V ( 0 , " 操作失败 " );
}
} catch ( Exception $e ) {
Db :: rollback ();
return V ( 0 , $e -> getMessage ());
}
}
/*
* 批量补贴发放
*/
public function subsidy_give_batch (){
$ids = input ( 'ids' );
$status = input ( 'status' , 0 );
$remark = input ( 'remark' , 0 );
$ids = explode ( ',' , $ids );
if ( ! $ids ){
return V ( 0 , " 参数错误 " );
}
$data = db :: name ( $this -> table_room_subsidy ) -> alias ( 'a' )
-> join ( 'vs_room b' , 'a.room_id = b.id' )
-> whereIn ( " room_id " , $ids )
-> field ( 'a.subsidy_amount,b.user_id,a.status,a.id' )
-> select ();
if ( ! $data ){
return V ( 0 , " 参数错误 " );
}
$data_arr = [];
Db :: startTrans ();
try {
foreach ( $data as $value ){
if ( $value [ 'status' ] != 0 ) {
continue ;
}
if ( $status == 1 ){
//发放处理用户资金
$reslut = model ( 'common/UserWallet' ) -> change_user_money ( $value [ 'user_id' ], $value [ 'subsidy_amount' ], model ( 'common/UserWallet' ) :: MONEYTYPEARNINGS , model ( 'common/UserWallet' ) :: ROOM_SUBSIDY , model ( 'common/UserWallet' ) :: ChangeTypeLable ( model ( 'common/UserWallet' ) :: ROOM_SUBSIDY ));
if ( $reslut [ 'code' ] != 1 ) {
Db :: rollback ();
return V ( $reslut [ 'code' ], $reslut [ 'msg' ]);
}
}
}
$res = DB :: name ( $this -> table_room_subsidy ) -> whereIn ( 'id' , $ids ) -> where ( 'status' , 0 ) -> update ([
'status' => $status ,
'remark' => $remark
]);
if ( $res ){
Db :: commit ();
return V ( 1 , " 操作成功 " );
} else {
Db :: rollback ();
return V ( 0 , " 操作失败 " );
}
} catch ( Exception $e ) {
Db :: rollback ();
return V ( 0 , $e -> getMessage ());
}
}
/*
* 房间操作记录列表
*/
public function room_log_list (){
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$seach_room_id = input ( 'room_id' , '' );
$from_uid = input ( 'from_uid' , '' );
$to_id = input ( 'to_id' , '' );
$type = input ( 'type' , '' );
$stime = input ( 'stime' , '' );
$etime = input ( 'etime' , '' );
$where = [];
if ( $seach_room_id ){
if ( is_numeric ( $seach_room_id )) {
$room_id = db :: name ( 'vs_room' ) -> where ( 'room_number' , $seach_room_id ) -> value ( 'id' );
$where [ 'room_id' ] = $room_id ;
} else {
$room_id = db :: name ( 'vs_room' ) -> where ( 'room_name' , $seach_room_id ) -> value ( 'id' );
$where [ 'room_id' ] = $room_id ;
}
}
if ( $from_uid ){
if ( is_numeric ( $from_uid )){
$from_user_id = db :: name ( 'user' ) -> where ( 'user_code' , $from_uid ) -> value ( 'id' );
$where [ 'user_id' ] = $from_user_id ;
} else {
$from_user_id = db :: name ( 'user' ) -> where ( 'nickname' , $from_uid ) -> value ( 'id' );
$where [ 'user_id' ] = $from_user_id ;
}
}
if ( $to_id ){
if ( is_numeric ( $to_id )){
$accept_user_id = db :: name ( 'user' ) -> where ( 'user_code' , $to_id ) -> value ( 'id' );
$where [ 'accept_user_id' ] = $accept_user_id ;
} else {
$accept_user_id = db :: name ( 'user' ) -> where ( 'nickname' , $to_id ) -> value ( 'id' );
$where [ 'accept_user_id' ] = $accept_user_id ;
}
}
if ( $type ){
$where [ 'type' ] = $type ;
}
if ( ! empty ( $stime )){
$where [ 'createtime' ] = [ '>=' , strtotime ( $stime )];
}
if ( ! empty ( $etime )){
$where [ 'createtime' ] = [ '<=' , strtotime ( $etime . ' 23:59:59' )];
}
if ( ! empty ( $stime ) && ! empty ( $etime )){
$where [ 'createtime' ] = [ 'between' ,[ strtotime ( $stime ), strtotime ( $etime . ' 23:59:59' )]];
}
$room_log_lists = db :: name ( $this -> table_room_log ) -> where ( $where ) -> order ( 'id desc' ) -> page ( $page , $page_limit ) -> select ();
$count = db :: name ( $this -> table_room_log ) -> where ( $where ) -> count ();
$lists = [];
foreach ( $room_log_lists as $key => $value ) {
$lists [ $key ][ 'id' ] = $value [ 'id' ];
$lists [ $key ][ 'room_code' ] = db :: name ( 'vs_room' ) -> where ([ 'id' => $value [ 'room_id' ]]) -> value ( 'room_number' );
$lists [ $key ][ 'createtime' ] = date ( 'Y-m-d H:i:s' , $value [ 'createtime' ]);
$user = db :: name ( 'user' ) -> where ([ 'id' => $value [ 'user_id' ]]) -> find ();
$lists [ $key ][ 'from_uname' ] = $user [ 'user_code' ] . " - " . $user [ 'nickname' ];
$accept_user = db :: name ( 'user' ) -> where ([ 'id' => $value [ 'accept_user_id' ]]) -> find ();
$lists [ $key ][ 'to_uname' ] = $value [ 'accept_user_id' ] ? $accept_user [ 'user_code' ] . " - " . $accept_user [ 'nickname' ] : " " ;
$lists [ $key ][ 'room_name' ] = $lists [ $key ][ 'room_code' ] . " - " . db :: name ( 'vs_room' ) -> where ([ 'id' => $value [ 'room_id' ]]) -> value ( 'room_name' );
$lists [ $key ][ 'type' ] = $value [ 'type' ];
$lists [ $key ][ 'type_str' ] = model ( 'Room' ) -> room_log_type [ $value [ 'type' ]];
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $lists ,
'room_log_type' => model ( 'Room' ) -> room_log_type
];
return V ( 1 , " 成功 " , $return_data );
}
/*
* 头条列表
*/
public function room_headline_list (){
$page = input ( 'page' , 1 );
$page_limit = input ( 'page_limit' , 30 );
$user_id = input ( 'user_id' , '' );
$stime = input ( 'stime' , '' );
$etime = input ( 'etime' , '' );
$where = [];
if ( $user_id ){
$where [ 'user_id' ] = $user_id ;
}
if ( $stime ){
$where [ 'createtime' ] = [ '>=' , strtotime ( $stime )];
}
if ( $etime ){
$where [ 'createtime' ] = [ '<=' , strtotime ( $etime )];
}
$count = db :: name ( " vs_headline " ) -> where ( $where ) -> count ();
$room_headline_lists = db :: name ( " vs_headline " ) -> where ( $where ) -> page ( $page , $page_limit ) -> order ( 'id desc' ) -> select ();
$lists = [];
foreach ( $room_headline_lists as $key => $value ) {
if ( $value [ 'end_time' ] < time ()){
db :: name ( " vs_headline " ) -> where ([ 'id' => $value [ 'id' ]]) -> update ([ 'is_now' => 0 ]);
}
$lists [ $key ][ 'id' ] = $value [ 'id' ];
$user_code = model ( 'api/Decorate' ) -> user_decorate_detail ( $value [ 'user_id' ], 6 );
$lists [ $key ][ 'user_name' ] = $user_code . " - " . db :: name ( 'user' ) -> where ([ 'id' => $value [ 'user_id' ]]) -> value ( 'nickname' );
$lists [ $key ][ 'content' ] = $value [ 'content' ];
$lists [ $key ][ 'money' ] = $value [ 'money' ];
$lists [ $key ][ 'status' ] = $value [ 'is_now' ] == 1 ? " 显示中 " : " 已完成 " ;
if ( $value [ 'end_time' ] < time ()){
$lists [ $key ][ 'status' ] = " 已完成 " ;
}
$lists [ $key ][ 'createtime' ] = date ( 'Y-m-d H:i:s' , $value [ 'createtime' ]);
$lists [ $key ][ 'is_now' ] = $value [ 'is_now' ];
}
$return_data = [
'page' => $page ,
'page_limit' => $page_limit ,
'count' => $count ,
'lists' => $lists ,
];
return V ( 1 , " 成功 " , $return_data );
}
/*
* 删除头条
*/
public function room_headline_del (){
$id = input ( 'id' , '' );
if ( ! $id ){
return V ( 0 , " 参数错误 " );
}
$res = db :: name ( " vs_headline " ) -> where ([ 'id' => $id ]) -> delete ();
if ( $res ){
return V ( 1 , " 删除成功 " );
} else {
return V ( 0 , " 删除失败 " );
}
}
/*
* 隐藏头条
*/
public function room_headline_hide (){
$id = input ( 'id' , '' );
if ( ! $id ){
return V ( 0 , " 参数错误 " );
}
$headline = db :: name ( " vs_headline " ) -> where ([ 'id' => $id ]) -> find ();
if ( ! $headline ){
return V ( 0 , " 参数错误 " );
}
if ( $headline [ 'is_now' ] == 2 ){
return V ( 0 , " 该头条已隐藏 " );
}
$res = db :: name ( " vs_headline " ) -> where ([ 'id' => $id ]) -> update ([
'is_now' => 2
]);
if ( $res ){
return V ( 1 , " 隐藏成功 " );
} else {
return V ( 0 , " 隐藏失败 " );
}
}
/*
* 创建CP电影房
*/
public function create_cp_movie_room (){
$user_id1 = input ( 'user_id1' , '' );
$user_id2 = input ( 'user_id2' , '' );
$time_day = input ( 'time_day' , '' );
//开启电影房
$nickname = db :: name ( 'user' ) -> where ( 'id' , $user_id1 ) -> value ( 'nickname' );
$nickname1 = db :: name ( 'user' ) -> where ( 'id' , $user_id2 ) -> value ( 'nickname' );
//开启事务
db :: startTrans ();
//创建房间
$room_id = model ( 'api/Room' ) -> user_create_room ( $user_id1 , $nickname . ' & ' . $nickname1 . ' 的Cp电影房' , get_system_config_value ( 'web_site' ) . '/data/avatar/head_pic.png' , $nickname . ' 和 ' . $nickname1 . ' 的Cp电影房' , $user_id1 . $user_id2 );
if ( ! $room_id [ 'status' ]){
db :: rollback ();
return V ( 0 , $room_id [ 'msg' ]);
}
//添加到数据库
$res2 = db :: name ( 'vs_room_cp_movie' ) -> insertGetId ([
'room_id' => $room_id [ 'data' ],
'user_id' => $user_id1 ,
'user_id1' => $user_id2 ,
'time_day' => time () + $time_day ,
'createtime' => time (),
'status' => 1
]);
if ( ! $res2 ){
db :: rollback ();
return V ( 0 , " 添加失败 " );
}
db :: commit ();
return V ( 1 , " 成功 " , [ 'room_id' => $room_id [ 'data' ]]);
}
//声网的token
public function get_token (){
$admin_id = Session :: get ( 'admin_id' );
$room_id = input ( 'room_id' , '' );
$token = model ( 'api/Agora' ) -> agora_token_info ( $admin_id , $room_id );
return V ( 1 , " 成功 " , [ 'token' => $token ]);
}
//推荐房间列表(消息类型为房间公告时选择用)
public function recommend_room_list (){
$room_list = db :: name ( $this -> table ) -> where ([ 'is_recommend' => 2 , 'room_status' => 1 ]) -> select ();
$result = [];
foreach ( $room_list as $key => $value ) {
$result [ $key ][ 'room_id' ] = $value [ 'id' ];
$result [ $key ][ 'room_name' ] = $value [ 'room_name' ];
}
return V ( 1 , " 成功 " , $result );
}
}