= small_trigger_times then result.is_small_prize = 1 -- 小奖随机比例 local small_ratio = math.random(2, 99) result.small_prize_amount = math.floor(small_total_gold * small_ratio / 100 * 100) / 100 -- 小奖剩余金额(划入大奖池当前轮次) result.small_remain_amount = math.floor((small_total_gold - result.small_prize_amount) * 100) / 100 -- 重置小奖池,小轮次+1 redis.call('set', small_total_times_key, 0) redis.call('set', small_total_gold_key, 0) small_round = small_round + 1 redis.call('set', small_round_key, small_round) result.small_round = small_round -- 6. 小奖剩余划入大奖池当前轮次 big_total_gold = math.floor((big_total_gold + result.small_remain_amount) * 100) / 100 redis.call('set', big_total_gold_key, big_total_gold) result.big_total_gold = big_total_gold -- 7. 大奖池开奖判断(大轮次+1) if big_total_gold >= big_threshold then result.is_big_prize = 1 -- 大奖比例权重 local weight_sum = 20 + 50 + 30 local random_weight = math.random(1, weight_sum) local big_ratio = random_weight <= 20 and 60 or (random_weight <= 70 and 70 or 80) -- 大奖金额 result.big_prize_amount = math.floor(big_total_gold * big_ratio / 100 * 100) / 100 result.big_release_amount = math.floor((big_total_gold - result.big_prize_amount) * 100) / 100 -- 原有逻辑:重置大奖池,大轮次+1 redis.call('set', big_total_gold_key, 0) big_round = big_round + 1 redis.call('set', big_round_key, big_round) -- 强制保证小轮次≥大轮次 if small_round < big_round then small_round = big_round redis.call('set', small_round_key, small_round) result.small_round = small_round end result.big_round = big_round result.big_total_gold = 0 -- ===================== 新增核心逻辑 ===================== -- 小奖开奖金额累加到大奖池下一轮次(新的big_round) result.small_prize_to_big_next_round = result.small_prize_amount -- 原子性更新大奖池下一轮次金额 local new_big_total_gold = math.floor(result.small_prize_amount * 100) / 100 redis.call('set', big_total_gold_key, new_big_total_gold) result.big_total_gold = new_big_total_gold -- ====================================================== end end -- 返回结果 return cjson.encode(result) LUA; } // 获取Lua脚本 public static function getLotteryLuaScripts() { return <<= small_trigger_times then result.is_small_prize = 1 -- 小奖随机比例 local small_ratio = math.random(1, 99) result.small_prize_amount = math.floor(small_total_gold * small_ratio / 100 * 100) / 100 result.small_remain_amount = math.floor((small_total_gold - result.small_prize_amount) * 100) / 100 -- 重置小奖池,小轮次+1 redis.call('set', small_total_times_key, 0) redis.call('set', small_total_gold_key, 0) small_round = small_round + 1 redis.call('set', small_round_key, small_round) result.small_round = small_round -- 6. 小奖剩余划入大奖池当前轮次 big_total_gold = math.floor((big_total_gold + result.small_remain_amount) * 100) / 100 redis.call('set', big_total_gold_key, big_total_gold) result.big_total_gold = big_total_gold -- 7. 大奖池开奖判断 if big_total_gold >= big_threshold then -- ===================== 关键修改:记录开奖前总金额 ===================== result.big_pool_total_before_open = big_total_gold -- 保存开奖前的总金额 -- ====================================================== result.is_big_prize = 1 -- 从配置读取权重计算出奖比例 local random_weight = math.random(1, big_weight_total) local big_ratio = 60 if random_weight > big_weight_60 and random_weight <= (big_weight_60 + big_weight_70) then big_ratio = 70 elseif random_weight > (big_weight_60 + big_weight_70) then big_ratio = 80 end result.big_ratio = big_ratio -- 大奖金额计算(基于开奖前的总金额) result.big_prize_amount = math.floor(big_threshold * big_ratio / 100) result.big_release_amount = math.floor(big_total_gold - result.big_prize_amount) -- 重置大奖池,大轮次+1 redis.call('set', big_total_gold_key, 0) big_round = big_round + 1 redis.call('set', big_round_key, big_round) if small_round < big_round then small_round = big_round redis.call('set', small_round_key, small_round) result.small_round = small_round end result.big_round = big_round result.big_total_gold = 0 -- 小奖开奖金额划入大奖池下一轮 result.small_prize_to_big_next_round = result.small_prize_amount local new_big_total_gold = math.floor(result.small_prize_amount * 100) / 100 redis.call('set', big_total_gold_key, new_big_total_gold) result.big_total_gold = new_big_total_gold end end -- 返回结果 return cjson.encode(result) LUA; } }