浏览代码

feat: clearer user traffic display

M1Screw 2 年之前
父节点
当前提交
ed6698c484

+ 18 - 18
composer.lock

@@ -123,16 +123,16 @@
         },
         {
             "name": "aws/aws-sdk-php",
-            "version": "3.269.2",
+            "version": "3.269.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/aws/aws-sdk-php.git",
-                "reference": "29318777b1a259471827d0f9f174e48677903d60"
+                "reference": "0be880140b9fe48f67fcbf5f1ed19a1d08116369"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/29318777b1a259471827d0f9f174e48677903d60",
-                "reference": "29318777b1a259471827d0f9f174e48677903d60",
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/0be880140b9fe48f67fcbf5f1ed19a1d08116369",
+                "reference": "0be880140b9fe48f67fcbf5f1ed19a1d08116369",
                 "shasum": ""
             },
             "require": {
@@ -212,9 +212,9 @@
             "support": {
                 "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
-                "source": "https://github.com/aws/aws-sdk-php/tree/3.269.2"
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.269.3"
             },
-            "time": "2023-04-28T18:22:53+00:00"
+            "time": "2023-05-01T18:21:53+00:00"
         },
         {
             "name": "bacon/bacon-qr-code",
@@ -7672,16 +7672,16 @@
         },
         {
             "name": "phpstan/phpdoc-parser",
-            "version": "1.20.3",
+            "version": "1.20.4",
             "source": {
                 "type": "git",
                 "url": "https://github.com/phpstan/phpdoc-parser.git",
-                "reference": "6c04009f6cae6eda2f040745b6b846080ef069c2"
+                "reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6c04009f6cae6eda2f040745b6b846080ef069c2",
-                "reference": "6c04009f6cae6eda2f040745b6b846080ef069c2",
+                "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd",
+                "reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd",
                 "shasum": ""
             },
             "require": {
@@ -7711,9 +7711,9 @@
             "description": "PHPDoc parser with support for nullable, intersection and generic types",
             "support": {
                 "issues": "https://github.com/phpstan/phpdoc-parser/issues",
-                "source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.3"
+                "source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.4"
             },
-            "time": "2023-04-25T09:01:03+00:00"
+            "time": "2023-05-02T09:19:37+00:00"
         },
         {
             "name": "phpunit/php-file-iterator",
@@ -7882,16 +7882,16 @@
         },
         {
             "name": "sebastian/diff",
-            "version": "5.0.1",
+            "version": "5.0.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/diff.git",
-                "reference": "aae9a0a43bff37bd5d8d0311426c87bf36153f02"
+                "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/aae9a0a43bff37bd5d8d0311426c87bf36153f02",
-                "reference": "aae9a0a43bff37bd5d8d0311426c87bf36153f02",
+                "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b",
+                "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b",
                 "shasum": ""
             },
             "require": {
@@ -7937,7 +7937,7 @@
             "support": {
                 "issues": "https://github.com/sebastianbergmann/diff/issues",
                 "security": "https://github.com/sebastianbergmann/diff/security/policy",
-                "source": "https://github.com/sebastianbergmann/diff/tree/5.0.1"
+                "source": "https://github.com/sebastianbergmann/diff/tree/5.0.3"
             },
             "funding": [
                 {
@@ -7945,7 +7945,7 @@
                     "type": "github"
                 }
             ],
-            "time": "2023-03-23T05:12:41+00:00"
+            "time": "2023-05-01T07:48:21+00:00"
         },
         {
             "name": "sebastian/version",

+ 8 - 1
resources/views/tabler/admin/user/edit.tpl

@@ -162,12 +162,19 @@
                                 </div>
                             </div>
                             <div class="form-group mb-3 row">
-                                <label class="form-label col-4 col-form-label">已用流量 (GB)</label>
+                                <label class="form-label col-4 col-form-label">当期用量</label>
                                 <div class="col">
                                     <input id="usedTraffic" type="text" class="form-control"
                                         value="{$edit_user->usedTraffic()}" disabled />
                                 </div>
                             </div>
+                            <div class="form-group mb-3 row">
+                                <label class="form-label col-4 col-form-label">累计用量</label>
+                                <div class="col">
+                                    <input id="usedTraffic" type="text" class="form-control"
+                                           value="{$edit_user->totalTraffic()}" disabled />
+                                </div>
+                            </div>
                             <div class="hr-text">
                                 <span>邀请注册</span>
                             </div>

+ 1 - 1
resources/views/tabler/user/profile.tpl

@@ -54,7 +54,7 @@
                             <div class="d-flex align-items-center">
                                 <div class="subheader">账户累计使用流量</div>
                             </div>
-                            <div class="h1 mb-3">{round($user->transfer_total / 1073741824,2)} GB</div>
+                            <div class="h1 mb-3">{$user->totalTraffic()}</div>
                         </div>
                     </div>
                 </div>

+ 3 - 3
src/Controllers/Admin/UserController.php

@@ -29,7 +29,7 @@ final class UserController extends BaseController
             'money' => '余额',
             'ref_by' => '邀请人',
             'transfer_enable' => '流量限制',
-            'last_day_t' => '累计用量',
+            'transfer_used' => '当期用量',
             'class' => '等级',
             'reg_date' => '注册时间',
             'expire_in' => '账户过期',
@@ -278,8 +278,8 @@ final class UserController extends BaseController
             $user->op = '<button type="button" class="btn btn-red" id="delete-user-' . $user->id . '" 
             onclick="deleteUser(' . $user->id . ')">删除</button>
             <a class="btn btn-blue" href="/admin/user/' . $user->id . '/edit">编辑</a>';
-            $user->transfer_enable = round($user->transfer_enable / 1073741824, 2);
-            $user->last_day_t = round($user->last_day_t / 1073741824, 2);
+            $user->transfer_enable = $user->enableTraffic();
+            $user->transfer_used = $user->usedTraffic();
         }
 
         return $response->withJson([

+ 9 - 14
src/Models/User.php

@@ -175,13 +175,21 @@ final class User extends Model
     }
 
     /*
-     * 已用流量[自动单位]
+     * 当期用量[自动单位]
      */
     public function usedTraffic(): string
     {
         return Tools::flowAutoShow($this->u + $this->d);
     }
 
+    /*
+     * 累计用量[自动单位]
+     */
+    public function totalTraffic(): string
+    {
+        return Tools::flowAutoShow($this->transfer_total);
+    }
+
     /*
      * 已用流量占总流量的百分比
      */
@@ -369,19 +377,6 @@ final class User extends Model
         return true;
     }
 
-    /**
-     * 获取用户被封禁的理由
-     */
-    public function disableReason(): string
-    {
-        $reason_id = DetectLog::where('user_id', $this->id)->orderBy('id', 'DESC')->first();
-        $reason = DetectRule::find($reason_id->list_id);
-        if (is_null($reason)) {
-            return '特殊原因被禁用,了解详情请联系管理员';
-        }
-        return $reason->text;
-    }
-
     /**
      * 最后一次被封禁的时间
      */