Patientinfo.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. class Patientinfo extends Base {
  12. public function index() {
  13. return $this->fetch();
  14. }
  15. public function datas() {
  16. $request = Request::instance();
  17. $params = $request->param();
  18. $wheres = array();
  19. $insid = isset($params["insid"]) ? $params["insid"] : null;
  20. $username = isset($params["username"]) ? $params["username"] : null;
  21. $tel = isset($params["tel"]) ? $params["tel"] : null;
  22. if ($insid != null && $insid != "") {
  23. $wheres["institution_id"] = $insid;
  24. }
  25. if ($username != null && $username != "") {
  26. $wheres["name"] = array("like", "%" . $username . "%");
  27. }
  28. if ($tel != null && $tel != "") {
  29. $wheres["phone"] = array("like", $tel . "%");
  30. }
  31. $insMap = array();
  32. $insArr = Db::table("institution")->field("id, name")->select();
  33. if (!empty($insArr)) {
  34. foreach ($insArr as $key => $val) {
  35. $insMap[$val["id"]] = $val["name"];
  36. }
  37. }
  38. $page = empty($params["page"]) ? 1 : $params["page"];
  39. $pagesize = empty($params["rows"]) ? 1 : $params["rows"];
  40. if (empty($page) || $page < 1) {
  41. $page = 1;
  42. }
  43. if (empty($pagesize) || $pagesize < 1) {
  44. $pagesize = 30;
  45. }
  46. $resultArr = array();
  47. $info = DB::table('patient_infos')->where($wheres)->page($page, $pagesize)->select();
  48. if (!empty($info)) {
  49. foreach ($info as $key => $val) {
  50. if (isset($insMap[$val["institution_id"]])) {
  51. $val["institution_name"] = $insMap[$val["institution_id"]];
  52. } else {
  53. $val["institution_name"] = $val["institution_id"];
  54. }
  55. array_push($resultArr, $val);
  56. }
  57. }
  58. $num = DB::table('patient_infos')->where($wheres)->count();
  59. $data = array();
  60. $data['total'] = $num;
  61. $data['rows'] = $resultArr;
  62. echo json_encode($data);
  63. }
  64. /**
  65. * 编辑窗口
  66. * @return type
  67. */
  68. public function edit() {
  69. if (isset($_GET["id"])) {
  70. $id = $_GET["id"];
  71. if ($id != null) {
  72. $patient_info = Db::table("patient_info")->where("id", $id)->find();
  73. if (count($patient_info) > 0) {
  74. $this->assign("patient_info", $patient_info);
  75. }
  76. }
  77. }
  78. return $this->fetch('edit');
  79. }
  80. public function save() {
  81. $request = Request::instance();
  82. $params = $request->param();
  83. $id = isset($params["id"]) ? $params["id"] : null;
  84. if ($id != null && $id != "") {
  85. // 更新
  86. // 判断下birthday
  87. if ($params["birthday"] == "") {
  88. $params["birthday"] = null;
  89. }
  90. $a = DB::table('patient_infos')->where('id', $params['id'])->update($params);
  91. SysLogs::log("patient_info", "U", 'id = ' . $params['id'] . " --> " . json_encode($params));
  92. if ($a) {
  93. return 'success';
  94. } else {
  95. return 'fail';
  96. }
  97. } else {
  98. // 或许是新增
  99. }
  100. return "fail";
  101. }
  102. /**
  103. * 软删除记录
  104. */
  105. public function delete() {
  106. if (isset($_GET["ids"])) {
  107. $ids = $_GET["ids"];
  108. if (!empty($ids)) {
  109. $idArr = explode(",", $ids);
  110. if (count($idArr) > 0) {
  111. Db::table("patient_info")->where("id", "in", $idArr)->update(['status' => "0"]);
  112. SysLogs::log("patient_info", "U", 'id in ' . $ids . " --> status = 0");
  113. }
  114. echo "delete_ok";
  115. return;
  116. }
  117. }
  118. echo "fail";
  119. }
  120. }