Comapi.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\apply\ApiClass;
  4. use app\common\model\apply\ApiPath;
  5. use app\common\model\apply\ApplyClass;
  6. use app\common\model\base\org\Org;
  7. use app\common\model\base\org\OrgRole;
  8. use app\common\model\base\org\OrgType;
  9. use app\common\model\base\OrgTypeClass;
  10. use app\common\model\base\other\Area;
  11. use app\common\model\basic\BasicSchool;
  12. use daorui\platform\platformAuth;
  13. use daorui\weixin\work\workAuth;
  14. /**
  15. * 公告参数获取
  16. */
  17. class Comapi extends Base
  18. {
  19. protected $noNeedLogin = [
  20. ];
  21. protected $noNeedAuth = [
  22. 'getApiClassPage', 'getOrgRolePage', 'getOrgTypeClassCode', 'getOrgPage', 'getApplyClassPage', 'getArea', 'getSchoolNature',
  23. ];
  24. public function initialize()
  25. {
  26. parent::initialize();
  27. }
  28. /**
  29. * @title :[获取学校性质]
  30. * @param {参数类型} {参数字段名} {默认值} {描述}
  31. * @return json|{*}
  32. * @Author : byl
  33. * @Date :2024/12/27 16:34
  34. */
  35. public function getSchoolNature()
  36. {
  37. $info = BasicSchool::schoolNatureList();
  38. $list = [];
  39. if ($info) {
  40. foreach ($info as $k => $v) {
  41. $list[] = [
  42. 'label' => $v,
  43. 'value' => $k,
  44. ];
  45. }
  46. }
  47. return pageRes(1, '', count($list), $list);
  48. }
  49. /**
  50. * @title :[获取应用权限]
  51. * @param {参数类型} {参数字段名} {默认值} {描述}
  52. * @param {int} {pid} {0} {父级id}
  53. * @return json|{*}
  54. * @Author : byl
  55. * @Date :2025/1/2 10:12
  56. */
  57. public function getPermission()
  58. {
  59. $pid = input('pid/d', 0);
  60. $where = [];
  61. if ($pid >= 0) {
  62. $where[] = ['pid', '=', $pid];
  63. }
  64. $list = ApiClass::field('id,pid,class_name')
  65. ->where($where)
  66. ->select()
  67. ->each(function ($itme) {
  68. $w = [
  69. ['class_id', '=', $itme['id']],
  70. ];
  71. $itme['permission'] = ApiPath::field('id,api_name')->where($w)->select();
  72. if ($itme['pid'] == 0) {
  73. $itme['hasChildren'] = true;
  74. } else {
  75. $itme['hasChildren'] = false;
  76. $itme['children'] = null;
  77. }
  78. });
  79. if ($pid >= 0) {
  80. return res(1, '', $list);
  81. } else {
  82. $list = $list ? $list->toArray() : [];
  83. $list = array2tree($list, 'pid', 'id', 0, 'children');
  84. return res(1, '', $list);
  85. }
  86. }
  87. /**
  88. * @title :[接口分类]
  89. * @param {参数类型} {参数字段名} {默认值} {描述}
  90. * @param {int} {page} {1} {页码}
  91. * @param {int} {limit} {10} {条数}
  92. * @param {string} {kw} {''} {关键词}
  93. * @param {int} {org_id} {''} {所属组织}
  94. * @param {array} {val} {''} {查询指定值}
  95. * @return json|{*}
  96. * @Author : byl
  97. * @Date :2024/12/31 8:52
  98. */
  99. public function getApiClassPage()
  100. {
  101. $kw = input('kw/s', '');
  102. $page = input('page/d', 1);
  103. $limit = input('limit/d', 10);
  104. $pid = input('pid/d', 0);
  105. // 查询指定值
  106. $val = input('val/a', []);
  107. $where = [];
  108. if ($val) {
  109. if (is_array($val)) {
  110. // 查询指定值
  111. $where[] = ['id', 'IN', $val];
  112. } else {
  113. // 查询指定值
  114. $where[] = ['id', '=', $val];
  115. }
  116. $data = ApiClass::field('class_name AS label,id AS value')->where($where)->select();
  117. return pageRes(1, '', count($data), $data);
  118. } else {
  119. // 父级id
  120. if ($pid >= 0) {
  121. $where[] = ['pid', '=', $pid];
  122. }
  123. // 查询分页
  124. if ($kw) {
  125. $where[] = ['org_type_name|code', 'LIKE', "%$kw%"];
  126. }
  127. $res = ApiClass::field('class_name AS label,id AS value,pid')
  128. ->where($where)
  129. ->paginate(['list_rows' => $limit, 'page' => $page])
  130. ->each(function ($item) {
  131. $item['hasChildren'] = $item['pid'] == 0 ? true : false;
  132. });
  133. return pageRes(1, '', $res->total(), $res->items());
  134. }
  135. }
  136. /**
  137. * @title :[获取组织角色]
  138. * @param {参数类型} {参数字段名} {默认值} {描述}
  139. * @param {int} {page} {1} {页码}
  140. * @param {int} {limit} {10} {条数}
  141. * @param {string} {kw} {''} {关键词}
  142. * @param {int} {org_id} {''} {所属组织}
  143. * @param {array} {val} {''} {查询指定值}
  144. * @return json|{*}
  145. * @Author : byl
  146. * @Date :2024/12/30 11:17
  147. */
  148. public function getOrgRolePage()
  149. {
  150. $kw = input('kw/s', '');
  151. $org_id = input('org_id/d', 0);
  152. $page = input('page/d', 1);
  153. $limit = input('limit/d', 10);
  154. // 查询指定值
  155. $val = input('val/a', []);
  156. $where = [];
  157. if ($val) {
  158. // 查询指定值
  159. $where[] = ['role_id', 'IN', $val];
  160. $data = OrgRole::field('name AS label,role_id AS value')
  161. ->where($where)
  162. ->select()
  163. ->each(function ($item) {
  164. $item['right'] = OrgRole::getOrgPath($item['value']);
  165. });
  166. return pageRes(1, '', count($data), $data);
  167. } else {
  168. // 查询分页
  169. if ($kw) {
  170. $where[] = ['name|code', 'LIKE', "%$kw%"];
  171. }
  172. // 所属企业
  173. if ($org_id) {
  174. $where[] = ['org_id', '=', $org_id];
  175. }
  176. $res = OrgRole::field('name AS label,role_id AS value')
  177. ->where($where)
  178. ->paginate(['list_rows' => $limit, 'page' => $page])
  179. ->each(function ($item) {
  180. $item['right'] = OrgRole::getOrgPath($item['value']);
  181. });
  182. return pageRes(1, '', $res->total(), $res->items());
  183. }
  184. }
  185. /**
  186. * @title :[获取组织分类code值]
  187. * @param {参数类型} {参数字段名} {默认值} {描述}
  188. * @param {string} {type_class} {''} {关键词}
  189. * @return json|{*}
  190. * @Author : byl
  191. * @Date :2024/12/27 16:34
  192. */
  193. public function getOrgTypeClassCode()
  194. {
  195. $inCode = (new platformAuth())->interfaceRequest("getSchoolCode", []);
  196. $inCode = array_column($inCode['data'], 'code');
  197. $list = OrgType::where('code', 'in', $inCode)->column('code as value,org_type_name as label');
  198. return pageRes(1, '', count($list), $list);
  199. }
  200. /**
  201. * @title :[获取组织结构]
  202. * @param {参数类型} {参数字段名} {默认值} {描述}
  203. * @param {int} {page} {1} {页码}
  204. * @param {int} {limit} {10} {条数}
  205. * @param {string} {kw} {''} {关键词}
  206. * @param {array} {val} {''} {查询指定值}
  207. * @return json|{*}
  208. * @Author : byl
  209. * @Date :2024/12/23 17:45
  210. */
  211. public function getOrgTypePage()
  212. {
  213. $kw = input('kw/s', '');
  214. $page = input('page/d', 1);
  215. $limit = input('limit/d', 10);
  216. // 查询指定值
  217. $val = input('val/a', []);
  218. $where = [];
  219. if ($val) {
  220. // 查询指定值
  221. $where[] = ['code', 'IN', $val];
  222. $data = OrgType::field('org_type_name AS label,code AS value')->where($where)->select();
  223. return pageRes(1, '', count($data), $data);
  224. } else {
  225. // 查询分页
  226. if ($kw) {
  227. $where[] = ['org_type_name|code', 'LIKE', "%$kw%"];
  228. }
  229. $res = OrgType::field('org_type_name AS label,code AS value')->where($where)->paginate(['list_rows' => $limit, 'page' => $page]);
  230. return pageRes(1, '', $res->total(), $res->items());
  231. }
  232. }
  233. /**
  234. * @title :[获取应用类型]
  235. * @param {参数类型} {参数字段名} {默认值} {描述}
  236. * @param {int} {page} {1} {页码}
  237. * @param {int} {limit} {10} {条数}
  238. * @param {string} {kw} {''} {关键词}
  239. * @param {array} {val} {''} {查询指定值}
  240. * @return json|{*}
  241. * @Author : byl
  242. * @Date :2024/12/24 17:24
  243. */
  244. public function getApplyClassPage()
  245. {
  246. $kw = input('kw/s', '');
  247. $page = input('page/d', 1);
  248. $limit = input('limit/d', 10);
  249. // 查询指定值
  250. $val = input('val/a', []);
  251. $where = [];
  252. if ($val) {
  253. // 查询指定值
  254. $where[] = ['id', 'IN', $val];
  255. $data = OrgType::field('class_name AS label,id AS value')->where($where)->select();
  256. return pageRes(1, '', count($data), $data);
  257. } else {
  258. // 查询分页
  259. if ($kw) {
  260. $where[] = ['class_name|class_code', 'LIKE', "%$kw%"];
  261. }
  262. $res = ApplyClass::field('class_name AS label,id AS value')->where($where)->paginate(['list_rows' => $limit, 'page' => $page]);
  263. return pageRes(1, '', $res->total(), $res->items());
  264. }
  265. }
  266. /**
  267. * @title :[获取地区]
  268. * @param {参数类型} {参数字段名} {默认值} {描述}
  269. * @param {int} {page} {1} {页码}
  270. * @param {int} {limit} {10} {条数}
  271. * @param {string} {kw} {''} {关键词}
  272. * @param {array} {val} {''} {查询指定值}
  273. * @return json|{*}
  274. * @Author : byl
  275. * @Date :2024/12/27 9:36
  276. */
  277. public function getArea()
  278. {
  279. $kw = input('kw/s', '');
  280. $pid = input('pid/d', 1);
  281. $status = input('status/d', 0);
  282. $lazy = input('lazy/b', true);
  283. // 查询指定值
  284. $val = input('val/a', []);
  285. $where = [];
  286. if ($val) {
  287. // 查询指定值
  288. $where[] = ['id', 'IN', $val];
  289. } else {
  290. // 动态加载,则一级一级加载输出.非动态则输出全部
  291. if ($lazy) {
  292. $where[] = ['pid', '=', $pid];
  293. }
  294. if ($status) {
  295. $where[] = ['status', '=', $status];
  296. }
  297. if ($kw) {
  298. $where[] = ['name', 'LIKE', "%$kw%"];
  299. }
  300. }
  301. if ($lazy) {
  302. $data = Area::field('name AS label,id AS value,common,id,pid')
  303. ->where($where)
  304. ->order(['common' => 'DESC'])
  305. ->select();
  306. return res(1, '', $data);
  307. } else {
  308. $data = Area::where($where)
  309. ->order(['common' => 'DESC'])
  310. ->column('name AS label,id AS value,common,id,pid');
  311. $treeData = [];
  312. if ($data) {
  313. $treeData = array2tree($data, 'pid', 'id', $pid);
  314. }
  315. return res(1, '', $treeData);
  316. }
  317. }
  318. }