Commit 0a5bb6a1 by lincyawer

重构完成我的信息、账号管理、组织管理.部门列表

parent d9fea626
<?php
namespace App\Http\ApiHelper;
interface ApiCode
{
const API_CODE_SUCCESS = 0;//接口请求正常
const API_CODE_ERROR = 1;//接口请求异常 可预测失败
}
\ No newline at end of file
...@@ -2,12 +2,65 @@ ...@@ -2,12 +2,65 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\ApiHelper\ApiCode;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController; use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Log;
class Controller extends BaseController class Controller extends BaseController implements ApiCode
{ {
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function setSuccess($data = null, $code = self::API_CODE_SUCCESS,$msg ='' )
{
// 兼容格式
if (is_string($data)) {
$res_data = [
"code" => $code,
"data" => (object)[],
"msg" => $data
];
} else {
$res_data = [
"code" => $code,
"data" => (object)$data,
"msg" => $msg
];
}
return response()->json($res_data);
}
public function setError($msg, $code = self::API_CODE_ERROR, $data = null)
{
$res_data = [
"code" => $code,
"msg" => $msg,
];
if ($data) {
$res_data['data'] = $data;
}
$this->logErr($msg, $code = self::API_CODE_ERROR, $data = null);
return response()->json($res_data);
}
private function logErr($msg, $code = self::API_CODE_ERROR, $data = null)
{
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$path_info = parse_url($request_uri);
$err_info = [
'domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '',
'interface' => isset($path_info) ? $path_info['path'] : '',
'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
'ip' => request()->getClientIp(),
'time' => time(),
'other' => '',
'request_params' => $_REQUEST,
'msg' => $msg,
"code" => $code,
"data" => $data
];
Log::error(json_encode($err_info, JSON_UNESCAPED_UNICODE));
}
} }
<?php
namespace App\Http\Controllers;
use App\Http\Error;
use App\Http\Output;
use App\Http\Service\PermService;
use App\Models\user\DepartmentModel;
use App\Models\user\UserInfoModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis as Redis;
class DepartmentController extends Controller
{
// 部门列表
public function departmentList(Request $request)
{
$data = [
'id' => 'departmentList',
'title' => '部门列表',
'paths' => [['href' => '#', 'title' => '组织管理'], ['href' => '#', 'title' => '部门列表']],
];
return view('department.departmentList', $data);
}
// 获取部门列表
public function getDepartmentList()
{
$search_fileds = ['department_id', 'department_name', 'parent_id', 'author', 'last_author', 'ctime', 'mtime'];
$list = DepartmentModel::getDepartmentInfoList($search_fileds);
$list = $this->getFormatDataWithChildInfo($list);
$data = [
"list" => $list
];
return $this->setSuccess($data);
}
private function getFormatDataWithChildInfo($data)
{
if (empty($data)) {
return [];
}
$department_ids = array_column($data, 'department_id');
$department_list = DepartmentModel::getDepartmentListByIds($department_ids);
$department_sub_list_map = [];
foreach ($department_list as $department) {
if ($department['parent_id']) {
$department_sub_list_map[$department['parent_id']][] = $department;
}
}
foreach ($data as &$v) {
// 判断是否存在子级
$v['child'] = isset($department_sub_list_map[$v['department_id']]);
}
return $data;
}
// 新增部门
public function addDepartment(Request $request)
{
$add_department_info = [];
$add_department_info['department_name'] = $request->input('department_name');
$add_department_info['author'] = $request->user->email;
$add_department_info['last_author'] = $request->user->email;
$created_department_list = DepartmentModel::queryWhere([['department_name', $add_department_info['department_name']]]);
if ($created_department_list) {
return $this->setError('新增失败,部门已存在');
}
$create_res = DepartmentModel::createData($add_department_info);
if ($create_res === false) {
return $this->setError('新增失败');
}
return $this->setSuccess('新增成功');
}
//编辑部门
public function editDepartment(Request $request)
{
$department_id = $request->input('department_id');
$update_department_info = [];
$update_department_info['department_name'] = $request->input('department_name');
$update_department_info['last_author'] = $request->user->email;
$created_department_list = DepartmentModel::queryWhere([['department_name',$update_department_info['department_name']]]);
if ($created_department_list) {
return $this->setError('编辑失败,部门已存在');
}
$update_res = DepartmentModel::updateDataByDepartmentId($department_id, $update_department_info);
if ($update_res === false) {
return $this->setError('更新失败');
}
UserInfoModel::updateByDepartmentId($department_id, ['department_name' => $update_department_info['department_name']]);
return $this->setSuccess('编辑成功');
}
// 删除部门
public function delDepartment(Request $request)
{
$department_id = $request->input('department_id');
DepartmentModel::deleteDepartmentId($department_id);
$delete_user_info = [
'department_id' => 0,
'department_name' => ''
];
UserInfoModel::updateByDepartmentId($department_id, $delete_user_info);
return $this->setSuccess('删除成功');
}
// 新增子级
public function addChildDepartment(Request $request)
{
$add_child_department_info = [];
$add_child_department_info['parent_id'] = $request->input('department_id');
$add_child_department_info['department_name'] = $request->input('department_name');
$add_child_department_info['author'] = $request->user->email;
$add_child_department_info['last_author'] = $request->user->email;
$created_child_department_list = DepartmentModel::queryWhere([['department_name', $add_child_department_info['department_name']]]);
if ($created_child_department_list) {
return $this->setError('新增子级失败,部门已存在');
}
$create_res = DepartmentModel::createData($add_child_department_info);
if ($create_res === false) {
return $this->setError('新增子级失败');
}
return $this->setSuccess('新增子级成功');
}
// 创建新部门
public function createDepartment(Request $request)
{
$uri = '/' . $request->path();
// 菜单
$menu_config = ConfigModel::getConfigTitle();
$menus = [];
if ($menu_config && !($menus = json_decode($menu_config->config_data))) {
$menus = [];
}
// 用户角色
$user_role = PermService::getUserRole($request);
// 获取权限菜单
if ($user_role != 1) {
$menus = PermService::getMenuPerm($menus, $request->user->userId);
}
$userPerms = PermService::getUserAllPerms($request->user->userId, $user_role); // 用户权限
$parent = $request->input('parent', null);
$dep = new DepartmentController();
$parentTitle = '';
if ($parent !== null) {
$parentTitle = $dep->pathTitle($dep->getDepartmentPath($parent));
if ($parentTitle === false) {
abort(404);
}
}
$data = [
'username' => $request->user->email,
'header' => $request->user->header,
'title' => '创建部门',
'active' => 'department',
'uri' => $uri,
'menus' => $menus,
'role' => $user_role,
'userPerms' => $userPerms,
'paths' => [
['href' => '/department', 'title' => '组织架构']
]
];
if ($parent !== null) {
$data['parent'] = $parent;
$data['parentTitle'] = $parentTitle;
}
return view('department.department', $data);
}
public function departmentInfo(Request $request, $departmentId = 0)
{
$uri = '/' . $request->path();
// 菜单
$menu_config = ConfigModel::getConfigTitle();
$menus = [];
if ($menu_config && !($menus = json_decode($menu_config->config_data))) {
$menus = [];
}
// 用户角色
$user_role = PermService::getUserRole($request);
// 获取权限菜单
if ($user_role != 1) {
$menus = PermService::getMenuPerm($menus, $request->user->userId);
}
$userPerms = PermService::getUserAllPerms($request->user->userId, $user_role); // 用户权限
$dep = new DepartmentController();
if ($departmentId < 0) {
abort(404);
}
$info = $dep->getInfo($request, $departmentId);
if (!$info) {
abort(404);
}
$data = [
'username' => $request->user->email,
'header' => $request->user->header,
'departmentId' => $departmentId,
'parent' => $info->parent,
'parentTitle' => $info->parentTitle,
'departmentInfo' => $info,
'title' => $info->title . ' - 部门详情',
'active' => 'department',
'canModify' => $info->subInfo['canModify'],
'uri' => $uri,
'menus' => $menus,
'role' => $user_role,
'userPerms' => $userPerms,
'paths' => [
['href' => '/department', 'title' => '组织架构'],
['href' => '/department/' . $departmentId, 'title' => $info->title]
]
];
return view('department.department', $data);
}
private $organization = null;
// public function edit()
// {
// $request = \request();
// $department_id = $request->input('department_id');
//
// $data['department_name'] = $request->input('department_name');
// $data['last_author'] = $request->user->email;
//
// $res = DB::table('user_department')->where('department_name', $data['department_name'])->first();
//
// if ($res) return ['err_code' => 1, 'err_msg' => '更新失败,部门已存在'];
//
// $edit = DB::table('user_department')->where('department_id', $department_id)->update($data);
//
// if ($edit === false) return ['err_code' => 1, 'err_msg' => '更新失败'];
//
// DB::table('user_info')
// ->where('department_id', $department_id)
// ->update(['department_name' => $data['department_name']]);
//
// return ['err_code' => 0, 'err_msg' => '更新成功'];
// }
private function checkDepartment($req, &$data, &$super)
{
$out = [];
if (isset($data['parent'])) {
if ($data['parent'] < 0) {
Log::error(Error::E_PARAM, "invaild parent {$data['parent']}"); // 记录到日志文件
return Output::makeResult($req, Error::E_PARAM, "invaild parent {$data['parent']}");
}
$super = UserDepartmentModel::getDepartmentIdList($data['parent']);
if (!$super) {
Log::error(Error::E_PARAM, "invaild parent, not fount {$data['parent']}"); // 记录到日志文件
return Output::makeResult($req, Error::E_PARAM, "invaild parent, not fount {$data['parent']}");
}
$out['parent'] = $data['parent'];
}
if (isset($data['title']))
$out['title'] = $data['title'];
if (isset($data['description']))
$out['description'] = $data['description'];
if (isset($data['isVirtual']))
$out['isVirtual'] = $data['isVirtual'] ? 1 : 0;
if (isset($data['type'])) {
if (!in_array($data['type'], [1, 2, 3, 30, 31])) {
Log::error(Error::E_PARAM, "invaild type {$data['type']}"); // 记录到日志文件
return Output::makeResult($req, Error::E_PARAM, "invaild type {$data['type']}");
}
$out['type'] = $data['type'];
}
if (isset($data['first']))
$out['first'] = $data['first'];
if (isset($data['second'])) {
if (!is_array($data['second'])) {
Log::error(Error::E_PARAM, "invaild second, not array"); // 记录到日志文件
return Output::makeResult($req, Error::E_PARAM, "invaild second, not array");
}
$out['second'] = json_encode($data['second']);
}
if (isset($data['admins'])) {
if (!is_array($data['admins'])) {
Log::error(Error::E_PARAM, "invaild admins, not array"); // 记录到日志文件
return Output::makeResult($req, Error::E_PARAM, "invaild admins, not array");
}
$out['admins'] = json_encode($data['admins']);
}
$users = [];
if (isset($data['first']) && $data['first'] > 1000)
$users[] = $data['first'];
if (isset($data['second']))
$users = array_merge($users, $data['second']);
if (isset($data['admins']))
$users = array_merge($users, $data['admins']);
$users = array_unique($users);
if (count($users) > 0) {
$count = UserInfoModel::countIdByStatus($users, 4);
if ($count != count($users)) {
Log::error(Error::E_PARAM, "invaild userId " . implode(',', $users)); // 记录到日志文件
return Output::makeResult($req, Error::E_PARAM, "invaild userId " . implode(',', $users));
}
}
$out['mtime'] = date('Y-m-d H:i:s');
$data = $out;
return true;
}
public function create(Request $request)
{
$super = null;
$data = json_decode($request->input('data', ''), true);
if (!$data) {
Log::error(Error::E_PARAM, "bad request: data is not json"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "bad request: data is not json");
}
$ret = $this->checkDepartment($request, $data, $super);
if ($ret !== true)
return $ret;
if (!in_array($request->user->userId, json_decode($super->admins))) {
Log::error(Error::E_PARAM, "not in admin"); // 记录到日志文件
return Output::makeResult($request, Error::E_FORBIDDEN, "not in admin");
}
if (!isset($data['admins']) || count($data['admins']) == 0) {
Log::error(Error::E_PARAM, "admins is empty"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "admins is empty");
}
try {
$data['ctime'] = date('Y-m-d H:i:s');
$id = UserDepartmentModel::getIdFormCtime($data);
Redis::del('__department_all');
return Output::makeResult($request, 0, null, ['departmentId' => $id]);
} catch (\Exception $e) {
Log::error(Error::E_SERVER, "unknow server error: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, "unknow server error: " . $e->getMessage() . ", try agant");
}
}
public function update(Request $request, $departmentId)
{
$super = null;
$data = json_decode($request->input('data', ''), true);
if (!$data) {
Log::error(Error::E_PARAM, "Bad Request: invaild data, not json"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: invaild data, not json");
}
if ($departmentId < 0) {
Log::error(Error::E_PARAM, "Bad Request: invaild departmentId"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: invaild departmentId");
}
$ret = $this->checkDepartment($request, $data, $super);
if ($ret !== true)
return $ret;
$userId = $request->user->userId;
try {
$old = UserDepartmentModel::getDepartmentIdList($departmentId);
if (!$old) {
Log::error(Error::E_NOT_EXISTS, "not found departmentId {$departmentId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_EXISTS, "not found departmentId {$departmentId}");
}
$old->admins = json_decode($old->admins);
if (!in_array($userId, $old->admins)) {
Log::error(Error::E_FORBIDDEN, "not in admin"); // 记录到日志文件
return Output::makeResult($request, Error::E_FORBIDDEN, "not in admin");
}
$changeParent = (isset($data['parent']) && $data['parent'] != $old->parent);
if ($changeParent) {
if (!in_array($userId, $super->admins)) {
Log::error(Error::E_FORBIDDEN, "not in parent admin"); // 记录到日志文件
return Output::makeResult($request, Error::E_FORBIDDEN, "not in parent admin");
}
}
$data['mtime'] = date('Y-m-d H:i:s');
unset($data['ctime']);
unset($data['departmentId']);
UserDepartmentModel::updateDataByDepartmentId($departmentId, $data);
Redis::del('__department_all');
return Output::makeResult($request, 0, null, ['departmentId' => $departmentId]);
} catch (\Exception $e) {
Log::error(Error::E_SERVER, "unknow server error: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, "unknow server error: " . $e->getMessage() . ", try agant");
}
}
public function delete(Request $request, $departmentId)
{
$userId = $request->user->userId;
try {
$dep = UserDepartmentModel::getDepartmentIdList($departmentId);
if (!$dep) {
Log::error(Error::E_NOT_EXISTS, "not found departmentId {$departmentId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_EXISTS, "not found departmentId {$departmentId}");
}
$super = UserDepartmentModel::getDepartmentIdList($dep->parent);
if (!$super) {
Log::error(Error::E_SERVER, "can't find parent"); // 记录到日志文件
Log::error("can't find department, id={$dep->parent}, sub department = {$departmentId}");
return Output::makeResult($request, Error::E_SERVER, "can't find parent");
}
$super->admins = json_decode($super->admins);
if (!in_array($userId, $super->admins)) {
Log::error(Error::E_FORBIDDEN, "not in parent admin"); // 记录到日志文件
return Output::makeResult($request, Error::E_FORBIDDEN, "not in parent admin");
}
$count = UserDepartmentModel::countDepartmentId($departmentId) + OrganizationModel::countDepartmentId($departmentId);
if ($count > 0) {
Log::error(Error::E_STATUS, "请先删除子部门和人员"); // 记录到日志文件
return Output::makeResult($request, Error::E_STATUS, "请先删除子部门和人员");
}
UserDepartmentModel::deleteDepartmentId($departmentId);
Redis::del('__department_all');
return Output::makeResult($request, 0);
} catch (\Exception $e) {
Log::error(Error::E_SERVER, "unknow server error: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, "unknow server error: " . $e->getMessage() . ", try agant");
}
}
public function addPeople(Request $request, $departmentId)
{
$userId = (int)$request->input('userId', -1);
$isPart = (int)$request->input('isPart', -1);
if ($userId <= 0 || $isPart < 0) {
Log::error(Error::E_PARAM, "bad request: invaild userId = {$userId} or isPart = {$isPart}"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "bad request: invaild userId = {$userId} or isPart = {$isPart}");
}
if ($departmentId < 0) {
Log::error(Error::E_PARAM, "bad request: invaild departmentId ={$departmentId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "bad request: invaild departmentId ={$departmentId}");
}
if ($isPart)
$isPart = 1;
try {
$user = UserInfoModel::getIdByStatus($userId, 4);
if (!$user) {
Log::error(Error::E_PARAM, "bad request: not found userId {$userId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "bad request: not found userId {$userId}");
}
$dep = DepartmentModel::getDepartmentId($departmentId);
if (!$dep) {
Log::error(Error::E_NOT_EXISTS, "not found department {$departmentId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_EXISTS, "not found department {$departmentId}");
}
$dep->admins = json_decode($dep->admins);
if (!in_array($request->user->userId, $dep->admins)) {
Log::error(Error::E_FORBIDDEN, "not in admins"); // 记录到日志文件
return Output::makeResult($request, Error::E_FORBIDDEN, "not in admins");
}
DB::insert('REPLACE INTO organization(departmentId,userId,isPartTime,ctime) VALUES(?,?,?,NOW())',
[$departmentId, $userId, $isPart]);
Redis::del('__department_all');
return Output::makeResult($request, 0);
} catch (\Exception $e) {
Log::error(Error::E_SERVER, "unknow server error: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, "unknow server error: " . $e->getMessage() . ", try agant");
}
}
public function delPeople(Request $request, $departmentId)
{
$userId = (int)$request->input('userId', -1);
if ($userId <= 0) {
Log::error(Error::E_PARAM, "bad request: invaild userId{$userId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "bad request: invaild userId{$userId}");
}
if ($departmentId < 0) {
Log::error(Error::E_PARAM, "bad request: invaild departmentId ={$departmentId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "bad request: invaild departmentId ={$departmentId}");
}
try {
$dep = DepartmentModel::getDepartmentId($departmentId);
if (!$dep) {
Log::error(Error::E_NOT_EXISTS, "not found department {$departmentId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_EXISTS, "not found department {$departmentId}");
}
$dep->admins = json_decode($dep->admins);
if (!in_array($request->user->userId, $dep->admins)) {
Log::error(Error::E_FORBIDDEN, "not in admins"); // 记录到日志文件
return Output::makeResult($request, Error::E_FORBIDDEN, "not in admins");
}
OrganizationModel::deleteDepartmentId($departmentId, $userId);
Redis::del('__department_all');
return Output::makeResult($request, 0);
} catch (\Exception $e) {
Log::error(Error::E_SERVER, "unknow server error: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, "unknow server error: " . $e->getMessage() . ", try agant");
}
}
public function getDepartmentPath($departmentId)
{
$path = $this->departmentPaths([$departmentId]);
if ($path === false)
return false;
return $path[0];
}
public function pathTitle($path)
{
$ret = '';
if ($path) {
foreach ($path as $ent) {
if ($ret)
$ret = $ret . '/';
$ret = $ret . $ent['title'];
}
}
return $ret;
}
public function departmentPaths(array $ids)
{
$depinfo = $this->getALLDepartment()['tree'];
$result = [];
foreach ($ids as $id) {
$path = [];
for (; ;) {
if (!isset($depinfo[$id]))
continue;
$info = $depinfo[$id];
$path[] = ['departmentId' => $id, 'title' => $info[0], 'isVirtual' => $info[2]];
if ($id == 0)
break;
$id = $info[2];
}
$result[] = array_reverse($path);
}
return $result;
}
public function getDepartments($request, $userId)
{
if ($userId <= 0) {
Log::error(Error::E_PARAM, "bad request: invaild userId{$userId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "bad request: invaild userId{$userId}");
}
try {
$deps = OrganizationModel::getUserIdByIspartAndCtime($userId);
if (!$deps)
return Output::makeResult($request, 0, null, ['userId' => $userId, 'departments' => []]);
$ids = [];
foreach ($deps as $dep)
$ids[$dep->departmentId] = true;
$departments = $this->departmentPaths(array_keys($ids));
if ($departments === false) {
Log::error(Error::E_SERVER, "data error"); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, "data error");
}
return Output::makeResult($request, 0, null, ['userId' => $userId, 'departments' => $departments]);
} catch (\Exception $e) {
Log::error(Error::E_SERVER, "unknow server error: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, "unknow server error: " . $e->getMessage() . ", try agant");
}
}
public function complete(Request $request)
{
$q = $request->input("q", "");
$arr = ['q' => $q, "results" => []];
$key = $q . "%";
try {
$ret = DepartmentModel::getDepartmentIdTitlePatent($key, 10);
if (!$ret)
return $arr;
$id = [];
foreach ($ret as $dep)
$id[] = $dep->departmentId;
$departments = $this->departmentPaths($id);
if ($departments === false)
return $arr;
foreach ($departments as $idx => $paths) {
$path = '';
foreach ($paths as $item) {
if ($path)
$path = $path . '/';
$path = $path . $item["title"];
}
$arr["results"][] = ['id' => $ret[$idx]->departmentId, 'text' => $path];
}
} catch (\Exception $e) {
Log::error(Error::E_SERVER, "unknow server error: " . $e->getMessage()); // 记录到日志文件
Log::error("complete failed: error " . $e->getMessage());
}
return $arr;
}
public function getSubInfoImpl(Request $request, $dep)
{
$path = null;
$departmentId = $dep->departmentId;
if (isset($dep->path)) {
$path = $dep->path;
unset($dep->path);
} else {
$path = $dep->departmentId ? $this->getDepartmentPath($dep->parent) : [];
}
$path[] = ['departmentId' => $departmentId, 'title' => $dep->title, 'isVirtual' => $dep->isVirtual];
$canModify = in_array($request->user->userId, $dep->admins);
$users = OrganizationModel::getDepartmentInfoMap($departmentId);
$tree = $this->getALLDepartment();
$sub = [];
if (isset($tree['parent'][$departmentId])) {
foreach ($tree['parent'][$departmentId] as $pid) {
$info = $tree['tree'][$pid];
$canDelete = ($info[3] == 0 && (!isset($tree['parent'][$pid]) || $tree['parent'][$pid] == 0));
$sub[] = [
'departmentId' => $pid,
'title' => $info[0],
'isVirtual' => $info[2],
'total' => $info[3],
'canDelete' => $canDelete
];
}
}
return compact('departmentId', 'path', 'canModify', 'users', 'sub');
}
public function getSubInfo(Request $request, $departmentId)
{
if ($departmentId < 0) {
Log::error(Error::E_PARAM, "Bad Request: invaild departmentId {$departmentId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: invaild departmentId {$departmentId}");
}
try {
$dep = DepartmentModel::getDepartmentId($departmentId);
if (!$dep) {
Log::error(Error::E_NOT_EXISTS, "not found {$departmentId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_EXISTS, "not found {$departmentId}");
}
$dep->admins = json_decode($dep->admins);
$result = $this->getSubInfoImpl($request, $dep);
return Output::makeResult($request, 0, null, $result);
} catch (\Exception $e) {
Log::error(Error::E_SERVER, "unknow server error: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, "unknow server error: " . $e->getMessage() . ", try agant");
}
}
public function getInfo(Request $request, $departmentId)
{
$department_id = DepartmentModel::getDepartmentId($departmentId);
if (!$department_id)
return $department_id;
$department_id->admins = json_decode($department_id->admins);
$department_id->second = json_decode($department_id->second);
$ids = [];
$infos = [];
if (!empty($department_id->first))
$ids[] = $department_id->first;
if (!empty($department_id->admins))
$ids = array_merge($department_id->admins, $ids);
if (!empty($department_id->second))
$ids = array_merge($department_id->second, $ids);
if (count($ids) > 0) {
$objs = UserInfoModel::getUserIdStatus($ids, 4);
foreach ($objs as $obj)
$infos[$obj->userId] = $obj;
}
if (isset($infos[$department_id->first])) {
$u = $infos[$department_id->first];
$department_id->firstTitle = $u->engName . (!empty($u->name) ? ('(' . $u->name . ')') : '');
} else {
$department_id->first = '';
}
$ids = [];
$title = [];
if ($department_id->admins) {
foreach ($department_id->admins as $id) {
if (!isset($infos[$id]))
continue;
$ids[] = $id;
$u = $infos[$id];
$title[] = $u->engName . (!empty($u->name) ? ('(' . $u->name . ')') : '');
}
}
$department_id->admins = $ids;
$department_id->adminsTitle = $title;
$ids = [];
$title = [];
if ($department_id->second) {
foreach ($department_id->second as $id) {
if (!isset($infos[$id]))
continue;
$ids[] = $id;
$u = $infos[$id];
$title[] = $u->engName . (!empty($u->name) ? ('(' . $u->name . ')') : '');
}
}
$department_id->second = $ids;
$department_id->secondTitle = $title;
if ($department_id->departmentId != 0) {
$department_id->path = $this->getDepartmentPath($department_id->parent);
$department_id->parentTitle = $this->pathTitle($department_id->path);
} else {
$department_id->path = [];
$department_id->parentTitle = '';
}
$department_id->subInfo = $this->getSubInfoImpl($request, $department_id);
return $department_id;
}
public function countTree($parent, $root)
{
$total = [];
if (isset($parent[$root->departmentId])) {
foreach ($parent[$root->departmentId] as $obj) {
$total = array_merge($total, $this->countTree($parent, $obj));
}
}
$total = array_unique(array_merge($total, $root->total));
$root->total = count($total);
return $total;
}
public function getALLDepartment()
{
if ($this->organization)
return $this->organization;
$data = Redis::get('__department_all');
if (!$data || !($data = json_decode($data, true))) {
$deps = DepartmentModel::getDepartmentIdParentIsvirtulTitle();
$users = OrganizationModel::getUserIdDepartment();
$counts = [];
foreach ($users as $count)
$counts[$count->departmentId][] = $count->userId;
$tree = [];
$parent = [];
foreach ($deps as $dep) {
$tree[$dep->departmentId] = $dep;
$dep->total = isset($counts[$dep->departmentId]) ? $counts[$dep->departmentId] : [];
if ($dep->departmentId != 0)
$parent[$dep->parent][] = $dep;
}
if (isset($tree[0]))
$this->countTree($parent, $tree[0]);
$trimTree = [];
$trimParent = [];
foreach ($tree as $id => $dep) {
$trimTree[$id] = [$dep->title, (int)$dep->parent, (int)$dep->isVirtual, (int)$dep->total];
if ($id != 0)
$trimParent[$dep->parent][] = (int)$id;
}
$data = ['tree' => $trimTree, 'parent' => $trimParent];
Redis::set('__department_all', json_encode($data));
}
$this->organization = $data;
return $data;
}
}
...@@ -169,7 +169,7 @@ private static function saveToRedis($info, $expire = 0) ...@@ -169,7 +169,7 @@ private static function saveToRedis($info, $expire = 0)
return Cache::getRedis()->setex($key, $expire, json_encode($info)); return Cache::getRedis()->setex($key, $expire, json_encode($info));
} }
private function setLoginCookie($userId, $skey, $header, $expire) public static function setLoginCookie($userId, $skey, $header, $expire)
{ {
$domain = Config::get('website.cookieDomain'); $domain = Config::get('website.cookieDomain');
$allow_domain_list = explode(",", $domain); $allow_domain_list = explode(",", $domain);
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
use App\Http\Service\LdapManagerService; use App\Http\Service\LdapManagerService;
use App\Http\Service\PermService; use App\Http\Service\PermService;
use App\Http\Service\UserService; use App\Http\Service\UserService;
use App\Http\Service\UserTokenService;
use App\Models\crm\EmployeeCardModel;
use App\Models\queue\QueuedModel; use App\Models\queue\QueuedModel;
use App\Models\user\DepartmentModel; use App\Models\user\DepartmentModel;
use App\Models\user\PositionModel; use App\Models\user\PositionModel;
...@@ -18,10 +20,13 @@ ...@@ -18,10 +20,13 @@
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Mockery\CountValidator\Exception; use Mockery\CountValidator\Exception;
class UserController extends Controller class UserController extends Controller
{ {
const STATUS_NEED_CHANGE_PASSWD = 1;
//用户详情 //用户详情
public function info(Request $request, $userId = 0) public function info(Request $request, $userId = 0)
{ {
...@@ -49,11 +54,11 @@ public function info(Request $request, $userId = 0) ...@@ -49,11 +54,11 @@ public function info(Request $request, $userId = 0)
abort(404); abort(404);
} }
// 如果头像地址不是正确的url,那么为空字符串,避免修改信息失败 // 如果头像地址不是正确的url,那么为空字符串,避免修改信息失败
if (!filter_var($user_info->header, FILTER_VALIDATE_URL)) { if (!filter_var($user_info['header'], FILTER_VALIDATE_URL)) {
$user_info->header = ""; $user_info['header'] = "";
} }
$department_id_name_parentId_list = DepartmentModel::getDepList(); $department_id_name_parentId_list = DepartmentModel::getDepartmentInfoList(['department_id', 'department_name', 'parent_id']);
$department_tree = UserService::generateTree($department_id_name_parentId_list); $department_tree = UserService::generateTree($department_id_name_parentId_list);
$data = [ $data = [
...@@ -67,7 +72,7 @@ public function info(Request $request, $userId = 0) ...@@ -67,7 +72,7 @@ public function info(Request $request, $userId = 0)
'active' => $userId == $request->user->userId ? 'my' : 'userlist', 'active' => $userId == $request->user->userId ? 'my' : 'userlist',
'isAdmin' => $isAdmin, 'isAdmin' => $isAdmin,
'userInfo' => $user_info, 'userInfo' => $user_info,
'department_html' => DepartmentService::getDepartmentHtml($department_tree), 'department_html' => UserService::getDepartmentHtml($department_tree),
'position' => PositionModel::getPositionNameMap(), // 职位 'position' => PositionModel::getPositionNameMap(), // 职位
'paths' => [ 'paths' => [
['href' => '/userlist', 'title' => '帐号列表'], ['href' => '/userlist', 'title' => '帐号列表'],
...@@ -154,14 +159,12 @@ public function update(Request $request) ...@@ -154,14 +159,12 @@ public function update(Request $request)
$info['mtime'] = date('Y-m-d H:i:s'); $info['mtime'] = date('Y-m-d H:i:s');
$email = $request->user->email;; $email = $request->user->email;;
// var_dump($request->getUserResolver()());
if (!in_array($email, Config::get('website.admin')) && $userId == $request->getUserResolver()()->userId) { if (!in_array($email, Config::get('website.admin')) && $userId == $request->getUserResolver()()->userId) {
unset($info['status']); unset($info['status']);
} }
$user = UserInfoModel::getInfoById($userId); $user = UserInfoModel::getInfoById($userId);
$info['email'] = $user[0]->email; $info['email'] = $user['email'];
DB::transaction(function () use ($info, $userId) { DB::transaction(function () use ($info, $userId) {
DB::table('user_info')->where('userId', $userId)->update($info); DB::table('user_info')->where('userId', $userId)->update($info);
...@@ -218,14 +221,14 @@ public function update(Request $request) ...@@ -218,14 +221,14 @@ public function update(Request $request)
// 如果部门不一样,那么ldap需要删除用户,在重新创建用户 // 如果部门不一样,那么ldap需要删除用户,在重新创建用户
if ($info['department_id'] != $user->department_id) { if ($info['department_id'] != $user['department_id']) {
$root_department_id = DepartmentService::getRootDepartmentId($user->department_id); $root_department_id = DepartmentService::getRootDepartmentId($user['department_id']);
if (isset($cms_department_id_with_ldap_map[$root_department_id])) { if (isset($cms_department_id_with_ldap_map[$root_department_id])) {
$businessCategory = $cms_department_id_with_ldap_map[$root_department_id]['ldap_department_name']; $businessCategory = $cms_department_id_with_ldap_map[$root_department_id]['ldap_department_name'];
} else { } else {
$businessCategory = $default_ldap_group_info['ldap_department_name']; $businessCategory = $default_ldap_group_info['ldap_department_name'];
} }
$ldap->ldapDelete($user->email, $businessCategory); $ldap->ldapDelete($user['email'], $businessCategory);
// 重新创建ldap用户 // 重新创建ldap用户
$userInfo = DB::table('user_info')->where('userId', $userId)->first(); $userInfo = DB::table('user_info')->where('userId', $userId)->first();
...@@ -263,7 +266,7 @@ public function update(Request $request) ...@@ -263,7 +266,7 @@ public function update(Request $request)
} }
if ($userId == $request->user->userId && isset($info['header']) && $info['header'] != $request->cookie('oa_header')) { if ($userId == $request->user->userId && isset($info['header']) && $info['header'] != $request->cookie('oa_header')) {
$this->setLoginCookie(null, null, $info['header'], time() + self::expireTime()); LoginController::setLoginCookie(null, null, $info['header'], time() + self::expireTime());
} }
// 推入到队列 // 推入到队列
...@@ -286,7 +289,172 @@ public function update(Request $request) ...@@ -286,7 +289,172 @@ public function update(Request $request)
"unknown server error: " . $err_msg . ", try again"); "unknown server error: " . $err_msg . ", try again");
} }
} }
public function createUser(Request $request)
{
try {
$token = $request->input('token', '');
if ($token != $request->cookie('crsf_token')) {
Log::error("Bad Request: invaild token $token"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: invaild token $token");
}
$email = $request->user->email;
if (!in_array($email, Config::get('website.admin'))) {
Log::error("not admin"); // 记录到日志文件
return Output::makeResult($request, Error::E_FORBIDDEN, "not admin");
}
$now = date('Y-m-d H:i:s');
$info = UserService::extractUserInfoFromReq($request, true);
if (!isset($info['email']) || strlen($info['email']) == 0 || !isset($info['engName']) || strlen($info['engName']) == 0 || !isset($info['name']) || strlen($info['name']) == 0) {
Log::error("邮箱、英文名或中文名没有设置"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "邮箱、英文名或中文名没有设置");
}
$status = $info['status'];
unset($info['userId']);
unset($info['status']);
$ret = UserService::checkUserInfo($info);
if ($ret !== true) {
Log::error(json_encode($ret)); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, array_pop($ret));
}
$registered = UserInfoModel::CheckUserRegistered($info['email'], $info['engName']);
if ($registered) {
Log::error("email or engName already exists"); // 记录到日志文件
return Output::makeResult($request, Error::E_DUP, "email or engName already exists");
}
if (!$info['department_id']) {
return Output::makeResult($request, Error::E_PARAM, "部门没有设置");
}
$userId = 0;
DB::transaction(function () use (&$info, &$userId, $now) {
$pass = bin2hex(openssl_random_pseudo_bytes(5));
$slat = UserService::createSlat();
$passwd = UserService::createPasswd(md5($pass), $slat);
$data = [
'slat' => $slat,
'status' => self::STATUS_NEED_CHANGE_PASSWD,
'passwd' => $passwd,
'ctime' => $now,
'mtime' => $now
];
$userId = UserModel::InsertUser($data);
if ($userId === false) {
throw new Exception("新增用户表失败");
}
$info['userId'] = $userId;
$info['ctime'] = $now;
$info['mtime'] = $now;
$ret = UserInfoModel::InsertUser($info);
if ($ret === false) {
throw new Exception("新增用户信息表失败");
}
// 获取用户角色绑定权限
$rolePerm = PositionPermModel::getUserRolePermList($info['position_id']);
if (!empty($rolePerm)) {
$del = PermService::delUserPerms($userId);
if ($del === false) {
throw new Exception("清除用户所有权限失败");
}
foreach ($rolePerm as $v) {
$res = PermService::setUserRolePerm($info, $v['bid'], $v['role_id']);
if ($res === false) {
throw new Exception("新增用户权限失败");
}
}
} else { // 若没绑定角色权限,则用户默认分配账号系统运营权限
$info['title'] = '内部用户管理系统';
$res = PermService::setupUserPerm($info);
if ($res === false) {
throw new Exception("新增账号系统运营权限失败");
}
}
try {
$ldap = new LdapManagerService();
$default_ldap_group_info = Config('config.default_ldap_group_info');
$cms_department_id_with_ldap_map = Config('config.cms_department_id_with_ldap_map');
$root_department_id = DepartmentService::getRootDepartmentId($info['department_id']);
if (isset($cms_department_id_with_ldap_map[$root_department_id])) {
$info['gidNumber'] = $cms_department_id_with_ldap_map[$root_department_id]['ldap_gid'];
$info['businessCategory'] = $cms_department_id_with_ldap_map[$root_department_id]['ldap_department_name'];
} else {
$info['gidNumber'] = $default_ldap_group_info['ldap_gid'];
$info['businessCategory'] = $default_ldap_group_info['ldap_department_name'];
}
$ldap->ldapCreateUser($info);
} catch (\Exception $e) {
Log::error("create ldap user failed: info=" . json_encode($info));
}
DepartmentService::getSubDepartmentId(Config('config.online_sales_department_id'),
$online_sales); // 获取线上销售部门ID集合
// 若新增用户属于线上部门,则添加到CRM员工卡
if (in_array($info['department_id'], $online_sales)) {
$employee = [];
$employee['sale_id'] = $userId;
$employee['sale_name'] = $info['name'];
$employee['email'] = $info['email'];
$res = EmployeeCardModel::insert($employee);
if ($res === false) {
throw new Exception("新增用户到CRM员工卡失败");
}
}
});
// 创建一个设置密码
$token = UserTokenService::createToken($userId, Config::get('website.setpasswdTokenExpire'));
if ($token) {
$url = $request->url();
$pos = strpos($url, '/', strpos($url, '//') + 2);
if ($pos) {
$url = substr($url, 0, $pos);
}
$url = $url . '/resetpasswd?uid=' . $userId . '&token=' . urlencode($token['token'])
. '&expire=' . urlencode($token['expireTime']);
Mail::send('email.setpasswd', ['url' => $url], function ($msg) use ($info) {
$name = !empty($info["name"]) ? $info["name"] : $info["engName"];
$msg->to($info["email"], $name);
$msg->subject('设置密码');
});
}
// 推入到队列
if (strpos(Config('website.user_url'), 'liexin') === false) { // 本地暂不推队列
$saveData['type'] = 'user.syn';
$userData['userid'] = $info['userId'];
$userData['email'] = $info['email'];
$userData['name'] = $info['name'];
$userData['status'] = $status == 0 ? 1 : -1;
$saveData['data'] = $userData;
$queue = new QueuedModel();
$queue->pushAmq(json_encode($saveData));
}
return Output::makeResult($request, 0, null, ['userId' => $userId]);
} catch (\Exception $e) {
Log::error("unknown server error: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER,
"unknown server error: " . $e->getMessage() . ", try again");
}
}
// 账号列表 // 账号列表
public function userlist(Request $request) public function userlist(Request $request)
{ {
...@@ -318,12 +486,98 @@ public function userlist(Request $request) ...@@ -318,12 +486,98 @@ public function userlist(Request $request)
return view('user.userlist', $data); return view('user.userlist', $data);
} }
//新增用户按钮
public function createNewUser(Request $request)
{
// 获取用户角色,用户权限
$user_role = PermService::getUserRole($request);
$userPerms = PermService::getUserAllPerms($request->user->userId, $user_role); // 用户权限
if (!in_array($request->user->email, Config::get('website.admin')) && !in_array('user_userlist_create',
$userPerms)) {
abort(403);
}
public static function expireTime() $data = [
'title' => '创建帐号',
'active' => 'userlist',
'isAdmin' => true,
'limitInfo' => false,
'position' => PositionModel::getPositionNameMap(),
'department_html' => DepartmentService::getDepartmentHtml(),
'paths' => [
['href' => '/user/userlist', 'title' => '帐号列表'],
['href' => '/user/create', 'title' => '创建帐号']
]
];
return view('user.info', $data);
}
private static function expireTime()
{ {
$expire = Config::get('website.skeyExpire'); $expire = Config::get('website.skeyExpire');
return $expire ? $expire : 3600 * 12; return $expire ? $expire : 3600 * 12;
} }
// 线上销售离职,推送到CRM队列
public function sysToCrm($info)
{
$department_ids = [];
DepartmentService::getSubDepartmentId(33, $department_ids); // 获取线上销售所有部门
if (!in_array($info['department_id'], $department_ids)) {
return false;
}
$queue = new QueuedModel();
$queue_name = 'crm_online_sales_leave';
$data['sale_id'] = intval($info['userId']);
$queue->pushQueue($queue_name, json_encode($data));
}
public function delete(Request $request, $userId)
{
if ($userId <= 0) {
Log::error( "Bad Request: invaild userId {$userId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: invaild userId {$userId}");
}
if (!in_array($request->user->email, Config::get('website.admin'))) {
Log::error("not admin"); // 记录到日志文件
return Output::makeResult($request, Error::E_FORBIDDEN, "not admin");
}
try {
$ret = UserInfoModel::getInfoById($userId);
if (!isset($ret)) {
Log::error("not found {$userId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_EXISTS, "not found {$userId}");
}
if ($ret['status'] != 4) {
Log::error("status != 4"); // 记录到日志文件
return Output::makeResult($request, Error::E_STATUS, "status != 4");
}
$ldap = new LdapManagerService();
$default_ldap_group_info = Config('config.default_ldap_group_info');
$cms_department_id_with_ldap_map = Config('config.cms_department_id_with_ldap_map');
$root_department_id = DepartmentService::getRootDepartmentId($ret['department_id']);
if (isset($cms_department_id_with_ldap_map[$root_department_id])) {
$businessCategory = $cms_department_id_with_ldap_map[$root_department_id]['ldap_department_name'];
} else {
$businessCategory = $default_ldap_group_info['ldap_department_name'];
}
$ldap->ldapDelete($ret['email'], $businessCategory);
UserInfoModel::deleteInfoById($userId);
return Output::makeResult($request, 0);
} catch (\Exception $e) {
Log::error( "unknown server: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER,
"unknown server error: " . $e->getMessage(). ", try again");
}
}
} }
......
...@@ -41,9 +41,9 @@ class Kernel extends HttpKernel ...@@ -41,9 +41,9 @@ class Kernel extends HttpKernel
], ],
'api' => [ 'api' => [
\App\Http\Middleware\CheckLogin::class,
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api', 'throttle:api',
\App\Http\Middleware\CheckLogin::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class, \Illuminate\Routing\Middleware\SubstituteBindings::class,
], ],
'noauth' => [], 'noauth' => [],
......
...@@ -16,7 +16,7 @@ class DepartmentService extends CommonModel ...@@ -16,7 +16,7 @@ class DepartmentService extends CommonModel
// 获取菜单 // 获取菜单
public static function getDepartmentHtml() public static function getDepartmentHtml()
{ {
$department_id_name_parentId_list = DepartmentModel::getDepList(); $department_id_name_parentId_list = DepartmentModel::getDepartmentInfoList(['department_id', 'department_name', 'parent_id']);
$department_tree = self::generateTree($department_id_name_parentId_list); $department_tree = self::generateTree($department_id_name_parentId_list);
return self::makeDepartmentHtml($department_tree); return self::makeDepartmentHtml($department_tree);
} }
...@@ -72,7 +72,7 @@ public static function getSubDepartmentId($department_id, &$department_ids) ...@@ -72,7 +72,7 @@ public static function getSubDepartmentId($department_id, &$department_ids)
if ($sub_department) { if ($sub_department) {
foreach ($sub_department as $v) { foreach ($sub_department as $v) {
self::getSubDepartmentId($v->department_id, $department_ids); self::getSubDepartmentId($v['department_id'], $department_ids);
} }
} }
......
...@@ -250,7 +250,6 @@ public function ldapDelete($email, $ldap_department_name) ...@@ -250,7 +250,6 @@ public function ldapDelete($email, $ldap_department_name)
ldap_close($ldapconn); ldap_close($ldapconn);
return $ret ? true : false; return (bool)$ret;
} }
} }
...@@ -63,10 +63,10 @@ public static function getUserRole(Request $request): int ...@@ -63,10 +63,10 @@ public static function getUserRole(Request $request): int
$business = TBusinessConfigModel::getBusinessInfoByTitle('内部用户管理系统'); $business = TBusinessConfigModel::getBusinessInfoByTitle('内部用户管理系统');
if ($business) { if ($business) {
$bid = $business->bid; $bid = $business['bid'];
// 权限系统配置的管理帐号 // 权限系统配置的管理帐号
$admin_account = json_decode($business->admin, true); $admin_account = json_decode($business['admin'], true);
if (in_array($email, $admin_account)) { if (in_array($email, $admin_account)) {
return 1; return 1;
...@@ -87,8 +87,8 @@ public static function getUserRole(Request $request): int ...@@ -87,8 +87,8 @@ public static function getUserRole(Request $request): int
foreach ($role as $role_id) { foreach ($role as $role_id) {
$role_info = TRolePermModel::getRoleInfoByRoleIdAndBid($role_id, $bid); $role_info = TRolePermModel::getRoleInfoByRoleIdAndBid($role_id, $bid);
if ($role_info) { if ($role_info) {
return in_array($role_info->name, array_keys(self::$roles)) ? array_get(self::$roles, return in_array($role_info['name'], array_keys(self::$roles)) ? array_get(self::$roles,
$role_info->name) : 0; $role_info['name']) : 0;
} }
} }
} }
...@@ -115,7 +115,7 @@ public static function getUserAllPerms($user_id, $role = 0) ...@@ -115,7 +115,7 @@ public static function getUserAllPerms($user_id, $role = 0)
return $user_perms['data']['perms']; return $user_perms['data']['perms'];
} }
} else { // 获取管理员所有权限 } else { // 获取管理员所有权限
return self::getAllPerms(json_decode($business->configs, true)); return self::getAllPerms(json_decode($business['configs'], true));
} }
} }
...@@ -198,7 +198,7 @@ public static function getParentDepartment($id) ...@@ -198,7 +198,7 @@ public static function getParentDepartment($id)
{ {
$parentId = DepartmentModel::getParentId($id); $parentId = DepartmentModel::getParentId($id);
$parentDep = DepartmentModel::getInfoById($parentId); $parentDep = DepartmentModel::getInfoById($parentId);
if(isset($parentDep[0])){ if (isset($parentDep[0])) {
return $parentDep[0]['department_name']; return $parentDep[0]['department_name'];
} }
return ''; return '';
...@@ -246,7 +246,7 @@ public static function delUserPerms($userId) ...@@ -246,7 +246,7 @@ public static function delUserPerms($userId)
public static function setupUserPerm($info, $rolename = '运营') public static function setupUserPerm($info, $rolename = '运营')
{ {
$business_info = TBusinessConfigModel::getBusinessInfoByTitle($info['title']); $business_info = TBusinessConfigModel::getBusinessInfoByTitle($info['title']);
$data['bid'] = $business_info->bid; $data['bid'] = $business_info['bid'];
$data['userId'] = $info['userId']; $data['userId'] = $info['userId'];
// 检查是否存在 // 检查是否存在
...@@ -266,8 +266,8 @@ public static function setupUserPerm($info, $rolename = '运营') ...@@ -266,8 +266,8 @@ public static function setupUserPerm($info, $rolename = '运营')
} }
// 不存在则创建 // 不存在则创建
$role = TRolePermModel::getBidUsername($business_info->bid, $rolename); $role = TRolePermModel::getBidUsername($business_info['bid'], $rolename);
$data['roles'] = json_encode(array("{$role->roleId}")); $data['roles'] = json_encode(array("{$role['roleId']}"));
$data['perms'] = json_encode(array()); $data['perms'] = json_encode(array());
$data['username'] = $info['email']; $data['username'] = $info['email'];
$data['begDate'] = date('Y-m-d'); $data['begDate'] = date('Y-m-d');
......
...@@ -19,35 +19,41 @@ public static function createPasswd($passwd, $slat) ...@@ -19,35 +19,41 @@ public static function createPasswd($passwd, $slat)
{ {
return hash('sha256', md5($passwd) . $slat); return hash('sha256', md5($passwd) . $slat);
} }
public static function createSlat()
{
return base64_encode(openssl_random_pseudo_bytes(self::SLAT_LENGTH));
}
public static function getUserInfo($userId, $isLimit) public static function getUserInfo($userId, $isLimit)
{ {
$user_info = UserInfoModel::getNameWithEngNameMap($userId);
$info = UserInfoModel::getInfoById($userId); $info = UserInfoModel::getInfoById($userId);
$boss = UserInfoModel::getInfoById($info[0]->superior); $boss = UserInfoModel::getInfoById($info['superior']);
$user_info = $info[0]; $user_info = $info;
if(isset($boss[0])){ var_dump($boss);
$user_info->sup_engName = $boss->engName; if($boss){
$user_info->sup_name = $boss->name; $user_info['sup_engName'] = $boss['engName'];
$user_info['sup_name'] = $boss['name'];
} }
if ($isLimit) { if ($isLimit) {
unset($user_info->idCard); unset($user_info['idCard']);
unset($user_info->birthday); unset($user_info['birthday']);
unset($user_info->sex); unset($user_info['sex']);
unset($user_info->abo); unset($user_info['abo']);
unset($user_info->emergencyPeople); unset($user_info['emergencyPeople']);
unset($user_info->emergencyPhone); unset($user_info['emergencyPhone']);
unset($user_info->address); unset($user_info['address']);
} }
$supTitle = $user_info->sup_engName; $supTitle = '';
if (!empty($user_info->sup_name)) { if(!empty($user_info['sup_engName'])){
$supTitle = $supTitle . '(' . $user_info->sup_name . ')'; $supTitle = $user_info['sup_engName'];
} }
unset($user_info->sup_engName); if (!empty($user_info['sup_name'])) {
unset($user_info->sup_name); $supTitle = $supTitle . '(' . $user_info['sup_name'] . ')';
}
unset($user_info['sup_engName']);
unset($user_info['sup_name']);
$user_info->supTitle = $supTitle; $user_info['supTitle'] = $supTitle;
return $user_info; return $user_info;
} }
...@@ -298,4 +304,25 @@ public static function generateTree($list, $pk = 'department_id', $pid = 'parent ...@@ -298,4 +304,25 @@ public static function generateTree($list, $pk = 'department_id', $pid = 'parent
return $department_tree; return $department_tree;
} }
// 部门添加html
public static function getDepartmentHtml($tree)
{
$html = '';
foreach ($tree as $v) {
$subClass = isset($v['_child']) ? 'class="dropdown-submenu"' : '';
if (isset($v['_child'])) {
$html .= '<li ' . $subClass . '>'
. '<a tabindex="-1" data-id="' . $v['department_id'] . '">' . $v['department_name'] . '</a>
<ul class="dropdown-menu">'
. self::getDepartmentHtml($v['_child'])
. '</a></ul></li>';
} else {
$html .= '<li ' . $subClass . '><a data-id="' . $v['department_id'] . '">' . $v['department_name'] . '</a></li>';
}
}
return $html;
}
} }
...@@ -6,4 +6,7 @@ ...@@ -6,4 +6,7 @@
class CommonModel extends Model class CommonModel extends Model
{ {
public static function queryWhere($whereList){
return self::where($whereList)->get()->toArray();
}
} }
...@@ -14,28 +14,60 @@ class DepartmentModel extends CommonModel ...@@ -14,28 +14,60 @@ class DepartmentModel extends CommonModel
const CREATED_AT = 'ctime'; const CREATED_AT = 'ctime';
const UPDATED_AT = 'mtime'; const UPDATED_AT = 'mtime';
public static function getDepList()
{
return self::select('department_id', 'department_name', 'parent_id')->get()->toArray();
}
public static function getParentId($id) public static function getParentId($id)
{ {
return self::select('department_id', 'department_name', 'parent_id')->where('department_id', $id)->get()->toArray(); $res = self::select('department_id', 'department_name', 'parent_id')->where('department_id', $id)->first();
return $res ? $res->toArray() : [];
} }
public static function getInfoById($id) public static function getInfoById($id)
{ {
return self::where('department_id', $id)->get()->toArray(); $res = self::where('department_id', $id)->first();
return $res ? $res->toArray() : [];
}
public static function deleteDepartmentId($departmentId)
{
self::where('department_id', $departmentId)->delete();
} }
public static function getDepartmentNameWithIdArray() public static function getDepartmentNameWithIdArray()
{ {
return self::select('department_name', 'department_id')->get(); $res = self::select('department_name', 'department_id')->get();
return $res;
} }
public static function getDepartmentIdWithNameList($department_id) public static function getDepartmentIdWithNameList($department_id)
{ {
return self::where('parent_id', $department_id)->select('department_id', 'department_name')->get(); $res = self::where('parent_id', $department_id)->select('department_id', 'department_name')->get();
return ($res) ? $res->toArray() : [];
}
public static function getDepartmentInfoList($select)
{
$res = self::select($select)->get();
return ($res) ? $res->toArray() : [];
}
public static function getDepartmentListByIds($ids)
{
$res = self::whereIn('department_id', $ids)->get();
return ($res) ? $res->toArray() : [];
}
public static function createData($data)
{
return self::create($data);
}
public function fromDateTime($value)
{
return strtotime(parent::fromDateTime($value));
}
public static function updateDataByDepartmentId($departmentId, $data)
{
return self::where('department_id', $departmentId)->update($data);
} }
} }
...@@ -13,6 +13,7 @@ class TBusinessConfigModel extends CommonModel ...@@ -13,6 +13,7 @@ class TBusinessConfigModel extends CommonModel
//根据title获取系统信息 //根据title获取系统信息
public static function getBusinessInfoByTitle($title) public static function getBusinessInfoByTitle($title)
{ {
return self::where('title', $title)->first(); $res = self::where('title', $title)->first();
return $res ? $res->toArray() : [];
} }
} }
...@@ -13,17 +13,15 @@ class TRolePermModel extends Model ...@@ -13,17 +13,15 @@ class TRolePermModel extends Model
//获取业务id和角色名 //获取业务id和角色名
public static function getRoleInfoByRoleIdAndBid($role_id, $bid) public static function getRoleInfoByRoleIdAndBid($role_id, $bid)
{ {
return self::where(['roleId' => $role_id, 'bid' => $bid])->first(); $res = self::where(['roleId' => $role_id, 'bid' => $bid])->first();
return $res ? $res->toArray() : [];
} }
//获取业务id和角色名 //获取业务id和角色名
public static function getBidUsername($bid, $roleName) public static function getBidUsername($bid, $roleName)
{ {
return self::where(['bid' => $bid, 'name' => $roleName])->first(); $res = self::where(['bid' => $bid, 'name' => $roleName])->first();
return $res ? $res->toArray() : [];
} }
public static function QueryWhere(array $whereCond)
{
return self::where($whereCond)->get();
}
} }
...@@ -24,14 +24,27 @@ public static function getNameWithEngNameMap($userId) ...@@ -24,14 +24,27 @@ public static function getNameWithEngNameMap($userId)
public static function getInfoById($id) public static function getInfoById($id)
{ {
return self::where('userId', $id)->get(); $res = self::where('userId', $id)->first();
return ($res) ? $res->toArray() : [];
} }
public static function getInfoByIds($user_ids)
{
$res = self::whereIn('userId', $user_ids)->get();
return ($res) ? $res->toArray() : [];
}
public static function QueryWhere(array $whereCond) public static function deleteInfoById($id)
{ {
return self::where($whereCond)->get(); return self::where('userId', $id)->delete();
} }
public static function InsertUser($info)
{
return self::insert($info);
}
public static function queryLimitOffset($whereList, $limit, $offset) public static function queryLimitOffset($whereList, $limit, $offset)
{ {
...@@ -39,8 +52,22 @@ public static function queryLimitOffset($whereList, $limit, $offset) ...@@ -39,8 +52,22 @@ public static function queryLimitOffset($whereList, $limit, $offset)
$count = $query->count(); $count = $query->count();
$list = $query->skip($offset)->take($limit)->orderBy("userId", "desc")->get(); $list = $query->skip($offset)->take($limit)->orderBy("userId", "desc")->get();
return [ return [
'data'=>$list, 'data' => $list,
'total'=>$count, 'total' => $count,
]; ];
} }
public static function CheckUserRegistered($email, $engName)
{
return self::where('status', '<>', self::STATUS_NOT_WORKING)
->where(function ($query) use ($engName, $email) {
$query->orwhere('email', '=', $email)
->orWhere('engName', '=', $engName);
})->get()->toArray();
}
public static function updateByDepartmentId($department_id, $data)
{
self::where('department_id', $department_id)->update($data);
}
} }
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
class UserModel extends CommonModel { class UserModel extends CommonModel {
protected $table = "user"; protected $table = "user";
public static function QueryWhere( array $whereCond) public static function InsertUser($user){
{ return self::insertGetId($user);
return self::where($whereCond)->get();
} }
} }
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"laravel/framework": "^8.75", "laravel/framework": "^8.75",
"laravel/sanctum": "^2.11", "laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5", "laravel/tinker": "^2.5",
"php-amqplib/php-amqplib": "^3.4" "php-amqplib/php-amqplib": "^3.4",
"ext-ldap": "*"
}, },
"require-dev": { "require-dev": {
"facade/ignition": "^2.5", "facade/ignition": "^2.5",
......
<?php
return [
'online_sales_department_id' => 33, // 线上
"cms_department_id_with_ldap_map" => [
1 => [
"ldap_gid" => 501,
"cms_department_name" => "产研中心",
"ldap_department_name" => 'RDC'
],
2 => [
"ldap_gid" => 502,
"cms_department_name" => " 供应链",
"ldap_department_name" => 'SupplyChain'
],
3 => [
"ldap_gid" => 503,
"cms_department_name" => "人力行政部",
"ldap_department_name" => 'Hr'
],
4 => [
"ldap_gid" => 504,
"cms_department_name" => "市场部",
"ldap_department_name" => 'Marketing'
],
5 => [
"ldap_gid" => 505,
"cms_department_name" => "财务部",
"ldap_department_name" => 'Finance'
],
6 => [
"ldap_gid" => 506,
"cms_department_name" => "仓储物流部",
"ldap_department_name" => 'Logistic'
],
7 => [
"ldap_gid" => 507,
"cms_department_name" => "销售部",
"ldap_department_name" => 'Sales'
],
8 => [
"ldap_gid" => 508,
"cms_department_name" => "采购部",
"ldap_department_name" => 'Purchase'
],
9 => [
"ldap_gid" => 509,
"cms_department_name" => "运营部",
"ldap_department_name" => 'Operation'
],
10 => [
"ldap_gid" => 510,
"cms_department_name" => "总经办",
"ldap_department_name" => 'Manager'
],
],
"default_ldap_group_info" => [
"ldap_gid" => 500,
"ldap_department_name" => "ichunt"
]
];
...@@ -36,11 +36,11 @@ ...@@ -36,11 +36,11 @@
'mailers' => [ 'mailers' => [
'smtp' => [ 'smtp' => [
'transport' => 'smtp', 'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 'host' => get_resource_config_section('mail', 'mail')['host'],
'port' => env('MAIL_PORT', 587), 'port' => get_resource_config_section('mail', 'mail')['port'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'), 'encryption' => get_resource_config_section('mail', 'mail')['encryption'],
'username' => env('MAIL_USERNAME'), 'username' => get_resource_config_section('mail', 'mail')['user'],
'password' => env('MAIL_PASSWORD'), 'password' => get_resource_config_section('mail', 'mail')['passwd'],
'timeout' => null, 'timeout' => null,
'auth_mode' => null, 'auth_mode' => null,
], ],
...@@ -92,8 +92,8 @@ ...@@ -92,8 +92,8 @@
*/ */
'from' => [ 'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 'address' => get_resource_config_section('mail', 'mail')['user'],
'name' => env('MAIL_FROM_NAME', 'Example'), 'name' => '系统管理员',
], ],
/* /*
......
layui.config({ layui.config({
base : '/js/plugins/layui/' base: '/js/plugins/layui/'
}).extend({ }).extend({
treetable : 'treetable-lay/treetable' // 添加树形table插件 treetable: 'treetable-lay/treetable' // 添加树形table插件
}).use(['form', 'table', 'laydate', 'treetable'], function(){ }).use(['form', 'table', 'laydate', 'treetable'], function () {
var form = layui.form; var form = layui.form;
var table = layui.table; var table = layui.table;
var laydate = layui.laydate; var laydate = layui.laydate;
...@@ -16,12 +16,12 @@ layui.config({ ...@@ -16,12 +16,12 @@ layui.config({
}); });
var treetable = layui.treetable; var treetable = layui.treetable;
//渲染表格 //渲染表格
var renderTable = function(){ var renderTable = function () {
layer.load(2); //加载层 layer.load(2); //加载层
console.log("hello world"); console.log("hello world");
treetable.render({ treetable.render({
height: 'full-160', height: 'full-160',
id:'department', id: 'department',
treeColIndex: 0, //树形图标显示在第几列 treeColIndex: 0, //树形图标显示在第几列
treeSpid: '0', //最上级的父级id treeSpid: '0', //最上级的父级id
treeIdName: 'department_id', //id字段的名称 treeIdName: 'department_id', //id字段的名称
...@@ -35,13 +35,13 @@ layui.config({ ...@@ -35,13 +35,13 @@ layui.config({
cols: [[ cols: [[
// {type:'radio'} // {type:'radio'}
{field: 'department_name', title: '部门名称', width: 333} {field: 'department_name', title: '部门名称', width: 333}
,{field: 'department_id', title: '部门ID', width: 100} , {field: 'department_id', title: '部门ID', width: 100}
,{field: 'parent_id', title: '父ID', width: 100} , {field: 'parent_id', title: '父ID', width: 100}
,{field: 'author', title: '创建人', width: 190} , {field: 'author', title: '创建人', width: 190}
,{field: 'last_author', title: '修改人', width: 190} , {field: 'last_author', title: '修改人', width: 190}
,{field: 'ctime', title: '创建时间', width: 220} , {field: 'ctime', title: '创建时间', width: 220}
,{field: 'mtime', title: '修改时间', width: 220} , {field: 'mtime', title: '修改时间', width: 220}
,{title: '操作', fixed:'right', toolbar: '#department_action', width: 200} , {title: '操作', fixed: 'right', toolbar: '#department_action', width: 200}
]], ]],
//数据渲染完的回调 //数据渲染完的回调
done: function () { done: function () {
...@@ -103,18 +103,18 @@ layui.config({ ...@@ -103,18 +103,18 @@ layui.config({
// tool操作 // tool操作
table.on('tool(department)', function(obj){ //注:tool是工具条事件名,department是table原始容器的属性lay-filter="对应的值" table.on('tool(department)', function (obj) { //注:tool是工具条事件名,department是table原始容器的属性lay-filter="对应的值"
var data = obj.data; //获得当前行数据 var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值) var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var title = ''; var title = '';
var content = ''; var content = '';
if (layEvent === 'edit') { // 编辑 if (layEvent === 'edit') { // 编辑
title = '编辑部门'; title = '编辑部门';
content = '<div class="layui-form-item"><input type="text" class="layui-input department_name" name="department_name" value="'+data.department_name+'" /></div>'; content = '<div class="layui-form-item"><input type="text" class="layui-input department_name" name="department_name" value="' + data.department_name + '" /></div>';
} else if (layEvent === 'del') { // 删除 } else if (layEvent === 'del') { // 删除
title = '删除部门'; title = '删除部门';
content = '确定删除该部门('+data.department_name+')吗?'; content = '确定删除该部门(' + data.department_name + ')吗?';
} else if (layEvent === 'add_child') { // 新增子级 } else if (layEvent === 'add_child') { // 新增子级
title = '新增子级'; title = '新增子级';
content = '<div class="layui-form-item"><input type="text" class="layui-input department_name" name="department_name" value="" autocomplete="off" /></div>'; content = '<div class="layui-form-item"><input type="text" class="layui-input department_name" name="department_name" value="" autocomplete="off" /></div>';
...@@ -125,7 +125,7 @@ layui.config({ ...@@ -125,7 +125,7 @@ layui.config({
title: title, title: title,
content: content, content: content,
btn: ['确定', '取消'], btn: ['确定', '取消'],
btn1: function() { btn1: function () {
if (layEvent === 'edit') { // 编辑 if (layEvent === 'edit') { // 编辑
var department_name = $('.department_name').val(); var department_name = $('.department_name').val();
departmentAction(2, department_name, data.department_id); departmentAction(2, department_name, data.department_id);
...@@ -135,12 +135,12 @@ layui.config({ ...@@ -135,12 +135,12 @@ layui.config({
var department_name = $('.department_name').val(); var department_name = $('.department_name').val();
departmentAction(4, department_name, data.department_id); departmentAction(4, department_name, data.department_id);
} }
}, },
btn2: function(index){ btn2: function (index) {
layer.close(index) layer.close(index)
} }
}) })
}) })
/** /**
* 新增/编辑部门 * 新增/编辑部门
...@@ -149,9 +149,9 @@ layui.config({ ...@@ -149,9 +149,9 @@ layui.config({
* @param {Number} department_id [部门ID] * @param {Number} department_id [部门ID]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
function departmentAction(type=1, department_name, department_id=0) function departmentAction(type = 1, department_name, department_id = 0) {
{ console.log(type, department_name, department_id)
if (!department_name && type != 3) { if (!department_name && type !== 3) {
layer.tips('部门名称不能为空', $('.department_name')); layer.tips('部门名称不能为空', $('.department_name'));
return false; return false;
} }
...@@ -177,10 +177,10 @@ layui.config({ ...@@ -177,10 +177,10 @@ layui.config({
} }
$.ajax({ $.ajax({
url : url, url: url,
type: 'post', type: 'post',
data: datas, data: datas,
success: function(resp){ success: function (resp) {
if (resp.code == 0) { if (resp.code == 0) {
layer.msg(resp.msg); layer.msg(resp.msg);
renderTable(); // 重新加载table renderTable(); // 重新加载table
...@@ -189,8 +189,8 @@ layui.config({ ...@@ -189,8 +189,8 @@ layui.config({
} }
layer.msg(resp.msg); layer.msg(resp.msg);
}, },
error: function(err) { error: function (err) {
console.log(err) console.log(err)
} }
}) })
...@@ -201,7 +201,7 @@ layui.config({ ...@@ -201,7 +201,7 @@ layui.config({
} }
// 新增部门 // 新增部门
$('.addDepartment').click(function(){ $('.addDepartment').click(function () {
var content = '<div class="layui-form-item"><input type="text" class="layui-input department_name" name="department_name" value="" autocomplete="off" /></div>'; var content = '<div class="layui-form-item"><input type="text" class="layui-input department_name" name="department_name" value="" autocomplete="off" /></div>';
layer.open({ layer.open({
...@@ -209,15 +209,15 @@ layui.config({ ...@@ -209,15 +209,15 @@ layui.config({
title: '新增部门', title: '新增部门',
content: content, content: content,
btn: ['确定', '取消'], btn: ['确定', '取消'],
btn1: function() { btn1: function () {
var department_name = $('.department_name').val(); var department_name = $('.department_name').val();
departmentAction(1, department_name); departmentAction(1, department_name);
}, },
btn2: function(index){ btn2: function (index) {
layer.close(index) layer.close(index)
} }
}) })
}) })
}); });
\ No newline at end of file
<?php <?php
use App\Http\Controllers\DepartmentController;
use App\Http\Controllers\UserController; use App\Http\Controllers\UserController;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
...@@ -19,6 +20,15 @@ ...@@ -19,6 +20,15 @@
return $request->user(); return $request->user();
}); });
Route::post('/login',[\App\Http\Controllers\LoginController::class, 'checkLogin']); //Route::post('/login',[\App\Http\Controllers\LoginController::class, 'checkLogin']);
Route::post('/update',[\App\Http\Controllers\UserController::class, 'update']); Route::post('/update', [\App\Http\Controllers\UserController::class, 'update']);
Route::post('/createuser', [\App\Http\Controllers\UserController::class, 'createUser']);
Route::post('/delete/{id?}', [\App\Http\Controllers\UserController::class, 'delete']);
Route::get('/user/userlist', [\App\Http\Service\UserService::class, 'getList']); Route::get('/user/userlist', [\App\Http\Service\UserService::class, 'getList']);
Route::match(['get', 'post'], '/department/getDepartmentList', [\App\Http\Controllers\DepartmentController::class, 'getDepartmentList']);
Route::match(['get', 'post'], '/department/addChildDepartment', [DepartmentController::class, 'addChildDepartment']);
Route::match(['get', 'post'], '/department/delDepartment', [DepartmentController::class, 'delDepartment']);
Route::match(['get', 'post'], '/department/addDepartment', [DepartmentController::class, 'addDepartment']);
Route::match(['get', 'post'], '/department/editDepartment', [DepartmentController::class, 'editDepartment']);
...@@ -3,3 +3,4 @@ ...@@ -3,3 +3,4 @@
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get('/login', [\App\Http\Controllers\LoginController::class, 'login']);//目前路由为 /my Route::get('/login', [\App\Http\Controllers\LoginController::class, 'login']);//目前路由为 /my
Route::post('/api/login', [\App\Http\Controllers\LoginController::class, 'checkLogin']);//目前路由为 /my
<?php <?php
use App\Http\Controllers\DepartmentController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController; use App\Http\Controllers\UserController;
...@@ -17,9 +18,10 @@ ...@@ -17,9 +18,10 @@
//Route::get('/', function () { //Route::get('/', function () {
// return view('welcome'); // return view('welcome');
//}); //});
Route::get('/', function () { Route::get('/', [UserController::class, 'my']);
return "func";
});
Route::get('/my', [UserController::class, 'my']);//目前路由为 /my Route::get('/my', [UserController::class, 'my']);//目前路由为 /my
Route::get('/userlist', [UserController::class, 'userlist']); Route::get('/userlist', [UserController::class, 'userlist']);
Route::get('/user/create', [UserController::class, 'createNewUser']);
Route::get('/user/{id?}', [UserController::class, 'info']); Route::get('/user/{id?}', [UserController::class, 'info']);
Route::match(['get', 'post'], '/web/departmentList', [DepartmentController::class, 'departmentList']);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment