From 889dfad9fac60f691844dca4c93c3a4778d1c786 Mon Sep 17 00:00:00 2001 From: printempw Date: Thu, 25 Aug 2016 13:26:53 +0800 Subject: [PATCH] decide storage unit automatically --- app/Models/User.php | 6 +++--- resources/views/admin/index.tpl | 8 +++----- resources/views/user/index.tpl | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 212d062c..1cc57536 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -165,9 +165,9 @@ class User if (is_null($this->storage_used)) { $this->storage_used = 0; // recalculate - $prefix = \Config::getDbConfig()['prefix']; - $sql = "SELECT SUM(`size`) AS total_size FROM `{$prefix}textures` WHERE uploader = {$this->uid}"; - $this->storage_used = \DB::fetchArray($sql)['total_size']; + $sql = "SELECT SUM(`size`) AS total_size FROM `{table}` WHERE uploader = {$this->uid}"; + $result = \DB::table('textures')->fetchArray($sql)['total_size']; + $this->storage_used = $result ?: 0; } return $this->storage_used; } diff --git a/resources/views/admin/index.tpl b/resources/views/admin/index.tpl index 919a28ef..259e996d 100644 --- a/resources/views/admin/index.tpl +++ b/resources/views/admin/index.tpl @@ -46,14 +46,11 @@ - - -
上传材质总数 - {{ \Storage::getFileNum(BASE_DIR."/textures/") }} + {{ \DB::table('textures')->getRecordNum() }}
@@ -61,7 +58,8 @@
占用空间大小 - {{ floor(\Storage::getDirSize(BASE_DIR."/textures/")/1024)."KB" }} + fetchArray("SELECT SUM(`size`) AS total_size FROM `{table}` WHERE 1")['total_size']; ?> + {{ $size > 1024 ? round($size / 1024, 1)."MB" : $size."KB" }}
diff --git a/resources/views/user/index.tpl b/resources/views/user/index.tpl index 4dcd76cd..10372d1c 100644 --- a/resources/views/user/index.tpl +++ b/resources/views/user/index.tpl @@ -43,9 +43,21 @@
存储空间 - {{ $user->getStorageUsed() }}/{{ $user->getStorageUsed() + $user->getScore() / Option::get('score_per_storage') }} KB + + @if ($user->getStorageUsed() > 1024) + + {{ round($user->getStorageUsed() / 1024, 1) }}/ + {{ round(($user->getStorageUsed() + $user->getScore() / $rate) / 1024, 1) }} MB + + @else + + {{ $user->getStorageUsed() }}/ + {{ $user->getStorageUsed() + $user->getScore() / $rate }} KB + + @endif +
-
+