Institution.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. namespace app\manage\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use think\Session;
  6. use think\Config;
  7. use think\Cookie;
  8. use think\Request;
  9. use app\common\library\SysLogs;
  10. use app\common\library\UUIDs;
  11. /*
  12. *
  13. */
  14. class Institution extends Base {
  15. public function index() {
  16. // 查询出全部的机构,显示上级机构使用
  17. $rs = Db::table("institution")->select();
  18. $this->assign("institutions", $rs);
  19. $agents = Db::table("manager")->where("role_id", "2")->field("id,username as 'text'")->select();
  20. $this->assign("agents", $agents);
  21. return $this->fetch('index');
  22. }
  23. /**
  24. * 列表数据
  25. */
  26. public function datas() {
  27. $request = Request::instance();
  28. $params = $request->param();
  29. $pid = isset($params["pid"]) ? $params["pid"] : null;
  30. $status = isset($params["status"]) ? $params["status"] : null;
  31. $name = isset($params["name"]) ? $params["name"] : null;
  32. $whereArr = array();
  33. if ($pid != null) {
  34. $whereArr["parent_institution"] = array("like", "%" . $pid . "%");
  35. }
  36. if ($status != null) {
  37. $whereArr["status"] = $status;
  38. }
  39. if ($name != null) {
  40. $whereArr["name"] = array("like", "%" . $name . "%");
  41. }
  42. $rs = Db::table("institution")->where($whereArr)->select();
  43. echo json_encode($rs);
  44. }
  45. /**
  46. * 更新或创建机构信息
  47. */
  48. public function save() {
  49. $request = Request::instance();
  50. $parms = $request->param();
  51. $id = $parms["id"];
  52. $data = array();
  53. $data["name"] = $parms["name"];
  54. $data["address"] = $parms["address"];
  55. $data["remark"] = $parms["remark"];
  56. $data["status"] = $parms["status"];
  57. $data["institution_level"] = $parms["institution_level"];
  58. $data["parent_institution"] = $parms["parent_institution"];
  59. $data["agent_id"] = isset($parms["agent_id"]) ? $parms["agent_id"] : "";
  60. if (is_array($data["parent_institution"])) {
  61. $pids = "";
  62. foreach ($data["parent_institution"] as $key => $val) {
  63. $pids = $pids . "," . $val;
  64. }
  65. if (strlen($pids) > 0) {
  66. $data["parent_institution"] = substr($pids, 1);
  67. } else {
  68. $data["parent_institution"] = "";
  69. }
  70. }
  71. $data["charge_mode"] = $parms["charge_mode"];
  72. $data["local_domain"] = $parms["local_domain"];
  73. // ID有值,认为是更新
  74. if (empty($id)) {
  75. // 无值,认为是添加
  76. $data["id"] = UUIDs::uuid16();
  77. $data["createdAt"] = date("Y-m-d H:i:s");
  78. Db::table("institution")->insert($data);
  79. echo "insert_ok;" . $data["id"];
  80. SysLogs::log("institution", "C", json_encode($data));
  81. } else {
  82. $data["updatedAt"] = date("Y-m-d H:i:s");
  83. // 更新
  84. Db::table("institution")->where("id", $id)->update($data);
  85. SysLogs::log("institution", "U", "id = " . $id . " --> " . json_encode($data));
  86. echo "update_ok";
  87. }
  88. }
  89. /**
  90. * 编辑窗口
  91. * @return type
  92. */
  93. public function edit() {
  94. // 查询出全部的机构,显示上级机构使用
  95. $insRs = Db::table("institution")->field("id,name as 'text'")->select();
  96. $this->assign("insJson", json_encode($insRs));
  97. if (isset($_GET["id"])) {
  98. $id = $_GET["id"];
  99. if ($id != null) {
  100. $institutions = Db::table("institution")->where("id", $id)->find();
  101. if (count($institutions) > 0) {
  102. $this->assign("institution", $institutions);
  103. }
  104. }
  105. }
  106. return $this->fetch('edit');
  107. }
  108. /**
  109. * 删除记录
  110. */
  111. public function delete() {
  112. if (isset($_GET["ids"])) {
  113. $ids = $_GET["ids"];
  114. if (!empty($ids)) {
  115. $idArr = explode(",", $ids);
  116. if (count($idArr) > 0) {
  117. Db::table("institution")->where("id", "in", $idArr)->delete();
  118. }
  119. SysLogs::log("institution", "D", $ids);
  120. echo "delete_ok";
  121. return;
  122. }
  123. }
  124. echo "fail";
  125. }
  126. /**
  127. * 代理商树
  128. */
  129. public function agents() {
  130. $treeData = array();
  131. $rows = Db::table("manager")->where("role_id", "2")->field("id,username as 'text'")->select();
  132. $parentTree = array();
  133. $parentTree["id"] = "";
  134. $parentTree["text"] = "请选择";
  135. array_push($treeData, $parentTree);
  136. if (!empty($rows)) {
  137. foreach ($rows as $key => $val) {
  138. array_push($treeData, $val);
  139. }
  140. }
  141. echo json_encode($treeData);
  142. }
  143. public function deptview() {
  144. $request = Request::instance();
  145. $params = $request->param();
  146. if (isset($params["insId"])) {
  147. $this->assign("insId", $params["insId"]);
  148. } else {
  149. echo "parameter insId error!";
  150. return;
  151. }
  152. return $this->fetch('dept');
  153. }
  154. /**
  155. * 获取医院科室数据
  156. * @return type
  157. */
  158. public function deptdatas() {
  159. $request = Request::instance();
  160. $params = $request->param();
  161. if (!isset($params["insId"])) {
  162. echo "please change a institution!";
  163. return;
  164. }
  165. $ins = Db::table("institution")->where("id", $params["insId"])->find();
  166. if (empty($ins)) {
  167. echo "please change a institution(2)!";
  168. return;
  169. }
  170. $whereArr = array();
  171. $whereArr["institution_id"] = $params["insId"];
  172. $rootMenuData = array();
  173. // 准备根节点
  174. $rootMenuData["id"] = "root";
  175. $rootMenuData["pId"] = "0";
  176. $rootMenuData["name"] = "科室管理(" . $ins["name"] . ")";
  177. $rootMenuData["url"] = "";
  178. $rootMenuData["open"] = "true";
  179. // 查询全部数据
  180. $menuData = $info = DB::table('department')->where($whereArr)->select();
  181. $jsonarray = array();
  182. if ($menuData != null) {
  183. foreach ($menuData as $k => $val) {
  184. $data = array();
  185. $data["id"] = $val["id"];
  186. $data['pId'] = $val["parent_id"];
  187. $data['name'] = $val["department_name"];
  188. $data['institutionid'] = $val["institution_id"];
  189. $data['isreport'] = $val["is_report"];
  190. $data['ordernum'] = $val["order_num"];
  191. array_push($jsonarray, $data);
  192. }
  193. }
  194. // 将根节点添加到树
  195. array_unshift($jsonarray, $rootMenuData);
  196. // 返回JSON数据
  197. echo json_encode($jsonarray);
  198. }
  199. /**
  200. * 添加或修改
  201. */
  202. public function deptupd() {
  203. $id = $_GET["id"];
  204. // id=&pid=root&name=%E5%A4%96%E7%A7%91&institutionid=&=0&ordernum=11
  205. // ID有值,认为是更新
  206. if (empty($id)) {
  207. $data = array();
  208. // 无值,认为是添加
  209. $data["id"] = UUIDs::uuid16();
  210. $data["parent_id"] = $_GET["pid"];
  211. $data["department_name"] = $_GET["name"];
  212. $data["institution_id"] = $_GET["institutionid"];
  213. $data["order_num"] = $_GET["ordernum"];
  214. $data["is_report"] = $_GET["isreport"];
  215. Db::table("department")->insert($data);
  216. echo "insert_ok";
  217. SysLogs::log("constant", "C", json_encode($data));
  218. } else {
  219. // 更新
  220. $data["id"] = $_GET["id"];
  221. $data["parent_id"] = $_GET["pid"];
  222. $data["department_name"] = $_GET["name"];
  223. $data["institution_id"] = $_GET["institutionid"];
  224. $data["order_num"] = $_GET["ordernum"];
  225. $data["is_report"] = $_GET["isreport"];
  226. 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"]]);
  227. echo "update_ok";
  228. SysLogs::log("constant", "U", $id . " --> " . json_encode($data));
  229. }
  230. }
  231. public function deptdel() {
  232. $id = $_GET["id"];
  233. $result = Db::table("department")->delete($id);
  234. if ($result) {
  235. echo "delete_ok";
  236. SysLogs::log("department", "D", $id . " --> delete_ok");
  237. } else {
  238. echo "delete_fail";
  239. SysLogs::log("department", "D", $id . " --> delete_fail");
  240. }
  241. }
  242. }