Addresslist.php 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. //通讯录列表
  84. // public function index()
  85. // {
  86. // $param = $this->param;
  87. // $where = array();
  88. // $where['user.status'] = 1;
  89. // if ($param['search']) {
  90. // $where['user.realname'] = array('like', '%'.$param['search'].'%');
  91. // }
  92. // if ($param['type'] == 1) {
  93. // $datalist = Db::name('AdminUser')
  94. // ->where($where)
  95. // ->alias('user')
  96. // ->join('AdminStructure structure', 'structure.id = user.structure_id', 'LEFT')
  97. // ->field('user.id,user.realname,user.thumb_img,user.post,user.structure_id,structure.name as structure_name,user.username,user.mobile,user.sex,user.email,user.status')
  98. // ->select();
  99. // foreach( $datalist as $k=>$v){
  100. // $datalist[$k]['thumb_img'] = $v['thumb_img'] ? getFullPath( $v['thumb_img'] ) : '';
  101. // }
  102. // $newarray = $this->groupByInitials($datalist,'realname');
  103. // return resultArray(['data' => $newarray]);
  104. // } else {
  105. // $structureList = Db::name('AdminStructure')->select();
  106. // foreach($structureList as $key=>$value){
  107. // $where['user.structure_id'] = $value['id'];
  108. // $userList = Db::name('AdminUser')
  109. // ->where($where)
  110. // ->alias('user')
  111. // ->field('user.id,user.realname,user.username,user.thumb_img,user.post,user.structure_id,user.mobile,user.sex,user.email')
  112. // ->order('realname asc')
  113. // ->select();
  114. // foreach ($userList as $k=>$v){
  115. // $userList[$k]['thumb_img'] = $v['thumb_img'] ? getFullPath( $v['thumb_img'] ) : '';
  116. // }
  117. // $structureList[$key]['userList'] = $userList;
  118. // $structureList[$key]['structure_name'] = $value['name'];
  119. // }
  120. // return resultArray(['data' => $structureList]);
  121. // }
  122. // }
  123. //
  124. // /**
  125. // * 二维数组根据首字母分组排序
  126. // * @param array $data 二维数组
  127. // * @param string $targetKey 首字母的键名
  128. // * @return array 根据首字母关联的二维数组
  129. // */
  130. // public function groupByInitials(array $data, $targetKey = 'name')
  131. // {
  132. // $data = array_map(function ($item) use ($targetKey) {
  133. // return array_merge($item, [
  134. // 'initials' => $this->getInitials($item[$targetKey]),
  135. // ]);
  136. // }, $data);
  137. // $data = $this->sortInitials($data);
  138. // return $data;
  139. // }
  140. //
  141. // /**
  142. // * 按字母排序
  143. // * @param array $data
  144. // * @return array
  145. // */
  146. // public function sortInitials(array $data)
  147. // {
  148. // $sortData = [];
  149. // foreach ($data as $key => $value) {
  150. // $sortData[$value['initials']][] = $value;
  151. // }
  152. // ksort($sortData);
  153. // return $sortData;
  154. // }
  155. //
  156. // /**
  157. // * 获取首字母
  158. // * @param string $str 汉字字符串
  159. // * @return string 首字母
  160. // */
  161. // public function getInitials($str)
  162. // {
  163. // if (empty($str)) {return '';}
  164. // $fchar = ord($str{0});
  165. // if ($fchar >= ord('A') && $fchar <= ord('z')) {
  166. // return strtoupper($str{0});
  167. // }
  168. //
  169. // $s1 = iconv('UTF-8', 'gb2312', $str);
  170. // $s2 = iconv('gb2312', 'UTF-8', $s1);
  171. // $s = $s2 == $str ? $s1 : $str;
  172. // $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
  173. // if($asc == -9300){
  174. // return 'G';
  175. // }
  176. // if ($asc >= -20319 && $asc <= -20284) {
  177. // return 'A';
  178. // }
  179. //
  180. // if ($asc >= -20283 && $asc <= -19776) {
  181. // return 'B';
  182. // }
  183. //
  184. // if ($asc >= -19775 && $asc <= -19219) {
  185. // return 'C';
  186. // }
  187. //
  188. // if ($asc >= -19218 && $asc <= -18711) {
  189. // return 'D';
  190. // }
  191. //
  192. // if ($asc >= -18710 && $asc <= -18527) {
  193. // return 'E';
  194. // }
  195. //
  196. // if ($asc >= -18526 && $asc <= -18240) {
  197. // return 'F';
  198. // }
  199. //
  200. // if ($asc >= -18239 && $asc <= -17923) {
  201. // return 'G';
  202. // }
  203. //
  204. // if ($asc >= -17922 && $asc <= -17418) {
  205. // return 'H';
  206. // }
  207. //
  208. // if ($asc >= -17417 && $asc <= -16475) {
  209. // return 'J';
  210. // }
  211. //
  212. // if ($asc >= -16474 && $asc <= -16213) {
  213. // return 'K';
  214. // }
  215. //
  216. // if ($asc >= -16212 && $asc <= -15641) {
  217. // return 'L';
  218. // }
  219. //
  220. // if ($asc >= -15640 && $asc <= -15166) {
  221. // return 'M';
  222. // }
  223. //
  224. // if ($asc >= -15165 && $asc <= -14923) {
  225. // return 'N';
  226. // }
  227. //
  228. // if ($asc >= -14922 && $asc <= -14915) {
  229. // return 'O';
  230. // }
  231. //
  232. // if ($asc >= -14914 && $asc <= -14631) {
  233. // return 'P';
  234. // }
  235. //
  236. // if ($asc >= -14630 && $asc <= -14150) {
  237. // return 'Q';
  238. // }
  239. //
  240. // if ($asc >= -14149 && $asc <= -14091) {
  241. // return 'R';
  242. // }
  243. //
  244. // if ($asc >= -14090 && $asc <= -13319) {
  245. // return 'S';
  246. // }
  247. //
  248. // if ($asc >= -13318 && $asc <= -12839) {
  249. // return 'T';
  250. // }
  251. //
  252. // if ($asc >= -12838 && $asc <= -12557) {
  253. // return 'W';
  254. // }
  255. //
  256. // if ($asc >= -12556 && $asc <= -11848) {
  257. // return 'X';
  258. // }
  259. //
  260. // if ($asc >= -11847 && $asc <= -11056) {
  261. // return 'Y';
  262. // }
  263. //
  264. // if ($asc >= -11055 && $asc <= -10247) {
  265. // return 'Z';
  266. // }
  267. // return '#';
  268. // }
  269. }