Remote.php 12 KB

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