Helper\Utils::flowAutoShow PHP Method

flowAutoShow() public static method

流量单位
public static flowAutoShow ( $value, integer $type = 1 ) : float | string
$value
$type integer
return float | string
    public static function flowAutoShow($value, $type = 1)
    {
        $negative = false;
        if ($value < 0) {
            $negative = true;
            $value = abs(intval($value));
        }
        if ($value > self::GB) {
            $str = round($value / self::GB, 2);
            if ($type) {
                $str .= " GB";
            }
        } else {
            if ($value > self::MB) {
                $str = round($value / self::MB, 2);
                if ($type) {
                    $str .= " MB";
                }
            } else {
                if ($value > self::KB) {
                    $str = round($value / self::KB, 2);
                    if ($type) {
                        $str .= " KB";
                    }
                } else {
                    $str = round($value, 2);
                    $str .= "";
                }
            }
        }
        if ($negative) {
            $str = '-' . $str;
        }
        return $str;
    }

Usage Example

 public function run()
 {
     $users = User::getUserArrayByExpire();
     $notificationMail = Option::get('mail_stop_expire_notification');
     $mailContentTemplate = Option::get('custom_mail_stop_expire_content');
     if (!$notificationMail) {
         Option::set('mail_stop_expire_notification', 0);
         // 设置邮件提醒的系统参数
     }
     $mailer = Mailer::getInstance();
     $mailer->toQueue(true);
     foreach ($users as $user) {
         $user->stop();
         Logger::getInstance()->info('user [' . $user->email . '] 未续费或流量超用已被暂停服务');
         if ($notificationMail) {
             $mail = new Mail();
             $mail->to = $user->email;
             $mail->subject = '[' . SITE_NAME . '] ' . "用户 {$user->nickname},您的账户由于未续费或流量超用已被暂停服务";
             $params = ['nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime)];
             $mailContent = Utils::placeholderReplace($mailContentTemplate, $params);
             $mailContent .= "<p style=\"padding: 1.5em 1em 0; color: #999; font-size: 12px;\">—— 本邮件由 " . SITE_NAME . " (<a href=\"" . BASE_URL . "\">" . BASE_URL . "</a>) 账户管控系统发送</p>";
             $mail->content = $mailContent;
             $mailer->send($mail);
         }
     }
     // 避免频繁更新 Option 单例对象,循环结束后再执行
     if ($notificationMail) {
         Option::set('mail_queue', 1);
     }
     // 2016-04-26 15:00 - by @Sendya Fixed issue #62
     // User::enableUsersByExpireTime(); // 启用已续费且流量未超过的用户
 }
All Usage Examples Of Helper\Utils::flowAutoShow