Doctorclass.php 3.3 KB

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