Messages.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 Messages extends Base {
  12. public function index() {
  13. return $this->fetch();
  14. }
  15. public function datas() {
  16. $request = Request::instance();
  17. $params = $request->param();
  18. $page = empty($params["page"]) ? 1 : $params["page"];
  19. $whereArr = array();
  20. if (isset($params["status"])) {
  21. array_push($whereArr, array("status", $params["status"]));
  22. }
  23. if (isset($params["insId"])) {
  24. array_push($whereArr, array("institution_id", $params["insId"]));
  25. }
  26. if (isset($params["deptId"])) {
  27. array_push($whereArr, array("department_id", $params["deptId"]));
  28. }
  29. $pagesize = empty($params["rows"]) ? 1 : $params["rows"];
  30. if (empty($page) || $page < 1) {
  31. $page = 1;
  32. }
  33. if (empty($pagesize) || $pagesize < 1) {
  34. $pagesize = 30;
  35. }
  36. $info = DB::table('messages')->where($whereArr)->page($page, $pagesize)->select();
  37. foreach ($info as $k => $v) {
  38. $doctor = DB::table('doctors')->where('id', $v['doctor_id'])->field('realname')->find();
  39. $info[$k]['doctor_name'] = $doctor['realname'];
  40. }
  41. $num = DB::table('messages')->where($whereArr)->count();
  42. $data = array();
  43. $data['total'] = $num;
  44. $data['rows'] = $info;
  45. echo json_encode($data);
  46. }
  47. /**
  48. * 编辑窗口
  49. * @return type
  50. */
  51. public function edit() {
  52. if (isset($_GET["id"])) {
  53. $id = $_GET["id"];
  54. if ($id != null) {
  55. $messages = Db::table("messages")->where("id", $id)->select();
  56. if (count($messages) > 0) {
  57. $this->assign("messages", $messages[0]);
  58. }
  59. }
  60. }
  61. return $this->fetch('edit');
  62. }
  63. public function save() {
  64. $a = DB::table('messages')->where('id', $_GET['id'])->update($_GET);
  65. SysLogs::log("messages", "U", 'id = ' . $_GET['id'] . " --> " . json_encode($_GET));
  66. if ($a) {
  67. return 'success';
  68. } else {
  69. return 'fail';
  70. }
  71. }
  72. /**
  73. * 软删除记录
  74. */
  75. public function delete() {
  76. if (isset($_GET["ids"])) {
  77. $ids = $_GET["ids"];
  78. if (!empty($ids)) {
  79. $idArr = explode(",", $ids);
  80. if (count($idArr) > 0) {
  81. Db::table("messages")->where("id", "in", $idArr)->update(['status' => "0"]);
  82. SysLogs::log("messages", "U", 'id in ' . $ids . " --> status = 0");
  83. }
  84. echo "delete_ok";
  85. return;
  86. }
  87. }
  88. echo "fail";
  89. }
  90. }