|
@@ -0,0 +1,338 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\manage\controller;
|
|
|
+
|
|
|
+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 Order extends Base {
|
|
|
+
|
|
|
+ public function local() {
|
|
|
+ // 查询出全部的机构,显示上级机构使用
|
|
|
+ $rs = Db::table("institution")->select();
|
|
|
+ $this->assign("institutions", $rs);
|
|
|
+
|
|
|
+ $manage = Session::get('session_manager');
|
|
|
+ // 取出所有上级医院
|
|
|
+ $up = DB::table('institution')->where('id',$manage['institution_id'])->value('parent_institution');
|
|
|
+ //取出所有下级医院
|
|
|
+ $down = DB::table('institution')->where('parent_institution','like','%'.$manage['institution_id'].'%')->column('id');
|
|
|
+ $string = implode(',',$down);
|
|
|
+ $agents = Db::table("doctors")->where("institution_id",'in', ','.$up.','.$string.','.$manage['institution_id'].',')->field("id,realname as 'text',institution_id")->select();
|
|
|
+ $this->assign("agents", $agents);
|
|
|
+
|
|
|
+ return $this->fetch('local');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function remote() {
|
|
|
+ // 查询出全部的机构,显示上级机构使用
|
|
|
+ $rs = Db::table("institution")->select();
|
|
|
+ $this->assign("institutions", $rs);
|
|
|
+
|
|
|
+ $manage = Session::get('session_manager');
|
|
|
+ // 取出所有上级医院
|
|
|
+ $up = DB::table('institution')->where('id',$manage['institution_id'])->value('parent_institution');
|
|
|
+ //取出所有下级医院
|
|
|
+ $down = DB::table('institution')->where('parent_institution','like','%'.$manage['institution_id'].'%')->column('id');
|
|
|
+ $string = implode(',',$down);
|
|
|
+ $agents = Db::table("doctors")->where("institution_id",'in', ','.$up.','.$string.','.$manage['institution_id'].',')->field("id,realname as 'text',institution_id")->select();
|
|
|
+ $this->assign("agents", $agents);
|
|
|
+
|
|
|
+ return $this->fetch('remote');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表数据
|
|
|
+ */
|
|
|
+ public function localdatas() {
|
|
|
+ $request = Request::instance();
|
|
|
+ $params = $request->param();
|
|
|
+// $pid = isset($params["pid"]) ? $params["pid"] : null;
|
|
|
+// $status = isset($params["status"]) ? $params["status"] : null;
|
|
|
+// $name = isset($params["name"]) ? $params["name"] : null;
|
|
|
+// $whereArr = array();
|
|
|
+// if ($pid != null) {
|
|
|
+// $whereArr["parent_institution"] = array("like", "%" . $pid . "%");
|
|
|
+// }
|
|
|
+// if ($status != null) {
|
|
|
+// $whereArr["status"] = $status;
|
|
|
+// }
|
|
|
+// if ($name != null) {
|
|
|
+// $whereArr["name"] = array("like", "%" . $name . "%");
|
|
|
+// }
|
|
|
+ $manage = Session::get('session_manager');
|
|
|
+ $rs = Db::table("remote_order")->where('hospital_id',$manage['institution_id'])->select();
|
|
|
+ echo json_encode($rs);
|
|
|
+ }
|
|
|
+ public function remotedatas() {
|
|
|
+ $request = Request::instance();
|
|
|
+ $params = $request->param();
|
|
|
+// $pid = isset($params["pid"]) ? $params["pid"] : null;
|
|
|
+// $status = isset($params["status"]) ? $params["status"] : null;
|
|
|
+// $name = isset($params["name"]) ? $params["name"] : null;
|
|
|
+// $whereArr = array();
|
|
|
+// if ($pid != null) {
|
|
|
+// $whereArr["parent_institution"] = array("like", "%" . $pid . "%");
|
|
|
+// }
|
|
|
+// if ($status != null) {
|
|
|
+// $whereArr["status"] = $status;
|
|
|
+// }
|
|
|
+// if ($name != null) {
|
|
|
+// $whereArr["name"] = array("like", "%" . $name . "%");
|
|
|
+// }
|
|
|
+ $manage = Session::get('session_manager');
|
|
|
+ $rs = Db::table("remote_order")->where('super_hospital_id',$manage['institution_id'])->select();
|
|
|
+// foreach ()
|
|
|
+ echo json_encode($rs);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新或创建机构信息
|
|
|
+ */
|
|
|
+ public function save() {
|
|
|
+ $request = Request::instance();
|
|
|
+ $parms = $request->param();
|
|
|
+ $id = $parms["id"];
|
|
|
+ $data = array();
|
|
|
+ $data["name"] = $parms["name"];
|
|
|
+ $data["address"] = $parms["address"];
|
|
|
+ $data["remark"] = $parms["remark"];
|
|
|
+ $data["status"] = $parms["status"];
|
|
|
+ $data["institution_level"] = $parms["institution_level"];
|
|
|
+ $data["parent_institution"] = $parms["parent_institution"];
|
|
|
+ $data["agent_id"] = isset($parms["agent_id"]) ? $parms["agent_id"] : "";
|
|
|
+ if (is_array($data["parent_institution"])) {
|
|
|
+ $pids = "";
|
|
|
+ foreach ($data["parent_institution"] as $key => $val) {
|
|
|
+ $pids = $pids . "," . $val;
|
|
|
+ }
|
|
|
+ if (strlen($pids) > 0) {
|
|
|
+ $data["parent_institution"] = substr($pids, 1);
|
|
|
+ } else {
|
|
|
+ $data["parent_institution"] = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data["charge_mode"] = $parms["charge_mode"];
|
|
|
+ $data["local_domain"] = $parms["local_domain"];
|
|
|
+ // ID有值,认为是更新
|
|
|
+ if (empty($id)) {
|
|
|
+ // 无值,认为是添加
|
|
|
+ if(empty($parms['yid'])){
|
|
|
+ $data["id"] = UUIDs::uuid16();
|
|
|
+ }else{
|
|
|
+ $data["id"] = $parms['yid'];
|
|
|
+ }
|
|
|
+ $data["createdAt"] = date("Y-m-d H:i:s");
|
|
|
+ $id = Db::table("institution")->insertGetId($data);
|
|
|
+ $this->saveContact($data["parent_institution"],$id);
|
|
|
+ echo "insert_ok;" . $data["id"];
|
|
|
+ SysLogs::log("institution", "C", json_encode($data));
|
|
|
+ } else {
|
|
|
+ if(!empty($parms['yid'])){
|
|
|
+ $data["id"] = $parms['yid'];
|
|
|
+ }
|
|
|
+ $data["updatedAt"] = date("Y-m-d H:i:s");
|
|
|
+ // 更新
|
|
|
+ Db::table("institution")->where("id", $id)->update($data);
|
|
|
+ $this->saveContact($data["parent_institution"],$id);
|
|
|
+ SysLogs::log("institution", "U", "id = " . $id . " --> " . json_encode($data));
|
|
|
+ echo "update_ok";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function saveContact($parent,$id)
|
|
|
+ {
|
|
|
+ if(empty($parent)){
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ $local_name = DB::table('institution')->where('id',$id)->value('name');
|
|
|
+ foreach ($parent as $k=>$v){
|
|
|
+ $data = DB::table('remote_contact')->where('hospital_id',$id)->where('super_hospital_id',$v)->find();
|
|
|
+ if(!empty($data)){
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ $parent_name = DB::table('institution')->where('id',$v)->value('name');
|
|
|
+ $info = [
|
|
|
+ 'hospital_id'=>$id,
|
|
|
+ 'super_hospital_id'=>$v,
|
|
|
+ 'timestamp'=>time(),
|
|
|
+ 'hospital_name'=>$local_name,
|
|
|
+ 'super_hospital_name'=>$parent_name
|
|
|
+ ];
|
|
|
+ DB::table('remote_contact')->insert($info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑窗口
|
|
|
+ * @return type
|
|
|
+ */
|
|
|
+ public function edit() {
|
|
|
+
|
|
|
+ // 查询出全部的机构,显示上级机构使用
|
|
|
+ $insRs = Db::table("institution")->field("id,name as 'text'")->select();
|
|
|
+ $this->assign("insJson", json_encode($insRs));
|
|
|
+ if (isset($_GET["id"])) {
|
|
|
+ $id = $_GET["id"];
|
|
|
+ if ($id != null) {
|
|
|
+ $institutions = Db::table("institution")->where("id", $id)->find();
|
|
|
+ if (count($institutions) > 0) {
|
|
|
+ $this->assign("institution", $institutions);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $this->fetch('edit');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录
|
|
|
+ */
|
|
|
+ public function delete() {
|
|
|
+ if (isset($_GET["ids"])) {
|
|
|
+ $ids = $_GET["ids"];
|
|
|
+ if (!empty($ids)) {
|
|
|
+ $idArr = explode(",", $ids);
|
|
|
+ if (count($idArr) > 0) {
|
|
|
+ Db::table("institution")->where("id", "in", $idArr)->delete();
|
|
|
+ }
|
|
|
+ SysLogs::log("institution", "D", $ids);
|
|
|
+ echo "delete_ok";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ echo "fail";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 代理商树
|
|
|
+ */
|
|
|
+ public function agents() {
|
|
|
+ $treeData = array();
|
|
|
+ $rows = Db::table("manager")->where("role_id", "2")->field("id,username as 'text'")->select();
|
|
|
+ $parentTree = array();
|
|
|
+ $parentTree["id"] = "";
|
|
|
+ $parentTree["text"] = "请选择";
|
|
|
+ array_push($treeData, $parentTree);
|
|
|
+ if (!empty($rows)) {
|
|
|
+ foreach ($rows as $key => $val) {
|
|
|
+ array_push($treeData, $val);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ echo json_encode($treeData);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deptview() {
|
|
|
+ $request = Request::instance();
|
|
|
+ $params = $request->param();
|
|
|
+ if (isset($params["insId"])) {
|
|
|
+ $this->assign("insId", $params["insId"]);
|
|
|
+ } else {
|
|
|
+ echo "parameter insId error!";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ return $this->fetch('dept');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取医院科室数据
|
|
|
+ * @return type
|
|
|
+ */
|
|
|
+ public function deptdatas() {
|
|
|
+ $request = Request::instance();
|
|
|
+ $params = $request->param();
|
|
|
+ if (!isset($params["insId"])) {
|
|
|
+ echo "please change a institution!";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $ins = Db::table("institution")->where("id", $params["insId"])->find();
|
|
|
+ if (empty($ins)) {
|
|
|
+ echo "please change a institution(2)!";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $whereArr = array();
|
|
|
+ $whereArr["institution_id"] = $params["insId"];
|
|
|
+ $rootMenuData = array();
|
|
|
+ // 准备根节点
|
|
|
+ $rootMenuData["id"] = "root";
|
|
|
+ $rootMenuData["pId"] = "0";
|
|
|
+ $rootMenuData["name"] = "科室管理(" . $ins["name"] . ")";
|
|
|
+ $rootMenuData["url"] = "";
|
|
|
+ $rootMenuData["open"] = "true";
|
|
|
+
|
|
|
+ // 查询全部数据
|
|
|
+ $menuData = $info = DB::table('department')->where($whereArr)->select();
|
|
|
+ $jsonarray = array();
|
|
|
+ if ($menuData != null) {
|
|
|
+ foreach ($menuData as $k => $val) {
|
|
|
+ $data = array();
|
|
|
+ $data["id"] = $val["id"];
|
|
|
+ $data['pId'] = $val["parent_id"];
|
|
|
+ $data['name'] = $val["department_name"];
|
|
|
+ $data['institutionid'] = $val["institution_id"];
|
|
|
+ $data['isreport'] = $val["is_report"];
|
|
|
+ $data['ordernum'] = $val["order_num"];
|
|
|
+ array_push($jsonarray, $data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 将根节点添加到树
|
|
|
+ array_unshift($jsonarray, $rootMenuData);
|
|
|
+ // 返回JSON数据
|
|
|
+ echo json_encode($jsonarray);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加或修改
|
|
|
+ */
|
|
|
+ public function deptupd() {
|
|
|
+ $id = $_GET["id"];
|
|
|
+ // id=&pid=root&name=%E5%A4%96%E7%A7%91&institutionid=&=0&ordernum=11
|
|
|
+ // ID有值,认为是更新
|
|
|
+ if (empty($id)) {
|
|
|
+ $data = array();
|
|
|
+ // 无值,认为是添加
|
|
|
+ $data["id"] = UUIDs::uuid16();
|
|
|
+ $data["parent_id"] = $_GET["pid"];
|
|
|
+ $data["department_name"] = $_GET["name"];
|
|
|
+ $data["institution_id"] = $_GET["institutionid"];
|
|
|
+ $data["order_num"] = $_GET["ordernum"];
|
|
|
+ $data["is_report"] = $_GET["isreport"];
|
|
|
+ Db::table("department")->insert($data);
|
|
|
+ echo "insert_ok";
|
|
|
+ SysLogs::log("constant", "C", json_encode($data));
|
|
|
+ } else {
|
|
|
+ // 更新
|
|
|
+ $data["id"] = $_GET["id"];
|
|
|
+ $data["parent_id"] = $_GET["pid"];
|
|
|
+ $data["department_name"] = $_GET["name"];
|
|
|
+ $data["institution_id"] = $_GET["institutionid"];
|
|
|
+ $data["order_num"] = $_GET["ordernum"];
|
|
|
+ $data["is_report"] = $_GET["isreport"];
|
|
|
+ Db::table("department")->where("id", $id)->update(["parent_id" => $data["parent_id"], "department_name" => $data["department_name"], "institution_id" => $data["institution_id"], "is_report" => $data["is_report"], "order_num" => $data["order_num"]]);
|
|
|
+ echo "update_ok";
|
|
|
+ SysLogs::log("constant", "U", $id . " --> " . json_encode($data));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deptdel() {
|
|
|
+ $id = $_GET["id"];
|
|
|
+ $result = Db::table("department")->delete($id);
|
|
|
+ if ($result) {
|
|
|
+ echo "delete_ok";
|
|
|
+ SysLogs::log("department", "D", $id . " --> delete_ok");
|
|
|
+ } else {
|
|
|
+ echo "delete_fail";
|
|
|
+ SysLogs::log("department", "D", $id . " --> delete_fail");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|