Institution.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. if(empty($parms['yid'])){
  77. $data["id"] = UUIDs::uuid16();
  78. }else{
  79. $data["id"] = $parms['yid'];
  80. }
  81. $data["createdAt"] = date("Y-m-d H:i:s");
  82. Db::table("institution")->insert($data);
  83. echo "insert_ok;" . $data["id"];
  84. SysLogs::log("institution", "C", json_encode($data));
  85. } else {
  86. if(!empty($parms['yid'])){
  87. $data["id"] = $parms['yid'];
  88. }
  89. $data["updatedAt"] = date("Y-m-d H:i:s");
  90. // 更新
  91. Db::table("institution")->where("id", $id)->update($data);
  92. SysLogs::log("institution", "U", "id = " . $id . " --> " . json_encode($data));
  93. echo "update_ok";
  94. }
  95. }
  96. /**
  97. * 编辑窗口
  98. * @return type
  99. */
  100. public function edit() {
  101. // 查询出全部的机构,显示上级机构使用
  102. $insRs = Db::table("institution")->field("id,name as 'text'")->select();
  103. $this->assign("insJson", json_encode($insRs));
  104. if (isset($_GET["id"])) {
  105. $id = $_GET["id"];
  106. if ($id != null) {
  107. $institutions = Db::table("institution")->where("id", $id)->find();
  108. if (count($institutions) > 0) {
  109. $this->assign("institution", $institutions);
  110. }
  111. }
  112. }
  113. return $this->fetch('edit');
  114. }
  115. /**
  116. * 删除记录
  117. */
  118. public function delete() {
  119. if (isset($_GET["ids"])) {
  120. $ids = $_GET["ids"];
  121. if (!empty($ids)) {
  122. $idArr = explode(",", $ids);
  123. if (count($idArr) > 0) {
  124. Db::table("institution")->where("id", "in", $idArr)->delete();
  125. }
  126. SysLogs::log("institution", "D", $ids);
  127. echo "delete_ok";
  128. return;
  129. }
  130. }
  131. echo "fail";
  132. }
  133. /**
  134. * 代理商树
  135. */
  136. public function agents() {
  137. $treeData = array();
  138. $rows = Db::table("manager")->where("role_id", "2")->field("id,username as 'text'")->select();
  139. $parentTree = array();
  140. $parentTree["id"] = "";
  141. $parentTree["text"] = "请选择";
  142. array_push($treeData, $parentTree);
  143. if (!empty($rows)) {
  144. foreach ($rows as $key => $val) {
  145. array_push($treeData, $val);
  146. }
  147. }
  148. echo json_encode($treeData);
  149. }
  150. public function deptview() {
  151. $request = Request::instance();
  152. $params = $request->param();
  153. if (isset($params["insId"])) {
  154. $this->assign("insId", $params["insId"]);
  155. } else {
  156. echo "parameter insId error!";
  157. return;
  158. }
  159. return $this->fetch('dept');
  160. }
  161. /**
  162. * 获取医院科室数据
  163. * @return type
  164. */
  165. public function deptdatas() {
  166. $request = Request::instance();
  167. $params = $request->param();
  168. if (!isset($params["insId"])) {
  169. echo "please change a institution!";
  170. return;
  171. }
  172. $ins = Db::table("institution")->where("id", $params["insId"])->find();
  173. if (empty($ins)) {
  174. echo "please change a institution(2)!";
  175. return;
  176. }
  177. $whereArr = array();
  178. $whereArr["institution_id"] = $params["insId"];
  179. $rootMenuData = array();
  180. // 准备根节点
  181. $rootMenuData["id"] = "root";
  182. $rootMenuData["pId"] = "0";
  183. $rootMenuData["name"] = "科室管理(" . $ins["name"] . ")";
  184. $rootMenuData["url"] = "";
  185. $rootMenuData["open"] = "true";
  186. // 查询全部数据
  187. $menuData = $info = DB::table('department')->where($whereArr)->select();
  188. $jsonarray = array();
  189. if ($menuData != null) {
  190. foreach ($menuData as $k => $val) {
  191. $data = array();
  192. $data["id"] = $val["id"];
  193. $data['pId'] = $val["parent_id"];
  194. $data['name'] = $val["department_name"];
  195. $data['institutionid'] = $val["institution_id"];
  196. $data['isreport'] = $val["is_report"];
  197. $data['ordernum'] = $val["order_num"];
  198. array_push($jsonarray, $data);
  199. }
  200. }
  201. // 将根节点添加到树
  202. array_unshift($jsonarray, $rootMenuData);
  203. // 返回JSON数据
  204. echo json_encode($jsonarray);
  205. }
  206. /**
  207. * 添加或修改
  208. */
  209. public function deptupd() {
  210. $id = $_GET["id"];
  211. // id=&pid=root&name=%E5%A4%96%E7%A7%91&institutionid=&=0&ordernum=11
  212. // ID有值,认为是更新
  213. if (empty($id)) {
  214. $data = array();
  215. // 无值,认为是添加
  216. $data["id"] = UUIDs::uuid16();
  217. $data["parent_id"] = $_GET["pid"];
  218. $data["department_name"] = $_GET["name"];
  219. $data["institution_id"] = $_GET["institutionid"];
  220. $data["order_num"] = $_GET["ordernum"];
  221. $data["is_report"] = $_GET["isreport"];
  222. Db::table("department")->insert($data);
  223. echo "insert_ok";
  224. SysLogs::log("constant", "C", json_encode($data));
  225. } else {
  226. // 更新
  227. $data["id"] = $_GET["id"];
  228. $data["parent_id"] = $_GET["pid"];
  229. $data["department_name"] = $_GET["name"];
  230. $data["institution_id"] = $_GET["institutionid"];
  231. $data["order_num"] = $_GET["ordernum"];
  232. $data["is_report"] = $_GET["isreport"];
  233. 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"]]);
  234. echo "update_ok";
  235. SysLogs::log("constant", "U", $id . " --> " . json_encode($data));
  236. }
  237. }
  238. public function deptdel() {
  239. $id = $_GET["id"];
  240. $result = Db::table("department")->delete($id);
  241. if ($result) {
  242. echo "delete_ok";
  243. SysLogs::log("department", "D", $id . " --> delete_ok");
  244. } else {
  245. echo "delete_fail";
  246. SysLogs::log("department", "D", $id . " --> delete_fail");
  247. }
  248. }
  249. }