Pārlūkot izejas kodu

update:增加通用格式化rtp方法

aiden 4 mēneši atpakaļ
vecāks
revīzija
7f128e4efb

+ 15 - 1
app/common.php

@@ -344,4 +344,18 @@ if(!function_exists('assignUserId')) {
 
         return 0;
     }
-}
+}
+
+/**
+ * 获取游戏RTP
+ */
+if(!function_exists('calculateRTP')) {
+    function calculateRTP($totalWin, $totalBet): int|float
+    {
+        $rtp = 0;
+        if (!empty($totalBet)) {
+            $rtp = (float)bcmul(bcdiv((string)$totalWin, (string)$totalBet, 4), '100', 2);
+        }
+        return $rtp;
+    }
+}

+ 2 - 6
app/controller/MerchantStatis.php

@@ -86,11 +86,7 @@ class MerchantStatis extends BaseController
             }
             
             // 格式化数据
-            if (!empty($result['bet_amount'])) {
-                $result['rtp'] = (float)bcmul(bcdiv((string)$result['total_winning_score'], (string)$result['bet_amount'], 4), '100', 2);
-            } else {
-                $result['rtp'] = 0;
-            }
+            $result['rtp'] = calculateRTP($result['total_winning_score'], $result['bet_amount']);
             $result['date_stage'] = implode(' ~ ', $filters);
             $result['game_profit'] = (float)$result['game_profit'];
             $result['bet_amount'] = (float)$result['bet_amount'];
@@ -130,7 +126,7 @@ class MerchantStatis extends BaseController
                 }
             }            
             // 格式化数据
-            $result['rtp'] = (float)bcmul(bcdiv($result['total_winning_score'], $result['bet_amount'], 4), '100', 2);
+            $result['rtp'] = calculateRTP($result['total_winning_score'], $result['bet_amount']);
             $result['game_profit'] = (float)$result['game_profit'];
             $result['bet_amount'] = (float)$result['bet_amount'];
             $result['total_winning_score'] = (float)$result['total_winning_score'];

+ 1 - 1
app/controller/TrendStatis.php

@@ -188,7 +188,7 @@ class TrendStatis extends BaseController
                         $item['total_bet'] = (float)$rowData['total_bet'];
                         $item['bet_count'] = (int) $rowData['bet_count'];
                         $item['bet_users'] = (int) $rowData['bet_users'];
-                        $item['rtp'] = (float)bcmul(bcdiv((string)$rowData['total_win'], (string)$rowData['total_bet'], 4), '100', 2);
+                        $item['rtp'] = calculateRTP($rowData['total_win'], $rowData['total_bet']);
                     }
                 }
             }            

+ 1 - 1
app/model/MerchantStatisModel.php

@@ -68,7 +68,7 @@ class MerchantStatisModel extends Model
         
         foreach ($list as &$row)
         {
-            $row['rtp'] = (float)bcmul(bcdiv($row['total_winning_score'], $row['bet_amount'], 4), '100', 2);
+            $row['rtp'] = calculateRTP($row['total_winning_score'], $row['bet_amount']);
             $row['login_users'] = $merchantsUserStatic['login'][$row['date']]['count'] ?? 0;
             $row['register_users'] = $merchantsUserStatic['register'][$row['date']]['count'] ?? 0;
         }