Browse Source

【Fix】修复抽奖概率的缺陷

liuxiangxin 3 months ago
parent
commit
deff1b6405

+ 5 - 5
app/Models/Lottery/OrderReward.php

@@ -133,10 +133,10 @@ class OrderReward extends Model
      * 
      * 
      */
      */
     public function getRewardResult($reward){
     public function getRewardResult($reward){
-        // 从1开始
-		$offset							= 1;
-		// 判断抽奖结果
-		$randInt						= random_int($offset,100);
+        // 从0开始, 包含0
+		$offset							= 0;
+		// 随机数,包含起始值,不含结束值
+		$randInt						= random_int($offset,10000);
 		// 中奖下标
 		// 中奖下标
 		$index							= 0;
 		$index							= 0;
 		// 循环奖品
 		// 循环奖品
@@ -146,7 +146,7 @@ class OrderReward extends Model
 			// 开始数值
 			// 开始数值
 			$start 						= $offset;
 			$start 						= $offset;
 			// 结束数值
 			// 结束数值
-			$end						= $value['probability'] ? $offset + $value['probability'] : 0;
+			$end						= $value['probability'] ? $offset + intval($value['probability'] * 100) : 0;
 			// 重新计算开始数值
 			// 重新计算开始数值
 			$offset						= $offset ? $end : $offset;
 			$offset						= $offset ? $end : $offset;
 			// 区间内即抽中
 			// 区间内即抽中

+ 5 - 5
app/Models/Lottery/RiddleReward.php

@@ -133,10 +133,10 @@ class RiddleReward extends Model
      * 
      * 
      */
      */
     public function getRewardResult($reward){
     public function getRewardResult($reward){
-        // 从1开始
-		$offset							= 1;
-		// 判断抽奖结果
-		$randInt						= random_int($offset,100);
+        // 从0开始
+		$offset							= 0;
+		// 随机数,包含起始值,不含结束值
+		$randInt						= random_int($offset,10000);
 		// 中奖下标
 		// 中奖下标
 		$index							= 0;
 		$index							= 0;
 		// 循环奖品
 		// 循环奖品
@@ -146,7 +146,7 @@ class RiddleReward extends Model
 			// 开始数值
 			// 开始数值
 			$start 						= $offset;
 			$start 						= $offset;
 			// 结束数值
 			// 结束数值
-			$end						= $value['probability'] ? $offset + $value['probability'] : 0;
+			$end						= $value['probability'] ? $offset + intval($value['probability'] * 100) : 0;
 			// 重新计算开始数值
 			// 重新计算开始数值
 			$offset						= $offset ? $end : $offset;
 			$offset						= $offset ? $end : $offset;
 			// 区间内即抽中
 			// 区间内即抽中

+ 4 - 4
app/Models/Lottery/ScoreReward.php

@@ -133,9 +133,9 @@ class ScoreReward extends Model
      * 
      * 
      */
      */
     public function getRewardResult($reward){
     public function getRewardResult($reward){
-        // 从1开始
-		$offset							= 1;
-		// 判断抽奖结果
+        // 从0开始
+		$offset							= 0;
+		// 随机数,包含起始值,不含结束值
 		$randInt						= random_int($offset,10000);
 		$randInt						= random_int($offset,10000);
 		// 中奖下标
 		// 中奖下标
 		$index							= 0;
 		$index							= 0;
@@ -146,7 +146,7 @@ class ScoreReward extends Model
 			// 开始数值
 			// 开始数值
 			$start 						= $offset;
 			$start 						= $offset;
 			// 结束数值
 			// 结束数值
-			$end						= $value['probability'] ? $offset + $value['probability']*100 : 0;
+			$end						= $value['probability'] ? $offset + intval($value['probability']*100) : 0;
 			// 重新计算开始数值
 			// 重新计算开始数值
 			$offset						= $offset ? $end : $offset;
 			$offset						= $offset ? $end : $offset;
 			// 区间内即抽中
 			// 区间内即抽中