You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

881 lines
30 KiB

4 years ago
<?php
// +----------------------------------------------------------------------
// | Description: 系统员工
// +----------------------------------------------------------------------
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\model\User;
use think\Request;
use think\Session;
use think\Hook;
use think\Cache;
use think\Db;
use app\admin\model\LoginRecord;
use app\admin\model\User as UserModel;
use app\admin\logic\UserLogic;
use app\admin\model\Admin as AdminModel;
use app\crm\traits\StarTrait;
4 years ago
4 years ago
class Users extends ApiCommon
{
use StarTrait;
4 years ago
4 years ago
/**
* 用于判断权限
* @permission 无限制
* @allow 登录员工可访问
* @other 其他根据系统设置
4 years ago
**/
4 years ago
public function _initialize()
{
$action = [
'permission' => ['exceldownload'],
'allow' => [
'index',
'update',
'updatepwd',
'read',
'updateimg',
'resetpassword',
'userlistbystructid',
'groups',
'groupsdel',
'tobeusers',
'structureuserlist',
'getuserlist',
'usernameedit',
'import',
'setparent',
'loginRecord',
'userstar',
'querylist',
'starlist',
'copyrole',
4 years ago
'subordinate',
'countnumofuser',
'setuserdept'
4 years ago
]
];
4 years ago
Hook::listen('check_auth', $action);
4 years ago
$request = Request::instance();
4 years ago
$a = strtolower($request->action());
4 years ago
if (!in_array($a, $action['permission'])) {
parent::_initialize();
4 years ago
}
4 years ago
}
4 years ago
4 years ago
/**
* 员工列表
4 years ago
* @param
4 years ago
* @return
*/
public function index()
4 years ago
{
4 years ago
$userModel = model('User');
4 years ago
$param = $this->param;
4 years ago
$data = $userModel->getDataList($param);
return resultArray(['data' => $data]);
}
4 years ago
4 years ago
/**
* 员工详情
4 years ago
* @param
4 years ago
* @return
*/
public function read()
4 years ago
{
4 years ago
$userModel = model('User');
$param = $this->param;
$userInfo = $this->userInfo;
if (!$param['id']) $param['id'] = $userInfo['id'];
$data = $userModel->getDataById($param['id']);
if (!$data) {
return resultArray(['error' => $userModel->getError()]);
4 years ago
}
4 years ago
$serverUserInfo = $this->queryLoginUser();
if (!empty($serverUserInfo)) $data['serverUserInfo'] = $serverUserInfo;
3 years ago
# 角色权限查看 配置范围对应id
$rule_authority_id = db('admin_rule')->where(['title' => '角色权限查看', 'name' => 'ruleList'])->value('id');
$data['rule_authority_id'] = $rule_authority_id;
# 数据库更新 todo 在线升级正常使用后删除
$updateStatus = $this->executeUpdateSql();
if (empty($updateStatus['status'])) return resultArray(['error' => $updateStatus['message']]);
4 years ago
return resultArray(['data' => $data]);
}
3 years ago
/**
* 更新SQL
*
* @author fanqi
* @since 2021-05-08
*/
public function executeUpdateSql()
{
// 表前缀
$prefix = config('database.prefix');
// 检查更新记录表是否存在
if (!db()->query("SHOW TABLES LIKE '".$prefix."admin_upgrade_record'")) {
db()->query("
CREATE TABLE `".$prefix."admin_upgrade_record` (
`version` int(10) unsigned DEFAULT NULL COMMENT '版本号',
UNIQUE KEY `version` (`version`) USING BTREE
) ENGINE = InnoDB DEFAULT CHARSET = utf8 COMMENT = 'SQL更新记录用于防止重复执行更新。'
");
}
// 检查是否执行过11.0.3版本的更新
if (!db('admin_upgrade_record')->where('version', 1103)->value('version')) {
// 添加跟进记录导入导出权限数据
UpdateSql::addFollowRuleData();
// 添加公海默认数据
$poolStatus = UpdateSql::addPoolDefaultData();
if (!$poolStatus) return ['status' => false, 'message' => '添加公海默认配置失败,请在后台手动添加!'];
// 添加此次升级标记
db('admin_upgrade_record')->insert(['version' => 1103]);
return ['status' => true, 'message' => '更新完成!'];
}
// 检查是否执行过11.0.4版本的更新
if (!db('admin_upgrade_record')->where('version', 1104)->value('version')) {
// 处理11.0.3升级时,没有处理旧公海数据的问题
UpdateSql::SynchronizationCustomerToPool();
// 发票导出权限
UpdateSql::createInvoiceExportRule();
// 修改数字字段类型
UpdateSql::updateFieldNumberType();
// 添加此次升级标记
db('admin_upgrade_record')->insert(['version' => 1104]);
}
return ['status' => true, 'message' => '没有可用更新!'];
}
4 years ago
4 years ago
/**
* 员工创建
4 years ago
* @param
4 years ago
* @return
4 years ago
*/
4 years ago
public function save()
{
$userModel = model('User');
$param = $this->param;
4 years ago
$userInfo = $this->userInfo;
3 years ago
$param['userId']=$userInfo['id'];
4 years ago
$data = $userModel->createData($param);
if (!$data) {
return resultArray(['error' => $userModel->getError()]);
}
return resultArray(['data' => '添加成功']);
}
4 years ago
4 years ago
/**
* 员工编辑
4 years ago
* @param
4 years ago
* @return
*/
public function update()
{
$userModel = model('User');
$param = $this->param;
$userInfo = $this->userInfo;
$userData = db('admin_user')->where(['id' => $param['id']])->find();
if (!$param['id']) {
//修改个人信息
$param['user_id'] = $userInfo['id'];
} else {
//权限判断
if (!checkPerByAction('admin', 'users', 'update')) {
header('Content-Type:application/json; charset=utf-8');
4 years ago
exit(json_encode(['code' => 102, 'error' => '无权操作']));
}
3 years ago
$param['userId']=$userInfo['id'];
4 years ago
}
unset($param['username']);
$data = $userModel->updateDataById($param, $param['id']);
if (!$data) {
return resultArray(['error' => $userModel->getError()]);
}
$param['userInfo'] = $userData;
$resSync = model('Sync')->syncData($param);
return resultArray(['data' => '编辑成功']);
4 years ago
}
//批量设置密码
public function updatePwd()
{
4 years ago
//权限判断
if (!checkPerByAction('admin', 'users', 'update')) {
header('Content-Type:application/json; charset=utf-8');
4 years ago
exit(json_encode(['code' => 102, 'error' => '无权操作']));
}
$param = $this->param;
3 years ago
$userInfo=$this->userInfo;
$param['user_id']=$userInfo['id'];
4 years ago
if ($param['password'] && is_array($param['id'])) {
$userModel = model('User');
$ret = $userModel->updatePwdById($param);
if ($ret) {
return resultArray(['data' => true]);
} else {
return resultArray(['error' => $userModel->getError()]);
}
} else {
return resultArray(['error' => '参数错误']);
}
}
4 years ago
/**
* 员工状态
* @param status 0禁用,1启用,2禁止登陆,3未激活
* @return
*/
public function enables()
{
$userModel = model('User');
$param = $this->param;
if (!is_array($param['id'])) {
$ids[] = $param['id'];
} else {
$ids = $param['id'];
}
//顶级管理员不能修改
4 years ago
foreach ($ids as $k => $v) {
4 years ago
if ((int)$v == 1 && $param['status'] == '0') {
unset($ids[$k]);
}
}
4 years ago
$data = $userModel->enableDatas($ids, $param['status']);
4 years ago
if (!$data) {
return resultArray(['error' => $userModel->getError()]);
4 years ago
}
# 添加记录
if ($param['status'] == 0) {
$content = '禁用了:';
} elseif ($param['status'] == 1) {
$content = '激活了:';
}
$user = new ApiCommon();
$userInfo = $user->userInfo;
foreach ($ids as $key => $val) {
$dataInfo = db('admin_user')->where('id', $val)->find();
SystemActionLog($userInfo['id'], 'admin_user', 'employee', $val, 'update', '员工状态', '', '', $content . $dataInfo['realname']);
}
return resultArray(['data' => '操作成功']);
4 years ago
}
4 years ago
4 years ago
/**
* 获取权限范围内的员工数组
4 years ago
* @param
4 years ago
* @return
*/
public function getUserList()
{
$userModel = model('User');
$param = $this->param;
4 years ago
$by = $param['by'] ?: '';
$user_id = $param['user_id'] ?: '';
4 years ago
$where = [];
$belowIds = [];
if ($param['m'] && $param['c'] && $param['a']) {
if ($param['m'] == 'oa' && $param['c'] == 'task') {
4 years ago
$belowIds = getSubUserId(true, 1);
4 years ago
} else {
$belowIds = $userModel->getUserByPer($param['m'], $param['c'], $param['a']);
}
4 years ago
$where['user.id'] = ['in', $belowIds];
4 years ago
} else {
if ($by == 'sub') {
$userInfo = $this->userInfo;
$adminIds = $userModel->getAdminId();
4 years ago
if (in_array($userInfo['id'], $adminIds)) {
4 years ago
$belowIds = getSubUserId(true, 1);
} else {
//下属id
$belowIds = getSubUserId();
4 years ago
}
$where['user.id'] = ['in', $belowIds];
4 years ago
} elseif ($by == 'parent') {
if ($user_id == 1) {
$where['user.id'] = 0;
} else {
$unUserId[] = $user_id;
$subUserId = getSubUser($user_id);
4 years ago
$unUserId = $subUserId ? array_merge($subUserId, $unUserId) : $unUserId;
4 years ago
}
4 years ago
$where['user.id'] = ['not in', $unUserId];
4 years ago
} else {
$belowIds = getSubUserId(true, 1);
4 years ago
$where['user.id'] = ['in', $belowIds];
4 years ago
}
}
$userList = db('admin_user')
4 years ago
->alias('user')
->where($where)
->where('user.status>0 and user.type=1')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->field('user.id,user.realname,user.thumb_img,structure.name as s_name')
->select();
4 years ago
# 角色数据
$groupList = db('admin_access')->alias('access')
4 years ago
->join('__ADMIN_GROUP__ group', 'group.id = access.group_id', 'LEFT')
->field('group.id, group.title, access.user_id')->select();
4 years ago
$groupArray = [];
4 years ago
foreach ($groupList as $key => $value) {
4 years ago
$groupArray[$value['user_id']]['roleId'][] = $value['id'];
$groupArray[$value['user_id']]['roleName'][] = $value['title'];
}
4 years ago
foreach ($userList as $k => $v) {
$userList[$k]['username'] = $v['realname'];
4 years ago
$userList[$k]['thumb_img'] = $v['thumb_img'] ? getFullPath($v['thumb_img']) : '';
4 years ago
4 years ago
# 员工新增角色ID和角色名称字段
4 years ago
$userList[$k]['roleId'] = !empty($groupArray[$v['id']]['roleId']) ? implode(',', $groupArray[$v['id']]['roleId']) : '';
$userList[$k]['roleName'] = !empty($groupArray[$v['id']]['roleName']) ? implode(',', $groupArray[$v['id']]['roleName']) : '';
4 years ago
# 单独处理admin管理员的角色ID和角色名称字段
if ($v['id'] == 1 && (empty($groupArray[$v['id']]['roleId']) || empty($groupArray[$v['id']]['roleName']))) {
4 years ago
$userList[$k]['roleId'] = '1';
4 years ago
$userList[$k]['roleName'] = '超级管理员角色';
}
}
4 years ago
return resultArray(['data' => $userList ?: []]);
4 years ago
}
4 years ago
4 years ago
/**
* 修改头像
4 years ago
* @param
4 years ago
* @return
4 years ago
*/
4 years ago
public function updateImg()
{
$fileModel = model('File');
$param = $this->param;
$userInfo = $this->userInfo;
//处理图片
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
4 years ago
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
4 years ago
$param['file'] = request()->file('file');
4 years ago
4 years ago
$resImg = $fileModel->updateByField($param['file'], 'User', $param['id'], 'img', 'thumb_img', 150, 150);
if (!$resImg) {
return resultArray(['error' => $fileModel->getError()]);
}
return resultArray(['data' => '上传成功']);
}
4 years ago
4 years ago
/**
* 重置密码
4 years ago
* @param
4 years ago
* @return
4 years ago
*/
4 years ago
public function resetPassword()
4 years ago
{
4 years ago
$param = $this->param;
$userInfo = $this->userInfo;
$userModel = model('User');
3 years ago
$userId=$userInfo['id'];
4 years ago
if (empty($param['new_pwd']) || empty($param['old_pwd'])) return resultArray(['error' => '密码不能为空!']);
4 years ago
4 years ago
if ($param['id'] && (int)$param['id'] !== $userInfo['id']) {
//权限判断
if (!checkPerByAction('admin', 'users', 'update')) {
header('Content-Type:application/json; charset=utf-8');
4 years ago
exit(json_encode(['code' => 102, 'error' => '无权操作']));
}
4 years ago
$user_id = $param['id'];
if (!$param['new_pwd']) {
$this->error = '请输入重置密码';
return false;
}
4 years ago
4 years ago
$userInfo = $userModel->getDataById($user_id);
if (user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']) == $userInfo['password']) {
$this->error = '密码没改变';
return false;
}
if (db('admin_user')->where('id', $user_id)->setField('password', user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']))) {
$syncData = [];
$syncModel = new \app\admin\model\Sync();
$syncData['user_id'] = $userInfo['id'];
$syncData['salt'] = $userInfo['salt'];
$syncData['password'] = user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']);
4 years ago
$resSync = $syncModel->syncData($syncData);
# 添加记录
SystemActionLog($userInfo['id'], 'admin_user', 'employee', $userInfo['id'], 'update', $userInfo['realname'], '', '', '重置了密码:' . $userInfo['realname']);
4 years ago
return resultArray(['data' => '密码重置成功']);
} else {
return resultArray(['error' => '密码重置失败,请重试']);
4 years ago
}
4 years ago
} else {
$userModel = model('User');
$old_pwd = $param['old_pwd'];
$new_pwd = $param['new_pwd'];
3 years ago
$data = $userModel->updatePaw($userInfo, $old_pwd, $new_pwd,$userId);
4 years ago
if (!$data) {
return resultArray(['error' => $userModel->getError()]);
4 years ago
}
return resultArray(['data' => $data]);
4 years ago
}
}
4 years ago
4 years ago
/**
* 员工角色关系
4 years ago
* @param
4 years ago
* @return
*/
public function groups()
{
//权限判断
if (!checkPerByAction('admin', 'groups', 'update')) {
header('Content-Type:application/json; charset=utf-8');
4 years ago
exit(json_encode(['code' => 102, 'error' => '无权操作']));
}
4 years ago
$param = $this->param;
if (!$param['users'] && !$param['structures']) {
return resultArray(['error' => '请选择员工']);
}
if (!$param['groups']) {
return resultArray(['error' => '请选择角色']);
}
$userModel = model('User');
//部门下所有员工
$userArr = [];
if (is_array($param['structures'])) {
foreach ($param['structures'] as $v) {
$userArr[] = $userModel->getSubUserByStr($v);
4 years ago
}
4 years ago
}
if ($userArr) $userArr = call_user_func_array('array_merge', $userArr); //数组合并
if ($userArr && $param['users']) {
$userIds = array_merge($userArr, $param['users']);
} elseif ($userArr) {
$userIds = $userArr;
} else {
$userIds = $param['users'];
}
$userIds = array_unique($userIds);
$groups = $param['groups'];
4 years ago
$accessModel = model('Access');
4 years ago
$resData = true;
4 years ago
$user_id = $this->userInfo;
foreach ($userIds as $k => $v) {
4 years ago
//角色员工关系处理
$res = $accessModel->userGroup($v, $param['groups']);
if (!$res) {
$resData = false;
4 years ago
}
$userInfo = Db::name('admin_user')->where('id', $v)->find();
$user_id=$this->userInfo;
SystemActionLog($user_id['id'], 'admin_user', 'employee', $v, 'update', $userInfo['realname'], '', '', '员工关联了角色:' . $userInfo['realname']);
4 years ago
}
// if ($resData == false) {
// return resultArray(['error' => '操作失败,请重试']);
// }
4 years ago
return resultArray(['data' => '创建成功']);
4 years ago
}
4 years ago
4 years ago
/**
* 员工角色关系(删除)
4 years ago
* @param
4 years ago
* @return
*/
public function groupsDel()
{
//权限判断
if (!checkPerByAction('admin', 'groups', 'update')) {
header('Content-Type:application/json; charset=utf-8');
4 years ago
exit(json_encode(['code' => 102, 'error' => '无权操作']));
}
4 years ago
$param = $this->param;
if (!$param['user_id']) {
return resultArray(['error' => '请选择员工']);
}
if (!$param['group_id']) {
return resultArray(['error' => '参数错误']);
}
4 years ago
4 years ago
# 员工至少保留一个角色
$count = db('admin_access')->where(['user_id' => $param['user_id']])->count();
if ($count == 1) return resultArray(['error' => '员工至少保留一个角色!']);
4 years ago
$res = db('admin_access')->where(['user_id' => $param['user_id'], 'group_id' => $param['group_id']])->delete();
4 years ago
if (!$res) {
4 years ago
return resultArray(['error' => '操作失败,请重试']);
4 years ago
}
4 years ago
return resultArray(['data' => '删除成功']);
4 years ago
}
4 years ago
4 years ago
/**
* [structureUserList 部门员工混合数据]
4 years ago
* @param
4 years ago
* @return
4 years ago
*/
4 years ago
public function structureUserList()
{
$structure_list = db('admin_structure')->select();
$structureList = getSubObj(0, $structure_list, '', 1);
4 years ago
foreach ($structureList as $k => $v) {
4 years ago
$userList = [];
4 years ago
$userList = db('admin_user')->where(['structure_id' => $v['id'], 'status' => array('in', ['1', '3'])])->field('id,realname')->select();
4 years ago
$structureList[$k]['userList'] = $userList;
}
return $structureList;
4 years ago
}
//人资员工导入
public function tobeusers()
{
$userModel = model('User');
$param = $this->param;
$flag = $userModel->beusers($param);
if ($flag) {
return resultArray(['data' => $flag]);
} else {
return resultArray(['error' => $userModel->getError()]);
}
}
//根据部门ID获取员工列表
public function userListByStructId()
{
$usermodel = model('User');
$param = $this->param;
$structure_id = $param['structure_id'] ?: '';
$ret = $usermodel->getUserListByStructureId($structure_id) ?: [];
return resultArray(['data' => $ret]);
}
4 years ago
/**
* 员工账号修改
4 years ago
* @param
4 years ago
* @return
4 years ago
*/
4 years ago
public function usernameEdit()
{
//权限判断
if (!checkPerByAction('admin', 'users', 'update')) {
header('Content-Type:application/json; charset=utf-8');
4 years ago
exit(json_encode(['code' => 102, 'error' => '无权操作']));
}
4 years ago
$param = $this->param;
$userInfo = $this->userInfo;
//权限判断
if ($param['id'] == 1) {
return resultArray(['error' => '管理员账号暂不能修改']);
}
$adminTypes = adminGroupTypes($userInfo['id']);
4 years ago
if (!in_array(3, $adminTypes) && !in_array(1, $adminTypes) && !in_array(2, $adminTypes)) {
4 years ago
header('Content-Type:application/json; charset=utf-8');
4 years ago
exit(json_encode(['code' => 102, 'error' => '无权操作']));
}
4 years ago
if (!$param['id'] || !$param['username'] || !$param['password']) {
return resultArray(['error' => '参数错误!']);
}
4 years ago
if (db('admin_user')->where(['id' => ['neq', $param['id']], 'username' => $param['username']])->find()) {
4 years ago
return resultArray(['error' => '手机号码已存在!']);
}
4 years ago
$userData = db('admin_user')->where(['id' => $param['id']])->field('username,salt,password,realname')->find();
4 years ago
$data = [];
$data['username'] = $param['username'];
$data['password'] = user_md5($param['password'], $userData['salt'], $param['username']);
$data['userInfo'] = $userData;
4 years ago
$data['mobile'] = $param['username'];
4 years ago
$resSync = model('Sync')->syncData($data);
if ($resSync) {
unset($data['userInfo']);
$res = db('admin_user')->where(['id' => $param['id']])->update($data);
4 years ago
SystemActionLog($userInfo['id'], 'admin_user', 'employee', $param['id'], 'update', $userData['realname'], '', '', '员工账号修改:' . $userData['realname']);
4 years ago
return resultArray(['data' => '修改成功!']);
} else {
return resultArray(['error' => '修改失败,请重试!']);
}
}
4 years ago
4 years ago
/**
* 登录记录
*/
public function loginRecord()
{
if (!checkPerByAction('admin', 'loginRecord', 'index')) {
header('Content-Type:application/json; charset=utf-8');
exit(json_encode(['code' => 102, 'error' => '无权操作']));
}
4 years ago
4 years ago
$loginRecordModel = new LoginRecord();
$where = [];
getWhereUserByParam($where, 'create_user_id');
getWhereTimeByParam($where, 'create_time');
4 years ago
4 years ago
$limit = $this->param['limit'] ?: 15;
$data = $loginRecordModel
->where($where)
->order(['create_time' => 'DESC'])
->paginate($limit)
->each(function ($val) {
$val['username'] = $val->create_user_info['realname'];
$val['type_name'] = $val->type_name;
})
->toArray();
return resultArray([
'data' => [
'list' => $data['data'],
'dataCount' => $data['total']
],
]);
}
4 years ago
4 years ago
/**
* 员工导入模板下载
* @param string $save_path 本地保存路径 用于错误数据导出,在 Admin\Model\Excel::batchImportData()调用
* @return
4 years ago
* @author Michael_xu
4 years ago
*/
public function excelDownload($save_path = '')
{
$param = $this->param;
$userInfo = $this->userInfo;
$excelModel = new \app\admin\model\Excel();
4 years ago
4 years ago
// 导出的字段列表
$field_list = UserModel::$import_field_list;
$excelModel->excelImportDownload($field_list, 'admin_user', $save_path);
}
4 years ago
4 years ago
/**
* 员工导入
*/
public function import()
{
// 仅允许超管,系统管理员,部门与员工管理员 导入
if (false === UserModel::checkUserGroup([1, 2, 3])) {
return resultArray(['error' => '没有该权限']);
}
$param = $this->param;
$userInfo = $this->userInfo;
$excelModel = new \app\admin\model\Excel();
$param['types'] = 'admin_user';
$file = request()->file('file');
$res = $excelModel->batchImportData($file, $param, $this);
4 years ago
$list = [];
$list[] = $excelModel->getError();
$item = $list[0];
4 years ago
if (!$res) {
return resultArray(['data' => $item]);
}
Cache::clear('user_info');
return resultArray(['data' => $item]);
}
4 years ago
4 years ago
/**
* 批量设置直属上级
*
* @author Ymob
* @datetime 2019-10-28 13:37:57
*/
public function setParent()
{
// 仅允许超管,系统管理员,部门与员工管理员 批量设置
if (false === UserModel::checkUserGroup([1, 2, 3])) {
return resultArray(['error' => '没有该权限']);
}
4 years ago
$parent_id = (int)$this->param['parent_id'];
4 years ago
$parent_user = UserModel::find($parent_id);
if (!$parent_user) {
return resultArray(['error' => '请选择直属上级']);
}
4 years ago
$user_id_list = (array)$this->param['id_list'];
4 years ago
if (empty($user_id_list)) {
return resultArray(['error' => '请选择员工']);
}
if (in_array(1, $user_id_list)) {
return resultArray(['error' => '超级管理员不能设置上级']);
}
4 years ago
4 years ago
if (in_array($parent_id, $user_id_list)) {
return resultArray(['error' => '直属上级不能为员工自己']);
}
foreach ($user_id_list as $val) {
4 years ago
if (in_array($parent_id, getSubUserId(true, 0, (int)$val))) {
4 years ago
return resultArray(['error' => '直属上级不能是自己下属(包含下属的下属)']);
}
}
4 years ago
4 years ago
$a = new UserModel;
if ($a->where(['id' => ['IN', $user_id_list]])->update(['parent_id' => $parent_id])) {
Cache::clear('user_info');
return resultArray(['data' => '员工直属上级设置成功']);
} else {
return resultArray(['error' => '员工直属上级设置失败' . $a->getError()]);
}
}
4 years ago
4 years ago
/**
* 通讯录列表
* @return mixed
*/
4 years ago
public function queryList()
{
4 years ago
$param = $this->param;
$userInfo = $this->userInfo;
4 years ago
$param['user_id'] = $userInfo['id'];
$userLogic = new UserLogic();
$data = $userLogic->getDataList($param);
4 years ago
return resultArray(['data' => $data]);
4 years ago
4 years ago
}
4 years ago
4 years ago
/**
* 关注的通讯录列表
* @return mixed
*/
4 years ago
public function starList()
{
4 years ago
$param = $this->param;
$userInfo = $this->userInfo;
4 years ago
$param['user_id'] = $userInfo['id'];
$userLogic = new UserLogic();
$data = $userLogic->queryList($param);
4 years ago
return resultArray(['data' => $data]);
}
4 years ago
4 years ago
/**
* 设置关注
*
*/
public function userStar()
{
$userInfo = $this->userInfo;
4 years ago
$userId = $userInfo['id'];
4 years ago
$targetId = $this->param['target_id'];
4 years ago
$type = $this->param['type'];
4 years ago
if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']);
4 years ago
4 years ago
if (!$this->setStar($type, $userId, $targetId)) {
return resultArray(['error' => '设置关注失败!']);
}
4 years ago
4 years ago
return resultArray(['data' => '设置关注成功!']);
}
4 years ago
4 years ago
/**
* 复制员工角色
*
* @return \think\response\Json
*/
public function copyRole()
{
$param = $this->param;
if (empty($param['user_id']) && empty($param['structure_id'])) return resultArray(['error' => '请选择员工或部门!']);
if (empty($param['group_id'])) return resultArray(['error' => '请选择角色!']);
4 years ago
4 years ago
$userModel = new User();
3 years ago
$userInfo=$this->userInfo;
$param['userId']=$userInfo['id'];
4 years ago
if (!$userModel->copyRole($param)) return resultArray(['error' => '操作失败!']);
4 years ago
4 years ago
return resultArray(['data' => '操作成功!']);
}
4 years ago
4 years ago
/**
* 获取下属(全部层级)
*
*/
public function subordinate()
{
$userId = $this->userInfo['id'];
4 years ago
4 years ago
# 获取下属的ID
$subIds = getSubUserId(false, 0, $userId);
4 years ago
4 years ago
$data = Db::name('admin_user')->field(['id', 'realname', 'thumb_img as img'])->whereIn('id', $subIds)->select();
4 years ago
foreach ($data as $key => $value) {
4 years ago
$data[$key]['img'] = !empty($data[$key]['img']) ? getFullPath($data[$key]['img']) : '';
}
4 years ago
4 years ago
return resultArray(['data' => $data]);
}
4 years ago
4 years ago
/**
* 获取当前登录人信息
*
4 years ago
*/
4 years ago
public function queryLoginUser()
{
$resData = [];
4 years ago
$wkcode = file_get_contents(CONF_PATH . 'license.dat');
4 years ago
if ($wkcode) {
$resCheckData = checkWkCode($wkcode);
if ($resCheckData) {
$resData = object_to_array(json_decode($resCheckData));
4 years ago
}
4 years ago
}
4 years ago
return $resData;
}
/**
* 批量重设部门
*
* @author alvin guogaobo
* @version 1.0 版本号
* @since 2021/4/15 0015 16:37
*/
public function setUserDept()
{
//权限判断
// 仅允许超管,系统管理员,部门与员工管理员 导入
if (false === UserModel::checkUserGroup([1, 2, 3])) {
return resultArray(['error' => '没有该权限']);
}
$userModel = model('User');
$param = $this->param;
if (!is_array($param['id'])) {
$ids[] = $param['id'];
} else {
$ids = $param['id'];
}
$data = $userModel->setUserDept($ids, $param);
if (!$data) {
return resultArray(['error' => $userModel->getError()]);
}
# 添加记录
$userInfo = $this->userInfo;
foreach ($ids as $key => $val) {
$dataInfo = db('admin_user')->where('id', $val)->find();
SystemActionLog($userInfo['id'], 'admin_user', 'employee', $val, 'update', $dataInfo['realname'], '', '','重置了部门: ' . $dataInfo['realname']);
}
return resultArray(['data' => '操作成功']);
}
/**
* 员工分类后面跟的数据
* @author alvin guogaobo
* @version 1.0 版本号
* @since 2021/4/24 0024 14:42
*/
public function countNumOfUser(){
$userModel = model('User');
$data=$userModel->countNumOfUser();
return resultArray(['data' => $data['list']]);
4 years ago
}
4 years ago
}