Browse Source

fix: division by zero

https://github.com/Anankke/SSPanel-Uim/issues/1683
Cat 2 năm trước cách đây
mục cha
commit
e1d79aa772
2 tập tin đã thay đổi với 6 bổ sung6 xóa
  1. 1 1
      resources/email/news/daily-traffic-report.tpl
  2. 5 5
      src/Models/User.php

+ 1 - 1
resources/email/news/daily-traffic-report.tpl

@@ -175,7 +175,7 @@
                                                             </td>
                                                             <td class="alignright"
                                                                 style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: right; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;"
-                                                                align="right" valign="top">{$lastday}
+                                                                align="right" valign="top">{$lastday_traffic}
                                                             </td>
                                                         </tr>
 

+ 5 - 5
src/Models/User.php

@@ -303,7 +303,7 @@ final class User extends Model
      */
     public function todayUsedTrafficPercent(): float
     {
-        if ($this->transfer_enable === 0) {
+        if ($this->transfer_enable === 0 || $this->transfer_enable === '0' || $this->transfer_enable === null) {
             return 0;
         }
         $Todayused = $this->u + $this->d - $this->last_day_t;
@@ -325,7 +325,7 @@ final class User extends Model
      */
     public function lastUsedTrafficPercent(): float
     {
-        if ($this->transfer_enable === 0) {
+        if ($this->transfer_enable === 0 || $this->transfer_enable === '0' || $this->transfer_enable === null) {
             return 0;
         }
         $Lastused = $this->last_day_t;
@@ -818,7 +818,7 @@ final class User extends Model
      */
     public function sendDailyNotification(string $ann = ''): void
     {
-        $lastday = $this->todayUsedTraffic();
+        $lastday_traffic = $this->todayUsedTraffic();
         $enable_traffic = $this->enableTraffic();
         $used_traffic = $this->usedTraffic();
         $unused_traffic = $this->unusedTraffic();
@@ -833,7 +833,7 @@ final class User extends Model
                     [
                         'user' => $this,
                         'text' => '下面是系统中目前的最新公告:<br><br>' . $ann . '<br><br>晚安!',
-                        'lastday' => $lastday,
+                        'lastday_traffic' => $lastday_traffic,
                         'enable_traffic' => $enable_traffic,
                         'used_traffic' => $used_traffic,
                         'unused_traffic' => $unused_traffic,
@@ -848,7 +848,7 @@ final class User extends Model
                 $text .= '流量总计:' . $enable_traffic . PHP_EOL;
                 $text .= '已用流量:' . $used_traffic . PHP_EOL;
                 $text .= '剩余流量:' . $unused_traffic . PHP_EOL;
-                $text .= '今日使用:' . $lastday;
+                $text .= '今日使用:' . $lastday_traffic;
                 $this->sendTelegram(
                     $text
                 );