Base.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace app\manage\controller;
  3. use app\admin\model\Admin;
  4. use think\Controller;
  5. use think\Db;
  6. use think\Session;
  7. use think\Config;
  8. use think\Cookie;
  9. use think\Request;
  10. use app\common\library\SysLogs;
  11. use app\common\library\UUIDs;
  12. class Base extends Controller {
  13. protected $logined = false; //登录状态
  14. /**
  15. * 无需登录的方法,同时也就不需要鉴权了
  16. * @var array
  17. */
  18. protected $noNeedLogin = [];
  19. /**
  20. * 初始化操作
  21. */
  22. public function _initialize() {
  23. $admin = Session::get('session_manager');
  24. if (!$admin) {
  25. $this->error('对不起,您还未进行登录,请先登录', '/manage/login/index');
  26. }
  27. }
  28. /**
  29. * 追加名称<br />
  30. * 如:已知医生id,添加医生名字<br />
  31. * 使用表必须以id作为查询主键
  32. * @param type $row
  33. * @param type $key
  34. * @param type $tablename
  35. * @param type $namefield
  36. * @return type
  37. */
  38. public function appendName($row, $key, $tablename, $namefield) {
  39. if (empty($row)) {
  40. return $row;
  41. }
  42. if (empty($key)) {
  43. return $row;
  44. }
  45. $id = $row[$key];
  46. if (!empty($id)) {
  47. $rs = Db::table($tablename)->where("id", $id)->field($namefield)->find();
  48. if (!empty($rs)) {
  49. $row[$key . "_name"] = $rs[$namefield];
  50. }
  51. }
  52. return $row;
  53. }
  54. /**
  55. * 展示机构树
  56. */
  57. public function insCombobox() {
  58. $rs = Db::table("institution")->field("id,name 'text',parent_institution")->select();
  59. $level = 1;
  60. $topIns = array();
  61. $topIns["id"] = "";
  62. // $topIns["name"] = "请选择医疗机构";
  63. $topIns["text"] = "请选择医疗机构";
  64. $insTreeData = self::itsInstitutionCombChild("", $rs, $level);
  65. $topIns["children"] = $insTreeData;
  66. $viewArr=array();
  67. array_push($viewArr, $topIns);
  68. echo json_encode($viewArr);
  69. }
  70. /**
  71. * 遍历显示机构树
  72. * @param type $pid
  73. * @return type
  74. */
  75. public function itsInstitutionCombChild($parent_id, $rs, $level) {
  76. $level = $level + 1;
  77. if ($level > 6) {
  78. return null;
  79. }
  80. // echo $level . "-" . $pid . "<br />";
  81. $childrenArr = array();
  82. if (count($rs) > 0) {
  83. foreach ($rs as $key => $val) {
  84. if (isset($val["id"])) {
  85. $id = $val["id"];
  86. $pidTmp = $val["parent_institution"];
  87. if ($pidTmp == $parent_id || (!empty($parent_id) && strpos("#" . $pidTmp, $parent_id) > 0)) {
  88. // 子类
  89. $thisChilds = self::itsInstitutionCombChild($val["id"], $rs, $level);
  90. if (!empty($thisChilds)) {
  91. $val["children"] = $thisChilds;
  92. }
  93. // $val["parent_institution"]=null;
  94. $keys = array_keys($childrenArr);
  95. $val = self::array_remove($val, "parent_institution" );
  96. array_push($childrenArr, $val);
  97. //array_splice($rs, $key);
  98. } else {
  99. }
  100. }
  101. }
  102. }
  103. return $childrenArr;
  104. }
  105. /**
  106. * 显示科室
  107. */
  108. public function insDept(){
  109. $request = Request::instance();
  110. $params=$request->param();
  111. $wheres=array();
  112. $selAll=array();
  113. $selAll["id"]="";
  114. $selAll["text"]="查询全部";
  115. if(isset($params['insid'])){
  116. $wheres["institution_id"]=$params['insid'];
  117. $orders = array();
  118. $orders["order_num"] = "1";
  119. $rs = Db::table("department")->where($wheres)->field("id,department_name 'text'")->order($orders)->select();
  120. if(!empty($rs)){
  121. array_unshift($rs,$selAll);
  122. echo json_encode($rs);
  123. }else{
  124. $list=array();
  125. array_push($list, $selAll);
  126. echo json_encode($list);
  127. }
  128. }else{
  129. $list=array();
  130. array_push($list, $selAll);
  131. echo json_encode($list);
  132. }
  133. }
  134. /**
  135. * 显示科室
  136. */
  137. public function examclass(){
  138. $request = Request::instance();
  139. $params=$request->param();
  140. $wheres=array();
  141. $selAll=array();
  142. $selAll["id"]="";
  143. $selAll["text"]="查询全部";
  144. if(isset($params['insid'])){
  145. $wheres["institution_id"]=$params['insid'];
  146. $orders = array();
  147. $orders["name"] = "1";
  148. $rs = Db::table("exam_class")->where($wheres)->field("id,name 'text'")->order($orders)->select();
  149. if(!empty($rs)){
  150. array_unshift($rs,$selAll);
  151. echo json_encode($rs);
  152. }else{
  153. $list=array();
  154. array_push($list, $selAll);
  155. echo json_encode($list);
  156. }
  157. }else{
  158. $list=array();
  159. array_push($list, $selAll);
  160. echo json_encode($list);
  161. }
  162. }
  163. function array_remove($arr, $key) {
  164. if (!array_key_exists($key, $arr)) {
  165. return $arr;
  166. }
  167. $keys = array_keys($arr);
  168. $index = array_search($key, $keys);
  169. if ($index !== FALSE) {
  170. array_splice($arr, $index, 1);
  171. }
  172. return $arr;
  173. }
  174. }