diff --git a/application/api/controller/RoomAuction.php b/application/api/controller/RoomAuction.php index 36180fa8..9e576ace 100644 --- a/application/api/controller/RoomAuction.php +++ b/application/api/controller/RoomAuction.php @@ -3,6 +3,7 @@ namespace app\api\controller; use app\common\controller\BaseCom; +use think\Db; class RoomAuction extends BaseCom { @@ -18,6 +19,10 @@ class RoomAuction extends BaseCom public function room_auction_time() { $gift_id = input('gift_id'); + $pool_gift_id = db::name('bb_lottery_config')->where(['key' => 'pool_gift_id'])->value('value'); + if($gift_id == $pool_gift_id){ + return V(0, '此礼物不能进行此操作'); + } $reslut = model('RoomAuction')->room_auction_time($gift_id); return V($reslut['code'], $reslut['msg'], $reslut['data']); } @@ -34,6 +39,10 @@ class RoomAuction extends BaseCom if (in_array($gift_id, $cp_gift_ids)) { return V( 0, '礼物不能是CP礼物,请重新选择'); } + $pool_gift_id = db::name('bb_lottery_config')->where(['key' => 'pool_gift_id'])->value('value'); + if($gift_id == $pool_gift_id){ + return V(0, '此礼物不能进行此操作'); + } $relation_id = input('relation_id',''); $auction_type = input('auction_type',1);//1真爱拍 2 亲密拍 $time_day = input('time_day', 0);//小时 @@ -59,7 +68,10 @@ class RoomAuction extends BaseCom $gift_id = input('gift_id'); $num = input('num'); $type = input('type',1);//1金币购买 2送背包礼物 - + $pool_gift_id = db::name('bb_lottery_config')->where(['key' => 'pool_gift_id'])->value('value'); + if($gift_id == $pool_gift_id){ + return V(0, '此礼物不能进行此操作'); + } $reslut = model('RoomAuction')->room_auction_join($auction_id,$user_id,$gift_id,$num,$type); return V($reslut['code'], $reslut['msg'], $reslut['data']); } diff --git a/application/api/controller/RoomPit.php b/application/api/controller/RoomPit.php index f10c6f5d..3271a2fe 100644 --- a/application/api/controller/RoomPit.php +++ b/application/api/controller/RoomPit.php @@ -89,6 +89,10 @@ class RoomPit extends BaseCom $room_id = input('room_id', 0); $gift_id = input('gift_id', 0); $gift_price = input('gift_price', 0); + $pool_gift_id = db::name('bb_lottery_config')->where(['key' => 'pool_gift_id'])->value('value'); + if($gift_id == $pool_gift_id){ + return V(0, '此礼物不能进行此操作'); + } $reslut = model('RoomPit')->set_room_pit_apply_help_gift($this->uid, $room_id, $gift_id, $gift_price); return V($reslut['code'], $reslut['msg'], $reslut['data']); } diff --git a/application/api/controller/SingerSong.php b/application/api/controller/SingerSong.php index 68d06a52..6d9a4c6c 100644 --- a/application/api/controller/SingerSong.php +++ b/application/api/controller/SingerSong.php @@ -33,6 +33,10 @@ class SingerSong extends BaseCom if (!$gift_id) { return V(0, '请选择礼物'); } + $pool_gift_id = db::name('bb_lottery_config')->where(['key' => 'pool_gift_id'])->value('value'); + if($gift_id == $pool_gift_id){ + return V(0, '此礼物不能进行此操作'); + } $gift_num = input('gift_num', 1); $reslut = model('SingerSong')->singerAddSong($this->uid, $song_name, $gift_id, $gift_num); return V($reslut['code'], $reslut['msg'], $reslut['data']); @@ -71,6 +75,10 @@ class SingerSong extends BaseCom if (!$gift_id) { return V(0, '请选择礼物'); } + $pool_gift_id = db::name('bb_lottery_config')->where(['key' => 'pool_gift_id'])->value('value'); + if($gift_id == $pool_gift_id){ + return V(0, '此礼物不能进行此操作'); + } $gift_num = input('gift_num', 1); $reslut = db::name('vs_singer_song')->insert([ 'user_id' => $this->uid, diff --git a/application/api/controller/UserZone.php b/application/api/controller/UserZone.php index f48b51a5..c05c16b4 100644 --- a/application/api/controller/UserZone.php +++ b/application/api/controller/UserZone.php @@ -185,6 +185,10 @@ class UserZone extends BaseCom $gift_id = input('gift_id', 0); $num = input('num', 1); $is_pack = input('is_pack', 1);//2背包 1金币 + $pool_gift_id = db::name('bb_lottery_config')->where(['key' => 'pool_gift_id'])->value('value'); + if($gift_id == $pool_gift_id){ + return V(0, '此礼物不能进行此操作'); + } $reslut = model('GiveGift')->reward_zone($this->uid, $zid, $gift_id, $num, $is_pack); return V($reslut['code'], $reslut['msg'], $reslut['data']); } diff --git a/application/api/model/Lottery.php b/application/api/model/Lottery.php index 39f10150..36c9ae39 100644 --- a/application/api/model/Lottery.php +++ b/application/api/model/Lottery.php @@ -75,22 +75,22 @@ class Lottery extends Model $giftId = Db::name('bb_lottery_gift_record')->insertGetId($giftRecord); //收礼记录行为日志 - $give_gift = model('api/GiveGift')->change_user_give_gift_log($send_uid,$gift_id,$gift_price,$num,$to_id,2,1,$room_id,0); + $give_gift = model('api/GiveGift')->change_user_give_gift_log($send_uid,$gift_id,$gift_price,$num,$to_id,2,1,0,0); if(!$give_gift){ Db::rollback(); return ['code' => 0, 'msg' => '送礼失败', 'data' => null]; } //计算收礼人得益 - $receiver_earnings = $gift_price /2/100; + $receiver_earnings = $gift_price /2/get_system_config_value('rmb_coin_ratio'); //增加收益并记录日志 $receiver = model('api/GiveGift') -> change_user_cion_or_earnings_log($to_id,$receiver_earnings,$room_id,2,11,'收礼增加收益'); - //用户魅力等级更新 - $user_level = model('api/Level')->user_level_data_update($to_id,$gift_price,2,$room_id); - if(!$user_level){ - Db::rollback(); - return ['code' => 0, 'msg' => '用户等级更新失败', 'data' => null]; - } +// //用户魅力等级更新 +// $user_level = model('api/Level')->user_level_data_update($to_id,$gift_price,2,$room_id); +// if(!$user_level){ +// Db::rollback(); +// return ['code' => 0, 'msg' => '用户等级更新失败', 'data' => null]; +// } //增加房间幸运值 db::name('vs_room')->where(['id' => $room_id])->setInc('luck_value',$gift_price); db::name('vs_room_luck_value')->insert( [ diff --git a/application/common/library/RedpacketLua.php b/application/common/library/RedpacketLua.php index e5359ae6..8ab7fa82 100644 --- a/application/common/library/RedpacketLua.php +++ b/application/common/library/RedpacketLua.php @@ -69,29 +69,38 @@ if leftCount <= 0 or leftAmount <= 0 then return {0, "红包已抢完", 0} end --- 计算红包金额 +-- 计算红包金额(核心修复:解决3金币2红包场景第二个红包为0的问题) local amount = 0 local isFinished = 0 if leftCount == 1 then - -- 最后一个红包,获得剩余所有金额 + -- 最后一个红包,获得剩余所有金额(确保至少1) amount = leftAmount isFinished = 1 else - -- 随机算法:二倍均值法,保证公平性 - local maxAmount = leftAmount / leftCount * 2 - amount = math.random(1, math.floor(maxAmount)) - -- 确保金额不会超过剩余金额 - if amount > leftAmount then - amount = leftAmount - end - -- 检查是否是最后一个(由于浮点数计算可能有误差) - if leftCount == 1 or (leftAmount - amount) < 0.01 then + -- 随机算法:二倍均值法(适配整数+保底逻辑,彻底避免0) + -- 1. 基础二倍均值(整数处理) + local avg = leftAmount / leftCount + local maxAmount = math.floor(avg * 2) + + -- 2. 核心修复:保底限制 - 最大金额不能超过「剩余金额 - (剩余个数 - 1)」 + -- 确保剩下的每个红包至少能分到1个金币(比如3金币2红包:3 - (2-1) = 2,第一个红包最多抢2) + local safeMax = leftAmount - (leftCount - 1) + maxAmount = math.min(maxAmount, safeMax) + + -- 3. 强制保证最小金额为1,最大金额不小于1 + maxAmount = math.max(maxAmount, 1) + + -- 4. 随机生成1到maxAmount之间的整数(绝对不会出现0) + amount = math.random(1, maxAmount) + + -- 5. 整数场景下的抢完判断(无需浮点数误差处理) + if (leftCount - 1) == 1 and (leftAmount - amount) == 0 then isFinished = 1 end end --- 更新红包数据 +-- 更新红包数据(整数处理,无小数) local newLeftAmount = leftAmount - amount local newLeftCount = leftCount - 1 diff --git a/application/common/service/LotteryService.php b/application/common/service/LotteryService.php index 6ac676f7..1e1bf602 100644 --- a/application/common/service/LotteryService.php +++ b/application/common/service/LotteryService.php @@ -147,21 +147,21 @@ class LotteryService ); } else { $winnerUid = $send_uid; // 奖默认给当前送礼用户 - // 1. 只要开小奖,小奖剩余划入大奖池流水 - $this->addPoolFlow( - 2, // 大奖池 - 3, // 划转 - $result['small_remain_amount'],//小奖剩余金额 - $result['big_pool_total_before_open'] - $result['small_remain_amount'], - $result['big_pool_total_before_open'], - $giftId, - $result['big_round'] - ($result['is_big_prize'] ? 1 : 0), - "小奖剩余划转大奖池:{$result['small_remain_amount']}金币" - ); - //2.开小奖剩余划入大奖后 大奖够开奖 //开大奖 if ($result['is_big_prize'] == 1) { + //开小奖,小奖剩余划入大奖池流水 + $this->addPoolFlow( + 2, // 大奖池 + 3, // 划转 + $result['small_remain_amount'],//小奖剩余金额 + $result['big_total_gold'] - $result['small_remain_amount'], + $result['big_total_gold'], + $giftId, + $result['big_round'] - ($result['is_big_prize'] ? 1 : 0), + "小奖剩余划转大奖池:{$result['small_remain_amount']}金币" + ); + //2.1 大奖中奖记录 $this->addWinnerRecord( $winnerUid, @@ -217,7 +217,17 @@ class LotteryService $result['small_round'] - 1, // 开奖轮次为当前轮次-1(已结束的轮次) "小奖池开奖:轮次" . ($result['small_round'] - 1).",中奖金额:{$result['small_prize_amount']}金币" ); - + //开小奖,小奖剩余划入大奖池流水 + $this->addPoolFlow( + 2, // 大奖池 + 3, // 划转 + $result['small_remain_amount'],//小奖剩余金额 + $result['big_total_gold'] - $result['small_remain_amount'], + $result['big_total_gold'], + $giftId, + $result['big_round'] - ($result['is_big_prize'] ? 1 : 0), + "小奖剩余划转大奖池:{$result['small_remain_amount']}金币" + ); } } diff --git a/application/common/service/RedpacketService.php b/application/common/service/RedpacketService.php index 7a6043f7..f497f155 100644 --- a/application/common/service/RedpacketService.php +++ b/application/common/service/RedpacketService.php @@ -610,7 +610,7 @@ class RedpacketService { $room_type = Db::name('vs_room')->where('id',$roomId)->field('type_id,label_id')->find(); //实际麦位 - if($room_type['type_id'] == 1 || $room_type['type_id'] == 7 || $room_type['type_id'] == 8){ + if($room_type['type_id'] == 1 || $room_type['type_id'] == 7 || $room_type['type_id'] == 8 || $room_type['type_id'] == 9 || $room_type['type_id'] == 10){ $onPit = Db::name('vs_room_pit')->where(['user_id' => $userId,'room_id' => $roomId])->value('pit_number'); if ($onPit <= 0){ return false;