123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 系统员工
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\controller;
  8. use app\admin\model\User;
  9. use think\Request;
  10. use think\Session;
  11. use think\Hook;
  12. use think\Cache;
  13. use think\Db;
  14. use app\admin\model\LoginRecord;
  15. use app\admin\model\User as UserModel;
  16. use app\admin\logic\UserLogic;
  17. use app\admin\model\Admin as AdminModel;
  18. use app\crm\traits\StarTrait;
  19. class Users extends ApiCommon
  20. {
  21. use StarTrait;
  22. /**
  23. * 用于判断权限
  24. * @permission 无限制
  25. * @allow 登录员工可访问
  26. * @other 其他根据系统设置
  27. **/
  28. public function _initialize()
  29. {
  30. $action = [
  31. 'permission' => ['exceldownload'],
  32. 'allow' => [
  33. 'index',
  34. 'update',
  35. 'updatepwd',
  36. 'read',
  37. 'updateimg',
  38. 'resetpassword',
  39. 'userlistbystructid',
  40. 'groups',
  41. 'groupsdel',
  42. 'tobeusers',
  43. 'structureuserlist',
  44. 'getuserlist',
  45. 'usernameedit',
  46. 'import',
  47. 'setparent',
  48. 'loginRecord',
  49. 'userstar',
  50. 'querylist',
  51. 'starlist',
  52. 'copyrole',
  53. 'subordinate'
  54. ]
  55. ];
  56. Hook::listen('check_auth',$action);
  57. $request = Request::instance();
  58. $a = strtolower($request->action());
  59. if (!in_array($a, $action['permission'])) {
  60. parent::_initialize();
  61. }
  62. }
  63. /**
  64. * 员工列表
  65. * @param
  66. * @return
  67. */
  68. public function index()
  69. {
  70. $userModel = model('User');
  71. $param = $this->param;
  72. $data = $userModel->getDataList($param);
  73. return resultArray(['data' => $data]);
  74. }
  75. /**
  76. * 员工详情
  77. * @param
  78. * @return
  79. */
  80. public function read()
  81. {
  82. $userModel = model('User');
  83. $param = $this->param;
  84. $userInfo = $this->userInfo;
  85. if (!$param['id']) $param['id'] = $userInfo['id'];
  86. $data = $userModel->getDataById($param['id']);
  87. if (!$data) {
  88. return resultArray(['error' => $userModel->getError()]);
  89. }
  90. $data['serverUserInfo'] = $this->queryLoginUser();
  91. return resultArray(['data' => $data]);
  92. }
  93. /**
  94. * 员工创建
  95. * @param
  96. * @return
  97. */
  98. public function save()
  99. {
  100. $userModel = model('User');
  101. $param = $this->param;
  102. $userInfo = $this->userInfo;
  103. $data = $userModel->createData($param);
  104. if (!$data) {
  105. return resultArray(['error' => $userModel->getError()]);
  106. }
  107. return resultArray(['data' => '添加成功']);
  108. }
  109. /**
  110. * 员工编辑
  111. * @param
  112. * @return
  113. */
  114. public function update()
  115. {
  116. $userModel = model('User');
  117. $param = $this->param;
  118. $userInfo = $this->userInfo;
  119. $userData = db('admin_user')->where(['id' => $param['id']])->find();
  120. if (!$param['id']) {
  121. //修改个人信息
  122. $param['user_id'] = $userInfo['id'];
  123. } else {
  124. //权限判断
  125. if (!checkPerByAction('admin', 'users', 'update')) {
  126. header('Content-Type:application/json; charset=utf-8');
  127. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  128. }
  129. }
  130. unset($param['username']);
  131. $data = $userModel->updateDataById($param, $param['id']);
  132. if (!$data) {
  133. return resultArray(['error' => $userModel->getError()]);
  134. }
  135. $param['userInfo'] = $userData;
  136. $resSync = model('Sync')->syncData($param);
  137. return resultArray(['data' => '编辑成功']);
  138. }
  139. //批量设置密码
  140. public function updatePwd()
  141. {
  142. //权限判断
  143. if (!checkPerByAction('admin', 'users', 'update')) {
  144. header('Content-Type:application/json; charset=utf-8');
  145. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  146. }
  147. $param = $this->param;
  148. if ($param['password'] && is_array($param['id'])) {
  149. $userModel = model('User');
  150. $ret = $userModel->updatePwdById($param);
  151. if ($ret) {
  152. return resultArray(['data'=>true]);
  153. } else {
  154. return resultArray(['error'=>$userModel->getError()]);
  155. }
  156. } else {
  157. return resultArray(['error'=>'参数错误']);
  158. }
  159. }
  160. /**
  161. * 员工状态
  162. * @param status 0禁用,1启用,2禁止登陆,3未激活
  163. * @return
  164. */
  165. public function enables()
  166. {
  167. $userModel = model('User');
  168. $param = $this->param;
  169. if (!is_array($param['id'])) {
  170. $ids[] = $param['id'];
  171. } else {
  172. $ids = $param['id'];
  173. }
  174. //顶级管理员不能修改
  175. foreach ($ids as $k=>$v) {
  176. if ((int)$v == 1 && $param['status'] == '0') {
  177. unset($ids[$k]);
  178. }
  179. }
  180. $data = $userModel->enableDatas($ids, $param['status']);
  181. if (!$data) {
  182. return resultArray(['error' => $userModel->getError()]);
  183. }
  184. return resultArray(['data' => '操作成功']);
  185. }
  186. /**
  187. * 获取权限范围内的员工数组
  188. * @param
  189. * @return
  190. */
  191. public function getUserList()
  192. {
  193. $userModel = model('User');
  194. $param = $this->param;
  195. $by = $param['by'] ? : '';
  196. $user_id = $param['user_id'] ? : '';
  197. $where = [];
  198. $belowIds = [];
  199. if ($param['m'] && $param['c'] && $param['a']) {
  200. if ($param['m'] == 'oa' && $param['c'] == 'task') {
  201. $belowIds = getSubUserId(true, 1);
  202. } else {
  203. $belowIds = $userModel->getUserByPer($param['m'], $param['c'], $param['a']);
  204. }
  205. $where['user.id'] = ['in',$belowIds];
  206. } else {
  207. if ($by == 'sub') {
  208. $userInfo = $this->userInfo;
  209. $adminIds = $userModel->getAdminId();
  210. if (in_array($userInfo['id'],$adminIds)) {
  211. $belowIds = getSubUserId(true, 1);
  212. } else {
  213. //下属id
  214. $belowIds = getSubUserId();
  215. }
  216. $where['user.id'] = ['in',$belowIds];
  217. } elseif ($by == 'parent') {
  218. if ($user_id == 1) {
  219. $where['user.id'] = 0;
  220. } else {
  221. $unUserId[] = $user_id;
  222. $subUserId = getSubUser($user_id);
  223. $unUserId = $subUserId ? array_merge($subUserId,$unUserId) : $unUserId;
  224. }
  225. $where['user.id'] = ['not in',$unUserId];
  226. } else {
  227. $belowIds = getSubUserId(true, 1);
  228. $where['user.id'] = ['in',$belowIds];
  229. }
  230. }
  231. $userList = db('admin_user')
  232. ->alias('user')
  233. ->where($where)
  234. ->where('user.status>0 and user.type=1')
  235. ->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
  236. ->field('user.id,user.realname,user.thumb_img,structure.name as s_name')
  237. ->select();
  238. # 角色数据
  239. $groupList = db('admin_access')->alias('access')
  240. ->join('__ADMIN_GROUP__ group', 'group.id = access.group_id', 'LEFT')
  241. ->field('group.id, group.title, access.user_id')->select();
  242. $groupArray = [];
  243. foreach ($groupList AS $key => $value) {
  244. $groupArray[$value['user_id']]['roleId'][] = $value['id'];
  245. $groupArray[$value['user_id']]['roleName'][] = $value['title'];
  246. }
  247. foreach ($userList as $k=>$v) {
  248. $userList[$k]['username'] = $v['realname'];
  249. $userList[$k]['thumb_img'] = $v['thumb_img'] ? getFullPath($v['thumb_img']) : '';
  250. # 员工新增角色ID和角色名称字段
  251. $userList[$k]['roleId'] = !empty($groupArray[$v['id']]['roleId']) ? implode(',', $groupArray[$v['id']]['roleId']) : '';
  252. $userList[$k]['roleName'] = !empty($groupArray[$v['id']]['roleName']) ? implode(',', $groupArray[$v['id']]['roleName']) : '';
  253. # 单独处理admin管理员的角色ID和角色名称字段
  254. if ($v['id'] == 1 && (empty($groupArray[$v['id']]['roleId']) || empty($groupArray[$v['id']]['roleName']))) {
  255. $userList[$k]['roleId'] = '1';
  256. $userList[$k]['roleName'] = '超级管理员角色';
  257. }
  258. }
  259. return resultArray(['data' => $userList ? : []]);
  260. }
  261. /**
  262. * 修改头像
  263. * @param
  264. * @return
  265. */
  266. public function updateImg()
  267. {
  268. $fileModel = model('File');
  269. $param = $this->param;
  270. $userInfo = $this->userInfo;
  271. //处理图片
  272. header('Access-Control-Allow-Origin: *');
  273. header('Access-Control-Allow-Methods: POST');
  274. header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
  275. $param['file'] = request()->file('file');
  276. $resImg = $fileModel->updateByField($param['file'], 'User', $param['id'], 'img', 'thumb_img', 150, 150);
  277. if (!$resImg) {
  278. return resultArray(['error' => $fileModel->getError()]);
  279. }
  280. return resultArray(['data' => '上传成功']);
  281. }
  282. /**
  283. * 重置密码
  284. * @param
  285. * @return
  286. */
  287. public function resetPassword()
  288. {
  289. $param = $this->param;
  290. $userInfo = $this->userInfo;
  291. $userModel = model('User');
  292. if (empty($param['new_pwd']) || empty($param['old_pwd'])) return resultArray(['error' => '密码不能为空!']);
  293. if ($param['id'] && (int)$param['id'] !== $userInfo['id']) {
  294. //权限判断
  295. if (!checkPerByAction('admin', 'users', 'update')) {
  296. header('Content-Type:application/json; charset=utf-8');
  297. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  298. }
  299. $user_id = $param['id'];
  300. if (!$param['new_pwd']) {
  301. $this->error = '请输入重置密码';
  302. return false;
  303. }
  304. $userInfo = $userModel->getDataById($user_id);
  305. if (user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']) == $userInfo['password']) {
  306. $this->error = '密码没改变';
  307. return false;
  308. }
  309. if (db('admin_user')->where('id', $user_id)->setField('password', user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']))) {
  310. $syncData = [];
  311. $syncModel = new \app\admin\model\Sync();
  312. $syncData['user_id'] = $userInfo['id'];
  313. $syncData['salt'] = $userInfo['salt'];
  314. $syncData['password'] = user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']);
  315. $resSync = $syncModel->syncData($syncData);
  316. return resultArray(['data' => '密码重置成功']);
  317. } else {
  318. return resultArray(['error' => '密码重置失败,请重试']);
  319. }
  320. } else {
  321. $userModel = model('User');
  322. $old_pwd = $param['old_pwd'];
  323. $new_pwd = $param['new_pwd'];
  324. $data = $userModel->updatePaw($userInfo, $old_pwd, $new_pwd);
  325. if (!$data) {
  326. return resultArray(['error' => $userModel->getError()]);
  327. }
  328. return resultArray(['data' => $data]);
  329. }
  330. }
  331. /**
  332. * 员工角色关系
  333. * @param
  334. * @return
  335. */
  336. public function groups()
  337. {
  338. //权限判断
  339. if (!checkPerByAction('admin', 'groups', 'update')) {
  340. header('Content-Type:application/json; charset=utf-8');
  341. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  342. }
  343. $param = $this->param;
  344. if (!$param['users'] && !$param['structures']) {
  345. return resultArray(['error' => '请选择员工']);
  346. }
  347. if (!$param['groups']) {
  348. return resultArray(['error' => '请选择角色']);
  349. }
  350. $userModel = model('User');
  351. //部门下所有员工
  352. $userArr = [];
  353. if (is_array($param['structures'])) {
  354. foreach ($param['structures'] as $v) {
  355. $userArr[] = $userModel->getSubUserByStr($v);
  356. }
  357. }
  358. if ($userArr) $userArr = call_user_func_array('array_merge', $userArr); //数组合并
  359. if ($userArr && $param['users']) {
  360. $userIds = array_merge($userArr, $param['users']);
  361. } elseif ($userArr) {
  362. $userIds = $userArr;
  363. } else {
  364. $userIds = $param['users'];
  365. }
  366. $userIds = array_unique($userIds);
  367. $groups = $param['groups'];
  368. $accessModel = model('Access');
  369. $resData = true;
  370. foreach ($userIds as $k=>$v) {
  371. //角色员工关系处理
  372. $res = $accessModel->userGroup($v, $param['groups']);
  373. if (!$res) {
  374. $resData = false;
  375. }
  376. }
  377. // if ($resData == false) {
  378. // return resultArray(['error' => '操作失败,请重试']);
  379. // }
  380. return resultArray(['data' => '创建成功']);
  381. }
  382. /**
  383. * 员工角色关系(删除)
  384. * @param
  385. * @return
  386. */
  387. public function groupsDel()
  388. {
  389. //权限判断
  390. if (!checkPerByAction('admin', 'groups', 'update')) {
  391. header('Content-Type:application/json; charset=utf-8');
  392. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  393. }
  394. $param = $this->param;
  395. if (!$param['user_id']) {
  396. return resultArray(['error' => '请选择员工']);
  397. }
  398. if (!$param['group_id']) {
  399. return resultArray(['error' => '参数错误']);
  400. }
  401. # 员工至少保留一个角色
  402. $count = db('admin_access')->where(['user_id' => $param['user_id']])->count();
  403. if ($count == 1) return resultArray(['error' => '员工至少保留一个角色!']);
  404. $res = db('admin_access')->where(['user_id' => $param['user_id'],'group_id' => $param['group_id']])->delete();
  405. if (!$res) {
  406. return resultArray(['error' => '操作失败,请重试']);
  407. }
  408. return resultArray(['data' => '删除成功']);
  409. }
  410. /**
  411. * [structureUserList 部门员工混合数据]
  412. * @param
  413. * @return
  414. */
  415. public function structureUserList()
  416. {
  417. $structure_list = db('admin_structure')->select();
  418. $structureList = getSubObj(0, $structure_list, '', 1);
  419. foreach ($structureList as $k=>$v) {
  420. $userList = [];
  421. $userList = db('admin_user')->where(['structure_id' => $v['id'],'status' => array('in',['1','3'])])->field('id,realname')->select();
  422. $structureList[$k]['userList'] = $userList;
  423. }
  424. return $structureList;
  425. }
  426. //人资员工导入
  427. public function tobeusers(){
  428. $userModel = model('User');
  429. $param = $this->param;
  430. $flag = $userModel->beusers($param);
  431. if ($flag) {
  432. return resultArray(['data'=>$flag]);
  433. } else {
  434. return resultArray(['error'=>$userModel->getError()]);
  435. }
  436. }
  437. //根据部门ID获取员工列表
  438. public function userListByStructId()
  439. {
  440. $usermodel = model('User');
  441. $param = $this->param;
  442. $structure_id = $param['structure_id']?:'';
  443. $ret = $usermodel->getUserListByStructureId($structure_id) ? : [];
  444. return resultArray(['data'=>$ret]);
  445. }
  446. /**
  447. * 员工账号修改
  448. * @param
  449. * @return
  450. */
  451. public function usernameEdit()
  452. {
  453. //权限判断
  454. if (!checkPerByAction('admin', 'users', 'update')) {
  455. header('Content-Type:application/json; charset=utf-8');
  456. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  457. }
  458. $param = $this->param;
  459. $userInfo = $this->userInfo;
  460. //权限判断
  461. if ($param['id'] == 1) {
  462. return resultArray(['error' => '管理员账号暂不能修改']);
  463. }
  464. $adminTypes = adminGroupTypes($userInfo['id']);
  465. if (!in_array(3,$adminTypes) && !in_array(1,$adminTypes) && !in_array(2,$adminTypes)) {
  466. header('Content-Type:application/json; charset=utf-8');
  467. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  468. }
  469. if (!$param['id'] || !$param['username'] || !$param['password']) {
  470. return resultArray(['error' => '参数错误!']);
  471. }
  472. if (db('admin_user')->where(['id' => ['neq',$param['id']],'username' => $param['username']])->find()) {
  473. return resultArray(['error' => '手机号码已存在!']);
  474. }
  475. $userData = db('admin_user')->where(['id' => $param['id']])->field('username,salt,password')->find();
  476. $data = [];
  477. $data['username'] = $param['username'];
  478. $data['password'] = user_md5($param['password'], $userData['salt'], $param['username']);
  479. $data['userInfo'] = $userData;
  480. $data['mobile'] = $param['username'];
  481. $resSync = model('Sync')->syncData($data);
  482. if ($resSync) {
  483. unset($data['userInfo']);
  484. $res = db('admin_user')->where(['id' => $param['id']])->update($data);
  485. return resultArray(['data' => '修改成功!']);
  486. } else {
  487. return resultArray(['error' => '修改失败,请重试!']);
  488. }
  489. }
  490. /**
  491. * 登录记录
  492. */
  493. public function loginRecord()
  494. {
  495. if (!checkPerByAction('admin', 'loginRecord', 'index')) {
  496. header('Content-Type:application/json; charset=utf-8');
  497. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  498. }
  499. $loginRecordModel = new LoginRecord();
  500. $where = [];
  501. getWhereUserByParam($where, 'create_user_id');
  502. getWhereTimeByParam($where, 'create_time');
  503. $limit = $this->param['limit'] ?: 15;
  504. $data = $loginRecordModel
  505. ->where($where)
  506. ->order(['create_time' => 'DESC'])
  507. ->paginate($limit)
  508. ->each(function ($val) {
  509. $val['username'] = $val->create_user_info['realname'];
  510. $val['type_name'] = $val->type_name;
  511. })
  512. ->toArray();
  513. return resultArray([
  514. 'data' => [
  515. 'list' => $data['data'],
  516. 'dataCount' => $data['total']
  517. ],
  518. ]);
  519. }
  520. /**
  521. * 员工导入模板下载
  522. * @author Michael_xu
  523. * @param string $save_path 本地保存路径 用于错误数据导出,在 Admin\Model\Excel::batchImportData()调用
  524. * @return
  525. */
  526. public function excelDownload($save_path = '')
  527. {
  528. $param = $this->param;
  529. $userInfo = $this->userInfo;
  530. $excelModel = new \app\admin\model\Excel();
  531. // 导出的字段列表
  532. $field_list = UserModel::$import_field_list;
  533. $excelModel->excelImportDownload($field_list, 'admin_user', $save_path);
  534. }
  535. /**
  536. * 员工导入
  537. */
  538. public function import()
  539. {
  540. // 仅允许超管,系统管理员,部门与员工管理员 导入
  541. if (false === UserModel::checkUserGroup([1, 2, 3])) {
  542. return resultArray(['error' => '没有该权限']);
  543. }
  544. $param = $this->param;
  545. $userInfo = $this->userInfo;
  546. $excelModel = new \app\admin\model\Excel();
  547. $param['types'] = 'admin_user';
  548. $file = request()->file('file');
  549. $res = $excelModel->batchImportData($file, $param, $this);
  550. $list=[];
  551. $list[]=$excelModel->getError();
  552. $item=$list[0];
  553. if (!$res) {
  554. return resultArray(['data' => $item]);
  555. }
  556. Cache::clear('user_info');
  557. return resultArray(['data' => $item]);
  558. }
  559. /**
  560. * 批量设置直属上级
  561. *
  562. * @author Ymob
  563. * @datetime 2019-10-28 13:37:57
  564. */
  565. public function setParent()
  566. {
  567. // 仅允许超管,系统管理员,部门与员工管理员 批量设置
  568. if (false === UserModel::checkUserGroup([1, 2, 3])) {
  569. return resultArray(['error' => '没有该权限']);
  570. }
  571. $parent_id = (int) $this->param['parent_id'];
  572. $parent_user = UserModel::find($parent_id);
  573. if (!$parent_user) {
  574. return resultArray(['error' => '请选择直属上级']);
  575. }
  576. $user_id_list = (array) $this->param['id_list'];
  577. if (empty($user_id_list)) {
  578. return resultArray(['error' => '请选择员工']);
  579. }
  580. if (in_array(1, $user_id_list)) {
  581. return resultArray(['error' => '超级管理员不能设置上级']);
  582. }
  583. if (in_array($parent_id, $user_id_list)) {
  584. return resultArray(['error' => '直属上级不能为员工自己']);
  585. }
  586. foreach ($user_id_list as $val) {
  587. if (in_array($parent_id, getSubUserId(true, 0, (int) $val))) {
  588. return resultArray(['error' => '直属上级不能是自己下属(包含下属的下属)']);
  589. }
  590. }
  591. $a = new UserModel;
  592. if ($a->where(['id' => ['IN', $user_id_list]])->update(['parent_id' => $parent_id])) {
  593. Cache::clear('user_info');
  594. return resultArray(['data' => '员工直属上级设置成功']);
  595. } else {
  596. return resultArray(['error' => '员工直属上级设置失败' . $a->getError()]);
  597. }
  598. }
  599. /**
  600. * 通讯录列表
  601. * @return mixed
  602. */
  603. public function queryList(){
  604. $param = $this->param;
  605. $userInfo = $this->userInfo;
  606. $param['user_id']=$userInfo['id'];
  607. $userLogic=new UserLogic();
  608. $data=$userLogic->getDataList($param);
  609. return resultArray(['data' => $data]);
  610. }
  611. /**
  612. * 关注的通讯录列表
  613. * @return mixed
  614. */
  615. public function starList(){
  616. $param = $this->param;
  617. $userInfo = $this->userInfo;
  618. $param['user_id']=$userInfo['id'];
  619. $userLogic=new UserLogic();
  620. $data=$userLogic->queryList($param);
  621. return resultArray(['data' => $data]);
  622. }
  623. /**
  624. * 设置关注
  625. *
  626. */
  627. public function userStar()
  628. {
  629. $userInfo = $this->userInfo;
  630. $userId = $userInfo['id'];
  631. $targetId = $this->param['target_id'];
  632. $type = $this->param['type'];
  633. if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']);
  634. if (!$this->setStar($type, $userId, $targetId)) {
  635. return resultArray(['error' => '设置关注失败!']);
  636. }
  637. return resultArray(['data' => '设置关注成功!']);
  638. }
  639. /**
  640. * 复制员工角色
  641. *
  642. * @return \think\response\Json
  643. */
  644. public function copyRole()
  645. {
  646. $param = $this->param;
  647. if (empty($param['user_id']) && empty($param['structure_id'])) return resultArray(['error' => '请选择员工或部门!']);
  648. if (empty($param['group_id'])) return resultArray(['error' => '请选择角色!']);
  649. $userModel = new User();
  650. if (!$userModel->copyRole($param)) return resultArray(['error' => '操作失败!']);
  651. return resultArray(['data' => '操作成功!']);
  652. }
  653. /**
  654. * 获取下属(全部层级)
  655. *
  656. */
  657. public function subordinate()
  658. {
  659. $userId = $this->userInfo['id'];
  660. # 获取下属的ID
  661. $subIds = getSubUserId(false, 0, $userId);
  662. $data = Db::name('admin_user')->field(['id', 'realname', 'thumb_img as img'])->whereIn('id', $subIds)->select();
  663. foreach ($data AS $key => $value) {
  664. $data[$key]['img'] = !empty($data[$key]['img']) ? getFullPath($data[$key]['img']) : '';
  665. }
  666. return resultArray(['data' => $data]);
  667. }
  668. /**
  669. * 获取当前登录人信息
  670. *
  671. */
  672. public function queryLoginUser()
  673. {
  674. $resData = [];
  675. $wkcode = file_get_contents(CONF_PATH.'license.dat');
  676. if ($wkcode) {
  677. $resCheckData = checkWkCode($wkcode);
  678. if ($resCheckData) {
  679. $resData = object_to_array(json_decode($resCheckData));
  680. }
  681. }
  682. return $resData;
  683. }
  684. }