123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <?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 Institution extends Base {
- public function index() {
- // 查询出全部的机构,显示上级机构使用
- $rs = Db::table("institution")->select();
- $this->assign("institutions", $rs);
- $agents = Db::table("manager")->where("role_id", "2")->field("id,username as 'text'")->select();
- $this->assign("agents", $agents);
- return $this->fetch('index');
- }
- /**
- * 列表数据
- */
- public function datas() {
- $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 . "%");
- }
- $rs = Db::table("institution")->where($whereArr)->select();
- 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)) {
- // 无值,认为是添加
- $data["id"] = UUIDs::uuid16();
- $data["createdAt"] = date("Y-m-d H:i:s");
- Db::table("institution")->insert($data);
- echo "insert_ok;" . $data["id"];
- SysLogs::log("institution", "C", json_encode($data));
- } else {
- $data["updatedAt"] = date("Y-m-d H:i:s");
- // 更新
- Db::table("institution")->where("id", $id)->update($data);
- SysLogs::log("institution", "U", "id = " . $id . " --> " . json_encode($data));
- echo "update_ok";
- }
- }
- /**
- * 编辑窗口
- * @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");
- }
- }
- }
|