123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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 ($param['id'] && (int)$param['id'] !== $userInfo['id']) {
  293. //权限判断
  294. if (!checkPerByAction('admin', 'users', 'update')) {
  295. header('Content-Type:application/json; charset=utf-8');
  296. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  297. }
  298. $user_id = $param['id'];
  299. if (!$param['new_pwd']) {
  300. $this->error = '请输入重置密码';
  301. return false;
  302. }
  303. $userInfo = $userModel->getDataById($user_id);
  304. if (user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']) == $userInfo['password']) {
  305. $this->error = '密码没改变';
  306. return false;
  307. }
  308. if (db('admin_user')->where('id', $user_id)->setField('password', user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']))) {
  309. $syncData = [];
  310. $syncModel = new \app\admin\model\Sync();
  311. $syncData['user_id'] = $userInfo['id'];
  312. $syncData['salt'] = $userInfo['salt'];
  313. $syncData['password'] = user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']);
  314. $resSync = $syncModel->syncData($syncData);
  315. return resultArray(['data' => '密码重置成功']);
  316. } else {
  317. return resultArray(['error' => '密码重置失败,请重试']);
  318. }
  319. } else {
  320. $userModel = model('User');
  321. $old_pwd = $param['old_pwd'];
  322. $new_pwd = $param['new_pwd'];
  323. $data = $userModel->updatePaw($userInfo, $old_pwd, $new_pwd);
  324. if (!$data) {
  325. return resultArray(['error' => $userModel->getError()]);
  326. }
  327. return resultArray(['data' => $data]);
  328. }
  329. }
  330. /**
  331. * 员工角色关系
  332. * @param
  333. * @return
  334. */
  335. public function groups()
  336. {
  337. //权限判断
  338. if (!checkPerByAction('admin', 'groups', 'update')) {
  339. header('Content-Type:application/json; charset=utf-8');
  340. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  341. }
  342. $param = $this->param;
  343. if (!$param['users'] && !$param['structures']) {
  344. return resultArray(['error' => '请选择员工']);
  345. }
  346. if (!$param['groups']) {
  347. return resultArray(['error' => '请选择角色']);
  348. }
  349. $userModel = model('User');
  350. //部门下所有员工
  351. $userArr = [];
  352. if (is_array($param['structures'])) {
  353. foreach ($param['structures'] as $v) {
  354. $userArr[] = $userModel->getSubUserByStr($v);
  355. }
  356. }
  357. if ($userArr) $userArr = call_user_func_array('array_merge', $userArr); //数组合并
  358. if ($userArr && $param['users']) {
  359. $userIds = array_merge($userArr, $param['users']);
  360. } elseif ($userArr) {
  361. $userIds = $userArr;
  362. } else {
  363. $userIds = $param['users'];
  364. }
  365. $userIds = array_unique($userIds);
  366. $groups = $param['groups'];
  367. $accessModel = model('Access');
  368. $resData = true;
  369. foreach ($userIds as $k=>$v) {
  370. //角色员工关系处理
  371. $res = $accessModel->userGroup($v, $param['groups']);
  372. if (!$res) {
  373. $resData = false;
  374. }
  375. }
  376. // if ($resData == false) {
  377. // return resultArray(['error' => '操作失败,请重试']);
  378. // }
  379. return resultArray(['data' => '创建成功']);
  380. }
  381. /**
  382. * 员工角色关系(删除)
  383. * @param
  384. * @return
  385. */
  386. public function groupsDel()
  387. {
  388. //权限判断
  389. if (!checkPerByAction('admin', 'groups', 'update')) {
  390. header('Content-Type:application/json; charset=utf-8');
  391. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  392. }
  393. $param = $this->param;
  394. if (!$param['user_id']) {
  395. return resultArray(['error' => '请选择员工']);
  396. }
  397. if (!$param['group_id']) {
  398. return resultArray(['error' => '参数错误']);
  399. }
  400. # 员工至少保留一个角色
  401. $count = db('admin_access')->where(['user_id' => $param['user_id']])->count();
  402. if ($count == 1) return resultArray(['error' => '员工至少保留一个角色!']);
  403. $res = db('admin_access')->where(['user_id' => $param['user_id'],'group_id' => $param['group_id']])->delete();
  404. if (!$res) {
  405. return resultArray(['error' => '操作失败,请重试']);
  406. }
  407. return resultArray(['data' => '删除成功']);
  408. }
  409. /**
  410. * [structureUserList 部门员工混合数据]
  411. * @param
  412. * @return
  413. */
  414. public function structureUserList()
  415. {
  416. $structure_list = db('admin_structure')->select();
  417. $structureList = getSubObj(0, $structure_list, '', 1);
  418. foreach ($structureList as $k=>$v) {
  419. $userList = [];
  420. $userList = db('admin_user')->where(['structure_id' => $v['id'],'status' => array('in',['1','3'])])->field('id,realname')->select();
  421. $structureList[$k]['userList'] = $userList;
  422. }
  423. return $structureList;
  424. }
  425. //人资员工导入
  426. public function tobeusers(){
  427. $userModel = model('User');
  428. $param = $this->param;
  429. $flag = $userModel->beusers($param);
  430. if ($flag) {
  431. return resultArray(['data'=>$flag]);
  432. } else {
  433. return resultArray(['error'=>$userModel->getError()]);
  434. }
  435. }
  436. //根据部门ID获取员工列表
  437. public function userListByStructId()
  438. {
  439. $usermodel = model('User');
  440. $param = $this->param;
  441. $structure_id = $param['structure_id']?:'';
  442. $ret = $usermodel->getUserListByStructureId($structure_id) ? : [];
  443. return resultArray(['data'=>$ret]);
  444. }
  445. /**
  446. * 员工账号修改
  447. * @param
  448. * @return
  449. */
  450. public function usernameEdit()
  451. {
  452. //权限判断
  453. if (!checkPerByAction('admin', 'users', 'update')) {
  454. header('Content-Type:application/json; charset=utf-8');
  455. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  456. }
  457. $param = $this->param;
  458. $userInfo = $this->userInfo;
  459. //权限判断
  460. if ($param['id'] == 1) {
  461. return resultArray(['error' => '管理员账号暂不能修改']);
  462. }
  463. $adminTypes = adminGroupTypes($userInfo['id']);
  464. if (!in_array(3,$adminTypes) && !in_array(1,$adminTypes) && !in_array(2,$adminTypes)) {
  465. header('Content-Type:application/json; charset=utf-8');
  466. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  467. }
  468. if (!$param['id'] || !$param['username'] || !$param['password']) {
  469. return resultArray(['error' => '参数错误!']);
  470. }
  471. if (db('admin_user')->where(['id' => ['neq',$param['id']],'username' => $param['username']])->find()) {
  472. return resultArray(['error' => '手机号码已存在!']);
  473. }
  474. $userData = db('admin_user')->where(['id' => $param['id']])->field('username,salt,password')->find();
  475. $data = [];
  476. $data['username'] = $param['username'];
  477. $data['password'] = user_md5($param['password'], $userData['salt'], $param['username']);
  478. $data['userInfo'] = $userData;
  479. $data['mobile'] = $param['username'];
  480. $resSync = model('Sync')->syncData($data);
  481. if ($resSync) {
  482. unset($data['userInfo']);
  483. $res = db('admin_user')->where(['id' => $param['id']])->update($data);
  484. return resultArray(['data' => '修改成功!']);
  485. } else {
  486. return resultArray(['error' => '修改失败,请重试!']);
  487. }
  488. }
  489. /**
  490. * 登录记录
  491. */
  492. public function loginRecord()
  493. {
  494. if (!checkPerByAction('admin', 'loginRecord', 'index')) {
  495. header('Content-Type:application/json; charset=utf-8');
  496. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  497. }
  498. $loginRecordModel = new LoginRecord();
  499. $where = [];
  500. getWhereUserByParam($where, 'create_user_id');
  501. getWhereTimeByParam($where, 'create_time');
  502. $limit = $this->param['limit'] ?: 15;
  503. $data = $loginRecordModel
  504. ->where($where)
  505. ->order(['create_time' => 'DESC'])
  506. ->paginate($limit)
  507. ->each(function ($val) {
  508. $val['username'] = $val->create_user_info['realname'];
  509. $val['type_name'] = $val->type_name;
  510. })
  511. ->toArray();
  512. return resultArray([
  513. 'data' => [
  514. 'list' => $data['data'],
  515. 'dataCount' => $data['total']
  516. ],
  517. ]);
  518. }
  519. /**
  520. * 员工导入模板下载
  521. * @author Michael_xu
  522. * @param string $save_path 本地保存路径 用于错误数据导出,在 Admin\Model\Excel::batchImportData()调用
  523. * @return
  524. */
  525. public function excelDownload($save_path = '')
  526. {
  527. $param = $this->param;
  528. $userInfo = $this->userInfo;
  529. $excelModel = new \app\admin\model\Excel();
  530. // 导出的字段列表
  531. $field_list = UserModel::$import_field_list;
  532. $excelModel->excelImportDownload($field_list, 'admin_user', $save_path);
  533. }
  534. /**
  535. * 员工导入
  536. */
  537. public function import()
  538. {
  539. // 仅允许超管,系统管理员,部门与员工管理员 导入
  540. if (false === UserModel::checkUserGroup([1, 2, 3])) {
  541. return resultArray(['error' => '没有该权限']);
  542. }
  543. $param = $this->param;
  544. $userInfo = $this->userInfo;
  545. $excelModel = new \app\admin\model\Excel();
  546. $param['types'] = 'admin_user';
  547. $file = request()->file('file');
  548. $res = $excelModel->batchImportData($file, $param, $this);
  549. $list=[];
  550. $list[]=$excelModel->getError();
  551. $item=$list[0];
  552. if (!$res) {
  553. return resultArray(['data' => $item]);
  554. }
  555. Cache::clear('user_info');
  556. return resultArray(['data' => $item]);
  557. }
  558. /**
  559. * 批量设置直属上级
  560. *
  561. * @author Ymob
  562. * @datetime 2019-10-28 13:37:57
  563. */
  564. public function setParent()
  565. {
  566. // 仅允许超管,系统管理员,部门与员工管理员 批量设置
  567. if (false === UserModel::checkUserGroup([1, 2, 3])) {
  568. return resultArray(['error' => '没有该权限']);
  569. }
  570. $parent_id = (int) $this->param['parent_id'];
  571. $parent_user = UserModel::find($parent_id);
  572. if (!$parent_user) {
  573. return resultArray(['error' => '请选择直属上级']);
  574. }
  575. $user_id_list = (array) $this->param['id_list'];
  576. if (empty($user_id_list)) {
  577. return resultArray(['error' => '请选择员工']);
  578. }
  579. if (in_array(1, $user_id_list)) {
  580. return resultArray(['error' => '超级管理员不能设置上级']);
  581. }
  582. if (in_array($parent_id, $user_id_list)) {
  583. return resultArray(['error' => '直属上级不能为员工自己']);
  584. }
  585. foreach ($user_id_list as $val) {
  586. if (in_array($parent_id, getSubUserId(true, 0, (int) $val))) {
  587. return resultArray(['error' => '直属上级不能是自己下属(包含下属的下属)']);
  588. }
  589. }
  590. $a = new UserModel;
  591. if ($a->where(['id' => ['IN', $user_id_list]])->update(['parent_id' => $parent_id])) {
  592. Cache::clear('user_info');
  593. return resultArray(['data' => '员工直属上级设置成功']);
  594. } else {
  595. return resultArray(['error' => '员工直属上级设置失败' . $a->getError()]);
  596. }
  597. }
  598. /**
  599. * 通讯录列表
  600. * @return mixed
  601. */
  602. public function queryList(){
  603. $param = $this->param;
  604. $userInfo = $this->userInfo;
  605. $param['user_id']=$userInfo['id'];
  606. $userLogic=new UserLogic();
  607. $data=$userLogic->getDataList($param);
  608. return resultArray(['data' => $data]);
  609. }
  610. /**
  611. * 关注的通讯录列表
  612. * @return mixed
  613. */
  614. public function starList(){
  615. $param = $this->param;
  616. $userInfo = $this->userInfo;
  617. $param['user_id']=$userInfo['id'];
  618. $userLogic=new UserLogic();
  619. $data=$userLogic->queryList($param);
  620. return resultArray(['data' => $data]);
  621. }
  622. /**
  623. * 设置关注
  624. *
  625. */
  626. public function userStar()
  627. {
  628. $userInfo = $this->userInfo;
  629. $userId = $userInfo['id'];
  630. $targetId = $this->param['target_id'];
  631. $type = $this->param['type'];
  632. if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']);
  633. if (!$this->setStar($type, $userId, $targetId)) {
  634. return resultArray(['error' => '设置关注失败!']);
  635. }
  636. return resultArray(['data' => '设置关注成功!']);
  637. }
  638. /**
  639. * 复制员工角色
  640. *
  641. * @return \think\response\Json
  642. */
  643. public function copyRole()
  644. {
  645. $param = $this->param;
  646. if (empty($param['user_id']) && empty($param['structure_id'])) return resultArray(['error' => '请选择员工或部门!']);
  647. if (empty($param['group_id'])) return resultArray(['error' => '请选择角色!']);
  648. $userModel = new User();
  649. if (!$userModel->copyRole($param)) return resultArray(['error' => '操作失败!']);
  650. return resultArray(['data' => '操作成功!']);
  651. }
  652. /**
  653. * 获取下属(全部层级)
  654. *
  655. */
  656. public function subordinate()
  657. {
  658. $userId = $this->userInfo['id'];
  659. # 获取下属的ID
  660. $subIds = getSubUserId(false, 0, $userId);
  661. $data = Db::name('admin_user')->field(['id', 'realname', 'thumb_img as img'])->whereIn('id', $subIds)->select();
  662. foreach ($data AS $key => $value) {
  663. $data[$key]['img'] = !empty($data[$key]['img']) ? getFullPath($data[$key]['img']) : '';
  664. }
  665. return resultArray(['data' => $data]);
  666. }
  667. /**
  668. * 获取当前登录人信息
  669. *
  670. */
  671. public function queryLoginUser()
  672. {
  673. $resData = [];
  674. $wkcode = file_get_contents(CONF_PATH.'license.dat');
  675. if ($wkcode) {
  676. $resCheckData = checkWkCode($wkcode);
  677. if ($resCheckData) {
  678. $resData = object_to_array(json_decode($resCheckData));
  679. }
  680. }
  681. return $resData;
  682. }
  683. }