更新
This commit is contained in:
13
app/services/SocialiteService.php
Normal file
13
app/services/SocialiteService.php
Normal 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{
|
||||
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
23
app/services/auth/DepartmentService.php
Normal file
23
app/services/auth/DepartmentService.php
Normal 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();
|
||||
}
|
||||
}
|
||||
82
app/services/auth/MenuService.php
Normal file
82
app/services/auth/MenuService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
89
app/services/auth/RoleService.php
Normal file
89
app/services/auth/RoleService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
94
app/services/auth/UsersLogService.php
Normal file
94
app/services/auth/UsersLogService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
171
app/services/auth/UsersService.php
Normal file
171
app/services/auth/UsersService.php
Normal 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;
|
||||
}
|
||||
}
|
||||
22
app/services/system/ConfigService.php
Normal file
22
app/services/system/ConfigService.php
Normal 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;
|
||||
}
|
||||
}
|
||||
151
app/services/system/DictionaryService.php
Normal file
151
app/services/system/DictionaryService.php
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user