This commit is contained in:
molong
2022-05-24 16:10:50 +08:00
parent a37870c93b
commit d8e43f9e93
63 changed files with 2169 additions and 230 deletions

View File

@@ -1 +1,22 @@
APP_DEBUG = true
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = test
USERNAME = username
PASSWORD = password
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
[JWT]
SECRET={secret}
ADMIN_ROOT = 1

View File

@@ -1,8 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app;
// 应用请求对象类
class Request extends \think\Request
{
use app\services\auth\UsersService;
// 应用请求对象类
class Request extends \think\Request{
public function auth(){
return app()->make(UsersService::class)->getUserAuth($this->user['uid']);
}
}

View File

@@ -1,2 +1,36 @@
<?php
// 应用公共文件
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
use think\facade\Cache;
function getDepartmentChild($pid = 0){
$department = Cache::get('department');
if(!$department){
$department = \app\model\auth\Departments::where('status', '=', 1)->column('id,parent_id,title', 'id');
Cache::set('department', $department);
}
$res = getChilds($department, $pid, 'id', 'parent_id');
$res[] = (int) $pid; //把自己包含在内
return $res;
}
/**
* 获得所有的子
* @param [type] $id [description]
* @return [type] [description]
*/
function getChilds($data, $id = 0, $pk = 'id', $pid = 'parent_id') {
$array = [];
foreach ($data as $k => $v) {
if ($v[$pid] == $id) {
$array[] = (int) $v[$pk];
array_merge($array, getChilds($data, $v[$pk]));
}
}
return $array;
}

View File

@@ -0,0 +1,124 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\auth;
use think\facade\Request;
use app\model\auth\Departments;
use app\services\auth\DepartmentService;
use sent\tree\Tree;
use app\controller\Base;
class Department extends Base {
/**
* @title 部门列表
*
* @time 2020年01月09日
* @param Departments $department
* @return Array
*/
public function index() {
$list = app()->make(DepartmentService::class)->getDepartmentList($this->request)->toArray();
if(count($list) > 0){
$root = '';
foreach ($list as $value) {
if($root == ''){
$root = $value['parent_id'];
}else{
if($root > $value['parent_id']){
$root = $value['parent_id'];
}
}
}
$tree = (new Tree())->listToTree($list, 'id', 'parent_id', 'children', $root);
if(empty($tree)){
$this->data['data'] = $list;
}else{
$this->data['data'] = $tree;
}
}else{
$this->data['data'] = [];
}
return $this->data;
}
/**
* @title 添加部门
*
* @time 2020年01月09日
* @return Array
*/
public function add() {
$data = request()->post();
$data['creator_id'] = request()->user['uid'];
try {
$result = Departments::create($data);
$this->data['message'] = '添加成功!';
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 更新部门
*
* @time 2020年01月09日
* @param $id
* @param Request $request
* @return Array
*/
public function edit() {
$data = request()->post();
$data['creator_id'] = request()->user['uid'];
try {
$result = Departments::update($data);
$this->data['message'] = '更新成功!';
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 删除部门
*
* @time 2020年01月09日
* @param $id
* @return Array
*/
public function delete() {
$data = request()->post('id');
$map = [];
if(is_array($data)){
$map[] = ['id', 'IN', $data];
}else if(is_numeric($data)){
$map[] = ['id', '=', $data];
}
try {
$result = Departments::destroy(function($query) use ($map){
$query->where($map);
});
$this->data['message'] = '删除成功!';
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 获取班级
*
* @return void
*/
public function studentclass(){
$this->data['data'] = app()->make(DepartmentService::class)->getStudentClassList();
$this->data['code'] = 1;
return $this->data;
}
}

View File

@@ -9,13 +9,14 @@
namespace app\controller\auth;
use app\controller\Base;
use app\services\auth\LoginService;
use app\services\auth\AuthService;
use app\services\SocialiteService;
class Index extends Base{
public function login(LoginService $service){
public function login(AuthService $service){
try {
$data = $service->authLogin($this->request);
$data = $service->login($this->request);
$this->data['data'] = $data;
} catch (\think\Exception $e) {
$this->data['code'] = 0;
@@ -23,4 +24,14 @@ class Index extends Base{
}
return $this->data;
}
/**
* @title 第三方账号登录
*/
public function socialite(){
//实例化第三方登录服务
$service = new SocialiteService();
return $service->login();
}
}

View File

@@ -0,0 +1,73 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\auth;
use app\controller\Base;
use app\services\auth\RoleService;
class Role extends Base{
/**
* @title 角色列表
*
* @time 2019年12月09日
* @return string|Json
*/
public function index() {
$tree = app()->make(RoleService::class)->getRolesList($this->request, true);
$this->data['code'] = 1;
$this->data['data'] = $tree;
return $this->data;
}
/**
* @title 角色授权
* @time 2019年12月11日
* @param $id
* @param Request $request
* @return Array
*/
public function auth() {
$role_id = $this->request->param('role_id', '');
$auth = $this->request->param('auth', '');
$service = app()->make(RoleService::class);
try {
$service->updateRolePermission($role_id, $auth);
$service->updateRoleAuth($this->request);
$this->data['code'] = 1;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 删除角色
*
* @time 2019年12月11日
* @param $id
* @throws FailedException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return Json
*/
public function delete(){
try {
$service = app()->make(RoleService::class)->deleteRole($this->request);
$this->data['code'] = 1;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
}

View File

@@ -0,0 +1,101 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\auth;
use app\services\auth\UsersService;
use app\controller\Base;
class User extends Base{
/**
* @title 用户列表
* @param int $uid
* @return array
*/
public function index(UsersService $user){
$list = $user->getUserList($this->request);
$this->data['data'] = $list;
return $this->data;
}
/**
* @title 添加用户
* @param int $uid
* @return array
*/
public function add(){
try {
$res = app()->make(UsersService::class)->createUsers($this->request);
$this->data['code'] = 1;
$this->data['data'] = $res;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 修改用户信息
* @param int $uid
* @return array
*/
public function edit(){
try {
$res = app()->make(UsersService::class)->updateUsers($this->request);
$this->data['code'] = 1;
$this->data['data'] = $res;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 批量导入用户
* @param int $uid
* @return array
*/
public function insert(){
try {
$users = app()->make(UsersService::class)->insertAll($this->request);
$this->data['data'] = $users;
$this->data['code'] = 1;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 用户信息
* @param int $uid
* @return array
*/
public function info(){
$this->data['data'] = app()->make(UsersService::class)->userInfo($this->request->user['uid']);
$this->data['code'] = 1;
return $this->data;
}
/**
* @title 用户授权
* @return array
*/
public function auth(){
try {
$uid = $this->request->param('uid');
$role = $this->request->param('role');
$manage_class = $this->request->param('manage_class');
app()->make(UsersService::class)->updateRoles($uid, $role, $manage_class);
$this->data['message'] = '更新成功!';
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
}

View File

@@ -0,0 +1,127 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\system;
use app\controller\Base;
use app\services\system\DictionaryService;
/**
* @title 字典功能
*/
class Dict extends Base{
/**
* @title 字典分类数据
*
* @return void
*/
public function category(DictionaryService $dic){
$list = $dic->getTree($this->request);
$this->data['data'] = $list;
return $this->data;
}
/**
* @title 添加字典分类
*
* @return void
*/
public function addcate(DictionaryService $dic){
try {
$data = $dic->addcate($this->request);
$this->data['code'] = 1;
$this->data['data'] = $data;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 修改字典分类
*
* @return void
*/
public function editcate(DictionaryService $dic){
try {
$data = $dic->editcate($this->request);
$this->data['code'] = 1;
$this->data['data'] = $data;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
public function delcate(DictionaryService $dic){
$dic->deleteCategory($this->request);
return $this->data;
}
/**
* @title 字典列表
*
* @return void
*/
public function lists(DictionaryService $dic){
$list = $dic->getDictionary($this->request);
$this->data['data'] = $list;
return $this->data;
}
/**
* @title 添加字典
*
* @return void
*/
public function add(DictionaryService $dic){
try {
$data = $dic->createDic($this->request);
$this->data['code'] = 1;
$this->data['data'] = $data;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 修改字典
*
* @return void
*/
public function edit(DictionaryService $dic){
try {
$data = $dic->updateDic($this->request);
$this->data['code'] = 1;
$this->data['data'] = $data;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 删除字典
*
* @param DictionaryService $dic
* @return void
*/
public function delete(DictionaryService $dic){
$dic->deleteDic($this->request);
return $this->data;
}
/**
* @title 字典明细
*
* @return void
*/
public function detail(DictionaryService $dic){
$list = $dic->getDictionaryDetail($this->request);
$this->data['data'] = $list;
return $this->data;
}
}

View File

@@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\system;
use app\controller\Base;
use app\services\system\ConfigService;
class Index extends Base{
public function version(){
$this->data['data'] = 'v1.5.0';
return $this->data;
}
/**
* 获取配置列表
*
* @param ConfigService $service
* @return void
*/
public function setting(ConfigService $service){
$list = $service->getConfigField();
$this->data['data'] = $list;
return $this->data;
}
}

View File

@@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\system;
use app\controller\Base;
use app\services\auth\UsersLogService;
/**
* @title 用户日志管理
*/
class Log extends Base {
/**
* @title 日志列表
*
* @return void
*/
public function index(){
$list = app()->make(UsersLogService::class)->getUserLogList($this->request);
$this->data['data'] = $list;
return $this->data;
}
}

View File

@@ -0,0 +1,135 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\system;
use app\controller\Base;
use app\services\auth\MenuService;
use app\services\auth\AuthService;
class Menu extends Base{
/**
* @title 权限列表
*
* @time 2020年01月09日
* @param Departments $department
* @return Array
*/
public function index() {
$data = app()->make(MenuService::class)->getSystemMenu(false);
$this->data['data'] = $data;
return $this->data;
}
/**
* @title 权限保存
*
* @time 2020年01月09日
* @return Array
*/
public function add() {
$data = request()->post();
$data['creator_id'] = request()->user['uid'];
try {
$result = app()->make(MenuService::class)->createData($data);
$this->data['data'] = $result;
$this->data['message'] = '添加成功!';
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 权限更新
*
* @time 2020年01月09日
* @param $id
* @param Request $request
* @return Array
*/
public function edit() {
$data = request()->post();
try {
$result = app()->make(MenuService::class)->saveData($data);
if($result){
$this->data['data'] = app()->make(MenuService::class)->getSystemMenu();
}
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 权限删除
*
* @time 2020年01月09日
* @param $id
* @return Array
*/
public function delete() {
$ids = request()->post('ids');
try {
$result = app()->make(MenuService::class)->deleteMenu($ids);
$this->data['data'] = app()->make(MenuService::class)->getSystemMenu();
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 菜单路由
*
* @time 2020年01月09日
* @param $id
* @return Array
*/
public function routes(Permissions $permission) {
$map = [];
$map[] = ['type', '=', 1];
$map[] = ['hidden', '=', 1];
$list = $permission->where($map)->field('router,name,icon,id,parent_id')->order('sort asc')->select()->toArray();
$tree = (new Tree())->listToTree($list, 'id', 'parent_id', 'children');
$this->data['data'] = [['router' => 'root', 'children' => $tree]];
return $this->data;
}
/**
* @title 权限数据
*
* @time 2020年01月09日
* @param $id
* @return Array
*/
public function permission(Permissions $permission) {
$map = [];
$map[] = ['hidden', '=', 1];
$list = $permission->where($map)->field('router,name,icon,id,parent_id')->order('sort asc')->select()->toArray();
$data = [];
foreach($list as $item){
if($item['type'] == 1){
$data[$item['id']] = $item;
}else{
$data[$item['parent_id']]['module'] = $item;
}
}
$this->data['data'] = $data;
return $this->data;
}
/**
* @title 我的菜单
* @return Array
*/
public function my(){
$menu = app()->make(AuthService::class)->getAuthMenu();
$this->data['code'] = 1;
$this->data['data'] = ['menu' => $menu, 'permissions' => []];
return $this->data;
}
}

View File

@@ -12,7 +12,6 @@ namespace app\middleware;
use think\Config;
use think\Request;
use think\Response;
class AllowCrossDomain{
@@ -36,6 +35,7 @@ class AllowCrossDomain{
* @return Response
*/
public function handle($request, \Closure $next, ? array $header = []){
$response = $next($request);
$header = !empty($header) ? array_merge($this->header, $header) : $this->header;
if (!isset($header['Access-Control-Allow-Origin'])) {
@@ -43,6 +43,10 @@ class AllowCrossDomain{
$header['Access-Control-Allow-Origin'] = $origin ? $origin : "*";
}
return $next($request)->header($header);
if (strtoupper($request->method()) == "OPTIONS") {
$response->code(204);
}
return $response->header($header);
}
}

View File

@@ -10,9 +10,9 @@ declare (strict_types = 1);
namespace app\middleware;
class Api{
use app\services\auth\UsersLogService;
public $data = ['code' => 1, 'data' => '', 'message' => ''];
class Api{
/**
* 处理请求
@@ -22,22 +22,18 @@ class Api{
* @return Response
*/
public function handle($request, \Closure $next){
$request->pageConfig = array(
'list_rows' => $request->param('pageSize', 30),
'page' => $request->param('page', 1),
);
$response = $next($request);
if (is_array($response->getData())) {
$this->data = array_merge($this->data, $response->getData());
//记录用户操作记录
app()->make(UsersLogService::class)->record($request, $response->getCode());
if ($request->isAjax() || is_array($response->getData())) {
return json($response->getData());
} else {
$this->data = $response->getData();
}
if ($request->isAjax()) {
return json($this->data);
} else {
if (\is_string($this->data) && $this->data != '') {
return $response;
} else {
return json($this->data);
}
}
}
}

61
app/middleware/Check.php Normal file
View File

@@ -0,0 +1,61 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace app\middleware;
use think\App;
use think\Response;
use xiaodi\JWTAuth\Exception\JWTException;
class Check{
protected $app;
public function __construct(App $app){
$this->app = $app;
}
/**
* @title 处理请求
*
* @param [type] $request
* @param \Closure $next
* @param [type] $store
* @return void
*/
public function handle($request, \Closure $next, $store = null){
try {
$verify = $this->app->get('jwt')->store($store)->verify();
if (true === $verify) {
if ($this->app->get('jwt.user')->getBind()) {
if ($user = $this->app->get('jwt.user')->find()) {
// 路由注入
$request->user = $user;
// 绑定当前用户模型
$class = $this->app->get('jwt.user')->getClass();
$this->app->bind($class, $user);
// 绑定用户后一些业务处理
$this->bindUserAfter($request);
} else {
return Response::create(['message' => '登录校验已失效, 请重新登录', 'code' => 2000], 'json', 401);
}
}
return $next($request);
}
} catch (JWTException $e) {
return Response::create(['message' => $e->getMessage(), 'code' => 2000], 'json', 401);
}
}
public function bindUserAfter(){
}
}

View File

@@ -9,7 +9,31 @@
namespace app\model;
use think\Model;
use think\facade\Config;
use think\facade\Db;
class BaseModel extends Model{
public function scopeUserauth($query, $where = []){
$auth = request()->auth();
$uid = request()->user['uid'];
$map = [];
if(!in_array($uid, Config::get('auth.admin_root'))){
$subMap = [];
if($auth['data_range'] == 4){
$subMap[] = ['department_id', 'IN', getDepartmentChild($auth['department_id'])];
}elseif($auth['data_range'] == 3){
$subMap[] = ['department_id', 'IN', $auth['department_id']];
}elseif($auth['data_range'] == 2){
$map[] = ['creator_id', '=', $uid];
}
if(!empty($subMap)){
$subsql = Db::name('users')->where($subMap)->field('uid')->buildSql();
$subsql = str_replace(" AS thinkphp) AS T1 )", "", $subsql);
$subsql = str_replace("SELECT T1.* FROM (SELECT thinkphp.*, ROW_NUMBER() OVER ( ORDER BY rand()) AS ROW_NUMBER FROM (", "", $subsql);
$map[] = ['creator_id', 'IN', Db::raw($subsql)];
}
}
$query->where($where)->where($map);
}
}

View File

@@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\auth;
use think\model\concern\SoftDelete;
use think\facade\Config;
use app\model\BaseModel;
class Departments extends BaseModel{
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
public function scopeAuth($query){
$auth = request()->auth();
$uid = request()->user['uid'];
$map = [];
// if(!in_array($uid, Config::get('auth.admin_root'))){
// if($auth['data_range'] == 2 || $auth['data_range'] == 3){
// $map[] = ['id', '=', $auth['department_id']]; //只能看自己是也只能查自己所在部门
// }elseif($auth['data_range'] == 4){
// $map[] = ['id', 'IN', getDepartmentChild($auth['department_id'])]; //部门及以下数据
// }
// }
$query->where($map);
}
}

View File

@@ -0,0 +1,13 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\auth;
class PermissionAccess extends \think\model\Pivot{
protected $name = "RoleHasPermissions";
}

View File

@@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\auth;
class Permissions extends \app\model\BaseModel{
protected $type = [
'created_time' => 'timestamp',
'updated_time' => 'timestamp',
'hidden' => 'int',
'hiddenBreadcrumb' => 'int',
'api_list' => 'json'
];
protected function getMetaAttr($value, $data){
return [
'title' => $data['title'],
'type' => $data['type'],
'icon' => $data['icon'],
'color' => $data['color'],
'hidden' => (int) $data['hidden'],
'hiddenBreadcrumb' => (int) $data['hiddenBreadcrumb'],
'affix' => (int) $data['affix'],
];
}
protected function getApiListAttr($value){
return $value ? json_decode($value, true) : [];
}
public function getList(){
$map = [];
return $this->where($map)->order('sort asc,id desc')->select();
}
}

23
app/model/auth/Roles.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\auth;
use app\model\BaseModel;
class Roles extends BaseModel{
protected function getMobileModuleAttr($value){
return is_string($value) ? explode(",", $value) : [];
}
protected function setMobileModuleAttr($value){
return is_array($value) ? implode(",", $value) : $value;
}
public function permissions(){
return $this->belongsToMany(Permissions::class, PermissionAccess::class, 'permission_id', 'role_id');
}
}

View File

@@ -0,0 +1,16 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\auth;
class RolesAccess extends \think\model\Pivot{
protected $name = "UserHasRoles";
public static function getRoleByUid(){
return [];
}
}

49
app/model/auth/Users.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\auth;
use app\model\BaseModel;
use think\facade\Config;
use xiaodi\JWTAuth\Facade\Jwt;
class Users extends BaseModel{
public $pk = 'uid';
public function getTokenAttr($value, $data){
$token = Jwt::store('api')->token($data)->__toString();
return $token;
}
public function scopeAuth($query, $where = []){
$auth = request()->auth();
$uid = request()->user['uid'];
$map = [];
// if(!in_array($uid, Config::get('auth.admin_root'))){
// if($auth['data_range'] == 2){
// $map[] = ['uid', '=', $uid];//只能看自己
// }elseif($auth['data_range'] == 3){
// $map[] = ['department_id', '=', $auth['department_id']]; //查自己所在部门
// }elseif($auth['data_range'] == 4){
// $map[] = ['department_id', 'IN', getDepartmentChild($auth['department_id'])]; //部门及以下数据
// }
// }
$query->where($query)->where($where);
}
public function roles(){
return $this->belongsToMany(Roles::class, RolesAccess::class, 'role_id', 'uid');
}
public function department(){
return $this->hasOne(Departments::class, 'id', 'department_id')->bind([
'department_name' => 'title'
]);
}
}

View File

@@ -0,0 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\auth;
use app\model\BaseModel;
use think\model\concern\SoftDelete;
class UsersLog extends BaseModel{
use SoftDelete;
protected $pk = 'uid';
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
public function user(){
return $this->hasOne(Users::class, 'uid', 'uid')->bind([
'nickname' => 'nickname'
]);
}
}

View File

@@ -6,15 +6,10 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\user;
namespace app\model\system;
use app\model\BaseModel;
use xiaodi\JWTAuth\Facade\Jwt;
class Users extends BaseModel{
class Config extends BaseModel{
public function getTokenAttr($value, $data){
$token = Jwt::store('api')->token($data)->__toString();
return $token;
}
}

View File

@@ -0,0 +1,20 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\system;
use app\model\BaseModel;
use think\model\concern\SoftDelete;
class Dictionary extends BaseModel{
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
}

View File

@@ -0,0 +1,20 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\system;
use app\model\BaseModel;
use think\model\concern\SoftDelete;
class DictionaryType extends BaseModel{
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
}

View File

@@ -0,0 +1,13 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\services;
class SocialiteService{
}

View File

@@ -8,11 +8,20 @@
// +----------------------------------------------------------------------
namespace app\services\auth;
use app\model\user\Users;
use app\model\auth\Users;
use app\model\auth\Permissions;
use sent\tree\Tree;
use think\facade\Env;
class LoginService{
class AuthService{
public function authLogin($request){
/**
* @title 用户登录
*
* @param [type] $request
* @return void
*/
public function login($request){
$params = $request->post();
$map = [];
foreach($params as $field => $value){
@@ -22,7 +31,7 @@ class LoginService{
}
$user = Users::where($map)->field(['uid','username', 'password', 'email', 'avatar', 'department_id', 'status'])->findOrEmpty();
if (!$user->isEmpty()) {
if(password_verify(base64_decode($params['password']), $user->password)){
if(password_verify($params['password'], $user->password)){
throw new \think\Exception('密码不正确!', 100002);
}elseif($user->status != 1){
throw new \think\Exception('当前用户不可用', 100003);
@@ -33,4 +42,26 @@ class LoginService{
throw new \think\Exception('当前用户不存在', 100001);
}
}
/**
* @title 获取已授权菜单
*
* @return void
*/
public function getAuthMenu(){
$order = "sort asc, id desc";
$map = [];
if(request()->user['uid'] == Env::get('admin_root')){
$map[] = ['name', 'IN', request()->auth()['permission']];
}
$map[] = ['type', '=', 'menu'];
$map[] = ['hidden', '=', 0];
$list = Permissions::where($map)->order($order)->append(['meta'])->select()
->each(function($item){
$item->hidden = (int) $item['hidden'];
$item->hiddenBreadcrumb = (int) $item['hiddenBreadcrumb'];
})->toArray();
return (new Tree())->listToTree($list, 'id', 'parent_id', 'children');
}
}

View File

@@ -0,0 +1,23 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\services\auth;
use app\model\auth\Departments;
class DepartmentService{
public function getDepartmentList($request){
$param = $request->param();
$map = [];
if(isset($param['keyword']) && $param['keyword']){
$map[] = ['title', 'LIKE', '%' . $param['keyword'] . '%'];
}
return Departments::where($map)->auth()->order('sort asc,id desc')->select();
}
}

View File

@@ -0,0 +1,82 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\services\auth;
use app\model\auth\Permissions;
use sent\tree\Tree;
use think\facade\Env;
class MenuService{
/**
* @title 获取菜单
*
* @param boolean $is_tree
* @return void
*/
public function getSystemMenu($is_menu = true, $is_tree = true){
$rootid = Env::get('admin_root');
$order = "sort asc, id desc";
$map = [];
if(request()->user['uid'] == $rootid){
$map[] = ['name', 'IN', request()->auth()['permission']];
}
if($is_menu){
$map[] = ['type', '=', 'menu'];
$map[] = ['hidden', '=', 0];
}
$list = Permissions::where($map)->order($order)->append(['meta'])->select()
->each(function($item){
$item->hidden = (int) $item['hidden'];
$item->hiddenBreadcrumb = (int) $item['hiddenBreadcrumb'];
})->toArray();
if($is_tree){
$menu = (new Tree())->listToTree($list, 'id', 'parent_id', 'children');
return $menu;
}else{
return $list;
}
}
/**
* @title 创建数据
*
* @param [type] $data
* @return void
*/
public function createData($data){
return Permissions::create($data);
}
/**
* @title 保存数据
*
* @param [type] $data
* @return void
*/
public function saveData($data){
$menu = Permissions::where('id', $data['id'])->findOrEmpty();
//移除时间,时间自动系统
unset($data['create_time']);
unset($data['update_time']);
if(!$menu->isEmpty()){
return $menu->save($data);
}else{
throw new \think\Exception("未找到数据!", 0);
}
}
/**
* @title 删除菜单
*
* @param [type] $data
* @return void
*/
public function deleteMenu($data){
return Permissions::destroy($data);
}
}

View File

@@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\services\auth;
use app\model\auth\Roles;
use app\model\auth\PermissionAccess;
use app\model\auth\RolesAccess;
use sent\tree\Tree;
class RoleService{
/**
* @title 获取角色列表
*
* @param [type] $request
* @param [type] $is_tree
* @return void
*/
public function getRolesList($request, $is_tree){
$param = $request->param();
$map = [];
if(isset($param['keyword']) && $param['keyword']){
$map[] = ['title', 'LIKE', '%' . $param['keyword'] . '%'];
}
$list = Roles::with(['permissions'])->where($map)->order('sort asc, id desc')->select()->each(function($item){
$item->data_range = strval($item->data_range);
$permission_id = [];
foreach($item->permissions as $val){
$permission_id[] = $val['id'];
}
$item->permission_id = $permission_id;
});
if($is_tree){
return (new Tree())->listToTree($list->toArray(), 'id', 'parent_id', 'children');
}else{
return $list;
}
}
public function deleteRole($request){
$id = $request->param('id', 0);
$parent = Roles::where('parent_id', $id)->findOrEmpty();
if (!$parent->isEmpty()) {
throw new \think\Exception("存在子角色,无法删除", 0);
}
$role = Roles::find($id);
// 删除权限
PermissionAccess::where('role_id', '=', $role_id)->delete();
// 删除部门关联
// $role->detachDepartments();
// 删除用户关联
RolesAccess::where('role_id', '=', $role_id)->delete();
// 删除
$role->delete();
}
/**
* @title 更新角色权限
*
* @param [type] $role_id
* @param [type] $data
* @return void
*/
public function updateRolePermission($role_id, $data){
PermissionAccess::where('role_id', '=', $role_id)->delete();
$save = [];
foreach ($data as $permiss) {
$save[] = ['role_id' => $role_id, 'permission_id' => $permiss];
}
(new PermissionAccess())->saveAll($save);
return true;
}
public function updateRoleAuth($request){
$role_id = $request->param('role_id', '');
$data_range = $request->param('data_range', '');
$dashboard = $request->param('dashboard', '');
$mobile_module = $request->param('mobile_module', '');
$role = Roles::find($role_id);
$save = [
'data_range' => $data_range,
'dashboard' => $dashboard,
'mobile_module' => $mobile_module
];
return $role->save($save);
}
}

View File

@@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\services\auth;
use app\model\auth\Users;
use app\model\auth\UsersLog;
use xin\helper\Server;
class UsersLogService{
/**
* @title 获取用户操作日志
*
* @param [type] $request
* @return void
*/
public function getUserLogList($request){
$param = $request->param();
$map = [];
if(isset($param['method']) && $param['method']){
$map[] = ['method', '=', strtoupper($param['method'])];
}
if(isset($param['date']) && $param['date'] && count($param['date']) == 2){
$map[] = ['create_time', 'BETWEEN TIME', $param['date']];
}
$list = UsersLog::with(['user'])->where($map)->order('create_time desc')->paginate($request->pageConfig);
return $list;
}
/**
* @title 用户操作记录
*
* @param [type] $request
* @param integer $code
* @return void
*/
public function record($request, $code = 200){
$param = array_merge($request->get(), $request->post());
if(!isset($request->user['uid'])){
return false;
}
$data = [
'uid' => isset($request->user['uid']) ? $request->user['uid'] : '',
'title' => self::getCurrentTitle($request),
'route' => $request->baseUrl(),
'params' => json_encode($param),
'method' => $request->method(),
'client_ip' => Server::getRemoteIp(),
'browser' => $request->header('user-agent'),
'code' => $code
];
if($data['route'] == '/admin/system/log/index'){
return false;
}
UsersLog::create($data);
}
protected static function getCurrentTitle($request) {
$mate = '';
$controller = strtr(strtolower($request->controller()), '.', '\\');
$action = $request->action();
$class = "\\app\\controller\\" . $controller;
if (class_exists($class)) {
$reflection = new \ReflectionClass($class);
$group_doc = self::Parser($reflection->getDocComment());
if (isset($group_doc['title'])) {
$mate = $group_doc['title'];
}
$method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC);
foreach ($method as $key => $v) {
if ($action == $v->name) {
$title_doc = self::Parser($v->getDocComment());
if (isset($title_doc['title'])) {
$mate = isset($title_doc['title']) ? $title_doc['title'] : '';
}
}
}
}
return $mate;
}
protected static function Parser($text) {
$doc = new \doc\Doc();
return $doc->parse($text);
}
}

View File

@@ -0,0 +1,171 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\services\auth;
use app\model\auth\Users;
use app\model\auth\RolesAccess;
use think\facade\Config;
class UsersService{
/**
* @title 获取管理员列表
*
* @param [type] $request
* @return void
*/
public function getUserList($request){
$auth = $request->auth();
$param = $request->param();
$map = [];
if(isset($param['name']) && $param['name']){
$map[] = ["username|nickname", "like", "%{$param['name']}%"];
}
if(isset($param['department_id']) && $param['department_id']){
$map[] = ["department_id", "IN", getDepartmentChild($param['department_id'])];
}
if(isset($param['role_id']) && $param['role_id']){
$exp = is_array($param['role_id']) ? "IN" : "=";
$subMap = [['role_id', $exp, $param['role_id']]];
$map[] = ['uid', "IN", function($q) use($subMap){
$q->name('user_has_roles')->where($subMap)->field('uid');
}];
}
$list = Users::with(['roles'])->auth([])->where($map)->order('uid desc')->paginate($request->pageConfig)->each(function($item){
$roleId = [];
$roleName = [];
$identify = [];
foreach($item->roles as $val){
$roleId[] = $val['id'];
$roleName[] = $val['title'];
$identify[] = $val['identify'];
}
$item->role_id = $roleId;
$item->roleName = $roleName;
$item->identify = $identify;
});
return $list;
}
/**
* 创建用户
*
* @param [type] $request
* @return void
*/
public function createUsers($request){
$param = $request->param();
// $data = [
// 'username' => $param['username'],
// 'nickname' => $param['nickname'],
// 'department_id' => $param['department_id']
// ];
// $user = Users::create($data);
// return $user;
}
/**
* @title 批量导入
*
* @param [type] $request
* @return void
*/
public function insertAll($request){
$data = $request->param('data');
$users = [];
foreach($data as $item){
$user = Users::where('uid', $item['XH'])->findOrEmpty();
if($user->isEmpty()){
$users = [
'uid' => $item['XH'],
'username' => $item['XH'],
'nickname' => $item['XM'],
'password' => md5(''),
'email' => "e@mail.cn",
'avatar' => $this->request->domain() . str_replace("/pic", "/", $item['RXZP']),
'creator_id' => 1,
'department_id' => 3,
'user_type' => $item['PYCC'],
'status' => 1,
'sex' => $item['XB'],
'xueyuan' => $item['XY'],
'student_class' => $item['BJMC'],
];
Users::create($users);
}
}
return $users;
}
public function updateUsers($request){
$param = $request->param();
$user = Users::where('uid', '=', $param['uid'])->findOrEmpty();
if(!$user->isEmpty()){
$data = [
'avatar' => $param['avatar'],
'nickname' => $param['nickname'],
'department_id' => is_array($param['department_id']) ? $param['department_id'][0] : $param['department_id'],
'manage_class' => $param['manage_class'],
];
$user->save($data);
}
return false;
}
/**
* @title 获取用户权限信息
*
* @return void
*/
public function getUserAuth($uid){
$user = Users::with(['roles', 'roles.permissions', 'department'])->where('uid', '=', $uid)->findOrEmpty();
if(!$user->isEmpty()){
$permission = [];
$apiList = [];
$data_range = [];
$mobile_module = [];
foreach ($user->roles as $role) {
$data_range[] = $role['data_range'];
$mobile_module = array_merge($mobile_module, $role['mobile_module']);
foreach($role->permissions as $item){
$permission[] = $item['name'];
$apiList = array_merge($apiList, $item['api_list']);
}
}
$user['permission'] = $permission;
$user['data_range'] = isset($data_range[0]) ? $data_range[0] : 1; //暂时适配到过角色的数据权限问题 后续调整
$user['mobile_module'] = $mobile_module;
$user['apiList'] = $apiList;
return $user;
}else{
return false;
}
}
public function userInfo($uid){
$user = $this->getUserAuth($uid);
return $user->append(['access_token']);
}
/**
* @title 更新用户角色
*
* @param int $uid
* @param array $roles
* @param int $manage_class 用户班级权限
* @return void
*/
public function updateRoles($uid, $roles, $manage_class = 0){
RolesAccess::where('uid', '=', $uid)->delete();
$save = [];
foreach ($roles as $role) {
$save[] = ['role_id' => $role, 'uid' => $uid];
}
(new RolesAccess())->saveAll($save);
if($uid && $manage_class){
Users::update(['manage_class' => $manage_class], ['uid' => $uid]);
}
return true;
}
}

View File

@@ -0,0 +1,22 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\services\system;
use app\model\system\Config;
class ConfigService{
public function getConfigField(){
$map = [];
$data = Config::where($map)->select();
return $data;
}
}

View File

@@ -0,0 +1,151 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\services\system;
use app\model\system\Dictionary;
use app\model\system\DictionaryType;
use sent\tree\Tree;
class DictionaryService{
/**
* @title 获取字典
*
* @return void
*/
public function getDictionary($request){
$param = $request->param();
$map = [];
if(isset($param['code']) && $param['code']){
$map[] = ['dic_type', '=', $param['code']];
}
if(isset($param['name']) && $param['name']){
$map[] = ['dic_type', '=', $param['name']];
}
$list = Dictionary::where($map)->order('id desc')->paginate($request->pageConfig);
return $list;
}
/**
* @title 获取字典明细
*
* @return void
*/
public function getDictionaryDetail($request){
$param = $request->param();
$map = [];
if(isset($param['name']) && $param['name']){
$map[] = ['dic_type', '=', $param['name']];
}
$list = Dictionary::where($map)->order('id desc')->select();
return $list;
}
/**
* @title 获取字典分类
*
* @param [type] $request
* @return void
*/
public function getTree($request){
$list = DictionaryType::select()->toArray();
$tree = (new Tree())->listToTree($list, 'id', 'parent_id', 'children');
return $tree;
}
/**
* @title 添加字段分类
*
* @param [type] $request
* @return void
*/
public function addcate($request){
$data = $request->param();
return DictionaryType::create($data);
}
/**
* @title 修改字段分类
*
* @param [type] $request
* @return void
*/
public function editcate($request){
$data = $request->param();
$dicType = DictionaryType::find($data['id']);
if($data['parent_id'] == $data['id']){
throw new \think\Exception('上级不能为自己!', 100);
}
//更新树下字段明细
$dic = Dictionary::where('dic_type', '=', $dicType['code'])->select();
$dicSave = [];
if($dic){
foreach ($dic as $key => $value) {
$dicSave[] = ['id' => $value['id'], 'dic_type' => $data['code']];
}
}
if($dicSave){
(new Dictionary())->saveAll($dicSave);
}
return $dicType->save($data);
}
/**
* @title 删除字段分类
*
* @param [type] $request
* @return void
*/
public function deleteCategory($request){
$map = [];
$id = $request->param('id');
if(is_array($id)){
$map[] = ['id', 'IN', $id];
}else{
$map[] = ['id', '=', $id];
}
DictionaryType::destroy(function($q) use($map){
$q->where($map);
});
}
/**
* @title 创建字段明细
*
* @return void
*/
public function createDic($request){
$data = $request->param();
return Dictionary::create($data);
}
/**
* @title 更新字典明细
*
* @param [type] $request
* @return void
*/
public function updateDic($request){
$data = $request->param();
$dic = Dictionary::find($data['id']);
$dic->save($data);
return $dic;
}
/**
* @title 删除字典明细
*
* @param [type] $request
* @return void
*/
public function deleteDic($request){
$map = [];
$id = $request->param('id');
if(is_array($id)){
$map[] = ['id', 'IN', $id];
}else{
$map[] = ['id', '=', $id];
}
Dictionary::destroy(function($q) use($map){
$q->where($map);
});
}
}

View File

@@ -0,0 +1,27 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\validate\auth;
use think\Validate;
class Index extends Validate{
protected $rule = [
'username' => 'require:id',
'password' => 'require'
];
protected $message = [
'password.require' => '登录密码必须',
'username.require' => '登录用户名必须'
];
protected $scene = [
'login' => ['username', 'password'],
'resetpasswd' => ['username', 'password']
];
}

View File

@@ -23,7 +23,9 @@
"php": ">=7.2.5",
"topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0",
"xiaodi/think-jwt": "^2.0"
"xiaodi/think-jwt": "^2.0",
"sent/tree": "^1.0",
"xin/helper": "1.0"
},
"require-dev": {
"symfony/var-dumper": "^4.2",

66
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "aed98006f10d9fbc1ef4ac60e21a2a0e",
"content-hash": "fc45399aa0379b0e0907f9125860728c",
"packages": [
{
"name": "lcobucci/jwt",
@@ -629,6 +629,35 @@
],
"time": "2017-10-23T01:57:42+00:00"
},
{
"name": "sent/tree",
"version": "v1.0.1",
"source": {
"type": "git",
"url": "https://gitee.com/ycgpp/tree.git",
"reference": "61229ea4cc4485fb8a82343921d33559daed2992"
},
"require": {
"php": ">=5.6"
},
"type": "library",
"autoload": {
"psr-4": {
"sent\\tree\\": "src"
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "molong",
"email": "ycgpp@126.com"
}
],
"description": "tree",
"time": "2019-11-26T13:24:07+00:00"
},
{
"name": "topthink/framework",
"version": "v6.0.12",
@@ -844,6 +873,41 @@
"thinkphp"
],
"time": "2021-02-22T02:09:36+00:00"
},
{
"name": "xin/helper",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://gitee.com/liuxiaojinla/php-helper",
"reference": "02a58132dae2aea2d1c0b8e66f55125969224747"
},
"require": {
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-simplexml": "*"
},
"type": "library",
"autoload": {
"psr-4": {
"xin\\helper\\": "src/"
}
},
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "晋",
"email": "1540175452@qq.com"
}
],
"description": "PHP项目日常开发必备基础库数组工具类、字符串工具类、数字工具类、函数工具类、服务器工具类、加密工具类",
"time": "2019-06-22T08:28:23+00:00"
}
],
"packages-dev": [

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
use app\model\user\Users;
use app\model\auth\Users;
return [
'stores' => [
@@ -30,7 +30,7 @@ return [
],
'user' => [
'bind' => true,
'class' => null,
'class' => Users::class,
]
]
],

View File

@@ -4,5 +4,11 @@ return [
// 别名或分组
'alias' => [],
// 优先级设置,此数组中的中间件会按照数组中的顺序优先执行
'priority' => [],
'priority' => [
\app\middleware\AllowCrossDomain::class,
\app\middleware\Api::class,
\app\middleware\Validate::class,
\app\middleware\Check::class,
\app\middleware\Auth::class
],
];

2
extend/.gitignore vendored
View File

@@ -1,2 +0,0 @@
*
!.gitignore

135
extend/doc/Doc.php Normal file
View File

@@ -0,0 +1,135 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace doc;
Class Doc{
private $params = array ();
/**
* 解析注释
* @param string $doc
* @return array
*/
public function parse($doc = '') {
if ($doc == '' || !$doc) {
return $this->params;
}
// Get the comment
if (preg_match ( '#^/\*\*(.*)\*/#s', $doc, $comment ) === false)
return $this->params;
$comment = trim ( $comment [1] );
// Get all the lines and strip the * from the first character
if (preg_match_all ( '#^\s*\*(.*)#m', $comment, $lines ) === false)
return $this->params;
$this->parseLines ( $lines [1] );
return $this->params;
}
private function parseLines($lines) {
$desc = [];
foreach ( $lines as $line ) {
$parsedLine = $this->parseLine ( $line ); // Parse the line
if ($parsedLine === false && ! isset ( $this->params ['description'] )) {
if (isset ( $desc )) {
// Store the first line in the short description
$this->params ['description'] = implode ( PHP_EOL, $desc );
}
$desc = array ();
} elseif ($parsedLine !== false) {
$desc [] = $parsedLine; // Store the line in the long description
}
}
$desc = implode ( ' ', $desc );
if (! empty ( $desc ))
$this->params ['long_description'] = $desc;
}
private function parseLine($line) {
// trim the whitespace from the line
$line = trim ( $line );
if (empty ( $line ))
return false; // Empty line
if (strpos ( $line, '@' ) === 0) {
if (strpos ( $line, ' ' ) > 0) {
// Get the parameter name
$param = substr ( $line, 1, strpos ( $line, ' ' ) - 1 );
$value = substr ( $line, strlen ( $param ) + 2 ); // Get the value
} else {
$param = substr ( $line, 1 );
$value = '';
}
// Parse the line and return false if the parameter is valid
if ($this->setParam ( $param, $value ))
return false;
}
return $line;
}
private function setParam($param, $value) {
if ($param == 'param' || $param == 'header')
$value = $this->formatParam( $value );
if ($param == 'class')
list ( $param, $value ) = $this->formatClass ( $value );
if($param == 'return' || $param == 'param' || $param == 'header'){
$this->params [$param][] = $value;
}else if (empty ( $this->params [$param] )) {
$this->params [$param] = $value;
} else {
$this->params [$param] = $this->params [$param] . $value;
}
return true;
}
private function formatClass($value) {
$r = preg_split ( "[\(|\)]", $value );
if (is_array ( $r )) {
$param = $r [0];
parse_str ( $r [1], $value );
foreach ( $value as $key => $val ) {
$val = explode ( ',', $val );
if (count ( $val ) > 1)
$value [$key] = $val;
}
} else {
$param = 'Unknown';
}
return array (
$param,
$value
);
}
private function formatParam($string) {
$string = $string." ";
if(preg_match_all('/(\w+):(.*?)[\s\n]/s', $string, $meatchs)){
$param = [];
foreach ($meatchs[1] as $key=>$value){
$param[$meatchs[1][$key]] = $this->getParamType($meatchs[2][$key]);
}
return $param;
}else{
return ''.$string;
}
}
private function getParamType($type){
$typeMaps = [
'string' => '字符串',
'int' => '整型',
'float' => '浮点型',
'boolean' => '布尔型',
'date' => '日期',
'array' => '数组',
'fixed' => '固定值',
'enum' => '枚举类型',
'object' => '对象',
];
return array_key_exists($type,$typeMaps) ? $typeMaps[$type] : $type;
}
}

View File

@@ -17,3 +17,10 @@ Route::rule('/', function(){
return view('index');
}
});
Route::group('/', function(){
Route::rule('system/:controller/:action', 'system.:controller/:action');
Route::rule('auth/user/:action', 'auth.User/:action');
Route::rule('auth/department/:action', 'auth.Department/:action');
Route::rule('auth/role/:action', 'auth.Role/:action');
})->middleware([\app\middleware\Check::class], 'api');

View File

@@ -7,7 +7,6 @@
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
use think\facade\Route;
use app\controller\auth;
Route::group('auth', function(){
Route::post('login', 'auth.Index/login');

View File

@@ -57,70 +57,70 @@ export default {
},
dictionary: {
category: {
url: `${config.API_URL}/system/dictionary/category`,
url: `${config.API_URL}system/dict/category`,
name: "获取字典树",
get: async function(){
return await http.get(this.url);
}
},
editcate:{
url: `${config.API_URL}/system/dictionary/editcate`,
url: `${config.API_URL}system/dict/editcate`,
name: "编辑字典树",
post: async function(data = {}){
return await http.post(this.url, data);
}
},
addcate:{
url: `${config.API_URL}/system/dictionary/addcate`,
url: `${config.API_URL}system/dict/addcate`,
name: "添加字典树",
post: async function(data = {}){
return await http.post(this.url, data);
}
},
delCate:{
url: `${config.API_URL}/system/dictionary/delcate`,
url: `${config.API_URL}system/dict/delcate`,
name: "删除字典树",
post: async function(data = {}){
return await http.post(this.url, data);
}
},
list: {
url: `${config.API_URL}/system/dictionary/lists`,
url: `${config.API_URL}system/dict/lists`,
name: "字典明细",
get: async function(params){
return await http.get(this.url, params);
}
},
get: {
url: `${config.API_URL}/system/dictionary/detail`,
url: `${config.API_URL}system/dict/detail`,
name: "获取字典数据",
get: async function(params){
return await http.get(this.url, params);
}
},
edit:{
url: `${config.API_URL}/system/dictionary/edit`,
url: `${config.API_URL}system/dict/edit`,
name: "编辑字典明细",
post: async function(data = {}){
return await http.post(this.url, data);
}
},
add:{
url: `${config.API_URL}/system/dictionary/add`,
url: `${config.API_URL}system/dict/add`,
name: "添加字典明细",
post: async function(data = {}){
return await http.post(this.url, data);
}
},
delete:{
url: `${config.API_URL}/system/dictionary/delete`,
url: `${config.API_URL}system/dict/delete`,
name: "删除字典明细",
post: async function(data = {}){
return await http.post(this.url, data);
}
},
detail: {
url: `${config.API_URL}/system/dictionary/detail`,
url: `${config.API_URL}system/dict/detail`,
name: "字典明细",
get: async function(params){
return await http.get(this.url, params);

View File

@@ -3,21 +3,21 @@ import http from "@/utils/request"
export default {
list: {
url: `${config.API_URL}/user/user/index`,
url: `${config.API_URL}/auth/user/index`,
name: "获得用户列表",
get: async function(params){
return await http.get(this.url, params);
}
},
add: {
url: `${config.API_URL}/user/user/add`,
url: `${config.API_URL}/auth/user/add`,
name: "添加用户",
post: async function(params){
return await http.post(this.url, params);
}
},
edit: {
url: `${config.API_URL}/user/user/edit`,
url: `${config.API_URL}/auth/user/edit`,
name: "编辑用户",
post: async function(params){
return await http.post(this.url, params);
@@ -25,14 +25,14 @@ export default {
},
role: {
list: {
url: `${config.API_URL}/user/role/index`,
url: `${config.API_URL}/auth/role/index`,
name: "获得角色列表",
get: async function(params){
return await http.get(this.url, params);
}
},
edit: {
url: `${config.API_URL}/user/role/edit`,
url: `${config.API_URL}/auth/role/edit`,
name: "编辑角色",
post: async function(params){
return await http.post(this.url, params);
@@ -41,14 +41,14 @@ export default {
},
department: {
list: {
url: `${config.API_URL}/user/department/index`,
url: `${config.API_URL}/auth/department/index`,
name: "获得部门列表",
get: async function(params){
return await http.get(this.url, params);
}
},
edit: {
url: `${config.API_URL}/user/department/edit`,
url: `${config.API_URL}/auth/department/edit`,
name: "编辑部门",
post: async function(params){
return await http.post(this.url, params);
@@ -56,7 +56,7 @@ export default {
}
},
userinfo:{
url: `${config.API_URL}/user/user/info`,
url: `${config.API_URL}/auth/user/info`,
name: "获得部门列表",
get: async function(params){
return await http.get(this.url, params);

View File

@@ -27,11 +27,11 @@ export default {
data(){
return {
pageLoading: true,
dashboard: '1'
dashboard: '0'
}
},
created(){
this.dashboard = this.$TOOL.data.get("USER_INFO").dashboard || '1';
this.dashboard = this.$TOOL.data.get("USER_INFO").dashboard || '0';
},
mounted(){

View File

@@ -3,7 +3,7 @@
<div style="height: 200px;text-align: center;">
<img src="img/ver.svg" style="height:130px"/>
<h2 style="margin-top: 15px;">电子通行证 {{$CONFIG.CORE_VER}}</h2>
<p style="margin-top: 5px;">最新版本 {{ver.version}}</p>
<p style="margin-top: 5px;">最新版本 {{ver}}</p>
</div>
</el-card>
</template>

View File

@@ -3,7 +3,7 @@
<div class="welcome">
<div class="logo">
<img src="img/logo.png">
<h2>南昌工程学院电子通行证管理系统</h2>
<h2>SentOS</h2>
</div>
<div class="tips">
<div class="tips-item">

View File

@@ -87,7 +87,7 @@
this.visible = false;
this.$message.success("操作成功")
}else{
this.$alert(res.msg, "提示", {type: 'error'})
this.$alert(res.message, "提示", {type: 'error'})
}
}
})

View File

@@ -201,9 +201,9 @@ export default {
addInfo(){
this.dialog.list = true
this.$nextTick(() => {
var dicCurrentKey = this.$refs.dic.getCurrentKey();
var node = this.$refs.dic.getCurrentNode();
const data = {
dic: dicCurrentKey
dic_type: node.code
}
this.$refs.listDialog.open().setData(data)
})

View File

@@ -95,7 +95,7 @@ export default {
this.visible = false;
this.$message.success("操作成功")
}else{
this.$alert(res.msg, "提示", {type: 'error'})
this.$alert(res.message, "提示", {type: 'error'})
}
}
})

View File

@@ -1,5 +1,5 @@
<template>
<el-main>
<el-main>
<el-card shadow="never">
<el-tabs tab-position="top">
@@ -95,11 +95,11 @@
</el-tabs>
</el-card>
</el-main>
</el-main>
</template>
<script>
export default {
export default {
name: 'system',
data() {
return {
@@ -143,7 +143,13 @@
]
}
},
async mounted(){
await this.getConfigField();
},
methods: {
getConfigField(){
this.$API.system.setting.list.get();
},
table_add(){
var newRow = {
key: "",
@@ -164,7 +170,7 @@
this.setting.splice(index, 1)
},
}
}
}
</script>
<style>

View File

@@ -84,7 +84,7 @@ export default {
userType: 'admin',
ruleForm: {
user: "admin",
password: "admin888",
password: "password",
autologin: false
},
rules: {