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 @@
namespace App\Http\Controllers;
use App\Http\ApiHelper\ApiCode;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
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;
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));
}
}
......@@ -169,7 +169,7 @@ private static function saveToRedis($info, $expire = 0)
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');
$allow_domain_list = explode(",", $domain);
......
......@@ -41,9 +41,9 @@ class Kernel extends HttpKernel
],
'api' => [
\App\Http\Middleware\CheckLogin::class,
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\App\Http\Middleware\CheckLogin::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'noauth' => [],
......
......@@ -16,7 +16,7 @@ class DepartmentService extends CommonModel
// 获取菜单
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);
return self::makeDepartmentHtml($department_tree);
}
......@@ -72,7 +72,7 @@ public static function getSubDepartmentId($department_id, &$department_ids)
if ($sub_department) {
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)
ldap_close($ldapconn);
return $ret ? true : false;
return (bool)$ret;
}
}
......@@ -63,10 +63,10 @@ public static function getUserRole(Request $request): int
$business = TBusinessConfigModel::getBusinessInfoByTitle('内部用户管理系统');
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)) {
return 1;
......@@ -87,8 +87,8 @@ public static function getUserRole(Request $request): int
foreach ($role as $role_id) {
$role_info = TRolePermModel::getRoleInfoByRoleIdAndBid($role_id, $bid);
if ($role_info) {
return in_array($role_info->name, array_keys(self::$roles)) ? array_get(self::$roles,
$role_info->name) : 0;
return in_array($role_info['name'], array_keys(self::$roles)) ? array_get(self::$roles,
$role_info['name']) : 0;
}
}
}
......@@ -115,7 +115,7 @@ public static function getUserAllPerms($user_id, $role = 0)
return $user_perms['data']['perms'];
}
} 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)
{
$parentId = DepartmentModel::getParentId($id);
$parentDep = DepartmentModel::getInfoById($parentId);
if(isset($parentDep[0])){
if (isset($parentDep[0])) {
return $parentDep[0]['department_name'];
}
return '';
......@@ -246,7 +246,7 @@ public static function delUserPerms($userId)
public static function setupUserPerm($info, $rolename = '运营')
{
$business_info = TBusinessConfigModel::getBusinessInfoByTitle($info['title']);
$data['bid'] = $business_info->bid;
$data['bid'] = $business_info['bid'];
$data['userId'] = $info['userId'];
// 检查是否存在
......@@ -266,8 +266,8 @@ public static function setupUserPerm($info, $rolename = '运营')
}
// 不存在则创建
$role = TRolePermModel::getBidUsername($business_info->bid, $rolename);
$data['roles'] = json_encode(array("{$role->roleId}"));
$role = TRolePermModel::getBidUsername($business_info['bid'], $rolename);
$data['roles'] = json_encode(array("{$role['roleId']}"));
$data['perms'] = json_encode(array());
$data['username'] = $info['email'];
$data['begDate'] = date('Y-m-d');
......
......@@ -19,35 +19,41 @@ public static function createPasswd($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)
{
$user_info = UserInfoModel::getNameWithEngNameMap($userId);
$info = UserInfoModel::getInfoById($userId);
$boss = UserInfoModel::getInfoById($info[0]->superior);
$user_info = $info[0];
if(isset($boss[0])){
$user_info->sup_engName = $boss->engName;
$user_info->sup_name = $boss->name;
$boss = UserInfoModel::getInfoById($info['superior']);
$user_info = $info;
var_dump($boss);
if($boss){
$user_info['sup_engName'] = $boss['engName'];
$user_info['sup_name'] = $boss['name'];
}
if ($isLimit) {
unset($user_info->idCard);
unset($user_info->birthday);
unset($user_info->sex);
unset($user_info->abo);
unset($user_info->emergencyPeople);
unset($user_info->emergencyPhone);
unset($user_info->address);
unset($user_info['idCard']);
unset($user_info['birthday']);
unset($user_info['sex']);
unset($user_info['abo']);
unset($user_info['emergencyPeople']);
unset($user_info['emergencyPhone']);
unset($user_info['address']);
}
$supTitle = $user_info->sup_engName;
if (!empty($user_info->sup_name)) {
$supTitle = $supTitle . '(' . $user_info->sup_name . ')';
$supTitle = '';
if(!empty($user_info['sup_engName'])){
$supTitle = $user_info['sup_engName'];
}
unset($user_info->sup_engName);
unset($user_info->sup_name);
if (!empty($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;
}
......@@ -298,4 +304,25 @@ public static function generateTree($list, $pk = 'department_id', $pid = 'parent
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 @@
class CommonModel extends Model
{
public static function queryWhere($whereList){
return self::where($whereList)->get()->toArray();
}
}
......@@ -14,28 +14,60 @@ class DepartmentModel extends CommonModel
const CREATED_AT = 'ctime';
const UPDATED_AT = 'mtime';
public static function getDepList()
{
return self::select('department_id', 'department_name', 'parent_id')->get()->toArray();
}
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)
{
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()
{
return self::select('department_name', 'department_id')->get();
$res = self::select('department_name', 'department_id')->get();
return $res;
}
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
//根据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
//获取业务id和角色名
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和角色名
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)
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)
{
......@@ -39,8 +52,22 @@ public static function queryLimitOffset($whereList, $limit, $offset)
$count = $query->count();
$list = $query->skip($offset)->take($limit)->orderBy("userId", "desc")->get();
return [
'data'=>$list,
'total'=>$count,
'data' => $list,
'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 @@
class UserModel extends CommonModel {
protected $table = "user";
public static function QueryWhere( array $whereCond)
{
return self::where($whereCond)->get();
public static function InsertUser($user){
return self::insertGetId($user);
}
}
......@@ -16,7 +16,8 @@
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"php-amqplib/php-amqplib": "^3.4"
"php-amqplib/php-amqplib": "^3.4",
"ext-ldap": "*"
},
"require-dev": {
"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 @@
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'host' => get_resource_config_section('mail', 'mail')['host'],
'port' => get_resource_config_section('mail', 'mail')['port'],
'encryption' => get_resource_config_section('mail', 'mail')['encryption'],
'username' => get_resource_config_section('mail', 'mail')['user'],
'password' => get_resource_config_section('mail', 'mail')['passwd'],
'timeout' => null,
'auth_mode' => null,
],
......@@ -92,8 +92,8 @@
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
'address' => get_resource_config_section('mail', 'mail')['user'],
'name' => '系统管理员',
],
/*
......
layui.config({
base : '/js/plugins/layui/'
base: '/js/plugins/layui/'
}).extend({
treetable : 'treetable-lay/treetable' // 添加树形table插件
}).use(['form', 'table', 'laydate', 'treetable'], function(){
treetable: 'treetable-lay/treetable' // 添加树形table插件
}).use(['form', 'table', 'laydate', 'treetable'], function () {
var form = layui.form;
var table = layui.table;
var laydate = layui.laydate;
......@@ -16,12 +16,12 @@ layui.config({
});
var treetable = layui.treetable;
//渲染表格
var renderTable = function(){
var renderTable = function () {
layer.load(2); //加载层
console.log("hello world");
treetable.render({
height: 'full-160',
id:'department',
id: 'department',
treeColIndex: 0, //树形图标显示在第几列
treeSpid: '0', //最上级的父级id
treeIdName: 'department_id', //id字段的名称
......@@ -35,13 +35,13 @@ layui.config({
cols: [[
// {type:'radio'}
{field: 'department_name', title: '部门名称', width: 333}
,{field: 'department_id', title: '部门ID', width: 100}
,{field: 'parent_id', title: '父ID', width: 100}
,{field: 'author', title: '创建人', width: 190}
,{field: 'last_author', title: '修改人', width: 190}
,{field: 'ctime', title: '创建时间', width: 220}
,{field: 'mtime', title: '修改时间', width: 220}
,{title: '操作', fixed:'right', toolbar: '#department_action', width: 200}
, {field: 'department_id', title: '部门ID', width: 100}
, {field: 'parent_id', title: '父ID', width: 100}
, {field: 'author', title: '创建人', width: 190}
, {field: 'last_author', title: '修改人', width: 190}
, {field: 'ctime', title: '创建时间', width: 220}
, {field: 'mtime', title: '修改时间', width: 220}
, {title: '操作', fixed: 'right', toolbar: '#department_action', width: 200}
]],
//数据渲染完的回调
done: function () {
......@@ -103,18 +103,18 @@ layui.config({
// tool操作
table.on('tool(department)', function(obj){ //注:tool是工具条事件名,department是table原始容器的属性lay-filter="对应的值"
var data = obj.data; //获得当前行数据
table.on('tool(department)', function (obj) { //注:tool是工具条事件名,department是table原始容器的属性lay-filter="对应的值"
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var title = '';
var content = '';
if (layEvent === 'edit') { // 编辑
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') { // 删除
title = '删除部门';
content = '确定删除该部门('+data.department_name+')吗?';
content = '确定删除该部门(' + data.department_name + ')吗?';
} else if (layEvent === 'add_child') { // 新增子级
title = '新增子级';
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({
title: title,
content: content,
btn: ['确定', '取消'],
btn1: function() {
btn1: function () {
if (layEvent === 'edit') { // 编辑
var department_name = $('.department_name').val();
departmentAction(2, department_name, data.department_id);
......@@ -135,12 +135,12 @@ layui.config({
var department_name = $('.department_name').val();
departmentAction(4, department_name, data.department_id);
}
},
btn2: function(index){
},
btn2: function (index) {
layer.close(index)
}
})
})
})
/**
* 新增/编辑部门
......@@ -149,9 +149,9 @@ layui.config({
* @param {Number} department_id [部门ID]
* @return {[type]} [description]
*/
function departmentAction(type=1, department_name, department_id=0)
{
if (!department_name && type != 3) {
function departmentAction(type = 1, department_name, department_id = 0) {
console.log(type, department_name, department_id)
if (!department_name && type !== 3) {
layer.tips('部门名称不能为空', $('.department_name'));
return false;
}
......@@ -177,10 +177,10 @@ layui.config({
}
$.ajax({
url : url,
url: url,
type: 'post',
data: datas,
success: function(resp){
success: function (resp) {
if (resp.code == 0) {
layer.msg(resp.msg);
renderTable(); // 重新加载table
......@@ -189,8 +189,8 @@ layui.config({
}
layer.msg(resp.msg);
},
error: function(err) {
},
error: function (err) {
console.log(err)
}
})
......@@ -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>';
layer.open({
......@@ -209,15 +209,15 @@ layui.config({
title: '新增部门',
content: content,
btn: ['确定', '取消'],
btn1: function() {
btn1: function () {
var department_name = $('.department_name').val();
departmentAction(1, department_name);
},
btn2: function(index){
},
btn2: function (index) {
layer.close(index)
}
})
})
});
\ No newline at end of file
});
<?php
use App\Http\Controllers\DepartmentController;
use App\Http\Controllers\UserController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
......@@ -19,6 +20,15 @@
return $request->user();
});
Route::post('/login',[\App\Http\Controllers\LoginController::class, 'checkLogin']);
Route::post('/update',[\App\Http\Controllers\UserController::class, 'update']);
//Route::post('/login',[\App\Http\Controllers\LoginController::class, 'checkLogin']);
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::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 @@
use Illuminate\Support\Facades\Route;
Route::get('/login', [\App\Http\Controllers\LoginController::class, 'login']);//目前路由为 /my
Route::post('/api/login', [\App\Http\Controllers\LoginController::class, 'checkLogin']);//目前路由为 /my
<?php
use App\Http\Controllers\DepartmentController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
......@@ -17,9 +18,10 @@
//Route::get('/', function () {
// return view('welcome');
//});
Route::get('/', function () {
return "func";
});
Route::get('/', [UserController::class, 'my']);
Route::get('/my', [UserController::class, 'my']);//目前路由为 /my
Route::get('/userlist', [UserController::class, 'userlist']);
Route::get('/user/create', [UserController::class, 'createNewUser']);
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