diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 809b19ddd..62a839941 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -2,50 +2,54 @@ namespace App\Controllers\Admin; -use App\Models\User; use App\Controllers\AdminController; +use App\Models\User; use App\Utils\Hash; +use App\Utils\Tools; class UserController extends AdminController { - public function index($request, $response, $args){ + public function index($request, $response, $args) + { $pageNum = 1; - if(isset($request->getQueryParams()["page"])){ + if (isset($request->getQueryParams()["page"])) { $pageNum = $request->getQueryParams()["page"]; } - $users = User::paginate(15,['*'],'page',$pageNum); + $users = User::paginate(15, ['*'], 'page', $pageNum); $users->setPath('/admin/user'); - return $this->view()->assign('users',$users)->display('admin/user/index.tpl'); + return $this->view()->assign('users', $users)->display('admin/user/index.tpl'); } - public function edit($request, $response, $args){ + public function edit($request, $response, $args) + { $id = $args['id']; $user = User::find($id); - if ($user == null){ + if ($user == null) { } - return $this->view()->assign('user',$user)->display('admin/user/edit.tpl'); + return $this->view()->assign('user', $user)->display('admin/user/edit.tpl'); } - public function update($request, $response, $args){ + public function update($request, $response, $args) + { $id = $args['id']; $user = User::find($id); - $user->email = $request->getParam('email'); + $user->email = $request->getParam('email'); if ($request->getParam('pass') != '') { $user->pass = Hash::passwordHash($request->getParam('pass')); } - if($request->getParam('passwd') != ''){ + if ($request->getParam('passwd') != '') { $user->passwd = $request->getParam('passwd'); } - $user->port = $request->getParam('port'); - $user->transfer_enable = $request->getParam('transfer_enable'); + $user->port = $request->getParam('port'); + $user->transfer_enable = Tools::toGB($request->getParam('transfer_enable')); $user->invite_num = $request->getParam('invite_num'); $user->method = $request->getParam('method'); $user->enable = $request->getParam('enable'); $user->is_admin = $request->getParam('is_admin'); $user->ref_by = $request->getParam('ref_by'); - if(!$user->save()){ + if (!$user->save()) { $rs['ret'] = 0; $rs['msg'] = "修改失败"; return $response->getBody()->write(json_encode($rs)); @@ -55,10 +59,11 @@ public function update($request, $response, $args){ return $response->getBody()->write(json_encode($rs)); } - public function delete($request, $response, $args){ + public function delete($request, $response, $args) + { $id = $args['id']; $user = User::find($id); - if(!$user->delete()){ + if (!$user->delete()) { $rs['ret'] = 0; $rs['msg'] = "删除失败"; return $response->getBody()->write(json_encode($rs)); @@ -68,7 +73,8 @@ public function delete($request, $response, $args){ return $response->getBody()->write(json_encode($rs)); } - public function deleteGet($request, $response, $args){ + public function deleteGet($request, $response, $args) + { $id = $args['id']; $user = User::find($id); $user->delete(); diff --git a/app/Models/User.php b/app/Models/User.php index b0125897d..271f37645 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,10 +6,9 @@ * User Model */ -use App\Utils\Tools; -use App\Utils\Hash; -use App\Models\InviteCode; use App\Services\Config; +use App\Utils\Hash; +use App\Utils\Tools; class User extends Model @@ -115,6 +114,12 @@ public function enableTraffic() return Tools::flowAutoShow($transfer_enable); } + public function enableTrafficInGB() + { + $transfer_enable = $this->attributes['transfer_enable']; + return Tools::flowToGB($transfer_enable); + } + public function usedTraffic() { $total = $this->attributes['u'] + $this->attributes['d']; diff --git a/app/Utils/Tools.php b/app/Utils/Tools.php index cf451647f..814cfd56a 100755 --- a/app/Utils/Tools.php +++ b/app/Utils/Tools.php @@ -30,18 +30,25 @@ static function flowAutoShow($value = 0) } } - static function toMB($traffic) + + public static function toMB($traffic) { $mb = 1048576; return $traffic * $mb; } - static function toGB($traffic) + public static function toGB($traffic) { $gb = 1048576 * 1024; return $traffic * $gb; } + public static function flowToGB($traffic) + { + $gb = 1048576 * 1024; + return $traffic / $gb; + } + //获取随机字符串 public static function genRandomChar($length = 8) { diff --git a/resources/views/default/admin/user/edit.tpl b/resources/views/default/admin/user/edit.tpl index 6ca69e95d..5f57301be 100644 --- a/resources/views/default/admin/user/edit.tpl +++ b/resources/views/default/admin/user/edit.tpl @@ -120,23 +120,20 @@