!18 修复及优化

Merge pull request !18 from Stefan阿钢/master
This commit is contained in:
Zhao 2019-10-23 15:58:14 +08:00 committed by Gitee
commit 1134aedf45
46 changed files with 189 additions and 261 deletions

View File

@ -7,7 +7,6 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminApp; use app\model\AdminApp;
use app\model\AdminList; use app\model\AdminList;
use app\model\AdminGroup; use app\model\AdminGroup;
@ -16,6 +15,7 @@ use app\util\Strs;
use app\util\Tools; use app\util\Tools;
class App extends Base { class App extends Base {
/** /**
* 获取应用列表 * 获取应用列表
* @return array * @return array
@ -23,7 +23,6 @@ class App extends Base {
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT')); $limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
$start = $this->request->get('page', 1); $start = $this->request->get('page', 1);
$keywords = $this->request->get('keywords', ''); $keywords = $this->request->get('keywords', '');
@ -44,7 +43,7 @@ class App extends Base {
break; break;
} }
} }
$listObj = $obj->order('app_add_time DESC')->paginate($limit, false, ['page' => $start])->toArray(); $listObj = $obj->order('app_add_time', 'DESC')->paginate($limit, false, ['page' => $start])->toArray();
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listObj['data'], 'list' => $listObj['data'],
@ -103,9 +102,9 @@ class App extends Base {
'app_name' => $postData['app_name'], 'app_name' => $postData['app_name'],
'app_info' => $postData['app_info'], 'app_info' => $postData['app_info'],
'app_group' => $postData['app_group'], 'app_group' => $postData['app_group'],
'app_add_time' => time(), 'app_add_time' => time(),
'app_api' => '', 'app_api' => '',
'app_api_show' => '', 'app_api_show' => ''
]; ];
if (isset($postData['app_api']) && $postData['app_api']) { if (isset($postData['app_api']) && $postData['app_api']) {
$appApi = []; $appApi = [];
@ -118,9 +117,9 @@ class App extends Base {
$res = AdminApp::create($data); $res = AdminApp::create($data);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -132,21 +131,19 @@ class App extends Base {
$id = $this->request->get('id'); $id = $this->request->get('id');
$status = $this->request->get('status'); $status = $this->request->get('status');
$res = AdminApp::update([ $res = AdminApp::update([
'id' => $id,
'app_status' => $status 'app_status' => $status
], [
'id' => $id
]); ]);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
$appInfo = AdminApp::get($id);
cache('AccessToken:' . $appInfo['app_secret'], null);
if($oldWiki = cache('WikiLogin:' . $id)) {
cache('WikiLogin:' . $oldWiki, null);
}
return $this->buildSuccess();
} }
$appInfo = AdminApp::get($id);
cache('AccessToken:' . $appInfo['app_secret'], null);
if($oldWiki = cache('WikiLogin:' . $id)) {
cache('WikiLogin:' . $oldWiki, null);
}
return $this->buildSuccess();
} }
/** /**
@ -157,12 +154,12 @@ class App extends Base {
public function edit() { public function edit() {
$postData = $this->request->post(); $postData = $this->request->post();
$data = [ $data = [
'app_secret' => $postData['app_secret'],
'app_name' => $postData['app_name'], 'app_name' => $postData['app_name'],
'app_info' => $postData['app_info'], 'app_info' => $postData['app_info'],
'app_group' => $postData['app_group'], 'app_group' => $postData['app_group'],
'app_secret' => $postData['app_secret'],
'app_api' => '', 'app_api' => '',
'app_api_show' => '', 'app_api_show' => ''
]; ];
if (isset($postData['app_api']) && $postData['app_api']) { if (isset($postData['app_api']) && $postData['app_api']) {
$appApi = []; $appApi = [];
@ -175,15 +172,15 @@ class App extends Base {
$res = AdminApp::update($data, ['id' => $postData['id']]); $res = AdminApp::update($data, ['id' => $postData['id']]);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
$appInfo = AdminApp::get($postData['id']);
cache('AccessToken:' . $appInfo['app_secret'], null);
if($oldWiki = cache('WikiLogin:' . $postData['id'])) {
cache('WikiLogin:' . $oldWiki, null);
}
return $this->buildSuccess();
} }
$appInfo = AdminApp::get($postData['id']);
cache('AccessToken:' . $appInfo['app_secret'], null);
if($oldWiki = cache('WikiLogin:' . $postData['id'])) {
cache('WikiLogin:' . $oldWiki, null);
}
return $this->buildSuccess();
} }
/** /**

View File

@ -7,13 +7,12 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminApp; use app\model\AdminApp;
use app\model\AdminAppGroup; use app\model\AdminAppGroup;
use app\util\ReturnCode; use app\util\ReturnCode;
use app\util\Tools;
class AppGroup extends Base { class AppGroup extends Base {
/** /**
* 获取应用组列表 * 获取应用组列表
* @return array * @return array
@ -75,15 +74,14 @@ class AppGroup extends Base {
$id = $this->request->get('id'); $id = $this->request->get('id');
$status = $this->request->get('status'); $status = $this->request->get('status');
$res = AdminAppGroup::update([ $res = AdminAppGroup::update([
'id' => $id,
'status' => $status 'status' => $status
], [
'id' => $id
]); ]);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -96,9 +94,9 @@ class AppGroup extends Base {
$res = AdminAppGroup::create($postData); $res = AdminAppGroup::create($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -111,9 +109,9 @@ class AppGroup extends Base {
$res = AdminAppGroup::update($postData); $res = AdminAppGroup::update($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**

View File

@ -7,7 +7,6 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminAuthGroup; use app\model\AdminAuthGroup;
use app\model\AdminAuthGroupAccess; use app\model\AdminAuthGroupAccess;
use app\model\AdminAuthRule; use app\model\AdminAuthRule;
@ -24,7 +23,6 @@ class Auth extends Base {
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT')); $limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
$start = $this->request->get('page', 1); $start = $this->request->get('page', 1);
$keywords = $this->request->get('keywords', ''); $keywords = $this->request->get('keywords', '');
@ -38,7 +36,7 @@ class Auth extends Base {
$obj = $obj->whereLike('name', "%{$keywords}%"); $obj = $obj->whereLike('name', "%{$keywords}%");
} }
$listObj = $obj->order('id DESC')->paginate($limit, false, ['page' => $start])->toArray(); $listObj = $obj->order('id', 'DESC')->paginate($limit, false, ['page' => $start])->toArray();
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listObj['data'], 'list' => $listObj['data'],
@ -76,7 +74,7 @@ class Auth extends Base {
public function getRuleList() { public function getRuleList() {
$groupId = $this->request->get('group_id', 0); $groupId = $this->request->get('group_id', 0);
$list = (new AdminMenu)->where([])->order('sort', 'ASC')->select(); $list = (new AdminMenu)->order('sort', 'ASC')->select();
$list = Tools::buildArrFromObj($list); $list = Tools::buildArrFromObj($list);
$list = Tools::listToTree($list); $list = Tools::listToTree($list);
@ -110,22 +108,21 @@ class Auth extends Base {
$res = AdminAuthGroup::create($postData); $res = AdminAuthGroup::create($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
if ($rules) {
$insertData = [];
foreach ($rules as $value) {
if ($value) {
$insertData[] = [
'group_id' => $res->id,
'url' => $value
];
}
}
(new AdminAuthRule())->saveAll($insertData);
}
return $this->buildSuccess();
} }
if ($rules) {
$insertData = [];
foreach ($rules as $value) {
if ($value) {
$insertData[] = [
'group_id' => $res->id,
'url' => $value
];
}
}
(new AdminAuthRule())->saveAll($insertData);
}
return $this->buildSuccess();
} }
/** /**
@ -142,9 +139,9 @@ class Auth extends Base {
]); ]);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -165,9 +162,9 @@ class Auth extends Base {
$res = AdminAuthGroup::update($postData); $res = AdminAuthGroup::update($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -227,9 +224,9 @@ class Auth extends Base {
]); ]);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -291,5 +288,4 @@ class Auth extends Base {
(new AdminAuthRule())->whereIn('url', $urlArr)->where('group_id', $postData['id'])->delete(); (new AdminAuthRule())->whereIn('url', $urlArr)->where('group_id', $postData['id'])->delete();
} }
} }
} }

View File

@ -74,5 +74,4 @@ class Base extends Controller {
$this->debug[] = $data; $this->debug[] = $data;
} }
} }
} }

View File

@ -7,7 +7,6 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminFields; use app\model\AdminFields;
use app\model\AdminList; use app\model\AdminList;
use app\util\DataType; use app\util\DataType;
@ -15,6 +14,7 @@ use app\util\ReturnCode;
use app\util\Tools; use app\util\Tools;
class Fields extends Base { class Fields extends Base {
private $dataType = array( private $dataType = array(
DataType::TYPE_INTEGER => 'Integer', DataType::TYPE_INTEGER => 'Integer',
DataType::TYPE_STRING => 'String', DataType::TYPE_STRING => 'String',
@ -42,21 +42,20 @@ class Fields extends Base {
$start = $this->request->get('page', 1); $start = $this->request->get('page', 1);
$hash = $this->request->get('hash', ''); $hash = $this->request->get('hash', '');
if (!empty($hash)) { if (empty($hash)) {
$listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 0])
->paginate($limit, false, ['page' => $start])->toArray();
$apiInfo = (new AdminList())->where('hash', $hash)->find();
return $this->buildSuccess([
'list' => $listObj['data'],
'count' => $listObj['total'],
'dataType' => $this->dataType,
'apiInfo' => $apiInfo
]);
} else {
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数'); return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
} }
$listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 0])
->paginate($limit, false, ['page' => $start])->toArray();
$apiInfo = (new AdminList())->where('hash', $hash)->find();
return $this->buildSuccess([
'list' => $listObj['data'],
'count' => $listObj['total'],
'dataType' => $this->dataType,
'apiInfo' => $apiInfo
]);
} }
/** /**
@ -70,21 +69,20 @@ class Fields extends Base {
$start = $this->request->get('page', 1); $start = $this->request->get('page', 1);
$hash = $this->request->get('hash', ''); $hash = $this->request->get('hash', '');
if (!empty($hash)) { if (empty($hash)) {
$listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 1])
->paginate($limit, false, ['page' => $start])->toArray();
$apiInfo = (new AdminList())->where('hash', $hash)->find();
return $this->buildSuccess([
'list' => $listObj['data'],
'count' => $listObj['total'],
'dataType' => $this->dataType,
'apiInfo' => $apiInfo
]);
} else {
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数'); return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
} }
$listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 1])
->paginate($limit, false, ['page' => $start])->toArray();
$apiInfo = (new AdminList())->where('hash', $hash)->find();
return $this->buildSuccess([
'list' => $listObj['data'],
'count' => $listObj['total'],
'dataType' => $this->dataType,
'apiInfo' => $apiInfo
]);
} }
/** /**
@ -105,9 +103,9 @@ class Fields extends Base {
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -128,9 +126,9 @@ class Fields extends Base {
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -208,10 +206,10 @@ class Fields extends Base {
$addArr = array( $addArr = array(
'field_name' => $index, 'field_name' => $index,
'show_name' => $prefix, 'show_name' => $prefix,
'hash' => $this->request->post('hash'), 'hash' => $this->request->post('hash'),
'is_must' => 1, 'is_must' => 1,
'data_type' => DataType::TYPE_ARRAY, 'data_type' => DataType::TYPE_ARRAY,
'type' => $this->request->post('type') 'type' => $this->request->post('type')
); );
$dataArr[] = $addArr; $dataArr[] = $addArr;
$prefix .= '[]'; $prefix .= '[]';
@ -222,10 +220,10 @@ class Fields extends Base {
$addArr = array( $addArr = array(
'field_name' => $index, 'field_name' => $index,
'show_name' => $prefix, 'show_name' => $prefix,
'hash' => $this->request->post('hash'), 'hash' => $this->request->post('hash'),
'is_must' => 1, 'is_must' => 1,
'data_type' => DataType::TYPE_OBJECT, 'data_type' => DataType::TYPE_OBJECT,
'type' => $this->request->post('type') 'type' => $this->request->post('type')
); );
$dataArr[] = $addArr; $dataArr[] = $addArr;
$prefix .= '{}'; $prefix .= '{}';
@ -234,10 +232,10 @@ class Fields extends Base {
$addArr = array( $addArr = array(
'field_name' => $index, 'field_name' => $index,
'show_name' => $myPre, 'show_name' => $myPre,
'hash' => $this->request->post('hash'), 'hash' => $this->request->post('hash'),
'is_must' => 1, 'is_must' => 1,
'data_type' => DataType::TYPE_STRING, 'data_type' => DataType::TYPE_STRING,
'type' => $this->request->post('type') 'type' => $this->request->post('type')
); );
if (is_numeric($datum)) { if (is_numeric($datum)) {
if (preg_match('/^\d*$/', $datum)) { if (preg_match('/^\d*$/', $datum)) {

View File

@ -7,14 +7,13 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminApp; use app\model\AdminApp;
use app\model\AdminGroup; use app\model\AdminGroup;
use app\model\AdminList; use app\model\AdminList;
use app\util\ReturnCode; use app\util\ReturnCode;
use app\util\Tools;
class InterfaceGroup extends Base { class InterfaceGroup extends Base {
/** /**
* 获取接口组列表 * 获取接口组列表
* @return array * @return array
@ -42,7 +41,7 @@ class InterfaceGroup extends Base {
break; break;
} }
} }
$listObj = $obj->order('create_time desc')->paginate($limit, false, ['page' => $start])->toArray(); $listObj = $obj->order('create_time', 'desc')->paginate($limit, false, ['page' => $start])->toArray();
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listObj['data'], 'list' => $listObj['data'],
@ -74,15 +73,14 @@ class InterfaceGroup extends Base {
$id = $this->request->get('id'); $id = $this->request->get('id');
$status = $this->request->get('status'); $status = $this->request->get('status');
$res = AdminGroup::update([ $res = AdminGroup::update([
'status' => $status 'id' => $id,
], [ 'status' => $status,
'id' => $id
]); ]);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -95,9 +93,9 @@ class InterfaceGroup extends Base {
$res = AdminGroup::create($postData); $res = AdminGroup::create($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -110,9 +108,9 @@ class InterfaceGroup extends Base {
$res = AdminGroup::update($postData); $res = AdminGroup::update($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**

View File

@ -7,7 +7,6 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminApp; use app\model\AdminApp;
use app\model\AdminFields; use app\model\AdminFields;
use app\model\AdminList; use app\model\AdminList;
@ -15,6 +14,7 @@ use app\util\ReturnCode;
use think\facade\Env; use think\facade\Env;
class InterfaceList extends Base { class InterfaceList extends Base {
/** /**
* 获取接口列表 * 获取接口列表
* @return array * @return array
@ -22,7 +22,6 @@ class InterfaceList extends Base {
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT')); $limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
$start = $this->request->get('page', 1); $start = $this->request->get('page', 1);
$keywords = $this->request->get('keywords', ''); $keywords = $this->request->get('keywords', '');
@ -79,9 +78,9 @@ class InterfaceList extends Base {
$res = AdminList::create($postData); $res = AdminList::create($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -99,11 +98,10 @@ class InterfaceList extends Base {
]); ]);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
cache('ApiInfo:' . $hash, null);
return $this->buildSuccess();
} }
cache('ApiInfo:' . $hash, null);
return $this->buildSuccess();
} }
/** /**
@ -120,11 +118,10 @@ class InterfaceList extends Base {
$res = AdminList::update($postData); $res = AdminList::update($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
cache('ApiInfo:' . $postData['hash'], null);
return $this->buildSuccess();
} }
cache('ApiInfo:' . $postData['hash'], null);
return $this->buildSuccess();
} }
/** /**

View File

@ -7,13 +7,8 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminAuthGroupAccess;
use app\model\AdminUser;
use app\model\AdminUserAction; use app\model\AdminUserAction;
use app\model\AdminUserData;
use app\util\ReturnCode; use app\util\ReturnCode;
use app\util\Tools;
class Log extends Base { class Log extends Base {
@ -24,7 +19,6 @@ class Log extends Base {
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT')); $limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
$start = $this->request->get('page', 1); $start = $this->request->get('page', 1);
$type = $this->request->get('type', ''); $type = $this->request->get('type', '');
@ -44,7 +38,7 @@ class Log extends Base {
break; break;
} }
} }
$listObj = $obj->order('add_time DESC')->paginate($limit, false, ['page' => $start])->toArray(); $listObj = $obj->order('add_time', 'DESC')->paginate($limit, false, ['page' => $start])->toArray();
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listObj['data'], 'list' => $listObj['data'],
@ -65,7 +59,5 @@ class Log extends Base {
AdminUserAction::destroy($id); AdminUserAction::destroy($id);
return $this->buildSuccess(); return $this->buildSuccess();
} }
} }

View File

@ -7,7 +7,6 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminAuthGroupAccess; use app\model\AdminAuthGroupAccess;
use app\model\AdminAuthRule; use app\model\AdminAuthRule;
use app\model\AdminMenu; use app\model\AdminMenu;
@ -121,5 +120,4 @@ class Login extends Base {
} }
} }
} }
} }

View File

@ -7,7 +7,6 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminMenu; use app\model\AdminMenu;
use app\util\ReturnCode; use app\util\ReturnCode;
use app\util\Tools; use app\util\Tools;
@ -21,7 +20,7 @@ class Menu extends Base {
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$list = (new AdminMenu)->where([])->order('sort', 'ASC')->select(); $list = (new AdminMenu)->order('sort', 'ASC')->select();
$list = Tools::buildArrFromObj($list); $list = Tools::buildArrFromObj($list);
$list = Tools::formatTree(Tools::listToTree($list)); $list = Tools::formatTree(Tools::listToTree($list));
@ -62,9 +61,9 @@ class Menu extends Base {
]); ]);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -80,9 +79,9 @@ class Menu extends Base {
$res = AdminMenu::update($postData); $res = AdminMenu::update($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess();
} }
return $this->buildSuccess();
} }
/** /**
@ -98,11 +97,9 @@ class Menu extends Base {
$childNum = AdminMenu::where(['fid' => $id])->count(); $childNum = AdminMenu::where(['fid' => $id])->count();
if ($childNum) { if ($childNum) {
return $this->buildFailed(ReturnCode::INVALID, '当前菜单存在子菜单,不可以被删除!'); return $this->buildFailed(ReturnCode::INVALID, '当前菜单存在子菜单,不可以被删除!');
} else {
AdminMenu::destroy($id);
return $this->buildSuccess();
} }
} AdminMenu::destroy($id);
return $this->buildSuccess();
}
} }

View File

@ -1,9 +1,11 @@
<?php <?php
namespace app\admin\controller; namespace app\admin\controller;
use app\util\ReturnCode; use app\util\ReturnCode;
class Miss extends Base { class Miss extends Base {
public function index() { public function index() {
if ($this->request->isOptions()) { if ($this->request->isOptions()) {
return $this->buildSuccess(); return $this->buildSuccess();

View File

@ -7,7 +7,6 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminAuthGroupAccess; use app\model\AdminAuthGroupAccess;
use app\model\AdminUser; use app\model\AdminUser;
use app\util\ReturnCode; use app\util\ReturnCode;
@ -297,7 +296,6 @@ class ThirdLogin extends Base {
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
private function doLogin($openid, $userDetail) { private function doLogin($openid, $userDetail) {
$userInfo = AdminUser::get(['openid' => $openid]); $userInfo = AdminUser::get(['openid' => $openid]);
if (empty($userInfo)) { if (empty($userInfo)) {
$userInfo = AdminUser::create([ $userInfo = AdminUser::create([
@ -345,5 +343,4 @@ class ThirdLogin extends Base {
return $this->buildSuccess($userInfo, '登录成功'); return $this->buildSuccess($userInfo, '登录成功');
} }
} }

View File

@ -7,7 +7,6 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\model\AdminAuthGroupAccess; use app\model\AdminAuthGroupAccess;
use app\model\AdminUser; use app\model\AdminUser;
use app\model\AdminUserData; use app\model\AdminUserData;
@ -24,7 +23,6 @@ class User extends Base {
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT')); $limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
$start = $this->request->get('page', 1); $start = $this->request->get('page', 1);
$type = $this->request->get('type', '', 'intval'); $type = $this->request->get('type', '', 'intval');
@ -46,7 +44,7 @@ class User extends Base {
} }
} }
$listObj = $obj->order('create_time DESC') $listObj = $obj->order('create_time', 'DESC')
->paginate($limit, false, ['page' => $start])->each(function($item, $key){ ->paginate($limit, false, ['page' => $start])->each(function($item, $key){
$item->userData; $item->userData;
})->toArray(); })->toArray();
@ -96,14 +94,13 @@ class User extends Base {
$res = AdminUser::create($postData); $res = AdminUser::create($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
AdminAuthGroupAccess::create([
'uid' => $res->id,
'group_id' => $groups
]);
return $this->buildSuccess();
} }
AdminAuthGroupAccess::create([
'uid' => $res->id,
'group_id' => $groups
]);
return $this->buildSuccess();
} }
/** /**
@ -161,13 +158,12 @@ class User extends Base {
]); ]);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
if($oldAdmin = cache('Login:' . $id)) {
cache('Login:' . $oldAdmin, null);
}
return $this->buildSuccess();
} }
if($oldAdmin = cache('Login:' . $id)) {
cache('Login:' . $oldAdmin, null);
}
return $this->buildSuccess();
} }
/** /**
@ -191,26 +187,25 @@ class User extends Base {
$res = AdminUser::update($postData); $res = AdminUser::update($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
$has = AdminAuthGroupAccess::get(['uid' => $postData['id']]);
if ($has) {
AdminAuthGroupAccess::update([
'group_id' => $groups
], [
'uid' => $postData['id'],
]);
} else {
AdminAuthGroupAccess::create([
'uid' => $postData['id'],
'group_id' => $groups
]);
}
if($oldAdmin = cache('Login:' . $postData['id'])) {
cache('Login:' . $oldAdmin, null);
}
return $this->buildSuccess();
} }
$has = AdminAuthGroupAccess::get(['uid' => $postData['id']]);
if ($has) {
AdminAuthGroupAccess::update([
'group_id' => $groups
], [
'uid' => $postData['id'],
]);
} else {
AdminAuthGroupAccess::create([
'uid' => $postData['id'],
'group_id' => $groups
]);
}
if($oldAdmin = cache('Login:' . $postData['id'])) {
cache('Login:' . $oldAdmin, null);
}
return $this->buildSuccess();
} }
/** /**
@ -240,16 +235,15 @@ class User extends Base {
$res = AdminUser::update($postData); $res = AdminUser::update($postData);
if ($res === false) { if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
$userData = AdminUserData::get(['uid' => $postData['id']]);
$userData->head_img = $headImg;
$userData->save();
if($oldWiki = cache('WikiLogin:' . $postData['id'])) {
cache('WikiLogin:' . $oldWiki, null);
}
return $this->buildSuccess();
} }
$userData = AdminUserData::get(['uid' => $postData['id']]);
$userData->head_img = $headImg;
$userData->save();
if($oldWiki = cache('WikiLogin:' . $postData['id'])) {
cache('WikiLogin:' . $oldWiki, null);
}
return $this->buildSuccess();
} }
/** /**
@ -274,7 +268,5 @@ class User extends Base {
} }
return $this->buildSuccess(); return $this->buildSuccess();
} }
} }

View File

@ -7,7 +7,6 @@
namespace app\api\controller; namespace app\api\controller;
use app\util\ReturnCode; use app\util\ReturnCode;
use think\Controller; use think\Controller;
@ -51,5 +50,4 @@ class Base extends Controller {
$this->debug[] = $data; $this->debug[] = $data;
} }
} }
} }

View File

@ -7,7 +7,6 @@
namespace app\api\controller; namespace app\api\controller;
use app\model\AdminApp; use app\model\AdminApp;
use app\util\ReturnCode; use app\util\ReturnCode;
use app\util\Strs; use app\util\Strs;
@ -85,5 +84,4 @@ class BuildToken extends Base {
return md5($preStr); return md5($preStr);
} }
} }

View File

@ -2,20 +2,20 @@
namespace app\api\controller; namespace app\api\controller;
use think\facade\App; use think\facade\App;
class Index extends Base { class Index extends Base {
public function index() { public function index() {
$this->debug([ $this->debug([
'TpVersion' => App::version() 'TpVersion' => App::version()
]); ]);
return $this->buildSuccess([ return $this->buildSuccess([
'Product' => config('apiadmin.APP_NAME'), 'Product' => config('apiadmin.APP_NAME'),
'Version' => config('apiadmin.APP_VERSION'), 'Version' => config('apiadmin.APP_VERSION'),
'Company' => config('apiadmin.COMPANY_NAME'), 'Company' => config('apiadmin.COMPANY_NAME'),
'ToYou' => "I'm glad to meet you终于等到你" 'ToYou' => "I'm glad to meet you终于等到你"
]); ]);
} }
} }

View File

@ -2,22 +2,22 @@
namespace app\api\controller; namespace app\api\controller;
use app\util\StrRandom; use app\util\StrRandom;
use think\facade\App; use think\facade\App;
class Miss extends Base { class Miss extends Base {
public function index() { public function index() {
$this->debug([ $this->debug([
'TpVersion' => App::version(), 'TpVersion' => App::version(),
'Float' => StrRandom::randomPhone() 'Float' => StrRandom::randomPhone()
]); ]);
return $this->buildSuccess([ return $this->buildSuccess([
'Product' => config('apiadmin.APP_NAME'), 'Product' => config('apiadmin.APP_NAME'),
'Version' => config('apiadmin.APP_VERSION'), 'Version' => config('apiadmin.APP_VERSION'),
'Company' => config('apiadmin.COMPANY_NAME'), 'Company' => config('apiadmin.COMPANY_NAME'),
'ToYou' => "I'm glad to meet you终于等到你" 'ToYou' => "I'm glad to meet you终于等到你"
]); ]);
} }
} }

View File

@ -20,7 +20,7 @@ class Install extends Command {
} }
/** /**
* php think apiadmin:install --db mysql://root:123456@127.0.0.1:3306/apiadmin#utf8 * php think apiadmin:install --db mysql://root:123456@127.0.0.1:3306/apiadmin#utf8mb4
* @param Input $input * @param Input $input
* @param Output $output * @param Output $output
* @return int|void|null * @return int|void|null

View File

@ -40,5 +40,4 @@ class AdminLog {
return $next($request); return $next($request);
} }
} }

View File

@ -53,7 +53,6 @@ class AdminPermission {
} else { } else {
return true; return true;
} }
} }
/** /**
@ -93,5 +92,4 @@ class AdminPermission {
return []; return [];
} }
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\http\middleware;
use think\facade\Config; use think\facade\Config;
class AdminResponse { class AdminResponse {
public function handle($request, \Closure $next) { public function handle($request, \Closure $next) {
return $next($request)->header(Config::get('apiadmin.CROSS_DOMAIN')); return $next($request)->header(Config::get('apiadmin.CROSS_DOMAIN'));
} }

View File

@ -5,6 +5,7 @@ namespace app\http\middleware;
use think\facade\Config; use think\facade\Config;
class ApiResponse { class ApiResponse {
public function handle($request, \Closure $next) { public function handle($request, \Closure $next) {
return $next($request)->header(Config::get('apiadmin.CROSS_DOMAIN')); return $next($request)->header(Config::get('apiadmin.CROSS_DOMAIN'));
} }

View File

@ -8,7 +8,6 @@ use app\util\ReturnCode;
use think\facade\Cache; use think\facade\Cache;
use think\facade\Validate; use think\facade\Validate;
class RequestFilter { class RequestFilter {
/** /**

2
application/install/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
!.gitignore
lock.ini

View File

@ -2,7 +2,6 @@
namespace app\model; namespace app\model;
class AdminApp extends Base { class AdminApp extends Base {
} }

View File

@ -7,7 +7,6 @@
namespace app\model; namespace app\model;
class AdminAppGroup extends Base { class AdminAppGroup extends Base {
} }

View File

@ -7,11 +7,9 @@
namespace app\model; namespace app\model;
class AdminAuthGroup extends Base { class AdminAuthGroup extends Base {
public function rules() { public function rules() {
return $this->hasMany('AdminAuthRule', 'group_id', 'id'); return $this->hasMany('AdminAuthRule', 'group_id', 'id');
} }
} }

View File

@ -7,7 +7,6 @@
namespace app\model; namespace app\model;
class AdminAuthGroupAccess extends Base { class AdminAuthGroupAccess extends Base {
} }

View File

@ -7,7 +7,6 @@
namespace app\model; namespace app\model;
class AdminAuthRule extends Base { class AdminAuthRule extends Base {
} }

View File

@ -7,7 +7,7 @@
namespace app\model; namespace app\model;
class AdminGroup extends Base { class AdminGroup extends Base {
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
} }

View File

@ -2,7 +2,6 @@
namespace app\model; namespace app\model;
class AdminMenu extends Base { class AdminMenu extends Base {
} }

View File

@ -6,12 +6,11 @@
namespace app\model; namespace app\model;
class AdminUser extends Base { class AdminUser extends Base {
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
public function userData() { public function userData() {
return $this->hasOne('AdminUserData', 'uid', 'id'); return $this->hasOne('AdminUserData', 'uid', 'id');
} }
} }

View File

@ -7,7 +7,6 @@
namespace app\model; namespace app\model;
class AdminUserAction extends Base { class AdminUserAction extends Base {
} }

View File

@ -6,7 +6,6 @@
namespace app\model; namespace app\model;
class AdminUserData extends Base { class AdminUserData extends Base {
} }

View File

@ -7,7 +7,6 @@
namespace app\model; namespace app\model;
use think\Model; use think\Model;
class Base extends Model { class Base extends Model {

View File

@ -6,7 +6,6 @@
namespace app\util; namespace app\util;
use think\facade\Env; use think\facade\Env;
class ApiLogTool { class ApiLogTool {
@ -95,6 +94,4 @@ class ApiLogTool {
@fwrite($handle, date('Y-m-d H:i:s') . "\t" . $log . "\r\n"); @fwrite($handle, date('Y-m-d H:i:s') . "\t" . $log . "\r\n");
@fclose($handle); @fclose($handle);
} }
} }

View File

@ -7,8 +7,8 @@
namespace app\util; namespace app\util;
class BuildName { class BuildName {
private $arrXing, $numbXing; private $arrXing, $numbXing;
private $arrMing, $numbMing; private $arrMing, $numbMing;
@ -66,7 +66,6 @@ class BuildName {
$this->numbMing = count($this->arrMing); $this->numbMing = count($this->arrMing);
} }
// 获取姓 // 获取姓
private function getXing() { private function getXing() {
// mt_rand() 比rand()方法快四倍而且生成的随机数比rand()生成的伪随机数无规律。 // mt_rand() 比rand()方法快四倍而且生成的随机数比rand()生成的伪随机数无规律。
@ -79,7 +78,6 @@ class BuildName {
return $this->arrMing[mt_rand(0, $this->numbMing - 1)]; return $this->arrMing[mt_rand(0, $this->numbMing - 1)];
} }
// 获取名字 // 获取名字
public function getName($type = 2) { public function getName($type = 2) {
switch ($type) { switch ($type) {

View File

@ -8,7 +8,6 @@
namespace app\util; namespace app\util;
class DataType { class DataType {
const TYPE_INTEGER = 1; const TYPE_INTEGER = 1;
@ -20,5 +19,4 @@ class DataType {
const TYPE_ENUM = 7; const TYPE_ENUM = 7;
const TYPE_MOBILE = 8; const TYPE_MOBILE = 8;
const TYPE_OBJECT = 9; const TYPE_OBJECT = 9;
} }

View File

@ -7,7 +7,6 @@
namespace app\util; namespace app\util;
class MockConf { class MockConf {
public function mockToApiAdmin() { public function mockToApiAdmin() {
@ -17,5 +16,4 @@ class MockConf {
public function apiAdminToMock() { public function apiAdminToMock() {
} }
} }

View File

@ -41,9 +41,8 @@ class ReturnCode {
const UNKNOWN = -998; const UNKNOWN = -998;
const EXCEPTION = -999; const EXCEPTION = -999;
static public function getConstants() { public static function getConstants() {
$oClass = new \ReflectionClass(__CLASS__); $oClass = new \ReflectionClass(__CLASS__);
return $oClass->getConstants(); return $oClass->getConstants();
} }
}
}

View File

@ -7,7 +7,6 @@
namespace app\util; namespace app\util;
class StrRandom { class StrRandom {
/** /**
@ -182,5 +181,4 @@ class StrRandom {
return $prefixArr[0] . '0000' . self::randomDate('Ymd') . Strs::randString(3, 1) . $suffixArr[0]; return $prefixArr[0] . '0000' . self::randomDate('Ymd') . Strs::randString(3, 1) . $suffixArr[0];
} }
} }

View File

@ -8,6 +8,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com> // | Author: liu21st <liu21st@gmail.com>
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\util; namespace app\util;
class Strs { class Strs {
@ -17,7 +18,7 @@ class Strs {
* @access public * @access public
* @return string * @return string
*/ */
static public function uuid() { public static function uuid() {
$charId = md5(uniqid(mt_rand(), true)); $charId = md5(uniqid(mt_rand(), true));
$hyphen = chr(45); $hyphen = chr(45);
$uuid = chr(123) $uuid = chr(123)
@ -35,7 +36,7 @@ class Strs {
* 生成Guid主键 * 生成Guid主键
* @return Boolean * @return Boolean
*/ */
static public function keyGen() { public static function keyGen() {
return str_replace('-', '', substr(self::uuid(), 1, -1)); return str_replace('-', '', substr(self::uuid(), 1, -1));
} }
@ -44,7 +45,7 @@ class Strs {
* @param string $string 字符串 * @param string $string 字符串
* @return Boolean * @return Boolean
*/ */
static public function isUtf8($string) { public static function isUtf8($string) {
$len = strlen($string); $len = strlen($string);
for ($i = 0; $i < $len; $i++) { for ($i = 0; $i < $len; $i++) {
$c = ord($string[$i]); $c = ord($string[$i]);
@ -79,7 +80,7 @@ class Strs {
* @param bool $suffix 截断显示字符 * @param bool $suffix 截断显示字符
* @return string * @return string
*/ */
static public function mSubStr($str, $start = 0, $length, $charset = "utf-8", $suffix = true) { public static function mSubStr($str, $start = 0, $length, $charset = "utf-8", $suffix = true) {
if (function_exists("mb_substr")) if (function_exists("mb_substr"))
$slice = mb_substr($str, $start, $length, $charset); $slice = mb_substr($str, $start, $length, $charset);
elseif (function_exists('iconv_substr')) { elseif (function_exists('iconv_substr')) {
@ -105,7 +106,7 @@ class Strs {
* @param string $addChars 额外字符 * @param string $addChars 额外字符
* @return string * @return string
*/ */
static public function randString($len = 6, $type = '', $addChars = '') { public static function randString($len = 6, $type = '', $addChars = '') {
$str = ''; $str = '';
switch ($type) { switch ($type) {
case 0: case 0:
@ -152,7 +153,7 @@ class Strs {
* 0 字母 1 数字 其它 混合 * 0 字母 1 数字 其它 混合
* @return string * @return string
*/ */
static public function buildCountRand($number, $length = 4, $mode = 1) { public static function buildCountRand($number, $length = 4, $mode = 1) {
if ($mode == 1 && $length < strlen($number)) { if ($mode == 1 && $length < strlen($number)) {
//不足以生成一定数量的不重复数字 //不足以生成一定数量的不重复数字
return false; return false;
@ -182,7 +183,7 @@ class Strs {
* @param integer $number 生成数量 * @param integer $number 生成数量
* @return string | array * @return string | array
*/ */
static public function buildFormatRand($format, $number = 1) { public static function buildFormatRand($format, $number = 1) {
$str = array(); $str = array();
$length = strlen($format); $length = strlen($format);
for ($j = 0; $j < $number; $j++) { for ($j = 0; $j < $number; $j++) {
@ -216,12 +217,12 @@ class Strs {
* @param integer $max 最大值 * @param integer $max 最大值
* @return string * @return string
*/ */
static public function randNumber($min, $max) { public static function randNumber($min, $max) {
return sprintf("%0" . strlen($max) . "d", mt_rand($min, $max)); return sprintf("%0" . strlen($max) . "d", mt_rand($min, $max));
} }
// 自动转换字符集 支持数组转换 // 自动转换字符集 支持数组转换
static public function autoCharset($string, $from = 'gbk', $to = 'utf-8') { public static function autoCharset($string, $from = 'gbk', $to = 'utf-8') {
$from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from; $from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from;
$to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to; $to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to;
if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) { if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) {
@ -249,4 +250,4 @@ class Strs {
return $string; return $string;
} }
} }
} }

View File

@ -7,7 +7,6 @@
namespace app\util; namespace app\util;
class Tools { class Tools {
public static function getDate($timestamp) { public static function getDate($timestamp) {

View File

@ -6,7 +6,6 @@
namespace app\wiki\controller; namespace app\wiki\controller;
use app\model\AdminApp; use app\model\AdminApp;
use app\model\AdminFields; use app\model\AdminFields;
use app\model\AdminGroup; use app\model\AdminGroup;
@ -179,5 +178,4 @@ class Api extends Base {
return $this->buildSuccess([], '登出成功'); return $this->buildSuccess([], '登出成功');
} }
} }

View File

@ -7,7 +7,6 @@
namespace app\wiki\controller; namespace app\wiki\controller;
use app\util\ReturnCode; use app\util\ReturnCode;
use think\Controller; use think\Controller;
@ -39,5 +38,4 @@ class Base extends Controller {
return $return; return $return;
} }
} }

View File

@ -11,7 +11,6 @@
use think\facade\Route; use think\facade\Route;
Route::group('admin', function() { Route::group('admin', function() {
Route::rule( Route::rule(
'Login/index', 'admin/Login/index', 'post' 'Login/index', 'admin/Login/index', 'post'
@ -290,4 +289,3 @@ Route::group('admin', function() {
//MISS路由定义 //MISS路由定义
Route::miss('admin/Miss/index'); Route::miss('admin/Miss/index');
})->middleware('AdminResponse'); })->middleware('AdminResponse');