2025-08-08 14:45:40 +08:00
< ? php
namespace app\api\model ;
use think\Db ;
use think\Model ;
use think\facade\Cache ;
class Gift extends Model
{
2025-11-07 17:24:56 +08:00
//厅主收益
2025-08-08 14:45:40 +08:00
public $room_owner_rate ;
2025-11-07 17:24:56 +08:00
//用户实时收益
public $user_rate ;
//加入工会用户实时收益
public $guild_user_rate ;
2025-08-08 14:45:40 +08:00
public function __construct ( $data = [])
{
parent :: __construct ( $data );
// $now_time = time();
// $end_time = strtotime("2024-11-18 00:00:00");
// if($now_time < $end_time){
// $rate = 0.1;
// }else{
// $rate = 0.2;
// }
// $rate = 0.2;
$rate = 0.1 ;
$this -> room_owner_rate = $rate ;
2025-11-07 17:24:56 +08:00
$this -> user_rate = 0.6 ;
$this -> guild_user_rate = 0.63 ;
2025-08-08 14:45:40 +08:00
}
public function get_gift_list ()
{
$map = [];
$map [] = [ 'is_delete' , '=' , 1 ];
$map [] = [ 'is_show' , '=' , 1 ];
$list = db :: name ( 'gift' ) -> field ( 'gid,gift_name,base_image,gift_price' ) -> where ( $map ) -> order ( 'sort desc' ) -> select ();
foreach ( $list as $k => & $v ) {
$v [ 'base_image' ] = localpath_to_netpath ( $v [ 'base_image' ]);
}
return [ 'code' => 200 , 'msg' => '获取成功' , 'data' => $list ];
}
public function send_gift ( $uid , $to_uid_list , $rid , $gid , $num , $send_type , $help_uid )
{
$map = [];
$map [] = [ 'gid' , '=' , $gid ];
$map [] = [ 'is_delete' , '=' , 1 ];
$map [] = [ 'is_show' , '=' , 1 ];
$gift_info = db :: name ( 'gift' ) -> where ( $map ) -> find ();
if ( empty ( $gift_info )) {
return [ 'code' => 201 , 'msg' => '打赏礼物信息不存在' , 'data' => null ];
}
$gift_info [ 'play_image' ] = localpath_to_netpath ( $gift_info [ 'play_image' ]);
$gift_info [ 'base_image' ] = localpath_to_netpath ( $gift_info [ 'base_image' ]);
if ( ceil ( $num ) != $num ) {
return [ 'code' => 201 , 'msg' => '打赏礼物数量必须为整数' , 'data' => null ];
}
if ( $num < 1 ) {
return [ 'code' => 201 , 'msg' => '打赏礼物数量必须大于零' , 'data' => null ];
}
if ( $send_type == 1 ){
if ( $gift_info [ 'is_can_buy' ] != 1 ){
return [ 'code' => 201 , 'msg' => '该礼物不可购买赠送' , 'data' => null ];
}
}
if ( $gift_info [ 'type' ] == 4 && $send_type == 1 ){
$reslut = model ( 'GiftMultiple' ) -> send_gift_multiple ( $uid , $to_uid_list , $rid , $gid , $num , $send_type , $help_uid );
return $reslut ;
}
$map = [];
$map [] = [ 'rid' , '=' , $rid ];
$map [] = [ 'is_delete' , '=' , 1 ];
$room_info = db :: name ( 'room' ) -> where ( $map ) -> find ();
if ( empty ( $room_info )) {
return [ 'code' => 201 , 'msg' => '所处房间不存在' , 'data' => null ];
}
$room_owner_info = db :: name ( 'user' ) -> where ( 'uid' , $room_info [ 'room_owner_uid' ]) -> find ();
//该房间是否加入公会
$room_guild_id = model ( 'guild' ) -> user_guild_info ( $room_info [ 'room_owner_uid' ]);
$to_uid_data = explode ( ',' , trim ( $to_uid_list , ',' ));
$to_uid_data = array_values ( array_unique ( $to_uid_data ));
if ( in_array ( $uid , $to_uid_data )) {
return [ 'code' => 201 , 'msg' => '不能给自己打赏' , 'data' => null ];
}
$map = [];
$map [] = [ 'uid' , 'in' , $to_uid_data ];
$user_list = db :: name ( 'user' ) -> field ( 'uid,is_tester,money,integral,nick_name,base64_nick_name,head_pic,europe_key,airship' ) -> where ( $map ) -> select ();
if ( empty ( $user_list )) {
return [ 'code' => 201 , 'msg' => '打赏礼物对象不能为空' , 'data' => null ];
}
if ( count ( $to_uid_data ) != count ( $user_list )) {
return [ 'code' => 201 , 'msg' => '打赏礼物对象不存在' , 'data' => null ];
}
$send_count = count ( $user_list ); //赠送总人数
$total_send_num = $num * $send_count ; //赠送礼物总数量
$total_send_amount = $gift_info [ 'gift_price' ] * $num * $send_count ; //赠送礼物总价值
$config = get_uncache_system_config ();
if ( $config [ 'gift_earnings_rate' ] > 1 ){
2025-11-07 17:24:56 +08:00
$config [ 'gift_earnings_rate' ] = $this -> user_rate ;
2025-08-08 14:45:40 +08:00
}
$now_time = time ();
$user_info = db :: name ( 'user' ) -> where ( 'uid' , $uid ) -> find ();
if ( $user_info [ 'is_teenager' ] == 1 ){
return [ 'code' => 201 , 'msg' => '已开启青少年模式' , 'data' => null ];
}
$ress = model ( 'api/UserWallet' ) -> get_user_wallet ( $uid , $user_info [ 'money' ], $user_info [ 'integral' ]);
if ( $ress [ 'code' ] != 200 ) {
return $ress ;
}
//礼物盲盒
$blind_box = [ 37 , 38 , 39 ];
if ( in_array ( $gid , $blind_box )){
$reslut = $this -> open_blind_box ( $uid , $rid , $gid , $num , $to_uid_data , $help_uid );
return $reslut ;
}
if ( $send_type == 1 ) { //直接购买
if ( $gift_info [ 'type' ] == 6 && $user_info [ 'nobility_id' ] < $gift_info [ 'nid' ]){
return [ 'code' => 201 , 'msg' => '爵位等级不足' , 'data' => null ];
}
if ( $gift_info [ 'type' ] == 8 ){
if ( in_array ( $uid , $to_uid_data )){
return [ 'code' => 201 , 'msg' => '挂件礼物不能给自己打赏' , 'data' => null ];
}
if ( count ( $user_list ) > 1 ){
return [ 'code' => 201 , 'msg' => '挂件礼物不能一次赠送多人' , 'data' => null ];
}
}
//扣款时进行用户资金是否充足判断
$user_auction_price = model ( 'NewRoom' ) -> get_user_auction_price ( $uid );
if ( $user_info [ 'integral' ] < ( $total_send_amount + $user_auction_price )) {
return [ 'code' => 201 , 'msg' => '账户资金不足' , 'data' => null ];
}
} elseif ( $send_type == 2 ) { //扣除背包
//判断背包礼物是否充足
$map = [];
$map [] = [ 'gid' , '=' , $gid ];
$map [] = [ 'uid' , '=' , $uid ];
$map [] = [ 'is_use_give' , '=' , 1 ];
$user_gift_pack_info = db :: name ( 'user_gift_pack' ) -> where ( $map ) -> find ();
if ( empty ( $user_gift_pack_info )) {
return [ 'code' => 201 , 'msg' => '背包礼物不足' , 'data' => null ];
}
if ( $user_gift_pack_info [ 'num' ] < $total_send_num ) {
return [ 'code' => 201 , 'msg' => '背包礼物不足' , 'data' => null ];
}
} else {
return [ 'code' => 201 , 'msg' => '参数非法' , 'data' => null ];
}
//当前主持比例
$room_host_commission = 0 ;
if ( $room_info [ 'room_owner_uid' ] != $room_info [ 'room_host_uid' ] && ! empty ( $room_info [ 'room_host_uid' ])){
$room_host_info = db :: name ( 'room_host' ) -> where ( 'rid' , $rid ) -> where ( 'uid' , $room_info [ 'room_host_uid' ]) -> where ( 'is_delete' , 1 ) -> find ();
if ( ! empty ( $room_host_info )){
$room_host_commission = $room_host_info [ 'ratio' ];
}
}
Db :: startTrans ();
try {
if ( $user_info [ 'is_tester' ] == 1 ) { //测试用户只推送赠送礼物信息
//$total_amount = $gift_info['gift_price'] * $num * $send_count;
if ( $send_type == 1 ) { //直接购买
//计算赠送礼物总资金
$reslut = model ( 'admin/User' ) -> change_user_money_by_uid ( $uid , - $total_send_amount , 2 , 4 , " 打赏礼物 " , $uid , 0 , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
//CP关系处理
foreach ( $to_uid_data as $a => $b ){
if ( $uid != $b ){
if ( ! empty ( $config [ 'cp_gift_id' ]) && $config [ 'cp_gift_id' ] == $gid ){
$coupling_info = model ( 'Coupling' ) -> get_coupling_info ( $uid , $b , $total_send_amount );
if ( $coupling_info [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $coupling_info [ 'msg' ], 'data' => null ];
}
} else {
$coupling_info = model ( 'Coupling' ) -> update_user_cp_value ( $uid , $b , $total_send_amount );
if ( $coupling_info [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $coupling_info [ 'msg' ], 'data' => null ];
}
}
}
}
// //消费爵位处理
// $nobility_info = model('Nobility')->user_gain_nobility_value($uid, $total_send_amount);
// if($nobility_info['code'] == 201){
// Db::rollback();
// return ['code' => 201, 'msg' => $nobility_info['msg'], 'data' => null];
// }
//挂件礼物记录
if ( $gift_info [ 'type' ] == 8 ){
$is_show = 2 ;
$pendant_log = $this -> add_pendant_gift_log ( $uid , $to_uid_list , $rid , $gid , $num , $gift_info [ 'gift_price' ]);
if ( $pendant_log [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
$is_show = $pendant_log [ 'data' ][ 'is_show' ];
}
if ( $gift_info [ 'type' ] == 7 ){
foreach ( $to_uid_data as $a => $b ){
$micro_gift_log = model ( 'RoomMicroGift' ) -> update_room_micro_gift ( $uid , $b , $rid , $gid , $gift_info [ 'position' ]);
if ( $micro_gift_log [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试2' , 'data' => null ];
}
}
}
} elseif ( $send_type == 2 ) { //扣除背包
//扣除背包礼物
$reslut = model ( 'UserGiftPack' ) -> change_user_gift_pack ( $uid , $gid , - $total_send_num , 3 , '背包打赏礼物' );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
foreach ( $to_uid_data as $a => $b ){
if ( $uid != $b ){
// if(!empty($config['cp_gift_id']) && $config['cp_gift_id'] == $gid){
// $coupling_info = model('Coupling')->get_coupling_info($uid, $b, $total_send_amount);
// if($coupling_info['code'] == 201){
// Db::rollback();
// return ['code' => 201, 'msg' => $coupling_info['msg'], 'data' => null];
// }
// }else{
$coupling_info = model ( 'Coupling' ) -> update_user_cp_value ( $uid , $b , $total_send_amount );
if ( $coupling_info [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $coupling_info [ 'msg' ], 'data' => null ];
}
// }
}
}
} else {
return [ 'code' => 201 , 'msg' => '参数非法' , 'data' => null ];
}
//赠送礼物增加财富值 贡献值
$reslut = model ( 'User' ) -> change_user_contribution_value ( $uid , $total_send_amount );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试1' , 'data' => null ];
}
//赠送者增加房间魅力值
$reslut = model ( 'User' ) -> change_user_room_contribution_value ( $uid , $rid , $total_send_amount );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//日贡献
model ( 'Statistics' ) -> day_contribution ( $uid , $rid , $total_send_amount , 1 );
//房间礼物墙
$reslut = model ( 'GiftWall' ) -> room_gift_wall ( $rid , $gid , $total_send_num , $total_send_amount );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试5' , 'data' => null ];
}
//增加房间热度值
db :: name ( 'room' ) -> where ( 'rid' , $rid ) -> inc ( 'hot_value' , $total_send_amount ) -> inc ( 'today_hot_value' , $total_send_amount ) -> update ();
//送礼物人是否在麦位上--交友厅
$send_user_micro_info = Db :: name ( 'room_micro' ) -> where ([ 'rid' => $rid , 'uid' => $uid ]) -> find ();
$is_on_micro = 0 ;
if ( $send_user_micro_info && $send_user_micro_info [ 'micro_id' ] <= 6 ) {
$is_on_micro = 1 ;
}
$message_data = [];
foreach ( $user_list as $k => $v ) {
//收礼用户公会ID
$user_guild_id = model ( 'guild' ) -> user_guild_info ( $v [ 'uid' ]);
//是否有制作人
$is_producer = 2 ;
$user_sign_contract = db :: name ( 'user_sign_contract' ) -> where ( 'sign_uid' , $v [ 'uid' ]) -> where ( 'is_delete' , 1 ) -> order ( 'id desc' ) -> find ();
if ( $user_sign_contract ){
$is_producer = 1 ;
}
$gift_total_price = $gift_info [ 'gift_price' ] * $num ;
//是否有厅主收益
if ( $room_info [ 'is_earnings' ] == 1 ){
$room_owner_profits = $gift_total_price * $this -> room_owner_rate ; //房主厅主收益
$room_owner_profit = $room_owner_profits * ( 1 - $room_host_commission );
$room_host_profit = $room_owner_profits * $room_host_commission ;
} else {
$room_owner_profits = 0 ; //房主厅主收益
$room_owner_profit = 0 ;
$room_host_profit = 0 ;
}
if ( $is_producer == 1 ){
$producer_profit = $gift_total_price * 0.05 ;
} else {
$producer_profit = 0 ;
}
$producer_profit = 0 ;
if ( ! empty ( $user_guild_id )){
2025-11-07 17:24:56 +08:00
$receiver_profit = $gift_total_price * $this -> user_rate ;
2025-08-08 14:45:40 +08:00
} else {
2025-11-07 17:24:56 +08:00
$receiver_profit = $gift_total_price * $this -> guild_user_rate ;
2025-08-08 14:45:40 +08:00
}
// $receiver_profit = $gift_total_price * $config['gift_earnings_rate'];
$platform_profit = $gift_total_price - $room_owner_profits - $receiver_profit - $producer_profit ;
$data = [];
$data [ 'guild_id' ] = $user_guild_id ;
$data [ 'room_guild_id' ] = $room_guild_id ;
$data [ 'uid' ] = $uid ;
$data [ 'rid' ] = $rid ;
$data [ 'room_uid' ] = $room_info [ 'room_owner_uid' ];
$data [ 'room_host_uid' ] = $room_info [ 'room_host_uid' ];
$data [ 'receive_uid' ] = $v [ 'uid' ];
$data [ 'gid' ] = $gid ;
$data [ 'gift_name' ] = $gift_info [ 'gift_name' ];
$data [ 'gift_price' ] = $gift_info [ 'gift_price' ];
$data [ 'gift_num' ] = $num ;
$data [ 'gift_total_price' ] = $gift_total_price ;
$data [ 'platform_profit' ] = $platform_profit ;
$data [ 'receiver_profit' ] = $receiver_profit ;
$data [ 'room_owner_profit' ] = $room_owner_profit ;
$data [ 'room_host_profit' ] = $room_host_profit ;
$data [ 'producer_profit' ] = $producer_profit ;
$data [ 'gift_from_type' ] = $send_type ;
$data [ 'is_tester' ] = $user_info [ 'is_tester' ];
$data [ 'add_time' ] = $now_time ;
$data [ 'update_time' ] = $now_time ;
$sid = db :: name ( 'user_send_gift' ) -> insertGetId ( $data );
if ( empty ( $sid )) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => " 请重试37 " , 'data' => null ];
}
//发送数据开始
$message_data_temp = [
'from_uid' => $uid ,
'to_uid' => $v [ 'uid' ],
'gift_name' => $gift_info [ 'gift_name' ],
'gift_price' => $gift_info [ 'gift_price' ],
'gift_num' => $num ,
'rid' => $rid ,
];
$message_data [] = $message_data_temp ;
//增加厅主收益记录
if ( $room_owner_profit > 0 ) {
$change_value = $room_owner_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_uid ( $room_info [ 'room_owner_uid' ], $change_value , 1 , 7 , " 打赏厅主流水收益 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
//收益记录
model ( 'Statistics' ) -> day_room_profit ( $room_info [ 'room_owner_uid' ], $rid , $change_value , 1 );
}
//增加主持收益记录
if ( $room_host_profit > 0 && $room_info [ 'room_host_uid' ] > 0 ) {
$change_value = $room_host_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_uid ( $room_info [ 'room_host_uid' ], $change_value , 1 , 28 , " 打赏主持流水收益 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
//收益记录
model ( 'Statistics' ) -> day_room_profit ( $room_info [ 'room_host_uid' ], $rid , $change_value , 2 );
}
//礼物接收者收益
if ( $receiver_profit > 0 ) {
$change_value = $receiver_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_user_info ( $v , $change_value , 1 , 6 , " 礼物收入 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
}
//制作人收益
if ( $producer_profit > 0 ){
$change_value = $producer_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_uid ( $user_sign_contract [ 'uid' ], $change_value , 1 , 38 , " 打赏制作人流水收益 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
}
//收礼物增加魅力值
$reslut = model ( 'User' ) -> change_user_charm_value ( $v [ 'uid' ], $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//接受者增加房间魅力值
$reslut = model ( 'User' ) -> change_user_room_charm_value ( $v [ 'uid' ], $rid , $gift_total_price , $uid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//日收益
model ( 'Statistics' ) -> day_charm ( $v [ 'uid' ], $rid , $gift_total_price , 1 );
//如果存在公会
if ( $user_guild_id > 0 ) {
model ( 'Statistics' ) -> day_guild_charm ( $v [ 'uid' ], $rid , $user_guild_id , $gift_total_price , 1 );
}
if ( $room_guild_id > 0 ){
model ( 'Statistics' ) -> day_room_guild_charm ( $v [ 'uid' ], $rid , $room_guild_id , $gift_total_price , 1 );
}
//送出礼物墙
// $reslut = model('GiftWall')->user_send_gift_wall($uid, $gid, $num, $v['uid']);
// if($reslut['code'] == 201){
// Db::rollback();
// return ['code' => 201, 'msg' => '请重试5', 'data' => null];
// }
//收礼物墙
$reslut = model ( 'GiftWall' ) -> user_receive_gift_wall ( $v [ 'uid' ], $gid , $num , $uid );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
if ( $gift_total_price > 0 ){
if ( $room_info [ 'cate_id' ] == 29 ){
$reslut = model ( 'DatingRoom' ) -> user_send_gift_heartbeat_line ( $uid , $v [ 'uid' ], $rid , $gift_total_price , $help_uid );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试7-1' , 'data' => null ];
}
}
if ( $room_info [ 'cate_id' ] == 28 && $uid != $v [ 'uid' ]){
$reslut = model ( 'AuctionRoom' ) -> record_user_auction_info ( $uid , $v [ 'uid' ], $rid , $gid , $gift_info [ 'gift_price' ], $num , $room_info [ 'room_host_uid' ]);
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
}
if ( $room_info [ 'cate_id' ] == 27 ){
$reslut = model ( 'KtvRoom' ) -> send_gift_add_song_time ( $uid , $v [ 'uid' ], $rid , $gid , $num , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试7' , 'data' => null ];
}
}
//增加签约人的身价
$reslut = model ( 'Contract' ) -> receive_gift_rise_user_social ( $v [ 'uid' ], $gift_total_price );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试7' , 'data' => null ];
}
}
}
//更新房间在线用户财富值
if ( in_array ( $room_info [ 'cate_id' ], [ 27 , 28 ])){
$reslut = model ( 'RoomBossMicro' ) -> update_room_visitor_value ( $uid , $rid , $total_send_amount );
if ( $reslut [ 'code' ] != 200 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
}
//发送开始
// if($message_data) {
// model('api/AsyncPushMessage')->store_message($message_data, 2);
// }
} elseif ( $user_info [ 'is_tester' ] == 2 ) {
//测试用户不处理
return [ 'code' => 201 , 'msg' => '测试号无法赠送' , 'data' => null ];
if ( $send_type == 2 ) { //扣除背包
//扣除背包礼物
$reslut = model ( 'UserGiftPack' ) -> change_user_gift_pack ( $uid , $gid , - $total_send_num , 3 , '背包打赏礼物' );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
} else {
return [ 'code' => 201 , 'msg' => '参数非法' , 'data' => null ];
}
//赠送礼物增加财富值 贡献值
$reslut = model ( 'User' ) -> change_user_contribution_value ( $uid , $total_send_amount );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试1' , 'data' => null ];
}
//赠送者增加房间魅力值
$reslut = model ( 'User' ) -> change_user_room_contribution_value ( $uid , $rid , $total_send_amount );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//增加房间热度值
db :: name ( 'room' ) -> where ( 'rid' , $rid ) -> inc ( 'hot_value' , $total_send_amount ) -> inc ( 'today_hot_value' , $total_send_amount ) -> update ();
foreach ( $user_list as $k => $v ) {
$gift_total_price = $gift_info [ 'gift_price' ] * $num ;
// $room_owner_profits = $gift_total_price * $room_owner_info['room_owner_commission']; //房主厅主收益
$room_owner_profits = $gift_total_price * $this -> room_owner_rate ; //房主厅主收益
$room_owner_profit = $room_owner_profits * ( 1 - $room_host_commission );
$room_host_profit = $room_owner_profits * $room_host_commission ;
// $receiver_profit = $gift_total_price * $config['gift_earnings_rate'];
$receiver_profit = $gift_total_price * 0.5 ;
$platform_profit = $gift_total_price - $room_owner_profits - $receiver_profit ;
$data = [];
// $data['guild_id'] = $guild_id;
$data [ 'uid' ] = $uid ;
$data [ 'rid' ] = $rid ;
$data [ 'room_uid' ] = $room_info [ 'room_owner_uid' ];
$data [ 'room_host_uid' ] = $room_info [ 'room_host_uid' ];
$data [ 'receive_uid' ] = $v [ 'uid' ];
$data [ 'gid' ] = $gid ;
$data [ 'gift_name' ] = $gift_info [ 'gift_name' ];
$data [ 'gift_price' ] = $gift_info [ 'gift_price' ];
$data [ 'gift_num' ] = $num ;
$data [ 'gift_total_price' ] = $gift_total_price ;
$data [ 'platform_profit' ] = $platform_profit ;
$data [ 'receiver_profit' ] = $receiver_profit ;
$data [ 'room_owner_profit' ] = $room_owner_profit ;
$data [ 'room_host_profit' ] = $room_host_profit ;
$data [ 'gift_from_type' ] = $send_type ;
$data [ 'is_tester' ] = $user_info [ 'is_tester' ];
$data [ 'add_time' ] = $now_time ;
$data [ 'update_time' ] = $now_time ;
$sid = db :: name ( 'user_send_gift' ) -> insertGetId ( $data );
if ( empty ( $sid )) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => " 请重试36 " , 'data' => null ];
}
//收礼物增加魅力值
$reslut = model ( 'User' ) -> change_user_charm_value ( $v [ 'uid' ], $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//接受者增加房间魅力值
$reslut = model ( 'User' ) -> change_user_room_charm_value ( $v [ 'uid' ], $rid , $gift_total_price , $uid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
}
}
Db :: commit ();
model ( 'Room' ) -> push_room_micro_data ( $rid ); //推送最新房间麦位信息
if ( $gift_info [ 'type' ] == 8 && $is_show == 1 ){
$receive_info = db :: name ( 'user' ) -> field ( 'uid, base64_nick_name, head_pic' ) -> find ( $to_uid_list );
$push_room_pendant_data = [];
$push_room_pendant_data [ 'user_info' ][ 'uid' ] = ( int ) $uid ;
$push_room_pendant_data [ 'user_info' ][ 'head_pic' ] = localpath_to_netpath ( $user_info [ 'head_pic' ]);
$push_room_pendant_data [ 'user_info' ][ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $user_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
$push_room_pendant_data [ 'receive_info' ][ 'uid' ] = ( int ) $to_uid_list ;
$push_room_pendant_data [ 'receive_info' ][ 'head_pic' ] = localpath_to_netpath ( $receive_info [ 'head_pic' ]);
$push_room_pendant_data [ 'receive_info' ][ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $receive_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
$push_room_pendant_data [ 'pendant_image' ] = localpath_to_netpath ( $gift_info [ 'pendant_image' ]);
$pust_data = [];
$pust_data [ 'code' ] = 355 ;
$pust_data [ 'msg' ] = '挂件礼物推送' ;
$pust_data [ 'data' ] = $push_room_pendant_data ;
$push_is_open = model ( 'api/WebSocketPush' ) -> send_to_group ( $rid , $pust_data );
}
//查询7号麦是否隐身
$room_xq1_activity = db :: name ( 'room_xq1' ) -> where ([ 'rid' => $rid , 'is_delete' => 1 ]) -> order ([ 'id' => 'desc' ]) -> find ();
$uid7 = 0 ;
if ( ! empty ( $room_xq1_activity )){
if ( $room_xq1_activity [ 'xq_uid_sm' ] == 2 ){ //神秘人
$uid7 = db :: name ( 'room_micro' ) -> where ([ 'rid' => $rid , 'micro_id' => 7 ]) -> value ( 'uid' );
}
}
$room_push_data = [];
$server_push_data = [];
$gift_list = [];
$gift_list [] = $gift_info ;
foreach ( $user_list as $k => $v ) {
foreach ( $gift_list as $m => $n ) {
$ls_data = [];
$ls_data [ 'rid' ] = $rid ;
//神秘人处理
if ( $uid == $uid7 ){
$ls_data [ 'send_user_info' ][ 'uid' ] = 0 ;
$ls_data [ 'send_user_info' ][ 'nick_name' ] = " 神秘人 " ;
} else {
$ls_data [ 'send_user_info' ][ 'uid' ] = $uid ;
$ls_data [ 'send_user_info' ][ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $user_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
}
$ls_data [ 'send_user_info' ][ 'head_pic' ] = localpath_to_netpath ( $user_info [ 'head_pic' ]);
//神秘人处理
if ( $v [ 'uid' ] == $uid7 ){
$ls_data [ 'recived_user_info' ][ 'uid' ] = 0 ;
$ls_data [ 'recived_user_info' ][ 'nick_name' ] = " 神秘人 " ;
} else {
$ls_data [ 'recived_user_info' ][ 'uid' ] = $v [ 'uid' ];
$ls_data [ 'recived_user_info' ][ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $v [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
}
$ls_data [ 'recived_user_info' ][ 'head_pic' ] = localpath_to_netpath ( $v [ 'head_pic' ]);
$ls_data [ 'gift_name' ] = $n [ 'gift_name' ];
$ls_data [ 'play_image' ] = $n [ 'play_image' ];
$ls_data [ 'base_image' ] = $n [ 'base_image' ];
$ls_data [ 'gift_type' ] = $n [ 'gift_type' ];
$ls_data [ 'gift_price' ] = $n [ 'gift_price' ];
$ls_data [ 'num' ] = $num ;
$ls_data [ 'is_public_screen' ] = $n [ 'is_public_screen' ];
$ls_data [ 'is_public_server' ] = $n [ 'is_public_server' ];
if ( $ls_data [ 'is_public_server' ] == 1 ) {
$server_push_data [] = $ls_data ;
}
$room_push_data [] = $ls_data ;
// else {
// $room_push_data[] = $ls_data;
// }
}
}
if ( ! empty ( $server_push_data )) {
$pust_data = [];
$pust_data [ 'code' ] = 306 ;
$pust_data [ 'msg' ] = '打赏礼物' ;
$pust_data [ 'data' ] = $server_push_data ;
model ( 'api/WebSocketPush' ) -> send_to_all ( $pust_data );
}
if ( ! empty ( $room_push_data )) {
$pust_data = [];
$pust_data [ 'code' ] = 302 ;
$pust_data [ 'msg' ] = '打赏礼物' ;
$pust_data [ 'data' ] = $room_push_data ;
model ( 'api/WebSocketPush' ) -> send_to_group ( $room_info [ 'rid' ], $pust_data );
}
$data = [];
$data [ 'integral' ] = db :: name ( 'user' ) -> where ( 'uid' , $uid ) -> value ( 'integral' );
$data [ 'integral' ] = ( int ) $data [ 'integral' ];
$data [ 'data' ] = $room_push_data ;
return [ 'code' => 200 , 'msg' => " 打赏成功 " , 'data' => $data ];
} catch ( \Exception $e ) {
dump ( $e );
//回滚事务
Db :: rollback ();
return [ 'code' => 201 , 'msg' => " 请重试5 " , 'data' => null ];
}
}
public function send_all_pack_gift ( $uid , $recived_uid , $rid , $help_uid )
{
if ( $uid == $recived_uid ) {
return [ 'code' => 201 , 'msg' => '背包礼物不能赠送给自己' , 'data' => null ];
}
$map = [];
$map [] = [ 'rid' , '=' , $rid ];
$map [] = [ 'is_delete' , '=' , 1 ];
$room_info = db :: name ( 'room' ) -> where ( $map ) -> find ();
if ( empty ( $room_info )) {
return [ 'code' => 201 , 'msg' => '所处房间不存在' , 'data' => null ];
}
$room_owner_info = db :: name ( 'user' ) -> where ( 'uid' , $room_info [ 'room_owner_uid' ]) -> find ();
$map = [];
$map [] = [ 'uid' , '=' , $recived_uid ];
$recived_user_info = db :: name ( 'user' ) -> field ( 'uid,is_tester,money,integral,nick_name,head_pic,base64_nick_name,europe_key,airship' ) -> where ( $map ) -> find ();
if ( empty ( $recived_user_info )) {
return [ 'code' => 201 , 'msg' => '打赏礼物对象不能为空' , 'data' => null ];
}
$user_info = db :: name ( 'user' ) -> where ( 'uid' , $uid ) -> find ();
if ( $user_info [ 'is_teenager' ] == 1 ){
return [ 'code' => 201 , 'msg' => '已开启青少年模式' , 'data' => null ];
}
$ress = model ( 'api/UserWallet' ) -> get_user_wallet ( $uid , $user_info [ 'money' ], $user_info [ 'integral' ]);
if ( $ress [ 'code' ] != 200 ) {
return $ress ;
}
//查找背包礼物列表
$map = [];
$map [] = [ 'uid' , '=' , $uid ];
$map [] = [ 'num' , '>' , 0 ];
$map [] = [ 'is_use_give' , '=' , 1 ];
$user_gift_pack_list = db :: name ( 'user_gift_pack' ) -> where ( $map ) -> select ();
if ( empty ( $user_gift_pack_list )) {
return [ 'code' => 201 , 'msg' => '背包暂无礼物' , 'data' => null ];
}
$user_gift_pack_data = [];
foreach ( $user_gift_pack_list as $k => $v ) {
$user_gift_pack_data [ $v [ 'gid' ]] = $v ;
}
$gid_list = array_column ( $user_gift_pack_list , 'gid' );
$map = [];
$map [] = [ 'gid' , 'in' , $gid_list ];
$gift_list = db :: name ( 'gift' ) -> where ( $map ) -> select ();
$gift_data = [];
foreach ( $gift_list as $k => & $v ) {
$v [ 'play_image' ] = localpath_to_netpath ( $v [ 'play_image' ]);
$v [ 'base_image' ] = localpath_to_netpath ( $v [ 'base_image' ]);
$gift_data [ $v [ 'gid' ]] = $v ;
}
if ( count ( $gift_data ) != count ( $user_gift_pack_list )) {
return [ 'code' => 201 , 'msg' => '礼物信息不存在' , 'data' => null ];
}
//该房间是否加入公会
$room_guild_id = model ( 'guild' ) -> user_guild_info ( $room_info [ 'room_owner_uid' ]);
$config = get_uncache_system_config ();
if ( $config [ 'gift_earnings_rate' ] > 1 ){
2025-11-07 17:24:56 +08:00
$config [ 'gift_earnings_rate' ] = $this -> user_rate ;
2025-08-08 14:45:40 +08:00
}
$now_time = time ();
//当前主持比例
$room_host_commission = 0 ;
if ( $room_info [ 'room_owner_uid' ] != $room_info [ 'room_host_uid' ] && ! empty ( $room_info [ 'room_host_uid' ])){
$room_host_info = db :: name ( 'room_host' ) -> where ( 'rid' , $rid ) -> where ( 'uid' , $room_info [ 'room_host_uid' ]) -> where ( 'is_delete' , 1 ) -> find ();
if ( ! empty ( $room_host_info )){
$room_host_commission = $room_host_info [ 'ratio' ];
}
}
Db :: startTrans ();
try {
if ( $user_info [ 'is_tester' ] == 1 ) { //测试用户只推送赠送礼物信息
$gift_total_price = 0 ;
foreach ( $user_gift_pack_list as $k => $v ) {
//扣除背包礼物
$reslut = model ( 'UserGiftPack' ) -> change_user_gift_pack ( $uid , $v [ 'gid' ], - $v [ 'num' ], 3 , '背包打赏礼物' );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
$gift_total_price += $v [ 'num' ] * $gift_data [ $v [ 'gid' ]][ 'gift_price' ];
}
if ( $uid != $recived_uid ){
$coupling_info = model ( 'Coupling' ) -> update_user_cp_value ( $uid , $recived_uid , $gift_total_price );
if ( $coupling_info [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $coupling_info [ 'msg' ], 'data' => null ];
}
}
//赠送礼物增加财富值 贡献值
$reslut = model ( 'User' ) -> change_user_contribution_value ( $uid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试1' , 'data' => null ];
}
//赠送者增加房间魅力值
$reslut = model ( 'User' ) -> change_user_room_contribution_value ( $uid , $rid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//增加房间热度值
db :: name ( 'room' ) -> where ( 'rid' , $rid ) -> inc ( 'hot_value' , $gift_total_price ) -> inc ( 'today_hot_value' , $gift_total_price ) -> update ();
$is_producer = 2 ;
$user_sign_contract = db :: name ( 'user_sign_contract' ) -> where ( 'sign_uid' , $recived_uid ) -> where ( 'is_delete' , 1 ) -> order ( 'id desc' ) -> find ();
if ( $user_sign_contract ){
$is_producer = 1 ;
}
//收礼物用户公会ID
$user_guild_id = model ( 'guild' ) -> user_guild_info ( $recived_uid );
//礼物列表
$gift_list_arr = [];
//抽中礼物总价值
$total_gift_total_price = 0 ;
foreach ( $user_gift_pack_list as $k => $v ) {
$this_gift_total_price = $v [ 'num' ] * $gift_data [ $v [ 'gid' ]][ 'gift_price' ];
$total_gift_total_price += $this_gift_total_price ;
//房主是否有收益
if ( $room_info [ 'is_earnings' ] == 1 ){
$this_room_owner_profits = $this_gift_total_price * $this -> room_owner_rate ; //房主厅主收益
$this_room_owner_profit = $this_room_owner_profits * ( 1 - $room_host_commission );
$this_room_host_profit = $this_room_owner_profits * $room_host_commission ;
} else {
$this_room_owner_profits = 0 ; //房主厅主收益
$this_room_owner_profit = 0 ;
$this_room_host_profit = 0 ;
}
//制作人收益
if ( $is_producer == 1 ){
$this_producer_profit = $this_gift_total_price * 0.05 ;
} else {
$this_producer_profit = 0 ;
}
// $this_receiver_profit = $this_gift_total_price * $config['gift_earnings_rate'];//接收人收益
// $this_receiver_profit = $this_gift_total_price * 0.6;//接收人收益
if ( ! empty ( $user_guild_id )){
2025-11-07 17:24:56 +08:00
$this_receiver_profit = $this_gift_total_price * $this -> user_rate ;
2025-08-08 14:45:40 +08:00
} else {
2025-11-07 17:24:56 +08:00
$this_receiver_profit = $this_gift_total_price * $this -> guild_user_rate ;
2025-08-08 14:45:40 +08:00
}
$this_platform_profit = $this_gift_total_price - $this_room_owner_profits - $this_receiver_profit - $this_producer_profit ; //平台收益
$data = [];
$data [ 'guild_id' ] = $user_guild_id ;
$data [ 'room_guild_id' ] = $room_guild_id ;
$data [ 'uid' ] = $uid ;
$data [ 'rid' ] = $rid ;
$data [ 'room_uid' ] = $room_info [ 'room_owner_uid' ];
$data [ 'room_host_uid' ] = $room_info [ 'room_host_uid' ];
$data [ 'receive_uid' ] = $recived_uid ;
$data [ 'gid' ] = $v [ 'gid' ];
$data [ 'gift_name' ] = $gift_data [ $v [ 'gid' ]][ 'gift_name' ];
$data [ 'gift_price' ] = $gift_data [ $v [ 'gid' ]][ 'gift_price' ];
$data [ 'gift_num' ] = $v [ 'num' ];
$data [ 'gift_total_price' ] = $this_gift_total_price ;
$data [ 'platform_profit' ] = $this_platform_profit ;
$data [ 'receiver_profit' ] = $this_receiver_profit ;
$data [ 'room_owner_profit' ] = $this_room_owner_profit ;
$data [ 'room_host_profit' ] = $this_room_host_profit ;
$data [ 'producer_profit' ] = $this_producer_profit ;
$data [ 'gift_from_type' ] = 2 ; //背包
$data [ 'is_tester' ] = $user_info [ 'is_tester' ];
$data [ 'add_time' ] = $now_time ;
$data [ 'update_time' ] = $now_time ;
$sid = db :: name ( 'user_send_gift' ) -> insertGetId ( $data );
if ( empty ( $sid )) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => " 请重试34 " , 'data' => null ];
}
//房间礼物墙
$reslut = model ( 'GiftWall' ) -> room_gift_wall ( $rid , $v [ 'gid' ], $v [ 'num' ], $this_gift_total_price );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试5' , 'data' => null ];
}
//送出礼物墙
// $reslut = model('GiftWall')->user_send_gift_wall($uid, $v['gid'], $v['num'], $recived_uid);
// if($reslut['code'] == 201){
// Db::rollback();
// return ['code' => 201, 'msg' => '请重试5', 'data' => null];
// }
//收到礼物墙
$reslut = model ( 'GiftWall' ) -> user_receive_gift_wall ( $recived_uid , $v [ 'gid' ], $v [ 'num' ], $uid );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试5' , 'data' => null ];
}
//异步通知---start
$gift_temp = [
'gift_name' => $gift_data [ $v [ 'gid' ]][ 'gift_name' ],
'gift_price' => $gift_data [ $v [ 'gid' ]][ 'gift_price' ],
'gift_num' => $v [ 'num' ],
];
$gift_list_arr [] = $gift_temp ;
//异步通知---end
//增加厅主收益记录
if ( $this_room_owner_profit > 0 ) {
$change_value = $this_room_owner_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_uid ( $room_info [ 'room_owner_uid' ], $change_value , 1 , 7 , " 打赏厅主流水收益 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
//收益记录
model ( 'Statistics' ) -> day_room_profit ( $room_info [ 'room_owner_uid' ], $rid , $change_value , 1 );
}
//增加主持收益记录
if ( $this_room_host_profit > 0 && $room_info [ 'room_host_uid' ] > 0 ) {
$change_value = $this_room_host_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_uid ( $room_info [ 'room_host_uid' ], $change_value , 1 , 28 , " 打赏主持流水收益 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
//收益记录
model ( 'Statistics' ) -> day_room_profit ( $room_info [ 'room_host_uid' ], $rid , $change_value , 2 );
}
//礼物接收者收益
if ( $this_receiver_profit > 0 ) {
$change_value = $this_receiver_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_user_info ( $recived_user_info , $change_value , 1 , 6 , " 礼物收入 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
}
//制作人收益
if ( $this_producer_profit > 0 ){
$change_value = $this_producer_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_uid ( $user_sign_contract [ 'uid' ], $change_value , 1 , 38 , " 打赏制作人流水收益 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
}
if ( $room_info [ 'cate_id' ] == 28 && $uid != $recived_uid && $uid != $room_info [ 'room_host_uid' ]){
$reslut = model ( 'AuctionRoom' ) -> record_user_auction_info ( $uid , $recived_uid , $rid , $v [ 'gid' ], $this_gift_total_price , $v [ 'num' ], $room_info [ 'room_host_uid' ]);
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试71' , 'data' => null ];
}
}
if ( $room_info [ 'cate_id' ] == 27 ){
$reslut = model ( 'KtvRoom' ) -> send_gift_add_song_time ( $uid , $recived_uid , $rid , $v [ 'gid' ], $v [ 'num' ], $this_gift_total_price );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试73' , 'data' => null ];
}
}
}
//收礼物增加魅力值
$reslut = model ( 'User' ) -> change_user_charm_value ( $recived_uid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//接受者增加房间魅力值
$reslut = model ( 'User' ) -> change_user_room_charm_value ( $recived_uid , $rid , $gift_total_price , $uid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//增加签约人的身价
$reslut = model ( 'Contract' ) -> receive_gift_rise_user_social ( $recived_uid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试72' , 'data' => null ];
}
//贡献值
model ( 'Statistics' ) -> day_contribution ( $uid , $rid , $total_gift_total_price , 1 );
//魅力
model ( 'Statistics' ) -> day_charm ( $recived_uid , $rid , $total_gift_total_price , 1 );
if ( $user_guild_id > 0 ) {
model ( 'Statistics' ) -> day_guild_charm ( $recived_uid , $rid , $user_guild_id , $total_gift_total_price , 1 );
}
if ( $room_guild_id > 0 ){
model ( 'Statistics' ) -> day_room_guild_charm ( $recived_uid , $rid , $room_guild_id , $total_gift_total_price , 1 );
}
//发送开始
// if($gift_list_arr) {
// $message_data = [
// 'from_uid' => $uid,
// 'to_uid' => $recived_uid,
// 'gift_list' => $gift_list_arr,
// 'rid' => $rid,
// ];
// model('api/AsyncPushMessage')->store_message($message_data, 3);
// }
//更新房间在线用户财富值
if ( in_array ( $room_info [ 'cate_id' ], [ 27 , 28 ])){
$reslut = model ( 'RoomBossMicro' ) -> update_room_visitor_value ( $uid , $rid , $gift_total_price );
if ( $reslut [ 'code' ] != 200 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试71' , 'data' => null ];
}
}
} elseif ( $user_info [ 'is_tester' ] == 2 ) {
return [ 'code' => 201 , 'msg' => '测试号无法赠送' , 'data' => null ];
//测试用户不处理
$gift_total_price = 0 ;
foreach ( $user_gift_pack_list as $k => $v ) {
//扣除背包礼物
$reslut = model ( 'UserGiftPack' ) -> change_user_gift_pack ( $uid , $v [ 'gid' ], - $v [ 'num' ], 3 , '背包打赏礼物' );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
$gift_total_price += $v [ 'num' ] * $gift_data [ $v [ 'gid' ]][ 'gift_price' ];
}
//赠送礼物增加财富值 贡献值
$reslut = model ( 'User' ) -> change_user_contribution_value ( $uid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试1' , 'data' => null ];
}
//赠送者增加房间魅力值
$reslut = model ( 'User' ) -> change_user_room_contribution_value ( $uid , $rid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//增加房间热度值
db :: name ( 'room' ) -> where ( 'rid' , $rid ) -> inc ( 'hot_value' , $gift_total_price ) -> inc ( 'today_hot_value' , $gift_total_price ) -> update ();
foreach ( $user_gift_pack_list as $k => $v ) {
$this_gift_total_price = $v [ 'num' ] * $gift_data [ $v [ 'gid' ]][ 'gift_price' ];
// $this_platform_profit = $this_gift_total_price * $config['send_gift_platform_commission']; //平台收益
// $this_room_owner_profit = $this_gift_total_price * $config['send_gift_room_owner_commission']; //房主厅主收益
// $this_receiver_profit = $this_gift_total_price - $this_platform_profit - $this_room_owner_profit; //接收人收益
// $this_room_owner_profits = $this_gift_total_price * $room_owner_info['room_owner_commission']; //房主厅主收益
$this_room_owner_profits = $this_gift_total_price * $this -> room_owner_rate ; //房主厅主收益
$this_room_owner_profit = $this_room_owner_profits * ( 1 - $room_host_commission );
$this_room_host_profit = $this_room_owner_profits * $room_host_commission ;
// $this_receiver_profit = $this_gift_total_price * $config['gift_earnings_rate'];//接收人收益
2025-11-07 17:24:56 +08:00
$this_receiver_profit = $this_gift_total_price * $this -> user_rate ; //接收人收益
2025-08-08 14:45:40 +08:00
$this_platform_profit = $this_gift_total_price - $this_room_owner_profits - $this_receiver_profit ; //平台收益
$data = [];
$data [ 'uid' ] = $uid ;
$data [ 'rid' ] = $rid ;
// $data['guild_id'] = $guild_id;
$data [ 'room_uid' ] = $room_info [ 'room_owner_uid' ];
$data [ 'room_host_uid' ] = $room_info [ 'room_host_uid' ];
$data [ 'receive_uid' ] = $recived_uid ;
$data [ 'gid' ] = $v [ 'gid' ];
$data [ 'gift_name' ] = $gift_data [ $v [ 'gid' ]][ 'gift_name' ];
$data [ 'gift_price' ] = $gift_data [ $v [ 'gid' ]][ 'gift_price' ];
$data [ 'gift_num' ] = $v [ 'num' ];
$data [ 'gift_total_price' ] = $this_gift_total_price ;
$data [ 'platform_profit' ] = $this_platform_profit ;
$data [ 'receiver_profit' ] = $this_receiver_profit ;
$data [ 'room_owner_profit' ] = $this_room_owner_profit ;
$data [ 'room_host_profit' ] = $this_room_host_profit ;
$data [ 'gift_from_type' ] = 2 ; //背包
$data [ 'is_tester' ] = $user_info [ 'is_tester' ];
$data [ 'add_time' ] = $now_time ;
$data [ 'update_time' ] = $now_time ;
$sid = db :: name ( 'user_send_gift' ) -> insertGetId ( $data );
if ( empty ( $sid )) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => " 请重试31 " , 'data' => null ];
}
}
//收礼物增加魅力值
$reslut = model ( 'User' ) -> change_user_charm_value ( $recived_uid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//接受者增加房间魅力值
$reslut = model ( 'User' ) -> change_user_room_charm_value ( $recived_uid , $rid , $gift_total_price , $uid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
}
if ( $user_info [ 'is_tester' ] == 1 && $gift_total_price > 0 && $room_info [ 'cate_id' ] == 29 ){
$reslut = model ( 'DatingRoom' ) -> user_send_gift_heartbeat_line ( $uid , $recived_uid , $rid , $gift_total_price , $help_uid );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试7' , 'data' => null ];
}
}
Db :: commit ();
model ( 'Room' ) -> push_room_micro_data ( $rid ); //推送最新房间麦位信息
//查询7号麦是否隐身
$room_xq1_activity = db :: name ( 'room_xq1' ) -> where ([ 'rid' => $rid , 'is_delete' => 1 ]) -> order ([ 'id' => 'desc' ]) -> find ();
$uid7 = 0 ;
if ( ! empty ( $room_xq1_activity )){
if ( $room_xq1_activity [ 'xq_uid_sm' ] == 2 ){ //神秘人
$uid7 = db :: name ( 'room_micro' ) -> where ([ 'rid' => $rid , 'micro_id' => 7 ]) -> value ( 'uid' );
}
}
//推送赠送礼物信息
$room_push_data = [];
$server_push_data = [];
// $user_list = [];
// $user_list[] = $recived_user_info;
// foreach ($user_list as $k => $v) {
foreach ( $user_gift_pack_list as $m => $n ) {
$ls_data = [];
$ls_data [ 'rid' ] = $rid ;
if ( $uid7 == $uid ){
$ls_data [ 'send_user_info' ][ 'uid' ] = 0 ;
$ls_data [ 'send_user_info' ][ 'nick_name' ] = " 神秘人 " ;
$ls_data [ 'send_user_info' ][ 'head_pic' ] = localpath_to_netpath ( $user_info [ 'head_pic' ]);
} else {
$ls_data [ 'send_user_info' ][ 'uid' ] = $uid ;
$ls_data [ 'send_user_info' ][ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $user_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
$ls_data [ 'send_user_info' ][ 'head_pic' ] = localpath_to_netpath ( $user_info [ 'head_pic' ]);
}
if ( $uid7 == $uid ){
$ls_data [ 'recived_user_info' ][ 'uid' ] = 0 ;
$ls_data [ 'recived_user_info' ][ 'nick_name' ] = " 神秘人 " ;
$ls_data [ 'recived_user_info' ][ 'head_pic' ] = localpath_to_netpath ( $recived_user_info [ 'head_pic' ]);
} else {
$ls_data [ 'recived_user_info' ][ 'uid' ] = $recived_user_info [ 'uid' ];
$ls_data [ 'recived_user_info' ][ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $recived_user_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
$ls_data [ 'recived_user_info' ][ 'head_pic' ] = localpath_to_netpath ( $recived_user_info [ 'head_pic' ]);
}
$ls_data [ 'gift_name' ] = $gift_data [ $n [ 'gid' ]][ 'gift_name' ];
$ls_data [ 'play_image' ] = $gift_data [ $n [ 'gid' ]][ 'play_image' ];
$ls_data [ 'base_image' ] = $gift_data [ $n [ 'gid' ]][ 'base_image' ];
$ls_data [ 'gift_type' ] = $gift_data [ $n [ 'gid' ]][ 'gift_type' ];
$ls_data [ 'gift_price' ] = $gift_data [ $n [ 'gid' ]][ 'gift_price' ];
$ls_data [ 'num' ] = $n [ 'num' ];
$ls_data [ 'is_public_screen' ] = $gift_data [ $n [ 'gid' ]][ 'is_public_screen' ];
$ls_data [ 'is_public_server' ] = $gift_data [ $n [ 'gid' ]][ 'is_public_server' ];
if ( $ls_data [ 'is_public_server' ] == 1 ) {
$server_push_data [] = $ls_data ;
}
$room_push_data [] = $ls_data ;
// else {
// $room_push_data[] = $ls_data;
// }
}
// }
if ( ! empty ( $server_push_data )) {
$pust_data = [];
$pust_data [ 'code' ] = 306 ;
$pust_data [ 'msg' ] = '打赏礼物' ;
$pust_data [ 'data' ] = $server_push_data ;
model ( 'api/WebSocketPush' ) -> send_to_all ( $pust_data );
}
if ( ! empty ( $room_push_data )) {
$pust_data = [];
$pust_data [ 'code' ] = 302 ;
$pust_data [ 'msg' ] = '打赏礼物' ;
$pust_data [ 'data' ] = $room_push_data ;
model ( 'api/WebSocketPush' ) -> send_to_group ( $room_info [ 'rid' ], $pust_data );
}
$data = [];
$data [ 'integral' ] = db :: name ( 'user' ) -> where ( 'uid' , $uid ) -> value ( 'integral' );
$data [ 'integral' ] = ( int ) $data [ 'integral' ];
$data [ 'data' ] = $room_push_data ;
return [ 'code' => 200 , 'msg' => " 打赏成功 " , 'data' => $data ];
} catch ( \Exception $e ) {
//回滚事务
Db :: rollback ();
return [ 'code' => 201 , 'msg' => " 请重试5 " , 'data' => null ];
}
}
//赠送礼物发送推送
//推送礼物信息
public function push_send_gift_data ( $send_user_info , $recived_user_list , $room_info , $gift_info , $num )
{
$data = [];
$data [ 'sender_nick_name' ] = $send_user_info [ 'nick_name' ];
$data [ 'recived_list' ] = [];
foreach ( $recived_user_list as $k => $v ) {
$ls_data = [];
$ls_data [ 'reciveder_nick_name' ] = $v [ 'nick_name' ];
$ls_data [ 'gift_name' ] = $gift_info [ 'gift_name' ];
$ls_data [ 'is_public_screen' ] = $gift_info [ 'is_public_screen' ];
$ls_data [ 'is_public_server' ] = $gift_info [ 'is_public_server' ];
$ls_data [ 'num' ] = $num ;
$data [ 'recived_list' ][] = $ls_data ;
}
//判断是否全服播报
if ( $gift_info [ 'is_public_server' ] == 1 ) {
$pust_data = [];
$pust_data [ 'code' ] = 306 ;
$pust_data [ 'msg' ] = '打赏礼物' ;
$pust_data [ 'data' ] = $data ;
model ( 'api/WebSocketPush' ) -> send_to_all ( $pust_data );
} else {
$pust_data = [];
$pust_data [ 'code' ] = 302 ;
$pust_data [ 'msg' ] = '打赏礼物' ;
$pust_data [ 'data' ] = $data ;
model ( 'api/WebSocketPush' ) -> send_to_group ( $room_info [ 'rid' ], $pust_data );
}
}
public function is_open_box ( $uid ){
$user_info = db :: name ( 'user' ) -> find ( $uid );
if ( ! $user_info ){
return [ 'code' => 201 , 'msg' => '该用户不存在' , 'data' => null ];
}
$map = [];
$map [] = [ 'uid' , '=' , $uid ];
$user_money_log = db :: name ( 'user_contribution_count_day' ) -> where ( $map ) -> sum ( 'amount' );
$config = model ( 'admin/Config' ) -> get_system_config ();
$open_box_integral = $config [ 'open_box_integral' ];
$room_info = [];
$room_info [ 'is_open_box' ] = 0 ;
if ( $user_info [ 'is_tester' ] == 1 ){
if ( $user_money_log >= $open_box_integral ){
$room_info [ 'is_open_box' ] = 1 ;
}
} else {
$room_info [ 'is_open_box' ] = 1 ;
}
return [ 'code' => 200 , 'msg' => '获取成功' , 'data' => $room_info ];
}
//盲盒礼物
public function open_blind_box ( $uid , $rid , $type , $open_num , $recived_uid , $help_uid )
{
if ( ceil ( $open_num ) != $open_num ) {
return [ 'code' => 201 , 'msg' => '开奖次数参数非法' , 'data' => null ];
}
$config = get_uncache_system_config ();
if ( $config [ 'gift_earnings_rate' ] > 1 ){
2025-11-07 17:24:56 +08:00
$config [ 'gift_earnings_rate' ] = $this -> user_rate ;
2025-08-08 14:45:40 +08:00
}
$map = [];
$map [ 'rid' ] = $rid ;
$map [ 'is_delete' ] = 1 ;
$room_info = db :: name ( 'room' ) -> where ( $map ) -> find ();
if ( empty ( $room_info )) {
return [ 'code' => 201 , 'msg' => '房间信息不存在' , 'data' => null ];
}
if ( count ( $recived_uid ) > 1 ){
return [ 'code' => 201 , 'msg' => '打赏礼物对象不能为多个' , 'data' => null ];
}
$recived_uid = $recived_uid [ 0 ];
$map = [];
$map [] = [ 'uid' , '=' , $recived_uid ];
$recived_user_info = db :: name ( 'user' ) -> field ( 'uid,is_tester,money,integral,europe_key,nick_name,base64_nick_name,head_pic,airship' ) -> where ( $map ) -> find ();
if ( empty ( $recived_user_info )) {
return [ 'code' => 201 , 'msg' => '打赏礼物对象不能为空' , 'data' => null ];
}
if ( $uid == $recived_uid ) {
return [ 'code' => 201 , 'msg' => '不能给自己打赏' , 'data' => null ];
}
// dump($recived_uid);exit;
$redis = connectionRedis ();
$user_gift_id_list = []; //用户抽中礼物id集合
$user_gift_id_redis_list = []; //用户抽中redis礼物id集合
$user_win_gift_data = []; //抽中礼物列表
$box_log_data = []; //抽中礼物期数数据
$box_type_data = []; //宝箱类型配置信息
$user_pay_amount = 0 ; //用户支付总额
$user_win_gift_total_value = 0 ; //抽中礼物总价值
$surplus_user_money = 0 ; //用户剩余资金
$now_time = time ();
$tid = '' ;
$user_info = db :: name ( 'user' ) -> find ( $uid ); //获取用户信息
if ( ! $user_info ){
return [ 'code' => 201 , 'msg' => '用户信息不存在' , 'data' => null ];
}
//是否有盲盒活动
$is_blind_box_active = 0 ; //是否有活动
$blind_term_id = 0 ; //活动期数
$blind_stage = 0 ; //
$pattern_id = 0 ; //模块id
$blind_gift_num = 0 ; //礼物数量
$new_stage_info = []; //阶段是否更新
$blind_lock_gid = 0 ; //当前阶段锁定礼物id
$blind_send_data = []; //送礼物记录
$blind_lock_gift_data = []; //抽中限定礼物数组
$now_multi = 0 ; //当前阶段倍数
$add_time_long = 0 ; //限定礼物增加时长
$stage_process_min_num = 0 ; //阶段进度条最小
$stage_process_max_num = 0 ; //阶段进度条最大
$blind_reward_gid = 0 ; //奖励礼物id
$blind_reward_gid_r = 0 ; //收礼物人奖励礼物id
$term_info = [];
//用户消费所对应的宝箱类型
if ( $type == 37 ) { //小糖果
$tid = 101 ;
} else if ( $type == 38 ) { //大糖果
$tid = 102 ;
$term_info_result = BlindBox :: get_blind_box_term ();
if ( $term_info_result [ 'code' ] == 200 ) {
if ( ! in_array ( $open_num , [ 1 , 10 ])) {
return [ 'code' => 201 , 'msg' => '盲盒巡乐会期间只能赠送1个或10个' , 'data' => null ];
}
$term_info = $term_info_result [ 'data' ];
$is_blind_box_active = 1 ;
$blind_term_id = $term_info [ 'term_id' ];
$blind_stage = $term_info [ 'stage' ];
$pattern_id = $term_info [ 'pattern_id' ];
$blind_gift_num = $term_info [ 'gift_num' ];
$blind_lock_gid = $term_info [ 'gid' ];
$add_time_long = $term_info [ 'time_long' ];
$stage_process_min_num = $term_info [ 'min_num' ];
$now_multi = $term_info [ 'now_multi' ];
$blind_reward_gid = $term_info [ 'reward_gid' ];
$blind_reward_gid_r = $term_info [ 'reward_gid_r' ];
if ( $blind_stage < 5 ) {
$stage_process_max_num = Db :: name ( 'blind_box_term_params' ) -> where ([ 'term_id' => $blind_term_id ])
-> where ( 'stage' , $blind_stage + 1 ) -> value ( 'num' );
} else {
$stage_process_max_num = $config [ 'blind_box_max_amount' ];
}
}
} else if ( $type == 39 ) { //大糖果
$tid = 103 ;
}
else {
return [ 'code' => 201 , 'msg' => '盲盒类型错误' , 'data' => null ];
}
//判断是否是虚拟用户
if ( $user_info [ 'is_tester' ] == 2 ){
return [ 'code' => 201 , 'msg' => '虚拟用户无法购买' , 'data' => null ];
}
// dump($tid);exit;
//该奖池是否配置礼物
$map = [];
$map [] = [ 'tid' , '=' , $tid ];
$is_box_config = db ( 'box_config' ) -> where ( $map ) -> select ();
if ( ! $is_box_config ){
return [ 'code' => 201 , 'msg' => '盲盒数量不足' , 'data' => null ];
}
//获取宝箱类型配置信息
$box_type_list = db :: name ( 'box_type' ) -> field ( 'tid,open_price,open_status,show_name' ) -> select ();
foreach ( $box_type_list as $k => & $v ) {
$box_type_data [ $v [ 'tid' ]] = $v ;
}
if ( empty ( $box_type_data [ $tid ])) {
return [ 'code' => 201 , 'msg' => '开奖类型非法参数' , 'data' => null ];
}
if ( $box_type_data [ $tid ][ 'open_status' ] != 1 ) {
return [ 'code' => 201 , 'msg' => '该开奖类型暂时已关闭' , 'data' => null ];
}
//盲盒信息
$box_type_info = $box_type_data [ $tid ];
//盲盒礼物
$blind_box_gift = Db :: name ( 'gift' ) -> find ( $type );
$user_pay_amount = $open_num * $box_type_data [ $tid ][ 'open_price' ];
$keyname = " box:list:tid: " . $tid ;
// $len = $redis->llen($keyname);
if ( $keyname == " box:list:tid: " ) {
return [ 'code' => 201 , 'msg' => '开奖类型非法参数' , 'data' => null ];
}
//扣款时进行用户资金是否充足判断
$user_auction_price = model ( 'NewRoom' ) -> get_user_auction_price ( $uid );
if ( $user_info [ 'integral' ] < ( $user_pay_amount + $user_auction_price )) {
return [ 'code' => 201 , 'msg' => '账户资金不足' , 'data' => null ];
}
//该房间是否加入公会
$room_guild_id = model ( 'guild' ) -> user_guild_info ( $room_info [ 'room_owner_uid' ]);
//当前主持比例
$room_host_commission = 0 ;
if ( $room_info [ 'room_owner_uid' ] != $room_info [ 'room_host_uid' ] && ! empty ( $room_info [ 'room_host_uid' ])){
$room_host_info = db :: name ( 'room_host' ) -> where ( 'rid' , $rid ) -> where ( 'uid' , $room_info [ 'room_host_uid' ]) -> where ( 'is_delete' , 1 ) -> find ();
if ( ! empty ( $room_host_info )){
$room_host_commission = $room_host_info [ 'ratio' ];
}
}
// 启动事务
Db :: startTrans ();
try {
//获取用户必中信息 (每次补发一个)
$map = [];
$map [] = [ 'uid' , '=' , $uid ];
$map [] = [ 'tid' , '=' , $tid ];
$map [] = [ 'give_status' , '=' , 1 ];
$box_give_gift_info = db :: name ( 'box_give_gift' ) -> where ( $map ) -> find ();
//插入用户必中
$need_open_num = $open_num ;
if ( ! empty ( $box_give_gift_info )) {
$data = [];
$data [ 'bl_id' ] = 0 ;
$data [ 'gid' ] = $box_give_gift_info [ 'gid' ];
$user_gift_id_list [] = $data ;
$need_open_num -- ; //待取礼物总数-1
}
//获取待核销必中礼物数据
$map = [];
$map [] = [ 'tid' , '=' , $tid ];
$map [] = [ 'give_status' , '=' , 2 ];
$map [] = [ 'deduction_status' , '=' , 1 ];
$box_un_deduction_give_gift_list = db :: name ( 'box_give_gift' ) -> where ( $map ) -> order ( 'id asc' ) -> column ( 'id' , 'gid' ); //每种礼物只核销第一个
//获取待开奖池礼物
for ( $i = 0 ; $i < $need_open_num ; $i ++ ) {
$gift_data = $redis -> blpop ( $keyname , 2 ); //1s 超时
if ( empty ( $gift_data )) {
return [ 'code' => 201 , 'msg' => '' , 'data' => null ];
} else {
//获取是否有待核销必中
$gift_data_data = explode ( '-' , $gift_data [ 1 ]);
$bl_id = $gift_data_data [ 0 ];
$gid = $gift_data_data [ 1 ];
if ( ! empty ( $box_un_deduction_give_gift_list [ $gid ])) {
$id = $box_un_deduction_give_gift_list [ $gid ];
unset ( $box_un_deduction_give_gift_list [ $gid ]);
$data = [];
$data [ 'bl_id' ] = $bl_id ;
$data [ 'gid' ] = $gid ;
$user_gift_id_redis_list [] = $data ;
//更新对应数据
//补偿表 更新
$map = [];
$map [] = [ 'id' , '=' , $id ];
$map [] = [ 'tid' , '=' , $tid ];
$map [] = [ 'gid' , '=' , $gid ];
$map [] = [ 'deduction_status' , '=' , 1 ];
$data = [];
$data [ 'deduction_bl_id' ] = $bl_id ;
$data [ 'deduction_status' ] = 2 ;
$data [ 'deduction_time' ] = time ();
$data [ 'update_time' ] = time ();
$reslut = db :: name ( 'box_give_gift' ) -> where ( $map ) -> order ( 'id asc' ) -> limit ( 1 ) -> update ( $data );
if ( ! $reslut ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
//开宝箱记录表更新
// $map = [];
// $map[] = ['tid', '=', $tid];
// $map[] = ['gid', '=', $gid];
// $map[] = ['num', '=', 1];
// $map[] = ['bl_id', '=', 0];
// $data = [];
// $data['bl_id'] = $bl_id;
// $data['update_time'] = time();
// $reslut = db::name('user_box_log')->where($map)->order('aid asc')->limit(1)->update($data);
// if (!$reslut) {
// Db::rollback();
// $this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
// return ['code' => 201, 'msg' => '请重试', 'data' => null];
// }
//重新从队列获取一个礼物信息
$gift_data = $redis -> blpop ( $keyname , 2 ); //1s 超时
if ( empty ( $gift_data )) {
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '盲盒数量不足' , 'data' => null ];
}
$gift_data_data = explode ( '-' , $gift_data [ 1 ]);
$bl_id = $gift_data_data [ 0 ];
$gid = $gift_data_data [ 1 ];
}
$data = [];
$data [ 'bl_id' ] = $bl_id ;
$data [ 'gid' ] = $gid ;
$user_gift_id_redis_list [] = $data ;
$user_gift_id_list [] = $data ;
}
}
if ( count ( $user_gift_id_list ) != $open_num ) {
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '盲盒数量不足' , 'data' => null ];
}
//取出所有礼物数据
$gift_list = db :: name ( 'gift' ) -> field ( 'gid,gift_name,gift_price,base_image,play_image,gift_type' ) -> select ();
$gift_list_data = [];
foreach ( $gift_list as $k => & $v ) {
$v [ 'base_image' ] = localpath_to_netpath ( $v [ 'base_image' ]);
$v [ 'play_image' ] = localpath_to_netpath ( $v [ 'play_image' ]);
$gift_list_data [ $v [ 'gid' ]] = $v ;
}
//获取宝箱礼物配置信息
$box_config_list = db :: name ( 'box_config' ) -> field ( 'gid,tid,is_public_screen,is_public_server' ) -> select ();
$box_config_list_data = [];
foreach ( $box_config_list as $k => $v ) {
$box_config_list_data [ $v [ 'gid' ]][ $v [ 'tid' ]] = $v ;
}
//整理用户抽中礼物数量
foreach ( $user_gift_id_list as $k => $v ) {
if ( empty ( $gift_list_data [ $v [ 'gid' ]])) {
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '礼物信息不存在' , 'data' => null ];
}
if ( empty ( $box_config_list_data [ $v [ 'gid' ]])) {
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '宝箱礼物信息不存在' , 'data' => null ];
}
if ( empty ( $user_win_gift_data [ $v [ 'gid' ]])) {
$user_win_gift_data [ $v [ 'gid' ]] = $gift_list_data [ $v [ 'gid' ]];
$user_win_gift_data [ $v [ 'gid' ]][ 'open_num' ] = 1 ;
} else {
$user_win_gift_data [ $v [ 'gid' ]][ 'open_num' ] ++ ;
}
$user_win_gift_data [ $v [ 'gid' ]][ 'bl_id' ] = $v [ 'bl_id' ];
$user_win_gift_data [ $v [ 'gid' ]][ 'is_public_screen' ] = $box_config_list_data [ $v [ 'gid' ]][ $tid ][ 'is_public_screen' ];
$user_win_gift_data [ $v [ 'gid' ]][ 'is_public_server' ] = $box_config_list_data [ $v [ 'gid' ]][ $tid ][ 'is_public_server' ];
if ( empty ( $box_log_data [ $v [ 'bl_id' ]])) {
$box_log_data [ $v [ 'bl_id' ]][ 'open_num' ] = 1 ;
$box_log_data [ $v [ 'bl_id' ]][ 'open_gift_value' ] = $gift_list_data [ $v [ 'gid' ]][ 'gift_price' ];
} else {
$box_log_data [ $v [ 'bl_id' ]][ 'open_num' ] ++ ;
$box_log_data [ $v [ 'bl_id' ]][ 'open_gift_value' ] += $gift_list_data [ $v [ 'gid' ]][ 'gift_price' ];
}
$user_win_gift_total_value += $gift_list_data [ $v [ 'gid' ]][ 'gift_price' ];
}
if ( $user_info [ 'is_tester' ] == 1 ){
//扣除账户积分
$reslut = model ( 'admin/User' ) -> change_user_money_by_user_info ( $user_info , - $user_pay_amount , 2 , 16 , " 开盲盒送礼物 " , $user_info [ 'uid' ], 0 );
if ( $reslut [ 'code' ] != 200 ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
$surplus_user_money = $user_info [ 'integral' ] - $user_pay_amount ;
}
foreach ( $box_log_data as $k => $v ) {
if ( $k != 0 ) {
$map = [];
$map [] = [ 'bl_id' , '=' , $k ];
$reslut = db :: name ( 'box_log' ) -> where ( $map ) -> inc ( 'open_num' , $v [ 'open_num' ]) -> inc ( 'open_gift_value' , $v [ 'open_gift_value' ]) -> update ();
if ( ! $reslut ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
}
}
//用户必中礼物状态更新
if ( ! empty ( $box_give_gift_info )) {
$map = [];
$map [] = [ 'id' , '=' , $box_give_gift_info [ 'id' ]];
$data = [];
$data [ 'give_time' ] = $now_time ;
$data [ 'give_status' ] = 2 ;
$data [ 'update_time' ] = $now_time ;
$reslut = db :: name ( 'box_give_gift' ) -> where ( $map ) -> update ( $data );
if ( ! $reslut ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
}
//添加用户开宝箱日志 可能存在2期奖情况 特殊处理
$user_box_data_by_bl_id = [];
foreach ( $user_gift_id_list as $k => $v ) {
if ( empty ( $user_box_data_by_bl_id [ $v [ 'bl_id' ]][ $v [ 'gid' ]])) {
$user_box_data_by_bl_id [ $v [ 'bl_id' ]][ $v [ 'gid' ]][ 'bl_id' ] = $v [ 'bl_id' ];
$user_box_data_by_bl_id [ $v [ 'bl_id' ]][ $v [ 'gid' ]][ 'gid' ] = $v [ 'gid' ];
$user_box_data_by_bl_id [ $v [ 'bl_id' ]][ $v [ 'gid' ]][ 'open_num' ] = 1 ;
} else {
$user_box_data_by_bl_id [ $v [ 'bl_id' ]][ $v [ 'gid' ]][ 'open_num' ] ++ ;
}
}
foreach ( $user_box_data_by_bl_id as $k => $v ) {
$insert_user_box_data = [];
foreach ( $v as $m => $n ) {
$gift_info = $gift_list_data [ $n [ 'gid' ]];
$data = [];
$data [ 'uid' ] = $user_info [ 'uid' ];
$data [ 'rid' ] = $rid ;
$data [ 'tid' ] = $tid ;
$data [ 'bl_id' ] = $n [ 'bl_id' ];
$data [ 'gid' ] = $n [ 'gid' ];
$data [ 'num' ] = $n [ 'open_num' ];
$data [ 'gift_price' ] = $gift_info [ 'gift_price' ];
$data [ 'total_price' ] = $n [ 'open_num' ] * $gift_info [ 'gift_price' ];
$data [ 'total_open_num' ] = $open_num ;
$data [ 'add_time' ] = $now_time ;
$data [ 'update_time' ] = $now_time ;
$insert_user_box_data [] = $data ;
}
$reslut = db :: name ( 'user_box_log' ) -> insertAll ( $insert_user_box_data );
if ( ! $reslut ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
}
//添加用户开宝箱统计数据
$time = strtotime ( date ( " Y-m-d " ));
$box_type = 0 ;
$map = [];
$map [] = [ 'uid' , '=' , $user_info [ 'uid' ]];
$map [] = [ 'box_type' , '=' , $tid ];
$box_type = $tid ;
$map [] = [ 'add_time' , '>' , $time ];
$user_box_count_info = db :: name ( 'user_box_count' ) -> where ( $map ) -> find ();
if ( ! empty ( $user_box_count_info )) {
$rate = 0 ; //支收比
$rate = round (( $user_win_gift_total_value + $user_box_count_info [ 'in_amount' ]) / ( $user_box_count_info [ 'out_amount' ] + $user_pay_amount ), 4 );
$map = [];
$map [] = [ 'sid' , '=' , $user_box_count_info [ 'sid' ]];
// $map[] = ['uid', '=', $user_info['uid']];
// $map[] = ['box_type', '=', $box_type];
$data = [];
$data [ 'rate' ] = $rate ;
$data [ 'update_time' ] = $now_time ;
$profit = $user_win_gift_total_value - $user_pay_amount ;
$reslut = db :: name ( 'user_box_count' ) -> where ( $map ) -> inc ( 'out_amount' , $user_pay_amount ) -> inc ( 'in_amount' , $user_win_gift_total_value ) -> inc ( 'profit' , $profit ) -> update ( $data );
if ( ! $reslut ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
} else {
$rate = round ( $user_win_gift_total_value / $user_pay_amount , 4 );
$profit = $user_win_gift_total_value - $user_pay_amount ;
$data = [];
$data [ 'uid' ] = $user_info [ 'uid' ];
$data [ 'out_amount' ] = $user_pay_amount ;
$data [ 'in_amount' ] = $user_win_gift_total_value ;
$data [ 'profit' ] = $profit ;
$data [ 'rate' ] = $rate ;
$data [ 'box_type' ] = $box_type ;
$data [ 'add_time' ] = $now_time ;
$data [ 'update_time' ] = $now_time ;
$reslut = db :: name ( 'user_box_count' ) -> insert ( $data );
if ( ! $reslut ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
}
//添加房间开宝箱统计数据
$time = strtotime ( date ( " Y-m-d " ));
$box_type = 0 ;
$map = [];
$map [] = [ 'rid' , '=' , $rid ];
$map [] = [ 'box_type' , '=' , $tid ];
$box_type = $tid ;
$map [] = [ 'add_time' , '>' , $time ];
$room_box_count_info = db :: name ( 'room_box_count' ) -> where ( $map ) -> find ();
if ( ! empty ( $room_box_count_info )) {
$rate = 0 ; //支收比
$rate = round (( $user_win_gift_total_value + $room_box_count_info [ 'in_amount' ]) / ( $room_box_count_info [ 'out_amount' ] + $user_pay_amount ), 4 );
$map = [];
$map [] = [ 'sid' , '=' , $room_box_count_info [ 'sid' ]];
// $map[] = ['uid', '=', $user_info['uid']];
// $map[] = ['box_type', '=', $box_type];
$data = [];
$data [ 'rate' ] = $rate ;
$data [ 'update_time' ] = $now_time ;
$profit = $user_win_gift_total_value - $user_pay_amount ;
$reslut = db :: name ( 'room_box_count' ) -> where ( $map ) -> inc ( 'out_amount' , $user_pay_amount ) -> inc ( 'in_amount' , $user_win_gift_total_value ) -> inc ( 'profit' , $profit ) -> update ( $data );
if ( ! $reslut ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
} else {
$rate = round ( $user_win_gift_total_value / $user_pay_amount , 4 );
$profit = $user_win_gift_total_value - $user_pay_amount ;
$data = [];
$data [ 'rid' ] = $rid ;
$data [ 'out_amount' ] = $user_pay_amount ;
$data [ 'in_amount' ] = $user_win_gift_total_value ;
$data [ 'profit' ] = $profit ;
$data [ 'rate' ] = $rate ;
$data [ 'box_type' ] = $box_type ;
$data [ 'add_time' ] = $now_time ;
$data [ 'update_time' ] = $now_time ;
$reslut = db :: name ( 'room_box_count' ) -> insert ( $data );
if ( ! $reslut ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
}
//礼物放入背包
$insert_user_gift_pack_log_data = [];
foreach ( $user_win_gift_data as $k => $v ) {
$map = [];
$map [] = [ 'uid' , '=' , $user_info [ 'uid' ]];
$map [] = [ 'gid' , '=' , $v [ 'gid' ]];
$data = [];
$data [ 'gid' ] = $v [ 'gid' ];
$data [ 'update_time' ] = $now_time ;
$reslut = db :: name ( 'user_gift_pack' ) -> where ( $map ) -> inc ( 'num' , $v [ 'open_num' ]) -> inc ( 'total_num' , $v [ 'open_num' ]) -> update ( $data );
if ( ! $reslut ) {
$data = [];
$data [ 'uid' ] = $user_info [ 'uid' ];
$data [ 'gid' ] = $v [ 'gid' ];
$data [ 'total_num' ] = $v [ 'open_num' ];
$data [ 'num' ] = $v [ 'open_num' ];
$data [ 'is_tester' ] = $user_info [ 'is_tester' ];
$data [ 'add_time' ] = $now_time ;
$data [ 'update_time' ] = $now_time ;
$reslut = db :: name ( 'user_gift_pack' ) -> insert ( $data );
if ( ! $reslut ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
}
$data = [];
$data [ 'uid' ] = $user_info [ 'uid' ];
$data [ 'type' ] = 2 ;
$data [ 'bl_id' ] = $v [ 'bl_id' ];
$data [ 'gid' ] = $v [ 'gid' ];
$data [ 'gift_price' ] = $gift_list_data [ $v [ 'gid' ]][ 'gift_price' ];
$data [ 'change_num' ] = $v [ 'open_num' ];
$data [ 'total_gift_price' ] = $gift_list_data [ $v [ 'gid' ]][ 'gift_price' ] * $v [ 'open_num' ];
$data [ 'after_num' ] = 0 ;
$data [ 'is_tester' ] = $user_info [ 'is_tester' ];
$data [ 'remarks' ] = " 开盲盒获得 " ;
$data [ 'add_time' ] = $now_time ;
$data [ 'update_time' ] = $now_time ;
$insert_user_gift_pack_log_data [] = $data ;
}
if ( ! empty ( $insert_user_gift_pack_log_data )) {
$reslut = db :: name ( 'user_gift_pack_log' ) -> insertAll ( $insert_user_gift_pack_log_data );
if ( ! $reslut ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试' , 'data' => null ];
}
}
// dump($user_win_gift_data);exit;
//礼物信息 $user_win_gift_data 扣除背包礼物
$gift_total_price = 0 ;
foreach ( $user_win_gift_data as $a => $b ){
//扣除背包礼物
$reslut = model ( 'UserGiftPack' ) -> change_user_gift_pack ( $uid , $b [ 'gid' ], - $b [ 'open_num' ], 3 , '开盲盒,背包打赏礼物' );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
$gift_total_price += $b [ 'open_num' ] * $b [ 'gift_price' ];
}
if ( $uid != $recived_uid ){
$coupling_info = model ( 'Coupling' ) -> update_user_cp_value ( $uid , $recived_uid , $gift_total_price );
if ( $coupling_info [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => $coupling_info [ 'msg' ], 'data' => null ];
}
}
//赠送礼物增加财富值 贡献值
$reslut = model ( 'User' ) -> change_user_contribution_value ( $uid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试1' , 'data' => null ];
}
//赠送者增加房间魅力值
$reslut = model ( 'User' ) -> change_user_room_contribution_value ( $uid , $rid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//增加房间热度值
db :: name ( 'room' ) -> where ( 'rid' , $rid ) -> inc ( 'hot_value' , $gift_total_price ) -> inc ( 'today_hot_value' , $gift_total_price ) -> update ();
$is_producer = 2 ;
$user_sign_contract = db :: name ( 'user_sign_contract' ) -> where ( 'sign_uid' , $recived_uid ) -> where ( 'is_delete' , 1 ) -> order ( 'id desc' ) -> find ();
if ( $user_sign_contract ){
$is_producer = 1 ;
}
//盲盒活动--检查是否进入下一阶段
if ( $is_blind_box_active == 1 ) {
$blind_total_num = $blind_gift_num + $open_num ;
$new_stage_info_result = model ( 'api/BlindBox' ) -> check_next_stage ( $blind_term_id , $blind_stage , $blind_total_num );
// dump($new_stage_info_result);
if ( $new_stage_info_result [ 'data' ]) {
$new_stage_info = $new_stage_info_result [ 'data' ];
$blind_lock_gid = $new_stage_info [ 'gid' ];
$add_time_long = $new_stage_info [ 'time_long' ];
$blind_stage = $new_stage_info [ 'stage' ];
$stage_process_min_num = $new_stage_info [ 'now_num' ];
$stage_process_max_num = $new_stage_info [ 'next_num' ];
$pattern_id = $new_stage_info [ 'pattern_id' ];
$now_multi = $new_stage_info [ 'now_multi' ];
$blind_reward_gid = $new_stage_info [ 'reward_gid' ];
$blind_reward_gid_r = $new_stage_info [ 'reward_gid_r' ];
$lock_gift_name = $new_stage_info [ 'lock_gift_name' ];
}
}
//收礼物的公会ID
$user_guild_id = model ( 'guild' ) -> user_guild_info ( $recived_uid );
//礼物记录
$gift_list_arr = [];
//抽中礼物总价值
$total_gift_total_price = 0 ;
//礼物收益记录
$room_owner_info = db :: name ( 'user' ) -> where ( 'uid' , $room_info [ 'room_owner_uid' ]) -> find ();
foreach ( $user_win_gift_data as $k => $v ) {
$this_gift_total_price = $v [ 'open_num' ] * $v [ 'gift_price' ];
$total_gift_total_price += $this_gift_total_price ;
// $this_room_owner_profits = $this_gift_total_price * $room_owner_info['room_owner_commission']; //房主厅主收益
//房间是否有收益
if ( $room_info [ 'is_earnings' ] == 1 ){
$this_room_owner_profits = $this_gift_total_price * $this -> room_owner_rate ; //房主厅主收益
$this_room_owner_profit = $this_room_owner_profits * ( 1 - $room_host_commission );
$this_room_host_profit = $this_room_owner_profits * $room_host_commission ;
} else {
$this_room_owner_profits = 0 ; //房主厅主收益
$this_room_owner_profit = 0 ;
$this_room_host_profit = 0 ;
}
//制作人收益
if ( $is_producer == 1 ){
$this_producer_profit = $this_gift_total_price * 0.05 ;
} else {
$this_producer_profit = 0 ;
}
// $this_receiver_profit = $this_gift_total_price * $config['gift_earnings_rate'];//接收人收益
// $this_receiver_profit = $this_gift_total_price * 0.6;//接收人收益
if ( ! empty ( $user_guild_id )){
2025-11-07 17:24:56 +08:00
$this_receiver_profit = $this_gift_total_price * $this -> user_rate ; //接收人收益
2025-08-08 14:45:40 +08:00
} else {
2025-11-07 17:24:56 +08:00
$this_receiver_profit = $this_gift_total_price * $this -> guild_user_rate ; //接收人收益
2025-08-08 14:45:40 +08:00
}
$this_platform_profit = $this_gift_total_price - $this_room_owner_profits - $this_receiver_profit - $this_producer_profit ; //平台收益
$data = [];
$data [ 'uid' ] = $uid ;
$data [ 'rid' ] = $rid ;
$data [ 'guild_id' ] = $user_guild_id ;
$data [ 'room_guild_id' ] = $room_guild_id ;
$data [ 'room_uid' ] = $room_info [ 'room_owner_uid' ];
$data [ 'room_host_uid' ] = $room_info [ 'room_host_uid' ];
$data [ 'receive_uid' ] = $recived_uid ;
$data [ 'gid' ] = $v [ 'gid' ];
$data [ 'gift_name' ] = $v [ 'gift_name' ];
$data [ 'gift_price' ] = $v [ 'gift_price' ];
$data [ 'gift_num' ] = $v [ 'open_num' ];
$data [ 'gift_total_price' ] = $this_gift_total_price ;
$data [ 'platform_profit' ] = $this_platform_profit ;
$data [ 'receiver_profit' ] = $this_receiver_profit ;
$data [ 'room_owner_profit' ] = $this_room_owner_profit ;
$data [ 'room_host_profit' ] = $this_room_host_profit ;
$data [ 'producer_profit' ] = $this_producer_profit ;
$data [ 'gift_from_type' ] = 2 ; //背包
$data [ 'is_tester' ] = $user_info [ 'is_tester' ];
// $data['gift_level_type'] = $level_type;
$data [ 'add_time' ] = $now_time ;
$data [ 'update_time' ] = $now_time ;
$sid = db :: name ( 'user_send_gift' ) -> insertGetId ( $data );
if ( empty ( $sid )) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => " 请重试32 " , 'data' => null ];
}
//盲盒活动记录
if ( $is_blind_box_active ) {
//送礼物日统计
$term_update = [ 'update_time' => time ()];
if ( $new_stage_info ) {
$term_update [ 'stage' ] = $blind_stage ;
$term_update [ 'pattern_id' ] = $pattern_id ;
}
model ( 'api/BlindBox' ) -> user_blind_box_count_day ( $uid , $v [ 'gid' ], $v [ 'open_num' ], $v [ 'gift_price' ], $this_gift_total_price );
$temp = [
'uid' => $uid ,
'receive_uid' => $recived_uid ,
'gid' => $v [ 'gid' ],
'tid' => $tid ,
'gift_price' => $v [ 'gift_price' ],
'gift_num' => $v [ 'open_num' ],
'total_gift_price' => $this_gift_total_price ,
'term_id' => $blind_term_id ,
'stage' => $blind_stage ,
'add_time' => time (),
'pattern_id' => $pattern_id ,
];
$blind_send_data [] = $temp ;
if ( $blind_lock_gid == $v [ 'gid' ]) {
$end_time = Db :: name ( 'blind_box_term' ) -> where ( 'id' , $blind_term_id )
-> value ( 'real_end_time' );
$max_time = time () + 1200 ;
$add_time_long = $add_time_long * $v [ 'open_num' ];
if ( $end_time >= $max_time ) {
$inc_time = 0 ;
} else {
if (( $end_time + $add_time_long ) >= $max_time ) {
$inc_time = $max_time - $end_time ;
} else {
$inc_time = $add_time_long ;
}
}
//更新时间
Db :: name ( 'blind_box_term' ) -> where ( 'id' , $blind_term_id )
-> inc ( 'real_end_time' , $inc_time )
-> inc ( 'gift_num' , $v [ 'open_num' ])
-> update ( $term_update );
$temp_lock = [
'uid' => $uid ,
'receive_uid' => $recived_uid ,
'gid' => $v [ 'gid' ],
'tid' => $tid ,
'gift_price' => $v [ 'gift_price' ],
'gift_num' => $v [ 'open_num' ],
'multi' => $now_multi ,
'term_id' => $blind_term_id ,
'stage' => $blind_stage ,
'add_time' => time (),
'time_long' => $add_time_long ,
'reward_gid' => $blind_reward_gid ,
'reward_gid_r' => $blind_reward_gid_r ,
];
$blind_lock_gift_data [] = $temp_lock ;
} else {
//更新时间
Db :: name ( 'blind_box_term' ) -> where ( 'id' , $blind_term_id )
-> inc ( 'gift_num' , $v [ 'open_num' ])
-> update ( $term_update );
}
}
//房间礼物墙
$reslut = model ( 'GiftWall' ) -> room_gift_wall ( $rid , $v [ 'gid' ], $v [ 'open_num' ], $this_gift_total_price );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试5' , 'data' => null ];
}
//送出礼物墙
// $reslut = model('GiftWall')->user_send_gift_wall($uid, $v['gid'], $v['open_num'], $recived_uid);
// if($reslut['code'] == 201){
// Db::rollback();
// return ['code' => 201, 'msg' => '请重试5', 'data' => null];
// }
//收到礼物墙
$reslut = model ( 'GiftWall' ) -> user_receive_gift_wall ( $recived_uid , $v [ 'gid' ], $v [ 'open_num' ], $uid );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试5' , 'data' => null ];
}
//礼物数据
$gift_temp = [
'gift_name' => $v [ 'gift_name' ],
'gift_price' => $v [ 'gift_price' ],
'gift_num' => $v [ 'open_num' ],
];
$gift_list_arr [] = $gift_temp ;
//增加厅主收益记录
if ( $this_room_owner_profit > 0 ) {
$change_value = $this_room_owner_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_uid ( $room_info [ 'room_owner_uid' ], $change_value , 1 , 7 , " 打赏厅主流水收益 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
//收益记录
model ( 'Statistics' ) -> day_room_profit ( $room_info [ 'room_owner_uid' ], $rid , $change_value , 1 );
}
//增加主持收益记录
if ( $this_room_host_profit > 0 && $room_info [ 'room_host_uid' ] > 0 ) {
$change_value = $this_room_host_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_uid ( $room_info [ 'room_host_uid' ], $change_value , 1 , 28 , " 打赏主持流水收益 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
//收益记录
model ( 'Statistics' ) -> day_room_profit ( $room_info [ 'room_host_uid' ], $rid , $change_value , 2 );
}
//礼物接收者收益
if ( $this_receiver_profit > 0 ) {
$change_value = $this_receiver_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_user_info ( $recived_user_info , $change_value , 1 , 6 , " 礼物收入 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
}
//制作人收益
if ( $this_producer_profit > 0 ){
$change_value = $this_producer_profit / $config [ 'exchange_rate' ];
$reslut = model ( 'admin/User' ) -> change_user_money_by_uid ( $user_sign_contract [ 'uid' ], $change_value , 1 , 38 , " 打赏制作人流水收益 " , $uid , $sid , $rid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => $reslut [ 'msg' ], 'data' => null ];
}
}
if ( $room_info [ 'cate_id' ] == 28 && $uid != $recived_uid && $uid != $room_info [ 'room_host_uid' ]){
$reslut = model ( 'AuctionRoom' ) -> record_user_auction_info ( $uid , $recived_uid , $rid , $v [ 'gid' ], $this_gift_total_price , $v [ 'open_num' ], $room_info [ 'room_host_uid' ]);
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试7' , 'data' => null ];
}
}
if ( $room_info [ 'cate_id' ] == 27 ){
$reslut = model ( 'KtvRoom' ) -> send_gift_add_song_time ( $uid , $recived_uid , $rid , $v [ 'gid' ], $v [ 'open_num' ], $this_gift_total_price );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试7' , 'data' => null ];
}
}
}
//盲盒活动
if ( $is_blind_box_active ) {
if ( $blind_send_data ) {
model ( 'api/BlindBox' ) -> user_blind_box_log ( $blind_send_data );
}
if ( $blind_lock_gift_data ) {
model ( 'api/BlindBox' ) -> user_blind_box_win ( $blind_lock_gift_data );
}
}
//贡献值
model ( 'Statistics' ) -> day_contribution ( $uid , $rid , $total_gift_total_price , 1 );
//魅力
model ( 'Statistics' ) -> day_charm ( $recived_uid , $rid , $total_gift_total_price , 1 );
if ( $user_guild_id > 0 ) {
model ( 'Statistics' ) -> day_guild_charm ( $recived_uid , $rid , $user_guild_id , $total_gift_total_price , 1 );
}
if ( $room_guild_id > 0 ) {
model ( 'Statistics' ) -> day_room_guild_charm ( $recived_uid , $rid , $room_guild_id , $total_gift_total_price , 1 );
}
//增加签约人的身价
$reslut = model ( 'Contract' ) -> receive_gift_rise_user_social ( $recived_uid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试7' , 'data' => null ];
}
//收礼物增加魅力值
$reslut = model ( 'User' ) -> change_user_charm_value ( $recived_uid , $gift_total_price );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//接受者增加房间魅力值
$reslut = model ( 'User' ) -> change_user_room_charm_value ( $recived_uid , $rid , $gift_total_price , $uid );
if ( $reslut [ 'code' ] == 201 ) {
Db :: rollback ();
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
return [ 'code' => 201 , 'msg' => '请重试4' , 'data' => null ];
}
//更新房间在线用户财富值
if ( in_array ( $room_info [ 'cate_id' ], [ 27 , 28 ])){
$reslut = model ( 'RoomBossMicro' ) -> update_room_visitor_value ( $uid , $rid , $gift_total_price );
if ( $reslut [ 'code' ] != 200 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试7' , 'data' => null ];
}
}
if ( $gift_total_price > 0 && $room_info [ 'cate_id' ] == 29 ){
$reslut = model ( 'DatingRoom' ) -> user_send_gift_heartbeat_line ( $uid , $recived_uid , $rid , $gift_total_price , $help_uid );
if ( $reslut [ 'code' ] == 201 ){
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '请重试7' , 'data' => null ];
}
}
//发消息
// if($gift_list_arr) {
// $message_data = [
// 'from_uid' => $uid,
// 'to_uid' => $recived_uid,
// 'gift_list' => $gift_list_arr,
// 'rid' => $rid,
// ];
// model('api/AsyncPushMessage')->store_message($message_data, 4);
// }
// 提交事务
Db :: commit ();
model ( 'Room' ) -> push_room_micro_data ( $rid ); //推送最新房间麦位信息
//推送赠送礼物信息
$room_push_data = [];
$server_push_data = [];
// $user_list = [];
// $user_list[] = $recived_user_info;
// foreach ($user_list as $k => $v) {
foreach ( $user_win_gift_data as $m => $n ) {
$ls_data = [];
$ls_data [ 'rid' ] = $rid ;
$ls_data [ 'send_user_info' ][ 'uid' ] = $uid ;
$ls_data [ 'send_user_info' ][ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $user_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
$ls_data [ 'send_user_info' ][ 'head_pic' ] = localpath_to_netpath ( $user_info [ 'head_pic' ]);
$ls_data [ 'recived_user_info' ][ 'uid' ] = $recived_user_info [ 'uid' ];
$ls_data [ 'recived_user_info' ][ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $recived_user_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
$ls_data [ 'recived_user_info' ][ 'head_pic' ] = localpath_to_netpath ( $recived_user_info [ 'head_pic' ]);
// $ls_data['gift_name'] = $n['gift_name'];
// $ls_data['play_image'] = $n['play_image'];
// $ls_data['base_image'] = $n['base_image'];
// $ls_data['gift_type'] = $n['gift_type'];
// $ls_data['num'] = $n['num'];
// $ls_data['is_public_screen'] = $n['is_public_screen'];
// $ls_data['is_public_server'] = $n['is_public_server'];
$ls_data [ 'gift_name' ] = $n [ 'gift_name' ];
$ls_data [ 'play_image' ] = $n [ 'play_image' ];
$ls_data [ 'gift_price' ] = $n [ 'gift_price' ];
$ls_data [ 'base_image' ] = $n [ 'base_image' ];
$ls_data [ 'gift_type' ] = $n [ 'gift_type' ];
$ls_data [ 'is_blind_gift' ] = 1 ;
$ls_data [ 'blind_box_name' ] = $box_type_info [ 'show_name' ];
$ls_data [ 'blind_box_image' ] = localpath_to_netpath ( $blind_box_gift [ 'base_image' ]);
$ls_data [ 'num' ] = $n [ 'open_num' ];
$ls_data [ 'is_public_screen' ] = $n [ 'is_public_screen' ];
$ls_data [ 'is_public_server' ] = $n [ 'is_public_server' ];
if ( $ls_data [ 'is_public_server' ] == 1 ) {
$server_push_data [] = $ls_data ;
}
$room_push_data [] = $ls_data ;
}
// }
if ( ! empty ( $server_push_data )) {
$pust_data = [];
$pust_data [ 'code' ] = 306 ;
$pust_data [ 'msg' ] = '打赏礼物' ;
// $pust_data['data']['room_info']['rid'] = $room_info['rid'];
// $pust_data['data']['room_info']['head_pic'] = localpath_to_netpath($user_info['head_pic']);
// $pust_data['data']['room_info']['room_name'] = mb_convert_encoding(base64_decode($room_info['base64_room_name']), 'UTF-8', 'UTF-8');
// $pust_data['data']['gift_list'] = $server_push_data;
// $pust_data['data']['rid'] = $room_info['rid'];
// $pust_data['data']['room_info']['head_pic'] = localpath_to_netpath($user_info['head_pic']);
// $pust_data['data']['room_info']['room_name'] = mb_convert_encoding(base64_decode($room_info['base64_room_name']), 'UTF-8', 'UTF-8');
// $pust_data['data']['gift_list'] = $server_push_data;
$pust_data [ 'data' ] = $server_push_data ;
model ( 'api/WebSocketPush' ) -> send_to_all ( $pust_data );
}
if ( ! empty ( $room_push_data )) {
$pust_data = [];
$pust_data [ 'code' ] = 302 ;
$pust_data [ 'msg' ] = '打赏礼物' ;
$pust_data [ 'data' ] = $room_push_data ;
model ( 'api/WebSocketPush' ) -> send_to_group ( $room_info [ 'rid' ], $pust_data );
}
//盲盒活动
if ( $is_blind_box_active == 1 ) {
//推送锁定礼物
$new_term_info = Db :: name ( 'blind_box_term' ) -> where ( 'id' , $blind_term_id ) -> find ();
if ( $blind_lock_gift_data ) {
$real_end_time = $new_term_info [ 'real_end_time' ];
$blind_count = count ( $blind_lock_gift_data );
$last_data = $blind_lock_gift_data [ $blind_count - 1 ];
$reward_gid = $last_data [ 'reward_gid' ];
$reward_gid_r = $last_data [ 'reward_gid_r' ];
$gift_arr = Db :: name ( 'gift' ) -> whereIn ( 'gid' , [ $reward_gid , $reward_gid_r ])
-> column ( 'base_image' , 'gid' );
$end_time = $real_end_time - time ();
if ( $end_time < 0 ) {
$end_time = 0 ;
}
$lock_user_info = [
'send_head_pic' => localpath_to_netpath ( $user_info [ 'head_pic' ]),
'send_uid' => $user_info [ 'uid' ],
'send_nick_name' => mb_convert_encoding ( base64_decode ( $user_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' ),
'receive_head_pic' => localpath_to_netpath ( $recived_user_info [ 'head_pic' ]),
'receive_uid' => $recived_user_info [ 'uid' ],
'receive_nick_name' => mb_convert_encoding ( base64_decode ( $recived_user_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' ),
'base_image' => isset ( $gift_arr [ $reward_gid ]) ? localpath_to_netpath ( $gift_arr [ $reward_gid ]) : '' ,
'receive_base_image' => isset ( $gift_arr [ $reward_gid_r ]) ? localpath_to_netpath ( $gift_arr [ $reward_gid_r ]) : '' ,
'multi' => $last_data [ 'multi' ],
'end_time' => $end_time
];
$push_data = [];
$push_data [ 'code' ] = 313 ;
$push_data [ 'msg' ] = '盲盒锁定礼物' ;
$push_data [ 'data' ] = $lock_user_info ;
model ( 'api/WebSocketPush' ) -> send_to_all ( $push_data );
}
//新阶段
if ( $new_stage_info ) {
$push_data = [];
$push_data [ 'code' ] = 314 ;
$push_data [ 'msg' ] = '新阶段' ;
$push_data [ 'data' ] = $new_stage_info ;
model ( 'api/WebSocketPush' ) -> send_to_all ( $push_data );
}
//推送进度条
$total_gift_num = $new_term_info [ 'gift_num' ];
$process_data = model ( 'api/BlindBox' ) -> stage_process_bar ( $blind_stage , $total_gift_num , $stage_process_min_num , $stage_process_max_num );
$push_data = [];
$push_data [ 'code' ] = 315 ;
$push_data [ 'msg' ] = '进度条推送' ;
$push_data [ 'data' ] = $process_data ;
model ( 'api/WebSocketPush' ) -> send_to_all ( $push_data );
}
$data = [];
$data [ 'integral' ] = db :: name ( 'user' ) -> where ( 'uid' , $uid ) -> value ( 'integral' );
$data [ 'integral' ] = ( int ) $data [ 'integral' ];
$data [ 'data' ] = $room_push_data ;
return [ 'code' => 200 , 'msg' => " 打赏成功 " , 'data' => $data ];
} catch ( \Exception $e ) {
// 回滚事务
dump ( $e -> getMessage ());
$this -> redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_redis_list );
Db :: rollback ();
return [ 'code' => 201 , 'msg' => '开启失败' , 'data' => null ];
}
}
//返还用户抽中礼物到奖池
private function redis_gift_data_rollback ( $redis , $keyname , $user_gift_id_list )
{
$insert_data = [];
foreach ( $user_gift_id_list as $k => $v ) {
$insert_data [] = $v [ 'bl_id' ] . '-' . $v [ 'gid' ];
}
if ( ! empty ( $insert_data )) {
array_unshift ( $insert_data , $keyname );
//右侧取 右侧插入
call_user_func_array ([ $redis , 'lPush' ], $insert_data );
}
return [ 'code' => 200 , 'msg' => '返还成功' , 'data' => null ];
}
//增加挂件记录
public function add_pendant_gift_log ( $uid , $recived_uid , $rid , $gid , $num , $gift_price ){
$now_time = time ();
$map = [];
$map [] = [ 'rid' , '=' , $rid ];
$map [] = [ 'end_time' , '>' , time ()];
$map [] = [ 'is_show' , '=' , 1 ];
$room_pendant_gift_log = db :: name ( 'room_pendant_gift_log' ) -> where ( $map ) -> order ( 'id desc' ) -> find ();
if ( ! empty ( $room_pendant_gift_log )){
if ( $gift_price >= $room_pendant_gift_log [ 'gift_price' ]){
$is_show = 1 ;
$end_time = $now_time + ( 60 * 60 * 24 );
} else {
$is_show = 2 ;
$end_time = 0 ;
}
} else {
$is_show = 1 ;
$end_time = $now_time + ( 60 * 60 * 24 );
}
$insert = [];
$insert [ 'rid' ] = $rid ;
$insert [ 'uid' ] = $uid ;
$insert [ 'receive_uid' ] = $recived_uid ;
$insert [ 'gid' ] = $gid ;
$insert [ 'num' ] = $num ;
$insert [ 'gift_price' ] = $gift_price ;
$insert [ 'total_gift_price' ] = $gift_price * $num ;
$insert [ 'add_time' ] = $now_time ;
$insert [ 'is_show' ] = $is_show ;
$insert [ 'end_time' ] = $end_time ;
$reslut = db :: name ( 'room_pendant_gift_log' ) -> insert ( $insert );
if ( $reslut ){
$data = [];
$data [ 'is_show' ] = $is_show ;
return [ 'code' => 200 , 'msg' => '成功' , 'data' => $data ];
} else {
return [ 'code' => 201 , 'msg' => '失败' , 'data' => null ];
}
}
// //周星礼物列表
// public function week_star_gift_list(){
// $map = [];
// $tag_name = '周星';
// $map[] = ['tag_name', 'like', '%'.$tag_name.'%'];
// $map[] = ['is_delete', '=', 1];
// $map[] = ['is_show', '=', 1];
// $gift_list = db::name('gift')->where($map)->field('gid,gift_name,gift_price,base_image,tag_name')->order('gift_price asc')->select();
// foreach ($gift_list as $k => &$v){
// $v['base_image'] = localpath_to_netpath($v['base_image']);
// }
// return ['code' => 200, 'msg' => '成功', 'data' => $gift_list];
// }
//周星礼物列表
public function week_star_gift_list (){
$map = [];
$tag_name = '周星' ;
$map [] = [ 'tag_name' , '=' , $tag_name ];
$map [] = [ 'is_delete' , '=' , 1 ];
$map [] = [ 'is_show' , '=' , 1 ];
$gift_list = db :: name ( 'gift' ) -> where ( $map ) -> field ( 'gid,gift_name,gift_price,base_image,tag_name' ) -> order ( 'gift_price asc' ) -> select ();
foreach ( $gift_list as $k => & $v ){
$v [ 'base_image' ] = localpath_to_netpath ( $v [ 'base_image' ]);
}
return [ 'code' => 200 , 'msg' => '成功' , 'data' => $gift_list ];
}
//周星榜
public function now_week_rank ( $gid , $uid ){
$page = 1 ;
$page_limit = 20 ;
$gift_info = db :: name ( 'gift' ) -> find ( $gid );
if ( ! $gift_info ){
return [ 'code' => 201 , 'msg' => '礼物不存在' , 'data' => null ];
}
$group = '' ;
$map = [];
// $tag_name = '周星';
// $map[] = ['b.tag_name', '=', $tag_name];
$map [] = [ 'a.gid' , '=' , $gid ];
$time_where = " week " ;
//本周收到的礼物排行
$uids_arr = [];
$list1 = db :: name ( 'user_send_gift' ) -> alias ( 'a' ) -> where ( $map ) -> whereTime ( 'a.add_time' , $time_where ) -> field ( 'a.uid,a.receive_uid,sum(a.gift_num) as total_gift_num' ) -> group ( " a.receive_uid " ) -> order ( 'total_gift_num desc' ) -> cache ( 20 ) -> page ( $page , $page_limit ) -> select ();
$all_receive_uids = [];
if ( ! empty ( $list1 )){
$all_receive_uids = array_column ( $list1 , 'receive_uid' );
$uids_arr = array_merge ( array_column ( $list1 , 'uid' ), array_column ( $list1 , 'receive_uid' ));
}
$end_user_data = end ( $list1 );
$is_top_rank = 2 ;
$diff_num = 0 ;
$my_user_info = db :: name ( 'user' ) -> where ( 'uid' , $uid ) -> field ( 'uid,base64_nick_name as nick_name,head_pic' ) -> find ();
$my_user_info [ 'head_pic' ] = localpath_to_netpath ( $my_user_info [ 'head_pic' ]);
$my_user_info [ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $my_user_info [ 'nick_name' ]), 'UTF-8' , 'UTF-8' );
if ( ! empty ( $list1 )){
$num_rank = array_search ( $uid , $all_receive_uids );
if ( $num_rank !== false ){
$is_top_rank = 1 ;
} else {
$had_num = db :: name ( 'user_send_gift' ) -> alias ( 'a' ) -> where ( 'receive_uid' , $uid ) -> where ( $map ) -> whereTime ( 'a.add_time' , $time_where ) -> sum ( 'a.gift_num' );
$diff_num = $end_user_data [ 'total_gift_num' ] - $had_num ;
}
}
$my_user_info [ 'is_top_rank' ] = $is_top_rank ;
$my_user_info [ 'diff_num' ] = $diff_num ;
//本周
$list2 = db :: name ( 'user_send_gift' ) -> alias ( 'a' ) -> where ( $map ) -> whereTime ( 'a.add_time' , $time_where ) -> field ( 'a.uid,a.receive_uid,sum(a.gift_num) as total_gift_num' ) -> group ( " a.uid " ) -> order ( 'total_gift_num desc' ) -> cache ( 20 ) -> page ( $page , $page_limit ) -> select ();
if ( ! empty ( $list2 )){
$uids_arr = array_merge ( array_column ( $list2 , 'uid' ), $uids_arr );
$uids_arr = array_merge ( array_column ( $list2 , 'receive_uid' ), $uids_arr );
}
//获取排行榜用户基本信息
$map = [];
$map [] = [ 'uid' , 'in' , $uids_arr ];
$user_list = db :: name ( 'user' ) -> field ( 'uid,base64_nick_name,head_pic' ) -> cache ( 60 ) -> where ( $map ) -> select ();
$user_list_data = [];
foreach ( $user_list as $k => & $v ) {
$v [ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $v [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
$v [ 'head_pic' ] = localpath_to_netpath ( $v [ 'head_pic' ]);
$user_list_data [ $v [ 'uid' ]] = $v ;
}
foreach ( $list1 as $m => $n ) {
$ls_data = $user_list_data [ $n [ 'receive_uid' ]];
$ls_data [ 'total_gift_num' ] = $n [ 'total_gift_num' ];
$list1 [ $m ] = $ls_data ;
}
foreach ( $list2 as $m1 => $n1 ){
$ls_data = $user_list_data [ $n1 [ 'uid' ]];
$ls_data [ 'total_gift_num' ] = $n1 [ 'total_gift_num' ];
$list2 [ $m1 ] = $ls_data ;
}
foreach ( $list1 as $k =>& $v ){
unset ( $v [ 'base64_nick_name' ]);
$v [ 'gift_name' ] = $gift_info [ 'gift_name' ];
if ( ! empty ( $list2 [ $k ])){
$v [ 'give_uid' ] = $list2 [ $k ][ 'uid' ];
$v [ 'give_head_pic' ] = $list2 [ $k ][ 'head_pic' ];
$v [ 'give_nick_name' ] = $list2 [ $k ][ 'nick_name' ];
$v [ 'give_total_gift_num' ] = $list2 [ $k ][ 'total_gift_num' ];
} else {
$v [ 'give_uid' ] = " " ;
$v [ 'give_head_pic' ] = " " ;
$v [ 'give_nick_name' ] = " " ;
$v [ 'give_total_gift_num' ] = " " ;
}
}
return [ 'code' => 200 , 'msg' => '获取成功' , 'data' => [ 'list' => $list1 , 'my_user_info' => $my_user_info ]];
}
//周星榜
public function last_week_rank (){
$map = [];
$tag_name = '周星' ;
$map [] = [ 'tag_name' , '=' , $tag_name ];
$map [] = [ 'is_delete' , '=' , 1 ];
$map [] = [ 'is_show' , '=' , 1 ];
$gift_list = db :: name ( 'gift' ) -> where ( $map ) -> field ( 'gid,gift_name,gift_price,base_image,tag_name' ) -> order ( 'gift_price asc' ) -> select ();
$gids_arr = [];
foreach ( $gift_list as $k => & $v ){
$v [ 'base_image' ] = localpath_to_netpath ( $v [ 'base_image' ]);
$gift_list [ $v [ 'gid' ]] = $v ;
$gids_arr [] = $v [ 'gid' ];
}
if ( ! empty ( $gids_arr )){
$num_limit = count ( $gids_arr );
//获取最大数量的人
$list1 = db :: name ( 'user_send_gift' )
-> alias ( 'a' ) -> where ( 'gid' , 'in' , $gids_arr )
-> whereTime ( 'a.add_time' , 'last week' )
-> field ( 'a.receive_uid,sum(a.gift_num) as total_gift_num,a.gid' )
-> group ( " a.gid,a.receive_uid " )
-> order ( 'total_gift_num desc' )
-> limit ( 0 , $num_limit )
-> cache ( 20 )
-> select ();
foreach ( $list1 as & $v ){
$v [ 'gift_name' ] = $gift_list [ $v [ 'gid' ]][ 'gift_name' ];
$v [ 'base_image' ] = $gift_list [ $v [ 'gid' ]][ 'base_image' ];
$user_info = db :: name ( 'user' ) -> where ( 'uid' , $v [ 'receive_uid' ]) -> field ( 'base64_nick_name as nick_name,head_pic' ) -> find ();
$v [ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $user_info [ 'nick_name' ]), 'UTF-8' , 'UTF-8' );
$v [ 'head_pic' ] = localpath_to_netpath ( $user_info [ 'head_pic' ]);
}
} else {
$list1 = [];
}
return [ 'code' => 200 , 'msg' => '获取成功' , 'data' => $list1 ];
}
//周星榜
public function last_week_rank1 (){
$map = [];
$tag_name = '周星' ;
$map [] = [ 'tag_name' , '=' , $tag_name ];
$map [] = [ 'is_delete' , '=' , 1 ];
$map [] = [ 'is_show' , '=' , 1 ];
$gift_list = db :: name ( 'gift' ) -> where ( $map ) -> field ( 'gid,gift_name,gift_price,base_image,tag_name' ) -> order ( 'gift_price asc' ) -> select ();
$gids_arr = [];
foreach ( $gift_list as $k => & $v ){
$v [ 'base_image' ] = localpath_to_netpath ( $v [ 'base_image' ]);
$gift_list [ $v [ 'gid' ]] = $v ;
$gids_arr [] = $v [ 'gid' ];
}
$gids_arr = array_unique ( $gids_arr );
if ( ! empty ( $gids_arr )){
// $num_limit = count($gids_arr);
//获取最大数量的人
// $list1 = db::name('user_send_gift')
// ->alias('a')->where('gid','in',$gids_arr)
// ->whereTime('a.add_time', 'last week')
// ->field('a.receive_uid,sum(a.gift_num) as total_gift_num,a.gid')
// ->group("a.gid,a.receive_uid")
// ->order('total_gift_num desc')
// ->limit(0,$num_limit)
// ->cache(20)
// ->select();
//上周数据储储存
$week_start = date ( 'Y-m-d' , strtotime ( " last week Monday " ));
$week_end = date ( 'Y-m-d' , strtotime ( " last week Sunday " ));
$belong_week = $week_start . '-' . $week_end ;
$zhou_xing_gifts = Cache :: get ( " zhou_xing_gifts_ { $belong_week } " );
if ( empty ( $zhou_xing_gifts )){
//查询最大值
$list1 = [];
foreach ( $gids_arr as $gid ){
$data = db :: name ( 'user_send_gift' )
-> alias ( 'a' )
-> where ( 'gid' , '=' , $gid )
-> whereTime ( 'a.add_time' , 'last week' )
-> field ( 'a.receive_uid,sum(a.gift_num) as total_gift_num,a.gid' )
-> group ( " a.receive_uid " )
-> order ( 'a.gid,total_gift_num desc,a.receive_uid desc' )
-> find ();
$list1 [] = $data ;
}
Cache :: set ( " zhou_xing_gifts_ { $belong_week } " , $list1 );
$zhou_xing_gifts = Cache :: get ( " zhou_xing_gifts_ { $belong_week } " );
}
$list1 = $zhou_xing_gifts ;
// dump($list1);exit;
if ( empty ( $list1 [ 0 ])){
$list1 = [];
} else {
$list1 = array_filter ( $list1 );
foreach ( $list1 as & $v ){
if ( ! empty ( $v )){
// $v['gift_name'] = $gift_list[$v['gid']]['gift_name'];
// $v['base_image'] = $gift_list[$v['gid']]['base_image'];
$gift_info = db :: name ( 'gift' ) -> where ([ 'gid' => $v [ 'gid' ]]) -> field ( 'gift_name,base_image' ) -> find ();
$v [ 'gift_name' ] = $gift_info [ 'gift_name' ];
$v [ 'base_image' ] = localpath_to_netpath ( $gift_info [ 'base_image' ]);
$user_info = db :: name ( 'user' ) -> where ( 'uid' , $v [ 'receive_uid' ]) -> field ( 'base64_nick_name as nick_name,head_pic' ) -> find ();
$v [ 'nick_name' ] = mb_convert_encoding ( base64_decode ( $user_info [ 'nick_name' ]), 'UTF-8' , 'UTF-8' );
$v [ 'head_pic' ] = localpath_to_netpath ( $user_info [ 'head_pic' ]);
}
}
}
} else {
$list1 = [];
}
return [ 'code' => 200 , 'msg' => '获取成功' , 'data' => $list1 ];
}
//获取本周周星榜前4
public function now_week_rank_four (){
$zhou_xing_now_week_rank_four = Cache :: get ( " zhou_xing_now_week_rank_four " );
if ( empty ( $zhou_xing_now_week_rank_four )){
$map = [];
$tag_name = '周星' ;
$map [] = [ 'tag_name' , '=' , $tag_name ];
$map [] = [ 'is_delete' , '=' , 1 ];
$map [] = [ 'is_show' , '=' , 1 ];
$gids_arr = db :: name ( 'gift' )
-> where ( $map )
-> column ( 'gid' );
//本周收到的礼物排行
$list1 = db :: name ( 'user_send_gift' ) -> alias ( 'a' ) -> where ( 'a.gid' , 'in' , $gids_arr ) -> whereTime ( 'a.add_time' , " week " ) -> field ( 'a.uid,a.receive_uid,sum(a.gift_num) as total_gift_num,a.gid,a.gift_price,a.gift_name' ) -> group ( " a.gid,a.receive_uid " ) -> order ( 'total_gift_num desc' ) -> buildSql ();
$list1 = db :: table ( $list1 . " b " ) -> group ( 'b.gid' ) -> order ( 'b.gift_price asc' ) -> select ();
if ( ! empty ( $list1 )){
foreach ( $list1 as & $v ){
$head_pic = db :: name ( 'user' ) -> where ([ 'uid' => $v [ 'receive_uid' ]]) -> value ( 'head_pic' );
$head_pic = localpath_to_netpath ( $head_pic );
$v [ 'head_pic' ] = $head_pic ;
}
}
Cache :: set ( " zhou_xing_now_week_rank_four " , $list1 , 60 );
$zhou_xing_now_week_rank_four = Cache :: get ( " zhou_xing_now_week_rank_four " );
}
return [ 'code' => 200 , 'msg' => '获取成功' , 'data' => $zhou_xing_now_week_rank_four ];
}
public function top_cp (){
$cp_info = db :: name ( 'user_coupling' ) -> where ([ 'is_delete' => 1 ]) -> order ( 'cp_value' , 'desc' ) -> find ();
if ( ! empty ( $cp_info )){
$user_info = db :: name ( 'user' ) -> where ([ 'uid' => $cp_info [ 'uid' ]]) -> field ( 'base64_nick_name,head_pic' ) -> find ();
$cp_info [ 'u_nick_name' ] = mb_convert_encoding ( base64_decode ( $user_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
$cp_info [ 'u_head_pic' ] = localpath_to_netpath ( $user_info [ 'head_pic' ]);
$receive_info = db :: name ( 'user' ) -> where ([ 'uid' => $cp_info [ 'receive_uid' ]]) -> field ( 'base64_nick_name,head_pic' ) -> find ();
$cp_info [ 'receive_nick_name' ] = localpath_to_netpath ( $receive_info [ 'base64_nick_name' ]);
$cp_info [ 'receive_head_pic' ] = localpath_to_netpath ( $receive_info [ 'head_pic' ]);
}
return [ 'code' => 200 , 'msg' => '获取成功' , 'data' => $cp_info ];
}
//cp等级情况
public function my_cp ( $uid ){
$cp_info = db :: name ( 'user_coupling' ) -> where ([ 'receive_uid|uid' => $uid ]) -> where ([ 'is_delete' => 1 ]) -> order ( 'cp_value' , 'desc' ) -> find ();
if ( empty ( $cp_info )){
return [ 'code' => 201 , 'msg' => '您不存在CP关系' , 'data' => null ];
}
if ( ! empty ( $cp_info )){
//获取两个头像框
$map = [];
$map [] = [ 'a.uid' , 'in' , [ $cp_info [ 'uid' ], $cp_info [ 'receive_uid' ]]];
$map [] = [ 'a.is_using' , '=' , 1 ];
$map [] = [ 'a.end_time' , '>' , time ()];
$map [] = [ 'a.type' , '=' , 1 ];
$map [] = [ 'b.show_status' , '=' , 1 ];
$map [] = [ 'b.is_delete' , '=' , 1 ];
$model = Db :: name ( 'user_decorate' ) -> alias ( 'a' ) -> join ( 'yy_decorate b' , 'a.did = b.did' );
$user_decorate_list = $model -> field ( 'b.base_image,b.play_image,b.title,a.uid' ) -> where ( $map ) -> select ();
$user_decorate_list_data = [];
foreach ( $user_decorate_list as $k => $v ) {
$user_decorate_list_data [ $v [ 'uid' ]] = $v ;
}
$user_info = db :: name ( 'user' ) -> where ([ 'uid' => $cp_info [ 'uid' ]]) -> field ( 'base64_nick_name,head_pic' ) -> find ();
$cp_info [ 'u_nick_name' ] = mb_convert_encoding ( base64_decode ( $user_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
$cp_info [ 'u_head_pic' ] = localpath_to_netpath ( $user_info [ 'head_pic' ]);
$cp_info [ 'u_avatar_play_image' ] = " " ;
if ( ! empty ( $user_decorate_list_data [ $cp_info [ 'uid' ]][ 'play_image' ])){
$cp_info [ 'u_avatar_play_image' ] = localpath_to_netpath ( $user_decorate_list_data [ $cp_info [ 'uid' ]][ 'play_image' ]);
}
$receive_info = db :: name ( 'user' ) -> where ([ 'uid' => $cp_info [ 'receive_uid' ]]) -> field ( 'base64_nick_name,head_pic' ) -> find ();
$cp_info [ 'receive_nick_name' ] = mb_convert_encoding ( base64_decode ( $receive_info [ 'base64_nick_name' ]), 'UTF-8' , 'UTF-8' );
$cp_info [ 'receive_head_pic' ] = localpath_to_netpath ( $receive_info [ 'head_pic' ]);
$cp_info [ 'receive_avatar_play_image' ] = " " ;
if ( ! empty ( $user_decorate_list_data [ $cp_info [ 'receive_uid' ]][ 'play_image' ])){
$cp_info [ 'receive_avatar_play_image' ] = localpath_to_netpath ( $user_decorate_list_data [ $cp_info [ 'receive_uid' ]][ 'play_image' ]);
}
//获取下一等级
$next_cp_value = db :: name ( 'cp_privilege' ) -> where ([[ 'level' , '>' , $cp_info [ 'cp_level' ]]]) -> order ( 'level' , 'asc' ) -> find ();
$next_cp_level = $next_cp_value [ 'level' ];
if ( empty ( $next_cp_level )){
$next_cp_level = $cp_info [ 'cp_level' ];
}
$cp_info [ 'next_cp_level' ] = $next_cp_level ;
$cp_info [ 'next_cp_value' ] = db :: name ( 'cp_privilege' ) -> where ([[ 'level' , '<=' , $next_cp_level ]]) -> sum ( " number " );
}
return [ 'code' => 200 , 'msg' => '获取成功' , 'data' => $cp_info ];
}
public function my_cp_txk ( $uid , $type = 1 ){
$cp_info = db :: name ( 'user_coupling' ) -> where ([ 'receive_uid|uid' => $uid ]) -> where ([ 'is_delete' => 1 ]) -> order ( 'cp_value' , 'desc' ) -> find ();
// if(empty($cp_info)){
// return ['code' => 201, 'msg' => '您不存在CP关系', 'data' =>null];
// }
$where = [];
$where [] = [ " cpr.is_delete " , '=' , 1 ];
if ( $type == 1 ){
$where [] = [ " cpr.head_decorate_id " , '<>' , 0 ];
} elseif ( $type == 9 ){
$where [] = [ " cpr.cp_tx_id " , '<>' , 0 ];
} else {
return [ 'code' => 201 , 'msg' => '装扮类型有误!' , 'data' => null ];
}
if ( ! empty ( $cp_info )){
$now_level = $cp_info [ 'cp_level' ];
} else {
$now_level = - 1 ;
}
$cp_txks = db :: name ( " cp_privilege " )
-> alias ( 'cpr' )
-> join ( 'yy_decorate d' , 'd.did = cpr.head_decorate_id and d.is_delete=1' , 'left' )
-> join ( 'yy_decorate d2' , 'd2.did = cpr.cp_tx_id and d2.is_delete=1' , 'left' )
-> field ( 'level,head_decorate_id,d.base_image as head_decorate_img,d.play_image as head_decorate_play_img,d.title as head_decorate_title,cp_tx_id,d2.base_image as cp_tx_img,d2.play_image as cp_tx_play_img,d2.title as cp_tx_title' )
-> where ( $where )
-> order ( 'cpr.level' , 'asc' )
-> select ();
foreach ( $cp_txks as & $v ){
$v [ 'js_suo' ] = 2 ;
$v [ 'head_decorate_img' ] = localpath_to_netpath ( $v [ 'head_decorate_img' ]);
$v [ 'head_decorate_play_img' ] = localpath_to_netpath ( $v [ 'head_decorate_play_img' ]);
$v [ 'cp_tx_img' ] = localpath_to_netpath ( $v [ 'cp_tx_img' ]);
$v [ 'cp_tx_play_img' ] = localpath_to_netpath ( $v [ 'cp_tx_play_img' ]);
$v [ 'is_using' ] = 2 ;
$v [ 'udid' ] = 0 ;
if ( $v [ 'level' ] <= $now_level ){
if ( $type == 1 ){
$did = $v [ 'head_decorate_id' ];
$user_decorate = db :: name ( " user_decorate " ) -> where ([ 'uid' => $uid , 'did' => $did , 'type' => $type ]) -> where ( 'end_time' , " > " , time ()) -> find ();
if ( ! empty ( $user_decorate )){
$v [ 'js_suo' ] = 1 ;
$v [ 'is_using' ] = $user_decorate [ 'is_using' ];
$v [ 'udid' ] = $user_decorate [ 'udid' ];
} else {
if (( $cp_info [ 'id' ] >= 1 ) && ( $cp_info [ 'id' ] <= 1072 )){
$reslut = model ( 'Decorate' ) -> draw_user_decorate ( $uid , $did , 720 , 'CP特权赠送' , 1 , $cp_info [ 'id' ]);
if ( $reslut [ 'code' ] == 201 ){
return [ 'code' => 201 , 'msg' => '请重试2' , 'data' => null ];
}
//再次查询校验获取
$user_decorate = db :: name ( " user_decorate " ) -> where ([ 'uid' => $uid , 'did' => $did , 'type' => $type ]) -> where ( 'end_time' , " > " , time ()) -> find ();
$v [ 'udid' ] = $user_decorate [ 'udid' ];
if ( $user_decorate [ 'is_using' ] == 1 ){
$v [ 'is_using' ] = 1 ;
}
}
}
} else {
$did = $v [ 'cp_tx_id' ];
$user_decorate = db :: name ( " user_decorate " ) -> where ([ 'uid' => $uid , 'did' => $did , 'type' => $type ]) -> where ( 'end_time' , " > " , time ()) -> find ();
$v [ 'js_suo' ] = 1 ;
if ( ! empty ( $user_decorate )){
if ( $user_decorate [ 'is_using' ] == 1 ){
$v [ 'is_using' ] = 1 ;
}
$v [ 'udid' ] = $user_decorate [ 'udid' ];
} else {
$reslut = model ( 'Decorate' ) -> draw_user_decorate ( $uid , $did , 720 , 'CP特权赠送' , 1 , $cp_info [ 'id' ]);
if ( $reslut [ 'code' ] == 201 ){
return [ 'code' => 201 , 'msg' => '请重试2' , 'data' => null ];
}
$user_decorate = db :: name ( " user_decorate " ) -> where ([ 'uid' => $uid , 'did' => $did , 'type' => $type ]) -> where ( 'end_time' , " > " , time ()) -> find ();
$v [ 'udid' ] = $user_decorate [ 'udid' ];
if ( $user_decorate [ 'is_using' ] == 1 ){
$v [ 'is_using' ] = 1 ;
}
}
}
}
}
return [ 'code' => 200 , 'msg' => '获取成功' , 'data' => $cp_txks ];
}
}