Commit d8f711ff by lincyawer

重构基本完成,还剩一些小问题

parent 0a5bb6a1
Showing with 1607 additions and 866 deletions
<?php
namespace App\Http\Caches;
use Illuminate\Support\Facades\Redis;
class MenuCache
{
const _KEY_MENU_PREFIX = 'system_menu';
private $enable_cache_system_names = [
'新crm客户管理系统',
'交易系统-采购系统',
'交易系统-销售系统',
'询报价后台管理系统',
];
private $redis;
public function __construct($default_instance = 'data')
{
if ($default_instance) {
$this->redis = Redis::connection($default_instance);
} else {
$this->redis = Redis::connection();
}
}
// 清除所有系统缓存
public function deleteAllSystemMenuCache()
{
$perm_cache_key = self::_KEY_MENU_PREFIX . ':*';
$system_menu_cache = $this->redis->keys($perm_cache_key);
if( $system_menu_cache ){
return $this->redis->del($system_menu_cache);
}
return ;
}
}
<?php
namespace App\Http\Caches;
use Illuminate\Support\Facades\Redis;
class PermCache
{
const _KEY_PERM_PREFIX = 'system_perm';
private $enable_cache_system_names = [
'新crm客户管理系统',
'交易系统-采购系统',
'交易系统-销售系统',
'询报价后台管理系统',
];
private $redis;
public function __construct($default_instance = 'data')
{
if ($default_instance) {
$this->redis = Redis::connection($default_instance);
} else {
$this->redis = Redis::connection();
}
}
// 清除所有系统缓存
public function deleteAllSystemPermCache()
{
$perm_cache_key = self::_KEY_PERM_PREFIX . ':*';
$system_menu_cache = $this->redis->keys($perm_cache_key);
if( $system_menu_cache ){
return $this->redis->del($system_menu_cache);
}
return ;
}
// 去掉该系统的权限缓存
public function deleteSystemPermCache($system_name)
{
if( !in_array($system_name, $this->enable_cache_system_names) ){
return false;
}
$perm_cache_key = self::_KEY_PERM_PREFIX . ':' . md5($system_name) . ':*';
$system_menu_cache = $this->redis->keys($perm_cache_key);
if( $system_menu_cache ){
return $this->redis->del($system_menu_cache);
}
return false;
}
}
<?php
namespace App\Http\Controllers;
use App\Http\Service\Cache;
use App\Http\Service\PermService;
use App\Models\spu\SupplierModel;
use App\Models\user\DepartmentModel;
use App\Models\department\DepartmentModel as Department;
use App\Models\user\IntraCodeModel;
use App\Models\user\OrganizationModel;
use App\Models\user\UserInfoModel;
use App\Models\web\UserMainModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Illuminate\Validation\Rules\In;
class CodeController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
// public function Entrance(Request $request,$id)
// {
// return $this->$id($request, $id);
// }
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\Response
*/
public function codelist(Request $request)
{
// 用户角色
$role = PermService::getUserRole($request);
$userPerms = PermService::getUserAllPerms($request->user->userId, $role); // 用户权限
$userId = $request->user->userId;
$isAdmin = in_array($request->user->email, Config::get('website.admin'));
$key = $request->input('key', '');
$val = $request->input('val', '');
if ($key && $val) {
$map = [];
if ($key == 'name') {
$user_info = UserInfoModel::querySingle([['name', $val]]);
if ($user_info) {
$map['admin_id'] = $user_info['userId'];
}
} else {
if ($key == 'mobile') {
$user_info = UserMainModel::getIdByMobile($val);
if ($user_info) {
$map['user_id'] = $user_info['user_id'];
}
}
}
if (!empty($map)) {
$list = $this->code_info(0, $map);
} else {
$list = [];
}
} else {
$list = $this->code_info();
}
$data = [
'title' => '内部编码',
'active' => 'intracode',
'isAdmin' => $isAdmin,
'userPerms' => $userPerms,
'paths' => [
['href' => '/intracode/codelist', 'title' => '内部编码'],
['href' => '/intracode/codelist' . $userId, 'title' => '内部编码列表']
],
'list' => $list ?? [],
'links' => $list->links(),
'key' => $key,
'val' => $val,
];
return view('intracode.codelist', $data);
}
//搜索
public function code_info($code_id = 0, $map = array())
{
$return = IntraCodeModel::wherePaginate(10, $map);
if ($return) {
$intracode_list = $return->toArray()['data'];
if ($intracode_list) {
$code_ids = array_column($intracode_list, 'code_id');
$admin_ids = array_column($intracode_list, 'admin_id');
$web_user_ids = array_column($intracode_list, 'user_id');
$adm_user_list = UserInfoModel::getInfoByIds($admin_ids);
$adm_user_map = [];
$web_user_map = [];
$code_id_supplier_map = [];
if ($adm_user_list) {
$adm_user_map = array_combine(array_column($adm_user_list, 'userId'), $adm_user_list);
}
$web_user_list = UserMainModel::getUsersByIds($web_user_ids);
if ($web_user_list) {
$web_user_map = array_combine(array_column($web_user_list, 'user_id'), $web_user_list);
}
$supplier_list = SupplierModel::getSupplierListByCodeIds($code_ids);
if ($supplier_list) {
$code_id_supplier_map = array_combine(array_column($supplier_list, 'code'), $supplier_list);
}
foreach ($return as $key => $intracode_item) {
$intracode_info = $intracode_item->toArray();
$adm_user_info = $adm_user_map[$intracode_info['admin_id']] ?? [];
$name = '';
if ($adm_user_info) {
$name = $adm_user_info['name'];
if (!$adm_user_info['name'] && $adm_user_info['email']) {
$name = $adm_user_info['email'];
}
}
$web_user_info = isset($web_user_map[$intracode_info['user_id']]) ? $web_user_map[$intracode_info['user_id']] : [];
$supplier_info = isset($code_id_supplier_map[$intracode_info['code_id']]) ? $code_id_supplier_map[$intracode_info['code_id']] : [];
$extra_info = [
'name' => $name,
'status' => ($adm_user_info) ? $adm_user_info['status'] : "",
'title' => ($adm_user_info) ? trim($adm_user_info['department_name']) : null,
'mobile' => ($web_user_info) ? $web_user_info['mobile'] : "",
'email' => ($web_user_info) ? $web_user_info['email'] : "",
'user_name' => ($web_user_info) ? $web_user_info['user_name'] : "",
'supplier_id' => ($supplier_info) ? $supplier_info['supplier_id'] : "",
'supplier_name' => ($supplier_info) ? $supplier_info['supplier_name'] : "",
'user_count' => UserMainModel::countUid($intracode_info['code_id'])
];
$return[$key] = array_merge($intracode_info, $extra_info);
}
}
} else {
return [];
}
return $return;
}
private function info($info)
{
$userInfo = UserInfoModel::getInfoById($info['admin_id']);
if ($userInfo) {
if (!$userInfo['name'] && $userInfo['email']) {
$userInfo['name'] = $userInfo['email'];
}
$userInfo['email'] = null;
$info = array_merge($info, $userInfo);
}
$web_user_info = UserMainModel::getNameMobileEmail($info['user_id']);
if ($web_user_info) {
$info = array_merge($info, $web_user_info);
}
$supplier_info = SupplierModel::getSupplierIdName($info['code_id']);
if ($supplier_info) {
$info = array_merge($info, $supplier_info);
}
$organization_info = OrganizationModel::getDepartmentIdByUserId($info['admin_id']);
if ($organization_info) {
$department = Department::getTitleParent($organization_info['departmentId']);
if ($department) {
$info = array_merge($info, $department);
}
}
return $info;
}
public function Handle_code(Request $request)
{
$code_id = $request->input('code_id');
$info = [];
//提取未绑定得管理员
$all_admin = UserInfoModel::getByWhere([['status', 0]]);
$bin_code = IntraCodeModel::pluckWhere([['admin_id', '>', 0]], ['code_id', 'admin_id']);
foreach ($all_admin as $k => $v) {
$v = $v->toArray();
if (!empty($bin_code[$v['userId']])) {
unset($all_admin[$k]);
}
}
//提取未绑定得供应商
$all_supplier = SupplierModel::wherePluck([['code', ''], ['status', 1]], ['supplier_name', 'supplier_id']);
if (!empty($code_id) && $code_id != 0) {
$info = IntraCodeModel::querySingle([['code_id', $code_id]]);
if ($info) {
$info = $this->info($info);
}
}
$data = [
'info' => $info,
'all_admin' => $all_admin,
'all_supplier' => $all_supplier
];
return view('intracode.Handle_code', $data);
}
//解绑
public function Unbundling(Request $request)
{
$code_id = $request->input('code_id');
$type = $request->input('type');
if (empty($code_id) || $code_id < 10000) {
Log::error("解绑失败"); // 记录到日志文件
$this->Export(10001, '解绑失败');
}
if ($type == 'admin' || $type == 'user') {
$update['update_time'] = time();
if ($type == 'admin') {
$update['admin_id'] = 0;
}
if ($type == 'user') {
$update['user_id'] = 0;
}
$return = IntraCodeModel::updateWhere([['code_id', $code_id]], $update);
if (!$return) {
Log::error("解绑失败"); // 记录到日志文件
$this->Export(10002, '解绑失败');
}
} else {
if ($type == 'supplier') {
$update['code'] = '';
$return = SupplierModel::updateWhere([['code', $code_id]], $update);
if (!$return) {
Log::error("解绑失败"); // 记录到日志文件
$this->Export(10002, '解绑失败');
}
} else {
Log::error("解绑失败"); // 记录到日志文件
$this->Export(10002, '解绑失败');
}
}
$redis = Redis::connection();
$redis->hdel('intracode', $code_id);
$this->Export(0, '解绑成功');
}
//绑定
public function binding(Request $request)
{
$collect = $request->input();
foreach ($collect as $k => $v) {
if (empty($v) || $v == 0 || $v == 'undefined') {
unset($collect[$k]);
continue;
}
if ($k != 'admin_id' && $k != 'mobile' && $k != 'supplier_id' && $k != 'code_id') {
unset($collect[$k]);
}
}
if (isset($collect['supplier_id'])) {
$supplier_id = $collect['supplier_id'];
unset($collect['supplier_id']);
}
if (!empty($collect['mobile'])) {
$map['mobile'] = $collect['mobile'];
unset($collect['mobile']);
$return_user = UserMainModel::querySingle($map);
if (empty($return_user['user_id'])) {
Log::error('不存在前台账号' . $map['mobile']); // 记录到日志文件
$this->Export(10003, '不存在前台账号' . $map['mobile']);
}
$find_user = IntraCodeModel::querySingle([['user_id', $return_user['user_id']]]);
if (!empty($find_user['code_id'])) {
Log::error('前台账号' . $map['mobile'] . '已经绑定编号' . $find_user['code_id']);
$this->Export(10003, '前台账号' . $map['mobile'] . '已经绑定编号' . $find_user['code_id']);
}
$collect['user_id'] = $return_user['user_id'];
}
$collect['update_time'] = time();
if (!empty($collect['code_id']) && $collect > 9999) {
$redis = Cache::getRedis();
$redis->hdel('intracode', $collect['code_id']);
$return = IntraCodeModel::updateWhere([['code_id', $collect['code_id']]], $collect);
if (!$return && $return != 0) {
Log::error('绑定失败'); // 记录到日志文件
$this->Export(10001, '绑定失败');
}
} else {
$collect['create_time'] = time();
$return = IntraCodeModel::insertAndGetId($collect);
if (!$return) {
Log::error('新增失败'); // 记录到日志文件
$this->Export(10002, '新增失败');
}
}
if (!empty($supplier_id)) {
$arr_su['code'] = !empty($collect['code_id']) ? $collect['code_id'] : $return;
$return = SupplierModel::updateWhere([['supplier_id', $supplier_id]], $arr_su);
if (!$return) {
Log::error('绑定供应商失败'); // 记录到日志文件
$this->Export(10003, '绑定供应商失败');
}
}
$this->Export();
}
/**
* 刷新钉钉缓存
*/
public function refreshDingDing()
{
try {
$client = new \GuzzleHttp\Client();
// $client->getAsync('http://api.liexin.com/Wechat/WechatArticleJinJi/getdingtalkinfo');
$res = $client->request('GET', Config("website.api_url") . '/Wechat/WechatArticleJinJi/getdingtalkinfo');
header('Content-Type:application/json; charset=utf-8');
if ($res->getStatusCode() == '200') {
return $this->setSuccess('成功');
} else {
return $this->setError('失败');
}
} catch (\Exception $e) {
return $this->setError('失败');
}
}
private function Export($code = 0, $msg = '', $data = [])
{
$info = [
'errcode' => $code ? $code : 0,
'errmsg' => $msg ? $msg : '成功',
'data' => $data ? $data : []
];
echo json_encode($info);
exit();
}
}
<?php
namespace App\Http\Controllers;
class ConfigController extends Controller
{
// 帮助文档
public function help()
{
return redirect('/doc/user_helper.html');
}
}
...@@ -2,13 +2,9 @@ ...@@ -2,13 +2,9 @@
namespace App\Http\Controllers; 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\DepartmentModel;
use App\Models\user\UserInfoModel; use App\Models\user\UserInfoModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis as Redis;
class DepartmentController extends Controller class DepartmentController extends Controller
{ {
...@@ -87,9 +83,10 @@ public function editDepartment(Request $request) ...@@ -87,9 +83,10 @@ public function editDepartment(Request $request)
$department_id = $request->input('department_id'); $department_id = $request->input('department_id');
$update_department_info = []; $update_department_info = [];
$update_department_info['department_name'] = $request->input('department_name'); $update_department_info['department_name'] = $request->input('department_name');
$update_department_info['last_author'] = $request->user->email; $update_department_info['last_author'] = $request->user->email;
$created_department_list = DepartmentModel::queryWhere([['department_name',$update_department_info['department_name']]]); $created_department_list = DepartmentModel::queryWhere([['department_name', $update_department_info['department_name']]]);
if ($created_department_list) { if ($created_department_list) {
return $this->setError('编辑失败,部门已存在'); return $this->setError('编辑失败,部门已存在');
} }
...@@ -141,700 +138,4 @@ public function addChildDepartment(Request $request) ...@@ -141,700 +138,4 @@ public function addChildDepartment(Request $request)
return $this->setSuccess('新增子级成功'); 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;
}
} }
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
use App\Http\Service\UserService; use App\Http\Service\UserService;
use App\Http\Service\UserTokenService; use App\Http\Service\UserTokenService;
use App\Models\user\LoginModel; use App\Models\user\LoginModel;
use App\Models\user\UserInfoModel;
use App\Models\user\UserLoginModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
...@@ -77,35 +79,34 @@ public function checkLogin(Request $request): array ...@@ -77,35 +79,34 @@ public function checkLogin(Request $request): array
Log::error("passwd or name not match"); // 记录到日志文件 Log::error("passwd or name not match"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_MATCH, "passwd or name not match"); return Output::makeResult($request, Error::E_NOT_MATCH, "passwd or name not match");
} }
$info = $info[0];
if ($info->status != LoginController::STATUS_NEED_CHANGE_PASSWD && $info->status != 0) { if ($info['status'] != LoginController::STATUS_NEED_CHANGE_PASSWD && $info['status'] != 0) {
Log::error("forbidden login"); // 记录到日志文件 Log::error("forbidden login"); // 记录到日志文件
return Output::makeResult($request, Error::E_FORBIDDEN, "forbidden login"); return Output::makeResult($request, Error::E_FORBIDDEN, "forbidden login");
} }
if ($info->status == LoginController::STATUS_NEED_CHANGE_PASSWD) { if ($info['status'] == LoginController::STATUS_NEED_CHANGE_PASSWD) {
$token = UserTokenService::createToken($info->status); $token = UserTokenService::createToken($info['status']);
return Output::makeResult($request, Error::E_RESET_PASSWD, "", $token); return Output::makeResult($request, Error::E_RESET_PASSWD, "", $token);
} }
$passwd = UserService::createPasswd($passwd, $info->slat); $passwd = UserService::createPasswd($passwd, $info['slat']);
if ($passwd != $info->passwd) { if ($passwd != $info['passwd']) {
$this->checkLoginFailedLimit($info); $this->checkLoginFailedLimit($info);
Log::error($info->email . ":passwd or name not match"); // 记录到日志文件 Log::error($info['email'] . ":passwd or name not match"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_MATCH, "passwd or name not match"); return Output::makeResult($request, Error::E_NOT_MATCH, "passwd or name not match");
} }
$session = self::generateSession($info->userId, $request->ip(), $info->email, $info->name, $info->engName); $session = self::generateSession($info['userId'], $request->ip(), $info['email'], $info['name'], $info['engName']);
if (!$session) { if (!$session) {
Log::error("unknown server error"); // 记录到日志文件 Log::error("unknown server error"); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, "unknow server error, try again"); return Output::makeResult($request, Error::E_SERVER, "unknow server error, try again");
} }
$this->setLoginCookie($session['userId'], $session['skey'], $info->header, $this->setLoginCookie($session['userId'], $session['skey'], $info['header'],
$remember ? strtotime($session['expireTime']) : 0); $remember ? strtotime($session['expireTime']) : 0);
$this->delLoginFailed($info->userId); // 登录成功后删除错误次数 $this->delLoginFailed($info['userId']); // 登录成功后删除错误次数
return Output::makeResult($request, 0, 'OK', ['userId' => $info->userId, 'skey' => $session['skey']]); return Output::makeResult($request, 0, 'OK', ['userId' => $info['userId'], 'skey' => $session['skey']]);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error("unknown server error: " . $e->getMessage()); // 记录到日志文件 Log::error("unknown server error: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, return Output::makeResult($request, Error::E_SERVER,
...@@ -227,4 +228,61 @@ private function checkLoginFailedLimit($info) ...@@ -227,4 +228,61 @@ private function checkLoginFailedLimit($info)
}); });
} }
} }
// 用户登录日志列表接口
public function getLoginLogList(Request $request)
{
$page = $request->input('page', 1);
$limit = $request->input('limit', 10);
$params = [
'email' => $request->input('email', ''),
'begin_time' => $request->input('begin_time', '') ? $request->input('begin_time') : '',
'end_time' => $request->input('end_time', '') ? $request->input('end_time') : '',
];
// 查询条件
$where = [];
if ($params['email']) {
$user_info = UserInfoModel::querySingle([['email',$params['email']]]);
if ($user_info) {
$where[] = ['userId', '=', $user_info['userId']];
} else {
return $this->setSuccess(['list' => [], 'total' => 0]);
}
}
if ($params['begin_time']) {
$where[] = ['loginTime', '>=', $params['begin_time']];
}
if ($params['end_time']) {
$where[] = ['loginTime', '<=', date("Y-m-d", strtotime($params['end_time']) + 86400)];
}
$search_field = ['userId', 'loginTime', 'loginIp'];
$login_log_data = UserLoginModel::getListByWhere($where, $page, $limit, $search_field);
$login_log_list = [];
if ($login_log_data['data']) {
$user_ids = array_column($login_log_data['data'], 'userId');//返回数组中单个列(userId)的值
$user_list_map = UserService::getUserListMapByIds($user_ids);
foreach ($login_log_data['data'] as $login_log_info) {
$user_info = $user_list_map[$login_log_info['userId']] ?? [];
$login_log_list[] = [
"email" => $user_info ? $user_info['email'] : '',
'name' => $user_info ? $user_info['name'] : '',
"engName" => $user_info ? $user_info['engName'] : '',
"loginIp" => $login_log_info['loginIp'],
"loginTime" => $login_log_info['loginTime'],
"userId" => $login_log_info['userId']
];
}
}
$data = [
'list' => $login_log_list,
'total' => $login_log_data['total']
];
return $this->setSuccess($data);
}
} }
<?php
namespace App\Http\Controllers;
use App\Http\Service\PermService;
use App\Http\Service\UserService;
use App\Models\user\DepartmentModel;
use App\Models\user\PositionModel;
use App\Models\user\UserInfoModel;
use Illuminate\Http\Request;
class PositionController extends Controller
{
// 职位列表
public function positionList(Request $request)
{
$map['parent_id'] = 0;
$data = [
'id' => 'positionList',
'title' => '职位列表',
'paths' => [['href' => '#', 'title' => '组织管理'], ['href' => '#', 'title' => '职位列表']],
'department' => DepartmentModel::getDepartmentNameWithIdList($map),
];
return view('position.positionList', $data);
}
// 职位列表
public function getPositionList(Request $request)
{
$page = $request->input('page', 1);
$limit = $request->input('limit', 10);
$position_map = [];
$position_map['position_name'] = $request->input('position_name', ''); // 职位名称
$position_map['department_id'] = $request->input('search_department_id', ''); // 部门
$position_map['begin_time'] = $request->input('begin_time', '') ? strtotime($request->input('begin_time')) : '';
$position_map['end_time'] = $request->input('end_time', '') ? strtotime($request->input('end_time')) + 86399 : '';
$where = [];
if ($position_map['position_name']) {
$where[] = ['position_name', 'like', $position_map['position_name'] . '%'];
}
if (isset($position_map['department_id']) && $position_map['department_id']) {
$where[] = ['department_id', '=', $position_map['department_id']];
}
if ($position_map['begin_time']) {
$where[] = ['ctime', '>=', $position_map['begin_time']];
}
if ($position_map['end_time']) {
$where[] = ['ctime', '<=', $position_map['end_time']];
}
$position_field = ['position_id', 'position_name', 'department_id', 'department_name', 'author', 'last_author', 'ctime', 'mtime'];
$position_list = PositionModel::getPositionFieldList($where, $position_field, $limit, $page);
$data = [
"total" => isset($position_list['total']) ? $position_list['total'] : 0,
"list" => $position_list['data']
];
return $this->setSuccess($data);
}
// 新增职位
public function addPosition(Request $request)
{
$input_data = [];
$input_data['position_name'] = $request->input('position_name');
$input_data['department_id'] = $request->input('department_id');
$input_data['department_name'] = $request->input('department_name');
$input_data['author'] = $request->user->email;
$input_data['last_author'] = $request->user->email;
$res_get = PositionModel::querySingle([['position_name', $input_data['position_name']]]);
if ($res_get) {
return $this->setError('新增失败,职位已存在');
}
$res_creat = PositionModel::createItem($input_data);
if ($res_creat === false) {
return $this->setError('新增失败');
}
return $this->setSuccess('新增成功');
}
// 编辑职位
public function editPosition(Request $request)
{
$position_id = $request->input('position_id');
$input_data = [];
$input_data['position_name'] = $request->input('position_name');
$input_data['department_id'] = $request->input('department_id');
$input_data['department_name'] = $request->input('department_name');
$input_data['last_author'] = $request->user->email;
$res_get = PositionModel::querySingle([['position_name', $input_data['position_name']]]);
if (!$res_get) {
return $this->setError('编辑失败,职位不存在');
}
$res_update = PositionModel::updateWhere([['position_id', $position_id]], $input_data);
if ($res_update === false) {
return $this->setError('更新失败');
}
UserInfoModel::updateWhere([['position_id', $position_id]], ['position_name' => $input_data['position_name']]);
UserInfoModel::updateByDepartmentId($input_data['department_id'], ['department_name' => $input_data['department_name']]);
return $this->setSuccess('更新成功');
}
// 删除职位
public function delPosition(Request $request)
{
$position_id = $request->input('position_id');
$res_delete = PositionModel::deleteWhere([['position_id', $position_id]]);
if ($res_delete === false) {
return $this->setError('删除失败');
}
$delete_position_id_name = [
'position_id' => 0,
'position_name' => ''
];
UserInfoModel::updateWhere([['position_id', $position_id]], $delete_position_id_name);
return $this->setSuccess('删除成功');
}
}
<?php
namespace App\Http\Controllers;
use App\Http\Caches\MenuCache;
use App\Http\Caches\PermCache;
use App\Http\Service\PermService;
use App\Models\user\PositionModel;
use App\Models\user\PositionPermModel;
use App\Models\user\TBusinessConfigModel;
use App\Models\user\TUserPermModel;
use App\Models\user\UserInfoModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class PositionPermController extends Controller
{
// 职位权限列表
public function positionPermList(Request $request)
{
$info = [
'id' => 'positionPerm',
'title' => '职位权限列表',
'paths' => [['href' => '#', 'title' => '组织管理'], ['href' => '#', 'title' => '职位权限列表']],
'position' => PositionModel::getPositionNameMap(),// 职位
'businessName' => TBusinessConfigModel::getBusinessNameList(),// 业务系统名称
];
return view('positionPerm.positionPermList', $info);
}
// 职位角色权限列表
public function getPositionPermList(Request $request)
{
$page = $request->input('page', 1);
$limit = $request->input('limit', 10);
$position_perm_map = [];
$position_perm_map['position_id'] = $request->input('position_id', ''); // 职位名称
$position_perm_map['bid'] = $request->input('bid', ''); // 业务系统ID
$position_perm_map['role_id'] = $request->input('business_role_id', ''); // 角色ID
$position_perm_map['begin_time'] = $request->input('begin_time', '') ? strtotime($request->input('begin_time')) : '';
$position_perm_map['end_time'] = $request->input('end_time', '') ? strtotime($request->input('end_time')) + 86399 : '';
$where = [];
if ($position_perm_map['position_id']) {
$where[] = ['position_id', '=', $position_perm_map['position_id']];
}
if ($position_perm_map['bid']) {
$where[] = ['bid', '=', $position_perm_map['bid']];
}
if ($position_perm_map['role_id']) {
$where[] = ['role_id', '=', $position_perm_map['role_id']];
}
if ($position_perm_map['begin_time']) {
$where[] = ['ctime', '>=', $position_perm_map['begin_time']];
}
if ($position_perm_map['end_time']) {
$where[] = ['ctime', '<=', $position_perm_map['end_time']];
}
$position_field = ['position_perm_id', 'position_id', 'position_name', 'bid', 'business_name', 'role_id', 'role_name', 'author', 'last_author', 'ctime', 'mtime'];
$position_perm_list = PositionPermModel::getPositionPermList($where, $position_field, $limit, $page);
$data = [
"total" => $position_perm_list['total'] ?? 0,
"list" => $position_perm_list['data']
];
return $this->setSuccess($data);
}
// 职位绑定/编辑角色
public function setPositionPerm(Request $request)
{
$map['position_perm_id'] = $request->input('position_perm_id', '');
$input_data = [];
$input_data['position_id'] = $request->input('position_id');
$input_data['position_name'] = $request->input('position_name');
$input_data['bid'] = $request->input('bid');
$input_data['business_name'] = $request->input('business_name');
$input_data['role_id'] = $request->input('business_role_id');
$input_data['role_name'] = $request->input('role_name');
$input_data['author'] = $request->user->email;
$input_data['last_author'] = $request->user->email;
$msg_txt = !$map['position_perm_id'] ? '绑定' : '更新';
$check_data = [];
$check_data['position_id'] = $input_data['position_id'];
$check_data['bid'] = $input_data['bid'];
$res_get = PositionPermModel::querySingle($check_data);
if ($res_get) {
return $this->setError('该职位已绑定');
}
DB::beginTransaction();
try {
$res_update = PositionPermModel::updateOrCreateData($map, $input_data);
if ($res_update === false) {
DB::rollBack();
return $this->setError('操作失败');
}
/*** 绑定用户权限 ***/
// 查询该职位下所有用户
$user_id_email = UserInfoModel::queryWhere([['position_id', $input_data['position_id']]]);
if (!$user_id_email) {
DB::commit();
return $this->setSuccess('绑定成功');
}
$user_ids = array_column($user_id_email, 'userId');
$res_get = PermService::delUserPerms($user_ids); // 删除该职位下用户的所有权限
if ($res_get === false) {
return $this->setError('删除用户权限失败');
}
// 查询该职位绑定的系统、角色,并重新设置用户权限
$position_roles = PositionPermModel::queryWhere([['position_id', $input_data['position_id']]]);
$user_perm = [];
foreach ($position_roles as $roles) {
foreach ($user_id_email as $v) {
$temp = [];
$temp['bid'] = $roles['bid'];
$temp['roles'] = json_encode(array("{$roles['role_id']}"));
$temp['userId'] = $v['userId'];
$temp['perms'] = json_encode(array());
$temp['username'] = $v['email'];
$temp['begDate'] = date('Y-m-d');
$temp['endDate'] = date('Y-m-d', time() + 15552000); // 半年
$temp['ctime'] = date('Y-m-d H:i:s');
$temp['mtime'] = date('Y-m-d H:i:s');
$user_perm[] = $temp;
}
}
$res_get = TUserPermModel::createItem($user_perm);
if ($res_get === false) {
DB::rollBack();
return $this->setError('添加用户失败');
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
return $this->setError('操作失败', 0, $e->getMessage());
}
// 绑定职位权限,删除系统的权限和菜单缓存
$perm_cache = new PermCache();
$perm_cache->deleteAllSystemPermCache();
$menu_cache = new MenuCache();
$menu_cache->deleteAllSystemMenuCache();
return $this->setSuccess('操作成功');
}
// 删除职位权限
public function delPositionPerm(Request $request)
{
$position_perm_id = $request->input('position_perm_id');
$delete_position_perm_id = PositionPermModel::deleteWhere([['position_perm_id', $position_perm_id]]);
if ($delete_position_perm_id === false) {
return $this->setError('删除失败');
}
// 如果职位变更,删除系统的权限和菜单缓存
$perm_cache = new PermCache();
$perm_cache->deleteAllSystemPermCache();
$menu_cache = new MenuCache();
$menu_cache->deleteAllSystemMenuCache();
return $this->setSuccess('删除成功');
}
}
<?php
namespace App\Http\Controllers;
use App\Http\Service\PermService;
use App\Models\user\TRolePermModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class RoleController extends Controller
{
// 获取业务系统角色
public function getBusinessRoles(Request $request)
{
$bid = $request->input('bid');
$role_id_name_map = TRolePermModel::getRoles($bid);
if (!$role_id_name_map) {
return $this->setError('业务系统角色为空');
}
return $this->setSuccess($role_id_name_map);
}
}
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
use App\Http\Output; use App\Http\Output;
use App\Http\Service\DepartmentService; use App\Http\Service\DepartmentService;
use App\Http\Service\LdapManagerService; use App\Http\Service\LdapManagerService;
use App\Http\Service\LoginService;
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\Http\Service\UserTokenService;
use App\Models\config\ConfigModel;
use App\Models\crm\EmployeeCardModel; 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;
...@@ -16,6 +18,7 @@ ...@@ -16,6 +18,7 @@
use App\Models\user\PositionPermModel; use App\Models\user\PositionPermModel;
use App\Models\user\UserInfoModel; use App\Models\user\UserInfoModel;
use App\Models\user\UserModel; use App\Models\user\UserModel;
use App\Models\user\UserTokenModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
...@@ -83,6 +86,7 @@ public function info(Request $request, $userId = 0) ...@@ -83,6 +86,7 @@ public function info(Request $request, $userId = 0)
setcookie('crsf_token', bin2hex(openssl_random_pseudo_bytes(16)), 0, '/'); setcookie('crsf_token', bin2hex(openssl_random_pseudo_bytes(16)), 0, '/');
return view('user.info', $data); return view('user.info', $data);
} }
public function my(Request $req, $userId = 0) public function my(Request $req, $userId = 0)
{ {
$user = $req->getUserResolver()(); $user = $req->getUserResolver()();
...@@ -167,7 +171,7 @@ public function update(Request $request) ...@@ -167,7 +171,7 @@ public function update(Request $request)
$info['email'] = $user['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); UserInfoModel::updateWhere([['userId', $userId]], $info);
// 获取用户角色绑定权限 // 获取用户角色绑定权限
$rolePerm = PositionPermModel::getUserRolePermList($info['position_id']); $rolePerm = PositionPermModel::getUserRolePermList($info['position_id']);
...@@ -211,7 +215,7 @@ public function update(Request $request) ...@@ -211,7 +215,7 @@ public function update(Request $request)
// 若设置离职状态,且为线上销售部门,则同步到CRM // 若设置离职状态,且为线上销售部门,则同步到CRM
if (isset($info['status']) && $info['status'] == 4) { if (isset($info['status']) && $info['status'] == 4) {
$this->sysToCrm($info); UserService::sysToCrm($info);
} }
try { try {
...@@ -231,8 +235,7 @@ public function update(Request $request) ...@@ -231,8 +235,7 @@ public function update(Request $request)
$ldap->ldapDelete($user['email'], $businessCategory); $ldap->ldapDelete($user['email'], $businessCategory);
// 重新创建ldap用户 // 重新创建ldap用户
$userInfo = DB::table('user_info')->where('userId', $userId)->first(); $userInfo = UserInfoModel::querySingle([['userId', $userId]]);
$userInfo = (array)$userInfo;
$root_department_id = DepartmentService::getRootDepartmentId($info['department_id']); $root_department_id = DepartmentService::getRootDepartmentId($info['department_id']);
if (isset($cms_department_id_with_ldap_map[$root_department_id])) { if (isset($cms_department_id_with_ldap_map[$root_department_id])) {
$userInfo['gidNumber'] = $cms_department_id_with_ldap_map[$root_department_id]['ldap_gid']; $userInfo['gidNumber'] = $cms_department_id_with_ldap_map[$root_department_id]['ldap_gid'];
...@@ -266,7 +269,7 @@ public function update(Request $request) ...@@ -266,7 +269,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')) {
LoginController::setLoginCookie(null, null, $info['header'], time() + self::expireTime()); LoginController::setLoginCookie(null, null, $info['header'], time() + LoginService::expireTime());
} }
// 推入到队列 // 推入到队列
...@@ -289,6 +292,7 @@ public function update(Request $request) ...@@ -289,6 +292,7 @@ public function update(Request $request)
"unknown server error: " . $err_msg . ", try again"); "unknown server error: " . $err_msg . ", try again");
} }
} }
public function createUser(Request $request) public function createUser(Request $request)
{ {
try { try {
...@@ -455,6 +459,7 @@ public function createUser(Request $request) ...@@ -455,6 +459,7 @@ public function createUser(Request $request)
"unknown server error: " . $e->getMessage() . ", try again"); "unknown server error: " . $e->getMessage() . ", try again");
} }
} }
// 账号列表 // 账号列表
public function userlist(Request $request) public function userlist(Request $request)
{ {
...@@ -486,6 +491,7 @@ public function userlist(Request $request) ...@@ -486,6 +491,7 @@ public function userlist(Request $request)
return view('user.userlist', $data); return view('user.userlist', $data);
} }
//新增用户按钮 //新增用户按钮
public function createNewUser(Request $request) public function createNewUser(Request $request)
{ {
...@@ -513,35 +519,10 @@ public function createNewUser(Request $request) ...@@ -513,35 +519,10 @@ public function createNewUser(Request $request)
return view('user.info', $data); return view('user.info', $data);
} }
private static function expireTime()
{
$expire = Config::get('website.skeyExpire');
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) public function delete(Request $request, $userId)
{ {
if ($userId <= 0) { if ($userId <= 0) {
Log::error( "Bad Request: invaild userId {$userId}"); // 记录到日志文件 Log::error("Bad Request: invaild userId {$userId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "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'))) { if (!in_array($request->user->email, Config::get('website.admin'))) {
...@@ -550,7 +531,7 @@ public function delete(Request $request, $userId) ...@@ -550,7 +531,7 @@ public function delete(Request $request, $userId)
} }
try { try {
$ret = UserInfoModel::getInfoById($userId); $ret = UserInfoModel::getInfoById($userId);
if (!isset($ret)) { if (!isset($ret)) {
Log::error("not found {$userId}"); // 记录到日志文件 Log::error("not found {$userId}"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_EXISTS, "not found {$userId}"); return Output::makeResult($request, Error::E_NOT_EXISTS, "not found {$userId}");
...@@ -573,11 +554,188 @@ public function delete(Request $request, $userId) ...@@ -573,11 +554,188 @@ public function delete(Request $request, $userId)
UserInfoModel::deleteInfoById($userId); UserInfoModel::deleteInfoById($userId);
return Output::makeResult($request, 0); return Output::makeResult($request, 0);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error( "unknown server: " . $e->getMessage()); // 记录到日志文件 Log::error("unknown server: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER,
"unknown server error: " . $e->getMessage() . ", try again");
}
}
//修改密码、重置密码
public function resetPassWord(Request $request)
{
$token = $request->input('token', null);
$userId = $request->input('uid', null);
$expire = $request->input('expire', null);
$data = [];
if ($token) {
//token存在时通过邮箱重置密码
if (!$userId || $userId < 0 || !$expire) {
abort(403);
}
$data = ['token' => $token, 'userId' => $userId];
$sp = strtotime($expire);
if ($sp <= time() || !UserTokenModel::checkToken($userId, $token)) {
$data['isExpire'] = true;
}
} else {
$res_check = LoginService::checkLoginStatus($request);
if ($res_check["retcode"] != 0) {
return redirect('/login' . '?redirect=' . urlencode($request->url()));
}
$data = ['userId' => $res_check['data']['userId']];
}
return view('user.resetpasswd', $data);
}
//修改密码接口
public function resetpasswd(Request $request)
{
$userId = $request->input('userId', null);
$token = $request->input('token', null);
$newpasswd = $request->input('passwd', null);
$oldpasswd = $request->input('oldpasswd', null);
if (empty($userId) || $userId < 0) {
Log::error("Bad Request: invaild userId `{$userId}`"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: invaild userId `{$userId}`");
}
if (empty($newpasswd) || strlen($newpasswd) < 8) {
Log::error("Bad Request: 密码太短, 小于8个字节"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: 密码太短, 小于8个字节");
}
if (empty($token) && empty($oldpasswd)) {
Log::error("Bad Request: invaild token or oldpasswd`"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: invaild token or oldpasswd");
}
if ($token && strlen($token) < UserTokenService::TOKEN_LENGTH) {
Log::error("Bad Request: invaild token `{$token}`"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: invaild token `{$token}`");
}
if ($oldpasswd && strlen($oldpasswd) != 32) {
Log::error("Bad Request: invaild oldpasswd `{$oldpasswd}`"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: invaild oldpasswd `{$oldpasswd}`");
}
$info = UserModel::querySingle([['userId', $userId]]);
//检查原始密码是否正确
if (isset($oldpasswd) && $oldpasswd != '' && !UserService::checkoutPassword($info, $oldpasswd)) {
Log::error("Bad Request: invalid userId `{$userId}`"); // 记录到日志文件
return Output::makeResult($request, Error::E_PARAM, "Bad Request: invaild userId `{$userId}`");
}
try {
$slat = UserService::createSlat();
$passwd = UserService::createPasswd(md5($newpasswd), $slat);
$now = date('Y-m-d H:i:s');
$data = ['slat' => $slat, 'passwd' => $passwd];
if ($token) {
if (!UserTokenModel::checkToken($userId, $token)) {
Log::error("invalid token"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_MATCH, "invaild token");
}
if (!$info) {
Log::error("not match"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_MATCH, "not match");
}
if ($info->status == self::STATUS_NEED_CHANGE_PASSWD) {
$data['status'] = 0;
}
$ret = UserModel::updateWhere([['userId', $userId]], $data);
if ($ret) {
UserTokenService::setTokenStatus($userId, $token, 1);
}
} else {
if (!$info) {
Log::error("not match"); // 记录到日志文件
return Output::makeResult($request, Error::E_NOT_MATCH, "not match");
}
if ($info['status'] != 0) {
Log::error("can't reset passwd by old passwd"); // 记录到日志文件
return Output::makeResult($request, Error::E_STATUS, "can't reset passwd by old passwd");
}
$ret = UserModel::updateWhere([['userId', $userId]], $data);
}
if (!$ret) {
Log::error("unknown server error"); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, "unknown server error, try again");
}
$info = UserInfoModel::querySingle([['userId', $userId]]);
$engName = $info['engName'];
try {
//同步密码到bbs
$this->updateBBSUserPass([
'name' => $info['name'],
'email' => $info['email'],
'slat' => $data['slat'],
'passwd' => $data['passwd'],
]);
$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])) {
$ldap_department_name = $cms_department_id_with_ldap_map[$root_department_id]['ldap_department_name'];
} else {
$ldap_department_name = $default_ldap_group_info['ldap_department_name'];
}
$ldap->ldapResetPasswd($info['email'], $newpasswd, $ldap_department_name);
} catch (\Exception $e) {
Log::error("ldap reset passwd failed, engName={$engName}");
}
LoginService::expireLogin($userId);
return Output::makeResult($request, 0);
} catch (\Exception $e) {
Log::error("unknown server error: " . $e->getMessage()); // 记录到日志文件
return Output::makeResult($request, Error::E_SERVER, return Output::makeResult($request, Error::E_SERVER,
"unknown server error: " . $e->getMessage(). ", try again"); "unknown server error: " . $e->getMessage() . ", try again");
} }
} }
// 用户登录日志列表
public static function loginLog(Request $request)
{
$uri = '/' . $request->path();
// 菜单
$menu_config = ConfigModel::getConfigTitle();
$menus = [];
if ($menu_config && !($menus = json_decode($menu_config->config_data))) {
$menus = [];
}
// 用户角色
$role = PermService::getUserRole($request);
// 获取权限菜单
if ($role != 1) {
$menus = PermService::getMenuPerm($menus, $request->user->userId);
}
$userPerms = PermService::getUserAllPerms($request->user->userId, $role); // 用户权限
$info = [
'username' => $request->user->email,
'header' => $request->user->header,
'uri' => $uri,
'menus' => $menus,
'role' => $role,
'userPerms' => $userPerms,
'id' => 'loginLog',
'title' => '用户登录日志列表',
'paths' => [['href' => '#', 'title' => '登录日志']]
];
return view('user.loginLogList', $info);
}
} }
......
...@@ -13,5 +13,7 @@ class EncryptCookies extends Middleware ...@@ -13,5 +13,7 @@ class EncryptCookies extends Middleware
*/ */
protected $except = [ protected $except = [
// //
'oa_skey',
'oa_user_id'
]; ];
} }
...@@ -5,11 +5,15 @@ ...@@ -5,11 +5,15 @@
use App\Http\Error; use App\Http\Error;
use App\Http\Output; use App\Http\Output;
use App\Models\user\UserLoginModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
class LoginService{ class LoginService
{
public static function checkEmailDomain($email) public static function checkEmailDomain($email)
{ {
return substr($email, 1 + strpos($email, '@')) == Config::get('website.emailDomain'); return substr($email, 1 + strpos($email, '@')) == Config::get('website.emailDomain');
...@@ -34,14 +38,13 @@ public static function checkLoginStatus(Request $request): array ...@@ -34,14 +38,13 @@ public static function checkLoginStatus(Request $request): array
} }
} }
public static function checkSession($userId, $skey) public static function checkSession($userId, $skey)
{ {
$sKey = null; $sKey = null;
try { try {
$key = self::sessionKey($userId, $skey); $key = self::sessionKey($userId, $skey);
$sKey = Cache::getRedis()->get($key); $sKey = Cache::getRedis()->get($key);
}catch (\Exception $e){ } catch (\Exception $e) {
Log::error($e); Log::error($e);
} }
if ($sKey === null) { if ($sKey === null) {
...@@ -59,10 +62,12 @@ public static function checkSession($userId, $skey) ...@@ -59,10 +62,12 @@ public static function checkSession($userId, $skey)
} }
return $jsonResult; return $jsonResult;
} }
public static function sessionKey($userId, $skey): string public static function sessionKey($userId, $skey): string
{ {
return $userId . ':' . substr($skey, 0, 8); // 8个字节足够了; 一个用户的空间范围内冲突概率很低 return $userId . ':' . substr($skey, 0, 8); // 8个字节足够了; 一个用户的空间范围内冲突概率很低
} }
public static function isCookieDomain($url): bool public static function isCookieDomain($url): bool
{ {
$domain_info = parse_url($url); $domain_info = parse_url($url);
...@@ -75,4 +80,29 @@ public static function isCookieDomain($url): bool ...@@ -75,4 +80,29 @@ public static function isCookieDomain($url): bool
} }
return false; return false;
} }
public static function expireLogin($userId, $skey = null)
{
$expire = date('Y-m-d H:i:s', time() - 2 * 24 * 3600);
if ($skey === null) {
$login_list =UserLoginModel::queryWhere([['userId', $userId], ['expireTime', '>', $expire]]);
} else {
$login_list = [['skey' => $skey]];
}
if ($login_list) {
Redis::pipeline(function ($pipe) use ($login_list, $userId) {
foreach ($login_list as $login_info) {
$keys[] = self::sessionKey($userId, $login_info['skey']);
}
call_user_func_array([$pipe, 'del'], $keys);
});
}
return true;
}
public static function expireTime()
{
$expire = Config::get('website.skeyExpire');
return $expire ? $expire : 3600 * 12;
}
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
use App\Http\Error; use App\Http\Error;
use App\Http\Output; use App\Http\Output;
use App\Models\queue\QueuedModel;
use App\Models\user\UserInfoModel; use App\Models\user\UserInfoModel;
use App\Models\user\UserModel; use App\Models\user\UserModel;
use http\Client\Curl\User; use http\Client\Curl\User;
...@@ -13,23 +14,23 @@ ...@@ -13,23 +14,23 @@
class UserService class UserService
{ {
const SLAT_LENGTH = 32; // 用户密码加盐的随机数 const SLAT_LENGTH = 32; // 用户密码加盐的随机数
const TABLE_NAME = 'user'; // 表名
public static function createPasswd($passwd, $slat) public static function createPasswd($passwd, $slat)
{ {
return hash('sha256', md5($passwd) . $slat); return hash('sha256', md5($passwd) . $slat);
} }
public static function createSlat() public static function createSlat()
{ {
return base64_encode(openssl_random_pseudo_bytes(self::SLAT_LENGTH)); return base64_encode(openssl_random_pseudo_bytes(self::SLAT_LENGTH));
} }
public static function getUserInfo($userId, $isLimit) public static function getUserInfo($userId, $isLimit)
{ {
$info = UserInfoModel::getInfoById($userId); $info = UserInfoModel::getInfoById($userId);
$boss = UserInfoModel::getInfoById($info['superior']); $boss = UserInfoModel::getInfoById($info['superior']);
$user_info = $info; $user_info = $info;
var_dump($boss); if ($boss) {
if($boss){
$user_info['sup_engName'] = $boss['engName']; $user_info['sup_engName'] = $boss['engName'];
$user_info['sup_name'] = $boss['name']; $user_info['sup_name'] = $boss['name'];
} }
...@@ -44,7 +45,7 @@ public static function getUserInfo($userId, $isLimit) ...@@ -44,7 +45,7 @@ public static function getUserInfo($userId, $isLimit)
} }
$supTitle = ''; $supTitle = '';
if(!empty($user_info['sup_engName'])){ if (!empty($user_info['sup_engName'])) {
$supTitle = $user_info['sup_engName']; $supTitle = $user_info['sup_engName'];
} }
if (!empty($user_info['sup_name'])) { if (!empty($user_info['sup_name'])) {
...@@ -60,7 +61,7 @@ public static function getUserInfo($userId, $isLimit) ...@@ -60,7 +61,7 @@ public static function getUserInfo($userId, $isLimit)
public static function getUserInfoByName($type, $name) public static function getUserInfoByName($type, $name)
{ {
$userInfo = UserInfoModel::QueryWhere([ $userInfo = UserInfoModel::querySingle([
[ [
($type == 1) ? 'email' : 'engName', ($type == 1) ? 'email' : 'engName',
'=', '=',
...@@ -75,19 +76,19 @@ public static function getUserInfoByName($type, $name) ...@@ -75,19 +76,19 @@ public static function getUserInfoByName($type, $name)
if (!$userInfo) { if (!$userInfo) {
return []; return [];
} }
$metaUser = UserModel::QueryWhere([ $metaUser = UserModel::querySingle([
[ [
'userId', 'userId',
'=', '=',
$userInfo[0]->userId, $userInfo['userId'],
] ]
]); ]);
if (!$metaUser) { if (!$metaUser) {
return []; return [];
} }
$userInfo[0]->passwd = $metaUser[0]->passwd; $userInfo['passwd'] = $metaUser['passwd'];
$userInfo[0]->slat = $metaUser[0]->slat; $userInfo['slat'] = $metaUser['slat'];
$userInfo[0]->status = $metaUser[0]->status; $userInfo['status'] = $metaUser['status'];
return $userInfo; return $userInfo;
} }
...@@ -130,7 +131,7 @@ public static function getList(Request $request): array ...@@ -130,7 +131,7 @@ public static function getList(Request $request): array
} }
// $q->where($key, 'LIKE', $value . "%"); // $q->where($key, 'LIKE', $value . "%");
$result = UserInfoModel::queryLimitOffset($whereList,$count,($page - 1) * $count); $result = UserInfoModel::queryLimitOffset($whereList, $count, ($page - 1) * $count);
$total = $result['total']; $total = $result['total'];
$users = $result['data']; $users = $result['data'];
$list = []; $list = [];
...@@ -220,6 +221,7 @@ public static function extractUserInfoFromReq(Request $request, $isRegistered) ...@@ -220,6 +221,7 @@ public static function extractUserInfoFromReq(Request $request, $isRegistered)
return $data; return $data;
} }
public static function checkUserInfo($info) public static function checkUserInfo($info)
{ {
if (!empty($info['userId']) && $info['userId'] <= 0) { if (!empty($info['userId']) && $info['userId'] <= 0) {
...@@ -304,6 +306,7 @@ public static function generateTree($list, $pk = 'department_id', $pid = 'parent ...@@ -304,6 +306,7 @@ public static function generateTree($list, $pk = 'department_id', $pid = 'parent
return $department_tree; return $department_tree;
} }
// 部门添加html // 部门添加html
public static function getDepartmentHtml($tree) public static function getDepartmentHtml($tree)
{ {
...@@ -325,4 +328,40 @@ public static function getDepartmentHtml($tree) ...@@ -325,4 +328,40 @@ public static function getDepartmentHtml($tree)
return $html; return $html;
} }
public static function getUserListMapByIds($user_ids)
{
$user_list = UserInfoModel::getInfoByIds($user_ids);
$user_list_map = [];
if ($user_list) {
$user_list_map = array_column($user_list, null, 'userId');
}
return $user_list_map;
}
public static function checkoutPassword($info, $oldpasswd)
{
if (!$info) {
return false;
}
$passwd = UserService::createPasswd($oldpasswd, $info['slat']);
return $passwd == $info['passwd'];
}
// 线上销售离职,推送到CRM队列
public static 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));
}
} }
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
namespace App\Http\Service; namespace App\Http\Service;
use App\Models\user\UserTokenModel;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
class UserTokenService{ class UserTokenService
{
const TOKEN_RESET_PASSWD_FORCE = 1; const TOKEN_RESET_PASSWD_FORCE = 1;
const TOKEN_RESET_PASSWD_EMAIL = 2; const TOKEN_RESET_PASSWD_EMAIL = 2;
const TABLE_NAME = 'user_token'; protected const tableName = 'user_token';
const TOKEN_LENGTH = 64; // token的随机数字节数; base64之后是 TOKEN_LENGTH * 2 const TOKEN_LENGTH = 64; // token的随机数字节数; base64之后是 TOKEN_LENGTH * 2
public static function __createToken() public static function __createToken()
...@@ -39,7 +40,7 @@ public static function createToken($userId, $expire = null) ...@@ -39,7 +40,7 @@ public static function createToken($userId, $expire = null)
'mtime' => $now 'mtime' => $now
]; ];
$ret = DB::table(self::TABLE_NAME)->insert($data); $ret = UserTokenModel::createItem($data);
if (!$ret) { if (!$ret) {
return false; return false;
} }
......
...@@ -6,7 +6,30 @@ ...@@ -6,7 +6,30 @@
class CommonModel extends Model class CommonModel extends Model
{ {
public static function queryWhere($whereList){ public static function queryWhere($whereList)
{
return self::where($whereList)->get()->toArray(); return self::where($whereList)->get()->toArray();
} }
public static function querySingle($whereList)
{
$res = self::where($whereList)->first();
return $res ? $res->toArray() : [];
}
public static function updateWhere($whereList, $data)
{
return self::where($whereList)->update($data);
}
public static function deleteWhere($whereList)
{
return self::where($whereList)->delete();
}
public static function pluckWhere($whereList,$pluckList)
{
return self::where($whereList)->pluck(...$pluckList);
}
public static function createItem($data)
{
return self::insert($data);
}
} }
<?php
namespace App\Models\department;
use Illuminate\Database\Eloquent\Model;
class DepartmentModel extends Model
{
protected $table = 'department';
protected $primaryKey = 'departmentId';
public static function getDepartmentIdTitlePatent($key, $number)
{
return self::where('title', 'LIKE', $key)->take($number)
->select('departmentId', 'title', 'parent')->get();
}
public static function getDepartmentIdParentIsvirtulTitle()
{
return self::select('departmentId', 'parent', 'isVirtual', 'title')->get();
}
public static function getDepartmentId($departmentId)
{
return self::where('departmentId', $departmentId)->first();
}
public static function getTitleParent($data)
{
$res = self::where('departmentId', $data)
->select('title', 'parent')
->first();
return ($res) ? $res->toArray() : [];
}
}
...@@ -2,11 +2,12 @@ ...@@ -2,11 +2,12 @@
namespace App\Models\queue; namespace App\Models\queue;
use App\Models\CommonModel;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use PhpAmqpLib\Connection\AMQPStreamConnection; use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage; use PhpAmqpLib\Message\AMQPMessage;
class QueuedModel extends Model class QueuedModel extends CommonModel
{ {
public function pushAmq($content = '') public function pushAmq($content = '')
{ {
......
<?php
namespace App\Models\spu;
use App\Models\CommonModel;
class SupplierModel extends CommonModel
{
protected $connection = 'spu';
protected $table = 'supplier';
protected $primaryKey = 'supplier_id';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
public static function getSupplierIdName($data)
{
$res = self::where('code', $data)
->select('supplier_name', 'supplier_id')
->first();
return ($res) ? $res->toArray() : [];
}
public static function getSupplierListByCodeIds($code_ids)
{
$res = self::whereIn('code', $code_ids)->get();
return ($res) ? $res->toArray() : [];
}
public static function wherePluck($whereList, $pluckList)
{
return self::where($whereList)->pluck(...$pluckList);
}
}
...@@ -70,4 +70,9 @@ public static function updateDataByDepartmentId($departmentId, $data) ...@@ -70,4 +70,9 @@ public static function updateDataByDepartmentId($departmentId, $data)
{ {
return self::where('department_id', $departmentId)->update($data); return self::where('department_id', $departmentId)->update($data);
} }
public static function getDepartmentNameWithIdList($whereList)
{
$res = self::where($whereList)->pluck('department_name', 'department_id')->toArray();
return $res ?:[];
}
} }
<?php
namespace App\Models\user;
use App\Models\CommonModel;
class IntraCodeModel extends CommonModel
{
protected $table = 'lie_intracode';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
public static function wherePaginate($pagesize, $whereList = [])
{
return self::where($whereList)->paginate($pagesize);
}
public static function insertAndGetId($data){
return self::insertGetId($data);
}
}
<?php
namespace App\Models\user;
use App\Models\CommonModel;
use Illuminate\Database\Eloquent\Model;
class OrganizationModel extends CommonModel
{
protected $table = 'organization';
protected $primaryKey = 'departmentId';
public static function getDepartmentInfoMap($departmentId)
{
return self::leftJoin('user_info', 'organization.userId', '=', 'user_info.userId')
->where('organization.departmentId', $departmentId)
->select('user_info.userId', 'user_info.email', 'user_info.engName',
'user_info.name', 'organization.isPartTime', 'organization.ctime',
'user_info.header', 'user_info.position', 'user_info.jobLevel', 'user_info.mobile')
->get();
}
public static function getUserIdDepartment()
{
return self::select('userId', 'departmentId')->get();
}
public static function getDepartmentIdByUserId($data)
{
$res = self::where('userId', $data)
->select('departmentId')
->first();
return ($res) ? $res->toArray() : [];
}
public static function countDepartmentId($departmentId)
{
return self::where('departmentId', $departmentId)->count();
}
public static function deleteDepartmentId($departmentId, $userId)
{
self::where('departmentId', $departmentId)->where('userId', $userId)->delete();
}
public static function getUserIdByIspartAndCtime($userId)
{
return self::where('userId', $userId)->orderBy('isPart ASC, ctime DESC')->get();
}
}
...@@ -35,4 +35,15 @@ public static function getPositionNameMap() ...@@ -35,4 +35,15 @@ public static function getPositionNameMap()
public static function getPositionNameWithIdArray(){ public static function getPositionNameWithIdArray(){
return self::select('position_name', 'position_id')->get(); return self::select('position_name', 'position_id')->get();
} }
public static function getPositionFieldList($where, $field, $limit, $page)
{
$query = self::select($field);
if ($where) {
$query->where($where);
}
return $query->orderBy('ctime', 'desc')
->orderBy('position_id', 'desc')
->paginate($limit, ['*'], 'page', $page)->toArray();
}
} }
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
namespace App\Models\user; namespace App\Models\user;
use App\Models\CommonModel;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class PositionPermModel extends Model class PositionPermModel extends CommonModel
{ {
protected $table = 'user_position_perm'; protected $table = 'user_position_perm';
protected $primaryKey = 'position_perm_id'; protected $primaryKey = 'position_perm_id';
...@@ -12,6 +13,10 @@ class PositionPermModel extends Model ...@@ -12,6 +13,10 @@ class PositionPermModel extends Model
// protected $fillable = ['user_role_id', 'user_role_name', 'bid', 'business_name', 'role_id', 'role_name', 'author', 'last_author']; // protected $fillable = ['user_role_id', 'user_role_name', 'bid', 'business_name', 'role_id', 'role_name', 'author', 'last_author'];
const CREATED_AT = 'ctime'; const CREATED_AT = 'ctime';
const UPDATED_AT = 'mtime'; const UPDATED_AT = 'mtime';
public function fromDateTime($value)
{
return strtotime(parent::fromDateTime($value));
}
// 获取用户角色权限 // 获取用户角色权限
public static function getUserRolePermList($position_id) public static function getUserRolePermList($position_id)
...@@ -19,5 +24,22 @@ public static function getUserRolePermList($position_id) ...@@ -19,5 +24,22 @@ public static function getUserRolePermList($position_id)
if (!$position_id) return false; if (!$position_id) return false;
return self::where('position_id', $position_id)->select('position_perm_id', 'position_id', 'bid', 'role_id')->get()->toArray(); return self::where('position_id', $position_id)->select('position_perm_id', 'position_id', 'bid', 'role_id')->get()->toArray();
} }
// 职位角色权限列表
public static function getPositionPermList($where, $field, $limit, $page)
{
$query = self::select($field);
if($where){
$query->where($where);
}
return $query->orderBy('ctime', 'desc')
->orderBy('position_perm_id', 'desc')
->paginate($limit, ['*'], 'page', $page)->toArray();
}
public static function updateOrCreateData($map, $data)
{
return self::updateOrCreate($map, $data);
}
} }
...@@ -16,4 +16,9 @@ public static function getBusinessInfoByTitle($title) ...@@ -16,4 +16,9 @@ public static function getBusinessInfoByTitle($title)
$res = self::where('title', $title)->first(); $res = self::where('title', $title)->first();
return $res ? $res->toArray() : []; return $res ? $res->toArray() : [];
} }
// 获取所有业务系统名称
public static function getBusinessNameList()
{
return self::pluck('title', 'bid')->toArray();
}
} }
...@@ -23,5 +23,11 @@ public static function getBidUsername($bid, $roleName) ...@@ -23,5 +23,11 @@ public static function getBidUsername($bid, $roleName)
$res = self::where(['bid' => $bid, 'name' => $roleName])->first(); $res = self::where(['bid' => $bid, 'name' => $roleName])->first();
return $res ? $res->toArray() : []; return $res ? $res->toArray() : [];
} }
// 获取所有业务系统角色
public static function getRoles($bid)
{
return self::where('bid', $bid)->pluck('name', 'roleId')->toArray();
}
} }
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
namespace App\Models\user; namespace App\Models\user;
use App\Models\CommonModel;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class TUserPermModel extends Model class TUserPermModel extends CommonModel
{ {
protected $table = 't_user_perm'; protected $table = 't_user_perm';
protected $primaryKey = 'userId'; protected $primaryKey = 'userId';
......
...@@ -14,14 +14,6 @@ class UserInfoModel extends commonModel ...@@ -14,14 +14,6 @@ class UserInfoModel extends commonModel
const STATUS_WORKING = 0; const STATUS_WORKING = 0;
const STATUS_NOT_WORKING = 4; const STATUS_NOT_WORKING = 4;
public static function getNameWithEngNameMap($userId)
{
return self::leftJoin('user_info as t', 'user_info.superior', '=', 't.userId')
->where('user_info.userId', $userId)
->select('user_info.*', 't.engName as sup_engName', 't.name as sup_name')
->first();
}
public static function getInfoById($id) public static function getInfoById($id)
{ {
$res = self::where('userId', $id)->first(); $res = self::where('userId', $id)->first();
...@@ -34,7 +26,9 @@ public static function getInfoByIds($user_ids) ...@@ -34,7 +26,9 @@ public static function getInfoByIds($user_ids)
return ($res) ? $res->toArray() : []; return ($res) ? $res->toArray() : [];
} }
public static function getByWhere($whereList){
return self::where($whereList)->get();
}
public static function deleteInfoById($id) public static function deleteInfoById($id)
{ {
...@@ -45,7 +39,6 @@ public static function InsertUser($info) ...@@ -45,7 +39,6 @@ public static function InsertUser($info)
return self::insert($info); return self::insert($info);
} }
public static function queryLimitOffset($whereList, $limit, $offset) public static function queryLimitOffset($whereList, $limit, $offset)
{ {
$query = self::where($whereList); $query = self::where($whereList);
......
<?php
namespace App\Models\user;
use App\Models\CommonModel;
use Illuminate\Database\Eloquent\Model;
class UserLoginModel extends CommonModel
{
protected $table = 'user_login';
public $timestamps = false;
public static function insertData($data)
{
return self::insert($data);
}
public static function getLoginListByUserIdAndTime($userId, $expire)
{
$res = self::where('userId', $userId)
->where('expireTime', '>', $expire)->get();
return ($res) ? $res->toArray() : [];
}
// 根据条件获取列表
public static function getListByWhere($where, $page, $limit, $field = "*")
{
$query = self::select($field);
if ($where) {
$query->where($where);
}
return $query->orderBy('loginTime', 'desc')->paginate($limit, ['*'], 'page', $page)->toArray();
}
}
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
class UserModel extends CommonModel { class UserModel extends CommonModel {
protected $table = "user"; protected $table = "user";
const CREATED_AT = 'ctime';
const UPDATED_AT = 'mtime';
public static function InsertUser($user){ public static function InsertUser($user){
return self::insertGetId($user); return self::insertGetId($user);
} }
......
<?php
namespace App\Models\user;
use App\Models\CommonModel;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
class UserTokenModel extends CommonModel
{
const TOKEN_RESET_PASSWD_FORCE = 1;
const TOKEN_RESET_PASSWD_EMAIL = 2;
protected $table = 'user_token';
const TOKEN_LENGTH = 64; // token的随机数字节数; base64之后是 TOKEN_LENGTH * 2
public static function checkToken($userId, $token)
{
$count = self::where('userId', $userId)
->where('status', 0)->where('token', $token)
->where('expireTime', '>=', date('Y-m-d H:i:s'))->count();
return $count == 1;
}
}
<?php
namespace App\Models\web;
use App\Models\CommonModel;
use Illuminate\Database\Eloquent\Model;
class UserMainModel extends CommonModel
{
protected $connection = 'web';
protected $table = 'user_main';
protected $primaryKey = 'id';
// 根据用户ids,获取用户列表
public static function getUsersByIds($user_ids)
{
$res = self::whereIn('user_id', $user_ids)->get();
return ($res) ? $res->toArray() : [];
}
public static function getUserMobileByUserId($id)
{
return self::whereIn('user_id', $id)->get();
}
public static function getIdByMobile($val)
{
return self::where('mobile', $val)->select('user_id')->first();
}
public static function countUid($data)
{
return self::where('invite_uid', $data)
->count();
}
public static function getNameMobileEmail($data)
{
$res = self::where('user_id', $data)
->select('mobile', 'email', 'user_name')
->first();
return ($res) ? $res->toArray() : [];
}
}
...@@ -63,6 +63,32 @@ ...@@ -63,6 +63,32 @@
]) : [], ]) : [],
], ],
'web' => [
'driver' => 'mysql',
'host' => get_resource_config_section('db', 'db_liexin')['host'],
'database' => get_resource_config_section('db', 'db_liexin')['db'],
'username' => get_resource_config_section('db', 'db_liexin')['user'],
'password' => get_resource_config_section('db', 'db_liexin')['passwd'],
'port' => 3306,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'lie_',
'strict' => false,
],
'spu' => [
'driver' => 'mysql',
'host' => get_resource_config_section('db', 'db_spu')['host'],
'database' => get_resource_config_section('db', 'db_spu')['db'],
'username' => get_resource_config_section('db', 'db_spu')['user'],
'password' => get_resource_config_section('db', 'db_spu')['passwd'],
'port' => 3306,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'lie_',
'strict' => false,
],
'pgsql' => [ 'pgsql' => [
'driver' => 'pgsql', 'driver' => 'pgsql',
'url' => env('DATABASE_URL'), 'url' => env('DATABASE_URL'),
...@@ -133,7 +159,12 @@ ...@@ -133,7 +159,12 @@
'port' => get_resource_config_section('redis', 'user')['port'], 'port' => get_resource_config_section('redis', 'user')['port'],
'database' => env('REDIS_DB', '0'), 'database' => env('REDIS_DB', '0'),
], ],
'data' => [
'host' => get_resource_config_section('redis', 'data')['host'],
'password' => get_resource_config_section('redis', 'data')['passwd'],
'port' => get_resource_config_section('redis', 'data')['port'],
'database' => 0,
],
'cache' => [ 'cache' => [
'url' => env('REDIS_URL'), 'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'), 'host' => env('REDIS_HOST', '127.0.0.1'),
......
...@@ -52,55 +52,6 @@ layui.config({ ...@@ -52,55 +52,6 @@ layui.config({
}; };
renderTable(); renderTable();
// layui.use(['form', 'table', 'laydate'], function () {
// var form = layui.form;
// var table = layui.table;
// var laydate = layui.laydate;
//
// laydate.render({
// elem: '#begin_time' //指定元素
// });
//
// laydate.render({
// elem: '#end_time' //指定元素
// });
// var renderTable = function () {
// table.render({
// id: 'list'
// , elem: '#department'
// , url: '/ajax/departmentList' //数据接口
// , method: 'post'
// , cellMinWidth: 80 //全局定义常规单元格的最小宽度
// , page: true //开启分页
// , cols: [[ //表头
// {title: '序号', type: 'numbers', fixed: 'left', width: 60}
// , {field: 'department_id', title: '部门ID', width: 100}
// , {field: 'department_name', title: '部门名称', width: 313}
// , {field: 'author', title: '创建人', width: 260}
// , {field: 'last_author', title: '修改人', width: 260}
// , {field: 'ctime', title: '创建时间', width: 220}
// , {field: 'mtime', title: '修改时间', width: 220}
// , {title: '操作', fixed: 'right', toolbar: '#department_action', width: 120}
// ]]
// , limit: 10
// , limits: [10, 20, 50,]
// });
// };
//
// renderTable(); // 加载表格
// form.on('submit(load)', function(data) {
// //执行重载
// table.reload('list', {
// page: {
// curr: 1
// }
// ,where: data.field
// });
//
// return false;
// });
// tool操作 // tool操作
table.on('tool(department)', function (obj) { //注:tool是工具条事件名,department是table原始容器的属性lay-filter="对应的值" table.on('tool(department)', function (obj) { //注:tool是工具条事件名,department是table原始容器的属性lay-filter="对应的值"
...@@ -156,16 +107,16 @@ layui.config({ ...@@ -156,16 +107,16 @@ layui.config({
return false; return false;
} }
if (type == 1) { if (type === 1) {
var url = '/api/department/addDepartment'; var url = '/api/department/addDepartment';
var msg = '新增部门中...'; var msg = '新增部门中...';
} else if (type == 2) { } else if (type === 2) {
var url = '/api/department/editDepartment'; var url = '/api/department/editDepartment';
var msg = '编辑部门中...'; var msg = '编辑部门中...';
} else if (type == 3) { } else if (type === 3) {
var url = '/api/department/delDepartment'; var url = '/api/department/delDepartment';
var msg = '删除部门中...'; var msg = '删除部门中...';
} else if (type == 4) { } else if (type === 4) {
var url = '/api/department/addChildDepartment'; var url = '/api/department/addChildDepartment';
var msg = '新增子级中...'; var msg = '新增子级中...';
} }
...@@ -181,7 +132,7 @@ layui.config({ ...@@ -181,7 +132,7 @@ layui.config({
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
......
...@@ -6,7 +6,7 @@ layui.use(['form','layer'], function(){ ...@@ -6,7 +6,7 @@ layui.use(['form','layer'], function(){
form.on('submit(formDemo)', function(data){ form.on('submit(formDemo)', function(data){
$.ajax({ $.ajax({
type: 'post', type: 'post',
url: '/intracode/binding', url: '/api/intracode/binding',
timeout : 10000, //超时时间设置,单位毫秒 timeout : 10000, //超时时间设置,单位毫秒
data: { data: {
code_id:data.field.code_id, code_id:data.field.code_id,
...@@ -38,4 +38,4 @@ layui.use(['form','layer'], function(){ ...@@ -38,4 +38,4 @@ layui.use(['form','layer'], function(){
}); });
return false; return false;
}); });
}); });
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>账号管理系统 | {{$title or ''}}</title> <title>账号管理系统 | {{$title ?? ''}}</title>
@include('web.css') @include('web.css')
<style> <style>
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
<label class="layui-form-label">前台账号</label> <label class="layui-form-label">前台账号</label>
<div class="layui-input-block"> <div class="layui-input-block">
@if(!empty($info['mobile'])) @if(!empty($info['mobile']))
<input type="text" autocomplete="off" autocomplete="off" class="layui-input" value="{{$info['mobile'] or ''}}" disabled> <input type="text" autocomplete="off" autocomplete="off" class="layui-input"
value="{{$info['mobile'] ?? ''}}" disabled>
@else @else
<input type="text" name="mobile" autocomplete="off" placeholder="请输入手机号" autocomplete="off" class="layui-input"> <input type="text" name="mobile" autocomplete="off" placeholder="请输入手机号" autocomplete="off"
class="layui-input">
@endif @endif
</div> </div>
</div> </div>
...@@ -24,7 +26,7 @@ ...@@ -24,7 +26,7 @@
<select name="admin_id" lay-search> <select name="admin_id" lay-search>
<option value="">未绑定</option> <option value="">未绑定</option>
@foreach($all_admin as $k=>$v) @foreach($all_admin as $k=>$v)
<option value="{{$v->userId}}">{{$v->name or $v->email}}</option> <option value="{{$v->userId}}">{{$v->name?$v->name:$v->email}}</option>
@endforeach @endforeach
</select> </select>
@else @else
...@@ -39,15 +41,15 @@ ...@@ -39,15 +41,15 @@
<label class="layui-form-label">供应商名称</label> <label class="layui-form-label">供应商名称</label>
<div class="layui-input-block"> <div class="layui-input-block">
@if( empty($info['supplier_id']) || $info['supplier_id']==0) @if( empty($info['supplier_id']) || $info['supplier_id']==0)
<select name="supplier_id"> <select name="supplier_id">
<option value="">未绑定</option> <option value="">未绑定</option>
@foreach($all_supplier as $k=>$v) @foreach($all_supplier as $k=>$v)
<option value="{{$k}}">{{$v}}</option> <option value="{{$k}}">{{$v}}</option>
@endforeach @endforeach
</select> </select>
@else @else
<select name="city" disabled> <select name="city" disabled>
<option value="">{{$info['supplier_name'] or ''}}</option> <option value="">{{$info['supplier_name'] ?? ''}}</option>
</select> </select>
@endif @endif
</div> </div>
...@@ -63,4 +65,4 @@ ...@@ -63,4 +65,4 @@
<script src="/js/intracode/Handle_code.js?v={{time()}}"> <script src="/js/intracode/Handle_code.js?v={{time()}}">
</script> </script>
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>帐号系统 | {{$title}}</title> {{-- <title>帐号系统 | {{$title}}</title>--}}
@include('userlist.css') @include('userlist.css')
</head> </head>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
@if (in_array('user_codelist_create', $userPerms)) @if (in_array('user_codelist_create', $userPerms))
<a class="btn btn-primary add_code" href="javascript:;" data-id="0">创建</a> <a class="btn btn-primary add_code" href="javascript:;" data-id="0">创建</a>
@endif @endif
<a class="btn btn-primary update_dd_cache" href="javascript:;" >更新钉钉缓存</a> <a class="btn btn-primary update_dd_cache" href="javascript:;" >更新钉钉缓存</a>
<div class="form-inline" style="float:right;height:34px;"> <div class="form-inline" style="float:right;height:34px;">
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
<tr role="row"> <tr role="row">
<td style="width:100px;" class="text-center">{{$v['code_id']}}</td> <td style="width:100px;" class="text-center">{{$v['code_id']}}</td>
<td style="width:120px;" class="text-center"> <td style="width:120px;" class="text-center">
{{$v['name'] or '未绑定'}} {{$v['name'] ? $v['name']: '未绑定'}}
<span class="label label-primary"> <span class="label label-primary">
{{ $v['title'] ? $v['title'] : '猎芯科技' }} {{ $v['title'] ? $v['title'] : '猎芯科技' }}
</span> </span>
...@@ -83,8 +83,8 @@ ...@@ -83,8 +83,8 @@
<a class="btn btn-xs btn-outline btn-warning Unbundling" data-type="supplier" data-id="{{$v['code_id']}}">解绑</a> <a class="btn btn-xs btn-outline btn-warning Unbundling" data-type="supplier" data-id="{{$v['code_id']}}">解绑</a>
@endif @endif
</td> </td>
<td style="width:100px;" class="text-center">{{$v['user_count'] or 0}}</td> <td style="width:100px;" class="text-center">{{$v['user_count'] ? $v['user_count']: 0}}</td>
<td style="width:133px;" class="text-center">{{date('Y-m-d H:i',$v['update_time'])}}</td> <td style="width:133px;" class="text-center">{{date('Y-m-d H:i',strtotime($v['update_time']))}}</td>
<td style="width: 64px;" class="text-center"> <td style="width: 64px;" class="text-center">
@if(!empty($v['status'])) @if(!empty($v['status']))
<span class="label label-primary"> <span class="label label-primary">
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
</tbody> </tbody>
<tfoot></tfoot> <tfoot></tfoot>
</table> </table>
{!! $list ? $list->links() : '' !!} {!! $links !!}
</div> </div>
</div> </div>
<div class="row" id="my_list_paginate"></div> <div class="row" id="my_list_paginate"></div>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>账号管理系统 | {{$title or ''}}</title> <title>账号管理系统 | {{$title ?? ''}}</title>
@include('web.css') @include('web.css')
<style> <style>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>账号管理系统 | {{$title or ''}}</title> <title>账号管理系统 | {{$title ?? ''}}</title>
@include('web.css') @include('web.css')
<style> <style>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>账号管理系统 | {{$title or ''}}</title> <title>账号管理系统 | {{$title ?? ''}}</title>
@include('web.css') @include('web.css')
<style> <style>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>账号管理系统 | {{$title or ''}}</title> <title>账号管理系统 | {{$title ?? ''}}</title>
@include('role.css') @include('role.css')
<style> <style>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>账号管理系统 | {{$title or ''}}</title> <title>账号管理系统 | {{$title ?? ''}}</title>
@include('role.css') @include('role.css')
<style> <style>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>账号管理系统 | {{$title or ''}}</title> <title>账号管理系统 | {{$title ?? ''}}</title>
@include('web.css') @include('web.css')
<style> <style>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>账号管理系统 | {{$title or ''}}</title> <title>账号管理系统 | {{$title ?? ''}}</title>
@include('web.css') @include('web.css')
<style> <style>
......
<?php <?php
use App\Http\Controllers\CodeController;
use App\Http\Controllers\DepartmentController; use App\Http\Controllers\DepartmentController;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\PositionController;
use App\Http\Controllers\PositionPermController;
use App\Http\Controllers\RoleController;
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;
...@@ -29,6 +34,25 @@ ...@@ -29,6 +34,25 @@
Route::match(['get', 'post'], '/department/getDepartmentList', [\App\Http\Controllers\DepartmentController::class, 'getDepartmentList']); 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/addChildDepartment', [DepartmentController::class, 'addChildDepartment']);
Route::match(['get', 'post'], '/department/delDepartment', [DepartmentController::class, 'delDepartment']); Route::match(['get', 'post'], '/department/delDepartment', [DepartmentController::class, 'delDepartment']);
Route::match(['get', 'post'], '/department/addDepartment', [DepartmentController::class, 'addDepartment']); Route::match(['get', 'post'], '/department/addDepartment', [DepartmentController::class, 'addDepartment']);
Route::match(['get', 'post'], '/department/editDepartment', [DepartmentController::class, 'editDepartment']); Route::match(['get', 'post'], '/department/editDepartment', [DepartmentController::class, 'editDepartment']);
Route::match(['get', 'post'], '/position/getPositionList', [PositionController::class, 'getPositionList']);
Route::match(['get', 'post'], '/position/addPosition', [PositionController::class, 'addPosition']);
Route::match(['get', 'post'], '/position/editPosition', [PositionController::class, 'editPosition']);
Route::match(['get', 'post'], '/position/delPosition', [PositionController::class, 'delPosition']);
Route::match(['get', 'post'], '/positionPerm/getPositionPermList', [PositionPermController::class, 'getPositionPermList']);
Route::match(['get', 'post'], '/positionPerm/setPositionPerm', [PositionPermController::class, 'setPositionPerm']);
Route::match(['get', 'post'], '/positionPerm/delPositionPerm', [PositionPermController::class, 'delPositionPerm']);
Route::match(['get', 'post'], '/businessRoles/getBusinessRoles', [RoleController::class, 'getBusinessRoles']);
Route::match(['get', 'post'], '/intracode/Unbundling', [CodeController::class, 'Unbundling']);
Route::match(['get', 'post'], '/intracode/refreshDingDing', [CodeController::class, 'refreshDingDing']);
Route::match(['get', 'post'], '/intracode/binding', [CodeController::class, 'binding']);
Route::match(['get', 'post'], '/log/getLoginLogList', [LoginController::class, 'getLoginLogList']);
Route::post('/resetpasswd', [UserController::class, 'resetpasswd']);//用户修改密码接口
<?php <?php
use App\Http\Controllers\CodeController;
use App\Http\Controllers\ConfigController;
use App\Http\Controllers\DepartmentController; use App\Http\Controllers\DepartmentController;
use App\Http\Controllers\PositionController;
use App\Http\Controllers\PositionPermController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController; use App\Http\Controllers\UserController;
...@@ -25,3 +29,11 @@ ...@@ -25,3 +29,11 @@
Route::get('/user/{id?}', [UserController::class, 'info']); Route::get('/user/{id?}', [UserController::class, 'info']);
Route::match(['get', 'post'], '/web/departmentList', [DepartmentController::class, 'departmentList']); Route::match(['get', 'post'], '/web/departmentList', [DepartmentController::class, 'departmentList']);
Route::match(['get', 'post'], '/web/positionList', [PositionController::class, 'positionList']);
Route::match(['get', 'post'], '/web/positionPermList', [PositionPermController::class, 'positionPermList']);
Route::match(['get', 'post'], '/intracode/codelist', [CodeController::class, 'codelist']);
Route::match(['get', 'post'], '/intracode/Handle_code', [CodeController::class, 'Handle_code']);
Route::get('/resetpasswd', [UserController::class, 'resetPassWord']);//用户修改密码
Route::match(['get', 'post'], '/web/loginLog', [UserController::class, 'loginLog']);
Route::get('/help', [ConfigController::class, 'help']);
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