123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- namespace app\manage\controller;
- use app\admin\model\Admin;
- use think\Controller;
- use think\Db;
- use think\Session;
- use think\Config;
- use think\Cookie;
- use think\Request;
- use app\common\library\SysLogs;
- use app\common\library\UUIDs;
- class Base extends Controller {
- protected $logined = false; //登录状态
- /**
- * 无需登录的方法,同时也就不需要鉴权了
- * @var array
- */
- protected $noNeedLogin = [];
- /**
- * 初始化操作
- */
- public function _initialize() {
- $admin = Session::get('session_manager');
- if (!$admin) {
- $this->error('对不起,您还未进行登录,请先登录', '/manage/login/index');
- }
- }
- /**
- * 追加名称<br />
- * 如:已知医生id,添加医生名字<br />
- * 使用表必须以id作为查询主键
- * @param type $row
- * @param type $key
- * @param type $tablename
- * @param type $namefield
- * @return type
- */
- public function appendName($row, $key, $tablename, $namefield) {
- if (empty($row)) {
- return $row;
- }
- if (empty($key)) {
- return $row;
- }
- $id = $row[$key];
- if (!empty($id)) {
- $rs = Db::table($tablename)->where("id", $id)->field($namefield)->find();
- if (!empty($rs)) {
- $row[$key . "_name"] = $rs[$namefield];
- }
- }
- return $row;
- }
- /**
- * 展示机构树
- */
- public function insCombobox() {
- $rs = Db::table("institution")->field("id,name 'text',parent_institution")->select();
- $level = 1;
- $topIns = array();
- $topIns["id"] = "";
- // $topIns["name"] = "请选择医疗机构";
- $topIns["text"] = "请选择医疗机构";
- $insTreeData = self::itsInstitutionCombChild("", $rs, $level);
- $topIns["children"] = $insTreeData;
- $viewArr=array();
- array_push($viewArr, $topIns);
- echo json_encode($viewArr);
- }
- /**
- * 遍历显示机构树
- * @param type $pid
- * @return type
- */
- public function itsInstitutionCombChild($parent_id, $rs, $level) {
- $level = $level + 1;
- if ($level > 6) {
- return null;
- }
- // echo $level . "-" . $pid . "<br />";
- $childrenArr = array();
- if (count($rs) > 0) {
- foreach ($rs as $key => $val) {
- if (isset($val["id"])) {
- $id = $val["id"];
- $pidTmp = $val["parent_institution"];
- if ($pidTmp == $parent_id || (!empty($parent_id) && strpos("#" . $pidTmp, $parent_id) > 0)) {
- // 子类
- $thisChilds = self::itsInstitutionCombChild($val["id"], $rs, $level);
- if (!empty($thisChilds)) {
- $val["children"] = $thisChilds;
- }
- // $val["parent_institution"]=null;
- $keys = array_keys($childrenArr);
- $val = self::array_remove($val, "parent_institution" );
- array_push($childrenArr, $val);
- //array_splice($rs, $key);
- } else {
-
- }
- }
- }
- }
- return $childrenArr;
- }
-
- /**
- * 显示科室
- */
- public function insDept(){
- $request = Request::instance();
- $params=$request->param();
- $wheres=array();
- $selAll=array();
- $selAll["id"]="";
- $selAll["text"]="查询全部";
- if(isset($params['insid'])){
- $wheres["institution_id"]=$params['insid'];
- $orders = array();
- $orders["order_num"] = "1";
- $rs = Db::table("department")->where($wheres)->field("id,department_name 'text'")->order($orders)->select();
- if(!empty($rs)){
- array_unshift($rs,$selAll);
- echo json_encode($rs);
- }else{
- $list=array();
- array_push($list, $selAll);
- echo json_encode($list);
- }
- }else{
- $list=array();
- array_push($list, $selAll);
- echo json_encode($list);
- }
- }
-
- /**
- * 显示科室
- */
- public function examclass(){
- $request = Request::instance();
- $params=$request->param();
- $wheres=array();
- $selAll=array();
- $selAll["id"]="";
- $selAll["text"]="查询全部";
- if(isset($params['insid'])){
- $wheres["institution_id"]=$params['insid'];
- $orders = array();
- $orders["name"] = "1";
- $rs = Db::table("exam_class")->where($wheres)->field("id,name 'text'")->order($orders)->select();
- if(!empty($rs)){
- array_unshift($rs,$selAll);
- echo json_encode($rs);
- }else{
- $list=array();
- array_push($list, $selAll);
- echo json_encode($list);
- }
- }else{
- $list=array();
- array_push($list, $selAll);
- echo json_encode($list);
- }
- }
- function array_remove($arr, $key) {
- if (!array_key_exists($key, $arr)) {
- return $arr;
- }
- $keys = array_keys($arr);
- $index = array_search($key, $keys);
- if ($index !== FALSE) {
- array_splice($arr, $index, 1);
- }
- return $arr;
- }
- }
|