12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 通讯录
  4. // +----------------------------------------------------------------------
  5. // | Author: yyk
  6. // +----------------------------------------------------------------------
  7. namespace app\oa\controller;
  8. use app\admin\controller\ApiCommon;
  9. use think\Hook;
  10. use think\Request;
  11. use think\Db;
  12. use app\crm\traits\StarTrait;
  13. use app\oa\logic\UserLogic;
  14. class Addresslist extends ApiCommon
  15. {
  16. use StarTrait;
  17. /**
  18. * 用于判断权限
  19. * @permission 无限制
  20. * @allow 登录用户可访问
  21. * @other 其他根据系统设置
  22. **/
  23. public function _initialize()
  24. {
  25. $action = [
  26. 'permission'=>[''],
  27. 'allow'=>[
  28. 'userstar',
  29. 'querylist',
  30. 'starlist'
  31. ]
  32. ];
  33. Hook::listen('check_auth',$action);
  34. $request = Request::instance();
  35. $a = strtolower($request->action());
  36. if (!in_array($a, $action['permission'])) {
  37. parent::_initialize();
  38. }
  39. }
  40. /**
  41. * 通讯录列表
  42. * @return mixed
  43. */
  44. public function queryList(){
  45. $param = $this->param;
  46. $userInfo = $this->userInfo;
  47. $param['user_id']=$userInfo['id'];
  48. $userLogic=new UserLogic();
  49. $data=$userLogic->getDataList($param);
  50. return resultArray(['data' => $data]);
  51. }
  52. /**
  53. * 关注的通讯录列表
  54. * @return mixed
  55. */
  56. public function starList(){
  57. $param = $this->param;
  58. $userInfo = $this->userInfo;
  59. $param['user_id']=$userInfo['id'];
  60. $userLogic=new UserLogic();
  61. $data=$userLogic->queryList($param);
  62. return resultArray(['data' => $data]);
  63. }
  64. /**
  65. * 设置关注
  66. *
  67. * @return \think\response\Json
  68. * @throws \think\Exception
  69. * @throws \think\exception\PDOException
  70. */
  71. public function userStar()
  72. {
  73. $userInfo = $this->userInfo;
  74. $userId = $userInfo['id'];
  75. $targetId = $this->param['target_id'];
  76. $type = $this->param['type'];
  77. if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']);
  78. if (!$this->setStar($type, $userId, $targetId)) {
  79. return resultArray(['error' => '设置关注失败!']);
  80. }
  81. return resultArray(['data' => '设置关注成功!']);
  82. }
  83. }