diff --git a/controllers/AdminController.php b/controllers/AdminController.php index 851677b..f09d3ab 100644 --- a/controllers/AdminController.php +++ b/controllers/AdminController.php @@ -5,6 +5,7 @@ namespace app\controllers; use app\models\User; use app\models\UserSearch; use app\utils\AdminSword; +use app\utils\FileSizeHelper; use Throwable; use Yii; use yii\base\Exception; @@ -135,6 +136,27 @@ class AdminController extends Controller } else { return ['output' => $oldValue, 'message' => 'Incorrect Value! Please reenter.']; } + } elseif (isset($_POST['storage_limit'])) { //修改用户存储限制 + $oldValue = $model->storage_limit; + $input_limit = $_POST['storage_limit']; + $limit = FileSizeHelper::getConvertedLimit($input_limit); + switch ($limit) { + case -1: + $model->storage_limit = -1; + break; + case -2: + return ['output' => $oldValue, 'message' => '值不能为空']; + case -3: + return ['output' => $oldValue, 'message' => '格式错误']; + default: + $model->storage_limit = $limit; + } + if ($model->save(true, ['storage_limit'])) { + return ['output' => FileSizeHelper::formatMegaBytes($model->storage_limit), 'message' => '']; + } else { + return ['output' => FileSizeHelper::formatMegaBytes($oldValue), 'message' => 'Incorrect Value! Please reenter.']; + } + } else { return ['output' => '', 'message' => '']; } diff --git a/views/admin/user_view.php b/views/admin/user_view.php index 526a672..a5ae9ae 100644 --- a/views/admin/user_view.php +++ b/views/admin/user_view.php @@ -22,6 +22,7 @@ $alreadyDisabled = $model->status == 0; $IPLocation = new IPLocation(); YiiAsset::register($this); FontAwesomeAsset::register($this); +$this->registerCssFile('@web/css/admin-userv.css'); ?>
@@ -53,7 +54,7 @@ FontAwesomeAsset::register($this); ['attribute' => 'name', 'label' => '昵称', 'format' => 'raw', 'value' => function ($model) { return Editable::widget([ 'name' => 'name', - 'asPopover' => false, + 'asPopover' => true, 'value' => $model->name, 'header' => '昵称', 'size' => 'md', @@ -141,11 +142,24 @@ FontAwesomeAsset::register($this); } return FileSizeHelper::formatBytes(FileSizeHelper::getUserVaultDirSize($model->id)); }], - ['attribute' => 'storage_limit', 'label' => '存储容量限制', 'value' => function ($model) { +// ['attribute' => 'storage_limit', 'label' => '存储容量限制', 'value' => function ($model) { +// if ($model->role == 'admin') { +// return '不可用'; +// } +// return FileSizeHelper::formatMegaBytes($model->storage_limit); +// }], + ['attribute' => 'storage_limit', 'label' => '存储容量限制', 'format' => 'raw', 'value' => function ($model) { if ($model->role == 'admin') { return '不可用'; } - return FileSizeHelper::formatMegaBytes($model->storage_limit); + return Editable::widget([ + 'name' => 'storage_limit', + 'asPopover' => true, + 'value' => FileSizeHelper::formatMegaBytes($model->storage_limit), + 'header' => '存储容量限制(最小1MB)', + 'size' => 'md', + 'options' => ['class' => 'form-control', 'placeholder' => '在这里输入容量限制(最小值为1MB)...'], + ]); }], ['attribute' => 'storage_limit', 'format' => 'html', 'label' => '存储空间使用状态', 'value' => function ($model) { if ($model->role == 'admin') {