From 2e60c0db88292d87ff667c5f043fc0761b02f88c Mon Sep 17 00:00:00 2001 From: zhaoxiang Date: Sat, 22 Jun 2019 18:36:36 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E5=85=A8=E9=9D=A2=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=9D=83=E9=99=90=E7=BB=84=E7=AD=89=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Auth.php | 46 ++++++++++++++------------- application/admin/controller/User.php | 14 ++++---- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/application/admin/controller/Auth.php b/application/admin/controller/Auth.php index 6d091b0..ac8399b 100644 --- a/application/admin/controller/Auth.php +++ b/application/admin/controller/Auth.php @@ -30,12 +30,15 @@ class Auth extends Base { $keywords = $this->request->get('keywords', ''); $status = $this->request->get('status', ''); - $where['name'] = ['like', "%{$keywords}%"]; - if ($status === '1' || $status === '0') { - $where['status'] = $status; + $obj = new AdminAuthGroup(); + if (strlen($status)) { + $obj = $obj->where('status', $status); } - $listObj = (new AdminAuthGroup())->where($where)->order('id DESC') - ->paginate($limit, false, ['page' => $start])->toArray(); + if ($keywords) { + $obj = $obj->where('name', 'like', $keywords); + } + + $listObj = $obj->order('id DESC')->paginate($limit, false, ['page' => $start])->toArray(); return $this->buildSuccess([ 'list' => $listObj['data'], @@ -45,11 +48,11 @@ class Auth extends Base { /** * 获取全部已开放的可选组 - * @author zhaoxiang * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException + * @author zhaoxiang */ public function getGroups() { $listInfo = (new AdminAuthGroup())->where(['status' => 1])->order('id', 'DESC')->select(); @@ -71,15 +74,15 @@ class Auth extends Base { * @author zhaoxiang */ public function getRuleList() { - $groupId = $this->request->get('groupId', 0); + $groupId = $this->request->get('group_id', 0); $list = (new AdminMenu)->where([])->order('sort', 'ASC')->select(); $list = Tools::buildArrFromObj($list); - $list = listToTree($list); + $list = Tools::listToTree($list); $rules = []; if ($groupId) { - $rules = (new AdminAuthRule())->where(['groupId' => $groupId])->select(); + $rules = (new AdminAuthRule())->where(['group_id' => $groupId])->select(); $rules = Tools::buildArrFromObj($rules); $rules = array_column($rules, 'url'); } @@ -113,8 +116,8 @@ class Auth extends Base { foreach ($rules as $value) { if ($value) { $insertData[] = [ - 'groupId' => $res->id, - 'url' => $value + 'group_id' => $res->id, + 'url' => $value ]; } } @@ -181,21 +184,20 @@ class Auth extends Base { return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数'); } - $listInfo = (new AdminAuthGroupAccess())->where(['groupId' => ['like', "%{$id}%"]])->select(); + $listInfo = (new AdminAuthGroupAccess())->where('find_in_set("' . $id . '", `group_id`)')->select(); if ($listInfo) { foreach ($listInfo as $value) { - $valueArr = $value->toArray(); - $oldGroupArr = explode(',', $valueArr['groupId']); + $oldGroupArr = explode(',', $value->group_id); $key = array_search($id, $oldGroupArr); unset($oldGroupArr[$key]); $newData = implode(',', $oldGroupArr); - $value->groupId = $newData; + $value->group_id = $newData; $value->save(); } } AdminAuthGroup::destroy($id); - AdminAuthRule::destroy(['groupId' => $id]); + AdminAuthRule::destroy(['group_id' => $id]); return $this->buildSuccess([]); } @@ -214,12 +216,12 @@ class Auth extends Base { return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数'); } $oldInfo = AdminAuthGroupAccess::get(['uid' => $uid])->toArray(); - $oldGroupArr = explode(',', $oldInfo['groupId']); + $oldGroupArr = explode(',', $oldInfo['group_id']); $key = array_search($gid, $oldGroupArr); unset($oldGroupArr[$key]); $newData = implode(',', $oldGroupArr); $res = AdminAuthGroupAccess::update([ - 'groupId' => $newData + 'group_id' => $newData ], [ 'uid' => $uid ]); @@ -266,7 +268,7 @@ class Auth extends Base { private function editRule() { $postData = $this->request->post(); $needAdd = []; - $has = (new AdminAuthRule())->where(['groupId' => $postData['id']])->select(); + $has = (new AdminAuthRule())->where(['group_id' => $postData['id']])->select(); $has = Tools::buildArrFromObj($has); $hasRule = array_column($has, 'url'); $needDel = array_flip($hasRule); @@ -274,7 +276,7 @@ class Auth extends Base { if (!empty($value)) { if (!in_array($value, $hasRule)) { $data['url'] = $value; - $data['groupId'] = $postData['id']; + $data['group_id'] = $postData['id']; $needAdd[] = $data; } else { unset($needDel[$value]); @@ -287,8 +289,8 @@ class Auth extends Base { if (count($needDel)) { $urlArr = array_keys($needDel); AdminAuthRule::destroy([ - 'groupId' => $postData['id'], - 'url' => ['in', $urlArr] + 'group_id' => $postData['id'], + 'url' => ['in', $urlArr] ]); } } diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index 298e385..b78017d 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -121,11 +121,11 @@ class User extends Base { return $this->buildFailed(ReturnCode::PARAM_INVALID, '非法操作'); } - $totalNum = (new AdminAuthGroupAccess())->where('find_in_set("' . $gid . '", `groupId`)')->count(); + $totalNum = (new AdminAuthGroupAccess())->where('find_in_set("' . $gid . '", `group_id`)')->count(); $start = $limit * ($page - 1); $sql = "SELECT au.* FROM admin_user as au LEFT JOIN admin_auth_group_access as aaga " . - " ON aaga.`uid` = au.`id` WHERE find_in_set('{$gid}', aaga.`groupId`) " . - " ORDER BY au.regTime DESC LIMIT {$start}, {$limit}"; + " ON aaga.`uid` = au.`id` WHERE find_in_set('{$gid}', aaga.`group_id`) " . + " ORDER BY au.create_time DESC LIMIT {$start}, {$limit}"; $userInfo = Db::query($sql); $uidArr = array_column($userInfo, 'id'); @@ -134,11 +134,11 @@ class User extends Base { foreach ($userInfo as $key => $value) { if (isset($userData[$value['id']])) { - $userInfo[$key]['lastLoginIp'] = long2ip($userData[$value['id']]['lastLoginIp']); - $userInfo[$key]['loginTimes'] = $userData[$value['id']]['loginTimes']; - $userInfo[$key]['lastLoginTime'] = date('Y-m-d H:i:s', $userData[$value['id']]['lastLoginTime']); + $userInfo[$key]['last_login_ip'] = long2ip($userData[$value['id']]['last_login_ip']); + $userInfo[$key]['login_times'] = $userData[$value['id']]['login_times']; + $userInfo[$key]['last_login_time'] = date('Y-m-d H:i:s', $userData[$value['id']]['last_login_time']); } - $userInfo[$key]['regIp'] = long2ip($userInfo[$key]['regIp']); + $userInfo[$key]['create_ip'] = long2ip($userInfo[$key]['create_ip']); } return $this->buildSuccess([