Remote.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 Remote extends Base {
  15. public function remote() {
  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('remote');
  22. }
  23. public function local() {
  24. // 查询出全部的机构,显示上级机构使用
  25. $rs = Db::table("institution")->select();
  26. $this->assign("institutions", $rs);
  27. $agents = Db::table("manager")->where("role_id", "2")->field("id,username as 'text'")->select();
  28. $this->assign("agents", $agents);
  29. return $this->fetch('local');
  30. }
  31. /**
  32. * 列表数据
  33. */
  34. public function localdatas() {
  35. $request = Request::instance();
  36. $params = $request->param();
  37. /*$pid = isset($params["pid"]) ? $params["pid"] : null;
  38. $status = isset($params["status"]) ? $params["status"] : null;
  39. $name = isset($params["name"]) ? $params["name"] : null;
  40. $whereArr = array();
  41. if ($pid != null) {
  42. $whereArr["parent_institution"] = array("like", "%" . $pid . "%");
  43. }
  44. if ($status != null) {
  45. $whereArr["status"] = $status;
  46. }
  47. if ($name != null) {
  48. $whereArr["name"] = array("like", "%" . $name . "%");
  49. }*/
  50. $manage = Session::get('session_manager');
  51. $rs = Db::table("remote_cost")->where('hospital_id',$manage['institution_id'])->select();
  52. echo json_encode($rs);
  53. }
  54. public function remotedatas() {
  55. $request = Request::instance();
  56. $params = $request->param();
  57. /*$pid = isset($params["pid"]) ? $params["pid"] : null;
  58. $status = isset($params["status"]) ? $params["status"] : null;
  59. $name = isset($params["name"]) ? $params["name"] : null;
  60. $whereArr = array();
  61. if ($pid != null) {
  62. $whereArr["parent_institution"] = array("like", "%" . $pid . "%");
  63. }
  64. if ($status != null) {
  65. $whereArr["status"] = $status;
  66. }
  67. if ($name != null) {
  68. $whereArr["name"] = array("like", "%" . $name . "%");
  69. }*/
  70. $manage = Session::get('session_manager');
  71. $rs = Db::table("remote_cost")->where('super_hospital_id',$manage['institution_id'])->select();
  72. echo json_encode($rs);
  73. }
  74. /**
  75. * 更新或创建机构信息
  76. */
  77. public function save() {
  78. $manage = Session::get('session_manager');
  79. $request = Request::instance();
  80. $parms = $request->param();
  81. $id = $parms["id"];
  82. $data = array();
  83. $data["hospital_id"] = $parms["hospital_id"];
  84. $data["super_hospital_id"] = $manage['institution_id'];
  85. $data["exam_class"] = $parms["exam_class"];
  86. $data["super_doctor_id"] = $parms["super_doctor_id"];
  87. $data["remark"] = $parms["remark"];
  88. $data["money"] = $parms["money"];
  89. $data["timestamp"] = time();
  90. $doctor = DB::table('doctors')->where('id',$parms['super_doctor_id'])->field('realname,username,is_admin')->find();
  91. if(empty($doctor['realname'])){
  92. $data['super_doctor_name'] = $doctor['username'];
  93. }else{
  94. $data['super_doctor_name'] = $doctor['realname'];
  95. }
  96. $data['is_admin'] = $doctor['is_admin'] ?? '';
  97. // var_dump($data);die;
  98. // ID有值,认为是更新
  99. if (empty($id)) {
  100. // 无值,认为是添加
  101. $id = Db::table("remote_cost")->insertGetId($data);
  102. echo "insert_ok;" . $id;
  103. SysLogs::log("remote", "C", json_encode($data));
  104. } else {
  105. // 更新
  106. Db::table("remote_cost")->where("id", $id)->update($data);
  107. SysLogs::log("remote", "U", "id = " . $id . " --> " . json_encode($data));
  108. echo "update_ok";
  109. }
  110. }
  111. public function saveContact($parent,$id)
  112. {
  113. if(empty($parent)){
  114. return '';
  115. }
  116. $local_name = DB::table('institution')->where('id',$id)->value('name');
  117. foreach ($parent as $k=>$v){
  118. $data = DB::table('remote_contact')->where('hospital_id',$id)->where('super_hospital_id',$v)->find();
  119. if(!empty($data)){
  120. return '';
  121. }
  122. $parent_name = DB::table('institution')->where('id',$v)->value('name');
  123. $info = [
  124. 'id'=>UUIDs::uuid16(),
  125. 'hospital_id'=>$id,
  126. 'super_hospital_id'=>$v,
  127. 'timestamp'=>time(),
  128. 'hospital_name'=>$local_name,
  129. 'super_hospital_name'=>$parent_name
  130. ];
  131. DB::table('remote_contact')->insert($info);
  132. }
  133. }
  134. /**
  135. * 编辑窗口
  136. * @return type
  137. */
  138. public function edit() {
  139. // 显示下级机构使用
  140. $manage = Session::get('session_manager');
  141. // 显示下级机构
  142. $insRs = Db::table("remote_contact")->where('super_hospital_id',$manage['institution_id'])->field("hospital_id as id,hospital_name as 'name'")->select();
  143. $this->assign("insJson", $insRs);
  144. $class = DB::table('constant')->where('parent_id','exam_class')->column('constant_value');
  145. $this->assign("class", $class);
  146. $doctors = DB::table('doctors')->where('institution_id',$manage['institution_id'])->field('id,realname,username')->select();
  147. foreach ($doctors as $k=>$v){
  148. if(empty($v['realname'])){
  149. $doctors[$k]['realname'] = $v['username'];
  150. }
  151. }
  152. $this->assign("doctors", $doctors);
  153. if (isset($_GET["id"])) {
  154. $id = $_GET["id"];
  155. if ($id != null) {
  156. $remote = Db::table("remote_cost")->where("id", $id)->find();
  157. $this->assign("remote", $remote);
  158. if (count($remote) > 0) {
  159. $this->assign("remote", $remote);
  160. }
  161. }
  162. }
  163. return $this->fetch('edit');
  164. }
  165. /**
  166. * 删除记录
  167. */
  168. public function delete() {
  169. if (isset($_GET["ids"])) {
  170. $ids = $_GET["ids"];
  171. if (!empty($ids)) {
  172. $idArr = explode(",", $ids);
  173. if (count($idArr) > 0) {
  174. Db::table("remote_cost")->where("id", "in", $idArr)->delete();
  175. }
  176. SysLogs::log("remote_cost", "D", $ids);
  177. echo "delete_ok";
  178. return;
  179. }
  180. }
  181. echo "fail";
  182. }
  183. /**
  184. * 代理商树
  185. */
  186. public function agents() {
  187. $treeData = array();
  188. $rows = Db::table("manager")->where("role_id", "2")->field("id,username as 'text'")->select();
  189. $parentTree = array();
  190. $parentTree["id"] = "";
  191. $parentTree["text"] = "请选择";
  192. array_push($treeData, $parentTree);
  193. if (!empty($rows)) {
  194. foreach ($rows as $key => $val) {
  195. array_push($treeData, $val);
  196. }
  197. }
  198. echo json_encode($treeData);
  199. }
  200. public function deptview() {
  201. $request = Request::instance();
  202. $params = $request->param();
  203. if (isset($params["insId"])) {
  204. $this->assign("insId", $params["insId"]);
  205. } else {
  206. echo "parameter insId error!";
  207. return;
  208. }
  209. return $this->fetch('dept');
  210. }
  211. /**
  212. * 获取医院科室数据
  213. * @return type
  214. */
  215. public function deptdatas() {
  216. $request = Request::instance();
  217. $params = $request->param();
  218. if (!isset($params["insId"])) {
  219. echo "please change a institution!";
  220. return;
  221. }
  222. $ins = Db::table("institution")->where("id", $params["insId"])->find();
  223. if (empty($ins)) {
  224. echo "please change a institution(2)!";
  225. return;
  226. }
  227. $whereArr = array();
  228. $whereArr["institution_id"] = $params["insId"];
  229. $rootMenuData = array();
  230. // 准备根节点
  231. $rootMenuData["id"] = "root";
  232. $rootMenuData["pId"] = "0";
  233. $rootMenuData["name"] = "科室管理(" . $ins["name"] . ")";
  234. $rootMenuData["url"] = "";
  235. $rootMenuData["open"] = "true";
  236. // 查询全部数据
  237. $menuData = $info = DB::table('department')->where($whereArr)->select();
  238. $jsonarray = array();
  239. if ($menuData != null) {
  240. foreach ($menuData as $k => $val) {
  241. $data = array();
  242. $data["id"] = $val["id"];
  243. $data['pId'] = $val["parent_id"];
  244. $data['name'] = $val["department_name"];
  245. $data['institutionid'] = $val["institution_id"];
  246. $data['isreport'] = $val["is_report"];
  247. $data['ordernum'] = $val["order_num"];
  248. array_push($jsonarray, $data);
  249. }
  250. }
  251. // 将根节点添加到树
  252. array_unshift($jsonarray, $rootMenuData);
  253. // 返回JSON数据
  254. echo json_encode($jsonarray);
  255. }
  256. /**
  257. * 添加或修改
  258. */
  259. public function deptupd() {
  260. $id = $_GET["id"];
  261. // id=&pid=root&name=%E5%A4%96%E7%A7%91&institutionid=&=0&ordernum=11
  262. // ID有值,认为是更新
  263. if (empty($id)) {
  264. $data = array();
  265. // 无值,认为是添加
  266. $data["id"] = UUIDs::uuid16();
  267. $data["parent_id"] = $_GET["pid"];
  268. $data["department_name"] = $_GET["name"];
  269. $data["institution_id"] = $_GET["institutionid"];
  270. $data["order_num"] = $_GET["ordernum"];
  271. $data["is_report"] = $_GET["isreport"];
  272. Db::table("department")->insert($data);
  273. echo "insert_ok";
  274. SysLogs::log("constant", "C", json_encode($data));
  275. } else {
  276. // 更新
  277. $data["id"] = $_GET["id"];
  278. $data["parent_id"] = $_GET["pid"];
  279. $data["department_name"] = $_GET["name"];
  280. $data["institution_id"] = $_GET["institutionid"];
  281. $data["order_num"] = $_GET["ordernum"];
  282. $data["is_report"] = $_GET["isreport"];
  283. 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"]]);
  284. echo "update_ok";
  285. SysLogs::log("constant", "U", $id . " --> " . json_encode($data));
  286. }
  287. }
  288. public function deptdel() {
  289. $id = $_GET["id"];
  290. $result = Db::table("department")->delete($id);
  291. if ($result) {
  292. echo "delete_ok";
  293. SysLogs::log("department", "D", $id . " --> delete_ok");
  294. } else {
  295. echo "delete_fail";
  296. SysLogs::log("department", "D", $id . " --> delete_fail");
  297. }
  298. }
  299. }